diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/bindings/googlepb/test_vs_proto2.cc | 14 | ||||
-rw-r--r-- | tests/bindings/ruby/upb.rb | 62 | ||||
-rw-r--r-- | tests/pb/test_decoder.cc | 18 |
3 files changed, 90 insertions, 4 deletions
diff --git a/tests/bindings/googlepb/test_vs_proto2.cc b/tests/bindings/googlepb/test_vs_proto2.cc index 2d53f80..15a5388 100644 --- a/tests/bindings/googlepb/test_vs_proto2.cc +++ b/tests/bindings/googlepb/test_vs_proto2.cc @@ -27,8 +27,14 @@ #include "upb/pb/glue.h" #include "upb/pb/varint.int.h" -static const char message_data[] = { -#include MESSAGE_DATA_HFILE +// Pull in string data from benchmarks/google_message{1,2}.dat +// (the .h files are generated with xxd). +const char message1_data[] = { +#include "benchmarks/google_message1.h" +}; + +const char message2_data[] = { +#include "benchmarks/google_message2.h" }; void compare_metadata(const google::protobuf::Descriptor* d, @@ -117,8 +123,8 @@ extern "C" { int run_tests(int argc, char *argv[]) { UPB_UNUSED(argc); UPB_UNUSED(argv); - size_t len = sizeof(message_data); - const char *str = message_data; + size_t len = sizeof(MESSAGE_DATA_IDENT); + const char *str = MESSAGE_DATA_IDENT; MESSAGE_CIDENT msg1; MESSAGE_CIDENT msg2; diff --git a/tests/bindings/ruby/upb.rb b/tests/bindings/ruby/upb.rb new file mode 100644 index 0000000..3e06c17 --- /dev/null +++ b/tests/bindings/ruby/upb.rb @@ -0,0 +1,62 @@ +#!/usr/bin/ruby +# +# Tests for Ruby upb extension. + +require 'test/unit' +require 'set' +require 'upb' + +def get_descriptor + File.open("upb/descriptor/descriptor.pb").read +end + +def load_descriptor + symtab = Upb::SymbolTable.new + symtab.load_descriptor(get_descriptor()) + return symtab +end + +def get_message_class(name) + return Upb.get_message_class(load_descriptor().lookup(name)) +end + +class TestRubyExtension < Test::Unit::TestCase + def test_parsedescriptor + msgdef = load_descriptor.lookup("google.protobuf.FileDescriptorSet") + assert_instance_of(Upb::MessageDef, msgdef) + + file_descriptor_set = Upb.get_message_class(msgdef) + msg = file_descriptor_set.parse(get_descriptor()) + + # A couple message types we know should exist. + names = Set.new(["DescriptorProto", "FieldDescriptorProto"]) + + msg.file.each { |file| + file.message_type.each { |message_type| + names.delete(message_type.name) + } + } + + assert_equal(0, names.size) + end + + def test_parseserialize + field_descriptor_proto = get_message_class("google.protobuf.FieldDescriptorProto") + field_options = get_message_class("google.protobuf.FieldOptions") + + field = field_descriptor_proto.new + + field.name = "MyName" + field.number = 5 + field.options = field_options.new + field.options.packed = true + + serialized = Upb::Message.serialize(field) + + field2 = field_descriptor_proto.parse(serialized) + + assert_equal("MyName", field2.name) + assert_equal(5, field2.number) + assert_equal(true, field2.options.packed) + end +end diff --git a/tests/pb/test_decoder.cc b/tests/pb/test_decoder.cc index 2d94d82..d976a54 100644 --- a/tests/pb/test_decoder.cc +++ b/tests/pb/test_decoder.cc @@ -207,8 +207,16 @@ void indentbuf(string *buf, int depth) { buf->append(2 * depth, ' '); } +void check_stack_alignment() { +#ifdef UPB_USE_JIT_X64 + void *rsp = __builtin_frame_address(0); + ASSERT(((uintptr_t)rsp % 16) == 0); +#endif +} + #define NUMERIC_VALUE_HANDLER(member, ctype, fmt) \ bool value_##member(int* depth, const uint32_t* num, ctype val) { \ + check_stack_alignment(); \ indentbuf(&output, *depth); \ appendf(&output, "%" PRIu32 ":%" fmt "\n", *num, val); \ return true; \ @@ -222,12 +230,14 @@ NUMERIC_VALUE_HANDLER(float, float, "g") NUMERIC_VALUE_HANDLER(double, double, "g") bool value_bool(int* depth, const uint32_t* num, bool val) { + check_stack_alignment(); indentbuf(&output, *depth); appendf(&output, "%" PRIu32 ":%s\n", *num, val ? "true" : "false"); return true; } int* startstr(int* depth, const uint32_t* num, size_t size_hint) { + check_stack_alignment(); indentbuf(&output, *depth); appendf(&output, "%" PRIu32 ":(%zu)\"", *num, size_hint); return depth + 1; @@ -237,6 +247,7 @@ size_t value_string(int* depth, const uint32_t* num, const char* buf, size_t n, const upb::BufferHandle* handle) { UPB_UNUSED(num); UPB_UNUSED(depth); + check_stack_alignment(); output.append(buf, n); ASSERT(handle == &global_handle); return n; @@ -245,11 +256,13 @@ size_t value_string(int* depth, const uint32_t* num, const char* buf, bool endstr(int* depth, const uint32_t* num) { UPB_UNUSED(depth); UPB_UNUSED(num); + check_stack_alignment(); output.append("\"\n"); return true; } int* startsubmsg(int* depth, const uint32_t* num) { + check_stack_alignment(); indentbuf(&output, *depth); appendf(&output, "%" PRIu32 ":{\n", *num); return depth + 1; @@ -257,12 +270,14 @@ int* startsubmsg(int* depth, const uint32_t* num) { bool endsubmsg(int* depth, const uint32_t* num) { UPB_UNUSED(num); + check_stack_alignment(); indentbuf(&output, *depth); output.append("}\n"); return true; } int* startseq(int* depth, const uint32_t* num) { + check_stack_alignment(); indentbuf(&output, *depth); appendf(&output, "%" PRIu32 ":[\n", *num); return depth + 1; @@ -270,12 +285,14 @@ int* startseq(int* depth, const uint32_t* num) { bool endseq(int* depth, const uint32_t* num) { UPB_UNUSED(num); + check_stack_alignment(); indentbuf(&output, *depth); output.append("]\n"); return true; } bool startmsg(int* depth) { + check_stack_alignment(); indentbuf(&output, *depth); output.append("<\n"); return true; @@ -283,6 +300,7 @@ bool startmsg(int* depth) { bool endmsg(int* depth, upb_status* status) { UPB_UNUSED(status); + check_stack_alignment(); indentbuf(&output, *depth); output.append(">\n"); return true; |