protobuf 2.8.0.beta9 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +0 -1
- data/{UPGRADING.md → CHANGES.md} +20 -12
- data/LICENSE.txt +14 -0
- data/README.md +60 -74
- data/bin/protoc-gen-ruby +26 -0
- data/bin/rprotoc +4 -58
- data/lib/protobuf.rb +15 -13
- data/lib/protobuf/code_generator.rb +41 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +51 -0
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +248 -0
- data/lib/protobuf/field/base_field.rb +0 -1
- data/lib/protobuf/field/bytes_field.rb +1 -1
- data/lib/protobuf/field/message_field.rb +2 -4
- data/lib/protobuf/field/varint_field.rb +4 -7
- data/lib/protobuf/generators/base.rb +71 -0
- data/lib/protobuf/generators/enum_generator.rb +31 -0
- data/lib/protobuf/generators/extension_generator.rb +28 -0
- data/lib/protobuf/generators/field_generator.rb +132 -0
- data/lib/protobuf/generators/file_generator.rb +140 -0
- data/lib/protobuf/generators/group_generator.rb +113 -0
- data/lib/protobuf/generators/message_generator.rb +99 -0
- data/lib/protobuf/generators/printable.rb +161 -0
- data/lib/protobuf/generators/service_generator.rb +27 -0
- data/lib/protobuf/lifecycle.rb +7 -3
- data/lib/protobuf/message.rb +51 -34
- data/lib/protobuf/rpc/connectors/common.rb +4 -6
- data/lib/protobuf/rpc/server.rb +1 -1
- data/lib/protobuf/rpc/servers/zmq/server.rb +2 -2
- data/lib/protobuf/rpc/servers/zmq/worker.rb +2 -2
- data/lib/protobuf/rpc/service.rb +3 -3
- data/lib/protobuf/rpc/service_directory.rb +24 -12
- data/lib/protobuf/version.rb +1 -1
- data/proto/google/protobuf/compiler/plugin.proto +147 -0
- data/proto/google/protobuf/descriptor.proto +620 -0
- data/protobuf.gemspec +12 -21
- data/spec/bin/protoc-gen-ruby_spec.rb +18 -0
- data/spec/data/data.bin +3 -0
- data/{test/data/unk.png → spec/data/types.bin} +0 -0
- data/spec/encoding/all_types_spec.rb +91 -0
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/lib/protobuf/code_generator_spec.rb +60 -0
- data/spec/lib/protobuf/generators/base_spec.rb +87 -0
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +45 -0
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +43 -0
- data/spec/lib/protobuf/generators/field_generator_spec.rb +99 -0
- data/spec/lib/protobuf/generators/file_generator_spec.rb +29 -0
- data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
- data/spec/lib/protobuf/generators/service_generator_spec.rb +43 -0
- data/spec/lib/protobuf/lifecycle_spec.rb +31 -1
- data/spec/lib/protobuf/logger_spec.rb +5 -0
- data/spec/lib/protobuf/message_spec.rb +22 -8
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +1 -1
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +45 -7
- data/spec/lib/protobuf/rpc/service_spec.rb +3 -3
- data/spec/spec_helper.rb +15 -16
- data/spec/support/test/all_types.data.bin +0 -0
- data/spec/support/test/all_types.data.txt +119 -0
- data/spec/support/test/defaults.pb.rb +25 -0
- data/spec/support/test/defaults.proto +9 -0
- data/spec/support/test/enum.pb.rb +10 -8
- data/spec/support/test/extended.pb.rb +5 -3
- data/spec/support/test/extreme_values.data.bin +0 -0
- data/spec/support/test/google_unittest.pb.rb +543 -0
- data/spec/support/test/google_unittest.proto +713 -0
- data/spec/support/test/google_unittest_import.pb.rb +37 -0
- data/{ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h → spec/support/test/google_unittest_import.proto} +27 -17
- data/spec/support/test/google_unittest_import_public.pb.rb +8 -0
- data/{ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h → spec/support/test/google_unittest_import_public.proto} +5 -31
- data/spec/support/test/multi_field_extensions.pb.rb +29 -7
- data/spec/support/test/multi_field_extensions.proto +12 -2
- data/spec/support/test/resource.pb.rb +20 -16
- metadata +149 -236
- data/examples/addressbook.pb.rb +0 -55
- data/examples/addressbook.proto +0 -24
- data/examples/reading_a_message.rb +0 -32
- data/examples/writing_a_message.rb +0 -46
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +0 -142
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +0 -318
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +0 -99
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +0 -103
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +0 -85
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +0 -167
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +0 -98
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +0 -72
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +0 -159
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +0 -170
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +0 -102
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +0 -103
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +0 -118
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +0 -104
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +0 -2721
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +0 -303
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +0 -84
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +0 -121
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +0 -77
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +0 -108
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +0 -101
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +0 -72
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +0 -213
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +0 -109
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +0 -134
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +0 -121
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +0 -113
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +0 -120
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +0 -113
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +0 -64
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +0 -434
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +0 -73
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +0 -790
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +0 -156
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +0 -108
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +0 -93
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +0 -1367
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +0 -5223
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +0 -366
- data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +0 -136
- data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +0 -904
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +0 -424
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +0 -82
- data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +0 -1102
- data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +0 -207
- data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +0 -136
- data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +0 -313
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +0 -238
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +0 -357
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +0 -340
- data/ext/protobuf-2.4.1/src/google/protobuf/message.h +0 -692
- data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +0 -239
- data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +0 -64
- data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +0 -80
- data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +0 -1295
- data/ext/protobuf-2.4.1/src/google/protobuf/service.h +0 -291
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +0 -1211
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +0 -220
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +0 -119
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +0 -123
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +0 -121
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +0 -457
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +0 -170
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +0 -174
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +0 -101
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +0 -83
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +0 -98
- data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +0 -285
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +0 -11915
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +0 -2895
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +0 -211
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +0 -56
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +0 -188
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +0 -151
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +0 -4752
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +0 -150
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +0 -816
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +0 -197
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +0 -403
- data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +0 -268
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +0 -304
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +0 -620
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +0 -774
- data/ext/ruby_generator/Makefile +0 -10
- data/ext/ruby_generator/RubyGenerator.cpp +0 -544
- data/ext/ruby_generator/RubyGenerator.h +0 -206
- data/ext/ruby_generator/extconf.rb +0 -35
- data/test/data/data_source.py +0 -14
- data/test/data/types_source.py +0 -22
- data/test/proto/addressbook.pb.rb +0 -66
- data/test/proto/addressbook.proto +0 -33
- data/test/proto/addressbook_base.pb.rb +0 -58
- data/test/proto/addressbook_base.proto +0 -26
- data/test/proto/addressbook_ext.pb.rb +0 -20
- data/test/proto/addressbook_ext.proto +0 -6
- data/test/proto/collision.pb.rb +0 -17
- data/test/proto/collision.proto +0 -5
- data/test/proto/ext_collision.pb.rb +0 -24
- data/test/proto/ext_collision.proto +0 -8
- data/test/proto/ext_range.pb.rb +0 -22
- data/test/proto/ext_range.proto +0 -7
- data/test/proto/float_default.proto +0 -10
- data/test/proto/lowercase.pb.rb +0 -30
- data/test/proto/lowercase.proto +0 -9
- data/test/proto/merge.pb.rb +0 -39
- data/test/proto/merge.proto +0 -15
- data/test/proto/nested.pb.rb +0 -30
- data/test/proto/nested.proto +0 -9
- data/test/proto/optional_field.pb.rb +0 -35
- data/test/proto/optional_field.proto +0 -12
- data/test/proto/packed.pb.rb +0 -22
- data/test/proto/packed.proto +0 -6
- data/test/proto/rpc.proto +0 -6
- data/test/proto/types.pb.rb +0 -84
- data/test/proto/types.proto +0 -37
- data/test/test_addressbook.rb +0 -56
- data/test/test_enum_value.rb +0 -41
- data/test/test_extension.rb +0 -36
- data/test/test_lowercase.rb +0 -11
- data/test/test_message.rb +0 -128
- data/test/test_optional_field.rb +0 -103
- data/test/test_packed_field.rb +0 -40
- data/test/test_parse.rb +0 -15
- data/test/test_repeated_types.rb +0 -132
- data/test/test_serialize.rb +0 -61
- data/test/test_standard_message.rb +0 -96
- data/test/test_types.rb +0 -226
data/test/proto/types.proto
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
package test.types;
|
2
|
-
|
3
|
-
message TestTypes {
|
4
|
-
required double type1 = 1;
|
5
|
-
required float type2 = 2;
|
6
|
-
required int32 type3 = 3;
|
7
|
-
required int64 type4 = 4;
|
8
|
-
required uint32 type5 = 5;
|
9
|
-
required uint64 type6 = 6;
|
10
|
-
required sint32 type7 = 7;
|
11
|
-
required sint64 type8 = 8;
|
12
|
-
required fixed32 type9 = 9;
|
13
|
-
required fixed64 type10 = 10;
|
14
|
-
required bool type11 = 11;
|
15
|
-
required string type12 = 12;
|
16
|
-
required bytes type13 = 13;
|
17
|
-
required sfixed32 type14 = 14;
|
18
|
-
required sfixed64 type15 = 15;
|
19
|
-
}
|
20
|
-
|
21
|
-
message RepeatedTypes {
|
22
|
-
repeated double type1 = 1;
|
23
|
-
repeated float type2 = 2;
|
24
|
-
repeated int32 type3 = 3;
|
25
|
-
repeated int64 type4 = 4;
|
26
|
-
repeated uint32 type5 = 5;
|
27
|
-
repeated uint64 type6 = 6;
|
28
|
-
repeated sint32 type7 = 7;
|
29
|
-
repeated sint64 type8 = 8;
|
30
|
-
repeated fixed32 type9 = 9;
|
31
|
-
repeated fixed64 type10 = 10;
|
32
|
-
repeated bool type11 = 11;
|
33
|
-
repeated string type12 = 12;
|
34
|
-
repeated bytes type13 = 13;
|
35
|
-
repeated sfixed32 type14 = 14;
|
36
|
-
repeated sfixed64 type15 = 15;
|
37
|
-
}
|
data/test/test_addressbook.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'protobuf/message/message'
|
3
|
-
require 'protobuf/enum'
|
4
|
-
require 'test/proto/addressbook.pb'
|
5
|
-
|
6
|
-
class AddressbookTest < Test::Unit::TestCase
|
7
|
-
def test_enum
|
8
|
-
phone_number = Tutorial::Person::PhoneNumber.new
|
9
|
-
assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type)
|
10
|
-
phone_number.type = Tutorial::Person::PhoneType::MOBILE
|
11
|
-
assert_equal(0, phone_number.type)
|
12
|
-
phone_number.type = Tutorial::Person::PhoneType::HOME
|
13
|
-
assert_equal(1, phone_number.type)
|
14
|
-
phone_number.type = Tutorial::Person::PhoneType::WORK
|
15
|
-
assert_equal(2, phone_number.type)
|
16
|
-
assert_raise(TypeError) do
|
17
|
-
phone_number.type = 3
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_symbol_enum
|
22
|
-
phone_number = Tutorial::Person::PhoneNumber.new
|
23
|
-
assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type)
|
24
|
-
phone_number.type = :MOBILE
|
25
|
-
assert_equal(0, phone_number.type)
|
26
|
-
phone_number.type = :HOME
|
27
|
-
assert_equal(1, phone_number.type)
|
28
|
-
phone_number.type = :WORK
|
29
|
-
assert_equal(2, phone_number.type)
|
30
|
-
assert_raise(TypeError) do
|
31
|
-
phone_number.type = :UNKNOWN
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_initial_value
|
36
|
-
person = Tutorial::Person.new
|
37
|
-
assert_nil(person.name)
|
38
|
-
assert_nil(person.id)
|
39
|
-
assert_equal([], person.phone)
|
40
|
-
assert_equal('', person.email)
|
41
|
-
end
|
42
|
-
|
43
|
-
def test_repeatable
|
44
|
-
address_book = Tutorial::AddressBook.new
|
45
|
-
assert_equal([], address_book.person)
|
46
|
-
assert_instance_of(Protobuf::Field::FieldArray, address_book.person)
|
47
|
-
address_book.person << Tutorial::Person.new
|
48
|
-
assert_equal(1, address_book.person.size)
|
49
|
-
assert_raise(TypeError) do
|
50
|
-
address_book.person << 1
|
51
|
-
end
|
52
|
-
assert_equal(1, address_book.person.size)
|
53
|
-
address_book.person << Tutorial::Person.new
|
54
|
-
assert_equal(2, address_book.person.size)
|
55
|
-
end
|
56
|
-
end
|
data/test/test_enum_value.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'protobuf/message/message'
|
3
|
-
require 'protobuf/enum'
|
4
|
-
require 'test/proto/addressbook.pb'
|
5
|
-
require 'test/proto/addressbook_base.pb'
|
6
|
-
|
7
|
-
class EnumValueTest < Test::Unit::TestCase
|
8
|
-
def test_enum_value
|
9
|
-
e = Protobuf::EnumValue.new(Object, :name, 100)
|
10
|
-
assert_kind_of(Protobuf::EnumValue, e)
|
11
|
-
assert_equal(:name, e.name)
|
12
|
-
assert_equal(100, e.value)
|
13
|
-
assert_equal('name', e.to_s)
|
14
|
-
assert_equal('name', "#{e}")
|
15
|
-
assert(e == 100)
|
16
|
-
assert(100 == e)
|
17
|
-
assert(101, e + 1)
|
18
|
-
assert(101, 1 + e)
|
19
|
-
end
|
20
|
-
|
21
|
-
def test_enum_field_and_enum_value
|
22
|
-
phone_number = Tutorial::Person::PhoneNumber.new
|
23
|
-
|
24
|
-
assert_kind_of(Protobuf::EnumValue, phone_number.type)
|
25
|
-
assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type)
|
26
|
-
|
27
|
-
phone_number.type = 1
|
28
|
-
assert_kind_of(Protobuf::EnumValue, phone_number.type)
|
29
|
-
assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type)
|
30
|
-
assert_equal(1, phone_number.type)
|
31
|
-
|
32
|
-
phone_number.type = :HOME
|
33
|
-
assert_kind_of(Protobuf::EnumValue, phone_number.type)
|
34
|
-
assert_equal(Tutorial::Person::PhoneType::HOME, phone_number.type)
|
35
|
-
assert_equal(1, phone_number.type)
|
36
|
-
|
37
|
-
assert_raise(TypeError) do
|
38
|
-
phone_number.type = TutorialExt::Person::PhoneType::HOME
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
data/test/test_extension.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test/proto/addressbook_ext.pb'
|
3
|
-
|
4
|
-
class ExtensionTest < Test::Unit::TestCase
|
5
|
-
def test_accessor
|
6
|
-
assert(TutorialExt::Person.extension_fields.to_a.map{|t, f| f.name}.include?(:age))
|
7
|
-
person = TutorialExt::Person.new
|
8
|
-
assert_nothing_raised {person.age = 100}
|
9
|
-
assert_equal(100, person.age)
|
10
|
-
end
|
11
|
-
|
12
|
-
def test_serialize
|
13
|
-
# serialize to string
|
14
|
-
person = TutorialExt::Person.new
|
15
|
-
person.id = 1234
|
16
|
-
person.age = 70
|
17
|
-
person.name = 'John Doe'
|
18
|
-
person.email = 'jdoe@example.com'
|
19
|
-
phone = TutorialExt::Person::PhoneNumber.new
|
20
|
-
phone.number = '555-4321'
|
21
|
-
phone.type = TutorialExt::Person::PhoneType::HOME
|
22
|
-
person.phone << phone
|
23
|
-
serialized_string = person.serialize_to_string
|
24
|
-
|
25
|
-
# parse the serialized string
|
26
|
-
person2 = TutorialExt::Person.new
|
27
|
-
person2.parse_from_string serialized_string
|
28
|
-
assert_equal(1234, person2.id)
|
29
|
-
assert_equal(70, person2.age)
|
30
|
-
assert_equal('John Doe', person2.name)
|
31
|
-
assert_equal('jdoe@example.com', person2.email)
|
32
|
-
assert_equal(1, person2.phone.size)
|
33
|
-
assert_equal('555-4321', person2.phone[0].number)
|
34
|
-
assert_equal(TutorialExt::Person::PhoneType::HOME, person2.phone[0].type)
|
35
|
-
end
|
36
|
-
end
|
data/test/test_lowercase.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test/proto/lowercase.pb'
|
3
|
-
|
4
|
-
class LowercaseTest < Test::Unit::TestCase
|
5
|
-
def test_lowercase
|
6
|
-
message = nil
|
7
|
-
assert_nothing_raised { message = Test::Lowercase::Baaz.new }
|
8
|
-
assert_nothing_raised { message.x = Test::Lowercase::Foo::Bar.new }
|
9
|
-
assert_equal(Test::Lowercase::Foo::Bar, message.get_field_by_name(:x).type)
|
10
|
-
end
|
11
|
-
end
|
data/test/test_message.rb
DELETED
@@ -1,128 +0,0 @@
|
|
1
|
-
require 'protobuf/message/message'
|
2
|
-
require 'test/proto/addressbook.pb'
|
3
|
-
require 'test/proto/merge.pb'
|
4
|
-
require 'test/unit'
|
5
|
-
|
6
|
-
# It should not conflict with Test::InnerMessage1 which is included in merge.proto
|
7
|
-
class InnerMessage1; end
|
8
|
-
|
9
|
-
class MessageTest < Test::Unit::TestCase
|
10
|
-
def test_equality
|
11
|
-
person1 = Tutorial::Person.new :name => 'ando'
|
12
|
-
person2 = Tutorial::Person.new :name => 'ando'
|
13
|
-
person3 = Tutorial::Person.new :name => 'Ando'
|
14
|
-
assert(person1 == person2)
|
15
|
-
assert(person1 != person3)
|
16
|
-
assert(person1 != 'ando')
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_bracketed_access
|
20
|
-
person = Tutorial::Person.new
|
21
|
-
name_tag = 1
|
22
|
-
person[name_tag] = 'Ichiro'
|
23
|
-
assert_equal('Ichiro', person.name)
|
24
|
-
assert_equal('Ichiro', person[name_tag])
|
25
|
-
|
26
|
-
person[:id] = 100
|
27
|
-
assert_equal(100, person.id)
|
28
|
-
person['id'] = 200
|
29
|
-
assert_equal(200, person.id)
|
30
|
-
assert_equal(200, person[:id])
|
31
|
-
assert_equal(200, person['id'])
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_initialize_with_hash
|
35
|
-
person = Tutorial::Person.new(:name => 'Jiro', :id => 300, :email => 'jiro@ema.il')
|
36
|
-
assert_equal('Jiro', person.name)
|
37
|
-
assert_equal(300, person.id)
|
38
|
-
assert_equal('jiro@ema.il', person.email)
|
39
|
-
|
40
|
-
# initialize with array of hash
|
41
|
-
person = Tutorial::Person.new(:phone => [{:number => 'phone1'}, {:number => 'phone2'}])
|
42
|
-
assert_equal('phone1', person.phone[0].number)
|
43
|
-
assert_equal('phone2', person.phone[1].number)
|
44
|
-
|
45
|
-
# initalize with hash in hash
|
46
|
-
message = Test::MergeMessage.new(:require_message => { :name => 'name1', :repeate_message => [{:name => 'name2'}] })
|
47
|
-
assert_equal('name1', message.require_message.name)
|
48
|
-
assert_equal('name2', message.require_message.repeate_message[0].name)
|
49
|
-
|
50
|
-
message.require_message = { :name => 'name21' }
|
51
|
-
message.require_message.repeate_message = [ {:name => 'name22'} ]
|
52
|
-
assert_equal('name21', message.require_message.name)
|
53
|
-
assert_equal('name22', message.require_message.repeate_message[0].name)
|
54
|
-
assert_equal(1, message.require_message.repeate_message.size)
|
55
|
-
end
|
56
|
-
|
57
|
-
def test_defined_filenames
|
58
|
-
assert(Tutorial::Person.defined_filenames)
|
59
|
-
assert_equal(1, Tutorial::Person.defined_filenames.size)
|
60
|
-
assert_match(%r{/.*/proto/addressbook\.pb\.rb}, Tutorial::Person.defined_filenames.first)
|
61
|
-
end
|
62
|
-
|
63
|
-
def test_proto_filenames
|
64
|
-
assert(Tutorial::Person.proto_filenames)
|
65
|
-
assert_equal(1, Tutorial::Person.proto_filenames.size)
|
66
|
-
assert_equal('test/proto/addressbook.proto', Tutorial::Person.proto_filenames.first)
|
67
|
-
end
|
68
|
-
|
69
|
-
def test_proto_contents
|
70
|
-
assert_equal(<<-EOS.strip, Tutorial::Person.proto_contents.values.first.strip)
|
71
|
-
package tutorial;
|
72
|
-
|
73
|
-
message Person {
|
74
|
-
required string name = 1;
|
75
|
-
required int32 id = 2;
|
76
|
-
optional string email = 3;
|
77
|
-
|
78
|
-
enum PhoneType {
|
79
|
-
MOBILE = 0;
|
80
|
-
HOME = 1;
|
81
|
-
WORK = 2;
|
82
|
-
}
|
83
|
-
|
84
|
-
message PhoneNumber {
|
85
|
-
required string number = 1;
|
86
|
-
optional PhoneType type = 2 [default = HOME];
|
87
|
-
}
|
88
|
-
|
89
|
-
repeated PhoneNumber phone = 4;
|
90
|
-
optional uint32 age = 5 [default = 20];
|
91
|
-
|
92
|
-
extensions 100 to 200;
|
93
|
-
}
|
94
|
-
|
95
|
-
/*
|
96
|
-
extend Person {
|
97
|
-
optional int32 age = 100;
|
98
|
-
}
|
99
|
-
*/
|
100
|
-
|
101
|
-
message AddressBook {
|
102
|
-
repeated Person person = 1;
|
103
|
-
}
|
104
|
-
EOS
|
105
|
-
end
|
106
|
-
|
107
|
-
def test_merge_field
|
108
|
-
inner_message1_2 = Test::MergeMessage::InnerMessage2.new(:name => 'name12')
|
109
|
-
inner_message1_2.repeate_message << Test::MergeMessage::InnerMessage1.new(:name => 'name121')
|
110
|
-
message1 = Test::MergeMessage.new(:name => 'name1', :require_message => inner_message1_2)
|
111
|
-
message1.repeate_message << Test::MergeMessage::InnerMessage1.new(:name => 'name11')
|
112
|
-
|
113
|
-
inner_message2_2 = Test::MergeMessage::InnerMessage2.new(:name => 'name22')
|
114
|
-
inner_message2_2.repeate_message << Test::MergeMessage::InnerMessage1.new(:name => 'name221')
|
115
|
-
message2 = Test::MergeMessage.new(:name => 'name2', :require_message => inner_message2_2)
|
116
|
-
message2.repeate_message << Test::MergeMessage::InnerMessage1.new(:name => 'name21')
|
117
|
-
|
118
|
-
message1.merge_from(message2)
|
119
|
-
assert_equal('name2', message1.name)
|
120
|
-
assert_equal(2, message1.repeate_message.size)
|
121
|
-
assert_equal('name11', message1.repeate_message[0].name)
|
122
|
-
assert_equal('name21', message1.repeate_message[1].name)
|
123
|
-
assert_equal('name22', message1.require_message.name)
|
124
|
-
assert_equal(2, message1.require_message.repeate_message.size)
|
125
|
-
assert_equal('name121', message1.require_message.repeate_message[0].name)
|
126
|
-
assert_equal('name221', message1.require_message.repeate_message[1].name)
|
127
|
-
end
|
128
|
-
end
|
data/test/test_optional_field.rb
DELETED
@@ -1,103 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test/proto/optional_field.pb'
|
3
|
-
|
4
|
-
class OptionalFieldTest < Test::Unit::TestCase
|
5
|
-
def test_accessor
|
6
|
-
message = Test::OptionalField::Message.new
|
7
|
-
|
8
|
-
# default values
|
9
|
-
assert(!message.has_field?(:number))
|
10
|
-
assert_equal(20, message.number)
|
11
|
-
|
12
|
-
assert(!message.has_field?(:text))
|
13
|
-
assert_equal('default string', message.text)
|
14
|
-
|
15
|
-
assert(!message.has_field?(:enum))
|
16
|
-
assert_equal(2, message.enum)
|
17
|
-
|
18
|
-
assert(!message.has_field?(:signed))
|
19
|
-
assert_equal(-100, message.signed)
|
20
|
-
|
21
|
-
# assign values
|
22
|
-
assert_nothing_raised { message.number = 100 }
|
23
|
-
assert(message.has_field?(:number))
|
24
|
-
assert_equal(100, message.number)
|
25
|
-
|
26
|
-
assert_nothing_raised { message.text = 'abc' }
|
27
|
-
assert(message.has_field?(:text))
|
28
|
-
assert_equal('abc', message.text)
|
29
|
-
|
30
|
-
assert_nothing_raised { message.enum = Test::OptionalField::Message::Enum::A }
|
31
|
-
assert(message.has_field?(:enum))
|
32
|
-
assert_equal(1, message.enum)
|
33
|
-
|
34
|
-
assert_nothing_raised { message.signed = -20 }
|
35
|
-
assert(message.has_field?(:signed))
|
36
|
-
assert_equal(-20, message.signed)
|
37
|
-
end
|
38
|
-
|
39
|
-
def test_serialize
|
40
|
-
message1 = Test::OptionalField::Message.new
|
41
|
-
message2 = Test::OptionalField::Message.new
|
42
|
-
|
43
|
-
# all fields are empty
|
44
|
-
serialized_string = message1.to_s
|
45
|
-
assert(serialized_string.empty?)
|
46
|
-
message2.parse_from_string(serialized_string)
|
47
|
-
assert_equal(message1.number, message2.number)
|
48
|
-
assert_equal(message1.text, message2.text)
|
49
|
-
assert_equal(message1.enum, message2.enum)
|
50
|
-
assert_equal(message1.signed, message2.signed)
|
51
|
-
assert(!message2.has_field?(:number))
|
52
|
-
assert(!message2.has_field?(:text))
|
53
|
-
assert(!message2.has_field?(:enum))
|
54
|
-
assert(!message2.has_field?(:signed))
|
55
|
-
|
56
|
-
# assign the value whith is equal to default value
|
57
|
-
message1 = Test::OptionalField::Message.new
|
58
|
-
message1.number = message1.number
|
59
|
-
message1.text = message1.text
|
60
|
-
message1.enum = message1.enum
|
61
|
-
message1.signed = message1.signed
|
62
|
-
serialized_string = message1.to_s
|
63
|
-
assert !serialized_string.empty?
|
64
|
-
|
65
|
-
# set some fields
|
66
|
-
message1 = Test::OptionalField::Message.new
|
67
|
-
message1.number = 100
|
68
|
-
message1.text = 'new text'
|
69
|
-
serialized_string = message1.to_s
|
70
|
-
message2.parse_from_string(serialized_string)
|
71
|
-
assert_equal(message1.number, message2.number)
|
72
|
-
assert_equal(message1.text, message2.text)
|
73
|
-
assert_equal(message1.enum, message2.enum)
|
74
|
-
assert_equal(message1.signed, message2.signed)
|
75
|
-
assert( message2.has_field?(:number))
|
76
|
-
assert( message2.has_field?(:text))
|
77
|
-
assert(!message2.has_field?(:enum))
|
78
|
-
assert(!message2.has_field?(:signed))
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_merge_optional_fields
|
82
|
-
src1 = Test::OptionalField::Message.new
|
83
|
-
src2 = Test::OptionalField::Message.new
|
84
|
-
dst = Test::OptionalField::Message.new
|
85
|
-
|
86
|
-
src1.number = 100
|
87
|
-
src1.text = 'old'
|
88
|
-
src2.text = 'new'
|
89
|
-
src2.signed = 20
|
90
|
-
|
91
|
-
serialized_string = src1.to_s + src2.to_s
|
92
|
-
dst.parse_from_string(serialized_string)
|
93
|
-
|
94
|
-
assert_equal(100, dst.number)
|
95
|
-
assert_equal('new', dst.text)
|
96
|
-
assert_equal(20, dst.signed)
|
97
|
-
assert dst.has_field?(:number)
|
98
|
-
assert dst.has_field?(:text)
|
99
|
-
assert !dst.has_field?(:enum)
|
100
|
-
assert dst.has_field?(:signed)
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
data/test/test_packed_field.rb
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'test/proto/packed.pb'
|
3
|
-
|
4
|
-
class PackedFieldTest < Test::Unit::TestCase
|
5
|
-
|
6
|
-
def test_packed_field
|
7
|
-
values = [1, 1_000, 10_000, 1_000_000, 1_000_000_000]
|
8
|
-
|
9
|
-
# encode
|
10
|
-
message = Test::PackedField::Message.new
|
11
|
-
message.a = values
|
12
|
-
message.b = values
|
13
|
-
|
14
|
-
expected = ''
|
15
|
-
serialized_string = nil
|
16
|
-
assert_nothing_raised { serialized_string = message.serialize_to_string }
|
17
|
-
|
18
|
-
value = values.map {|v| Protobuf::Field::VarintField.encode(v) }.join
|
19
|
-
expected << Protobuf::Field::VarintField.encode((1 << 3) | 2) # tag=1, wire_type=2 (length-delimited)
|
20
|
-
expected << Protobuf::Field::VarintField.encode(value.size)
|
21
|
-
expected << value
|
22
|
-
|
23
|
-
value = values.pack('V*')
|
24
|
-
expected << Protobuf::Field::VarintField.encode((2 << 3) | 2) # tag=2, wire_type=2 (length-delimited)
|
25
|
-
expected << Protobuf::Field::VarintField.encode(value.size)
|
26
|
-
expected << value
|
27
|
-
|
28
|
-
assert_equal(expected, serialized_string)
|
29
|
-
|
30
|
-
# decode
|
31
|
-
message2 = Test::PackedField::Message.new
|
32
|
-
assert_nothing_raised { message2.parse_from_string(serialized_string) }
|
33
|
-
|
34
|
-
values.each_with_index do |val, n|
|
35
|
-
assert_equal(val, message.a[n])
|
36
|
-
assert_equal(val, message.b[n])
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|