• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gtest/gtest.h"
16 #include "pw_protobuf_compiler_pwpb_protos/pwpb_test.pwpb.h"
17 #include "pw_string/string.h"
18 
19 namespace pw::protobuf_compiler {
20 namespace {
21 
TEST(Pwpb,CompilesProtobufs)22 TEST(Pwpb, CompilesProtobufs) {
23   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::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<pwpb::OptionsFileExample::StreamEncoder,
47                                  pwpb::OptionsFileExample::StreamDecoder>>,
48       "The field `unspecified_length` should be a `pw::protobuf::Callback`.");
49 }
50 
TEST(Pwpb,InlineOptionsAppliedAndOverridden)51 TEST(Pwpb, InlineOptionsAppliedAndOverridden) {
52   pw::protobuf_compiler::InlineOptionsExample::Message inline_options_example;
53 
54   static_assert(
55       std::is_same_v<decltype(inline_options_example.ten_chars_inline),
56                      pw::InlineString<10>>,
57       "Field `ten_chars_inline` should be a `pw::InlineString<10>`.");
58 }
59 
60 }  // namespace
61 }  // namespace pw::protobuf_compiler
62