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