xref: /aosp_15_r20/external/angle/src/common/Optional_unittest.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1*8975f5c5SAndroid Build Coastguard Worker //
2*8975f5c5SAndroid Build Coastguard Worker // Copyright 2015 The ANGLE Project Authors. All rights reserved.
3*8975f5c5SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
4*8975f5c5SAndroid Build Coastguard Worker // found in the LICENSE file.
5*8975f5c5SAndroid Build Coastguard Worker //
6*8975f5c5SAndroid Build Coastguard Worker // Unit tests for ANGLE's Optional helper class.
7*8975f5c5SAndroid Build Coastguard Worker //
8*8975f5c5SAndroid Build Coastguard Worker 
9*8975f5c5SAndroid Build Coastguard Worker #include "gmock/gmock.h"
10*8975f5c5SAndroid Build Coastguard Worker #include "gtest/gtest.h"
11*8975f5c5SAndroid Build Coastguard Worker 
12*8975f5c5SAndroid Build Coastguard Worker #include "common/Optional.h"
13*8975f5c5SAndroid Build Coastguard Worker 
14*8975f5c5SAndroid Build Coastguard Worker namespace
15*8975f5c5SAndroid Build Coastguard Worker {
16*8975f5c5SAndroid Build Coastguard Worker 
TEST(OptionalTest,BasicInvalid)17*8975f5c5SAndroid Build Coastguard Worker TEST(OptionalTest, BasicInvalid)
18*8975f5c5SAndroid Build Coastguard Worker {
19*8975f5c5SAndroid Build Coastguard Worker     Optional<int> testInvalid;
20*8975f5c5SAndroid Build Coastguard Worker     ASSERT_FALSE(testInvalid.valid());
21*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(Optional<int>::Invalid(), testInvalid);
22*8975f5c5SAndroid Build Coastguard Worker }
23*8975f5c5SAndroid Build Coastguard Worker 
TEST(OptionalTest,BasicValid)24*8975f5c5SAndroid Build Coastguard Worker TEST(OptionalTest, BasicValid)
25*8975f5c5SAndroid Build Coastguard Worker {
26*8975f5c5SAndroid Build Coastguard Worker     Optional<int> testValid(3);
27*8975f5c5SAndroid Build Coastguard Worker     ASSERT_TRUE(testValid.valid());
28*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(3, testValid.value());
29*8975f5c5SAndroid Build Coastguard Worker     ASSERT_NE(Optional<int>::Invalid(), testValid);
30*8975f5c5SAndroid Build Coastguard Worker }
31*8975f5c5SAndroid Build Coastguard Worker 
TEST(OptionalTest,Copies)32*8975f5c5SAndroid Build Coastguard Worker TEST(OptionalTest, Copies)
33*8975f5c5SAndroid Build Coastguard Worker {
34*8975f5c5SAndroid Build Coastguard Worker     Optional<int> testValid(3);
35*8975f5c5SAndroid Build Coastguard Worker     Optional<int> testInvalid;
36*8975f5c5SAndroid Build Coastguard Worker 
37*8975f5c5SAndroid Build Coastguard Worker     Optional<int> testCopy = testInvalid;
38*8975f5c5SAndroid Build Coastguard Worker     ASSERT_FALSE(testCopy.valid());
39*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(testInvalid, testCopy);
40*8975f5c5SAndroid Build Coastguard Worker 
41*8975f5c5SAndroid Build Coastguard Worker     testCopy = testValid;
42*8975f5c5SAndroid Build Coastguard Worker     ASSERT_TRUE(testCopy.valid());
43*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(3, testCopy.value());
44*8975f5c5SAndroid Build Coastguard Worker     ASSERT_EQ(testValid, testCopy);
45*8975f5c5SAndroid Build Coastguard Worker }
46*8975f5c5SAndroid Build Coastguard Worker 
47*8975f5c5SAndroid Build Coastguard Worker }  // namespace
48