EnumIterator_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "TestUtil.hpp"
40 #include "EnumIterator.hpp"
41 #include <iostream>
42 
43 using namespace std;
44 
45 enum class TestEnum1
46 {
47  One,
48  Two,
49  Three,
50  Four,
51  Five,
52  Last
53 };
54 
55 ostream& operator<<(ostream& s, TestEnum1 e)
56 {
57  s << static_cast<int>(e);
58  return s;
59 }
60 
62 {
63 public:
64  unsigned constructorTest();
65  unsigned incrementTest();
66  unsigned inequalityTest();
67  unsigned beginEndTest();
68 };
69 
70 
71 unsigned EnumIterator_T ::
73 {
74  TUDEF("EnumIterator", "EnumIterator()");
76  TestIterator1 test1;
77  // this also tests the dereference operator
79 
81  TestIterator2 test2;
82  // this also tests the dereference operator
84 
85  TUCSM("EnumIterator(C)");
86  TestIterator1 test3(TestEnum1::Three);
87  // this also tests the dereference operator
89 
90  TURETURN();
91 }
92 
93 
94 unsigned EnumIterator_T ::
96 {
97  TUDEF("EnumIterator", "operator++");
99  TestIterator1 test1;
100  // this also tests the dereference operator
102  ++test1;
104  TURETURN();
105 }
106 
107 
108 unsigned EnumIterator_T ::
110 {
111  TUDEF("EnumIterator", "operator!=");
113  TestIterator1 test1, test2;
114  TUASSERT(!(test1.operator!=(test2)));
115  ++test2;
116  TUASSERT(test1.operator!=(test2));
117  TURETURN();
118 }
119 
120 
121 unsigned EnumIterator_T ::
123 {
124  TUDEF("EnumIterator", "begin/end");
126  unsigned count = 0;
127  TestIterator1 test;
128  for (test = test.begin(); test != test.end(); ++test, count++)
129  {
130  }
131  TUASSERTE(unsigned, 5, count);
132  // nicer syntax
133  count = 0;
134  for (TestEnum1 e : TestIterator1())
135  {
136  count++;
137  }
138  TUASSERTE(unsigned, 5, count);
139  TURETURN();
140 }
141 
142 
143 int main()
144 {
145  unsigned errorTotal = 0;
146  EnumIterator_T testClass;
147  errorTotal += testClass.constructorTest();
148  errorTotal += testClass.incrementTest();
149  errorTotal += testClass.inequalityTest();
150  errorTotal += testClass.beginEndTest();
151  cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
152  return errorTotal;
153 }
TUCSM
#define TUCSM(METHOD)
Definition: TestUtil.hpp:59
EnumIterator_T::inequalityTest
unsigned inequalityTest()
Definition: EnumIterator_T.cpp:109
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
TestEnum1::One
@ One
EnumIterator_T::incrementTest
unsigned incrementTest()
Definition: EnumIterator_T.cpp:95
main
int main()
Definition: EnumIterator_T.cpp:143
EnumIterator_T::constructorTest
unsigned constructorTest()
Definition: EnumIterator_T.cpp:72
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
TestEnum1::Two
@ Two
TestUtil.hpp
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
TestEnum1::Three
@ Three
EnumIterator.hpp
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
std::operator<<
std::ostream & operator<<(std::ostream &s, gnsstk::StringUtils::FFLead v)
Definition: FormattedDouble_T.cpp:44
EnumIterator_T
Definition: EnumIterator_T.cpp:61
gnsstk::EnumIterator
Definition: EnumIterator.hpp:68
std
Definition: Angle.hpp:142
EnumIterator_T::beginEndTest
unsigned beginEndTest()
Definition: EnumIterator_T.cpp:122
TestEnum1::Four
@ Four
TestEnum1
TestEnum1
Definition: EnumIterator_T.cpp:45
TestEnum1::Five
@ Five


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39