diff options
author | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-07-22 21:07:19 (GMT) |
---|---|---|
committer | vladlosev <vladlosev@861a406c-534a-0410-8894-cb66d6ee9925> | 2010-07-22 21:07:19 (GMT) |
commit | e96d247b20116646f343b6e2ec37af154f655977 (patch) | |
tree | 6182008e59b5ef52fa7b5967a64e6d7649c855ef | |
parent | e2a7f03b80fc0e9e6a6f36acb43776509486a6d4 (diff) | |
download | googletest-e96d247b20116646f343b6e2ec37af154f655977.zip googletest-e96d247b20116646f343b6e2ec37af154f655977.tar.gz googletest-e96d247b20116646f343b6e2ec37af154f655977.tar.bz2 |
Allows Google Test to build on OSes other then a pre-determined set and implements GTEST_HAS_POSIX_REGEX condition for compatibility with them.
-rw-r--r-- | include/gtest/internal/gtest-port.h | 49 | ||||
-rw-r--r-- | src/gtest-port.cc | 1 | ||||
-rw-r--r-- | test/gtest-port_test.cc | 11 |
3 files changed, 44 insertions, 17 deletions
diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index aa3d0af..733dae5 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -50,6 +50,8 @@ // GTEST_HAS_GLOBAL_WSTRING - Define it to 1/0 to indicate that ::string // is/isn't available (some systems define // ::wstring, which is different to std::wstring). +// GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular +// expressions are/aren't available. // GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that <pthread.h> // is/isn't available. // GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't @@ -107,7 +109,9 @@ // GTEST_HAS_PARAM_TEST - value-parameterized tests // GTEST_HAS_TYPED_TEST - typed tests // GTEST_HAS_TYPED_TEST_P - type-parameterized tests -// GTEST_USES_POSIX_RE - enhanced POSIX regex is used. +// GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with +// GTEST_HAS_POSIX_RE (see above) which users can +// define themselves. // GTEST_USES_SIMPLE_RE - our own simple regex is used; // the above two are mutually exclusive. // GTEST_CAN_COMPARE_NULL - accepts untyped NULL in EXPECT_EQ(). @@ -174,6 +178,7 @@ #include <stdio.h> #include <string.h> #ifndef _WIN32_WCE +#include <sys/types.h> #include <sys/stat.h> #endif // !_WIN32_WCE @@ -221,28 +226,37 @@ #define GTEST_OS_AIX 1 #endif // __CYGWIN__ -#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_SYMBIAN || \ - GTEST_OS_SOLARIS || GTEST_OS_AIX +// Brings in definitions for functions used in the testing::internal::posix +// namespace (read, write, close, chdir, isatty, stat). We do not currently +// use them on Windows Mobile. +#if !GTEST_OS_WINDOWS +// This assumes that non-Windows OSes provide unistd.h. For OSes where this +// is not the case, we need to include headers that provide the functions +// mentioned above. +#include <unistd.h> +#include <strings.h> +#elif !GTEST_OS_WINDOWS_MOBILE +#include <direct.h> +#include <io.h> +#endif + +// Defines this to true iff Google Test can use POSIX regular expressions. +#ifndef GTEST_HAS_POSIX_RE +#define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS) +#endif + +#if GTEST_HAS_POSIX_RE // On some platforms, <regex.h> needs someone to define size_t, and // won't compile otherwise. We can #include it here as we already // included <stdlib.h>, which is guaranteed to define size_t through // <stddef.h>. #include <regex.h> // NOLINT -#include <strings.h> // NOLINT -#include <sys/types.h> // NOLINT -#include <time.h> // NOLINT -#include <unistd.h> // NOLINT #define GTEST_USES_POSIX_RE 1 #elif GTEST_OS_WINDOWS -#if !GTEST_OS_WINDOWS_MOBILE -#include <direct.h> // NOLINT -#include <io.h> // NOLINT -#endif - // <regex.h> is not available on Windows. Use our own simple regex // implementation instead. #define GTEST_USES_SIMPLE_RE 1 @@ -253,8 +267,7 @@ // simple regex implementation instead. #define GTEST_USES_SIMPLE_RE 1 -#endif // GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC || - // GTEST_OS_SYMBIAN || GTEST_OS_SOLARIS || GTEST_OS_AIX +#endif // GTEST_HAS_POSIX_RE #ifndef GTEST_HAS_EXCEPTIONS // The user didn't tell us whether exceptions are enabled, so we need @@ -308,8 +321,7 @@ // TODO(wan@google.com): uses autoconf to detect whether ::std::wstring // is available. -// Cygwin 1.5 and below doesn't support ::std::wstring. -// Cygwin 1.7 might add wstring support; this should be updated when clear. +// Cygwin 1.7 and below doesn't support ::std::wstring. // Solaris' libc++ doesn't support it either. #define GTEST_HAS_STD_WSTRING (!(GTEST_OS_CYGWIN || GTEST_OS_SOLARIS)) @@ -382,7 +394,10 @@ #if GTEST_HAS_PTHREAD // gtest-port.h guarantees to #include <pthread.h> when GTEST_HAS_PTHREAD is // true. -#include <pthread.h> +#include <pthread.h> // NOLINT + +// For timespec and nanosleep, used below. +#include <time.h> // NOLINT #endif // Determines whether Google Test can use tr1/tuple. You can define diff --git a/src/gtest-port.cc b/src/gtest-port.cc index b9504f5..5eec8fa 100644 --- a/src/gtest-port.cc +++ b/src/gtest-port.cc @@ -34,6 +34,7 @@ #include <limits.h> #include <stdlib.h> #include <stdio.h> +#include <string.h> #if GTEST_OS_WINDOWS_MOBILE #include <windows.h> // For TerminateProcess() diff --git a/test/gtest-port_test.cc b/test/gtest-port_test.cc index 6f1512c..6cdbfab 100644 --- a/test/gtest-port_test.cc +++ b/test/gtest-port_test.cc @@ -284,6 +284,17 @@ TEST(GtestCheckDeathTest, LivesSilentlyOnSuccess) { #endif // GTEST_HAS_DEATH_TEST +// Verifies that Google Test choose regular expression engine appropriate to +// the platform. The test will produce compiler errors in case of failure. +// For simplicity, we only cover the most important platforms here. +TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) { +#if GTEST_HAS_POSIX_RE + EXPECT_TRUE(GTEST_USES_POSIX_RE); +#else + EXPECT_TRUE(GTEST_USES_SIMPLE_RE); +#endif +} + #if GTEST_USES_POSIX_RE #if GTEST_HAS_TYPED_TEST |