summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-01-09 22:40:50 -0800
committerJoshua Haberman <jhaberman@gmail.com>2019-01-09 22:40:50 -0800
commit0553eff64a87eceff0de3b6260b4f2d45b61703a (patch)
tree5b051740c041786655d1794a5034ccf20928e8ee /tests
parent31e0997c1abaa531505d28e36473f1c972ca0849 (diff)
upb_refcounted is gone! Some tests still to fix.
Diffstat (limited to 'tests')
-rw-r--r--tests/json/test_json.cc23
-rw-r--r--tests/pb/test_encoder.cc22
2 files changed, 27 insertions, 18 deletions
diff --git a/tests/json/test_json.cc b/tests/json/test_json.cc
index 98bf59e..b9b50cd 100644
--- a/tests/json/test_json.cc
+++ b/tests/json/test_json.cc
@@ -204,12 +204,15 @@ void test_json_roundtrip_message(const char* json_src,
// and compares the result.
void test_json_roundtrip() {
upb::SymbolTable* symtab = upb::SymbolTable::New();
+ upb::HandlerCache* serialize_handlercache = upb::json::Printer::NewCache(false);
+ upb::json::CodeCache* parse_codecache = upb::json::CodeCache::New();
+
const upb::MessageDef* md = upb_test_json_TestMessage_getmsgdef(symtab);
ASSERT(md);
- upb::reffed_ptr<const upb::Handlers> serialize_handlers(
- upb::json::Printer::NewHandlers(md, false));
- upb::reffed_ptr<const upb::json::ParserMethod> parser_method(
- upb::json::ParserMethod::New(md));
+ const upb::Handlers* serialize_handlers = serialize_handlercache->Get(md);
+ const upb::json::ParserMethod* parser_method = parse_codecache->Get(md);
+ ASSERT(serialize_handlers);
+ ASSERT(parser_method);
for (const TestCase* test_case = kTestRoundtripMessages;
test_case->input != NULL; test_case++) {
@@ -220,12 +223,13 @@ void test_json_roundtrip() {
for (size_t i = 0; i < strlen(test_case->input); i++) {
test_json_roundtrip_message(test_case->input, expected,
- serialize_handlers.get(), parser_method.get(),
- i);
+ serialize_handlers, parser_method, i);
}
}
- serialize_handlers = upb::json::Printer::NewHandlers(md, true);
+ upb::HandlerCache::Free(serialize_handlercache);
+ serialize_handlercache = upb::json::Printer::NewCache(true);
+ serialize_handlers = serialize_handlercache->Get(md);
for (const TestCase* test_case = kTestRoundtripMessagesPreserve;
test_case->input != NULL; test_case++) {
@@ -236,11 +240,12 @@ void test_json_roundtrip() {
for (size_t i = 0; i < strlen(test_case->input); i++) {
test_json_roundtrip_message(test_case->input, expected,
- serialize_handlers.get(), parser_method.get(),
- i);
+ serialize_handlers, parser_method, i);
}
}
+ upb::HandlerCache::Free(serialize_handlercache);
+ upb::json::CodeCache::Free(parse_codecache);
upb::SymbolTable::Free(symtab);
}
diff --git a/tests/pb/test_encoder.cc b/tests/pb/test_encoder.cc
index a0f8453..fac0dae 100644
--- a/tests/pb/test_encoder.cc
+++ b/tests/pb/test_encoder.cc
@@ -19,6 +19,11 @@ std::string read_string(const char *filename) {
void test_pb_roundtrip() {
std::string input = read_string("google/protobuf/descriptor.pb");
upb::SymbolTable* symtab = upb::SymbolTable::New();
+ upb::HandlerCache* encoder_cache = upb::pb::Encoder::NewCache();
+ upb::pb::CodeCache* decoder_cache = upb::pb::CodeCache::New(encoder_cache);
+ ASSERT(symtab);
+ ASSERT(encoder_cache);
+ ASSERT(decoder_cache);
upb::Arena arena;
google_protobuf_FileDescriptorSet *set =
google_protobuf_FileDescriptorSet_parsenew(
@@ -37,24 +42,23 @@ void test_pb_roundtrip() {
const upb::MessageDef *md =
symtab->LookupMessage("google.protobuf.FileDescriptorSet");
ASSERT(md);
- printf("name: %s\n", md->full_name());
- upb::reffed_ptr<const upb::Handlers> encoder_handlers(
- upb::pb::Encoder::NewHandlers(md));
- upb::reffed_ptr<const upb::pb::DecoderMethod> method(
- upb::pb::DecoderMethod::New(
- upb::pb::DecoderMethodOptions(encoder_handlers.get())));
+ const upb::Handlers* encoder_handlers = encoder_cache->Get(md);
+ ASSERT(encoder_handlers);
+ const upb::pb::DecoderMethod* method = decoder_cache->Get(md);
+ ASSERT(method);
upb::InlinedEnvironment<512> env;
std::string output;
upb::StringSink string_sink(&output);
upb::pb::Encoder* encoder =
- upb::pb::Encoder::Create(&env, encoder_handlers.get(),
- string_sink.input());
+ upb::pb::Encoder::Create(&env, encoder_handlers, string_sink.input());
upb::pb::Decoder* decoder =
- upb::pb::Decoder::Create(&env, method.get(), encoder->input());
+ upb::pb::Decoder::Create(&env, method, encoder->input());
ok = upb::BufferSource::PutBuffer(input, decoder->input());
ASSERT(ok);
ASSERT(input == output);
+ upb::pb::CodeCache::Free(decoder_cache);
+ upb::HandlerCache::Free(encoder_cache);
upb::SymbolTable::Free(symtab);
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback