summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-04-24 10:54:27 -0700
committerGitHub <noreply@github.com>2019-04-24 10:54:27 -0700
commitb08819749e6c2a6d8d771f954f6162933a8ba648 (patch)
treec80170fc566219ee865a48b3434e399b528cd01f /tests
parentf9dab27de3f3a77650199da487dd450a49ed35b2 (diff)
parente1fb10002d3ddda0576ab40d3a70065a27baa25a (diff)
Merge pull request #162 from haberman/aspect
Replaced upb_proto_library() with a truly aspect-based rule.
Diffstat (limited to 'tests')
-rw-r--r--tests/json/enum_from_separate_file.proto9
-rw-r--r--tests/pb/test_encoder.cc34
2 files changed, 17 insertions, 26 deletions
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/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);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback