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
This commit is contained in:
Tom Hughes 2023-02-21 10:24:42 -08:00 committed by Copybara-Service
parent 7a7231c442
commit 750d67d809
4 changed files with 12 additions and 14 deletions

View File

@ -302,7 +302,7 @@ class GTEST_API_ Test {
template <typename T, std::enable_if_t<std::is_convertible<T, int64_t>::value,
bool> = true>
static void RecordProperty(const std::string& key, const T& value) {
RecordProperty(key, (Message() << static_cast<int64_t>(value)).GetString());
RecordProperty(key, (Message() << value).GetString());
}
protected:

View File

@ -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',

View File

@ -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);

View File

@ -57,14 +57,14 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
<testsuite name="PropertyTwo" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*">
<testcase name="TestInt64Properties" file="gtest_xml_outfile2_test_.cc" line="41" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo">
<testcase name="TestInt64ConvertibleProperties" file="gtest_xml_outfile2_test_.cc" line="41" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo">
<properties>
<property name="SetUpProp" value="2"/>
<property name="TestFloatProperty" value="3"/>
<property name="TestDoubleProperty" value="4"/>
<property name="TestFloatProperty" value="3.25"/>
<property name="TestDoubleProperty" value="4.75"/>
<property name="TestSizetProperty" value="5"/>
<property name="TestBoolProperty" value="1"/>
<property name="TestCharProperty" value="65"/>
<property name="TestBoolProperty" value="true"/>
<property name="TestCharProperty" value="A"/>
<property name="TestInt16Property" value="6"/>
<property name="TestInt32Property" value="7"/>
<property name="TestInt64Property" value="8"/>