xref: /aosp_15_r20/external/pigweed/pw_protobuf_compiler/pwpb_test.cc (revision 61c4878ac05f98d0ceed94b57d316916de578985)
1*61c4878aSAndroid Build Coastguard Worker // Copyright 2022 The Pigweed Authors
2*61c4878aSAndroid Build Coastguard Worker //
3*61c4878aSAndroid Build Coastguard Worker // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4*61c4878aSAndroid Build Coastguard Worker // use this file except in compliance with the License. You may obtain a copy of
5*61c4878aSAndroid Build Coastguard Worker // the License at
6*61c4878aSAndroid Build Coastguard Worker //
7*61c4878aSAndroid Build Coastguard Worker //     https://www.apache.org/licenses/LICENSE-2.0
8*61c4878aSAndroid Build Coastguard Worker //
9*61c4878aSAndroid Build Coastguard Worker // Unless required by applicable law or agreed to in writing, software
10*61c4878aSAndroid Build Coastguard Worker // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11*61c4878aSAndroid Build Coastguard Worker // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12*61c4878aSAndroid Build Coastguard Worker // License for the specific language governing permissions and limitations under
13*61c4878aSAndroid Build Coastguard Worker // the License.
14*61c4878aSAndroid Build Coastguard Worker 
15*61c4878aSAndroid Build Coastguard Worker #include "pw_protobuf_compiler/pwpb_test_protos/pwpb_test.pwpb.h"
16*61c4878aSAndroid Build Coastguard Worker #include "pw_string/string.h"
17*61c4878aSAndroid Build Coastguard Worker #include "pw_unit_test/framework.h"
18*61c4878aSAndroid Build Coastguard Worker 
19*61c4878aSAndroid Build Coastguard Worker namespace pw::protobuf_compiler {
20*61c4878aSAndroid Build Coastguard Worker namespace {
21*61c4878aSAndroid Build Coastguard Worker 
TEST(Pwpb,CompilesProtobufs)22*61c4878aSAndroid Build Coastguard Worker TEST(Pwpb, CompilesProtobufs) {
23*61c4878aSAndroid Build Coastguard Worker   pwpb_test_protos::pwpb::Point::Message point = {4, 8, "point"};
24*61c4878aSAndroid Build Coastguard Worker   EXPECT_EQ(point.x, 4u);
25*61c4878aSAndroid Build Coastguard Worker   EXPECT_EQ(point.y, 8u);
26*61c4878aSAndroid Build Coastguard Worker   EXPECT_EQ(point.name.size(), 5u);
27*61c4878aSAndroid Build Coastguard Worker   EXPECT_EQ(point.name, "point");
28*61c4878aSAndroid Build Coastguard Worker }
29*61c4878aSAndroid Build Coastguard Worker 
TEST(Pwpb,OptionsFilesAreApplied)30*61c4878aSAndroid Build Coastguard Worker TEST(Pwpb, OptionsFilesAreApplied) {
31*61c4878aSAndroid Build Coastguard Worker   pwpb_test_protos::pwpb::OptionsFileExample::Message string_options_comparison;
32*61c4878aSAndroid Build Coastguard Worker 
33*61c4878aSAndroid Build Coastguard Worker   static_assert(
34*61c4878aSAndroid Build Coastguard Worker       std::is_same_v<decltype(string_options_comparison.thirty_two_chars),
35*61c4878aSAndroid Build Coastguard Worker                      pw::InlineString<32>>,
36*61c4878aSAndroid Build Coastguard Worker       "Field `thirty_two_chars` should be a `pw::InlineString<32>`.");
37*61c4878aSAndroid Build Coastguard Worker 
38*61c4878aSAndroid Build Coastguard Worker   static_assert(
39*61c4878aSAndroid Build Coastguard Worker       std::is_same_v<decltype(string_options_comparison.forty_two_chars),
40*61c4878aSAndroid Build Coastguard Worker                      pw::InlineString<42>>,
41*61c4878aSAndroid Build Coastguard Worker       "Field `forty_two_chars` should be a `pw::InlineString<42>`.");
42*61c4878aSAndroid Build Coastguard Worker 
43*61c4878aSAndroid Build Coastguard Worker   static_assert(
44*61c4878aSAndroid Build Coastguard Worker       std::is_same_v<
45*61c4878aSAndroid Build Coastguard Worker           decltype(string_options_comparison.unspecified_length),
46*61c4878aSAndroid Build Coastguard Worker           pw::protobuf::Callback<
47*61c4878aSAndroid Build Coastguard Worker               pwpb_test_protos::pwpb::OptionsFileExample::StreamEncoder,
48*61c4878aSAndroid Build Coastguard Worker               pwpb_test_protos::pwpb::OptionsFileExample::StreamDecoder>>,
49*61c4878aSAndroid Build Coastguard Worker       "The field `unspecified_length` should be a `pw::protobuf::Callback`.");
50*61c4878aSAndroid Build Coastguard Worker }
51*61c4878aSAndroid Build Coastguard Worker 
TEST(Pwpb,InlineOptionsAppliedAndOverridden)52*61c4878aSAndroid Build Coastguard Worker TEST(Pwpb, InlineOptionsAppliedAndOverridden) {
53*61c4878aSAndroid Build Coastguard Worker   pw::protobuf_compiler::pwpb_test_protos::pwpb::InlineOptionsExample::Message
54*61c4878aSAndroid Build Coastguard Worker       inline_options_example;
55*61c4878aSAndroid Build Coastguard Worker 
56*61c4878aSAndroid Build Coastguard Worker   static_assert(
57*61c4878aSAndroid Build Coastguard Worker       std::is_same_v<decltype(inline_options_example.ten_chars_inline),
58*61c4878aSAndroid Build Coastguard Worker                      pw::InlineString<10>>,
59*61c4878aSAndroid Build Coastguard Worker       "Field `ten_chars_inline` should be a `pw::InlineString<10>`.");
60*61c4878aSAndroid Build Coastguard Worker }
61*61c4878aSAndroid Build Coastguard Worker 
62*61c4878aSAndroid Build Coastguard Worker }  // namespace
63*61c4878aSAndroid Build Coastguard Worker }  // namespace pw::protobuf_compiler
64