summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-01-15 03:37:34 -0800
committerJoshua Haberman <jhaberman@gmail.com>2019-01-15 03:37:34 -0800
commit754b9f1cfdf59104fa62cfaf99f21e5a817d281b (patch)
tree4272965f29708dcdc72fef096d85569c1dd59643 /tests
parentcb26d883d1290ed258e5594454c2ffe0526b13f9 (diff)
All tests pass again!
Diffstat (limited to 'tests')
-rw-r--r--tests/json/test_json.cc2
-rw-r--r--tests/pb/test_decoder.cc12
-rw-r--r--tests/pb/test_encoder.cc2
-rw-r--r--tests/test_util.h27
4 files changed, 21 insertions, 22 deletions
diff --git a/tests/json/test_json.cc b/tests/json/test_json.cc
index 1f7d364..3dc4a6c 100644
--- a/tests/json/test_json.cc
+++ b/tests/json/test_json.cc
@@ -176,7 +176,7 @@ void test_json_roundtrip_message(const char* json_src,
upb::json::PrinterPtr printer = upb::json::PrinterPtr::Create(
env.arena(), serialize_handlers, data_sink.Sink());
upb::json::ParserPtr parser = upb::json::ParserPtr::Create(
- env.arena(), parser_method, NULL, printer.input(), false);
+ env.arena(), parser_method, NULL, printer.input(), env.status(), false);
env.ResetBytesSink(parser.input());
env.Reset(json_src, strlen(json_src), false, false);
diff --git a/tests/pb/test_decoder.cc b/tests/pb/test_decoder.cc
index b2dd812..3c41801 100644
--- a/tests/pb/test_decoder.cc
+++ b/tests/pb/test_decoder.cc
@@ -454,8 +454,9 @@ upb::pb::DecoderMethodPtr global_method;
upb::pb::DecoderPtr CreateDecoder(upb::Arena* arena,
upb::pb::DecoderMethodPtr method,
- upb::Sink sink) {
- upb::pb::DecoderPtr ret = upb::pb::DecoderPtr::Create(arena, method, sink);
+ upb::Sink sink, upb::Status* status) {
+ upb::pb::DecoderPtr ret =
+ upb::pb::DecoderPtr::Create(arena, method, sink, status);
ret.set_max_nesting(MAX_NESTING);
return ret;
}
@@ -556,7 +557,7 @@ void do_run_decoder(VerboseParserEnvironment* env, upb::pb::DecoderPtr decoder,
void run_decoder(const string& proto, const string* expected_output) {
VerboseParserEnvironment env(filter_hash != 0);
upb::Sink sink(global_handlers, &closures[0]);
- upb::pb::DecoderPtr decoder = CreateDecoder(env.arena(), global_method, sink);
+ upb::pb::DecoderPtr decoder = CreateDecoder(env.arena(), global_method, sink, env.status());
env.ResetBytesSink(decoder.input());
for (size_t i = 0; i < proto.size(); i++) {
for (size_t j = i; j < UPB_MIN(proto.size(), i + 5); j++) {
@@ -874,7 +875,8 @@ void test_valid() {
upb::Status status;
upb::Arena arena;
upb::Sink sink(global_handlers, &closures[0]);
- upb::pb::DecoderPtr decoder = CreateDecoder(&arena, global_method, sink);
+ upb::pb::DecoderPtr decoder =
+ CreateDecoder(&arena, global_method, sink, &status);
output.clear();
bool ok = upb::PutBuffer(std::string(), decoder.input());
ASSERT(ok);
@@ -1161,7 +1163,7 @@ void test_emptyhandlers(upb::SymbolTable* symtab, bool allowjit) {
VerboseParserEnvironment env(filter_hash != 0);
upb::Sink sink(global_method.dest_handlers(), &closures[0]);
upb::pb::DecoderPtr decoder =
- CreateDecoder(env.arena(), global_method, sink);
+ CreateDecoder(env.arena(), global_method, sink, env.status());
env.ResetBytesSink(decoder.input());
env.Reset(testdata[i].data, testdata[i].length, true, false);
ASSERT(env.Start());
diff --git a/tests/pb/test_encoder.cc b/tests/pb/test_encoder.cc
index 7145097..a042d3d 100644
--- a/tests/pb/test_encoder.cc
+++ b/tests/pb/test_encoder.cc
@@ -48,7 +48,7 @@ void test_pb_roundtrip() {
upb::pb::EncoderPtr encoder =
upb::pb::EncoderPtr::Create(&arena, encoder_handlers, string_sink.input());
upb::pb::DecoderPtr decoder =
- upb::pb::DecoderPtr::Create(&arena, method, encoder.input());
+ upb::pb::DecoderPtr::Create(&arena, method, encoder.input(), &status);
ok = upb::PutBuffer(input, decoder.input());
ASSERT(ok);
ASSERT(input == output);
diff --git a/tests/test_util.h b/tests/test_util.h
index 04ca3fb..680673d 100644
--- a/tests/test_util.h
+++ b/tests/test_util.h
@@ -32,21 +32,6 @@ class VerboseParserEnvironment {
/* Pass verbose=true to print detailed diagnostics to stderr. */
VerboseParserEnvironment(bool verbose) : verbose_(verbose) {}
- static bool OnError(void *ud, const upb::Status* status) {
- VerboseParserEnvironment* env = static_cast<VerboseParserEnvironment*>(ud);
-
- if (env->expect_error_ && env->verbose_) {
- fprintf(stderr, "Encountered error, as expected: ");
- } else if (!env->expect_error_) {
- fprintf(stderr, "Encountered unexpected error: ");
- } else {
- return false;
- }
-
- fprintf(stderr, "%s\n", status->error_message());
- return false;
- }
-
void Reset(const char *buf, size_t len, bool may_skip, bool expect_error) {
buf_ = buf;
len_ = len;
@@ -99,6 +84,17 @@ class VerboseParserEnvironment {
return false;
}
+ if (!status_.ok()) {
+ if (expect_error_ && verbose_) {
+ fprintf(stderr, "Encountered error, as expected: %s",
+ status_.error_message());
+ } else if (!expect_error_) {
+ fprintf(stderr, "Encountered unexpected error: %s",
+ status_.error_message());
+ return false;
+ }
+ }
+
return true;
}
@@ -175,6 +171,7 @@ class VerboseParserEnvironment {
bool SkippedWithNull() { return skipped_with_null_; }
upb::Arena* arena() { return &arena_; }
+ upb::Status* status() { return &status_; }
private:
upb::Arena arena_;
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback