1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program Tester Core
3 * ----------------------------------------
5 * Copyright 2015 The Android Open Source Project
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 * \brief Template class that is either type of Left or Right.
22 *//*--------------------------------------------------------------------*/
24 #include "tcuEither.hpp"
33 COPYCHECK_VALUE = 1637423219
36 class TestClassWithConstructor
39 TestClassWithConstructor (int i)
41 , m_copyCheck (COPYCHECK_VALUE)
45 ~TestClassWithConstructor (void)
47 DE_TEST_ASSERT(m_copyCheck == COPYCHECK_VALUE);
50 TestClassWithConstructor (const TestClassWithConstructor& other)
52 , m_copyCheck (other.m_copyCheck)
56 TestClassWithConstructor& operator= (const TestClassWithConstructor& other)
58 TCU_CHECK(m_copyCheck == COPYCHECK_VALUE);
64 m_copyCheck = other.m_copyCheck;
66 TCU_CHECK(m_copyCheck == COPYCHECK_VALUE);
71 int getValue (void) const
73 TCU_CHECK(m_copyCheck == COPYCHECK_VALUE);
85 void Either_selfTest (void)
87 // Simple test for first
89 const int intValue = 1503457782;
90 const Either<int, float> either (intValue);
92 TCU_CHECK(either.isFirst());
93 TCU_CHECK(!either.isSecond());
95 TCU_CHECK(either.is<int>());
96 TCU_CHECK(!either.is<float>());
98 TCU_CHECK(either.getFirst() == intValue);
99 TCU_CHECK(either.get<int>() == intValue);
102 // Simple test for second
104 const float floatValue = 0.43223332995f;
105 const Either<int, float> either (floatValue);
107 TCU_CHECK(!either.isFirst());
108 TCU_CHECK(either.isSecond());
110 TCU_CHECK(!either.is<int>());
111 TCU_CHECK(either.is<float>());
113 TCU_CHECK(either.getSecond() == floatValue);
114 TCU_CHECK(either.get<float>() == floatValue);
117 // Assign first value
119 const int intValue = 1942092699;
120 const float floatValue = 0.43223332995f;
121 Either<int, float> either (floatValue);
125 TCU_CHECK(either.isFirst());
126 TCU_CHECK(!either.isSecond());
128 TCU_CHECK(either.is<int>());
129 TCU_CHECK(!either.is<float>());
131 TCU_CHECK(either.getFirst() == intValue);
132 TCU_CHECK(either.get<int>() == intValue);
135 // Assign second value
137 const int intValue = 1942092699;
138 const float floatValue = 0.43223332995f;
139 Either<int, float> either (intValue);
143 TCU_CHECK(!either.isFirst());
144 TCU_CHECK(either.isSecond());
146 TCU_CHECK(!either.is<int>());
147 TCU_CHECK(either.is<float>());
149 TCU_CHECK(either.getSecond() == floatValue);
150 TCU_CHECK(either.get<float>() == floatValue);
153 // Assign first either value
155 const int intValue = 1942092699;
156 const float floatValue = 0.43223332995f;
157 Either<int, float> either (floatValue);
158 const Either<int, float> otherEither (intValue);
160 either = otherEither;
162 TCU_CHECK(either.isFirst());
163 TCU_CHECK(!either.isSecond());
165 TCU_CHECK(either.is<int>());
166 TCU_CHECK(!either.is<float>());
168 TCU_CHECK(either.getFirst() == intValue);
169 TCU_CHECK(either.get<int>() == intValue);
172 // Assign second either value
174 const int intValue = 1942092699;
175 const float floatValue = 0.43223332995f;
176 Either<int, float> either (intValue);
177 const Either<int, float> otherEither (floatValue);
179 either = otherEither;
181 TCU_CHECK(!either.isFirst());
182 TCU_CHECK(either.isSecond());
184 TCU_CHECK(!either.is<int>());
185 TCU_CHECK(either.is<float>());
187 TCU_CHECK(either.getSecond() == floatValue);
188 TCU_CHECK(either.get<float>() == floatValue);
191 // Simple test for first with constructor
193 const TestClassWithConstructor testObject (171899615);
194 const Either<TestClassWithConstructor, int> either (testObject);
196 TCU_CHECK(either.isFirst());
197 TCU_CHECK(!either.isSecond());
199 TCU_CHECK(either.is<TestClassWithConstructor>());
200 TCU_CHECK(!either.is<int>());
202 TCU_CHECK(either.getFirst().getValue() == testObject.getValue());
203 TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
206 // Simple test for second with constructor
208 const TestClassWithConstructor testObject (171899615);
209 const Either<int, TestClassWithConstructor> either (testObject);
211 TCU_CHECK(!either.isFirst());
212 TCU_CHECK(either.isSecond());
214 TCU_CHECK(either.is<TestClassWithConstructor>());
215 TCU_CHECK(!either.is<int>());
217 TCU_CHECK(either.getSecond().getValue() == testObject.getValue());
218 TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
221 // Assign first with constructor
223 const int intValue = 1942092699;
224 const TestClassWithConstructor testObject (171899615);
225 Either<TestClassWithConstructor, int> either (intValue);
229 TCU_CHECK(either.isFirst());
230 TCU_CHECK(!either.isSecond());
232 TCU_CHECK(either.is<TestClassWithConstructor>());
233 TCU_CHECK(!either.is<int>());
235 TCU_CHECK(either.getFirst().getValue() == testObject.getValue());
236 TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
239 // Assign second with constructor
241 const int intValue = 1942092699;
242 const TestClassWithConstructor testObject (171899615);
243 Either<int, TestClassWithConstructor> either (intValue);
247 TCU_CHECK(!either.isFirst());
248 TCU_CHECK(either.isSecond());
250 TCU_CHECK(either.is<TestClassWithConstructor>());
251 TCU_CHECK(!either.is<int>());
253 TCU_CHECK(either.getSecond().getValue() == testObject.getValue());
254 TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
257 // Assign first either with constructor
259 const int intValue = 1942092699;
260 const TestClassWithConstructor testObject (171899615);
261 Either<TestClassWithConstructor, int> either (intValue);
262 const Either<TestClassWithConstructor, int> otherEither (testObject);
264 either = otherEither;
266 TCU_CHECK(either.isFirst());
267 TCU_CHECK(!either.isSecond());
269 TCU_CHECK(either.is<TestClassWithConstructor>());
270 TCU_CHECK(!either.is<int>());
272 TCU_CHECK(either.getFirst().getValue() == testObject.getValue());
273 TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
276 // Assign second either with constructor
278 const int intValue = 1942092699;
279 const TestClassWithConstructor testObject (171899615);
280 Either<int, TestClassWithConstructor> either (intValue);
281 const Either<int, TestClassWithConstructor> otherEither (testObject);
283 either = otherEither;
285 TCU_CHECK(!either.isFirst());
286 TCU_CHECK(either.isSecond());
288 TCU_CHECK(either.is<TestClassWithConstructor>());
289 TCU_CHECK(!either.is<int>());
291 TCU_CHECK(either.getSecond().getValue() == testObject.getValue());
292 TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());