protobuf 2.2.5-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.travis.yml +9 -0
- data/.yardopts +5 -0
- data/Gemfile +3 -0
- data/README.md +316 -0
- data/Rakefile +29 -0
- data/UPGRADING.md +60 -0
- data/bin/rpc_server +5 -0
- data/bin/rprotoc +62 -0
- data/examples/addressbook.pb.rb +55 -0
- data/examples/addressbook.proto +24 -0
- data/examples/reading_a_message.rb +32 -0
- data/examples/writing_a_message.rb +46 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +142 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +318 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +99 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +103 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +85 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +167 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +98 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +159 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +170 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +102 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +103 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +104 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +2721 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +303 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +84 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +77 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +108 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +101 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +72 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +213 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +109 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +134 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +113 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +120 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +113 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +434 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +73 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +790 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +156 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +108 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +93 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +1367 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +5223 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +366 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +136 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +904 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +424 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +82 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +1102 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +207 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h +54 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +136 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +313 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +238 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +357 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +340 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/message.h +692 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +239 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +64 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +80 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +1295 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/service.h +291 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +1211 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +220 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +119 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +123 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +121 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +457 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +170 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +174 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +101 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +83 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +98 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +285 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +11915 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +2895 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +211 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +56 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +188 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +151 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +4752 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +150 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +816 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +197 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +403 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +268 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +304 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +620 -0
- data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +774 -0
- data/ext/ruby_generator/Makefile +10 -0
- data/ext/ruby_generator/RubyGenerator.cpp +450 -0
- data/ext/ruby_generator/RubyGenerator.h +199 -0
- data/ext/ruby_generator/extconf.rb +36 -0
- data/ext/ruby_generator/protoc-ruby +0 -0
- data/lib/protobuf/cli.rb +188 -0
- data/lib/protobuf/enum.rb +58 -0
- data/lib/protobuf/enum_value.rb +59 -0
- data/lib/protobuf/evented.rb +22 -0
- data/lib/protobuf/exceptions.rb +11 -0
- data/lib/protobuf/ext/eventmachine.rb +14 -0
- data/lib/protobuf/field/base_field.rb +240 -0
- data/lib/protobuf/field/bool_field.rb +36 -0
- data/lib/protobuf/field/bytes_field.rb +38 -0
- data/lib/protobuf/field/double_field.rb +19 -0
- data/lib/protobuf/field/enum_field.rb +50 -0
- data/lib/protobuf/field/extension_fields.rb +32 -0
- data/lib/protobuf/field/field_array.rb +65 -0
- data/lib/protobuf/field/fixed32_field.rb +19 -0
- data/lib/protobuf/field/fixed64_field.rb +22 -0
- data/lib/protobuf/field/float_field.rb +31 -0
- data/lib/protobuf/field/int32_field.rb +12 -0
- data/lib/protobuf/field/int64_field.rb +12 -0
- data/lib/protobuf/field/integer_field.rb +19 -0
- data/lib/protobuf/field/message_field.rb +53 -0
- data/lib/protobuf/field/sfixed32_field.rb +21 -0
- data/lib/protobuf/field/sfixed64_field.rb +24 -0
- data/lib/protobuf/field/signed_integer_field.rb +23 -0
- data/lib/protobuf/field/sint32_field.rb +12 -0
- data/lib/protobuf/field/sint64_field.rb +12 -0
- data/lib/protobuf/field/string_field.rb +14 -0
- data/lib/protobuf/field/uint32_field.rb +12 -0
- data/lib/protobuf/field/uint64_field.rb +12 -0
- data/lib/protobuf/field/varint_field.rb +61 -0
- data/lib/protobuf/field.rb +57 -0
- data/lib/protobuf/logger.rb +86 -0
- data/lib/protobuf/message/decoder.rb +83 -0
- data/lib/protobuf/message/encoder.rb +48 -0
- data/lib/protobuf/message/extend.rb +8 -0
- data/lib/protobuf/message/message.rb +1 -0
- data/lib/protobuf/message.rb +320 -0
- data/lib/protobuf/rpc/buffer.rb +79 -0
- data/lib/protobuf/rpc/client.rb +166 -0
- data/lib/protobuf/rpc/connector.rb +19 -0
- data/lib/protobuf/rpc/connectors/base.rb +38 -0
- data/lib/protobuf/rpc/connectors/common.rb +156 -0
- data/lib/protobuf/rpc/connectors/em_client.rb +84 -0
- data/lib/protobuf/rpc/connectors/eventmachine.rb +87 -0
- data/lib/protobuf/rpc/connectors/socket.rb +73 -0
- data/lib/protobuf/rpc/connectors/zmq.rb +69 -0
- data/lib/protobuf/rpc/error/client_error.rb +31 -0
- data/lib/protobuf/rpc/error/server_error.rb +43 -0
- data/lib/protobuf/rpc/error.rb +25 -0
- data/lib/protobuf/rpc/rpc.pb.rb +118 -0
- data/lib/protobuf/rpc/server.rb +89 -0
- data/lib/protobuf/rpc/servers/evented/server.rb +41 -0
- data/lib/protobuf/rpc/servers/evented_runner.rb +21 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +111 -0
- data/lib/protobuf/rpc/servers/socket/worker.rb +66 -0
- data/lib/protobuf/rpc/servers/socket_runner.rb +27 -0
- data/lib/protobuf/rpc/servers/zmq/broker.rb +87 -0
- data/lib/protobuf/rpc/servers/zmq/server.rb +50 -0
- data/lib/protobuf/rpc/servers/zmq/util.rb +27 -0
- data/lib/protobuf/rpc/servers/zmq/worker.rb +60 -0
- data/lib/protobuf/rpc/servers/zmq_runner.rb +25 -0
- data/lib/protobuf/rpc/service.rb +173 -0
- data/lib/protobuf/rpc/service_dispatcher.rb +130 -0
- data/lib/protobuf/rpc/service_filters.rb +267 -0
- data/lib/protobuf/rpc/stat.rb +83 -0
- data/lib/protobuf/socket.rb +22 -0
- data/lib/protobuf/version.rb +4 -0
- data/lib/protobuf/wire_type.rb +10 -0
- data/lib/protobuf/zmq.rb +21 -0
- data/lib/protobuf.rb +86 -0
- data/proto/rpc.pb.rb +48 -0
- data/proto/rpc.proto +73 -0
- data/protobuf.gemspec +44 -0
- data/spec/benchmark/tasks.rb +179 -0
- data/spec/functional/embedded_service_spec.rb +7 -0
- data/spec/functional/evented_server_spec.rb +64 -0
- data/spec/functional/socket_server_spec.rb +58 -0
- data/spec/functional/zmq_server_spec.rb +58 -0
- data/spec/lib/protobuf/cli_spec.rb +212 -0
- data/spec/lib/protobuf/enum_spec.rb +98 -0
- data/spec/lib/protobuf/enum_value_spec.rb +15 -0
- data/spec/lib/protobuf/logger_spec.rb +131 -0
- data/spec/lib/protobuf/message/encoder_spec.rb +19 -0
- data/spec/lib/protobuf/message_spec.rb +209 -0
- data/spec/lib/protobuf/rpc/client_spec.rb +158 -0
- data/spec/lib/protobuf/rpc/connector_spec.rb +32 -0
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +50 -0
- data/spec/lib/protobuf/rpc/connectors/common_spec.rb +128 -0
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +36 -0
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +22 -0
- data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +18 -0
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +43 -0
- data/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +35 -0
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +41 -0
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +45 -0
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +44 -0
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +116 -0
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +451 -0
- data/spec/lib/protobuf/rpc/service_spec.rb +165 -0
- data/spec/lib/protobuf_spec.rb +62 -0
- data/spec/spec_helper.rb +51 -0
- data/spec/support/all.rb +6 -0
- data/spec/support/server.rb +101 -0
- data/spec/support/test/enum.pb.rb +34 -0
- data/spec/support/test/enum.proto +12 -0
- data/spec/support/test/resource.pb.rb +58 -0
- data/spec/support/test/resource.proto +31 -0
- data/spec/support/test/resource_service.rb +14 -0
- data/spec/support/test_app_file.rb +2 -0
- data/spec/support/tolerance_matcher.rb +40 -0
- data/test/data/data.bin +3 -0
- data/test/data/data_source.py +14 -0
- data/test/data/types.bin +0 -0
- data/test/data/types_source.py +22 -0
- data/test/data/unk.png +0 -0
- data/test/proto/addressbook.pb.rb +66 -0
- data/test/proto/addressbook.proto +33 -0
- data/test/proto/addressbook_base.pb.rb +58 -0
- data/test/proto/addressbook_base.proto +26 -0
- data/test/proto/addressbook_ext.pb.rb +20 -0
- data/test/proto/addressbook_ext.proto +6 -0
- data/test/proto/collision.pb.rb +17 -0
- data/test/proto/collision.proto +5 -0
- data/test/proto/ext_collision.pb.rb +24 -0
- data/test/proto/ext_collision.proto +8 -0
- data/test/proto/ext_range.pb.rb +22 -0
- data/test/proto/ext_range.proto +7 -0
- data/test/proto/float_default.proto +10 -0
- data/test/proto/lowercase.pb.rb +30 -0
- data/test/proto/lowercase.proto +9 -0
- data/test/proto/merge.pb.rb +39 -0
- data/test/proto/merge.proto +15 -0
- data/test/proto/nested.pb.rb +30 -0
- data/test/proto/nested.proto +9 -0
- data/test/proto/optional_field.pb.rb +35 -0
- data/test/proto/optional_field.proto +12 -0
- data/test/proto/packed.pb.rb +22 -0
- data/test/proto/packed.proto +6 -0
- data/test/proto/rpc.proto +6 -0
- data/test/proto/types.pb.rb +84 -0
- data/test/proto/types.proto +37 -0
- data/test/test_addressbook.rb +56 -0
- data/test/test_enum_value.rb +41 -0
- data/test/test_extension.rb +36 -0
- data/test/test_lowercase.rb +11 -0
- data/test/test_message.rb +128 -0
- data/test/test_optional_field.rb +103 -0
- data/test/test_packed_field.rb +40 -0
- data/test/test_parse.rb +15 -0
- data/test/test_repeated_types.rb +132 -0
- data/test/test_serialize.rb +61 -0
- data/test/test_standard_message.rb +96 -0
- data/test/test_types.rb +226 -0
- metadata +461 -0
@@ -0,0 +1,103 @@
|
|
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
|
@@ -0,0 +1,40 @@
|
|
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
|
data/test/test_parse.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/proto/addressbook.pb'
|
3
|
+
|
4
|
+
class ParseTest < Test::Unit::TestCase
|
5
|
+
def test_parse
|
6
|
+
person = Tutorial::Person.new
|
7
|
+
person.parse_from_file('test/data/data.bin')
|
8
|
+
assert_equal(1234, person.id)
|
9
|
+
assert_equal('John Doe', person.name)
|
10
|
+
assert_equal('jdoe@example.com', person.email)
|
11
|
+
assert_equal(1, person.phone.size)
|
12
|
+
assert_equal('555-4321', person.phone[0].number)
|
13
|
+
assert_equal(Tutorial::Person::PhoneType::HOME, person.phone[0].type)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/proto/types.pb'
|
3
|
+
|
4
|
+
class RepeatedTypesTest < Test::Unit::TestCase
|
5
|
+
def test_serialize
|
6
|
+
# empty set
|
7
|
+
types = Test::Types::RepeatedTypes.new
|
8
|
+
assert_equal('', types.to_s)
|
9
|
+
|
10
|
+
# has 1 member
|
11
|
+
types = Test::Types::RepeatedTypes.new
|
12
|
+
types.type1 << 0.01
|
13
|
+
types.type2 << 0.1
|
14
|
+
types.type3 << 1
|
15
|
+
types.type4 << 10
|
16
|
+
types.type5 << 100
|
17
|
+
types.type6 << 1000
|
18
|
+
types.type7 << -1
|
19
|
+
types.type8 << -10
|
20
|
+
types.type9 << 10000
|
21
|
+
types.type10 << 100000
|
22
|
+
types.type11 << false
|
23
|
+
types.type12 << 'hello all types'
|
24
|
+
image_bin = File.open('test/data/unk.png', 'r+b'){|f| f.read}
|
25
|
+
types.type13 << image_bin
|
26
|
+
types.type14 << -100
|
27
|
+
types.type15 << -1000
|
28
|
+
|
29
|
+
serialized_string = types.serialize_to_string
|
30
|
+
|
31
|
+
types2 = Test::Types::RepeatedTypes.new
|
32
|
+
types2.parse_from_string serialized_string
|
33
|
+
assert_in_delta(0.01, types2.type1[0], 0.00001)
|
34
|
+
assert_in_delta(0.1, types2.type2[0], 0.00001)
|
35
|
+
assert_equal(1, types2.type3[0])
|
36
|
+
assert_equal(10, types2.type4[0])
|
37
|
+
assert_equal(100, types2.type5[0])
|
38
|
+
assert_equal(1000, types2.type6[0])
|
39
|
+
assert_equal(-1, types2.type7[0])
|
40
|
+
assert_equal(-10, types2.type8[0])
|
41
|
+
assert_equal(10000, types2.type9[0])
|
42
|
+
assert_equal(100000, types2.type10[0])
|
43
|
+
assert(!types2.type11[0])
|
44
|
+
assert_equal('hello all types', types2.type12[0])
|
45
|
+
assert_equal(10938, types2.type13[0].size)
|
46
|
+
assert_equal(image_bin, types2.type13[0])
|
47
|
+
assert_equal(-100, types2.type14[0])
|
48
|
+
assert_equal(-1000, types2.type15[0])
|
49
|
+
|
50
|
+
# has 2 members
|
51
|
+
types.type1 << 1.0/0 # double (Inf)
|
52
|
+
types.type2 << -1.0/0 # float (-Inf)
|
53
|
+
types.type3 << -1 # int32
|
54
|
+
types.type4 << -10 # int64
|
55
|
+
types.type5 << 100 # uint32
|
56
|
+
types.type6 << 1000 # uint64
|
57
|
+
types.type7 << -1000 # sint32
|
58
|
+
types.type8 << -10000 # sint64
|
59
|
+
types.type9 << 10000 # fixed32
|
60
|
+
types.type10 << 100000 # fixed64
|
61
|
+
types.type11 << true
|
62
|
+
types.type12 << 'hello all types'
|
63
|
+
image_bin = File.open('test/data/unk.png', 'r+b'){|f| f.read}
|
64
|
+
types.type13 << image_bin
|
65
|
+
types.type14 << -2_000_000_000 # sfixed32
|
66
|
+
types.type15 << -8_000_000_000_000_000_000 # sfixed64
|
67
|
+
|
68
|
+
serialized_string = types.serialize_to_string
|
69
|
+
|
70
|
+
types2 = Test::Types::RepeatedTypes.new
|
71
|
+
types2.parse_from_string serialized_string
|
72
|
+
assert_in_delta(0.01, types2.type1[0], 0.00001)
|
73
|
+
assert_in_delta(0.1, types2.type2[0], 0.00001)
|
74
|
+
assert_equal(1, types2.type3[0])
|
75
|
+
assert_equal(10, types2.type4[0])
|
76
|
+
assert_equal(100, types2.type5[0])
|
77
|
+
assert_equal(1000, types2.type6[0])
|
78
|
+
assert_equal(-1, types2.type7[0])
|
79
|
+
assert_equal(-10, types2.type8[0])
|
80
|
+
assert_equal(10000, types2.type9[0])
|
81
|
+
assert_equal(100000, types2.type10[0])
|
82
|
+
assert(!types2.type11[0])
|
83
|
+
assert_equal('hello all types', types2.type12[0])
|
84
|
+
assert_equal(10938, types2.type13[0].size)
|
85
|
+
assert_equal(image_bin, types2.type13[0])
|
86
|
+
assert_equal(-100, types2.type14[0])
|
87
|
+
assert_equal(-1000, types2.type15[0])
|
88
|
+
|
89
|
+
assert_equal(1.0/0.0, types2.type1[1])
|
90
|
+
assert_equal(-1.0/0.0, types2.type2[1])
|
91
|
+
assert_equal(-1, types2.type3[1])
|
92
|
+
assert_equal(-10, types2.type4[1])
|
93
|
+
assert_equal(100, types2.type5[1])
|
94
|
+
assert_equal(1000, types2.type6[1])
|
95
|
+
assert_equal(-1000, types2.type7[1])
|
96
|
+
assert_equal(-10000, types2.type8[1])
|
97
|
+
assert_equal(10000, types2.type9[1])
|
98
|
+
assert_equal(100000, types2.type10[1])
|
99
|
+
assert types2.type11[1]
|
100
|
+
assert_equal('hello all types', types2.type12[1])
|
101
|
+
assert_equal(10938, types2.type13[1].size)
|
102
|
+
assert_equal(image_bin, types2.type13[1])
|
103
|
+
assert_equal(-2_000_000_000, types2.type14[1])
|
104
|
+
assert_equal(-8_000_000_000_000_000_000, types2.type15[1])
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_repeated_types
|
108
|
+
types = Test::Types::RepeatedTypes.new
|
109
|
+
# types.type3 is a repeated int32 field.
|
110
|
+
assert(types.type3.empty?)
|
111
|
+
types.type3 << 0
|
112
|
+
types.type3 << 1
|
113
|
+
assert_equal(0, types.type3[0])
|
114
|
+
assert_equal(1, types.type3[1])
|
115
|
+
assert_equal(2, types.type3.size)
|
116
|
+
|
117
|
+
assert_raise(TypeError) do
|
118
|
+
types.type3 << 'string'
|
119
|
+
end
|
120
|
+
|
121
|
+
types.type3[1] = 10
|
122
|
+
assert_equal(0, types.type3[0])
|
123
|
+
assert_equal(10, types.type3[1])
|
124
|
+
assert_equal(2, types.type3.size)
|
125
|
+
|
126
|
+
types.type3.replace([10, 20, 30])
|
127
|
+
assert_equal(10, types.type3[0])
|
128
|
+
assert_equal(20, types.type3[1])
|
129
|
+
assert_equal(30, types.type3[2])
|
130
|
+
assert_equal(3, types.type3.size)
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'test/unit'
|
3
|
+
require 'test/proto/addressbook.pb'
|
4
|
+
|
5
|
+
class SerializeTest < Test::Unit::TestCase
|
6
|
+
def test_serialize
|
7
|
+
# serialize to string
|
8
|
+
person = Tutorial::Person.new
|
9
|
+
person.id = 1234
|
10
|
+
person.name = 'John Doe'
|
11
|
+
person.email = 'jdoe@example.com'
|
12
|
+
phone = Tutorial::Person::PhoneNumber.new
|
13
|
+
phone.number = '555-4321'
|
14
|
+
phone.type = Tutorial::Person::PhoneType::HOME
|
15
|
+
person.phone << phone
|
16
|
+
serialized_string = person.serialize_to_string
|
17
|
+
|
18
|
+
# parse the serialized string
|
19
|
+
person2 = Tutorial::Person.new
|
20
|
+
person2.parse_from_string(serialized_string)
|
21
|
+
assert_equal(1234, person2.id)
|
22
|
+
assert_equal('John Doe', person2.name)
|
23
|
+
assert_equal('jdoe@example.com', person2.email)
|
24
|
+
assert_equal(1, person2.phone.size)
|
25
|
+
assert_equal('555-4321', person2.phone[0].number)
|
26
|
+
assert_equal(Tutorial::Person::PhoneType::HOME, person2.phone[0].type)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_serialize_utf8string
|
30
|
+
# serialize to string
|
31
|
+
person = Tutorial::Person.new
|
32
|
+
person.id = 1234
|
33
|
+
person.name = '山田 太郎' # kanji characters
|
34
|
+
serialized_string = person.serialize_to_string
|
35
|
+
|
36
|
+
# parse the serialized string
|
37
|
+
person2 = Tutorial::Person.new
|
38
|
+
person2.parse_from_string(serialized_string)
|
39
|
+
assert_equal(1234, person2.id)
|
40
|
+
assert_equal('山田 太郎', person2.name)
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_unknown_field
|
44
|
+
person = Tutorial::Person.new
|
45
|
+
person.id = 1234
|
46
|
+
person.name = 'a b c'
|
47
|
+
serialized_string = person.serialize_to_string
|
48
|
+
|
49
|
+
# add invalid field
|
50
|
+
tag = 1000
|
51
|
+
wire_type = Protobuf::WireType::VARINT
|
52
|
+
serialized_string << Protobuf::Field::VarintField.encode((tag << 3) | wire_type)
|
53
|
+
serialized_string << Protobuf::Field::VarintField.encode(100)
|
54
|
+
|
55
|
+
# decode
|
56
|
+
person2 = Tutorial::Person.new
|
57
|
+
person2.parse_from_string(serialized_string)
|
58
|
+
|
59
|
+
assert_equal(person, person2)
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'protobuf/message/message'
|
3
|
+
require 'protobuf/enum'
|
4
|
+
require 'test/proto/addressbook.pb'
|
5
|
+
|
6
|
+
class StandardMessageTest < Test::Unit::TestCase
|
7
|
+
def test_initialized
|
8
|
+
person = Tutorial::Person.new
|
9
|
+
assert(!person.initialized?)
|
10
|
+
assert_raise(Protobuf::NotInitializedError) { person.to_s }
|
11
|
+
person.name = 'name'
|
12
|
+
assert(!person.initialized?)
|
13
|
+
person.id = 12
|
14
|
+
assert( person.initialized?)
|
15
|
+
|
16
|
+
# repeated field
|
17
|
+
person.phone << Tutorial::Person::PhoneNumber.new
|
18
|
+
assert(!person.initialized?)
|
19
|
+
person.phone.last.number = '123-456'
|
20
|
+
assert( person.initialized?)
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_clear
|
24
|
+
person = Tutorial::Person.new
|
25
|
+
person.name = 'name'
|
26
|
+
person.id = 1234
|
27
|
+
person.email = 'abc@cde.fgh'
|
28
|
+
person.phone << Tutorial::Person::PhoneNumber.new
|
29
|
+
person.clear!
|
30
|
+
|
31
|
+
assert_nil(person.name)
|
32
|
+
assert_nil(person.id)
|
33
|
+
assert_equal('', person.email)
|
34
|
+
assert_equal(0, person.phone.size)
|
35
|
+
|
36
|
+
assert(!person.has_field?(:name))
|
37
|
+
assert(!person.has_field?(:id))
|
38
|
+
assert(!person.has_field?(:email))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_dup
|
42
|
+
person = Tutorial::Person.new
|
43
|
+
person.name = 'name'
|
44
|
+
person.id = 1234
|
45
|
+
person.email = 'abc@cde.fgh'
|
46
|
+
person.phone << Tutorial::Person::PhoneNumber.new
|
47
|
+
person.phone.last.number = '123-456'
|
48
|
+
person.phone.last.type = Tutorial::Person::PhoneType::MOBILE
|
49
|
+
person.phone << Tutorial::Person::PhoneNumber.new
|
50
|
+
person.phone.last.number = '456-123'
|
51
|
+
person.phone.last.type = Tutorial::Person::PhoneType::WORK
|
52
|
+
|
53
|
+
person2 = person.dup
|
54
|
+
assert(person == person2)
|
55
|
+
assert(!person.eql?(person2))
|
56
|
+
assert_equal(person.name, person2.name)
|
57
|
+
assert_equal(person.id, person2.id)
|
58
|
+
assert_equal(person.email, person2.email)
|
59
|
+
assert_equal(person.phone.size, person2.phone.size)
|
60
|
+
assert(person.phone.first == person2.phone.first)
|
61
|
+
assert(!person.phone.first.eql?(person2.phone.first))
|
62
|
+
assert_equal(person.phone.first.number, person2.phone.first.number)
|
63
|
+
assert_equal(person.phone.first.type, person2.phone.first.type)
|
64
|
+
assert(person.phone.last == person2.phone.last)
|
65
|
+
assert(!person.phone.last.eql?(person2.phone.last))
|
66
|
+
assert_equal(person.phone.last.number, person2.phone.last.number)
|
67
|
+
assert_equal(person.phone.last.type, person2.phone.last.type)
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_inspect
|
71
|
+
person = Tutorial::Person.new
|
72
|
+
person.name = 'name'
|
73
|
+
person.id = 1234
|
74
|
+
person.email = 'abc@cde.fgh'
|
75
|
+
person.phone << Tutorial::Person::PhoneNumber.new
|
76
|
+
person.phone.last.number = '123-456'
|
77
|
+
person.phone.last.type = Tutorial::Person::PhoneType::MOBILE
|
78
|
+
person.phone << Tutorial::Person::PhoneNumber.new
|
79
|
+
person.phone.last.number = '456-123'
|
80
|
+
person.phone.last.type = Tutorial::Person::PhoneType::WORK
|
81
|
+
|
82
|
+
assert_equal <<-EOS, person.inspect
|
83
|
+
name: "name"
|
84
|
+
id: 1234
|
85
|
+
email: "abc@cde.fgh"
|
86
|
+
phone {
|
87
|
+
number: "123-456"
|
88
|
+
type: MOBILE
|
89
|
+
}
|
90
|
+
phone {
|
91
|
+
number: "456-123"
|
92
|
+
type: WORK
|
93
|
+
}
|
94
|
+
EOS
|
95
|
+
end
|
96
|
+
end
|
data/test/test_types.rb
ADDED
@@ -0,0 +1,226 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'test/proto/types.pb'
|
3
|
+
|
4
|
+
class TypesTest < Test::Unit::TestCase
|
5
|
+
def test_serialize
|
6
|
+
types = Test::Types::TestTypes.new
|
7
|
+
types.type1 = 0.01
|
8
|
+
types.type2 = 0.1
|
9
|
+
types.type3 = 1
|
10
|
+
types.type4 = 10
|
11
|
+
types.type5 = 100
|
12
|
+
types.type6 = 1000
|
13
|
+
types.type7 = -1
|
14
|
+
types.type8 = -10
|
15
|
+
types.type9 = 10000
|
16
|
+
types.type10 = 100000
|
17
|
+
types.type11 = false
|
18
|
+
types.type12 = 'hello all types'
|
19
|
+
image_bin = File.open('test/data/unk.png', 'r+b'){|f| f.read}
|
20
|
+
types.type13 = image_bin
|
21
|
+
types.type14 = -100
|
22
|
+
types.type15 = -1000
|
23
|
+
|
24
|
+
serialized_string = types.serialize_to_string
|
25
|
+
|
26
|
+
types2 = Test::Types::TestTypes.new
|
27
|
+
types2.parse_from_string(serialized_string)
|
28
|
+
assert_in_delta(0.01, types2.type1, 0.00001)
|
29
|
+
assert_in_delta(0.1, types2.type2, 0.00001)
|
30
|
+
assert_equal(1, types2.type3)
|
31
|
+
assert_equal(10, types2.type4)
|
32
|
+
assert_equal(100, types2.type5)
|
33
|
+
assert_equal(1000, types2.type6)
|
34
|
+
assert_equal(-1, types2.type7)
|
35
|
+
assert_equal(-10, types2.type8)
|
36
|
+
assert_equal(10000, types2.type9)
|
37
|
+
assert_equal(100000, types2.type10)
|
38
|
+
assert(!types2.type11)
|
39
|
+
assert_equal('hello all types', types2.type12)
|
40
|
+
assert_equal(10938, types2.type13.size)
|
41
|
+
assert_equal(image_bin, types2.type13)
|
42
|
+
assert_equal(-100, types2.type14)
|
43
|
+
assert_equal(-1000, types2.type15)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_serialize2
|
47
|
+
types = Test::Types::TestTypes.new
|
48
|
+
types.type1 = 1.0/0 # double (Inf)
|
49
|
+
types.type2 = -1.0/0 # float (-Inf)
|
50
|
+
types.type3 = -1 # int32
|
51
|
+
types.type4 = -10 # int64
|
52
|
+
types.type5 = 100 # uint32
|
53
|
+
types.type6 = 1000 # uint64
|
54
|
+
types.type7 = -1000 # sint32
|
55
|
+
types.type8 = -10000 # sint64
|
56
|
+
types.type9 = 10000 # fixed32
|
57
|
+
types.type10 = 100000 # fixed64
|
58
|
+
types.type11 = true
|
59
|
+
types.type12 = 'hello all types'
|
60
|
+
image_bin = File.open('test/data/unk.png', 'r+b'){|f| f.read}
|
61
|
+
types.type13 = image_bin
|
62
|
+
types.type14 = -2_000_000_000 # sfixed32
|
63
|
+
types.type15 = -8_000_000_000_000_000_000 # sfixed64
|
64
|
+
|
65
|
+
serialized_string = types.serialize_to_string
|
66
|
+
|
67
|
+
types2 = Test::Types::TestTypes.new
|
68
|
+
types2.parse_from_string(serialized_string)
|
69
|
+
assert_equal(1.0/0.0, types2.type1)
|
70
|
+
assert_equal(-1.0/0.0, types2.type2)
|
71
|
+
assert_equal(-1, types2.type3)
|
72
|
+
assert_equal(-10, types2.type4)
|
73
|
+
assert_equal(100, types2.type5)
|
74
|
+
assert_equal(1000, types2.type6)
|
75
|
+
assert_equal(-1000, types2.type7)
|
76
|
+
assert_equal(-10000, types2.type8)
|
77
|
+
assert_equal(10000, types2.type9)
|
78
|
+
assert_equal(100000, types2.type10)
|
79
|
+
assert(types2.type11)
|
80
|
+
assert_equal('hello all types', types2.type12)
|
81
|
+
assert_equal(10938, types2.type13.size)
|
82
|
+
assert_equal(image_bin, types2.type13)
|
83
|
+
assert_equal(-2_000_000_000, types2.type14)
|
84
|
+
assert_equal(-8_000_000_000_000_000_000, types2.type15)
|
85
|
+
end
|
86
|
+
|
87
|
+
def test_parse
|
88
|
+
types = Test::Types::TestTypes.new
|
89
|
+
types.parse_from_file('test/data/types.bin')
|
90
|
+
assert_in_delta(0.01, types.type1, 0.00001)
|
91
|
+
assert_in_delta(0.1, types.type2, 0.00001)
|
92
|
+
assert_equal(1, types.type3)
|
93
|
+
assert_equal(10, types.type4)
|
94
|
+
assert_equal(100, types.type5)
|
95
|
+
assert_equal(1000, types.type6)
|
96
|
+
assert_equal(-1, types.type7)
|
97
|
+
assert_equal(-10, types.type8)
|
98
|
+
assert_equal(10000, types.type9)
|
99
|
+
assert_equal(100000, types.type10)
|
100
|
+
assert_equal(false, !!types.type11)
|
101
|
+
assert_equal('hello all types', types.type12)
|
102
|
+
assert_equal(File.open('test/data/unk.png', 'r+b'){|f| f.read}, types.type13)
|
103
|
+
end
|
104
|
+
|
105
|
+
def test_double
|
106
|
+
# double fixed 64-bit
|
107
|
+
types = Test::Types::TestTypes.new
|
108
|
+
assert_nothing_raised { types.type1 = 1 }
|
109
|
+
assert_nothing_raised { types.type1 = 1.0 }
|
110
|
+
assert_raise(TypeError) { types.type1 = '' }
|
111
|
+
assert_nothing_raised { types.type1 = Protobuf::Field::DoubleField.max }
|
112
|
+
assert_nothing_raised { types.type1 = Protobuf::Field::DoubleField.min }
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_float
|
116
|
+
# float fixed 32-bit
|
117
|
+
types = Test::Types::TestTypes.new
|
118
|
+
assert_nothing_raised { types.type2 = 1 }
|
119
|
+
assert_nothing_raised { types.type2 = 1.0 }
|
120
|
+
assert_raise(TypeError) { types.type2 = '' }
|
121
|
+
assert_nothing_raised { types.type2 = Protobuf::Field::FloatField.max }
|
122
|
+
assert_nothing_raised { types.type2 = Protobuf::Field::FloatField.min }
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_int32
|
126
|
+
types = Test::Types::TestTypes.new
|
127
|
+
assert_nothing_raised { types.type3 = 1 }
|
128
|
+
assert_nothing_raised { types.type3 = -1 }
|
129
|
+
assert_raise(TypeError) { types.type3 = 1.0 }
|
130
|
+
assert_raise(TypeError) { types.type3 = '' }
|
131
|
+
end
|
132
|
+
|
133
|
+
def test_int64
|
134
|
+
types = Test::Types::TestTypes.new
|
135
|
+
assert_nothing_raised { types.type4 = 1 }
|
136
|
+
assert_nothing_raised { types.type4 = -1 }
|
137
|
+
assert_raise(TypeError) { types.type4 = 1.0 }
|
138
|
+
assert_raise(TypeError) { types.type4 = '' }
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_uint32
|
142
|
+
types = Test::Types::TestTypes.new
|
143
|
+
assert_nothing_raised { types.type5 = 1 }
|
144
|
+
assert_raise(RangeError) { types.type5 = -1 }
|
145
|
+
assert_raise(TypeError) { types.type5 = 1.0 }
|
146
|
+
assert_raise(TypeError) { types.type5 = '' }
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_uint64
|
150
|
+
types = Test::Types::TestTypes.new
|
151
|
+
assert_nothing_raised { types.type6 = 1 }
|
152
|
+
assert_raise(RangeError) { types.type6 = -1 }
|
153
|
+
assert_raise(TypeError) { types.type6 = 1.0 }
|
154
|
+
assert_raise(TypeError) { types.type6 = '' }
|
155
|
+
end
|
156
|
+
|
157
|
+
def test_sint32
|
158
|
+
types = Test::Types::TestTypes.new
|
159
|
+
assert_nothing_raised { types.type7 = 1 }
|
160
|
+
assert_nothing_raised { types.type7 = -1 }
|
161
|
+
assert_raise(TypeError) { types.type7 = 1.0 }
|
162
|
+
assert_raise(TypeError) { types.type7 = '' }
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_sint64
|
166
|
+
types = Test::Types::TestTypes.new
|
167
|
+
assert_nothing_raised { types.type8 = 1 }
|
168
|
+
assert_nothing_raised { types.type8 = -1 }
|
169
|
+
assert_raise(TypeError) { types.type8 = 1.0 }
|
170
|
+
assert_raise(TypeError) { types.type8 = '' }
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_fixed32
|
174
|
+
types = Test::Types::TestTypes.new
|
175
|
+
assert_nothing_raised { types.type9 = 1 }
|
176
|
+
assert_raise(TypeError) { types.type9 = 1.0 }
|
177
|
+
assert_raise(TypeError) { types.type9 = '' }
|
178
|
+
assert_nothing_raised { types.type9 = Protobuf::Field::Fixed32Field.max }
|
179
|
+
assert_raise(RangeError) { types.type9 = Protobuf::Field::Fixed32Field.max + 1 }
|
180
|
+
assert_nothing_raised { types.type9 = Protobuf::Field::Fixed32Field.min }
|
181
|
+
assert_raise(RangeError) { types.type9 = Protobuf::Field::Fixed32Field.min - 1 }
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_fixed64
|
185
|
+
types = Test::Types::TestTypes.new
|
186
|
+
assert_nothing_raised { types.type10 = 1 }
|
187
|
+
assert_raise(TypeError) { types.type10 = 1.0 }
|
188
|
+
assert_raise(TypeError) { types.type10 = '' }
|
189
|
+
assert_nothing_raised { types.type10 = Protobuf::Field::Fixed64Field.max }
|
190
|
+
assert_raise(RangeError) { types.type10 = Protobuf::Field::Fixed64Field.max + 1 }
|
191
|
+
assert_nothing_raised { types.type10 = Protobuf::Field::Fixed64Field.min }
|
192
|
+
assert_raise(RangeError) { types.type10 = Protobuf::Field::Fixed64Field.min - 1 }
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_bool
|
196
|
+
types = Test::Types::TestTypes.new
|
197
|
+
assert_nothing_raised { types.type11 = true }
|
198
|
+
assert_nothing_raised { types.type11 = false }
|
199
|
+
assert_nothing_raised { types.type11 = nil }
|
200
|
+
assert_raise(TypeError) { types.type11 = 0 }
|
201
|
+
assert_raise(TypeError) { types.type11 = '' }
|
202
|
+
end
|
203
|
+
|
204
|
+
def test_string
|
205
|
+
types = Test::Types::TestTypes.new
|
206
|
+
assert_nothing_raised { types.type12 = '' }
|
207
|
+
assert_nothing_raised { types.type12 = 'hello' }
|
208
|
+
assert_nothing_raised { types.type12 = nil }
|
209
|
+
assert_raise(TypeError) { types.type12 = 0 }
|
210
|
+
assert_raise(TypeError) { types.type12 = true }
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_bytes
|
214
|
+
types = Test::Types::TestTypes.new
|
215
|
+
assert_nothing_raised { types.type13 = '' }
|
216
|
+
assert_nothing_raised { types.type13 = 'hello' }
|
217
|
+
assert_nothing_raised { types.type13 = nil }
|
218
|
+
assert_raise(TypeError) { types.type13 = 0 }
|
219
|
+
assert_raise(TypeError) { types.type13 = true }
|
220
|
+
assert_raise(TypeError) { types.type13 = [] }
|
221
|
+
end
|
222
|
+
|
223
|
+
def test_varint_getbytes
|
224
|
+
assert_equal("\xac\x02", Protobuf::Field::VarintField.encode(300))
|
225
|
+
end
|
226
|
+
end
|