1*35238bceSAndroid Build Coastguard Worker /*-------------------------------------------------------------------------
2*35238bceSAndroid Build Coastguard Worker * drawElements Quality Program Tester Core
3*35238bceSAndroid Build Coastguard Worker * ----------------------------------------
4*35238bceSAndroid Build Coastguard Worker *
5*35238bceSAndroid Build Coastguard Worker * Copyright 2015 The Android Open Source Project
6*35238bceSAndroid Build Coastguard Worker *
7*35238bceSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
8*35238bceSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
9*35238bceSAndroid Build Coastguard Worker * You may obtain a copy of the License at
10*35238bceSAndroid Build Coastguard Worker *
11*35238bceSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
12*35238bceSAndroid Build Coastguard Worker *
13*35238bceSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
14*35238bceSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
15*35238bceSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16*35238bceSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
17*35238bceSAndroid Build Coastguard Worker * limitations under the License.
18*35238bceSAndroid Build Coastguard Worker *
19*35238bceSAndroid Build Coastguard Worker *//*!
20*35238bceSAndroid Build Coastguard Worker * \file
21*35238bceSAndroid Build Coastguard Worker * \brief Template class that is either type of Left or Right.
22*35238bceSAndroid Build Coastguard Worker *//*--------------------------------------------------------------------*/
23*35238bceSAndroid Build Coastguard Worker
24*35238bceSAndroid Build Coastguard Worker #include "tcuEither.hpp"
25*35238bceSAndroid Build Coastguard Worker
26*35238bceSAndroid Build Coastguard Worker namespace tcu
27*35238bceSAndroid Build Coastguard Worker {
28*35238bceSAndroid Build Coastguard Worker namespace
29*35238bceSAndroid Build Coastguard Worker {
30*35238bceSAndroid Build Coastguard Worker
31*35238bceSAndroid Build Coastguard Worker enum
32*35238bceSAndroid Build Coastguard Worker {
33*35238bceSAndroid Build Coastguard Worker COPYCHECK_VALUE = 1637423219
34*35238bceSAndroid Build Coastguard Worker };
35*35238bceSAndroid Build Coastguard Worker
36*35238bceSAndroid Build Coastguard Worker class TestClassWithConstructor
37*35238bceSAndroid Build Coastguard Worker {
38*35238bceSAndroid Build Coastguard Worker public:
TestClassWithConstructor(int i)39*35238bceSAndroid Build Coastguard Worker TestClassWithConstructor(int i) : m_i(i), m_copyCheck(COPYCHECK_VALUE)
40*35238bceSAndroid Build Coastguard Worker {
41*35238bceSAndroid Build Coastguard Worker }
42*35238bceSAndroid Build Coastguard Worker
~TestClassWithConstructor(void)43*35238bceSAndroid Build Coastguard Worker ~TestClassWithConstructor(void)
44*35238bceSAndroid Build Coastguard Worker {
45*35238bceSAndroid Build Coastguard Worker DE_TEST_ASSERT(m_copyCheck == COPYCHECK_VALUE);
46*35238bceSAndroid Build Coastguard Worker }
47*35238bceSAndroid Build Coastguard Worker
TestClassWithConstructor(const TestClassWithConstructor & other)48*35238bceSAndroid Build Coastguard Worker TestClassWithConstructor(const TestClassWithConstructor &other) : m_i(other.m_i), m_copyCheck(other.m_copyCheck)
49*35238bceSAndroid Build Coastguard Worker {
50*35238bceSAndroid Build Coastguard Worker }
51*35238bceSAndroid Build Coastguard Worker
operator =(const TestClassWithConstructor & other)52*35238bceSAndroid Build Coastguard Worker TestClassWithConstructor &operator=(const TestClassWithConstructor &other)
53*35238bceSAndroid Build Coastguard Worker {
54*35238bceSAndroid Build Coastguard Worker TCU_CHECK(m_copyCheck == COPYCHECK_VALUE);
55*35238bceSAndroid Build Coastguard Worker
56*35238bceSAndroid Build Coastguard Worker if (this == &other)
57*35238bceSAndroid Build Coastguard Worker return *this;
58*35238bceSAndroid Build Coastguard Worker
59*35238bceSAndroid Build Coastguard Worker m_i = other.m_i;
60*35238bceSAndroid Build Coastguard Worker m_copyCheck = other.m_copyCheck;
61*35238bceSAndroid Build Coastguard Worker
62*35238bceSAndroid Build Coastguard Worker TCU_CHECK(m_copyCheck == COPYCHECK_VALUE);
63*35238bceSAndroid Build Coastguard Worker
64*35238bceSAndroid Build Coastguard Worker return *this;
65*35238bceSAndroid Build Coastguard Worker }
66*35238bceSAndroid Build Coastguard Worker
getValue(void) const67*35238bceSAndroid Build Coastguard Worker int getValue(void) const
68*35238bceSAndroid Build Coastguard Worker {
69*35238bceSAndroid Build Coastguard Worker TCU_CHECK(m_copyCheck == COPYCHECK_VALUE);
70*35238bceSAndroid Build Coastguard Worker
71*35238bceSAndroid Build Coastguard Worker return m_i;
72*35238bceSAndroid Build Coastguard Worker }
73*35238bceSAndroid Build Coastguard Worker
74*35238bceSAndroid Build Coastguard Worker private:
75*35238bceSAndroid Build Coastguard Worker int m_i;
76*35238bceSAndroid Build Coastguard Worker int m_copyCheck;
77*35238bceSAndroid Build Coastguard Worker };
78*35238bceSAndroid Build Coastguard Worker
79*35238bceSAndroid Build Coastguard Worker } // namespace
80*35238bceSAndroid Build Coastguard Worker
Either_selfTest(void)81*35238bceSAndroid Build Coastguard Worker void Either_selfTest(void)
82*35238bceSAndroid Build Coastguard Worker {
83*35238bceSAndroid Build Coastguard Worker // Simple test for first
84*35238bceSAndroid Build Coastguard Worker {
85*35238bceSAndroid Build Coastguard Worker const int intValue = 1503457782;
86*35238bceSAndroid Build Coastguard Worker const Either<int, float> either(intValue);
87*35238bceSAndroid Build Coastguard Worker
88*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isFirst());
89*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isSecond());
90*35238bceSAndroid Build Coastguard Worker
91*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<int>());
92*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<float>());
93*35238bceSAndroid Build Coastguard Worker
94*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getFirst() == intValue);
95*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<int>() == intValue);
96*35238bceSAndroid Build Coastguard Worker }
97*35238bceSAndroid Build Coastguard Worker
98*35238bceSAndroid Build Coastguard Worker // Simple test for second
99*35238bceSAndroid Build Coastguard Worker {
100*35238bceSAndroid Build Coastguard Worker const float floatValue = 0.43223332995f;
101*35238bceSAndroid Build Coastguard Worker const Either<int, float> either(floatValue);
102*35238bceSAndroid Build Coastguard Worker
103*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isFirst());
104*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isSecond());
105*35238bceSAndroid Build Coastguard Worker
106*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<int>());
107*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<float>());
108*35238bceSAndroid Build Coastguard Worker
109*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getSecond() == floatValue);
110*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<float>() == floatValue);
111*35238bceSAndroid Build Coastguard Worker }
112*35238bceSAndroid Build Coastguard Worker
113*35238bceSAndroid Build Coastguard Worker // Assign first value
114*35238bceSAndroid Build Coastguard Worker {
115*35238bceSAndroid Build Coastguard Worker const int intValue = 1942092699;
116*35238bceSAndroid Build Coastguard Worker const float floatValue = 0.43223332995f;
117*35238bceSAndroid Build Coastguard Worker Either<int, float> either(floatValue);
118*35238bceSAndroid Build Coastguard Worker
119*35238bceSAndroid Build Coastguard Worker either = intValue;
120*35238bceSAndroid Build Coastguard Worker
121*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isFirst());
122*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isSecond());
123*35238bceSAndroid Build Coastguard Worker
124*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<int>());
125*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<float>());
126*35238bceSAndroid Build Coastguard Worker
127*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getFirst() == intValue);
128*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<int>() == intValue);
129*35238bceSAndroid Build Coastguard Worker }
130*35238bceSAndroid Build Coastguard Worker
131*35238bceSAndroid Build Coastguard Worker // Assign second value
132*35238bceSAndroid Build Coastguard Worker {
133*35238bceSAndroid Build Coastguard Worker const int intValue = 1942092699;
134*35238bceSAndroid Build Coastguard Worker const float floatValue = 0.43223332995f;
135*35238bceSAndroid Build Coastguard Worker Either<int, float> either(intValue);
136*35238bceSAndroid Build Coastguard Worker
137*35238bceSAndroid Build Coastguard Worker either = floatValue;
138*35238bceSAndroid Build Coastguard Worker
139*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isFirst());
140*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isSecond());
141*35238bceSAndroid Build Coastguard Worker
142*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<int>());
143*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<float>());
144*35238bceSAndroid Build Coastguard Worker
145*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getSecond() == floatValue);
146*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<float>() == floatValue);
147*35238bceSAndroid Build Coastguard Worker }
148*35238bceSAndroid Build Coastguard Worker
149*35238bceSAndroid Build Coastguard Worker // Assign first either value
150*35238bceSAndroid Build Coastguard Worker {
151*35238bceSAndroid Build Coastguard Worker const int intValue = 1942092699;
152*35238bceSAndroid Build Coastguard Worker const float floatValue = 0.43223332995f;
153*35238bceSAndroid Build Coastguard Worker Either<int, float> either(floatValue);
154*35238bceSAndroid Build Coastguard Worker const Either<int, float> otherEither(intValue);
155*35238bceSAndroid Build Coastguard Worker
156*35238bceSAndroid Build Coastguard Worker either = otherEither;
157*35238bceSAndroid Build Coastguard Worker
158*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isFirst());
159*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isSecond());
160*35238bceSAndroid Build Coastguard Worker
161*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<int>());
162*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<float>());
163*35238bceSAndroid Build Coastguard Worker
164*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getFirst() == intValue);
165*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<int>() == intValue);
166*35238bceSAndroid Build Coastguard Worker }
167*35238bceSAndroid Build Coastguard Worker
168*35238bceSAndroid Build Coastguard Worker // Assign second either value
169*35238bceSAndroid Build Coastguard Worker {
170*35238bceSAndroid Build Coastguard Worker const int intValue = 1942092699;
171*35238bceSAndroid Build Coastguard Worker const float floatValue = 0.43223332995f;
172*35238bceSAndroid Build Coastguard Worker Either<int, float> either(intValue);
173*35238bceSAndroid Build Coastguard Worker const Either<int, float> otherEither(floatValue);
174*35238bceSAndroid Build Coastguard Worker
175*35238bceSAndroid Build Coastguard Worker either = otherEither;
176*35238bceSAndroid Build Coastguard Worker
177*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isFirst());
178*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isSecond());
179*35238bceSAndroid Build Coastguard Worker
180*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<int>());
181*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<float>());
182*35238bceSAndroid Build Coastguard Worker
183*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getSecond() == floatValue);
184*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<float>() == floatValue);
185*35238bceSAndroid Build Coastguard Worker }
186*35238bceSAndroid Build Coastguard Worker
187*35238bceSAndroid Build Coastguard Worker // Simple test for first with constructor
188*35238bceSAndroid Build Coastguard Worker {
189*35238bceSAndroid Build Coastguard Worker const TestClassWithConstructor testObject(171899615);
190*35238bceSAndroid Build Coastguard Worker const Either<TestClassWithConstructor, int> either(testObject);
191*35238bceSAndroid Build Coastguard Worker
192*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isFirst());
193*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isSecond());
194*35238bceSAndroid Build Coastguard Worker
195*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<TestClassWithConstructor>());
196*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<int>());
197*35238bceSAndroid Build Coastguard Worker
198*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getFirst().getValue() == testObject.getValue());
199*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
200*35238bceSAndroid Build Coastguard Worker }
201*35238bceSAndroid Build Coastguard Worker
202*35238bceSAndroid Build Coastguard Worker // Simple test for second with constructor
203*35238bceSAndroid Build Coastguard Worker {
204*35238bceSAndroid Build Coastguard Worker const TestClassWithConstructor testObject(171899615);
205*35238bceSAndroid Build Coastguard Worker const Either<int, TestClassWithConstructor> either(testObject);
206*35238bceSAndroid Build Coastguard Worker
207*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isFirst());
208*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isSecond());
209*35238bceSAndroid Build Coastguard Worker
210*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<TestClassWithConstructor>());
211*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<int>());
212*35238bceSAndroid Build Coastguard Worker
213*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getSecond().getValue() == testObject.getValue());
214*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
215*35238bceSAndroid Build Coastguard Worker }
216*35238bceSAndroid Build Coastguard Worker
217*35238bceSAndroid Build Coastguard Worker // Assign first with constructor
218*35238bceSAndroid Build Coastguard Worker {
219*35238bceSAndroid Build Coastguard Worker const int intValue = 1942092699;
220*35238bceSAndroid Build Coastguard Worker const TestClassWithConstructor testObject(171899615);
221*35238bceSAndroid Build Coastguard Worker Either<TestClassWithConstructor, int> either(intValue);
222*35238bceSAndroid Build Coastguard Worker
223*35238bceSAndroid Build Coastguard Worker either = testObject;
224*35238bceSAndroid Build Coastguard Worker
225*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isFirst());
226*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isSecond());
227*35238bceSAndroid Build Coastguard Worker
228*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<TestClassWithConstructor>());
229*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<int>());
230*35238bceSAndroid Build Coastguard Worker
231*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getFirst().getValue() == testObject.getValue());
232*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
233*35238bceSAndroid Build Coastguard Worker }
234*35238bceSAndroid Build Coastguard Worker
235*35238bceSAndroid Build Coastguard Worker // Assign second with constructor
236*35238bceSAndroid Build Coastguard Worker {
237*35238bceSAndroid Build Coastguard Worker const int intValue = 1942092699;
238*35238bceSAndroid Build Coastguard Worker const TestClassWithConstructor testObject(171899615);
239*35238bceSAndroid Build Coastguard Worker Either<int, TestClassWithConstructor> either(intValue);
240*35238bceSAndroid Build Coastguard Worker
241*35238bceSAndroid Build Coastguard Worker either = testObject;
242*35238bceSAndroid Build Coastguard Worker
243*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isFirst());
244*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isSecond());
245*35238bceSAndroid Build Coastguard Worker
246*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<TestClassWithConstructor>());
247*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<int>());
248*35238bceSAndroid Build Coastguard Worker
249*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getSecond().getValue() == testObject.getValue());
250*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
251*35238bceSAndroid Build Coastguard Worker }
252*35238bceSAndroid Build Coastguard Worker
253*35238bceSAndroid Build Coastguard Worker // Assign first either with constructor
254*35238bceSAndroid Build Coastguard Worker {
255*35238bceSAndroid Build Coastguard Worker const int intValue = 1942092699;
256*35238bceSAndroid Build Coastguard Worker const TestClassWithConstructor testObject(171899615);
257*35238bceSAndroid Build Coastguard Worker Either<TestClassWithConstructor, int> either(intValue);
258*35238bceSAndroid Build Coastguard Worker const Either<TestClassWithConstructor, int> otherEither(testObject);
259*35238bceSAndroid Build Coastguard Worker
260*35238bceSAndroid Build Coastguard Worker either = otherEither;
261*35238bceSAndroid Build Coastguard Worker
262*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isFirst());
263*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isSecond());
264*35238bceSAndroid Build Coastguard Worker
265*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<TestClassWithConstructor>());
266*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<int>());
267*35238bceSAndroid Build Coastguard Worker
268*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getFirst().getValue() == testObject.getValue());
269*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
270*35238bceSAndroid Build Coastguard Worker }
271*35238bceSAndroid Build Coastguard Worker
272*35238bceSAndroid Build Coastguard Worker // Assign second either with constructor
273*35238bceSAndroid Build Coastguard Worker {
274*35238bceSAndroid Build Coastguard Worker const int intValue = 1942092699;
275*35238bceSAndroid Build Coastguard Worker const TestClassWithConstructor testObject(171899615);
276*35238bceSAndroid Build Coastguard Worker Either<int, TestClassWithConstructor> either(intValue);
277*35238bceSAndroid Build Coastguard Worker const Either<int, TestClassWithConstructor> otherEither(testObject);
278*35238bceSAndroid Build Coastguard Worker
279*35238bceSAndroid Build Coastguard Worker either = otherEither;
280*35238bceSAndroid Build Coastguard Worker
281*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.isFirst());
282*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.isSecond());
283*35238bceSAndroid Build Coastguard Worker
284*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.is<TestClassWithConstructor>());
285*35238bceSAndroid Build Coastguard Worker TCU_CHECK(!either.is<int>());
286*35238bceSAndroid Build Coastguard Worker
287*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.getSecond().getValue() == testObject.getValue());
288*35238bceSAndroid Build Coastguard Worker TCU_CHECK(either.get<TestClassWithConstructor>().getValue() == testObject.getValue());
289*35238bceSAndroid Build Coastguard Worker }
290*35238bceSAndroid Build Coastguard Worker }
291*35238bceSAndroid Build Coastguard Worker
292*35238bceSAndroid Build Coastguard Worker } // namespace tcu
293