From deaf5615f18dd3b051006ba7326e2a976f5dff46 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Thu, 2 Feb 2023 09:31:10 -0800 Subject: Fix -Wsign-conversion warnings googletest/test/gtest_xml_outfile2_test_.cc:48:39: warning: implicit conversion turns floating-point number into integer: 'float' to 'int64_t' (aka 'long') [-Wfloat-conversion] RecordProperty("TestFloatProperty", float_prop); ~~~~~~~~~~~~~~ ^~~~~~~~~~ googletest/test/gtest_xml_outfile2_test_.cc:51:40: warning: implicit conversion turns floating-point number into integer: 'double' to 'int64_t' (aka 'long') [-Wfloat-conversion] RecordProperty("TestDoubleProperty", double_prop); ~~~~~~~~~~~~~~ ^~~~~~~~~~~ googletest/test/gtest_xml_outfile2_test_.cc:57:39: warning: implicit conversion changes signedness: 'size_t' (aka 'unsigned long') to 'int64_t' (aka 'long') [-Wsign-conversion] RecordProperty("TestSizetProperty", size_t_prop); ~~~~~~~~~~~~~~ ^~~~~~~~~~~ PiperOrigin-RevId: 506644143 Change-Id: I9c2cd5f52daebe25e73bb97f696687797ed2cabf --- googletest/include/gtest/gtest.h | 8 +++++- googletest/src/gtest.cc | 5 ---- googletest/test/googletest-json-outfiles-test.py | 9 +++++- googletest/test/gtest_xml_outfile2_test_.cc | 35 ++++++++++++++++++------ googletest/test/gtest_xml_outfiles_test.py | 9 +++++- 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index f99df35..35c0802 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -297,7 +297,13 @@ class GTEST_API_ Test { // SetUp/TearDown method of Environment objects registered with Google // Test) will be output as attributes of the element. static void RecordProperty(const std::string& key, const std::string& value); - static void RecordProperty(const std::string& key, int64_t value); + // We do not define a custom serialization except for values that can be + // converted to int64_t, but other values could be logged in this way. + template ::value, + bool> = true> + static void RecordProperty(const std::string& key, const T& value) { + RecordProperty(key, (Message() << static_cast(value)).GetString()); + } protected: // Creates a Test object. diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index b928943..f79f915 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc @@ -2459,11 +2459,6 @@ void Test::TearDown() {} void Test::RecordProperty(const std::string& key, const std::string& value) { UnitTest::GetInstance()->RecordProperty(key, value); } -// We do not define a customary serialization except for integers, -// but other values could be logged in this way. -void Test::RecordProperty(const std::string& key, int64_t value) { - RecordProperty(key, (Message() << value).GetString()); -} namespace internal { diff --git a/googletest/test/googletest-json-outfiles-test.py b/googletest/test/googletest-json-outfiles-test.py index 3387b1e..83a56de 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': 'TestSomeProperties', + 'name': 'TestInt64Properties', 'file': 'gtest_xml_outfile2_test_.cc', 'line': 41, 'status': 'RUN', @@ -100,6 +100,13 @@ EXPECTED_2 = { 'TestFloatProperty': '3', 'TestDoubleProperty': '4', 'TestSizetProperty': '5', + 'TestBoolProperty': '1', + 'TestCharProperty': '65', + 'TestInt16Property': '6', + 'TestInt32Property': '7', + 'TestInt64Property': '8', + 'TestEnumProperty': '9', + 'TestAtomicIntProperty': '10', 'TearDownProp': '2', }], }], diff --git a/googletest/test/gtest_xml_outfile2_test_.cc b/googletest/test/gtest_xml_outfile2_test_.cc index 047d3f6..5ee216d 100644 --- a/googletest/test/gtest_xml_outfile2_test_.cc +++ b/googletest/test/gtest_xml_outfile2_test_.cc @@ -38,21 +38,40 @@ class PropertyTwo : public testing::Test { void TearDown() override { RecordProperty("TearDownProp", 2); } }; -TEST_F(PropertyTwo, TestSomeProperties) { -// 'initializing': conversion from 'int' to 'short', possible loss of data - GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244) - - // Floats and doubles are written as int64_t, since RecordProperty takes an - // int64_t, so we test that the values written are truncated to int64_t. +TEST_F(PropertyTwo, TestInt64Properties) { + // Floats and doubles are written as int64_t, so we test that the values + // written are truncated to int64_t. float float_prop = 3.25; RecordProperty("TestFloatProperty", float_prop); double double_prop = 4.75; RecordProperty("TestDoubleProperty", double_prop); - GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 - // Validate we can write an unsigned size_t as a property size_t size_t_prop = 5; RecordProperty("TestSizetProperty", size_t_prop); + + bool bool_prop = true; + RecordProperty("TestBoolProperty", bool_prop); + + char char_prop = 'A'; + RecordProperty("TestCharProperty", char_prop); + + int16_t int16_prop = 6; + RecordProperty("TestInt16Property", int16_prop); + + int32_t int32_prop = 7; + RecordProperty("TestInt32Property", int32_prop); + + int64_t int64_prop = 8; + RecordProperty("TestInt64Property", int64_prop); + + enum Foo { + NINE = 9, + }; + Foo enum_prop = NINE; + RecordProperty("TestEnumProperty", enum_prop); + + std::atomic atomic_int_prop(10); + RecordProperty("TestAtomicIntProperty", atomic_int_prop); } diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py index de6794f..7ee0f3c 100755 --- a/googletest/test/gtest_xml_outfiles_test.py +++ b/googletest/test/gtest_xml_outfiles_test.py @@ -57,12 +57,19 @@ EXPECTED_XML_1 = """ EXPECTED_XML_2 = """ - + + + + + + + + -- cgit v0.12