diff options
author | Christopher Wiley <wiley@google.com> | 2016-07-19 19:26:55 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2016-07-19 19:26:55 +0000 |
commit | 4da2e74cb51eeea6f858e2ed85163f2fa640b57a (patch) | |
tree | 3152c73e9f53a188269ba6e109b76ea71e4d870e | |
parent | 405971b9dbd382d07b5ce09a06b20bd8a6727d9a (diff) | |
parent | a10f8ad722f16e7577e14d3e54d41facb2f4132a (diff) | |
download | aidl-4da2e74cb51eeea6f858e2ed85163f2fa640b57a.tar.gz |
Test that @nullable Interface passing works as expected am: 513fec62fb
am: a10f8ad722
Change-Id: I9fe1ba6c7dcc7b4eb1ce4af307329f19aca13bb5
-rw-r--r-- | tests/aidl_test_client_nullables.cpp | 31 | ||||
-rw-r--r-- | tests/aidl_test_service.cpp | 7 | ||||
-rw-r--r-- | tests/android/aidl/tests/ITestService.aidl | 2 | ||||
-rw-r--r-- | tests/java_app/src/android/aidl/tests/NullableTests.java | 19 |
4 files changed, 59 insertions, 0 deletions
diff --git a/tests/aidl_test_client_nullables.cpp b/tests/aidl_test_client_nullables.cpp index d2cfb0cc..e876af48 100644 --- a/tests/aidl_test_client_nullables.cpp +++ b/tests/aidl_test_client_nullables.cpp @@ -193,6 +193,32 @@ bool CheckAppropriateIBinderHandling(const sp<ITestService>& s) { return true; } +bool CheckAppropriateIInterfaceHandling(const sp<ITestService>& s) { + + sp<INamedCallback> callback; + if (!s->GetCallback(false, &callback).isOk()) { + cerr << "Received unexpected exception on line " + << __LINE__ << endl; + return false; + } + if (callback.get() == nullptr) { + cerr << "Expected to receive a non-null binder on line: " + << __LINE__ << endl; + return false; + } + if (!s->GetCallback(true, &callback).isOk()) { + cerr << "Received unexpected exception on line " + << __LINE__ << endl; + return false; + } + if (callback.get() != nullptr) { + cerr << "Expected to receive a null binder on line: " + << __LINE__ << endl; + return false; + } + return true; +} + } // namespace bool ConfirmNullables(const sp<ITestService>& s) { @@ -240,6 +266,11 @@ bool ConfirmNullables(const sp<ITestService>& s) { return false; } + if (!CheckAppropriateIInterfaceHandling(s)) { + cerr << "Handled nullable IInterface instances poorly." << endl; + return false; + } + return true; } diff --git a/tests/aidl_test_service.cpp b/tests/aidl_test_service.cpp index 5253ad76..9e2304ed 100644 --- a/tests/aidl_test_service.cpp +++ b/tests/aidl_test_service.cpp @@ -412,6 +412,13 @@ class NativeService : public BnTestService { return Status::ok(); } + Status GetCallback(bool return_null, sp<INamedCallback>* ret) { + if (!return_null) { + return GetOtherTestService(String16("ABT: always be testing"), ret); + } + return Status::ok(); + } + private: map<String16, sp<INamedCallback>> service_map_; }; diff --git a/tests/android/aidl/tests/ITestService.aidl b/tests/android/aidl/tests/ITestService.aidl index b8a3ab73..c9efecbc 100644 --- a/tests/android/aidl/tests/ITestService.aidl +++ b/tests/android/aidl/tests/ITestService.aidl @@ -102,4 +102,6 @@ interface ITestService { @nullable @utf8InCpp List<String> ReverseUtf8CppStringList( in @nullable @utf8InCpp List<String> input, out @nullable @utf8InCpp List<String> repeated); + + @nullable INamedCallback GetCallback(boolean return_null); } diff --git a/tests/java_app/src/android/aidl/tests/NullableTests.java b/tests/java_app/src/android/aidl/tests/NullableTests.java index 412731c5..83a9877c 100644 --- a/tests/java_app/src/android/aidl/tests/NullableTests.java +++ b/tests/java_app/src/android/aidl/tests/NullableTests.java @@ -81,9 +81,28 @@ class NullableTests { "null parameter, but nothing was thrown??"); } + public void checkNullInterfaceHandling() throws TestFailException { + mLog.log("Checking @nullable IInterface handling..."); + try { + INamedCallback callback = mService.GetCallback(false); + if (callback == null) { + mLog.logAndThrow("Expected to get non-null INamedCallback."); + } + callback = mService.GetCallback(true); + if (callback != null) { + mLog.logAndThrow("Expected to get null INamedCallback."); + } + } catch (Exception ex) { + mLog.logAndThrow("Unexpected exception during @nullable IInterface test: " + + ex.toString()); + } + mLog.log("@nullable IInterface handling works as expected."); + } + public void runTests() throws TestFailException { checkNullHandling(); checkNullBinderDetection(); checkNullBinderInListDetection(); + checkNullInterfaceHandling(); } } |