From 707d1f3a8c31d386179ad63ec8d563a87683e0f8 Mon Sep 17 00:00:00 2001
From: Armin Rigo <arigo@tunes.org>
Date: Thu, 22 Oct 2015 08:05:56 -0700
Subject: Fix tests on 32bit ARM

wchar_t can be signed or not, apparently, even on the same platform (arm
linux)

Bug-Upstream: https://bitbucket.org/cffi/cffi/issues/227/130-test-failures-on-32-bit-arm
Origin: upstream, https://bitbucket.org/cffi/cffi/commits/ebcda8268d47
Patch-Name: wchar_signed_test
---
 testing/cffi0/backend_tests.py  | 7 ++++---
 testing/cffi1/test_new_ffi_1.py | 7 ++++---
 2 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/testing/cffi0/backend_tests.py b/testing/cffi0/backend_tests.py
index f887bf0..66bf462 100644
--- a/testing/cffi0/backend_tests.py
+++ b/testing/cffi0/backend_tests.py
@@ -756,10 +756,11 @@ class BackendTests:
         p = ffi.cast("long long", ffi.cast("wchar_t", -1))
         if SIZE_OF_WCHAR == 2:      # 2 bytes, unsigned
             assert int(p) == 0xffff
-        elif platform.machine().startswith(('arm', 'aarch64')):
-            assert int(p) == 0xffffffff      # 4 bytes, unsigned
-        else:                       # 4 bytes, signed
+        elif (sys.platform.startswith('linux') and
+              platform.machine().startswith('x86')):   # known to be signed
             assert int(p) == -1
+        else:                     # in general, it can be either signed or not
+            assert int(p) in [-1, 0xffffffff]  # e.g. on arm, both cases occur
         p = ffi.cast("int", u+'\u1234')
         assert int(p) == 0x1234
 
diff --git a/testing/cffi1/test_new_ffi_1.py b/testing/cffi1/test_new_ffi_1.py
index 4e4f515..b1f1b33 100644
--- a/testing/cffi1/test_new_ffi_1.py
+++ b/testing/cffi1/test_new_ffi_1.py
@@ -781,10 +781,11 @@ class TestNewFFI1:
         p = ffi.cast("long long", ffi.cast("wchar_t", -1))
         if SIZE_OF_WCHAR == 2:      # 2 bytes, unsigned
             assert int(p) == 0xffff
-        elif platform.machine().startswith(('arm', 'aarch64')):
-            assert int(p) == 0xffffffff      # 4 bytes, unsigned
-        else:                       # 4 bytes, signed
+        elif (sys.platform.startswith('linux') and
+              platform.machine().startswith('x86')):   # known to be signed
             assert int(p) == -1
+        else:                     # in general, it can be either signed or not
+            assert int(p) in [-1, 0xffffffff]  # e.g. on arm, both cases occur
         p = ffi.cast("int", u+'\u1234')
         assert int(p) == 0x1234
 
