From b72202078d0a7a2f2509eb5237685bcf1baea3b4 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 27 Jan 2023 06:38:06 -0800 Subject: [PATCH] Test current behavior of doubles and floats in RecordProperty PiperOrigin-RevId: 505104193 Change-Id: I4c2758f22ee1321ed6b6662ab2668f6c5b6aa661 --- .../test/googletest-json-outfiles-test.py | 4 +++- googletest/test/gtest_xml_outfile2_test_.cc | 17 +++++++++++++++-- googletest/test/gtest_xml_outfiles_test.py | 4 +++- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/googletest/test/googletest-json-outfiles-test.py b/googletest/test/googletest-json-outfiles-test.py index bc17fe21..3387b1ea 100644 --- a/googletest/test/googletest-json-outfiles-test.py +++ b/googletest/test/googletest-json-outfiles-test.py @@ -97,7 +97,9 @@ EXPECTED_2 = { 'time': '*', 'classname': 'PropertyTwo', 'SetUpProp': '2', - 'TestSomeProperty': '2', + 'TestFloatProperty': '3', + 'TestDoubleProperty': '4', + 'TestSizetProperty': '5', 'TearDownProp': '2', }], }], diff --git a/googletest/test/gtest_xml_outfile2_test_.cc b/googletest/test/gtest_xml_outfile2_test_.cc index f743b31b..047d3f6c 100644 --- a/googletest/test/gtest_xml_outfile2_test_.cc +++ b/googletest/test/gtest_xml_outfile2_test_.cc @@ -39,7 +39,20 @@ class PropertyTwo : public testing::Test { }; 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. + 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 prop_two = 2; - RecordProperty("TestSomeProperty", prop_two); + size_t size_t_prop = 5; + RecordProperty("TestSizetProperty", size_t_prop); } diff --git a/googletest/test/gtest_xml_outfiles_test.py b/googletest/test/gtest_xml_outfiles_test.py index b482f025..de6794f6 100755 --- a/googletest/test/gtest_xml_outfiles_test.py +++ b/googletest/test/gtest_xml_outfiles_test.py @@ -60,7 +60,9 @@ EXPECTED_XML_2 = """ - + + +