Fixes some warnings when compiled with MSVC at warning level 4.

pull/496/merge
zhanyong.wan 16 years ago
parent c946ae6019
commit 4b83461e97
  1. 16
      include/gtest/gtest.h
  2. 5
      include/gtest/internal/gtest-internal.h
  3. 4
      src/gtest-internal-inl.h
  4. 22
      src/gtest.cc
  5. 2
      test/gtest-filepath_test.cc
  6. 12
      test/gtest_unittest.cc

@ -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

@ -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" \

@ -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

@ -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.

@ -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';

@ -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);

Loading…
Cancel
Save