1#!/usr/bin/ruby 2# 3# generated_code.rb is in the same directory as this test. 4$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) 5 6old_gc = GC.stress 7GC.stress = 0x01 | 0x04 8require 'generated_code_pb' 9require 'generated_code_proto2_pb' 10GC.stress = old_gc 11 12require 'test/unit' 13 14class GCTest < Test::Unit::TestCase 15 def get_msg_proto3 16 A::B::C::TestMessage.new( 17 :optional_int32 => 1, 18 :optional_int64 => 1, 19 :optional_uint32 => 1, 20 :optional_uint64 => 1, 21 :optional_bool => true, 22 :optional_double => 1.0, 23 :optional_float => 1.0, 24 :optional_string => "a", 25 :optional_bytes => "b", 26 :optional_enum => A::B::C::TestEnum::A, 27 :optional_msg => A::B::C::TestMessage.new(), 28 :repeated_int32 => [1], 29 :repeated_int64 => [1], 30 :repeated_uint32 => [1], 31 :repeated_uint64 => [1], 32 :repeated_bool => [true], 33 :repeated_double => [1.0], 34 :repeated_float => [1.0], 35 :repeated_string => ["a"], 36 :repeated_bytes => ["b"], 37 :repeated_enum => [A::B::C::TestEnum::A], 38 :repeated_msg => [A::B::C::TestMessage.new()], 39 :map_int32_string => {1 => "a"}, 40 :map_int64_string => {1 => "a"}, 41 :map_uint32_string => {1 => "a"}, 42 :map_uint64_string => {1 => "a"}, 43 :map_bool_string => {true => "a"}, 44 :map_string_string => {"a" => "a"}, 45 :map_string_msg => {"a" => A::B::C::TestMessage.new()}, 46 :map_string_int32 => {"a" => 1}, 47 :map_string_bool => {"a" => true}, 48 ) 49 end 50 51 def get_msg_proto2 52 A::B::Proto2::TestMessage.new( 53 :optional_int32 => 1, 54 :optional_int64 => 1, 55 :optional_uint32 => 1, 56 :optional_uint64 => 1, 57 :optional_bool => true, 58 :optional_double => 1.0, 59 :optional_float => 1.0, 60 :optional_string => "a", 61 :optional_bytes => "b", 62 :optional_enum => A::B::Proto2::TestEnum::A, 63 :optional_msg => A::B::Proto2::TestMessage.new(), 64 :repeated_int32 => [1], 65 :repeated_int64 => [1], 66 :repeated_uint32 => [1], 67 :repeated_uint64 => [1], 68 :repeated_bool => [true], 69 :repeated_double => [1.0], 70 :repeated_float => [1.0], 71 :repeated_string => ["a"], 72 :repeated_bytes => ["b"], 73 :repeated_enum => [A::B::Proto2::TestEnum::A], 74 :repeated_msg => [A::B::Proto2::TestMessage.new()], 75 :required_int32 => 1, 76 :required_int64 => 1, 77 :required_uint32 => 1, 78 :required_uint64 => 1, 79 :required_bool => true, 80 :required_double => 1.0, 81 :required_float => 1.0, 82 :required_string => "a", 83 :required_bytes => "b", 84 :required_enum => A::B::Proto2::TestEnum::A, 85 :required_msg => A::B::Proto2::TestMessage.new(), 86 ) 87 end 88 89 def test_generated_msg 90 old_gc = GC.stress 91 GC.stress = 0x01 | 0x04 92 from = get_msg_proto3 93 data = A::B::C::TestMessage.encode(from) 94 to = A::B::C::TestMessage.decode(data) 95 96 from = get_msg_proto2 97 data = A::B::Proto2::TestMessage.encode(from) 98 to = A::B::Proto2::TestMessage.decode(data) 99 GC.stress = old_gc 100 puts "passed" 101 end 102end 103