|
|
|
#!/usr/bin/ruby
|
|
|
|
|
|
|
|
# basic_test_pb.rb is in the same directory as this test.
|
|
|
|
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
|
|
|
|
|
|
|
require 'basic_test_pb'
|
|
|
|
require 'common_tests'
|
|
|
|
require 'google/protobuf'
|
|
|
|
require 'json'
|
|
|
|
require 'test/unit'
|
|
|
|
|
|
|
|
# ------------- generated code --------------
|
|
|
|
|
|
|
|
module BasicTest
|
|
|
|
pool = Google::Protobuf::DescriptorPool.new
|
|
|
|
pool.build do
|
|
|
|
add_message "BadFieldNames" do
|
|
|
|
optional :dup, :int32, 1
|
|
|
|
optional :class, :int32, 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
BadFieldNames = pool.lookup("BadFieldNames").msgclass
|
|
|
|
|
|
|
|
# ------------ test cases ---------------
|
|
|
|
|
|
|
|
class MessageContainerTest < Test::Unit::TestCase
|
|
|
|
# Required by CommonTests module to resolve proto3 proto classes used in tests.
|
|
|
|
def proto_module
|
|
|
|
::BasicTest
|
|
|
|
end
|
|
|
|
include CommonTests
|
|
|
|
|
|
|
|
def test_issue_8311_crash
|
|
|
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
|
|
add_file("inner.proto", :syntax => :proto3) do
|
|
|
|
add_message "Inner" do
|
|
|
|
# Removing either of these fixes the segfault.
|
|
|
|
optional :foo, :string, 1
|
|
|
|
optional :bar, :string, 2
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Google::Protobuf::DescriptorPool.generated_pool.build do
|
|
|
|
add_file("outer.proto", :syntax => :proto3) do
|
|
|
|
add_message "Outer" do
|
|
|
|
repeated :inners, :message, 1, "Inner"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
outer = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("Outer").msgclass
|
|
|
|
|
|
|
|
outer.new(
|
|
|
|
inners: []
|
|
|
|
)['inners'].to_s
|
|
|
|
|
|
|
|
assert_raise Google::Protobuf::TypeError do
|
|
|
|
outer.new(
|
|
|
|
inners: [nil]
|
|
|
|
).to_s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_issue_8559_crash
|
|
|
|
msg = TestMessage.new
|
|
|
|
msg.repeated_int32 = ::Google::Protobuf::RepeatedField.new(:int32, [1, 2, 3])
|
|
|
|
GC.start(full_mark: true, immediate_sweep: true)
|
|
|
|
TestMessage.encode(msg)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_has_field
|
|
|
|
m = TestSingularFields.new
|
|
|
|
assert !m.has_singular_msg?
|
|
|
|
m.singular_msg = TestMessage2.new
|
|
|
|
assert m.has_singular_msg?
|
|
|
|
assert TestSingularFields.descriptor.lookup('singular_msg').has?(m)
|
|
|
|
|
|
|
|
m = OneofMessage.new
|
|
|
|
assert !m.has_my_oneof?
|
|
|
|
m.a = "foo"
|
|
|
|
assert m.has_my_oneof?
|
|
|
|
assert_raise NoMethodError do
|
|
|
|
m.has_a?
|
|
|
|
end
|
|
|
|
assert_true OneofMessage.descriptor.lookup('a').has?(m)
|
|
|
|
|
|
|
|
m = TestSingularFields.new
|
|
|
|
assert_raise NoMethodError do
|
|
|
|
m.has_singular_int32?
|
|
|
|
end
|
|
|
|
assert_raise ArgumentError do
|
|
|
|
TestSingularFields.descriptor.lookup('singular_int32').has?(m)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise NoMethodError do
|
|
|
|
m.has_singular_string?
|
|
|
|
end
|
|
|
|
assert_raise ArgumentError do
|
|
|
|
TestSingularFields.descriptor.lookup('singular_string').has?(m)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise NoMethodError do
|
|
|
|
m.has_singular_bool?
|
|
|
|
end
|
|
|
|
assert_raise ArgumentError do
|
|
|
|
TestSingularFields.descriptor.lookup('singular_bool').has?(m)
|
|
|
|
end
|
|
|
|
|
|
|
|
m = TestMessage.new
|
|
|
|
assert_raise NoMethodError do
|
|
|
|
m.has_repeated_msg?
|
|
|
|
end
|
|
|
|
assert_raise ArgumentError do
|
|
|
|
TestMessage.descriptor.lookup('repeated_msg').has?(m)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_no_presence
|
|
|
|
m = TestSingularFields.new
|
|
|
|
|
|
|
|
# Explicitly setting to zero does not cause anything to be serialized.
|
|
|
|
m.singular_int32 = 0
|
|
|
|
assert_equal "", TestSingularFields.encode(m)
|
|
|
|
|
|
|
|
# Explicitly setting to a non-zero value *does* cause serialization.
|
|
|
|
m.singular_int32 = 1
|
|
|
|
assert_not_equal "", TestSingularFields.encode(m)
|
|
|
|
|
|
|
|
m.singular_int32 = 0
|
|
|
|
assert_equal "", TestSingularFields.encode(m)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_set_clear_defaults
|
|
|
|
m = TestSingularFields.new
|
|
|
|
|
|
|
|
m.singular_int32 = -42
|
|
|
|
assert_equal -42, m.singular_int32
|
|
|
|
m.clear_singular_int32
|
|
|
|
assert_equal 0, m.singular_int32
|
|
|
|
|
|
|
|
m.singular_int32 = 50
|
|
|
|
assert_equal 50, m.singular_int32
|
|
|
|
TestSingularFields.descriptor.lookup('singular_int32').clear(m)
|
|
|
|
assert_equal 0, m.singular_int32
|
|
|
|
|
|
|
|
m.singular_string = "foo bar"
|
|
|
|
assert_equal "foo bar", m.singular_string
|
|
|
|
m.clear_singular_string
|
|
|
|
assert_equal "", m.singular_string
|
|
|
|
|
|
|
|
m.singular_string = "foo"
|
|
|
|
assert_equal "foo", m.singular_string
|
|
|
|
TestSingularFields.descriptor.lookup('singular_string').clear(m)
|
|
|
|
assert_equal "", m.singular_string
|
|
|
|
|
|
|
|
m.singular_msg = TestMessage2.new(:foo => 42)
|
|
|
|
assert_equal TestMessage2.new(:foo => 42), m.singular_msg
|
|
|
|
assert m.has_singular_msg?
|
|
|
|
m.clear_singular_msg
|
|
|
|
assert_equal nil, m.singular_msg
|
|
|
|
assert !m.has_singular_msg?
|
|
|
|
|
|
|
|
m.singular_msg = TestMessage2.new(:foo => 42)
|
|
|
|
assert_equal TestMessage2.new(:foo => 42), m.singular_msg
|
|
|
|
TestSingularFields.descriptor.lookup('singular_msg').clear(m)
|
|
|
|
assert_equal nil, m.singular_msg
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_clear_repeated_fields
|
|
|
|
m = TestMessage.new
|
|
|
|
|
|
|
|
m.repeated_int32.push(1)
|
|
|
|
assert_equal [1], m.repeated_int32
|
|
|
|
m.clear_repeated_int32
|
|
|
|
assert_equal [], m.repeated_int32
|
|
|
|
|
|
|
|
m.repeated_int32.push(1)
|
|
|
|
assert_equal [1], m.repeated_int32
|
|
|
|
TestMessage.descriptor.lookup('repeated_int32').clear(m)
|
|
|
|
assert_equal [], m.repeated_int32
|
|
|
|
|
|
|
|
m = OneofMessage.new
|
|
|
|
m.a = "foo"
|
|
|
|
assert_equal "foo", m.a
|
|
|
|
assert m.has_my_oneof?
|
|
|
|
assert_equal :a, m.my_oneof
|
|
|
|
m.clear_a
|
|
|
|
assert !m.has_my_oneof?
|
|
|
|
|
|
|
|
m.a = "foobar"
|
|
|
|
assert m.has_my_oneof?
|
|
|
|
m.clear_my_oneof
|
|
|
|
assert !m.has_my_oneof?
|
|
|
|
|
|
|
|
m.a = "bar"
|
|
|
|
assert_equal "bar", m.a
|
|
|
|
assert m.has_my_oneof?
|
|
|
|
OneofMessage.descriptor.lookup('a').clear(m)
|
|
|
|
assert !m.has_my_oneof?
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_initialization_map_errors
|
|
|
|
e = assert_raise ArgumentError do
|
|
|
|
TestMessage.new(:hello => "world")
|
|
|
|
end
|
|
|
|
assert_match(/hello/, e.message)
|
|
|
|
|
|
|
|
e = assert_raise ArgumentError do
|
|
|
|
MapMessage.new(:map_string_int32 => "hello")
|
|
|
|
end
|
|
|
|
assert_equal e.message, "Expected Hash object as initializer value for map field 'map_string_int32' (given String)."
|
|
|
|
|
|
|
|
e = assert_raise ArgumentError do
|
|
|
|
TestMessage.new(:repeated_uint32 => "hello")
|
|
|
|
end
|
|
|
|
assert_equal e.message, "Expected array as initializer value for repeated field 'repeated_uint32' (given String)."
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_map_field
|
|
|
|
m = MapMessage.new
|
|
|
|
assert m.map_string_int32 == {}
|
|
|
|
assert m.map_string_msg == {}
|
|
|
|
|
|
|
|
m = MapMessage.new(
|
|
|
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
|
|
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
|
|
|
"b" => TestMessage2.new(:foo => 2)},
|
|
|
|
:map_string_enum => {"a" => :A, "b" => :B})
|
|
|
|
assert m.map_string_int32.keys.sort == ["a", "b"]
|
|
|
|
assert m.map_string_int32["a"] == 1
|
|
|
|
assert m.map_string_msg["b"].foo == 2
|
|
|
|
assert m.map_string_enum["a"] == :A
|
|
|
|
|
|
|
|
m.map_string_int32["c"] = 3
|
|
|
|
assert m.map_string_int32["c"] == 3
|
|
|
|
m.map_string_msg["c"] = TestMessage2.new(:foo => 3)
|
|
|
|
assert m.map_string_msg["c"] == TestMessage2.new(:foo => 3)
|
|
|
|
m.map_string_msg.delete("b")
|
|
|
|
m.map_string_msg.delete("c")
|
|
|
|
assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
|
|
|
|
|
|
|
|
assert_raise Google::Protobuf::TypeError do
|
|
|
|
m.map_string_msg["e"] = TestMessage.new # wrong value type
|
|
|
|
end
|
|
|
|
# ensure nothing was added by the above
|
|
|
|
assert m.map_string_msg == { "a" => TestMessage2.new(:foo => 1) }
|
|
|
|
|
|
|
|
m.map_string_int32 = Google::Protobuf::Map.new(:string, :int32)
|
|
|
|
assert_raise Google::Protobuf::TypeError do
|
|
|
|
m.map_string_int32 = Google::Protobuf::Map.new(:string, :int64)
|
|
|
|
end
|
|
|
|
assert_raise Google::Protobuf::TypeError do
|
|
|
|
m.map_string_int32 = {}
|
|
|
|
end
|
|
|
|
|
Ported Ruby extension to upb_msg (#8184)
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* Added some missing files.
* WIP.
* WIP.
* Updated upb.
* Extension loads, but crashes immediately.
* Gets through the test suite without SEGV!
Still a lot of bugs to fix, but it is a major step!
214 tests, 378 assertions, 37 failures, 147 errors, 0 pendings, 0 omissions, 0 notifications
14.0187% passed
* Test and build for Ruby 3.0
* Fixed a few more bugs, efficient #inspect is almost done.
214 tests, 134243 assertions, 30 failures, 144 errors, 0 pendings, 0 omissions, 0 notifications
18.6916% passed
* Fixed message hash initialization and encode depth checking.
214 tests, 124651 assertions, 53 failures, 70 errors, 0 pendings, 0 omissions, 0 notifications
42.5234% passed
* A bunch of fixes to failing tests, now 70% passing.
214 tests, 202091 assertions, 41 failures, 23 errors, 0 pendings, 0 omissions, 0 notifications
70.0935% passed
* More than 80% of tests are passing now.
214 tests, 322331 assertions, 30 failures, 9 errors, 0 pendings, 0 omissions, 0 notifications
81.7757% passed
Unfortunately there is also a sporadic bug/segfault hanging around
that appears to be GC-related.
* Add linux/ruby30 and macos/ruby30
* Use rvm master for 3.0.0-preview2
* Over 90% of tests are passing!
214 tests, 349898 assertions, 15 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
92.5234% passed
* Passes all tests!
214 tests, 369388 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
* A bunch of cleanup.
1. Removed a bunch of internal-only symbols from headers.
2. Required a frozen check to get a non-const pointer to a map or array.
3. De-duplicated the code to get a type argument for Map/RepeatedField.
* Removed a bunch more stuff from protobuf.h. There is an intermittent assert failure.
Intermittent failure:
ruby: ../../../../ext/google/protobuf_c/protobuf.c:263: ObjectCache_Add: Assertion `rb_funcall(obj_cache2, (__builtin_constant_p("[]") ? __extension__ ({ static ID rb_intern_id_cache; if (!rb_intern_id_cache) rb_intern_id_cache = rb_intern2((("[]")
), (long)strlen(("[]"))); (ID) rb_intern_id_cache; }) : rb_intern("[]")), 1, key_rb) == val' failed
* Removed a few more things from protobuf.h.
* Ruby 3.0.0-preview2 to 3.0.0
* Require rake-compiler-dock >= 1.1.0
* More progress, fighting with the object cache.
* Passes on all Ruby versions!
* Updated and clarified comment regarding WeakMap.
* Fixed the wyhash compile.
* Fixed conformance tests for Ruby.
Conformance results now look like:
RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 1955 successes, 0 skipped, 58 expected failures, 0 unexpected failures.
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 0 successes, 111 skipped, 8 expected failures, 0 unexpected failures.
Fixes include:
- Changed Ruby compiler to no longer reject proto2 maps.
- Changed Ruby compiler to emit a warning when proto2 extensions are
present instead of rejecting the .proto file completely.
- Fixed conformance tests to allow proto2 and look up message by name
instead of hardcoding a specific list of messages.
- Fixed conformance test to support the "ignore unknown" option for
JSON.
- Fixed conformance test to properly report serialization errors.
* Removed debug printf and fixed #inspect for floats.
* Fixed compatibility test to have proper semantics for #to_json.
* Updated Makefile.am with new file list.
* Don't try to copy wyhash when inside Docker.
* Fixed bug where we would forget that a sub-object is frozen in Ruby >=2.7.
* Avoid exporting unneeded symbols and refactored a bit of code.
* Some more refactoring.
* Simplified and added more comments.
* Some more comments and simplification. Added a missing license block.
Co-authored-by: Masaki Hara <hara@wantedly.com>
4 years ago
|
|
|
assert_raise Google::Protobuf::TypeError do
|
|
|
|
m = MapMessage.new(:map_string_int32 => { 1 => "I am not a number" })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_map_field_with_symbol
|
|
|
|
m = MapMessage.new
|
|
|
|
assert m.map_string_int32 == {}
|
|
|
|
assert m.map_string_msg == {}
|
|
|
|
|
|
|
|
m = MapMessage.new(
|
|
|
|
:map_string_int32 => {a: 1, "b" => 2},
|
|
|
|
:map_string_msg => {a: TestMessage2.new(:foo => 1),
|
|
|
|
b: TestMessage2.new(:foo => 10)})
|
|
|
|
assert_equal 1, m.map_string_int32[:a]
|
|
|
|
assert_equal 2, m.map_string_int32[:b]
|
|
|
|
assert_equal 10, m.map_string_msg[:b].foo
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_map_inspect
|
|
|
|
m = MapMessage.new(
|
|
|
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
|
|
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
|
|
|
"b" => TestMessage2.new(:foo => 2)},
|
|
|
|
:map_string_enum => {"a" => :A, "b" => :B})
|
|
|
|
|
|
|
|
# JRuby doesn't keep consistent ordering so check for either version
|
|
|
|
expected_a = "<BasicTest::MapMessage: map_string_int32: {\"b\"=>2, \"a\"=>1}, map_string_msg: {\"b\"=><BasicTest::TestMessage2: foo: 2>, \"a\"=><BasicTest::TestMessage2: foo: 1>}, map_string_enum: {\"b\"=>:B, \"a\"=>:A}>"
|
|
|
|
expected_b = "<BasicTest::MapMessage: map_string_int32: {\"a\"=>1, \"b\"=>2}, map_string_msg: {\"a\"=><BasicTest::TestMessage2: foo: 1>, \"b\"=><BasicTest::TestMessage2: foo: 2>}, map_string_enum: {\"a\"=>:A, \"b\"=>:B}>"
|
|
|
|
inspect_result = m.inspect
|
|
|
|
assert expected_a == inspect_result || expected_b == inspect_result, "Incorrect inspect result: #{inspect_result}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_map_corruption
|
|
|
|
# This pattern led to a crash in a previous version of upb/protobuf.
|
|
|
|
m = MapMessage.new(map_string_int32: { "aaa" => 1 })
|
|
|
|
m.map_string_int32['podid'] = 2
|
|
|
|
m.map_string_int32['aaa'] = 3
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_map_wrappers
|
|
|
|
run_asserts = ->(m) {
|
|
|
|
assert_equal 2.0, m.map_double[0].value
|
|
|
|
assert_equal 4.0, m.map_float[0].value
|
|
|
|
assert_equal 3, m.map_int32[0].value
|
|
|
|
assert_equal 4, m.map_int64[0].value
|
|
|
|
assert_equal 5, m.map_uint32[0].value
|
|
|
|
assert_equal 6, m.map_uint64[0].value
|
|
|
|
assert_equal true, m.map_bool[0].value
|
|
|
|
assert_equal 'str', m.map_string[0].value
|
|
|
|
assert_equal 'fun', m.map_bytes[0].value
|
|
|
|
}
|
|
|
|
|
|
|
|
m = proto_module::Wrapper.new(
|
|
|
|
map_double: {0 => Google::Protobuf::DoubleValue.new(value: 2.0)},
|
|
|
|
map_float: {0 => Google::Protobuf::FloatValue.new(value: 4.0)},
|
|
|
|
map_int32: {0 => Google::Protobuf::Int32Value.new(value: 3)},
|
|
|
|
map_int64: {0 => Google::Protobuf::Int64Value.new(value: 4)},
|
|
|
|
map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 5)},
|
|
|
|
map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 6)},
|
|
|
|
map_bool: {0 => Google::Protobuf::BoolValue.new(value: true)},
|
|
|
|
map_string: {0 => Google::Protobuf::StringValue.new(value: 'str')},
|
|
|
|
map_bytes: {0 => Google::Protobuf::BytesValue.new(value: 'fun')},
|
|
|
|
)
|
|
|
|
|
|
|
|
run_asserts.call(m)
|
|
|
|
serialized = proto_module::Wrapper::encode(m)
|
|
|
|
m2 = proto_module::Wrapper::decode(serialized)
|
|
|
|
run_asserts.call(m2)
|
|
|
|
|
|
|
|
# Test the case where we are serializing directly from the parsed form
|
|
|
|
# (before anything lazy is materialized).
|
|
|
|
m3 = proto_module::Wrapper::decode(serialized)
|
|
|
|
serialized2 = proto_module::Wrapper::encode(m3)
|
|
|
|
m4 = proto_module::Wrapper::decode(serialized2)
|
|
|
|
run_asserts.call(m4)
|
|
|
|
|
|
|
|
# Test that the lazy form compares equal to the expanded form.
|
|
|
|
m5 = proto_module::Wrapper::decode(serialized2)
|
|
|
|
assert_equal m5, m
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_map_wrappers_with_default_values
|
|
|
|
run_asserts = ->(m) {
|
|
|
|
assert_equal 0.0, m.map_double[0].value
|
|
|
|
assert_equal 0.0, m.map_float[0].value
|
|
|
|
assert_equal 0, m.map_int32[0].value
|
|
|
|
assert_equal 0, m.map_int64[0].value
|
|
|
|
assert_equal 0, m.map_uint32[0].value
|
|
|
|
assert_equal 0, m.map_uint64[0].value
|
|
|
|
assert_equal false, m.map_bool[0].value
|
|
|
|
assert_equal '', m.map_string[0].value
|
|
|
|
assert_equal '', m.map_bytes[0].value
|
|
|
|
}
|
|
|
|
|
|
|
|
m = proto_module::Wrapper.new(
|
|
|
|
map_double: {0 => Google::Protobuf::DoubleValue.new(value: 0.0)},
|
|
|
|
map_float: {0 => Google::Protobuf::FloatValue.new(value: 0.0)},
|
|
|
|
map_int32: {0 => Google::Protobuf::Int32Value.new(value: 0)},
|
|
|
|
map_int64: {0 => Google::Protobuf::Int64Value.new(value: 0)},
|
|
|
|
map_uint32: {0 => Google::Protobuf::UInt32Value.new(value: 0)},
|
|
|
|
map_uint64: {0 => Google::Protobuf::UInt64Value.new(value: 0)},
|
|
|
|
map_bool: {0 => Google::Protobuf::BoolValue.new(value: false)},
|
|
|
|
map_string: {0 => Google::Protobuf::StringValue.new(value: '')},
|
|
|
|
map_bytes: {0 => Google::Protobuf::BytesValue.new(value: '')},
|
|
|
|
)
|
|
|
|
|
|
|
|
run_asserts.call(m)
|
|
|
|
serialized = proto_module::Wrapper::encode(m)
|
|
|
|
m2 = proto_module::Wrapper::decode(serialized)
|
|
|
|
run_asserts.call(m2)
|
|
|
|
|
|
|
|
# Test the case where we are serializing directly from the parsed form
|
|
|
|
# (before anything lazy is materialized).
|
|
|
|
m3 = proto_module::Wrapper::decode(serialized)
|
|
|
|
serialized2 = proto_module::Wrapper::encode(m3)
|
|
|
|
m4 = proto_module::Wrapper::decode(serialized2)
|
|
|
|
run_asserts.call(m4)
|
|
|
|
|
|
|
|
# Test that the lazy form compares equal to the expanded form.
|
|
|
|
m5 = proto_module::Wrapper::decode(serialized2)
|
|
|
|
assert_equal m5, m
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_map_wrappers_with_no_value
|
|
|
|
run_asserts = ->(m) {
|
|
|
|
assert_equal 0.0, m.map_double[0].value
|
|
|
|
assert_equal 0.0, m.map_float[0].value
|
|
|
|
assert_equal 0, m.map_int32[0].value
|
|
|
|
assert_equal 0, m.map_int64[0].value
|
|
|
|
assert_equal 0, m.map_uint32[0].value
|
|
|
|
assert_equal 0, m.map_uint64[0].value
|
|
|
|
assert_equal false, m.map_bool[0].value
|
|
|
|
assert_equal '', m.map_string[0].value
|
|
|
|
assert_equal '', m.map_bytes[0].value
|
|
|
|
}
|
|
|
|
|
|
|
|
m = proto_module::Wrapper.new(
|
|
|
|
map_double: {0 => Google::Protobuf::DoubleValue.new()},
|
|
|
|
map_float: {0 => Google::Protobuf::FloatValue.new()},
|
|
|
|
map_int32: {0 => Google::Protobuf::Int32Value.new()},
|
|
|
|
map_int64: {0 => Google::Protobuf::Int64Value.new()},
|
|
|
|
map_uint32: {0 => Google::Protobuf::UInt32Value.new()},
|
|
|
|
map_uint64: {0 => Google::Protobuf::UInt64Value.new()},
|
|
|
|
map_bool: {0 => Google::Protobuf::BoolValue.new()},
|
|
|
|
map_string: {0 => Google::Protobuf::StringValue.new()},
|
|
|
|
map_bytes: {0 => Google::Protobuf::BytesValue.new()},
|
|
|
|
)
|
|
|
|
run_asserts.call(m)
|
|
|
|
|
|
|
|
serialized = proto_module::Wrapper::encode(m)
|
|
|
|
m2 = proto_module::Wrapper::decode(serialized)
|
|
|
|
run_asserts.call(m2)
|
|
|
|
|
|
|
|
# Test the case where we are serializing directly from the parsed form
|
|
|
|
# (before anything lazy is materialized).
|
|
|
|
m3 = proto_module::Wrapper::decode(serialized)
|
|
|
|
serialized2 = proto_module::Wrapper::encode(m3)
|
|
|
|
m4 = proto_module::Wrapper::decode(serialized2)
|
|
|
|
run_asserts.call(m4)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_concurrent_decoding
|
|
|
|
o = Outer.new
|
|
|
|
o.items[0] = Inner.new
|
|
|
|
raw = Outer.encode(o)
|
|
|
|
|
|
|
|
thds = 2.times.map do
|
|
|
|
Thread.new do
|
|
|
|
100000.times do
|
|
|
|
assert_equal o, Outer.decode(raw)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
thds.map(&:join)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_map_encode_decode
|
|
|
|
m = MapMessage.new(
|
|
|
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
|
|
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
|
|
|
"b" => TestMessage2.new(:foo => 2)},
|
|
|
|
:map_string_enum => {"a" => :A, "b" => :B})
|
|
|
|
m2 = MapMessage.decode(MapMessage.encode(m))
|
|
|
|
assert m == m2
|
|
|
|
|
|
|
|
m3 = MapMessageWireEquiv.decode(MapMessage.encode(m))
|
|
|
|
assert m3.map_string_int32.length == 2
|
|
|
|
|
|
|
|
kv = {}
|
|
|
|
m3.map_string_int32.map { |msg| kv[msg.key] = msg.value }
|
|
|
|
assert kv == {"a" => 1, "b" => 2}
|
|
|
|
|
|
|
|
kv = {}
|
|
|
|
m3.map_string_msg.map { |msg| kv[msg.key] = msg.value }
|
|
|
|
assert kv == {"a" => TestMessage2.new(:foo => 1),
|
|
|
|
"b" => TestMessage2.new(:foo => 2)}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_protobuf_decode_json_ignore_unknown_fields
|
|
|
|
m = TestMessage.decode_json({
|
|
|
|
optional_string: "foo",
|
|
|
|
not_in_message: "some_value"
|
|
|
|
}.to_json, { ignore_unknown_fields: true })
|
|
|
|
|
|
|
|
assert_equal m.optional_string, "foo"
|
|
|
|
e = assert_raise Google::Protobuf::ParseError do
|
|
|
|
TestMessage.decode_json({ not_in_message: "some_value" }.to_json)
|
|
|
|
end
|
|
|
|
assert_match(/No such field: not_in_message/, e.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
#def test_json_quoted_string
|
|
|
|
# m = TestMessage.decode_json(%q(
|
|
|
|
# "optionalInt64": "1",,
|
|
|
|
# }))
|
|
|
|
# puts(m)
|
|
|
|
# assert_equal 1, m.optional_int32
|
|
|
|
#end
|
|
|
|
|
|
|
|
def test_to_h
|
|
|
|
m = TestMessage.new(:optional_bool => true, :optional_double => -10.100001, :optional_string => 'foo', :repeated_string => ['bar1', 'bar2'], :repeated_msg => [TestMessage2.new(:foo => 100)])
|
|
|
|
expected_result = {
|
|
|
|
:optional_bool=>true,
|
|
|
|
:optional_bytes=>"",
|
|
|
|
:optional_double=>-10.100001,
|
|
|
|
:optional_enum=>:Default,
|
|
|
|
:optional_float=>0.0,
|
|
|
|
:optional_int32=>0,
|
|
|
|
:optional_int64=>0,
|
|
|
|
:optional_msg=>nil,
|
Ported Ruby extension to upb_msg (#8184)
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* Added some missing files.
* WIP.
* WIP.
* Updated upb.
* Extension loads, but crashes immediately.
* Gets through the test suite without SEGV!
Still a lot of bugs to fix, but it is a major step!
214 tests, 378 assertions, 37 failures, 147 errors, 0 pendings, 0 omissions, 0 notifications
14.0187% passed
* Test and build for Ruby 3.0
* Fixed a few more bugs, efficient #inspect is almost done.
214 tests, 134243 assertions, 30 failures, 144 errors, 0 pendings, 0 omissions, 0 notifications
18.6916% passed
* Fixed message hash initialization and encode depth checking.
214 tests, 124651 assertions, 53 failures, 70 errors, 0 pendings, 0 omissions, 0 notifications
42.5234% passed
* A bunch of fixes to failing tests, now 70% passing.
214 tests, 202091 assertions, 41 failures, 23 errors, 0 pendings, 0 omissions, 0 notifications
70.0935% passed
* More than 80% of tests are passing now.
214 tests, 322331 assertions, 30 failures, 9 errors, 0 pendings, 0 omissions, 0 notifications
81.7757% passed
Unfortunately there is also a sporadic bug/segfault hanging around
that appears to be GC-related.
* Add linux/ruby30 and macos/ruby30
* Use rvm master for 3.0.0-preview2
* Over 90% of tests are passing!
214 tests, 349898 assertions, 15 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
92.5234% passed
* Passes all tests!
214 tests, 369388 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
* A bunch of cleanup.
1. Removed a bunch of internal-only symbols from headers.
2. Required a frozen check to get a non-const pointer to a map or array.
3. De-duplicated the code to get a type argument for Map/RepeatedField.
* Removed a bunch more stuff from protobuf.h. There is an intermittent assert failure.
Intermittent failure:
ruby: ../../../../ext/google/protobuf_c/protobuf.c:263: ObjectCache_Add: Assertion `rb_funcall(obj_cache2, (__builtin_constant_p("[]") ? __extension__ ({ static ID rb_intern_id_cache; if (!rb_intern_id_cache) rb_intern_id_cache = rb_intern2((("[]")
), (long)strlen(("[]"))); (ID) rb_intern_id_cache; }) : rb_intern("[]")), 1, key_rb) == val' failed
* Removed a few more things from protobuf.h.
* Ruby 3.0.0-preview2 to 3.0.0
* Require rake-compiler-dock >= 1.1.0
* More progress, fighting with the object cache.
* Passes on all Ruby versions!
* Updated and clarified comment regarding WeakMap.
* Fixed the wyhash compile.
* Fixed conformance tests for Ruby.
Conformance results now look like:
RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 1955 successes, 0 skipped, 58 expected failures, 0 unexpected failures.
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 0 successes, 111 skipped, 8 expected failures, 0 unexpected failures.
Fixes include:
- Changed Ruby compiler to no longer reject proto2 maps.
- Changed Ruby compiler to emit a warning when proto2 extensions are
present instead of rejecting the .proto file completely.
- Fixed conformance tests to allow proto2 and look up message by name
instead of hardcoding a specific list of messages.
- Fixed conformance test to support the "ignore unknown" option for
JSON.
- Fixed conformance test to properly report serialization errors.
* Removed debug printf and fixed #inspect for floats.
* Fixed compatibility test to have proper semantics for #to_json.
* Updated Makefile.am with new file list.
* Don't try to copy wyhash when inside Docker.
* Fixed bug where we would forget that a sub-object is frozen in Ruby >=2.7.
* Avoid exporting unneeded symbols and refactored a bit of code.
* Some more refactoring.
* Simplified and added more comments.
* Some more comments and simplification. Added a missing license block.
Co-authored-by: Masaki Hara <hara@wantedly.com>
4 years ago
|
|
|
:optional_msg2=>nil,
|
|
|
|
:optional_string=>"foo",
|
|
|
|
:optional_uint32=>0,
|
|
|
|
:optional_uint64=>0,
|
|
|
|
:repeated_bool=>[],
|
|
|
|
:repeated_bytes=>[],
|
|
|
|
:repeated_double=>[],
|
|
|
|
:repeated_enum=>[],
|
|
|
|
:repeated_float=>[],
|
|
|
|
:repeated_int32=>[],
|
|
|
|
:repeated_int64=>[],
|
|
|
|
:repeated_msg=>[{:foo => 100}],
|
|
|
|
:repeated_string=>["bar1", "bar2"],
|
|
|
|
:repeated_uint32=>[],
|
|
|
|
:repeated_uint64=>[]
|
|
|
|
}
|
|
|
|
assert_equal expected_result, m.to_h
|
|
|
|
|
|
|
|
m = MapMessage.new(
|
|
|
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
|
|
|
:map_string_msg => {"a" => TestMessage2.new(:foo => 1),
|
|
|
|
"b" => TestMessage2.new(:foo => 2)},
|
|
|
|
:map_string_enum => {"a" => :A, "b" => :B})
|
|
|
|
expected_result = {
|
|
|
|
:map_string_int32 => {"a" => 1, "b" => 2},
|
|
|
|
:map_string_msg => {"a" => {:foo => 1}, "b" => {:foo => 2}},
|
|
|
|
:map_string_enum => {"a" => :A, "b" => :B}
|
|
|
|
}
|
|
|
|
assert_equal expected_result, m.to_h
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def test_json_maps
|
|
|
|
# TODO: Fix JSON in JRuby version.
|
|
|
|
return if RUBY_PLATFORM == "java"
|
|
|
|
m = MapMessage.new(:map_string_int32 => {"a" => 1})
|
|
|
|
expected = {mapStringInt32: {a: 1}, mapStringMsg: {}, mapStringEnum: {}}
|
|
|
|
expected_preserve = {map_string_int32: {a: 1}, map_string_msg: {}, map_string_enum: {}}
|
Ported Ruby extension to upb_msg (#8184)
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* Added some missing files.
* WIP.
* WIP.
* Updated upb.
* Extension loads, but crashes immediately.
* Gets through the test suite without SEGV!
Still a lot of bugs to fix, but it is a major step!
214 tests, 378 assertions, 37 failures, 147 errors, 0 pendings, 0 omissions, 0 notifications
14.0187% passed
* Test and build for Ruby 3.0
* Fixed a few more bugs, efficient #inspect is almost done.
214 tests, 134243 assertions, 30 failures, 144 errors, 0 pendings, 0 omissions, 0 notifications
18.6916% passed
* Fixed message hash initialization and encode depth checking.
214 tests, 124651 assertions, 53 failures, 70 errors, 0 pendings, 0 omissions, 0 notifications
42.5234% passed
* A bunch of fixes to failing tests, now 70% passing.
214 tests, 202091 assertions, 41 failures, 23 errors, 0 pendings, 0 omissions, 0 notifications
70.0935% passed
* More than 80% of tests are passing now.
214 tests, 322331 assertions, 30 failures, 9 errors, 0 pendings, 0 omissions, 0 notifications
81.7757% passed
Unfortunately there is also a sporadic bug/segfault hanging around
that appears to be GC-related.
* Add linux/ruby30 and macos/ruby30
* Use rvm master for 3.0.0-preview2
* Over 90% of tests are passing!
214 tests, 349898 assertions, 15 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
92.5234% passed
* Passes all tests!
214 tests, 369388 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
* A bunch of cleanup.
1. Removed a bunch of internal-only symbols from headers.
2. Required a frozen check to get a non-const pointer to a map or array.
3. De-duplicated the code to get a type argument for Map/RepeatedField.
* Removed a bunch more stuff from protobuf.h. There is an intermittent assert failure.
Intermittent failure:
ruby: ../../../../ext/google/protobuf_c/protobuf.c:263: ObjectCache_Add: Assertion `rb_funcall(obj_cache2, (__builtin_constant_p("[]") ? __extension__ ({ static ID rb_intern_id_cache; if (!rb_intern_id_cache) rb_intern_id_cache = rb_intern2((("[]")
), (long)strlen(("[]"))); (ID) rb_intern_id_cache; }) : rb_intern("[]")), 1, key_rb) == val' failed
* Removed a few more things from protobuf.h.
* Ruby 3.0.0-preview2 to 3.0.0
* Require rake-compiler-dock >= 1.1.0
* More progress, fighting with the object cache.
* Passes on all Ruby versions!
* Updated and clarified comment regarding WeakMap.
* Fixed the wyhash compile.
* Fixed conformance tests for Ruby.
Conformance results now look like:
RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 1955 successes, 0 skipped, 58 expected failures, 0 unexpected failures.
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 0 successes, 111 skipped, 8 expected failures, 0 unexpected failures.
Fixes include:
- Changed Ruby compiler to no longer reject proto2 maps.
- Changed Ruby compiler to emit a warning when proto2 extensions are
present instead of rejecting the .proto file completely.
- Fixed conformance tests to allow proto2 and look up message by name
instead of hardcoding a specific list of messages.
- Fixed conformance test to support the "ignore unknown" option for
JSON.
- Fixed conformance test to properly report serialization errors.
* Removed debug printf and fixed #inspect for floats.
* Fixed compatibility test to have proper semantics for #to_json.
* Updated Makefile.am with new file list.
* Don't try to copy wyhash when inside Docker.
* Fixed bug where we would forget that a sub-object is frozen in Ruby >=2.7.
* Avoid exporting unneeded symbols and refactored a bit of code.
* Some more refactoring.
* Simplified and added more comments.
* Some more comments and simplification. Added a missing license block.
Co-authored-by: Masaki Hara <hara@wantedly.com>
4 years ago
|
|
|
assert_equal JSON.parse(MapMessage.encode_json(m, :emit_defaults=>true), :symbolize_names => true), expected
|
|
|
|
|
Ported Ruby extension to upb_msg (#8184)
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* Added some missing files.
* WIP.
* WIP.
* Updated upb.
* Extension loads, but crashes immediately.
* Gets through the test suite without SEGV!
Still a lot of bugs to fix, but it is a major step!
214 tests, 378 assertions, 37 failures, 147 errors, 0 pendings, 0 omissions, 0 notifications
14.0187% passed
* Test and build for Ruby 3.0
* Fixed a few more bugs, efficient #inspect is almost done.
214 tests, 134243 assertions, 30 failures, 144 errors, 0 pendings, 0 omissions, 0 notifications
18.6916% passed
* Fixed message hash initialization and encode depth checking.
214 tests, 124651 assertions, 53 failures, 70 errors, 0 pendings, 0 omissions, 0 notifications
42.5234% passed
* A bunch of fixes to failing tests, now 70% passing.
214 tests, 202091 assertions, 41 failures, 23 errors, 0 pendings, 0 omissions, 0 notifications
70.0935% passed
* More than 80% of tests are passing now.
214 tests, 322331 assertions, 30 failures, 9 errors, 0 pendings, 0 omissions, 0 notifications
81.7757% passed
Unfortunately there is also a sporadic bug/segfault hanging around
that appears to be GC-related.
* Add linux/ruby30 and macos/ruby30
* Use rvm master for 3.0.0-preview2
* Over 90% of tests are passing!
214 tests, 349898 assertions, 15 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
92.5234% passed
* Passes all tests!
214 tests, 369388 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
* A bunch of cleanup.
1. Removed a bunch of internal-only symbols from headers.
2. Required a frozen check to get a non-const pointer to a map or array.
3. De-duplicated the code to get a type argument for Map/RepeatedField.
* Removed a bunch more stuff from protobuf.h. There is an intermittent assert failure.
Intermittent failure:
ruby: ../../../../ext/google/protobuf_c/protobuf.c:263: ObjectCache_Add: Assertion `rb_funcall(obj_cache2, (__builtin_constant_p("[]") ? __extension__ ({ static ID rb_intern_id_cache; if (!rb_intern_id_cache) rb_intern_id_cache = rb_intern2((("[]")
), (long)strlen(("[]"))); (ID) rb_intern_id_cache; }) : rb_intern("[]")), 1, key_rb) == val' failed
* Removed a few more things from protobuf.h.
* Ruby 3.0.0-preview2 to 3.0.0
* Require rake-compiler-dock >= 1.1.0
* More progress, fighting with the object cache.
* Passes on all Ruby versions!
* Updated and clarified comment regarding WeakMap.
* Fixed the wyhash compile.
* Fixed conformance tests for Ruby.
Conformance results now look like:
RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 1955 successes, 0 skipped, 58 expected failures, 0 unexpected failures.
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 0 successes, 111 skipped, 8 expected failures, 0 unexpected failures.
Fixes include:
- Changed Ruby compiler to no longer reject proto2 maps.
- Changed Ruby compiler to emit a warning when proto2 extensions are
present instead of rejecting the .proto file completely.
- Fixed conformance tests to allow proto2 and look up message by name
instead of hardcoding a specific list of messages.
- Fixed conformance test to support the "ignore unknown" option for
JSON.
- Fixed conformance test to properly report serialization errors.
* Removed debug printf and fixed #inspect for floats.
* Fixed compatibility test to have proper semantics for #to_json.
* Updated Makefile.am with new file list.
* Don't try to copy wyhash when inside Docker.
* Fixed bug where we would forget that a sub-object is frozen in Ruby >=2.7.
* Avoid exporting unneeded symbols and refactored a bit of code.
* Some more refactoring.
* Simplified and added more comments.
* Some more comments and simplification. Added a missing license block.
Co-authored-by: Masaki Hara <hara@wantedly.com>
4 years ago
|
|
|
json = MapMessage.encode_json(m, :preserve_proto_fieldnames => true, :emit_defaults=>true)
|
|
|
|
assert_equal JSON.parse(json, :symbolize_names => true), expected_preserve
|
|
|
|
|
|
|
|
m2 = MapMessage.decode_json(MapMessage.encode_json(m))
|
|
|
|
assert_equal m, m2
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_json_maps_emit_defaults_submsg
|
|
|
|
# TODO: Fix JSON in JRuby version.
|
|
|
|
return if RUBY_PLATFORM == "java"
|
Ported Ruby extension to upb_msg (#8184)
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* Added some missing files.
* WIP.
* WIP.
* Updated upb.
* Extension loads, but crashes immediately.
* Gets through the test suite without SEGV!
Still a lot of bugs to fix, but it is a major step!
214 tests, 378 assertions, 37 failures, 147 errors, 0 pendings, 0 omissions, 0 notifications
14.0187% passed
* Test and build for Ruby 3.0
* Fixed a few more bugs, efficient #inspect is almost done.
214 tests, 134243 assertions, 30 failures, 144 errors, 0 pendings, 0 omissions, 0 notifications
18.6916% passed
* Fixed message hash initialization and encode depth checking.
214 tests, 124651 assertions, 53 failures, 70 errors, 0 pendings, 0 omissions, 0 notifications
42.5234% passed
* A bunch of fixes to failing tests, now 70% passing.
214 tests, 202091 assertions, 41 failures, 23 errors, 0 pendings, 0 omissions, 0 notifications
70.0935% passed
* More than 80% of tests are passing now.
214 tests, 322331 assertions, 30 failures, 9 errors, 0 pendings, 0 omissions, 0 notifications
81.7757% passed
Unfortunately there is also a sporadic bug/segfault hanging around
that appears to be GC-related.
* Add linux/ruby30 and macos/ruby30
* Use rvm master for 3.0.0-preview2
* Over 90% of tests are passing!
214 tests, 349898 assertions, 15 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
92.5234% passed
* Passes all tests!
214 tests, 369388 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
* A bunch of cleanup.
1. Removed a bunch of internal-only symbols from headers.
2. Required a frozen check to get a non-const pointer to a map or array.
3. De-duplicated the code to get a type argument for Map/RepeatedField.
* Removed a bunch more stuff from protobuf.h. There is an intermittent assert failure.
Intermittent failure:
ruby: ../../../../ext/google/protobuf_c/protobuf.c:263: ObjectCache_Add: Assertion `rb_funcall(obj_cache2, (__builtin_constant_p("[]") ? __extension__ ({ static ID rb_intern_id_cache; if (!rb_intern_id_cache) rb_intern_id_cache = rb_intern2((("[]")
), (long)strlen(("[]"))); (ID) rb_intern_id_cache; }) : rb_intern("[]")), 1, key_rb) == val' failed
* Removed a few more things from protobuf.h.
* Ruby 3.0.0-preview2 to 3.0.0
* Require rake-compiler-dock >= 1.1.0
* More progress, fighting with the object cache.
* Passes on all Ruby versions!
* Updated and clarified comment regarding WeakMap.
* Fixed the wyhash compile.
* Fixed conformance tests for Ruby.
Conformance results now look like:
RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 1955 successes, 0 skipped, 58 expected failures, 0 unexpected failures.
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 0 successes, 111 skipped, 8 expected failures, 0 unexpected failures.
Fixes include:
- Changed Ruby compiler to no longer reject proto2 maps.
- Changed Ruby compiler to emit a warning when proto2 extensions are
present instead of rejecting the .proto file completely.
- Fixed conformance tests to allow proto2 and look up message by name
instead of hardcoding a specific list of messages.
- Fixed conformance test to support the "ignore unknown" option for
JSON.
- Fixed conformance test to properly report serialization errors.
* Removed debug printf and fixed #inspect for floats.
* Fixed compatibility test to have proper semantics for #to_json.
* Updated Makefile.am with new file list.
* Don't try to copy wyhash when inside Docker.
* Fixed bug where we would forget that a sub-object is frozen in Ruby >=2.7.
* Avoid exporting unneeded symbols and refactored a bit of code.
* Some more refactoring.
* Simplified and added more comments.
* Some more comments and simplification. Added a missing license block.
Co-authored-by: Masaki Hara <hara@wantedly.com>
4 years ago
|
|
|
m = MapMessage.new(:map_string_msg => {"a" => TestMessage2.new(foo: 0)})
|
|
|
|
expected = {mapStringInt32: {}, mapStringMsg: {a: {foo: 0}}, mapStringEnum: {}}
|
|
|
|
|
|
|
|
actual = MapMessage.encode_json(m, :emit_defaults => true)
|
|
|
|
|
|
|
|
assert_equal JSON.parse(actual, :symbolize_names => true), expected
|
|
|
|
end
|
|
|
|
|
Ported Ruby extension to upb_msg (#8184)
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* WIP.
* Added some missing files.
* WIP.
* WIP.
* Updated upb.
* Extension loads, but crashes immediately.
* Gets through the test suite without SEGV!
Still a lot of bugs to fix, but it is a major step!
214 tests, 378 assertions, 37 failures, 147 errors, 0 pendings, 0 omissions, 0 notifications
14.0187% passed
* Test and build for Ruby 3.0
* Fixed a few more bugs, efficient #inspect is almost done.
214 tests, 134243 assertions, 30 failures, 144 errors, 0 pendings, 0 omissions, 0 notifications
18.6916% passed
* Fixed message hash initialization and encode depth checking.
214 tests, 124651 assertions, 53 failures, 70 errors, 0 pendings, 0 omissions, 0 notifications
42.5234% passed
* A bunch of fixes to failing tests, now 70% passing.
214 tests, 202091 assertions, 41 failures, 23 errors, 0 pendings, 0 omissions, 0 notifications
70.0935% passed
* More than 80% of tests are passing now.
214 tests, 322331 assertions, 30 failures, 9 errors, 0 pendings, 0 omissions, 0 notifications
81.7757% passed
Unfortunately there is also a sporadic bug/segfault hanging around
that appears to be GC-related.
* Add linux/ruby30 and macos/ruby30
* Use rvm master for 3.0.0-preview2
* Over 90% of tests are passing!
214 tests, 349898 assertions, 15 failures, 1 errors, 0 pendings, 0 omissions, 0 notifications
92.5234% passed
* Passes all tests!
214 tests, 369388 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
* A bunch of cleanup.
1. Removed a bunch of internal-only symbols from headers.
2. Required a frozen check to get a non-const pointer to a map or array.
3. De-duplicated the code to get a type argument for Map/RepeatedField.
* Removed a bunch more stuff from protobuf.h. There is an intermittent assert failure.
Intermittent failure:
ruby: ../../../../ext/google/protobuf_c/protobuf.c:263: ObjectCache_Add: Assertion `rb_funcall(obj_cache2, (__builtin_constant_p("[]") ? __extension__ ({ static ID rb_intern_id_cache; if (!rb_intern_id_cache) rb_intern_id_cache = rb_intern2((("[]")
), (long)strlen(("[]"))); (ID) rb_intern_id_cache; }) : rb_intern("[]")), 1, key_rb) == val' failed
* Removed a few more things from protobuf.h.
* Ruby 3.0.0-preview2 to 3.0.0
* Require rake-compiler-dock >= 1.1.0
* More progress, fighting with the object cache.
* Passes on all Ruby versions!
* Updated and clarified comment regarding WeakMap.
* Fixed the wyhash compile.
* Fixed conformance tests for Ruby.
Conformance results now look like:
RUBYLIB=../ruby/lib:. ./conformance-test-runner --enforce_recommended --failure_list failure_list_ruby.txt --text_format_failure_list text_format_failure_list_ruby.txt ./conformance_ruby.rb
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 1955 successes, 0 skipped, 58 expected failures, 0 unexpected failures.
CONFORMANCE TEST BEGIN ====================================
CONFORMANCE SUITE PASSED: 0 successes, 111 skipped, 8 expected failures, 0 unexpected failures.
Fixes include:
- Changed Ruby compiler to no longer reject proto2 maps.
- Changed Ruby compiler to emit a warning when proto2 extensions are
present instead of rejecting the .proto file completely.
- Fixed conformance tests to allow proto2 and look up message by name
instead of hardcoding a specific list of messages.
- Fixed conformance test to support the "ignore unknown" option for
JSON.
- Fixed conformance test to properly report serialization errors.
* Removed debug printf and fixed #inspect for floats.
* Fixed compatibility test to have proper semantics for #to_json.
* Updated Makefile.am with new file list.
* Don't try to copy wyhash when inside Docker.
* Fixed bug where we would forget that a sub-object is frozen in Ruby >=2.7.
* Avoid exporting unneeded symbols and refactored a bit of code.
* Some more refactoring.
* Simplified and added more comments.
* Some more comments and simplification. Added a missing license block.
Co-authored-by: Masaki Hara <hara@wantedly.com>
4 years ago
|
|
|
def test_json_emit_defaults_submsg
|
|
|
|
# TODO: Fix JSON in JRuby version.
|
|
|
|
return if RUBY_PLATFORM == "java"
|
|
|
|
m = TestSingularFields.new(singular_msg: proto_module::TestMessage2.new)
|
|
|
|
|
|
|
|
expected = {
|
|
|
|
singularInt32: 0,
|
|
|
|
singularInt64: "0",
|
|
|
|
singularUint32: 0,
|
|
|
|
singularUint64: "0",
|
|
|
|
singularBool: false,
|
|
|
|
singularFloat: 0,
|
|
|
|
singularDouble: 0,
|
|
|
|
singularString: "",
|
|
|
|
singularBytes: "",
|
|
|
|
singularMsg: {},
|
|
|
|
singularEnum: "Default",
|
|
|
|
}
|
|
|
|
|
|
|
|
actual = proto_module::TestMessage.encode_json(m, :emit_defaults => true)
|
|
|
|
|
|
|
|
assert_equal expected, JSON.parse(actual, :symbolize_names => true)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_respond_to
|
|
|
|
# This test fails with JRuby 1.7.23, likely because of an old JRuby bug.
|
|
|
|
return if RUBY_PLATFORM == "java"
|
|
|
|
msg = MapMessage.new
|
|
|
|
assert msg.respond_to?(:map_string_int32)
|
|
|
|
assert !msg.respond_to?(:bacon)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_file_descriptor
|
|
|
|
file_descriptor = TestMessage.descriptor.file_descriptor
|
|
|
|
assert nil != file_descriptor
|
|
|
|
assert_equal "tests/basic_test.proto", file_descriptor.name
|
|
|
|
assert_equal :proto3, file_descriptor.syntax
|
|
|
|
|
|
|
|
file_descriptor = TestEnum.descriptor.file_descriptor
|
|
|
|
assert nil != file_descriptor
|
|
|
|
assert_equal "tests/basic_test.proto", file_descriptor.name
|
|
|
|
assert_equal :proto3, file_descriptor.syntax
|
|
|
|
end
|
|
|
|
|
|
|
|
# Ruby 2.5 changed to raise FrozenError instead of RuntimeError
|
|
|
|
FrozenErrorType = Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.5') ? RuntimeError : FrozenError
|
|
|
|
|
|
|
|
def test_map_freeze
|
|
|
|
m = proto_module::MapMessage.new
|
|
|
|
m.map_string_int32['a'] = 5
|
|
|
|
m.map_string_msg['b'] = proto_module::TestMessage2.new
|
|
|
|
|
|
|
|
m.map_string_int32.freeze
|
|
|
|
m.map_string_msg.freeze
|
|
|
|
|
|
|
|
assert m.map_string_int32.frozen?
|
|
|
|
assert m.map_string_msg.frozen?
|
|
|
|
|
|
|
|
assert_raise(FrozenErrorType) { m.map_string_int32['foo'] = 1 }
|
|
|
|
assert_raise(FrozenErrorType) { m.map_string_msg['bar'] = proto_module::TestMessage2.new }
|
|
|
|
assert_raise(FrozenErrorType) { m.map_string_int32.delete('a') }
|
|
|
|
assert_raise(FrozenErrorType) { m.map_string_int32.clear }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|