• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2025 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 <string>
16 
17 #if !defined(PW_PROTOBUF_COMPILER_IMPORT)
18 #error "This test requires specifying a value for PW_PROTOBUF_COMPILER_IMPORT!"
19 #endif
20 
21 #define DEFAULT 1
22 #define STRIP_IMPORT_PREFIX 2
23 #define IMPORT_PREFIX 3
24 
25 #if PW_PROTOBUF_COMPILER_IMPORT == DEFAULT
26 #include "pw_protobuf_compiler/nanopb_test_protos/prefix_tests.pb.h"
27 #endif
28 
29 #if PW_PROTOBUF_COMPILER_IMPORT == STRIP_IMPORT_PREFIX
30 #include "prefix_tests.pb.h"
31 #endif
32 
33 #if PW_PROTOBUF_COMPILER_IMPORT == IMPORT_PREFIX
34 #include "some_prefix/prefix_tests.pb.h"
35 #endif
36 
37 #include "pw_status/status.h"
38 #include "pw_string/util.h"
39 #include "pw_unit_test/framework.h"
40 
41 namespace pw::protobuf_compiler {
42 namespace {
43 
TEST(PrefixTest,Compiles)44 TEST(PrefixTest, Compiles) {
45   std::string str = "abcd";
46   prefixtest_Message proto = prefixtest_Message_init_default;
47   EXPECT_EQ(
48       pw::string::Copy(str.c_str(), proto.name, sizeof(proto.name)).status(),
49       pw::OkStatus());
50 }
51 
52 }  // namespace
53 }  // namespace pw::protobuf_compiler
54