1 // Copyright 2019 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include "runtime/cpp/emboss_constant_view.h"
16
17 #include "gtest/gtest.h"
18
19 namespace emboss {
20 namespace support {
21 namespace test {
22
TEST(MaybeConstantViewTest,Read)23 TEST(MaybeConstantViewTest, Read) {
24 EXPECT_EQ(7, MaybeConstantView</**/ ::std::uint8_t>(7).Read());
25 #if EMBOSS_CHECK_ABORTS
26 EXPECT_DEATH(MaybeConstantView</**/ ::std::uint8_t>().Read(), "Known\\(\\)");
27 #endif // EMBOSS_CHECK_ABORTS
28 }
29
TEST(MaybeConstantViewTest,UncheckedRead)30 TEST(MaybeConstantViewTest, UncheckedRead) {
31 EXPECT_EQ(7, MaybeConstantView</**/ ::std::uint8_t>(7).UncheckedRead());
32 EXPECT_EQ(0, MaybeConstantView</**/ ::std::uint8_t>().UncheckedRead());
33 }
34
TEST(MaybeConstantViewTest,Ok)35 TEST(MaybeConstantViewTest, Ok) {
36 EXPECT_TRUE(MaybeConstantView</**/ ::std::uint8_t>(7).Ok());
37 EXPECT_FALSE(MaybeConstantView</**/ ::std::uint8_t>().Ok());
38 }
39
TEST(MaybeConstantViewTest,CopyConstruction)40 TEST(MaybeConstantViewTest, CopyConstruction) {
41 auto with_value = MaybeConstantView</**/ ::std::uint8_t>(7);
42 auto copied_with_value = with_value;
43 EXPECT_EQ(7, copied_with_value.Read());
44
45 auto without_value = MaybeConstantView</**/ ::std::uint8_t>();
46 auto copied_without_value = without_value;
47 EXPECT_FALSE(copied_without_value.Ok());
48 }
49
TEST(MaybeConstantViewTest,Assignment)50 TEST(MaybeConstantViewTest, Assignment) {
51 auto with_value = MaybeConstantView</**/ ::std::uint8_t>(7);
52 MaybeConstantView</**/ ::std::uint8_t> copied_with_value;
53 copied_with_value = with_value;
54 EXPECT_EQ(7, copied_with_value.Read());
55
56 auto without_value = MaybeConstantView</**/ ::std::uint8_t>();
57 MaybeConstantView</**/ ::std::uint8_t> copied_without_value;
58 copied_without_value = without_value;
59 EXPECT_FALSE(copied_without_value.Ok());
60 }
61
62 } // namespace test
63 } // namespace support
64 } // namespace emboss
65