gc_test.rb 3.1 KB

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