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
Show 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,
const
char
*
actual_expression
,
const
T1
&
expected
,
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
)
{
return
AssertionSuccess
();
}
#ifdef _MSC_VER
#pragma warning(pop) // Restores the warning state.
#endif
return
EqFailure
(
expected_expression
,
actual_expression
,
FormatForComparisonFailureMessage
(
expected
,
actual
),
...
...
@@ -688,7 +698,7 @@ class EqHelper<true> {
template
<
typename
T1
,
typename
T2
>
static
AssertionResult
Compare
(
const
char
*
expected_expression
,
const
char
*
actual_expression
,
const
T1
&
expected
,
const
T1
&
/*
expected
*/
,
T2
*
actual
)
{
// We already know that 'expected' is a null pointer.
return
CmpHelperEQ
(
expected_expression
,
actual_expression
,
...
...
@@ -1315,7 +1325,7 @@ bool StaticAssertTypeEq() {
// value, as it always calls GetTypeId<>() from the Google Test
// framework.
#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())
...
...
@@ -1346,7 +1356,7 @@ bool StaticAssertTypeEq() {
// }
#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>())
// 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);
// Returns the number of failed test parts in the given test result object.
int
GetFailedPartCount
(
const
TestResult
*
result
);
// A helper for suppressing warnings on unreachable code in some macros.
inline
bool
True
()
{
return
true
;
}
}
// namespace internal
}
// namespace testing
...
...
@@ -835,7 +838,7 @@ int GetFailedPartCount(const TestResult* result);
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (const char* gtest_msg = "") { \
::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \
{ statement; } \
if (::testing::internal::True())
{ statement; } \
if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \
gtest_msg = "Expected: " #statement " doesn't generate new fatal " \
"failures in the current thread.\n" \
...
...
src/gtest-internal-inl.h
View file @
4b83461e
...
...
@@ -901,6 +901,8 @@ class DefaultGlobalTestPartResultReporter
private:
UnitTestImpl
*
const
unit_test_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
DefaultGlobalTestPartResultReporter
);
};
// This is the default per thread test part result reporter used in
...
...
@@ -915,6 +917,8 @@ class DefaultPerThreadTestPartResultReporter
private:
UnitTestImpl
*
const
unit_test_
;
GTEST_DISALLOW_COPY_AND_ASSIGN_
(
DefaultPerThreadTestPartResultReporter
);
};
// 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,
bool
UnitTestOptions
::
MatchesFilter
(
const
String
&
name
,
const
char
*
filter
)
{
const
char
*
cur_pattern
=
filter
;
while
(
true
)
{
for
(;;
)
{
if
(
PatternMatchesString
(
cur_pattern
,
name
.
c_str
()))
{
return
true
;
}
...
...
@@ -1458,23 +1458,19 @@ char* CodePointToUtf8(UInt32 code_point, char* str) {
// and thus should be combined into a single Unicode code point
// using CreateCodePointFromUtf16SurrogatePair.
inline
bool
IsUtf16SurrogatePair
(
wchar_t
first
,
wchar_t
second
)
{
if
(
sizeof
(
wchar_t
)
==
2
)
return
(
first
&
0xFC00
)
==
0xD800
&&
(
second
&
0xFC00
)
==
0xDC00
;
else
return
false
;
return
sizeof
(
wchar_t
)
==
2
&&
(
first
&
0xFC00
)
==
0xD800
&&
(
second
&
0xFC00
)
==
0xDC00
;
}
// Creates a Unicode code point from UTF16 surrogate pair.
inline
UInt32
CreateCodePointFromUtf16SurrogatePair
(
wchar_t
first
,
wchar_t
second
)
{
if
(
sizeof
(
wchar_t
)
==
2
)
{
const
UInt32
mask
=
(
1
<<
10
)
-
1
;
return
(((
first
&
mask
)
<<
10
)
|
(
second
&
mask
))
+
0x10000
;
}
else
{
// This should not be called, but we provide a sensible default
// in case it is.
return
static_cast
<
UInt32
>
(
first
);
}
return
(
sizeof
(
wchar_t
)
==
2
)
?
(((
first
&
mask
)
<<
10
)
|
(
second
&
mask
))
+
0x10000
:
// This function should not be called when the condition is
// false, but we provide a sensible default in case it is.
static_cast
<
UInt32
>
(
first
);
}
// 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) {
TEST
(
DirectoryTest
,
RootDirectoryExists
)
{
#ifdef GTEST_OS_WINDOWS // We are on Windows.
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
[
2
]
=
'\\'
;
current_drive
[
3
]
=
'\0'
;
...
...
test/gtest_unittest.cc
View file @
4b83461e
...
...
@@ -1090,7 +1090,7 @@ TEST(TestResultPropertyTest, OverridesValuesForDuplicateKeys) {
// property is not recorded.
void
ExpectNonFatalFailureRecordingPropertyWithReservedKey
(
const
char
*
key
)
{
TestResult
test_result
;
TestProperty
property
(
"name"
,
"1"
);
TestProperty
property
(
key
,
"1"
);
EXPECT_NONFATAL_FAILURE
(
test_result
.
RecordProperty
(
property
),
"Reserved key"
);
ASSERT_TRUE
(
test_result
.
test_properties
().
IsEmpty
())
<<
"Not recorded"
;
}
...
...
@@ -1594,31 +1594,31 @@ TEST(PredicateAssertionTest, AcceptsTemplateFunction) {
// Some helper functions for testing using overloaded/template
// 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
()
:
AssertionFailure
(
Message
()
<<
"Failure"
);
}
AssertionResult
IsPositiveFormat
(
const
char
*
expr
,
double
x
)
{
AssertionResult
IsPositiveFormat
(
const
char
*
/*
expr
*/
,
double
x
)
{
return
x
>
0
?
AssertionSuccess
()
:
AssertionFailure
(
Message
()
<<
"Failure"
);
}
template
<
typename
T
>
AssertionResult
IsNegativeFormat
(
const
char
*
expr
,
T
x
)
{
AssertionResult
IsNegativeFormat
(
const
char
*
/*
expr
*/
,
T
x
)
{
return
x
<
0
?
AssertionSuccess
()
:
AssertionFailure
(
Message
()
<<
"Failure"
);
}
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
)
{
return
x1
==
x2
?
AssertionSuccess
()
:
AssertionFailure
(
Message
()
<<
"Failure"
);
}
// 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
)
{
EXPECT_PRED_FORMAT1
(
IsPositiveFormat
,
5
);
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