Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
e92cceda
Commit
e92cceda
authored
Jan 08, 2010
by
zhanyong.wan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changes Message() to print double with enough precision by default.
parent
ef37aa40
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
39 deletions
+57
-39
gtest-message.h
include/gtest/gtest-message.h
+7
-1
prime_tables.h
samples/prime_tables.h
+1
-1
gtest.cc
src/gtest.cc
+8
-10
gtest-message_test.cc
test/gtest-message_test.cc
+17
-3
gtest_unittest.cc
test/gtest_unittest.cc
+24
-24
No files found.
include/gtest/gtest-message.h
View file @
e92cceda
...
@@ -46,6 +46,8 @@
...
@@ -46,6 +46,8 @@
#ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
#ifndef GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
#define GTEST_INCLUDE_GTEST_GTEST_MESSAGE_H_
#include <limits>
#include <gtest/internal/gtest-string.h>
#include <gtest/internal/gtest-string.h>
#include <gtest/internal/gtest-internal.h>
#include <gtest/internal/gtest-internal.h>
...
@@ -89,7 +91,11 @@ class Message {
...
@@ -89,7 +91,11 @@ class Message {
// ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
// ASSERT/EXPECT in a procedure adds over 200 bytes to the procedure's
// stack frame leading to huge stack frames in some cases; gcc does not reuse
// stack frame leading to huge stack frames in some cases; gcc does not reuse
// the stack space.
// the stack space.
Message
()
:
ss_
(
new
internal
::
StrStream
)
{}
Message
()
:
ss_
(
new
internal
::
StrStream
)
{
// By default, we want there to be enough precision when printing
// a double to a Message.
*
ss_
<<
std
::
setprecision
(
std
::
numeric_limits
<
double
>::
digits10
+
2
);
}
// Copy constructor.
// Copy constructor.
Message
(
const
Message
&
msg
)
:
ss_
(
new
internal
::
StrStream
)
{
// NOLINT
Message
(
const
Message
&
msg
)
:
ss_
(
new
internal
::
StrStream
)
{
// NOLINT
...
...
samples/prime_tables.h
View file @
e92cceda
...
@@ -116,7 +116,7 @@ class PreCalculatedPrimeTable : public PrimeTable {
...
@@ -116,7 +116,7 @@ class PreCalculatedPrimeTable : public PrimeTable {
const
int
is_prime_size_
;
const
int
is_prime_size_
;
bool
*
const
is_prime_
;
bool
*
const
is_prime_
;
// Disables compiler w
qarning "assignment operator could
ot be generated."
// Disables compiler w
arning "assignment operator could n
ot be generated."
void
operator
=
(
const
PreCalculatedPrimeTable
&
rhs
);
void
operator
=
(
const
PreCalculatedPrimeTable
&
rhs
);
};
};
...
...
src/gtest.cc
View file @
e92cceda
...
@@ -43,6 +43,7 @@
...
@@ -43,6 +43,7 @@
#include <wctype.h>
#include <wctype.h>
#include <ostream>
#include <ostream>
#include <sstream>
#if GTEST_OS_LINUX
#if GTEST_OS_LINUX
...
@@ -3168,14 +3169,11 @@ String XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(const char* str) {
...
@@ -3168,14 +3169,11 @@ String XmlUnitTestResultPrinter::RemoveInvalidXmlCharacters(const char* str) {
// </testsuite>
// </testsuite>
// </testsuites>
// </testsuites>
// Formats the given time in milliseconds as seconds. The returned
// Formats the given time in milliseconds as seconds.
// C-string is owned by this function and cannot be released by the
std
::
string
FormatTimeInMillisAsSeconds
(
TimeInMillis
ms
)
{
// caller. Calling the function again invalidates the previous
::
std
::
stringstream
ss
;
// result.
ss
<<
ms
/
1000.0
;
const
char
*
FormatTimeInMillisAsSeconds
(
TimeInMillis
ms
)
{
return
ss
.
str
();
static
String
str
;
str
=
(
Message
()
<<
(
ms
/
1000.0
)).
GetString
();
return
str
.
c_str
();
}
}
// Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
// Streams an XML CDATA section, escaping invalid CDATA sequences as needed.
...
@@ -3249,7 +3247,7 @@ void XmlUnitTestResultPrinter::PrintXmlTestCase(FILE* out,
...
@@ -3249,7 +3247,7 @@ void XmlUnitTestResultPrinter::PrintXmlTestCase(FILE* out,
test_case
.
disabled_test_count
());
test_case
.
disabled_test_count
());
fprintf
(
out
,
fprintf
(
out
,
"errors=
\"
0
\"
time=
\"
%s
\"
>
\n
"
,
"errors=
\"
0
\"
time=
\"
%s
\"
>
\n
"
,
FormatTimeInMillisAsSeconds
(
test_case
.
elapsed_time
()));
FormatTimeInMillisAsSeconds
(
test_case
.
elapsed_time
())
.
c_str
()
);
for
(
int
i
=
0
;
i
<
test_case
.
total_test_count
();
++
i
)
{
for
(
int
i
=
0
;
i
<
test_case
.
total_test_count
();
++
i
)
{
StrStream
stream
;
StrStream
stream
;
OutputXmlTestInfo
(
&
stream
,
test_case
.
name
(),
*
test_case
.
GetTestInfo
(
i
));
OutputXmlTestInfo
(
&
stream
,
test_case
.
name
(),
*
test_case
.
GetTestInfo
(
i
));
...
@@ -3268,7 +3266,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,
...
@@ -3268,7 +3266,7 @@ void XmlUnitTestResultPrinter::PrintXmlUnitTest(FILE* out,
unit_test
.
total_test_count
(),
unit_test
.
total_test_count
(),
unit_test
.
failed_test_count
(),
unit_test
.
failed_test_count
(),
unit_test
.
disabled_test_count
(),
unit_test
.
disabled_test_count
(),
FormatTimeInMillisAsSeconds
(
unit_test
.
elapsed_time
()));
FormatTimeInMillisAsSeconds
(
unit_test
.
elapsed_time
())
.
c_str
()
);
if
(
GTEST_FLAG
(
shuffle
))
{
if
(
GTEST_FLAG
(
shuffle
))
{
fprintf
(
out
,
"random_seed=
\"
%d
\"
"
,
unit_test
.
random_seed
());
fprintf
(
out
,
"random_seed=
\"
%d
\"
"
,
unit_test
.
random_seed
());
}
}
...
...
test/gtest-message_test.cc
View file @
e92cceda
...
@@ -68,6 +68,23 @@ TEST(MessageTest, ConstructsFromCString) {
...
@@ -68,6 +68,23 @@ TEST(MessageTest, ConstructsFromCString) {
EXPECT_STREQ
(
"Hello"
,
ToCString
(
msg
));
EXPECT_STREQ
(
"Hello"
,
ToCString
(
msg
));
}
}
// Tests streaming a float.
TEST
(
MessageTest
,
StreamsFloat
)
{
const
char
*
const
s
=
ToCString
(
Message
()
<<
1.23456
F
<<
" "
<<
2.34567
F
);
// Both numbers should be printed with enough precision.
EXPECT_PRED_FORMAT2
(
testing
::
IsSubstring
,
"1.234560"
,
s
);
EXPECT_PRED_FORMAT2
(
testing
::
IsSubstring
,
" 2.345669"
,
s
);
}
// Tests streaming a double.
TEST
(
MessageTest
,
StreamsDouble
)
{
const
char
*
const
s
=
ToCString
(
Message
()
<<
1260570880.4555497
<<
" "
<<
1260572265.1954534
);
// Both numbers should be printed with enough precision.
EXPECT_PRED_FORMAT2
(
testing
::
IsSubstring
,
"1260570880.45"
,
s
);
EXPECT_PRED_FORMAT2
(
testing
::
IsSubstring
,
" 1260572265.19"
,
s
);
}
// Tests streaming a non-char pointer.
// Tests streaming a non-char pointer.
TEST
(
MessageTest
,
StreamsPointer
)
{
TEST
(
MessageTest
,
StreamsPointer
)
{
int
n
=
0
;
int
n
=
0
;
...
@@ -93,9 +110,6 @@ TEST(MessageTest, StreamsNullCString) {
...
@@ -93,9 +110,6 @@ TEST(MessageTest, StreamsNullCString) {
}
}
// Tests streaming std::string.
// Tests streaming std::string.
//
// As std::string has problem in MSVC when exception is disabled, we only
// test this where std::string can be used.
TEST
(
MessageTest
,
StreamsString
)
{
TEST
(
MessageTest
,
StreamsString
)
{
const
::
std
::
string
str
(
"Hello"
);
const
::
std
::
string
str
(
"Hello"
);
EXPECT_STREQ
(
"Hello"
,
ToCString
(
Message
()
<<
str
));
EXPECT_STREQ
(
"Hello"
,
ToCString
(
Message
()
<<
str
));
...
...
test/gtest_unittest.cc
View file @
e92cceda
...
@@ -82,7 +82,7 @@ namespace testing {
...
@@ -82,7 +82,7 @@ namespace testing {
namespace
internal
{
namespace
internal
{
bool
ShouldUseColor
(
bool
stdout_is_tty
);
bool
ShouldUseColor
(
bool
stdout_is_tty
);
const
char
*
FormatTimeInMillisAsSeconds
(
TimeInMillis
ms
);
::
std
::
string
FormatTimeInMillisAsSeconds
(
TimeInMillis
ms
);
bool
ParseInt32Flag
(
const
char
*
str
,
const
char
*
flag
,
Int32
*
value
);
bool
ParseInt32Flag
(
const
char
*
str
,
const
char
*
flag
,
Int32
*
value
);
// Used for testing the flag parsing.
// Used for testing the flag parsing.
...
@@ -270,23 +270,23 @@ TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
...
@@ -270,23 +270,23 @@ TEST(GetTestTypeIdTest, ReturnsTheSameValueInsideOrOutsideOfGoogleTest) {
// Tests FormatTimeInMillisAsSeconds().
// Tests FormatTimeInMillisAsSeconds().
TEST
(
FormatTimeInMillisAsSecondsTest
,
FormatsZero
)
{
TEST
(
FormatTimeInMillisAsSecondsTest
,
FormatsZero
)
{
EXPECT_
STR
EQ
(
"0"
,
FormatTimeInMillisAsSeconds
(
0
));
EXPECT_EQ
(
"0"
,
FormatTimeInMillisAsSeconds
(
0
));
}
}
TEST
(
FormatTimeInMillisAsSecondsTest
,
FormatsPositiveNumber
)
{
TEST
(
FormatTimeInMillisAsSecondsTest
,
FormatsPositiveNumber
)
{
EXPECT_
STR
EQ
(
"0.003"
,
FormatTimeInMillisAsSeconds
(
3
));
EXPECT_EQ
(
"0.003"
,
FormatTimeInMillisAsSeconds
(
3
));
EXPECT_
STR
EQ
(
"0.01"
,
FormatTimeInMillisAsSeconds
(
10
));
EXPECT_EQ
(
"0.01"
,
FormatTimeInMillisAsSeconds
(
10
));
EXPECT_
STR
EQ
(
"0.2"
,
FormatTimeInMillisAsSeconds
(
200
));
EXPECT_EQ
(
"0.2"
,
FormatTimeInMillisAsSeconds
(
200
));
EXPECT_
STR
EQ
(
"1.2"
,
FormatTimeInMillisAsSeconds
(
1200
));
EXPECT_EQ
(
"1.2"
,
FormatTimeInMillisAsSeconds
(
1200
));
EXPECT_
STR
EQ
(
"3"
,
FormatTimeInMillisAsSeconds
(
3000
));
EXPECT_EQ
(
"3"
,
FormatTimeInMillisAsSeconds
(
3000
));
}
}
TEST
(
FormatTimeInMillisAsSecondsTest
,
FormatsNegativeNumber
)
{
TEST
(
FormatTimeInMillisAsSecondsTest
,
FormatsNegativeNumber
)
{
EXPECT_
STR
EQ
(
"-0.003"
,
FormatTimeInMillisAsSeconds
(
-
3
));
EXPECT_EQ
(
"-0.003"
,
FormatTimeInMillisAsSeconds
(
-
3
));
EXPECT_
STR
EQ
(
"-0.01"
,
FormatTimeInMillisAsSeconds
(
-
10
));
EXPECT_EQ
(
"-0.01"
,
FormatTimeInMillisAsSeconds
(
-
10
));
EXPECT_
STR
EQ
(
"-0.2"
,
FormatTimeInMillisAsSeconds
(
-
200
));
EXPECT_EQ
(
"-0.2"
,
FormatTimeInMillisAsSeconds
(
-
200
));
EXPECT_
STR
EQ
(
"-1.2"
,
FormatTimeInMillisAsSeconds
(
-
1200
));
EXPECT_EQ
(
"-1.2"
,
FormatTimeInMillisAsSeconds
(
-
1200
));
EXPECT_
STR
EQ
(
"-3"
,
FormatTimeInMillisAsSeconds
(
-
3000
));
EXPECT_EQ
(
"-3"
,
FormatTimeInMillisAsSeconds
(
-
3000
));
}
}
#if !GTEST_OS_SYMBIAN
#if !GTEST_OS_SYMBIAN
...
@@ -3095,9 +3095,9 @@ TEST_F(FloatTest, Commutative) {
...
@@ -3095,9 +3095,9 @@ TEST_F(FloatTest, Commutative) {
TEST_F
(
FloatTest
,
EXPECT_NEAR
)
{
TEST_F
(
FloatTest
,
EXPECT_NEAR
)
{
EXPECT_NEAR
(
-
1.0
f
,
-
1.1
f
,
0.2
f
);
EXPECT_NEAR
(
-
1.0
f
,
-
1.1
f
,
0.2
f
);
EXPECT_NEAR
(
2.0
f
,
3.0
f
,
1.0
f
);
EXPECT_NEAR
(
2.0
f
,
3.0
f
,
1.0
f
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_NEAR
(
1.0
f
,
1.
2
f
,
0.1
f
),
// NOLINT
EXPECT_NONFATAL_FAILURE
(
EXPECT_NEAR
(
1.0
f
,
1.
5
f
,
0.25
f
),
// NOLINT
"The difference between 1.0f and 1.
2f is 0.2
, "
"The difference between 1.0f and 1.
5f is 0.5
, "
"which exceeds 0.
1
f"
);
"which exceeds 0.
25
f"
);
// To work around a bug in gcc 2.95.0, there is intentionally no
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous line.
// space after the first comma in the previous line.
}
}
...
@@ -3106,9 +3106,9 @@ TEST_F(FloatTest, EXPECT_NEAR) {
...
@@ -3106,9 +3106,9 @@ TEST_F(FloatTest, EXPECT_NEAR) {
TEST_F
(
FloatTest
,
ASSERT_NEAR
)
{
TEST_F
(
FloatTest
,
ASSERT_NEAR
)
{
ASSERT_NEAR
(
-
1.0
f
,
-
1.1
f
,
0.2
f
);
ASSERT_NEAR
(
-
1.0
f
,
-
1.1
f
,
0.2
f
);
ASSERT_NEAR
(
2.0
f
,
3.0
f
,
1.0
f
);
ASSERT_NEAR
(
2.0
f
,
3.0
f
,
1.0
f
);
EXPECT_FATAL_FAILURE
(
ASSERT_NEAR
(
1.0
f
,
1.
2
f
,
0.1
f
),
// NOLINT
EXPECT_FATAL_FAILURE
(
ASSERT_NEAR
(
1.0
f
,
1.
5
f
,
0.25
f
),
// NOLINT
"The difference between 1.0f and 1.
2f is 0.2
, "
"The difference between 1.0f and 1.
5f is 0.5
, "
"which exceeds 0.
1
f"
);
"which exceeds 0.
25
f"
);
// To work around a bug in gcc 2.95.0, there is intentionally no
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous line.
// space after the first comma in the previous line.
}
}
...
@@ -3261,9 +3261,9 @@ TEST_F(DoubleTest, Commutative) {
...
@@ -3261,9 +3261,9 @@ TEST_F(DoubleTest, Commutative) {
TEST_F
(
DoubleTest
,
EXPECT_NEAR
)
{
TEST_F
(
DoubleTest
,
EXPECT_NEAR
)
{
EXPECT_NEAR
(
-
1.0
,
-
1.1
,
0.2
);
EXPECT_NEAR
(
-
1.0
,
-
1.1
,
0.2
);
EXPECT_NEAR
(
2.0
,
3.0
,
1.0
);
EXPECT_NEAR
(
2.0
,
3.0
,
1.0
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_NEAR
(
1.0
,
1.
2
,
0.1
),
// NOLINT
EXPECT_NONFATAL_FAILURE
(
EXPECT_NEAR
(
1.0
,
1.
5
,
0.25
),
// NOLINT
"The difference between 1.0 and 1.
2 is 0.2
, "
"The difference between 1.0 and 1.
5 is 0.5
, "
"which exceeds 0.
1
"
);
"which exceeds 0.
25
"
);
// To work around a bug in gcc 2.95.0, there is intentionally no
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous statement.
// space after the first comma in the previous statement.
}
}
...
@@ -3272,9 +3272,9 @@ TEST_F(DoubleTest, EXPECT_NEAR) {
...
@@ -3272,9 +3272,9 @@ TEST_F(DoubleTest, EXPECT_NEAR) {
TEST_F
(
DoubleTest
,
ASSERT_NEAR
)
{
TEST_F
(
DoubleTest
,
ASSERT_NEAR
)
{
ASSERT_NEAR
(
-
1.0
,
-
1.1
,
0.2
);
ASSERT_NEAR
(
-
1.0
,
-
1.1
,
0.2
);
ASSERT_NEAR
(
2.0
,
3.0
,
1.0
);
ASSERT_NEAR
(
2.0
,
3.0
,
1.0
);
EXPECT_FATAL_FAILURE
(
ASSERT_NEAR
(
1.0
,
1.
2
,
0.1
),
// NOLINT
EXPECT_FATAL_FAILURE
(
ASSERT_NEAR
(
1.0
,
1.
5
,
0.25
),
// NOLINT
"The difference between 1.0 and 1.
2 is 0.2
, "
"The difference between 1.0 and 1.
5 is 0.5
, "
"which exceeds 0.
1
"
);
"which exceeds 0.
25
"
);
// To work around a bug in gcc 2.95.0, there is intentionally no
// To work around a bug in gcc 2.95.0, there is intentionally no
// space after the first comma in the previous statement.
// space after the first comma in the previous statement.
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment