Test different cases of numeric values, including repeated values.
| 67 | |
| 68 | // Test different cases of numeric values, including repeated values. |
| 69 | TEST(CreateProtoDebugStringLibTest, ValidSimpleTypes) { |
| 70 | TestAllTypes proto; |
| 71 | |
| 72 | // Note that this also tests that output of fields matches tag number order, |
| 73 | // since some of these fields have high tag numbers. |
| 74 | proto.Clear(); |
| 75 | proto.set_optional_int32(-1); |
| 76 | proto.set_optional_int64(-2); |
| 77 | proto.set_optional_uint32(3); |
| 78 | proto.set_optional_uint64(4); |
| 79 | proto.set_optional_sint32(-5); |
| 80 | proto.set_optional_sint64(-6); |
| 81 | proto.set_optional_fixed32(-7); |
| 82 | proto.set_optional_fixed64(-8); |
| 83 | proto.set_optional_sfixed32(-9); |
| 84 | proto.set_optional_sfixed64(-10); |
| 85 | proto.set_optional_float(-12.34); |
| 86 | proto.set_optional_double(-5.678); |
| 87 | proto.set_optional_bool(true); |
| 88 | EXPECT_TEXT_TRANSFORMS_MATCH(); |
| 89 | |
| 90 | // Max numeric values. |
| 91 | proto.Clear(); |
| 92 | proto.set_optional_int32(std::numeric_limits<int32>::max()); |
| 93 | proto.set_optional_int64(std::numeric_limits<protobuf_int64>::max()); |
| 94 | proto.set_optional_uint32(std::numeric_limits<uint32>::max()); |
| 95 | proto.set_optional_uint64(std::numeric_limits<uint64>::max()); |
| 96 | // TODO(b/67475677): Re-enable after resolving float precision issue |
| 97 | // proto.set_optional_float(std::numeric_limits<float>::max()); |
| 98 | proto.set_optional_double(std::numeric_limits<double>::max()); |
| 99 | EXPECT_TEXT_TRANSFORMS_MATCH(); |
| 100 | |
| 101 | // Least positive numeric values. |
| 102 | proto.Clear(); |
| 103 | // TODO(b/67475677): Re-enable after resolving float precision issue |
| 104 | // proto.set_optional_float(std::numeric_limits<float>::min()); |
| 105 | proto.set_optional_double(std::numeric_limits<double>::min()); |
| 106 | EXPECT_TEXT_TRANSFORMS_MATCH(); |
| 107 | |
| 108 | // Lowest numeric values. |
| 109 | proto.Clear(); |
| 110 | proto.set_optional_int32(std::numeric_limits<int32>::lowest()); |
| 111 | proto.set_optional_int64(std::numeric_limits<protobuf_int64>::lowest()); |
| 112 | // TODO(b/67475677): Re-enable after resolving float precision issue |
| 113 | // proto.set_optional_float(std::numeric_limits<float>::lowest()); |
| 114 | proto.set_optional_double(std::numeric_limits<double>::lowest()); |
| 115 | EXPECT_TEXT_TRANSFORMS_MATCH(); |
| 116 | |
| 117 | // inf and -inf for float and double. |
| 118 | proto.Clear(); |
| 119 | proto.set_optional_double(std::numeric_limits<double>::infinity()); |
| 120 | proto.set_optional_float(std::numeric_limits<float>::infinity()); |
| 121 | EXPECT_TEXT_TRANSFORMS_MATCH(); |
| 122 | proto.set_optional_double(-1 * std::numeric_limits<double>::infinity()); |
| 123 | proto.set_optional_float(-1 * std::numeric_limits<float>::infinity()); |
| 124 | EXPECT_TEXT_TRANSFORMS_MATCH(); |
| 125 | |
| 126 | // String and bytes values. |