Index: test/gtest_unittest.cc |
=================================================================== |
--- test/gtest_unittest.cc (revision 610) |
+++ test/gtest_unittest.cc (working copy) |
@@ -151,7 +151,9 @@ |
using testing::internal::AppendUserMessage; |
using testing::internal::ArrayAwareFind; |
using testing::internal::ArrayEq; |
+#if GTEST_HAS_WCHAR |
using testing::internal::CodePointToUtf8; |
+#endif // GTEST_HAS_WCHAR |
using testing::internal::CompileAssertTypesEqual; |
using testing::internal::CopyArray; |
using testing::internal::CountIf; |
@@ -191,7 +193,9 @@ |
using testing::internal::TestEventListenersAccessor; |
using testing::internal::TestResultAccessor; |
using testing::internal::UInt32; |
+#if GTEST_HAS_WCHAR |
using testing::internal::WideStringToUtf8; |
+#endif // GTEST_HAS_WCHAR |
using testing::internal::kCopy; |
using testing::internal::kMaxRandomSeed; |
using testing::internal::kReference; |
@@ -355,6 +359,7 @@ |
} |
static void SetTimeZone(const char* time_zone) { |
+#if GTEST_HAS_SETENV |
// tzset() distinguishes between the TZ variable being present and empty |
// and not being present, so we have to consider the case of time_zone |
// being NULL. |
@@ -377,6 +382,8 @@ |
} |
tzset(); |
#endif |
+ |
+#endif // GTEST_HAS_SETENV |
} |
const char* saved_tz_; |
@@ -452,6 +459,7 @@ |
// |
// Tests CodePointToUtf8(). |
+#if GTEST_HAS_WCHAR |
// Tests that the NUL character L'\0' is encoded correctly. |
TEST(CodePointToUtf8Test, CanEncodeNul) { |
char buffer[32]; |
@@ -619,6 +627,7 @@ |
} |
#endif // !GTEST_WIDE_STRING_USES_UTF16_ |
+ |
// Tests that codepoint concatenation works correctly. |
#if !GTEST_WIDE_STRING_USES_UTF16_ |
TEST(WideStringToUtf8Test, ConcatenatesCodepointsCorrectly) { |
@@ -640,7 +649,9 @@ |
WideStringToUtf8(s, -1).c_str()); |
} |
#endif // !GTEST_WIDE_STRING_USES_UTF16_ |
+#endif // GTEST_HAS_WCHAR |
+ |
// Tests the Random class. |
TEST(RandomDeathTest, GeneratesCrashesOnInvalidRange) { |
@@ -1196,6 +1207,8 @@ |
EXPECT_FALSE(String("").EndsWithCaseInsensitive("foo")); |
} |
+ |
+#if GTEST_HAS_WCHAR |
// C++Builder's preprocessor is buggy; it fails to expand macros that |
// appear in macro parameters after wide char literals. Provide an alias |
// for NULL as a workaround. |
@@ -1212,6 +1225,7 @@ |
EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"foobar", L"FOOBAR")); |
EXPECT_TRUE(String::CaseInsensitiveWideCStringEquals(L"FOOBAR", L"foobar")); |
} |
+#endif // GTEST_HAS_WCHAR |
// Tests that NULL can be assigned to a String. |
TEST(StringTest, CanBeAssignedNULL) { |
@@ -1281,9 +1295,13 @@ |
buffer[kSize - 1] = '\0'; |
EXPECT_STREQ(buffer, String::Format("%s", buffer).c_str()); |
+#if !GTEST_OS_ECOS |
+ // ecos's implementation of vsnprintf is not C99 compliant |
+ |
// The result needs to be 4096 characters, exceeding Format()'s limit. |
EXPECT_STREQ("<formatting error or buffer exceeded>", |
String::Format("x%s", buffer).c_str()); |
+#endif |
#if GTEST_OS_LINUX |
// On Linux, invalid format spec should lead to an error message. |
@@ -1928,7 +1946,7 @@ |
// value. If the value argument is "", unsets the environment |
// variable. The caller must ensure that both arguments are not NULL. |
static void SetEnv(const char* name, const char* value) { |
-#if GTEST_OS_WINDOWS_MOBILE |
+#if GTEST_OS_WINDOWS_MOBILE || !GTEST_HAS_SETENV |
// Environment variables are not supported on Windows CE. |
return; |
#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) |
@@ -1961,7 +1979,7 @@ |
#endif // GTEST_OS_WINDOWS_MOBILE |
} |
-#if !GTEST_OS_WINDOWS_MOBILE |
+#if !GTEST_OS_WINDOWS_MOBILE && GTEST_HAS_SETENV |
// Environment variables are not supported on Windows CE. |
using testing::internal::Int32FromGTestEnv; |
@@ -2009,7 +2027,7 @@ |
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "TEMP", "-321"); |
EXPECT_EQ(-321, Int32FromGTestEnv("temp", 0)); |
} |
-#endif // !GTEST_OS_WINDOWS_MOBILE |
+#endif // !GTEST_OS_WINDOWS_MOBILE && GTEST_HAS_SETENV |
// Tests ParseInt32Flag(). |
@@ -2067,7 +2085,7 @@ |
// Tests that Int32FromEnvOrDie() parses the value of the var or |
// returns the correct default. |
// Environment variables are not supported on Windows CE. |
-#if !GTEST_OS_WINDOWS_MOBILE |
+#if !GTEST_OS_WINDOWS_MOBILE && GTEST_HAS_SETENV |
TEST(Int32FromEnvOrDieTest, ParsesAndReturnsValidValue) { |
EXPECT_EQ(333, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); |
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "123"); |
@@ -2075,7 +2093,7 @@ |
SetEnv(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", "-123"); |
EXPECT_EQ(-123, Int32FromEnvOrDie(GTEST_FLAG_PREFIX_UPPER_ "UnsetVar", 333)); |
} |
-#endif // !GTEST_OS_WINDOWS_MOBILE |
+#endif // !GTEST_OS_WINDOWS_MOBILE && GTEST_HAS_SETENV |
// Tests that Int32FromEnvOrDie() aborts with an error message |
// if the variable is not an Int32. |
@@ -2142,7 +2160,7 @@ |
// Tests that sharding is enabled if total_shards > 1 and |
// we are not in a death test subprocess. |
// Environment variables are not supported on Windows CE. |
-#if !GTEST_OS_WINDOWS_MOBILE |
+#if !GTEST_OS_WINDOWS_MOBILE && GTEST_HAS_SETENV |
TEST_F(ShouldShardTest, WorksWhenShardEnvVarsAreValid) { |
SetEnv(index_var_, "4"); |
SetEnv(total_var_, "22"); |
@@ -2159,7 +2177,7 @@ |
EXPECT_TRUE(ShouldShard(total_var_, index_var_, false)); |
EXPECT_FALSE(ShouldShard(total_var_, index_var_, true)); |
} |
-#endif // !GTEST_OS_WINDOWS_MOBILE |
+#endif // !GTEST_OS_WINDOWS_MOBILE && GTEST_HAS_SETENV |
// Tests that we exit in error if the sharding values are not valid. |
@@ -2620,6 +2638,7 @@ |
"(ignoring case)"); |
} |
+#if GTEST_HAS_WCHAR |
// Tests *_STREQ on wide strings. |
TEST(StringAssertionTest, STREQ_Wide) { |
// NULL strings. |
@@ -2669,6 +2688,7 @@ |
EXPECT_NONFATAL_FAILURE(EXPECT_STRNE(L"abc\x8119", L"abc\x8119"), |
"abc"); |
} |
+#endif // GTEST_HAS_WCHAR |
// Tests for ::testing::IsSubstring(). |
@@ -2683,6 +2703,7 @@ |
EXPECT_TRUE(IsSubstring("", "", "needle", "two needles")); |
} |
+#if GTEST_HAS_WCHAR |
// Tests that IsSubstring() returns the correct result when the input |
// argument type is const wchar_t*. |
TEST(IsSubstringTest, ReturnsCorrectResultForWideCString) { |
@@ -2693,6 +2714,7 @@ |
EXPECT_TRUE(IsSubstring("", "", static_cast<const wchar_t*>(NULL), NULL)); |
EXPECT_TRUE(IsSubstring("", "", L"needle", L"two needles")); |
} |
+#endif // GTEST_HAS_WCHAR |
// Tests that IsSubstring() generates the correct message when the input |
// argument type is const char*. |
@@ -2743,6 +2765,7 @@ |
EXPECT_FALSE(IsNotSubstring("", "", "needle", "two needles")); |
} |
+#if GTEST_HAS_WCHAR |
// Tests that IsNotSubstring() returns the correct result when the input |
// argument type is const wchar_t*. |
TEST(IsNotSubstringTest, ReturnsCorrectResultForWideCString) { |
@@ -2761,6 +2784,7 @@ |
"needle_expr", "haystack_expr", |
L"needle", L"two needles").failure_message()); |
} |
+#endif // GTEST_HAS_WCHAR |
// Tests that IsNotSubstring returns the correct result when the input |
// argument type is ::std::string. |
@@ -4648,6 +4672,7 @@ |
"ch"); |
} |
+#if GTEST_HAS_WCHAR |
// Tests using wchar_t values in {EXPECT|ASSERT}_EQ. |
TEST(EqAssertionTest, WideChar) { |
EXPECT_EQ(L'b', L'b'); |
@@ -4666,6 +4691,7 @@ |
EXPECT_FATAL_FAILURE(ASSERT_EQ(static_cast<wchar_t>(0x8120), wchar), |
"Value of: wchar"); |
} |
+#endif // GTEST_HAS_WCHAR |
// Tests using ::std::string values in {EXPECT|ASSERT}_EQ. |
TEST(EqAssertionTest, StdString) { |
@@ -4822,6 +4848,7 @@ |
"ABC0"); |
} |
+#if GTEST_HAS_WCHAR |
// Tests using wchar_t pointers in {EXPECT|ASSERT}_EQ. |
TEST(EqAssertionTest, WideCharPointer) { |
wchar_t* const p0 = NULL; |
@@ -4846,6 +4873,7 @@ |
EXPECT_NONFATAL_FAILURE(EXPECT_EQ(p3, p4), |
"p4"); |
} |
+#endif // GTEST_HAS_WCHAR |
// Tests using other types of pointers in {EXPECT|ASSERT}_EQ. |
TEST(EqAssertionTest, OtherPointer) { |
@@ -5174,6 +5202,7 @@ |
msg.GetString().c_str()); |
} |
+#if GTEST_HAS_WCHAR |
// Tests streaming wide strings to testing::Message. |
TEST(MessageTest, WideStrings) { |
// Streams a NULL of type const wchar_t*. |
@@ -5196,8 +5225,8 @@ |
EXPECT_STREQ("abc\xe8\x84\x99", |
(Message() << wstr).GetString().c_str()); |
} |
+#endif // GTEST_HAS_WCHAR |
- |
// This line tests that we can define tests in the testing namespace. |
namespace testing { |
@@ -6234,6 +6263,7 @@ |
#if GTEST_OS_WINDOWS |
// Tests parsing wide strings. |
+#if GTEST_HAS_WCHAR |
TEST_F(InitGoogleTestTest, WideStrings) { |
const wchar_t* argv[] = { |
L"foo.exe", |
@@ -6257,6 +6287,8 @@ |
GTEST_TEST_PARSING_FLAGS_(argv, argv2, expected_flags, false); |
} |
+#endif // GTEST_HAS_WCHAR |
+ |
#endif // GTEST_OS_WINDOWS |
// Tests current_test_info() in UnitTest. |
@@ -6542,6 +6574,7 @@ |
EXPECT_FALSE(ShouldUseColor(true)); // Stdout is a TTY. |
} |
+#if !GTEST_OS_ECOS |
TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) { |
GTEST_FLAG(color) = "auto"; |
@@ -6599,7 +6632,10 @@ |
EXPECT_TRUE(ShouldUseColor(true)); // Stdout is a TTY. |
#endif // GTEST_OS_WINDOWS |
} |
+#endif // !GTEST_OS_ECOS |
+ |
+ |
// Verifies that StaticAssertTypeEq works in a namespace scope. |
static bool dummy1 GTEST_ATTRIBUTE_UNUSED_ = StaticAssertTypeEq<bool, bool>(); |