summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-01-29 06:49:00 +0000
committerzhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925>2009-01-29 06:49:00 +0000
commitb0a12f719caf4e37894868334ce41b1864b0be53 (patch)
tree81c398e25c7db78187ecb3c6a756b9996140943b
parentd40d06d49055d6286a0a9fead61c0f86d94bc557 (diff)
downloadgoogletest-b0a12f719caf4e37894868334ce41b1864b0be53.tar.gz
Fixes some warnings when compiled with MSVC at warning level 4.
git-svn-id: http://googletest.googlecode.com/svn/trunk@183 861a406c-534a-0410-8894-cb66d6ee9925
-rw-r--r--include/gtest/gtest.h16
-rw-r--r--include/gtest/internal/gtest-internal.h5
-rw-r--r--src/gtest-internal-inl.h4
-rw-r--r--src/gtest.cc22
-rw-r--r--test/gtest-filepath_test.cc2
-rw-r--r--test/gtest_unittest.cc12
6 files changed, 37 insertions, 24 deletions
diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h
index dfa338b..f1184de 100644
--- a/include/gtest/gtest.h
+++ b/include/gtest/gtest.h
@@ -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
diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h
index 37faaae..541c89b 100644
--- a/include/gtest/internal/gtest-internal.h
+++ b/include/gtest/internal/gtest-internal.h
@@ -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" \
diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h
index caa0877..ef3fe98 100644
--- a/src/gtest-internal-inl.h
+++ b/src/gtest-internal-inl.h
@@ -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
diff --git a/src/gtest.cc b/src/gtest.cc
index 903dcd9..2607767 100644
--- a/src/gtest.cc
+++ b/src/gtest.cc
@@ -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);
- }
+ const UInt32 mask = (1 << 10) - 1;
+ 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.
diff --git a/test/gtest-filepath_test.cc b/test/gtest-filepath_test.cc
index 589442f..ee80f0d 100644
--- a/test/gtest-filepath_test.cc
+++ b/test/gtest-filepath_test.cc
@@ -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';
diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc
index 135493f..cf9163b 100644
--- a/test/gtest_unittest.cc
+++ b/test/gtest_unittest.cc
@@ -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 explicitly specifying their types.
TEST(PredicateFormatAssertionTest, AcceptsOverloadedFunction) {
EXPECT_PRED_FORMAT1(IsPositiveFormat, 5);
ASSERT_PRED_FORMAT1(IsPositiveFormat, 6.0);