mirror of
https://github.com/google/pebble.git
synced 2025-11-24 00:10:56 -05:00
Import of the watch repository from Pebble
This commit is contained in:
28
third_party/nanopb/tests/cxx_descriptor/SConscript
vendored
Normal file
28
third_party/nanopb/tests/cxx_descriptor/SConscript
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
# Test cxx descriptor functionality
|
||||
|
||||
Import('env')
|
||||
|
||||
base_env = env.Clone()
|
||||
base_env.Replace(NANOPBFLAGS = '--cpp-descriptor')
|
||||
base_env.NanopbProto('message')
|
||||
|
||||
for std in ["c++03", "c++11", "c++14", "c++17", "c++20"]:
|
||||
e = base_env.Clone()
|
||||
e.Append(CXXFLAGS = '-std={}'.format(std))
|
||||
|
||||
# Make sure compiler supports this version of C++ before we actually run the
|
||||
# test.
|
||||
conf = Configure(e)
|
||||
compiler_valid = conf.CheckCXX()
|
||||
e = conf.Finish()
|
||||
if not compiler_valid:
|
||||
print("Skipping {} test - compiler doesn't support it".format(std))
|
||||
continue
|
||||
|
||||
if std == 'c++03':
|
||||
e.Append(CPPDEFINES = {'PB_C99_STATIC_ASSERT': 1})
|
||||
|
||||
o1 = e.Object('message_descriptor_{}'.format(std), 'message_descriptor.cc')
|
||||
o2 = e.Object('message.pb_{}'.format(std), 'message.pb.c')
|
||||
p = e.Program([o1, o2])
|
||||
e.RunTest(p)
|
||||
12
third_party/nanopb/tests/cxx_descriptor/message.proto
vendored
Normal file
12
third_party/nanopb/tests/cxx_descriptor/message.proto
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
/* Test CPP descriptor generation */
|
||||
|
||||
syntax = "proto2";
|
||||
|
||||
import "nanopb.proto";
|
||||
|
||||
message MyEmptyMessage {
|
||||
}
|
||||
|
||||
message MyNonEmptyMessage {
|
||||
optional uint32 field = 1;
|
||||
}
|
||||
29
third_party/nanopb/tests/cxx_descriptor/message_descriptor.cc
vendored
Normal file
29
third_party/nanopb/tests/cxx_descriptor/message_descriptor.cc
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#include <stdio.h>
|
||||
#include "message.pb.h"
|
||||
#include "unittests.h"
|
||||
|
||||
extern "C" int main() {
|
||||
using namespace nanopb;
|
||||
|
||||
#if __cplusplus >= 201103L
|
||||
static_assert(MessageDescriptor<MyEmptyMessage>::fields_array_length == 0,
|
||||
"Unexpected field length");
|
||||
static_assert(MessageDescriptor<MyNonEmptyMessage>::fields_array_length == 1,
|
||||
"Unexpected field length");
|
||||
#endif // C++11 & newer
|
||||
|
||||
int status = 0;
|
||||
|
||||
TEST(MessageDescriptor<MyEmptyMessage>::fields_array_length ==
|
||||
MyEmptyMessage_msg.field_count);
|
||||
TEST(MessageDescriptor<MyNonEmptyMessage>::fields_array_length ==
|
||||
MyNonEmptyMessage_msg.field_count);
|
||||
|
||||
TEST(MessageDescriptor<MyEmptyMessage>::fields() == MyEmptyMessage_fields);
|
||||
TEST(MessageDescriptor<MyNonEmptyMessage>::fields() ==
|
||||
MyNonEmptyMessage_fields);
|
||||
|
||||
if (status != 0) fprintf(stdout, "\n\nSome tests FAILED!\n");
|
||||
|
||||
return status;
|
||||
}
|
||||
Reference in New Issue
Block a user