Improves Android support (by David Turner).
This commit is contained in:
parent
b535c1767e
commit
78bf6d5724
|
@ -242,9 +242,9 @@
|
||||||
# endif
|
# endif
|
||||||
#elif defined __linux__
|
#elif defined __linux__
|
||||||
# define GTEST_OS_LINUX 1
|
# define GTEST_OS_LINUX 1
|
||||||
# ifdef ANDROID
|
# if defined __ANDROID__
|
||||||
# define GTEST_OS_LINUX_ANDROID 1
|
# define GTEST_OS_LINUX_ANDROID 1
|
||||||
# endif // ANDROID
|
# endif
|
||||||
#elif defined __MVS__
|
#elif defined __MVS__
|
||||||
# define GTEST_OS_ZOS 1
|
# define GTEST_OS_ZOS 1
|
||||||
#elif defined(__sun) && defined(__SVR4)
|
#elif defined(__sun) && defined(__SVR4)
|
||||||
|
@ -288,9 +288,19 @@
|
||||||
# include <io.h>
|
# include <io.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if GTEST_OS_LINUX_ANDROID
|
||||||
|
// Used to define __ANDROID_API__ matching the target NDK API level.
|
||||||
|
# include <android/api-level.h> // NOLINT
|
||||||
|
#endif
|
||||||
|
|
||||||
// Defines this to true iff Google Test can use POSIX regular expressions.
|
// Defines this to true iff Google Test can use POSIX regular expressions.
|
||||||
#ifndef GTEST_HAS_POSIX_RE
|
#ifndef GTEST_HAS_POSIX_RE
|
||||||
# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
|
# if GTEST_OS_LINUX_ANDROID
|
||||||
|
// On Android, <regex.h> is only available starting with Gingerbread.
|
||||||
|
# define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9)
|
||||||
|
# else
|
||||||
|
# define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS)
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if GTEST_HAS_POSIX_RE
|
#if GTEST_HAS_POSIX_RE
|
||||||
|
@ -405,7 +415,16 @@
|
||||||
# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
|
# elif defined(__GNUC__) && (GTEST_GCC_VER_ >= 40302)
|
||||||
|
|
||||||
# ifdef __GXX_RTTI
|
# ifdef __GXX_RTTI
|
||||||
# define GTEST_HAS_RTTI 1
|
// When building against STLport with the Android NDK and with
|
||||||
|
// -frtti -fno-exceptions, the build fails at link time with undefined
|
||||||
|
// references to __cxa_bad_typeid. Note sure if STL or toolchain bug,
|
||||||
|
// so disable RTTI when detected.
|
||||||
|
# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \
|
||||||
|
!defined(__EXCEPTIONS)
|
||||||
|
# define GTEST_HAS_RTTI 0
|
||||||
|
# else
|
||||||
|
# define GTEST_HAS_RTTI 1
|
||||||
|
# endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS
|
||||||
# else
|
# else
|
||||||
# define GTEST_HAS_RTTI 0
|
# define GTEST_HAS_RTTI 0
|
||||||
# endif // __GXX_RTTI
|
# endif // __GXX_RTTI
|
||||||
|
@ -466,8 +485,13 @@
|
||||||
// this macro to 0 to prevent Google Test from using tuple (any
|
// this macro to 0 to prevent Google Test from using tuple (any
|
||||||
// feature depending on tuple with be disabled in this mode).
|
// feature depending on tuple with be disabled in this mode).
|
||||||
#ifndef GTEST_HAS_TR1_TUPLE
|
#ifndef GTEST_HAS_TR1_TUPLE
|
||||||
|
# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR)
|
||||||
|
// STLport, provided with the Android NDK, has neither <tr1/tuple> or <tuple>.
|
||||||
|
# define GTEST_HAS_TR1_TUPLE 0
|
||||||
|
# else
|
||||||
// The user didn't tell us not to do it, so we assume it's OK.
|
// The user didn't tell us not to do it, so we assume it's OK.
|
||||||
# define GTEST_HAS_TR1_TUPLE 1
|
# define GTEST_HAS_TR1_TUPLE 1
|
||||||
|
# endif
|
||||||
#endif // GTEST_HAS_TR1_TUPLE
|
#endif // GTEST_HAS_TR1_TUPLE
|
||||||
|
|
||||||
// Determines whether Google Test's own tr1 tuple implementation
|
// Determines whether Google Test's own tr1 tuple implementation
|
||||||
|
@ -578,7 +602,16 @@ using ::std::tuple_size;
|
||||||
// The user didn't tell us, so we need to figure it out.
|
// The user didn't tell us, so we need to figure it out.
|
||||||
|
|
||||||
# if GTEST_OS_LINUX && !defined(__ia64__)
|
# if GTEST_OS_LINUX && !defined(__ia64__)
|
||||||
# define GTEST_HAS_CLONE 1
|
# if GTEST_OS_LINUX_ANDROID
|
||||||
|
// On Android, clone() is only available on ARM starting with Gingerbread.
|
||||||
|
# if defined(__arm__) && __ANDROID_API__ >= 9
|
||||||
|
# define GTEST_HAS_CLONE 1
|
||||||
|
# else
|
||||||
|
# define GTEST_HAS_CLONE 0
|
||||||
|
# endif
|
||||||
|
# else
|
||||||
|
# define GTEST_HAS_CLONE 1
|
||||||
|
# endif
|
||||||
# else
|
# else
|
||||||
# define GTEST_HAS_CLONE 0
|
# define GTEST_HAS_CLONE 0
|
||||||
# endif // GTEST_OS_LINUX && !defined(__ia64__)
|
# endif // GTEST_OS_LINUX && !defined(__ia64__)
|
||||||
|
|
|
@ -531,11 +531,25 @@ class CapturedStream {
|
||||||
filename_ = temp_file_path;
|
filename_ = temp_file_path;
|
||||||
# else
|
# else
|
||||||
// There's no guarantee that a test has write access to the current
|
// There's no guarantee that a test has write access to the current
|
||||||
// directory, so we create the temporary file in the /tmp directory instead.
|
// directory, so we create the temporary file in the /tmp directory
|
||||||
// We use /tmp on most systems, and /mnt/sdcard on Android. That's because
|
// instead. We use /tmp on most systems, and /sdcard on Android.
|
||||||
// Android doesn't have /tmp.
|
// That's because Android doesn't have /tmp.
|
||||||
# if GTEST_OS_LINUX_ANDROID
|
# if GTEST_OS_LINUX_ANDROID
|
||||||
char name_template[] = "/mnt/sdcard/gtest_captured_stream.XXXXXX";
|
// Note: Android applications are expected to call the framework's
|
||||||
|
// Context.getExternalStorageDirectory() method through JNI to get
|
||||||
|
// the location of the world-writable SD Card directory. However,
|
||||||
|
// this requires a Context handle, which cannot be retrieved
|
||||||
|
// globally from native code. Doing so also precludes running the
|
||||||
|
// code as part of a regular standalone executable, which doesn't
|
||||||
|
// run in a Dalvik process (e.g. when running it through 'adb shell').
|
||||||
|
//
|
||||||
|
// The location /sdcard is directly accessible from native code
|
||||||
|
// and is the only location (unofficially) supported by the Android
|
||||||
|
// team. It's generally a symlink to the real SD Card mount point
|
||||||
|
// which can be /mnt/sdcard, /mnt/sdcard0, /system/media/sdcard, or
|
||||||
|
// other OEM-customized locations. Never rely on these, and always
|
||||||
|
// use /sdcard.
|
||||||
|
char name_template[] = "/sdcard/gtest_captured_stream.XXXXXX";
|
||||||
# else
|
# else
|
||||||
char name_template[] = "/tmp/captured_stream.XXXXXX";
|
char name_template[] = "/tmp/captured_stream.XXXXXX";
|
||||||
# endif // GTEST_OS_LINUX_ANDROID
|
# endif // GTEST_OS_LINUX_ANDROID
|
||||||
|
|
|
@ -543,6 +543,8 @@ class DirectoryCreationTest : public Test {
|
||||||
return String(temp_dir);
|
return String(temp_dir);
|
||||||
else
|
else
|
||||||
return String::Format("%s\\", temp_dir);
|
return String::Format("%s\\", temp_dir);
|
||||||
|
#elif GTEST_OS_LINUX_ANDROID
|
||||||
|
return String("/sdcard/");
|
||||||
#else
|
#else
|
||||||
return String("/tmp/");
|
return String("/tmp/");
|
||||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||||
|
|
|
@ -1275,7 +1275,7 @@ TEST(StringTest, FormatWorks) {
|
||||||
EXPECT_STREQ("<formatting error or buffer exceeded>",
|
EXPECT_STREQ("<formatting error or buffer exceeded>",
|
||||||
String::Format("x%s", buffer).c_str());
|
String::Format("x%s", buffer).c_str());
|
||||||
|
|
||||||
#if GTEST_OS_LINUX
|
#if GTEST_OS_LINUX && !GTEST_OS_LINUX_ANDROID
|
||||||
// On Linux, invalid format spec should lead to an error message.
|
// On Linux, invalid format spec should lead to an error message.
|
||||||
// In other environment (e.g. MSVC on Windows), String::Format() may
|
// In other environment (e.g. MSVC on Windows), String::Format() may
|
||||||
// simply ignore a bad format spec, so this assertion is run on
|
// simply ignore a bad format spec, so this assertion is run on
|
||||||
|
|
Loading…
Reference in New Issue
Block a user