blob: f3470ccaa58e8cc3520bbe7633c284089633d002 [file] [log] [blame]
Austin Schuh40c16522018-10-28 20:27:54 -07001#!/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'
9GC.stress = old_gc
10
11require 'test/unit'
12
13class GCTest < Test::Unit::TestCase
14 def get_msg
15 A::B::C::TestMessage.new(
16 :optional_int32 => 1,
17 :optional_int64 => 1,
18 :optional_uint32 => 1,
19 :optional_uint64 => 1,
20 :optional_bool => true,
21 :optional_double => 1.0,
22 :optional_float => 1.0,
23 :optional_string => "a",
24 :optional_bytes => "b",
25 :optional_enum => A::B::C::TestEnum::A,
26 :optional_msg => A::B::C::TestMessage.new(),
27 :repeated_int32 => [1],
28 :repeated_int64 => [1],
29 :repeated_uint32 => [1],
30 :repeated_uint64 => [1],
31 :repeated_bool => [true],
32 :repeated_double => [1.0],
33 :repeated_float => [1.0],
34 :repeated_string => ["a"],
35 :repeated_bytes => ["b"],
36 :repeated_enum => [A::B::C::TestEnum::A],
37 :repeated_msg => [A::B::C::TestMessage.new()],
38 :map_int32_string => {1 => "a"},
39 :map_int64_string => {1 => "a"},
40 :map_uint32_string => {1 => "a"},
41 :map_uint64_string => {1 => "a"},
42 :map_bool_string => {true => "a"},
43 :map_string_string => {"a" => "a"},
44 :map_string_msg => {"a" => A::B::C::TestMessage.new()},
45 :map_string_int32 => {"a" => 1},
46 :map_string_bool => {"a" => true},
47 )
48 end
49 def test_generated_msg
50 old_gc = GC.stress
51 GC.stress = 0x01 | 0x04
52 from = get_msg
53 data = A::B::C::TestMessage.encode(from)
54 to = A::B::C::TestMessage.decode(data)
55 GC.stress = old_gc
56 puts "passed"
57 end
58end