diff options
author | David 'Digit' Turner <digit@android.com> | 2013-07-20 00:49:37 +0200 |
---|---|---|
committer | David 'Digit' Turner <digit@android.com> | 2013-07-20 00:49:37 +0200 |
commit | 1fce92f9024e84c77777ba2a050c90af17790d80 (patch) | |
tree | 9d6288d5e3e043455eef3519c74e0672b505884a | |
parent | 81c782a08a9cc11e7395e0aaf493bea7314b2210 (diff) | |
download | ndk-1fce92f9024e84c77777ba2a050c90af17790d80.tar.gz |
Update the wchar-related tests.
This updates all wchar_t related definitions to match the fix
currently uploaded at:
https://android-review.googlesource.com/#/c/62320/
+ Fix a typo in <minitest/minitest.h>
See http://b.android.com/57749
Change-Id: Iaa30eb026c27bac1d3cb4e1870f787f9ca22414e
-rw-r--r-- | sources/android/support/include/wchar.h | 19 | ||||
-rw-r--r-- | sources/android/support/tests/minitest/minitest.h | 4 | ||||
-rw-r--r-- | sources/android/support/tests/wchar_unittest.cc | 9 | ||||
-rw-r--r-- | tests/build/wchar_t-size/jni/Android.mk | 3 | ||||
-rw-r--r-- | tests/build/wchar_t-size/jni/Application.mk | 3 | ||||
-rw-r--r-- | tests/build/wchar_t-size/jni/test_8bit.c | 9 | ||||
-rw-r--r-- | tests/build/wchar_t-size/jni/test_8bit_cplusplus.cpp | 16 | ||||
-rw-r--r-- | tests/build/wchar_t-size/jni/test_8bit_cplusplus_stdc_limit_macros.cpp | 9 | ||||
-rw-r--r-- | tests/build/wchar_t-size/jni/test_always_signed.c | 16 | ||||
-rw-r--r-- | tests/build/wchar_t-size/jni/test_default.c | 10 | ||||
-rw-r--r-- | tests/standalone/builtin-macros/run.sh | 35 |
11 files changed, 116 insertions, 17 deletions
diff --git a/sources/android/support/include/wchar.h b/sources/android/support/include/wchar.h index 26a8be7df..e3d84f5ff 100644 --- a/sources/android/support/include/wchar.h +++ b/sources/android/support/include/wchar.h @@ -78,7 +78,7 @@ typedef int wint_t; typedef int wctype_t; typedef struct locale_struct* locale_t; -// This is tricky: <stdio.h> indirectly includes <stdint.h>, which will +// See http://b.android.com/This is tricky: <stdio.h> indirectly includes <stdint.h>, which will // already have defined WCHAR_MIN / WCHAR_MAX in the following cases: // - When compiling C sources // - When compiling C++ sources AND having __STDC_LIMIT_MACROS defined. @@ -89,8 +89,21 @@ typedef struct locale_struct* locale_t; // The constants here ensure that they match the INT32_MIN / INT32_MAX // definitions. #ifndef WCHAR_MAX -#define WCHAR_MAX (0x7fffffff) -#define WCHAR_MIN (0x80000000) +# ifndef __WCHAR_MAX__ +# error "__WCHAR_MAX__ undefined. Check your toolchain." +# endif +// Clang doesn't define __WCHAR_MIN__, only __WCHAR_MAX__ +# ifndef __WCHAR_MIN__ +# if __WCHAR_MAX__ == 0xffffffff +# define __WCHAR_MIN__ 0U +# elif __WCHAR_MAX__ == 0x7fffffff +# define __WCHAR_MIN__ 0x80000000 +# else +# error "Invalid __WCHAR_MAX__ value. Check your toolchain." +# endif +# endif // !__WCHAR_MIN +#define WCHAR_MAX __WCHAR_MAX__ +#define WCHAR_MIN __WCHAR_MIN__ #endif #define WEOF ((wint_t)(-1)) diff --git a/sources/android/support/tests/minitest/minitest.h b/sources/android/support/tests/minitest/minitest.h index 6a1ca21bd..e3753052e 100644 --- a/sources/android/support/tests/minitest/minitest.h +++ b/sources/android/support/tests/minitest/minitest.h @@ -370,7 +370,7 @@ void RegisterTest(const char* test_name, if (!(expression)) { \ printf("ASSERT_TRUE:%s:%d: expression '%s' return 'false', expected 'true'\n", \ __FILE__, __LINE__, #expression); \ - minitest_testcaseFatalFailure(); \ + minitest_testcase->FatalFailure(); \ return; \ } \ } while (0) @@ -380,7 +380,7 @@ void RegisterTest(const char* test_name, if (!!(expression)) { \ printf("ASSERT_FALSE:%s:%d: expression '%s' return 'true', expected 'false'\n", \ __FILE__, __LINE__, #expression); \ - minitest_testcaseFatalFailure(); \ + minitest_testcase->FatalFailure(); \ return; \ } \ } while (0) diff --git a/sources/android/support/tests/wchar_unittest.cc b/sources/android/support/tests/wchar_unittest.cc index 4bd6a6967..95c027c81 100644 --- a/sources/android/support/tests/wchar_unittest.cc +++ b/sources/android/support/tests/wchar_unittest.cc @@ -6,6 +6,15 @@ TEST(wchar, wchar_limits) { ASSERT_EQ(4U, sizeof(wchar_t)); ASSERT_EQ(sizeof(int), sizeof(wint_t)); +#ifdef __arm__ + ASSERT_GT(wchar_t(0), wchar_t(-1)); + ASSERT_EQ(wchar_t(0), WCHAR_MIN); + ASSERT_EQ(wchar_t(0xffffffff), WCHAR_MAX); +#else + ASSERT_LT(wchar_t(0), wchar_t(-1)); + ASSERT_EQ(wchar_t(0x80000000), WCHAR_MIN); + ASSERT_EQ(wchar_t(0x7fffffff), WCHAR_MAX); +#endif } TEST(wchar, wcschr) { diff --git a/tests/build/wchar_t-size/jni/Android.mk b/tests/build/wchar_t-size/jni/Android.mk index 2aaf0b8df..cc8ed4135 100644 --- a/tests/build/wchar_t-size/jni/Android.mk +++ b/tests/build/wchar_t-size/jni/Android.mk @@ -6,6 +6,7 @@ LOCAL_SRC_FILES := \ test_default.c \ test_8bit.c \ test_8bit_cplusplus.cpp \ - test_8bit_cplusplus_stdc_limit_macros.cpp + test_8bit_cplusplus_stdc_limit_macros.cpp \ + test_always_signed.c \ include $(BUILD_SHARED_LIBRARY) diff --git a/tests/build/wchar_t-size/jni/Application.mk b/tests/build/wchar_t-size/jni/Application.mk index b7b94e952..f51c74048 100644 --- a/tests/build/wchar_t-size/jni/Application.mk +++ b/tests/build/wchar_t-size/jni/Application.mk @@ -1,3 +1,2 @@ -# The issue only exists for ARM. -APP_ABI := armeabi armeabi-v7a +APP_ABI := all APP_PLATFORM := android-3 diff --git a/tests/build/wchar_t-size/jni/test_8bit.c b/tests/build/wchar_t-size/jni/test_8bit.c index 980d2f14c..7089e1da3 100644 --- a/tests/build/wchar_t-size/jni/test_8bit.c +++ b/tests/build/wchar_t-size/jni/test_8bit.c @@ -7,7 +7,7 @@ #define _WCHAR_IS_8BIT #include <wchar.h> -#if __ANDROID_API__ != 3 +#if defined(__arm__) && __ANDROID_API__ != 3 #error "You should target API level 3 when compiling this file!" #endif @@ -17,10 +17,15 @@ #define STATIC_ASSERT(condition) \ static char CONCAT(dummy_,__LINE__)[1 - 2*(!(condition))]; +#ifdef __arm__ STATIC_ASSERT(sizeof(__WCHAR_TYPE__) == 1); STATIC_ASSERT(sizeof(wchar_t) == 1); +#else +STATIC_ASSERT(sizeof(__WCHAR_TYPE__) == 4); +STATIC_ASSERT(sizeof(wchar_t) == 4); +#endif // Since this is C code, the old behaviour was to always define -// these constants as 32 bit values. +// these constants as signed 32 bit values. STATIC_ASSERT(WCHAR_MIN == 0x80000000); STATIC_ASSERT(WCHAR_MAX == 0x7fffffff); diff --git a/tests/build/wchar_t-size/jni/test_8bit_cplusplus.cpp b/tests/build/wchar_t-size/jni/test_8bit_cplusplus.cpp index 29e847f0e..3396aabf7 100644 --- a/tests/build/wchar_t-size/jni/test_8bit_cplusplus.cpp +++ b/tests/build/wchar_t-size/jni/test_8bit_cplusplus.cpp @@ -7,7 +7,7 @@ #define _WCHAR_IS_8BIT #include <wchar.h> -#if __ANDROID_API__ != 3 +#if defined(__arm__) && __ANDROID_API__ != 3 #error "You should target API level 3 when compiling this file!" #endif @@ -17,13 +17,23 @@ #define STATIC_ASSERT(condition) \ static char CONCAT(dummy_,__LINE__)[1 - 2*(!(condition))]; +#ifdef __arm__ STATIC_ASSERT(sizeof(__WCHAR_TYPE__) == 1); +#else +STATIC_ASSERT(sizeof(__WCHAR_TYPE__) == 4); +#endif // wchar_t is never redefined by <stddef.h> because it's a C++ keyword, // unlike in C. STATIC_ASSERT(sizeof(wchar_t) == 4); -// Since this is C++ code, the old behaviour was to define -// these constants to 8-bit values. +// Since this is C++ code, and __STC_LIMIT_MACROS was not defined, the +// old behaviour on ARM was to define these constants to 8-bit values. +// Otherwise, always signed 32-bit values. +#ifdef __arm__ STATIC_ASSERT(WCHAR_MIN == 0); STATIC_ASSERT(WCHAR_MAX == 255); +#else +STATIC_ASSERT(WCHAR_MIN == 0x80000000); +STATIC_ASSERT(WCHAR_MAX == 0x7fffffff); +#endif diff --git a/tests/build/wchar_t-size/jni/test_8bit_cplusplus_stdc_limit_macros.cpp b/tests/build/wchar_t-size/jni/test_8bit_cplusplus_stdc_limit_macros.cpp index d159299fe..06c1c334a 100644 --- a/tests/build/wchar_t-size/jni/test_8bit_cplusplus_stdc_limit_macros.cpp +++ b/tests/build/wchar_t-size/jni/test_8bit_cplusplus_stdc_limit_macros.cpp @@ -9,7 +9,7 @@ #define _WCHAR_IS_8BIT #include <wchar.h> -#if __ANDROID_API__ != 3 +#if defined(__arm__) && __ANDROID_API__ != 3 #error "You should target API level 3 when compiling this file!" #endif @@ -19,12 +19,17 @@ #define STATIC_ASSERT(condition) \ static char CONCAT(dummy_,__LINE__)[1 - 2*(!(condition))]; +#ifdef __arm__ STATIC_ASSERT(sizeof(__WCHAR_TYPE__) == 1); +#else +STATIC_ASSERT(sizeof(__WCHAR_TYPE__) == 4); +#endif // wchar_t is never redefined by <stddef.h> because it's a C++ keyword, // unlike in C. STATIC_ASSERT(sizeof(wchar_t) == 4); -// This is C++ code but __STDC_LIMIT_MACROS was defined. +// This is C++ code but __STDC_LIMIT_MACROS was defined, and +// _WCHAR_IS_8BIT is defined, so the values are always 32-bit signed. STATIC_ASSERT(WCHAR_MIN == 0x80000000); STATIC_ASSERT(WCHAR_MAX == 0x7fffffff); diff --git a/tests/build/wchar_t-size/jni/test_always_signed.c b/tests/build/wchar_t-size/jni/test_always_signed.c new file mode 100644 index 000000000..9e6a1c957 --- /dev/null +++ b/tests/build/wchar_t-size/jni/test_always_signed.c @@ -0,0 +1,16 @@ +// This checks that, by default, wchar_t is 32-bit and +// WCHAR_MIN/WCHAR_MAX are 32-bit signed on all platforms when +// _WCHAR_IS_ALWAYS_SIGNED is defined. +#define _WCHAR_IS_ALWAYS_SIGNED 1 +#include <wchar.h> + +#define CONCAT(x,y) CONCAT_(x,y) +#define CONCAT_(x,y) x ## y + +#define STATIC_ASSERT(condition) \ + static char CONCAT(dummy_,__LINE__)[1 - 2*(!(condition))]; + +STATIC_ASSERT(sizeof(wchar_t) == 4); + +STATIC_ASSERT(WCHAR_MIN == -1-2147483647); +STATIC_ASSERT(WCHAR_MAX == 2147483647); diff --git a/tests/build/wchar_t-size/jni/test_default.c b/tests/build/wchar_t-size/jni/test_default.c index 08d809000..55ed5e759 100644 --- a/tests/build/wchar_t-size/jni/test_default.c +++ b/tests/build/wchar_t-size/jni/test_default.c @@ -1,9 +1,9 @@ // This checks that, by default, wchar_t is 32-bit and -// WCHAR_MIN/WCHAR_MAX are 32-bit signed. +// WCHAR_MIN/WCHAR_MAX are 32-bit signed on all platforms except ARM. #include <android/api-level.h> #include <wchar.h> -#if __ANDROID_API__ != 3 +#if defined(__arm__) && __ANDROID_API__ != 3 #error "You should target API level 3 when compiling this file!" #endif @@ -14,5 +14,11 @@ static char CONCAT(dummy_,__LINE__)[1 - 2*(!(condition))]; STATIC_ASSERT(sizeof(wchar_t) == 4); + +#ifdef __arm__ +STATIC_ASSERT(WCHAR_MIN == 0U); +STATIC_ASSERT(WCHAR_MAX == 2*2147483647U + 1U); +#else STATIC_ASSERT(WCHAR_MIN == -1-2147483647); STATIC_ASSERT(WCHAR_MAX == 2147483647); +#endif diff --git a/tests/standalone/builtin-macros/run.sh b/tests/standalone/builtin-macros/run.sh index 27a11a746..b40a418a4 100644 --- a/tests/standalone/builtin-macros/run.sh +++ b/tests/standalone/builtin-macros/run.sh @@ -72,6 +72,31 @@ macro_check () { COUNT=$(( $COUNT + 1 )) } +# Check the definition of a given macro against multiple values +# $1: macro name +# $2+: list of acceptable values. +macro_multi_check () { + echo -n "Checking $1: " + local VAL=$(macro_val $1) + if [ -z "$VAL" ]; then + echo "Missing built-in macro definition: $1" + return 1 + fi + local VAL2 FOUND + shift + for VAL2 in "$@"; do + if [ "$VAL2" = "$VAL" ]; then + FOUND=true + break + fi + done + if [ -z "$FOUND" ]; then + echo "Invalid built-in macro definition: '$VAL', expected one of: $@" + return 1 + fi + return 0 +} + # Check that a given macro is undefined macro_check_undef () { if [ -n "$2" ]; then @@ -114,6 +139,9 @@ case $ABI in macro_check __ARMEL__ 1 "ARM little-endian" macro_check __THUMB_INTERWORK__ 1 "ARM thumb-interwork" macro_check __PIC__ 1 "Position independent code (-fpic)" + macro_check __WCHAR_TYPE__ "unsigned" + macro_check __WCHAR_MAX__ "4294967295U" + # Clang doesn't define __WCHAR_MIN__ so don't check it" case $ABI in armeabi) @@ -148,6 +176,10 @@ case $ABI in macro_check __SSE3__ 1 "SSE3 instruction set" macro_check __SSE_MATH__ 1 "Use SSE for math operations" macro_check __SSE2_MATH__ 1 "Use SSE2 for math operations" + # GCC defines is as 'long', and Clang as 'int' + macro_multi_check __WCHAR_TYPE__ "long" "int" + # GCC defines it with an L suffix, Clang doesn't. + macro_multi_check __WCHAR_MAX__ "2147483647L" "2147483647" ;; mips) @@ -155,6 +187,9 @@ case $ABI in macro_check _MIPS_ARCH_MIPS32 1 "Mips 32-bit ABI" macro_check __MIPSEL__ 1 "Mips little-endian" macro_check __PIC__ 1 "Position independent code (-fpic)" + # GCC defines it as "signed int", and Clang as "int" + macro_multi_check __WCHAR_TYPE__ "signed int" "int" + macro_check __WCHAR_MAX__ "2147483647" ;; *) echo "Unknown ABI: $ABI" |