Passes all tests.

pull/13171/head
Joshua Haberman 4 years ago
parent de84e20788
commit 4f901b6430
  1. 1
      BUILD
  2. 1
      CMakeLists.txt
  3. 2
      generated_for_cmake/upb/json/parser.c
  4. 55
      tests/pb/test_decoder.cc

@ -855,6 +855,7 @@ filegroup(
"upbc/**/*", "upbc/**/*",
"upb/**/*", "upb/**/*",
"tests/**/*", "tests/**/*",
"third_party/**/*",
]), ]),
) )

@ -71,6 +71,7 @@ add_library(upb
upb/table.int.h upb/table.int.h
upb/upb.c upb/upb.c
upb/upb.int.h upb/upb.int.h
third_party/wyhash/wyhash.h
upb/decode.h upb/decode.h
upb/encode.h upb/encode.h
upb/upb.h upb/upb.h

@ -3306,7 +3306,7 @@ static upb_json_parsermethod *parsermethod_new(upb_json_codecache *c,
upb_byteshandler_setstring(&m->input_handler_, parse, m); upb_byteshandler_setstring(&m->input_handler_, parse, m);
upb_byteshandler_setendstr(&m->input_handler_, end, m); upb_byteshandler_setendstr(&m->input_handler_, end, m);
upb_strtable_init2(&m->name_table, UPB_CTYPE_CONSTPTR, alloc); upb_strtable_init2(&m->name_table, UPB_CTYPE_CONSTPTR, 4, alloc);
/* Build name_table */ /* Build name_table */

@ -53,17 +53,6 @@
#define PRINT_FAILURE(expr) \ #define PRINT_FAILURE(expr) \
fprintf(stderr, "Assertion failed: %s:%d\n", __FILE__, __LINE__); \ fprintf(stderr, "Assertion failed: %s:%d\n", __FILE__, __LINE__); \
fprintf(stderr, "expr: %s\n", #expr); \ fprintf(stderr, "expr: %s\n", #expr); \
if (testhash) { \
fprintf(stderr, "assertion failed running test %x.\n", testhash); \
if (!filter_hash) { \
fprintf(stderr, \
"Run with the arg %x to run only this test. " \
"(This will also turn on extra debugging output)\n", \
testhash); \
} \
fprintf(stderr, "Failed at %02.2f%% through tests.\n", \
(float)completed * 100 / total); \
}
#define MAX_NESTING 64 #define MAX_NESTING 64
@ -445,17 +434,6 @@ upb::pb::DecoderPtr CreateDecoder(upb::Arena* arena,
return ret; return ret;
} }
uint32_t Hash(const string& proto, const string* expected_output, size_t seam1,
size_t seam2, bool may_skip) {
uint32_t hash = upb_murmur_hash2(proto.c_str(), proto.size(), 0);
if (expected_output)
hash = upb_murmur_hash2(expected_output->c_str(), expected_output->size(), hash);
hash = upb_murmur_hash2(&seam1, sizeof(seam1), hash);
hash = upb_murmur_hash2(&seam2, sizeof(seam2), hash);
hash = upb_murmur_hash2(&may_skip, sizeof(may_skip), hash);
return hash;
}
void CheckBytesParsed(upb::pb::DecoderPtr decoder, size_t ofs) { void CheckBytesParsed(upb::pb::DecoderPtr decoder, size_t ofs) {
// We can't have parsed more data than the decoder callback is telling us it // We can't have parsed more data than the decoder callback is telling us it
// parsed. // parsed.
@ -484,13 +462,11 @@ void do_run_decoder(VerboseParserEnvironment* env, upb::pb::DecoderPtr decoder,
env->Reset(proto.c_str(), proto.size(), may_skip, expected_output == NULL); env->Reset(proto.c_str(), proto.size(), may_skip, expected_output == NULL);
decoder.Reset(); decoder.Reset();
testhash = Hash(proto, expected_output, i, j, may_skip);
if (filter_hash && testhash != filter_hash) return;
if (test_mode != COUNT_ONLY) { if (test_mode != COUNT_ONLY) {
output.clear(); output.clear();
if (filter_hash) { if (filter_hash) {
fprintf(stderr, "RUNNING TEST CASE, hash=%x\n", testhash); fprintf(stderr, "RUNNING TEST CASE\n");
fprintf(stderr, "Input (len=%u): ", (unsigned)proto.size()); fprintf(stderr, "Input (len=%u): ", (unsigned)proto.size());
PrintBinary(proto); PrintBinary(proto);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@ -549,7 +525,6 @@ void run_decoder(const string& proto, const string* expected_output) {
} }
} }
} }
testhash = 0;
} }
const static string thirty_byte_nop = cat( const static string thirty_byte_nop = cat(
@ -849,23 +824,17 @@ void test_valid() {
// Empty protobuf where we never call PutString between // Empty protobuf where we never call PutString between
// StartString/EndString. // StartString/EndString.
// Randomly generated hash for this test, hope it doesn't conflict with others upb::Status status;
// by chance. upb::Arena arena;
const uint32_t emptyhash = 0x5709be8e; upb::Sink sink(global_handlers, &closures[0]);
if (!filter_hash || filter_hash == testhash) { upb::pb::DecoderPtr decoder =
testhash = emptyhash; CreateDecoder(&arena, global_method, sink, &status);
upb::Status status; output.clear();
upb::Arena arena; bool ok = upb::PutBuffer(std::string(), decoder.input());
upb::Sink sink(global_handlers, &closures[0]); ASSERT(ok);
upb::pb::DecoderPtr decoder = ASSERT(status.ok());
CreateDecoder(&arena, global_method, sink, &status); if (test_mode == ALL_HANDLERS) {
output.clear(); ASSERT(output == string("<\n>\n"));
bool ok = upb::PutBuffer(std::string(), decoder.input());
ASSERT(ok);
ASSERT(status.ok());
if (test_mode == ALL_HANDLERS) {
ASSERT(output == string("<\n>\n"));
}
} }
test_valid_data_for_signed_type(UPB_DESCRIPTOR_TYPE_DOUBLE, test_valid_data_for_signed_type(UPB_DESCRIPTOR_TYPE_DOUBLE,

Loading…
Cancel
Save