Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
4b83461e
Commit
4b83461e
authored
Jan 29, 2009
by
zhanyong.wan
Browse files
Fixes some warnings when compiled with MSVC at warning level 4.
parent
c946ae60
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
24 deletions
+37
-24
include/gtest/gtest.h
include/gtest/gtest.h
+13
-3
include/gtest/internal/gtest-internal.h
include/gtest/internal/gtest-internal.h
+4
-1
src/gtest-internal-inl.h
src/gtest-internal-inl.h
+4
-0
src/gtest.cc
src/gtest.cc
+9
-13
test/gtest-filepath_test.cc
test/gtest-filepath_test.cc
+1
-1
test/gtest_unittest.cc
test/gtest_unittest.cc
+6
-6
No files found.
include/gtest/gtest.h
View file @
4b83461e
...
@@ -614,10 +614,20 @@ AssertionResult CmpHelperEQ(const char* expected_expression,
...
@@ -614,10 +614,20 @@ AssertionResult CmpHelperEQ(const char* expected_expression,
const
char
*
actual_expression
,
const
char
*
actual_expression
,
const
T1
&
expected
,
const
T1
&
expected
,
const
T2
&
actual
)
{
const
T2
&
actual
)
{
#ifdef _MSC_VER
#pragma warning(push) // Saves the current warning state.
#pragma warning(disable:4389) // Temporarily disables warning on
// signed/unsigned mismatch.
#endif
if
(
expected
==
actual
)
{
if
(
expected
==
actual
)
{
return
AssertionSuccess
();
return
AssertionSuccess
();
}
}
#ifdef _MSC_VER
#pragma warning(pop) // Restores the warning state.
#endif
return
EqFailure
(
expected_expression
,
return
EqFailure
(
expected_expression
,
actual_expression
,
actual_expression
,
FormatForComparisonFailureMessage
(
expected
,
actual
),
FormatForComparisonFailureMessage
(
expected
,
actual
),
...
@@ -688,7 +698,7 @@ class EqHelper<true> {
...
@@ -688,7 +698,7 @@ class EqHelper<true> {
template
<
typename
T1
,
typename
T2
>
template
<
typename
T1
,
typename
T2
>
static
AssertionResult
Compare
(
const
char
*
expected_expression
,
static
AssertionResult
Compare
(
const
char
*
expected_expression
,
const
char
*
actual_expression
,
const
char
*
actual_expression
,
const
T1
&
expected
,
const
T1
&
/*
expected
*/
,
T2
*
actual
)
{
T2
*
actual
)
{
// We already know that 'expected' is a null pointer.
// We already know that 'expected' is a null pointer.
return
CmpHelperEQ
(
expected_expression
,
actual_expression
,
return
CmpHelperEQ
(
expected_expression
,
actual_expression
,
...
@@ -1315,7 +1325,7 @@ bool StaticAssertTypeEq() {
...
@@ -1315,7 +1325,7 @@ bool StaticAssertTypeEq() {
// value, as it always calls GetTypeId<>() from the Google Test
// value, as it always calls GetTypeId<>() from the Google Test
// framework.
// framework.
#define TEST(test_case_name, test_name)\
#define TEST(test_case_name, test_name)\
GTEST_TEST_(test_case_name, test_name,\
GTEST_TEST_(test_case_name, test_name,
\
::testing::Test, ::testing::internal::GetTestTypeId())
::testing::Test, ::testing::internal::GetTestTypeId())
...
@@ -1346,7 +1356,7 @@ bool StaticAssertTypeEq() {
...
@@ -1346,7 +1356,7 @@ bool StaticAssertTypeEq() {
// }
// }
#define TEST_F(test_fixture, test_name)\
#define TEST_F(test_fixture, test_name)\
GTEST_TEST_(test_fixture, test_name, test_fixture,\
GTEST_TEST_(test_fixture, test_name, test_fixture,
\
::testing::internal::GetTypeId<test_fixture>())
::testing::internal::GetTypeId<test_fixture>())
// Use this macro in main() to run all tests. It returns 0 if all
// Use this macro in main() to run all tests. It returns 0 if all
...
...
include/gtest/internal/gtest-internal.h
View file @
4b83461e
...
@@ -748,6 +748,9 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count);
...
@@ -748,6 +748,9 @@ String GetCurrentOsStackTraceExceptTop(UnitTest* unit_test, int skip_count);
// Returns the number of failed test parts in the given test result object.
// Returns the number of failed test parts in the given test result object.
int
GetFailedPartCount
(
const
TestResult
*
result
);
int
GetFailedPartCount
(
const
TestResult
*
result
);
// A helper for suppressing warnings on unreachable code in some macros.
inline
bool
True
()
{
return
true
;
}
}
// namespace internal
}
// namespace internal
}
// namespace testing
}
// namespace testing
...
@@ -835,7 +838,7 @@ int GetFailedPartCount(const TestResult* result);
...
@@ -835,7 +838,7 @@ int GetFailedPartCount(const TestResult* result);
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const char* gtest_msg = "") { \
if (const char* gtest_msg = "") { \
::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
{ statement; } \
if (::testing::internal::True())
{ statement; } \
if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
gtest_msg = "Expected: " #statement " doesn't generate new fatal " \
gtest_msg = "Expected: " #statement " doesn't generate new fatal " \
"failures in the current thread.\n" \
"failures in the current thread.\n" \
...
...
src/gtest-internal-inl.h
View file @
4b83461e
...
@@ -901,6 +901,8 @@ class DefaultGlobalTestPartResultReporter
...
@@ -901,6 +901,8 @@ class DefaultGlobalTestPartResultReporter
private:
private:
UnitTestImpl
*
const
unit_test_
;
UnitTestImpl
*
const
unit_test_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
DefaultGlobalTestPartResultReporter
);
};
};
// This is the default per thread test part result reporter used in
// This is the default per thread test part result reporter used in
...
@@ -915,6 +917,8 @@ class DefaultPerThreadTestPartResultReporter
...
@@ -915,6 +917,8 @@ class DefaultPerThreadTestPartResultReporter
private:
private:
UnitTestImpl
*
const
unit_test_
;
UnitTestImpl
*
const
unit_test_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
DefaultPerThreadTestPartResultReporter
);
};
};
// The private implementation of the UnitTest class. We don't protect
// The private implementation of the UnitTest class. We don't protect
...
...
src/gtest.cc
View file @
4b83461e
...
@@ -374,7 +374,7 @@ bool UnitTestOptions::PatternMatchesString(const char *pattern,
...
@@ -374,7 +374,7 @@ bool UnitTestOptions::PatternMatchesString(const char *pattern,
bool
UnitTestOptions
::
MatchesFilter
(
const
String
&
name
,
const
char
*
filter
)
{
bool
UnitTestOptions
::
MatchesFilter
(
const
String
&
name
,
const
char
*
filter
)
{
const
char
*
cur_pattern
=
filter
;
const
char
*
cur_pattern
=
filter
;
while
(
true
)
{
for
(;;
)
{
if
(
PatternMatchesString
(
cur_pattern
,
name
.
c_str
()))
{
if
(
PatternMatchesString
(
cur_pattern
,
name
.
c_str
()))
{
return
true
;
return
true
;
}
}
...
@@ -1458,23 +1458,19 @@ char* CodePointToUtf8(UInt32 code_point, char* str) {
...
@@ -1458,23 +1458,19 @@ char* CodePointToUtf8(UInt32 code_point, char* str) {
// and thus should be combined into a single Unicode code point
// and thus should be combined into a single Unicode code point
// using CreateCodePointFromUtf16SurrogatePair.
// using CreateCodePointFromUtf16SurrogatePair.
inline
bool
IsUtf16SurrogatePair
(
wchar_t
first
,
wchar_t
second
)
{
inline
bool
IsUtf16SurrogatePair
(
wchar_t
first
,
wchar_t
second
)
{
if
(
sizeof
(
wchar_t
)
==
2
)
return
sizeof
(
wchar_t
)
==
2
&&
return
(
first
&
0xFC00
)
==
0xD800
&&
(
second
&
0xFC00
)
==
0xDC00
;
(
first
&
0xFC00
)
==
0xD800
&&
(
second
&
0xFC00
)
==
0xDC00
;
else
return
false
;
}
}
// Creates a Unicode code point from UTF16 surrogate pair.
// Creates a Unicode code point from UTF16 surrogate pair.
inline
UInt32
CreateCodePointFromUtf16SurrogatePair
(
wchar_t
first
,
inline
UInt32
CreateCodePointFromUtf16SurrogatePair
(
wchar_t
first
,
wchar_t
second
)
{
wchar_t
second
)
{
if
(
sizeof
(
wchar_t
)
==
2
)
{
const
UInt32
mask
=
(
1
<<
10
)
-
1
;
const
UInt32
mask
=
(
1
<<
10
)
-
1
;
return
(
sizeof
(
wchar_t
)
==
2
)
?
return
(((
first
&
mask
)
<<
10
)
|
(
second
&
mask
))
+
0x10000
;
(((
first
&
mask
)
<<
10
)
|
(
second
&
mask
))
+
0x10000
:
}
else
{
// This function should not be called when the condition is
// This should not be called, but we provide a sensible default
// false, but we provide a sensible default in case it is.
// in case it is.
static_cast
<
UInt32
>
(
first
);
return
static_cast
<
UInt32
>
(
first
);
}
}
}
// Converts a wide string to a narrow string in UTF-8 encoding.
// Converts a wide string to a narrow string in UTF-8 encoding.
...
...
test/gtest-filepath_test.cc
View file @
4b83461e
...
@@ -311,7 +311,7 @@ TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
...
@@ -311,7 +311,7 @@ TEST(RemoveTrailingPathSeparatorTest, ShouldReturnUnmodified) {
TEST
(
DirectoryTest
,
RootDirectoryExists
)
{
TEST
(
DirectoryTest
,
RootDirectoryExists
)
{
#ifdef GTEST_OS_WINDOWS // We are on Windows.
#ifdef GTEST_OS_WINDOWS // We are on Windows.
char
current_drive
[
_MAX_PATH
];
// NOLINT
char
current_drive
[
_MAX_PATH
];
// NOLINT
current_drive
[
0
]
=
_getdrive
()
+
'A'
-
1
;
current_drive
[
0
]
=
static_cast
<
char
>
(
_getdrive
()
+
'A'
-
1
)
;
current_drive
[
1
]
=
':'
;
current_drive
[
1
]
=
':'
;
current_drive
[
2
]
=
'\\'
;
current_drive
[
2
]
=
'\\'
;
current_drive
[
3
]
=
'\0'
;
current_drive
[
3
]
=
'\0'
;
...
...
test/gtest_unittest.cc
View file @
4b83461e
...
@@ -1090,7 +1090,7 @@ TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
...
@@ -1090,7 +1090,7 @@ TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
// property is not recorded.
// property is not recorded.
void
ExpectNonFatalFailureRecordingPropertyWithReservedKey
(
const
char
*
key
)
{
void
ExpectNonFatalFailureRecordingPropertyWithReservedKey
(
const
char
*
key
)
{
TestResult
test_result
;
TestResult
test_result
;
TestProperty
property
(
"name"
,
"1"
);
TestProperty
property
(
key
,
"1"
);
EXPECT_NONFATAL_FAILURE
(
test_result
.
RecordProperty
(
property
),
"Reserved key"
);
EXPECT_NONFATAL_FAILURE
(
test_result
.
RecordProperty
(
property
),
"Reserved key"
);
ASSERT_TRUE
(
test_result
.
test_properties
().
IsEmpty
())
<<
"Not recorded"
;
ASSERT_TRUE
(
test_result
.
test_properties
().
IsEmpty
())
<<
"Not recorded"
;
}
}
...
@@ -1594,31 +1594,31 @@ TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
...
@@ -1594,31 +1594,31 @@ TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
// Some helper functions for testing using overloaded/template
// Some helper functions for testing using overloaded/template
// functions with ASSERT_PRED_FORMATn and EXPECT_PRED_FORMATn.
// functions with ASSERT_PRED_FORMATn and EXPECT_PRED_FORMATn.
AssertionResult
IsPositiveFormat
(
const
char
*
expr
,
int
n
)
{
AssertionResult
IsPositiveFormat
(
const
char
*
/*
expr
*/
,
int
n
)
{
return
n
>
0
?
AssertionSuccess
()
:
return
n
>
0
?
AssertionSuccess
()
:
AssertionFailure
(
Message
()
<<
"Failure"
);
AssertionFailure
(
Message
()
<<
"Failure"
);
}
}
AssertionResult
IsPositiveFormat
(
const
char
*
expr
,
double
x
)
{
AssertionResult
IsPositiveFormat
(
const
char
*
/*
expr
*/
,
double
x
)
{
return
x
>
0
?
AssertionSuccess
()
:
return
x
>
0
?
AssertionSuccess
()
:
AssertionFailure
(
Message
()
<<
"Failure"
);
AssertionFailure
(
Message
()
<<
"Failure"
);
}
}
template
<
typename
T
>
template
<
typename
T
>
AssertionResult
IsNegativeFormat
(
const
char
*
expr
,
T
x
)
{
AssertionResult
IsNegativeFormat
(
const
char
*
/*
expr
*/
,
T
x
)
{
return
x
<
0
?
AssertionSuccess
()
:
return
x
<
0
?
AssertionSuccess
()
:
AssertionFailure
(
Message
()
<<
"Failure"
);
AssertionFailure
(
Message
()
<<
"Failure"
);
}
}
template
<
typename
T1
,
typename
T2
>
template
<
typename
T1
,
typename
T2
>
AssertionResult
EqualsFormat
(
const
char
*
expr1
,
const
char
*
expr2
,
AssertionResult
EqualsFormat
(
const
char
*
/*
expr1
*/
,
const
char
*
/*
expr2
*/
,
const
T1
&
x1
,
const
T2
&
x2
)
{
const
T1
&
x1
,
const
T2
&
x2
)
{
return
x1
==
x2
?
AssertionSuccess
()
:
return
x1
==
x2
?
AssertionSuccess
()
:
AssertionFailure
(
Message
()
<<
"Failure"
);
AssertionFailure
(
Message
()
<<
"Failure"
);
}
}
// Tests that overloaded functions can be used in *_PRED_FORMAT*
// Tests that overloaded functions can be used in *_PRED_FORMAT*
// without explictly specifying their types.
// without explic
i
tly specifying their types.
TEST
(
PredicateFormatAssertionTest
,
AcceptsOverloadedFunction
)
{
TEST
(
PredicateFormatAssertionTest
,
AcceptsOverloadedFunction
)
{
EXPECT_PRED_FORMAT1
(
IsPositiveFormat
,
5
);
EXPECT_PRED_FORMAT1
(
IsPositiveFormat
,
5
);
ASSERT_PRED_FORMAT1
(
IsPositiveFormat
,
6.0
);
ASSERT_PRED_FORMAT1
(
IsPositiveFormat
,
6.0
);
...
...
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