summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/conformance_upb.c28
-rw-r--r--tests/json/enum_from_separate_file.proto9
-rw-r--r--tests/json/test.proto5
-rw-r--r--tests/json/test.proto.pbbin1883 -> 1958 bytes
-rw-r--r--tests/json/test_json.cc1
-rw-r--r--tests/pb/test_encoder.cc34
-rw-r--r--tests/test_cpp.cc5
7 files changed, 34 insertions, 48 deletions
diff --git a/tests/conformance_upb.c b/tests/conformance_upb.c
index 782346f..36e550e 100644
--- a/tests/conformance_upb.c
+++ b/tests/conformance_upb.c
@@ -75,21 +75,16 @@ void DoTest(
break;
}
- case conformance_ConformanceRequest_payload_json_payload: {
- static const char msg[] = "JSON support not yet implemented.";
- conformance_ConformanceResponse_set_skipped(
- response, upb_strview_make(msg, sizeof(msg)));
- return;
- }
-
case conformance_ConformanceRequest_payload_NOT_SET:
fprintf(stderr, "conformance_upb: Request didn't have payload.\n");
return;
- default:
- fprintf(stderr, "conformance_upb: Unexpected case: %d\n",
- conformance_ConformanceRequest_payload_case(request));
- exit(1);
+ default: {
+ static const char msg[] = "Unsupported input format.";
+ conformance_ConformanceResponse_set_skipped(
+ response, upb_strview_make(msg, sizeof(msg)));
+ return;
+ }
}
switch (conformance_ConformanceRequest_requested_output_format(request)) {
@@ -113,17 +108,12 @@ void DoTest(
break;
}
- case conformance_JSON: {
- static const char msg[] = "JSON support not yet implemented.";
+ default: {
+ static const char msg[] = "Unsupported output format.";
conformance_ConformanceResponse_set_skipped(
response, upb_strview_make(msg, sizeof(msg)));
- break;
+ return;
}
-
- default:
- fprintf(stderr, "conformance_upb: Unknown output format: %d\n",
- conformance_ConformanceRequest_requested_output_format(request));
- exit(1);
}
return;
diff --git a/tests/json/enum_from_separate_file.proto b/tests/json/enum_from_separate_file.proto
new file mode 100644
index 0000000..ceb9b42
--- /dev/null
+++ b/tests/json/enum_from_separate_file.proto
@@ -0,0 +1,9 @@
+syntax = "proto2";
+
+import "tests/json/test.proto";
+
+package upb.test.json;
+
+message ImportEnum {
+ optional MyEnum e = 1;
+}
diff --git a/tests/json/test.proto b/tests/json/test.proto
index e659001..2db0388 100644
--- a/tests/json/test.proto
+++ b/tests/json/test.proto
@@ -29,6 +29,11 @@ message TestMessage {
map<string, int32> map_string_int32 = 23;
map<string, bool> map_string_bool = 24;
map<string, SubMessage> map_string_msg = 25;
+
+ oneof o {
+ int32 oneof_int32 = 26;
+ int64 oneof_int64 = 27;
+ }
}
message SubMessage {
diff --git a/tests/json/test.proto.pb b/tests/json/test.proto.pb
index 5da355d..94b8b92 100644
--- a/tests/json/test.proto.pb
+++ b/tests/json/test.proto.pb
Binary files differ
diff --git a/tests/json/test_json.cc b/tests/json/test_json.cc
index 3fddfb6..6650817 100644
--- a/tests/json/test_json.cc
+++ b/tests/json/test_json.cc
@@ -4,6 +4,7 @@
*/
#include "tests/json/test.upbdefs.h"
+#include "tests/json/test.upb.h" // Test that it compiles for C++.
#include "tests/test_util.h"
#include "tests/upb_test.h"
#include "upb/handlers.h"
diff --git a/tests/pb/test_encoder.cc b/tests/pb/test_encoder.cc
index 3039767..c6544be 100644
--- a/tests/pb/test_encoder.cc
+++ b/tests/pb/test_encoder.cc
@@ -3,43 +3,25 @@
#include "tests/upb_test.h"
#include "upb/bindings/stdc++/string.h"
#include "google/protobuf/descriptor.upb.h"
+#include "google/protobuf/descriptor.upbdefs.h"
#include "upb/pb/decoder.h"
#include "upb/pb/encoder.h"
#include "upb/port_def.inc"
-
-std::string read_string(const char *filename) {
- size_t len;
- char *str = upb_readfile(filename, &len);
- ASSERT(str);
- if (!str) { return std::string(); }
- std::string ret = std::string(str, len);
- free(str);
- return ret;
-}
+#include <iostream>
void test_pb_roundtrip() {
- std::string input = read_string("google/protobuf/descriptor.pb");
+ std::string input(
+ google_protobuf_descriptor_proto_upbdefinit.descriptor.data,
+ google_protobuf_descriptor_proto_upbdefinit.descriptor.size);
+ std::cout << input.size() << "\n";
upb::SymbolTable symtab;
upb::HandlerCache encoder_cache(upb::pb::EncoderPtr::NewCache());
upb::pb::CodeCache decoder_cache(&encoder_cache);
upb::Arena arena;
- google_protobuf_FileDescriptorSet *set =
- google_protobuf_FileDescriptorSet_parse(input.c_str(), input.size(),
- arena.ptr());
- ASSERT(set);
- size_t n;
- const google_protobuf_FileDescriptorProto *const *files =
- google_protobuf_FileDescriptorSet_file(set, &n);
- ASSERT(n == 1);
upb::Status status;
- upb::FileDefPtr file_def = symtab.AddFile(files[0], &status);
- if (!file_def) {
- fprintf(stderr, "Error building def: %s\n", status.error_message());
- ASSERT(false);
- }
- upb::MessageDefPtr md =
- symtab.LookupMessage("google.protobuf.FileDescriptorSet");
+ upb::MessageDefPtr md(
+ google_protobuf_FileDescriptorProto_getmsgdef(symtab.ptr()));
ASSERT(md);
const upb::Handlers *encoder_handlers = encoder_cache.Get(md);
ASSERT(encoder_handlers);
diff --git a/tests/test_cpp.cc b/tests/test_cpp.cc
index 8feb6e2..abbafda 100644
--- a/tests/test_cpp.cc
+++ b/tests/test_cpp.cc
@@ -12,14 +12,13 @@
#include <sstream>
#include "tests/test_cpp.upbdefs.h"
+#include "tests/upb_test.h"
#include "upb/def.h"
#include "upb/handlers.h"
#include "upb/pb/decoder.h"
#include "upb/pb/textprinter.h"
-#include "upb/upb.h"
-#include "upb_test.h"
-
#include "upb/port_def.inc"
+#include "upb/upb.h"
template <class T>
void AssertInsert(T* const container, const typename T::value_type& val) {
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback