tensorflow/tools/proto_text/gen_proto_text_functions_lib_test.cc
// Test different cases of numeric values, including repeated values.
Test different cases of numeric values, including repeated values.
Test different cases of numeric values including repeated values .
TEST(CreateProtoDebugStringLibTest, ValidSimpleTypes) {
  TestAllTypes proto;
  proto.Clear();
  proto.set_optional_int32(-1);
  proto.set_optional_int64(-2);
  proto.set_optional_uint32(3);
  proto.set_optional_uint64(4);
  proto.set_optional_sint32(-5);
  proto.set_optional_sint64(-6);
  proto.set_optional_fixed32(-7);
  proto.set_optional_fixed64(-8);
  proto.set_optional_sfixed32(-9);
  proto.set_optional_sfixed64(-10);
  proto.set_optional_float(-12.34);
  proto.set_optional_double(-5.678);
  proto.set_optional_bool(true);
  EXPECT_TEXT_TRANSFORMS_MATCH();
  proto.Clear();
  proto.set_optional_int32(std::numeric_limits<int32>::max());
  proto.set_optional_int64(std::numeric_limits<protobuf_int64>::max());
  proto.set_optional_uint32(std::numeric_limits<uint32>::max());
  proto.set_optional_uint64(std::numeric_limits<uint64>::max());
  proto.set_optional_double(std::numeric_limits<double>::max());
  EXPECT_TEXT_TRANSFORMS_MATCH();
  proto.Clear();
  proto.set_optional_double(std::numeric_limits<double>::min());
  EXPECT_TEXT_TRANSFORMS_MATCH();
  proto.Clear();
  proto.set_optional_int32(std::numeric_limits<int32>::lowest());
  proto.set_optional_int64(std::numeric_limits<protobuf_int64>::lowest());
  proto.set_optional_double(std::numeric_limits<double>::lowest());
  EXPECT_TEXT_TRANSFORMS_MATCH();
  proto.Clear();
  proto.set_optional_double(std::numeric_limits<double>::infinity());
  proto.set_optional_float(std::numeric_limits<float>::infinity());
  EXPECT_TEXT_TRANSFORMS_MATCH();
  proto.set_optional_double(-1 * std::numeric_limits<double>::infinity());
  proto.set_optional_float(-1 * std::numeric_limits<float>::infinity());
  EXPECT_TEXT_TRANSFORMS_MATCH();
  proto.Clear();
  for (int i = 0; i < 256; ++i) {
    proto.mutable_optional_string()->push_back(static_cast<char>(i));
    proto.mutable_optional_bytes()->push_back(static_cast<char>(i));
  }
  strings::StrAppend(proto.mutable_optional_string(), "¢€𐍈");
  proto.set_optional_cord(proto.optional_string());
  EXPECT_TEXT_TRANSFORMS_MATCH();
  proto.Clear();
  proto.add_repeated_int32(-1);
  proto.add_repeated_int32(0);
  proto.add_repeated_int64(0);
  proto.add_repeated_int64(1);
  proto.add_repeated_uint32(-10);
  proto.add_repeated_uint32(0);
  proto.add_repeated_uint32(10);
  proto.add_repeated_uint64(-20);
  proto.add_repeated_uint64(0);
  proto.add_repeated_uint64(20);
  proto.add_repeated_sint32(-30);
  proto.add_repeated_sint32(0);
  proto.add_repeated_sint32(30);
  proto.add_repeated_sint64(-40);
  proto.add_repeated_sint64(0);
  proto.add_repeated_sint64(40);
  proto.add_repeated_fixed32(-50);
  proto.add_repeated_fixed32(0);
  proto.add_repeated_fixed32(50);
  proto.add_repeated_fixed64(-60);
  proto.add_repeated_fixed64(0);
  proto.add_repeated_fixed64(60);
  proto.add_repeated_sfixed32(-70);
  proto.add_repeated_sfixed32(0);
  proto.add_repeated_sfixed32(70);
  proto.add_repeated_sfixed64(-80);
  proto.add_repeated_sfixed64(0);
  proto.add_repeated_sfixed64(80);
  proto.add_repeated_float(-1.2345);
  proto.add_repeated_float(0);
  proto.add_repeated_float(-2.3456);
  proto.add_repeated_double(-10.2345);
  proto.add_repeated_double(0);
  proto.add_repeated_double(-20.3456);
  proto.add_repeated_bool(false);
  proto.add_repeated_bool(true);
  proto.add_repeated_bool(false);
  proto.add_repeated_string("abc");
  proto.add_repeated_string("");
  proto.add_repeated_string("def");
  proto.add_repeated_cord("abc");
  proto.add_repeated_cord("");
  proto.add_repeated_cord("def");
  proto.add_packed_repeated_int64(-1000);
  proto.add_packed_repeated_int64(0);
  proto.add_packed_repeated_int64(1000);
  EXPECT_TEXT_TRANSFORMS_MATCH();
  EXPECT_PARSE_SUCCESS("repeated_int32: 1 repeated_int32: 2 repeated_int32: 3",
                       "repeated_int32: [1, 2 , 3]");
  EXPECT_PARSE_SUCCESS(("repeated_bool: false repeated_bool: false "
                        "repeated_bool: true repeated_bool: true "
                        "repeated_bool: false repeated_bool: true"),
                       "repeated_bool: [false, 0, 1, true, False, True]");
  EXPECT_PARSE_SUCCESS(("repeated_string: \"a,b\" "
                        "repeated_string: \"cdef\""),
                       "repeated_string:   [  'a,b', 'cdef'  ]  ");
  EXPECT_PARSE_SUCCESS("optional_string: \"123\\\" \\'xyz\"",
                       "optional_string: '123\\\" \\'xyz'  ");
  EXPECT_PARSE_SUCCESS("optional_double: 10000", "optional_double: 1e4");
  EXPECT_PARSE_FAILURE("optional_string: '1' optional_string: '2'");
  EXPECT_PARSE_FAILURE("optional_double: 123 optional_double: 456");
  EXPECT_PARSE_FAILURE("optional_double: 0001");
  EXPECT_PARSE_FAILURE("optional_double: 000.1");
  EXPECT_PARSE_FAILURE("optional_double: a");
  EXPECT_PARSE_FAILURE("optional_double: x123");
  EXPECT_PARSE_FAILURE("optional_double: '123'");
  EXPECT_PARSE_FAILURE("optional_double: --111");
  EXPECT_PARSE_FAILURE("optional_string: 'abc\"");
  EXPECT_PARSE_FAILURE("optional_bool: truE");
  EXPECT_PARSE_FAILURE("optional_bool: FALSE");
}
TEST ( CreateProtoDebugStringLibTest , ValidSimpleTypes ) { TestAllTypes proto ; proto . Clear ( ) ; proto . set_optional_int32 ( -1 ) ; proto . set_optional_int64 ( -2 ) ; proto . set_optional_uint32 ( 3 ) ; proto . set_optional_uint64 ( 4 ) ; proto . set_optional_sint32 ( -5 ) ; proto . set_optional_sint64 ( -6 ) ; proto . set_optional_fixed32 ( -7 ) ; proto . set_optional_fixed64 ( -8 ) ; proto . set_optional_sfixed32 ( -9 ) ; proto . set_optional_sfixed64 ( -10 ) ; proto . set_optional_float ( -12.34 ) ; proto . set_optional_double ( -5.678 ) ; proto . set_optional_bool ( true ) ; EXPECT_TEXT_TRANSFORMS_MATCH ( ) ; proto . Clear ( ) ; proto . set_optional_int32 ( std :: numeric_limits < int32 > :: max ( ) ) ; proto . set_optional_int64 ( std :: numeric_limits < protobuf_int64 > :: max ( ) ) ; proto . set_optional_uint32 ( std :: numeric_limits < uint32 > :: max ( ) ) ; proto . set_optional_uint64 ( std :: numeric_limits < uint64 > :: max ( ) ) ; proto . set_optional_double ( std :: numeric_limits < double > :: max ( ) ) ; EXPECT_TEXT_TRANSFORMS_MATCH ( ) ; proto . Clear ( ) ; proto . set_optional_double ( std :: numeric_limits < double > :: min ( ) ) ; EXPECT_TEXT_TRANSFORMS_MATCH ( ) ; proto . Clear ( ) ; proto . set_optional_int32 ( std :: numeric_limits < int32 > :: lowest ( ) ) ; proto . set_optional_int64 ( std :: numeric_limits < protobuf_int64 > :: lowest ( ) ) ; proto . set_optional_double ( std :: numeric_limits < double > :: lowest ( ) ) ; EXPECT_TEXT_TRANSFORMS_MATCH ( ) ; proto . Clear ( ) ; proto . set_optional_double ( std :: numeric_limits < double > :: infinity ( ) ) ; proto . set_optional_float ( std :: numeric_limits < float > :: infinity ( ) ) ; EXPECT_TEXT_TRANSFORMS_MATCH ( ) ; proto . set_optional_double ( -1 * std :: numeric_limits < double > :: infinity ( ) ) ; proto . set_optional_float ( -1 * std :: numeric_limits < float > :: infinity ( ) ) ; EXPECT_TEXT_TRANSFORMS_MATCH ( ) ; proto . Clear ( ) ; for ( int i = 0 ; i < 256 ; ++ i ) { proto . mutable_optional_string ( ) -> push_back ( static_cast < char > ( i ) ) ; proto . mutable_optional_bytes ( ) -> push_back ( static_cast < char > ( i ) ) ; } strings :: StrAppend ( proto . mutable_optional_string ( ) , " proto . set_optional_cord ( proto . optional_string ( ) ) ; EXPECT_TEXT_TRANSFORMS_MATCH ( ) ; proto . Clear ( ) ; proto . add_repeated_int32 ( -1 ) ; proto . add_repeated_int32 ( 0 ) ; proto . add_repeated_int64 ( 0 ) ; proto . add_repeated_int64 ( 1 ) ; proto . add_repeated_uint32 ( -10 ) ; proto . add_repeated_uint32 ( 0 ) ; proto . add_repeated_uint32 ( 10 ) ; proto . add_repeated_uint64 ( -20 ) ; proto . add_repeated_uint64 ( 0 ) ; proto . add_repeated_uint64 ( 20 ) ; proto . add_repeated_sint32 ( -30 ) ; proto . add_repeated_sint32 ( 0 ) ; proto . add_repeated_sint32 ( 30 ) ; proto . add_repeated_sint64 ( -40 ) ; proto . add_repeated_sint64 ( 0 ) ; proto . add_repeated_sint64 ( 40 ) ; proto . add_repeated_fixed32 ( -50 ) ; proto . add_repeated_fixed32 ( 0 ) ; proto . add_repeated_fixed32 ( 50 ) ; proto . add_repeated_fixed64 ( -60 ) ; proto . add_repeated_fixed64 ( 0 ) ; proto . add_repeated_fixed64 ( 60 ) ; proto . add_repeated_sfixed32 ( -70 ) ; proto . add_repeated_sfixed32 ( 0 ) ; proto . add_repeated_sfixed32 ( 70 ) ; proto . add_repeated_sfixed64 ( -80 ) ; proto . add_repeated_sfixed64 ( 0 ) ; proto . add_repeated_sfixed64 ( 80 ) ; proto . add_repeated_float ( -1.2345 ) ; proto . add_repeated_float ( 0 ) ; proto . add_repeated_float ( -2.3456 ) ; proto . add_repeated_double ( -10.2345 ) ; proto . add_repeated_double ( 0 ) ; proto . add_repeated_double ( -20.3456 ) ; proto . add_repeated_bool ( false ) ; proto . add_repeated_bool ( true ) ; proto . add_repeated_bool ( false ) ; proto . add_repeated_string ( " " ) ; proto . add_repeated_string ( " " ) ; proto . add_repeated_string ( " " ) ; proto . add_repeated_cord ( " " ) ; proto . add_repeated_cord ( " " ) ; proto . add_repeated_cord ( " " ) ; proto . add_packed_repeated_int64 ( -1000 ) ; proto . add_packed_repeated_int64 ( 0 ) ; proto . add_packed_repeated_int64 ( 1000 ) ; EXPECT_TEXT_TRANSFORMS_MATCH ( ) ; EXPECT_PARSE_SUCCESS ( " " , " " ) ; EXPECT_PARSE_SUCCESS ( ( " " " " " " ) , " " ) ; EXPECT_PARSE_SUCCESS ( ( " \" \" " " \" \" " ) , " " ) ; EXPECT_PARSE_SUCCESS ( " \" \\ \" \\ \" " , " \\ \" \\ " ) ; EXPECT_PARSE_SUCCESS ( " " , " " ) ; EXPECT_PARSE_FAILURE ( " " ) ; EXPECT_PARSE_FAILURE ( " " ) ; EXPECT_PARSE_FAILURE ( " " ) ; EXPECT_PARSE_FAILURE ( " " ) ; EXPECT_PARSE_FAILURE ( " " ) ; EXPECT_PARSE_FAILURE ( " " ) ; EXPECT_PARSE_FAILURE ( " " ) ; EXPECT_PARSE_FAILURE ( " " ) ; EXPECT_PARSE_FAILURE ( " \" " ) ; EXPECT_PARSE_FAILURE ( " " ) ; EXPECT_PARSE_FAILURE ( " " ) ; }
Test different cases of numeric values, including repeated values.
Test different cases of numeric values including repeated values .
// Note that this also tests that output of fields matches tag number order, // since some of these fields have high tag numbers. // Max numeric values. // TODO(b/67475677): Re-enable after resolving float precision issue // proto.set_optional_float(std::numeric_limits<float>::max()); // Least positive numeric values. // TODO(b/67475677): Re-enable after resolving float precision issue // proto.set_optional_float(std::numeric_limits<float>::min()); // Lowest numeric values. // TODO(b/67475677): Re-enable after resolving float precision issue // proto.set_optional_float(std::numeric_limits<float>::lowest()); // inf and -inf for float and double. // String and bytes values. // Repeated values. Include zero values to show they are retained in // repeateds. // Proto supports [] for list values as well. // Test [] and also interesting bool values. // Proto supports ' as quote character. // Error cases.