xref: /aosp_15_r20/external/pigweed/pw_protobuf_compiler/nested_packages_test.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1 // Copyright 2022 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // 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, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 #include "proto_root/aggregate.pwpb.h"
16 #include "proto_root/aggregate_wrapper.pwpb.h"
17 #include "proto_root/data_type/id/id.pwpb.h"
18 #include "proto_root/data_type/thing/thing.pwpb.h"
19 #include "proto_root/data_type/thing/type_of_thing.pwpb.h"
20 #include "pw_unit_test/framework.h"
21 
22 namespace pw::protobuf_compiler {
23 namespace {
24 
TEST(NestedPackages,CompilesProtobufs)25 TEST(NestedPackages, CompilesProtobufs) {
26   using Aggregate = proto_root::pwpb::Aggregate::Message;
27   using AggregateWrapper = proto_root::pwpb::AggregateWrapper::Message;
28   using Id = proto_root::data_type::id::pwpb::Id::Message;
29   using Thing = proto_root::data_type::thing::pwpb::Thing::Message;
30   using proto_root::data_type::thing::pwpb::TypeOfThing;
31 
32   AggregateWrapper wrapper = {
33       Id{0u, {1, 2}},
34       TypeOfThing::kOther,
35 
36       Aggregate{
37           Id{1u, {2, 3}},
38           TypeOfThing::kOther,
39 
40           Thing{Id{2u, {3, 4}}, TypeOfThing::kOrganism},
41           Thing{Id{3u, {4, 5}}, TypeOfThing::kSubstance},
42           Thing{Id{4u, {5, 6}}, TypeOfThing::kObject},
43       }};
44 
45   EXPECT_EQ(wrapper.id.id, 0u);
46   EXPECT_EQ(wrapper.id.impl.foo, 1);
47   EXPECT_EQ(wrapper.id.impl.bar, 2);
48   EXPECT_EQ(wrapper.type, TypeOfThing::kOther);
49 
50   EXPECT_EQ(wrapper.aggregate.id.id, 1u);
51   EXPECT_EQ(wrapper.aggregate.id.impl.foo, 2);
52   EXPECT_EQ(wrapper.aggregate.id.impl.bar, 3);
53   EXPECT_EQ(wrapper.aggregate.type, TypeOfThing::kOther);
54 
55   EXPECT_EQ(wrapper.aggregate.alice.id.id, 2u);
56   EXPECT_EQ(wrapper.aggregate.alice.id.impl.foo, 3);
57   EXPECT_EQ(wrapper.aggregate.alice.id.impl.bar, 4);
58   EXPECT_EQ(wrapper.aggregate.alice.type, TypeOfThing::kOrganism);
59 
60   EXPECT_EQ(wrapper.aggregate.neodymium.id.id, 3u);
61   EXPECT_EQ(wrapper.aggregate.neodymium.id.impl.foo, 4);
62   EXPECT_EQ(wrapper.aggregate.neodymium.id.impl.bar, 5);
63   EXPECT_EQ(wrapper.aggregate.neodymium.type, TypeOfThing::kSubstance);
64 
65   EXPECT_EQ(wrapper.aggregate.mountain.id.id, 4u);
66   EXPECT_EQ(wrapper.aggregate.mountain.id.impl.foo, 5);
67   EXPECT_EQ(wrapper.aggregate.mountain.id.impl.bar, 6);
68   EXPECT_EQ(wrapper.aggregate.mountain.type, TypeOfThing::kObject);
69 }
70 
71 }  // namespace
72 }  // namespace pw::protobuf_compiler
73