gc_test.rb 1.7 KB

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