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:
parent
7a7231c442
commit
750d67d809
@ -302,7 +302,7 @@ class GTEST_API_ Test {
|
|||||||
template <typename T, std::enable_if_t<std::is_convertible<T, int64_t>::value,
|
template <typename T, std::enable_if_t<std::is_convertible<T, int64_t>::value,
|
||||||
bool> = true>
|
bool> = true>
|
||||||
static void RecordProperty(const std::string& key, const T& value) {
|
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:
|
protected:
|
||||||
|
@ -88,7 +88,7 @@ EXPECTED_2 = {
|
|||||||
'time': '*',
|
'time': '*',
|
||||||
'timestamp': '*',
|
'timestamp': '*',
|
||||||
'testsuite': [{
|
'testsuite': [{
|
||||||
'name': 'TestInt64Properties',
|
'name': 'TestInt64ConvertibleProperties',
|
||||||
'file': 'gtest_xml_outfile2_test_.cc',
|
'file': 'gtest_xml_outfile2_test_.cc',
|
||||||
'line': 41,
|
'line': 41,
|
||||||
'status': 'RUN',
|
'status': 'RUN',
|
||||||
@ -97,11 +97,11 @@ EXPECTED_2 = {
|
|||||||
'time': '*',
|
'time': '*',
|
||||||
'classname': 'PropertyTwo',
|
'classname': 'PropertyTwo',
|
||||||
'SetUpProp': '2',
|
'SetUpProp': '2',
|
||||||
'TestFloatProperty': '3',
|
'TestFloatProperty': '3.25',
|
||||||
'TestDoubleProperty': '4',
|
'TestDoubleProperty': '4.75',
|
||||||
'TestSizetProperty': '5',
|
'TestSizetProperty': '5',
|
||||||
'TestBoolProperty': '1',
|
'TestBoolProperty': 'true',
|
||||||
'TestCharProperty': '65',
|
'TestCharProperty': 'A',
|
||||||
'TestInt16Property': '6',
|
'TestInt16Property': '6',
|
||||||
'TestInt32Property': '7',
|
'TestInt32Property': '7',
|
||||||
'TestInt64Property': '8',
|
'TestInt64Property': '8',
|
||||||
|
@ -38,9 +38,7 @@ class PropertyTwo : public testing::Test {
|
|||||||
void TearDown() override { RecordProperty("TearDownProp", 2); }
|
void TearDown() override { RecordProperty("TearDownProp", 2); }
|
||||||
};
|
};
|
||||||
|
|
||||||
TEST_F(PropertyTwo, TestInt64Properties) {
|
TEST_F(PropertyTwo, TestInt64ConvertibleProperties) {
|
||||||
// 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;
|
float float_prop = 3.25;
|
||||||
RecordProperty("TestFloatProperty", float_prop);
|
RecordProperty("TestFloatProperty", float_prop);
|
||||||
|
|
||||||
|
@ -57,14 +57,14 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
|
|||||||
EXPECTED_XML_2 = """<?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">
|
<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="*">
|
<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>
|
<properties>
|
||||||
<property name="SetUpProp" value="2"/>
|
<property name="SetUpProp" value="2"/>
|
||||||
<property name="TestFloatProperty" value="3"/>
|
<property name="TestFloatProperty" value="3.25"/>
|
||||||
<property name="TestDoubleProperty" value="4"/>
|
<property name="TestDoubleProperty" value="4.75"/>
|
||||||
<property name="TestSizetProperty" value="5"/>
|
<property name="TestSizetProperty" value="5"/>
|
||||||
<property name="TestBoolProperty" value="1"/>
|
<property name="TestBoolProperty" value="true"/>
|
||||||
<property name="TestCharProperty" value="65"/>
|
<property name="TestCharProperty" value="A"/>
|
||||||
<property name="TestInt16Property" value="6"/>
|
<property name="TestInt16Property" value="6"/>
|
||||||
<property name="TestInt32Property" value="7"/>
|
<property name="TestInt32Property" value="7"/>
|
||||||
<property name="TestInt64Property" value="8"/>
|
<property name="TestInt64Property" value="8"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user