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 "pw_protobuf_compiler/pwpb_test_protos/pwpb_test.pwpb.h"
16 #include "pw_string/string.h"
17 #include "pw_unit_test/framework.h"
18
19 namespace pw::protobuf_compiler {
20 namespace {
21
TEST(Pwpb,CompilesProtobufs)22 TEST(Pwpb, CompilesProtobufs) {
23 pwpb_test_protos::pwpb::Point::Message point = {4, 8, "point"};
24 EXPECT_EQ(point.x, 4u);
25 EXPECT_EQ(point.y, 8u);
26 EXPECT_EQ(point.name.size(), 5u);
27 EXPECT_EQ(point.name, "point");
28 }
29
TEST(Pwpb,OptionsFilesAreApplied)30 TEST(Pwpb, OptionsFilesAreApplied) {
31 pwpb_test_protos::pwpb::OptionsFileExample::Message string_options_comparison;
32
33 static_assert(
34 std::is_same_v<decltype(string_options_comparison.thirty_two_chars),
35 pw::InlineString<32>>,
36 "Field `thirty_two_chars` should be a `pw::InlineString<32>`.");
37
38 static_assert(
39 std::is_same_v<decltype(string_options_comparison.forty_two_chars),
40 pw::InlineString<42>>,
41 "Field `forty_two_chars` should be a `pw::InlineString<42>`.");
42
43 static_assert(
44 std::is_same_v<
45 decltype(string_options_comparison.unspecified_length),
46 pw::protobuf::Callback<
47 pwpb_test_protos::pwpb::OptionsFileExample::StreamEncoder,
48 pwpb_test_protos::pwpb::OptionsFileExample::StreamDecoder>>,
49 "The field `unspecified_length` should be a `pw::protobuf::Callback`.");
50 }
51
TEST(Pwpb,InlineOptionsAppliedAndOverridden)52 TEST(Pwpb, InlineOptionsAppliedAndOverridden) {
53 pw::protobuf_compiler::pwpb_test_protos::pwpb::InlineOptionsExample::Message
54 inline_options_example;
55
56 static_assert(
57 std::is_same_v<decltype(inline_options_example.ten_chars_inline),
58 pw::InlineString<10>>,
59 "Field `ten_chars_inline` should be a `pw::InlineString<10>`.");
60 }
61
62 } // namespace
63 } // namespace pw::protobuf_compiler
64