astrotypes  0.0
OptionalTest.cpp
Go to the documentation of this file.
1 /*
2  * MIT License
3  *
4  * Copyright (c) 2018 PulsarSearchSoft
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all
14  * copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
26 
27 
28 namespace pss {
29 namespace astrotypes {
30 namespace utils {
31 namespace test {
32 
33 
35  : ::testing::Test()
36 {
37 }
38 
40 {
41 }
42 
44 {
45 }
46 
48 {
49 }
50 
51 TEST_F(OptionalTest, test_int)
52 {
53  Optional<int> opt;
54  if(opt.is_set()) {
55  FAIL() << "expected to be marked unset";
56  }
57 
58  opt = 10;
59  ASSERT_TRUE(opt.is_set());
60  ASSERT_EQ(opt, 10);
61  ASSERT_NE(opt, 11);
62 
63  // test operator*
64  ASSERT_EQ(*opt, 10);
65 
66  // test reset
67  opt.reset();
68  ASSERT_FALSE(opt.is_set());
69 }
70 
71 TEST_F(OptionalTest, test_const_int)
72 {
73  const Optional<int> const_opt(100);
74  ASSERT_TRUE(const_opt.is_set());
75  ASSERT_EQ(*const_opt, 100);
76  ASSERT_EQ(const_opt, 100);
77  ASSERT_NE(const_opt, 11);
78 }
79 
80 TEST_F(OptionalTest, test_const_bool)
81 {
82  const Optional<bool> const_opt(true);
83  ASSERT_TRUE(const_opt.is_set());
84  ASSERT_TRUE(const_opt);
85  ASSERT_EQ(const_opt, true);
86  ASSERT_NE(const_opt, false);
87 
88  Optional<bool> false_opt(false);
89  ASSERT_TRUE(false_opt.is_set());
90  ASSERT_FALSE(false_opt);
91  ASSERT_NE(false_opt, true);
92  ASSERT_EQ(false_opt, false);
93  false_opt.reset();
94  ASSERT_FALSE(false_opt.is_set());
95 }
96 
97 } // namespace test
98 } // namespace utils
99 } // namespace astrotypes
100 } // namespace pss
TEST_F(OptionalTest, test_int)
void reset()
return to unset state
Definition: Optional.cpp:101
specialisation for bool
Definition: Optional.h:87
A simplified, faster, but less secure and less versatile version of boost::optional.
Definition: Optional.h:38
void reset()
return to unset state
Definition: Optional.cpp:150
bool is_set() const
if the value has been explicitly set then return true
Definition: Optional.cpp:122
bool is_set() const
if the value has been explicitly set then return true
Definition: Optional.cpp:56