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 // Tests for the generated View class from subtypes.emb.
16 //
17 // These tests check that nested types work.
18 #include <stdint.h>
19
20 #include <vector>
21
22 #include "gtest/gtest.h"
23 #include "testdata/subtypes.emb.h"
24
25 namespace emboss {
26 namespace test {
27 namespace {
28
TEST(SubtypesTest,InnerEnumNames)29 TEST(SubtypesTest, InnerEnumNames) {
30 EXPECT_EQ(0, static_cast<int>(Out::In::InIn::InInIn::NO));
31 EXPECT_EQ(0, static_cast<int>(Out::In::InInView::InInIn::NO));
32 }
33
TEST(SubtypesTest,OuterStructure)34 TEST(SubtypesTest, OuterStructure) {
35 ::std::uint8_t buffer[OutWriter::SizeInBytes()] = {0};
36 auto view = OutWriter(buffer, sizeof buffer);
37 buffer[1] = 0xcc;
38 EXPECT_EQ(0xcc, view.in_1().in_in_1().in_2().field_byte().Read());
39 view.in_1().in_in_1().in_2().field_byte().Write(0x88);
40 EXPECT_EQ(0x88, buffer[1]);
41 buffer[static_cast<int>(Out::In::InIn::outer_offset())] = 0xff;
42 EXPECT_EQ(0xff, view.nested_constant_check().Read());
43 view.nested_constant_check().Write(0x77);
44 EXPECT_EQ(0x77, buffer[24]);
45
46 buffer[6] = 0x7;
47 buffer[7] = 0x8;
48 buffer[14] = 0x6;
49 buffer[22] = 0xee;
50 EXPECT_EQ(0xee, view.name_collision().Read());
51 EXPECT_EQ(0x7, view.in_1().name_collision().Read());
52 EXPECT_EQ(0x8, view.in_1().name_collision_check().Read());
53 EXPECT_EQ(0x6, view.in_2().name_collision().Read());
54 EXPECT_EQ(0x6, view.in_2().name_collision().Read());
55 }
56
57 } // namespace
58 } // namespace test
59 } // namespace emboss
60