source: trunk/test/weighted_iterator_archetype.cc @ 3314

Last change on this file since 3314 was 3314, checked in by Peter, 9 years ago

new test class: weighted_iterator_archetype. refs #803

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.9 KB
Line 
1// $Id: weighted_iterator_archetype.cc 3314 2014-09-13 06:22:10Z peter $
2
3/*
4  Copyright (C) 2014 Peter Johansson
5
6  This file is part of the yat library, http://dev.thep.lu.se/yat
7
8  The yat library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License as
10  published by the Free Software Foundation; either version 3 of the
11  License, or (at your option) any later version.
12
13  The yat library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with yat. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22// Test that class test::weighted_iterator_archetype works as
23// intended. If the class does not work on a system (and this test
24// fails), it probably cause many other failures and it probably a
25// good idea to fix this test first before the other failures (which
26// might be bogus).
27
28
29#include <config.h>
30
31#include "Suite.h"
32#include "weighted_iterator_archetype.h"
33
34#include "yat/utility/concept_check.h"
35
36#include <boost/iterator/iterator_archetypes.hpp>
37#include <boost/iterator/iterator_categories.hpp>
38#include <boost/iterator/iterator_concepts.hpp>
39
40using namespace theplu::yat;
41using namespace boost::iterator_archetypes;
42
43template<typename Iterator>
44void test_const_access(Iterator iterator)
45{
46  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>));
47}
48
49
50template<typename Iterator>
51void test_access(Iterator iterator)
52{
53  BOOST_CONCEPT_ASSERT((boost_concepts::ReadableIterator<Iterator>));
54  BOOST_CONCEPT_ASSERT((boost_concepts::WritableIterator<Iterator>));
55}
56
57
58template<typename Iterator>
59void test_traversal(Iterator iterator, boost::incrementable_traversal_tag)
60{
61  BOOST_CONCEPT_ASSERT((boost_concepts::IncrementableIterator<Iterator>));
62}
63
64
65template<typename Iterator>
66void test_traversal(Iterator iterator, boost::single_pass_traversal_tag)
67{
68  BOOST_CONCEPT_ASSERT((boost_concepts::SinglePassIterator<Iterator>));
69}
70
71
72template<typename Iterator>
73void test_traversal(Iterator iterator, boost::forward_traversal_tag)
74{
75  BOOST_CONCEPT_ASSERT((boost_concepts::ForwardTraversal<Iterator>));
76}
77
78
79template<typename Iterator>
80void test_traversal(Iterator iterator, boost::bidirectional_traversal_tag)
81{
82  BOOST_CONCEPT_ASSERT((boost_concepts::BidirectionalTraversal<Iterator>));
83}
84
85
86template<typename Iterator>
87void test_traversal(Iterator iterator, boost::random_access_traversal_tag)
88{
89  BOOST_CONCEPT_ASSERT((boost_concepts::RandomAccessTraversal<Iterator>));
90}
91
92
93template<typename Iterator, typename ConstIterator>
94void test_interoperability(Iterator i, ConstIterator ci,
95                           boost::single_pass_traversal_tag)
96{
97  BOOST_CONCEPT_ASSERT((boost_concepts::InteroperableIterator<Iterator, ConstIterator>));
98}
99
100
101template<typename Iterator, typename ConstIterator>
102void test_interoperability(Iterator i, ConstIterator ci,
103                           boost::incrementable_traversal_tag)
104{
105}
106
107
108template<typename TraversalCategory>
109void test1(void)
110{
111  test::ctor_arg arg;
112  using boost::iterator_archetypes::readable_iterator_t;
113  typedef test::weighted_iterator_archetype<readable_iterator_t,
114                                            TraversalCategory>
115    ConstIterator;
116  ConstIterator ci(arg);
117  test_const_access(ci);
118  TraversalCategory traversal;
119  test_traversal(ci, traversal);
120
121  using boost::iterator_archetypes::readable_writable_iterator_t;
122  typedef test::weighted_iterator_archetype<readable_writable_iterator_t,
123                                            TraversalCategory> Iterator;
124  Iterator i(arg);
125  test_access(i);
126  test_traversal(i, traversal);
127
128  test_interoperability(i, ci, traversal);
129}
130
131
132int main(void)
133{
134  // this is a compilation test - do not run
135  if (false) {
136    test1<boost::incrementable_traversal_tag>();
137    test1<boost::single_pass_traversal_tag>();
138    test1<boost::forward_traversal_tag>();
139    test1<boost::bidirectional_traversal_tag>();
140    test1<boost::random_access_traversal_tag>();
141  }
142
143  return 0;
144}
Note: See TracBrowser for help on using the repository browser.