From 750d67d809700ae8fca6d610f7b41b71aa161808 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Tue, 21 Feb 2023 10:24:42 -0800 Subject: Remove int64_t cast in RecordProperty Historically, calls to RecordProperty with values that are convertible to int64_t have been casted to int64_t. The result was that types like float or double would be truncated when printed (e.g., 4.75 -> 4). This change removes the cast so that the types are printed in a more appropriate manner. PiperOrigin-RevId: 511238685 Change-Id: I80de5db14462da2a3e1f476086025ae514383a17 --- googletest/include/gtest/gtest.h | 2 +- googletest/test/googletest-json-outfiles-test.py | 10 +++++----- googletest/test/gtest_xml_outfile2_test_.cc | 4 +--- googletest/test/gtest_xml_outfiles_test.py | 10 +++++----- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index 35c0802..6fdf552 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -302,7 +302,7 @@ class GTEST_API_ Test { template ::value, bool> = true> static void RecordProperty(const std::string& key, const T& value) { - RecordProperty(key, (Message() << static_cast(value)).GetString()); + RecordProperty(key, (Message() << value).GetString()); } protected: diff --git a/googletest/test/googletest-json-outfiles-test.py b/googletest/test/googletest-json-outfiles-test.py index 83a56de..ff15722 100644 --- a/googletest/test/googletest-json-outfiles-test.py +++ b/googletest/test/googletest-json-outfiles-test.py @@ -88,7 +88,7 @@ EXPECTED_2 = { 'time': '*', 'timestamp': '*', 'testsuite': [{ - 'name': 'TestInt64Properties', + 'name': 'TestInt64ConvertibleProperties', 'file': 'gtest_xml_outfile2_test_.cc', 'line': 41, 'status': 'RUN', @@ -97,11 +97,11 @@ EXPECTED_2 = { 'time': '*', 'classname': 'PropertyTwo', 'SetUpProp': '2', - 'TestFloatProperty': '3', - 'TestDoubleProperty': '4', + 'TestFloatProperty': '3.25', + 'TestDoubleProperty': '4.75', 'TestSizetProperty': '5', - 'TestBoolProperty': '1', - 'TestCharProperty': '65', + 'TestBoolProperty': 'true', + 'TestCharProperty': 'A', 'TestInt16Property': '6', 'TestInt32Property': '7', 'TestInt64Property': '8', diff --git a/googletest/test/gtest_xml_outfile2_test_.cc b/googletest/test/gtest_xml_outfile2_test_.cc index 5ee216d..ed58dc8 100644 --- a/googletest/test/gtest_xml_outfile2_test_.cc +++ b/googletest/test/gtest_xml_outfile2_test_.cc @@ -38,9 +38,7 @@ class PropertyTwo : public testing::Test { void TearDown() override { RecordProperty("TearDownProp", 2); } }; -TEST_F(PropertyTwo, TestInt64Properties) { - // Floats and doubles are written as int64_t, so we test that the values - // written are truncated to int64_t. +TEST_F(PropertyTwo, TestInt64ConvertibleProperties) { float float_prop = 3.25; RecordProperty("TestFloatProperty", float_prop); diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py index 7ee0f3c..50291b0 100755 --- a/googletest/test/gtest_xml_outfiles_test.py +++ b/googletest/test/gtest_xml_outfiles_test.py @@ -57,14 +57,14 @@ EXPECTED_XML_1 = """ EXPECTED_XML_2 = """ - + - - + + - - + + -- cgit v0.12