diff options
author | Samuel Tan <samueltan@google.com> | 2015-12-17 00:55:01 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2015-12-17 00:55:01 +0000 |
commit | 199b04609883d0f19c950b48d5c97f1e1d042797 (patch) | |
tree | c8673969b942ff6a64a2c4beb258a1914e98591c | |
parent | afce0c72b471fed0126c49d8c5942b6ceca0623a (diff) | |
parent | 88c320053c5c0f9c45a5700c89b23a9c0c745369 (diff) | |
download | android_system_tools_aidl-199b04609883d0f19c950b48d5c97f1e1d042797.tar.gz android_system_tools_aidl-199b04609883d0f19c950b48d5c97f1e1d042797.tar.bz2 android_system_tools_aidl-199b04609883d0f19c950b48d5c97f1e1d042797.zip |
aidl: tests: add PersistableBundle integration tests
am: 88c320053c
* commit '88c320053c5c0f9c45a5700c89b23a9c0c745369':
aidl: tests: add PersistableBundle integration tests
-rw-r--r-- | Android.mk | 4 | ||||
-rw-r--r-- | tests/aidl_test_client.cpp | 4 | ||||
-rw-r--r-- | tests/aidl_test_client_parcelables.cpp | 86 | ||||
-rw-r--r-- | tests/aidl_test_client_parcelables.h | 3 | ||||
-rw-r--r-- | tests/aidl_test_service.cpp | 41 | ||||
-rw-r--r-- | tests/android/aidl/tests/ITestService.aidl | 12 | ||||
-rw-r--r-- | tests/java_app/src/android/aidl/tests/TestServiceClient.java | 147 |
7 files changed, 255 insertions, 42 deletions
@@ -137,7 +137,9 @@ LOCAL_MODULE := libaidl-integration-test LOCAL_MODULE_CLASS := SHARED_LIBRARIES LOCAL_CFLAGS := $(aidl_integration_test_cflags) LOCAL_SHARED_LIBRARIES := $(aidl_integration_test_shared_libs) libbase -LOCAL_AIDL_INCLUDES := system/tools/aidl/tests/ +LOCAL_AIDL_INCLUDES := \ + system/tools/aidl/tests/ \ + frameworks/base/core/java LOCAL_SRC_FILES := \ tests/android/aidl/tests/ITestService.aidl \ tests/android/aidl/tests/INamedCallback.aidl \ diff --git a/tests/aidl_test_client.cpp b/tests/aidl_test_client.cpp index 7ec1c6f..0663f2c 100644 --- a/tests/aidl_test_client.cpp +++ b/tests/aidl_test_client.cpp @@ -83,7 +83,9 @@ int main(int /* argc */, char * /* argv */ []) { if (!client_tests::ConfirmReverseBinderLists(service)) return 1; - if (!client_tests::ConfirmParcelables(service)) return 1; + if (!client_tests::ConfirmSimpleParcelables(service)) return 1; + + if (!client_tests::ConfirmPersistableBundles(service)) return 1; if (!client_tests::ConfirmFileDescriptors(service)) return 1; diff --git a/tests/aidl_test_client_parcelables.cpp b/tests/aidl_test_client_parcelables.cpp index 1258a4b..09e7f0a 100644 --- a/tests/aidl_test_client_parcelables.cpp +++ b/tests/aidl_test_client_parcelables.cpp @@ -28,6 +28,7 @@ using android::binder::Status; // generated using android::aidl::tests::ITestService; using android::aidl::tests::SimpleParcelable; +using android::os::PersistableBundle; using std::cout; using std::endl; @@ -38,35 +39,106 @@ namespace aidl { namespace tests { namespace client { -bool ConfirmParcelables(const sp<ITestService>& s) { - cout << "Confirming passing and returning Parcelables works." << endl; +bool ConfirmSimpleParcelables(const sp<ITestService>& s) { + cout << "Confirming passing and returning SimpleParcelable objects works." + << endl; SimpleParcelable input("Booya", 42); SimpleParcelable out_param, returned; - Status status = s->RepeatParcelable(input, &out_param, &returned); + Status status = s->RepeatSimpleParcelable(input, &out_param, &returned); if (!status.isOk()) { cout << "Binder call failed." << endl; return false; } if (input != out_param || input != returned) { - cout << "Failed to repeat parcelables." << endl; + cout << "Failed to repeat SimpleParcelable objects." << endl; return false; } - cout << "Attempting to reverse an array of parcelables." << endl; + cout << "Attempting to reverse an array of SimpleParcelable objects." << endl; const vector<SimpleParcelable> original{SimpleParcelable("first", 0), SimpleParcelable("second", 1), SimpleParcelable("third", 2)}; vector<SimpleParcelable> repeated; vector<SimpleParcelable> reversed; - status = s->ReverseParcelables(original, &repeated, &reversed); + status = s->ReverseSimpleParcelables(original, &repeated, &reversed); if (!status.isOk()) { cout << "Binder call failed." << endl; return false; } std::reverse(reversed.begin(), reversed.end()); if (repeated != original || reversed != original) { - cout << "Failed to reverse an array of parcelables." << endl; + cout << "Failed to reverse an array of SimpleParcelable objects." << endl; + return false; + } + + return true; +} + +bool ConfirmPersistableBundles(const sp<ITestService>& s) { + cout << "Confirming passing and returning PersistableBundle objects works." + << endl; + + PersistableBundle empty_bundle, returned; + Status status = s->RepeatPersistableBundle(empty_bundle, &returned); + if (!status.isOk()) { + cout << "Binder call failed for empty PersistableBundle." << endl; + return false; + } + if (empty_bundle != returned) { + cout << "Failed to repeat empty PersistableBundle." << endl; + return false; + } + + PersistableBundle non_empty_bundle; + non_empty_bundle.putBoolean(String16("test_bool"), false); + non_empty_bundle.putInt(String16("test_int"), 33); + non_empty_bundle.putLong(String16("test_long"), 34359738368l); + non_empty_bundle.putDouble(String16("test_double"), 1.1); + non_empty_bundle.putString(String16("test_string"), String16("Woot!")); + non_empty_bundle.putBooleanVector(String16("test_bool_vector"), + {true, false, true}); + non_empty_bundle.putIntVector(String16("test_int_vector"), {33, 44, 55, 142}); + non_empty_bundle.putLongVector(String16("test_long_vector"), + {34l, 8371l, 34359738375l}); + non_empty_bundle.putDoubleVector(String16("test_double_vector"), {2.2, 5.4}); + non_empty_bundle.putStringVector(String16("test_string_vector"), + {String16("hello"), String16("world!")}); + PersistableBundle nested_bundle; + nested_bundle.putInt(String16("test_nested_int"), 345); + non_empty_bundle.putPersistableBundle(String16("test_persistable_bundle"), + nested_bundle); + + status = s->RepeatPersistableBundle(non_empty_bundle, &returned); + if (!status.isOk()) { + cout << "Binder call failed. " << endl; + return false; + } + if (non_empty_bundle != returned) { + cout << "Failed to repeat PersistableBundle object." << endl; + return false; + } + + cout << "Attempting to reverse an array of PersistableBundle objects." + << endl; + PersistableBundle first; + PersistableBundle second; + PersistableBundle third; + first.putInt(String16("test_int"), 1231); + second.putLong(String16("test_long"), 222222l); + third.putDouble(String16("test_double"), 10.8); + const vector<PersistableBundle> original{first, second, third}; + + vector<PersistableBundle> repeated; + vector<PersistableBundle> reversed; + status = s->ReversePersistableBundles(original, &repeated, &reversed); + if (!status.isOk()) { + cout << "Binder call failed." << endl; + return false; + } + std::reverse(reversed.begin(), reversed.end()); + if (repeated != original || reversed != original) { + cout << "Failed to reverse an array of PersistableBundle objects." << endl; return false; } diff --git a/tests/aidl_test_client_parcelables.h b/tests/aidl_test_client_parcelables.h index 8bd8d68..9616e02 100644 --- a/tests/aidl_test_client_parcelables.h +++ b/tests/aidl_test_client_parcelables.h @@ -27,7 +27,8 @@ namespace aidl { namespace tests { namespace client { -bool ConfirmParcelables(const sp<ITestService>& s); +bool ConfirmSimpleParcelables(const sp<ITestService>& s); +bool ConfirmPersistableBundles(const sp<ITestService>& s); } // namespace client } // namespace tests diff --git a/tests/aidl_test_service.cpp b/tests/aidl_test_service.cpp index 66ab2a6..5f45ee8 100644 --- a/tests/aidl_test_service.cpp +++ b/tests/aidl_test_service.cpp @@ -59,10 +59,11 @@ using android::ProcessState; using android::binder::Status; // Generated code: -using android::aidl::tests::BnTestService; using android::aidl::tests::BnNamedCallback; +using android::aidl::tests::BnTestService; using android::aidl::tests::INamedCallback; using android::aidl::tests::SimpleParcelable; +using android::os::PersistableBundle; // Standard library using std::map; @@ -78,7 +79,7 @@ class BinderCallback : public LooperCallback { BinderCallback() {} ~BinderCallback() override {} - int handleEvent(int /* fd */, int /* events */, void* /* data */ ) override { + int handleEvent(int /* fd */, int /* events */, void* /* data */) override { IPCThreadState::self()->handlePolledCommands(); return 1; // Continue receiving callbacks. } @@ -134,7 +135,7 @@ class NativeService : public BnTestService { token.size()); } - template<typename T> + template <typename T> void LogRepeatedToken(const T& token) { std::ostringstream token_str; token_str << token; @@ -176,25 +177,30 @@ class NativeService : public BnTestService { *_aidl_return = token; return Status::ok(); } - Status RepeatString( - const String16& token, String16* _aidl_return) override { + Status RepeatString(const String16& token, String16* _aidl_return) override { LogRepeatedStringToken(token); *_aidl_return = token; return Status::ok(); } - Status RepeatParcelable(const SimpleParcelable& input, - SimpleParcelable* repeat, - SimpleParcelable* _aidl_return) override { + Status RepeatSimpleParcelable(const SimpleParcelable& input, + SimpleParcelable* repeat, + SimpleParcelable* _aidl_return) override { ALOGI("Repeated a SimpleParcelable %s", input.toString().c_str()); *repeat = input; *_aidl_return = input; return Status::ok(); } - template<typename T> - Status ReverseArray(const vector<T>& input, - vector<T>* repeated, + Status RepeatPersistableBundle(const PersistableBundle& input, + PersistableBundle* _aidl_return) override { + ALOGI("Repeated a PersistableBundle"); + *_aidl_return = input; + return Status::ok(); + } + + template <typename T> + Status ReverseArray(const vector<T>& input, vector<T>* repeated, vector<T>* _aidl_return) { ALOGI("Reversing array of length %zu", input.size()); *repeated = input; @@ -256,9 +262,16 @@ class NativeService : public BnTestService { vector<String16>* _aidl_return) override { return ReverseArray(input, repeated, _aidl_return); } - Status ReverseParcelables(const vector<SimpleParcelable>& input, - vector<SimpleParcelable>* repeated, - vector<SimpleParcelable>* _aidl_return) override { + Status ReverseSimpleParcelables( + const vector<SimpleParcelable>& input, + vector<SimpleParcelable>* repeated, + vector<SimpleParcelable>* _aidl_return) override { + return ReverseArray(input, repeated, _aidl_return); + } + Status ReversePersistableBundles( + const vector<PersistableBundle>& input, + vector<PersistableBundle>* repeated, + vector<PersistableBundle>* _aidl_return) override { return ReverseArray(input, repeated, _aidl_return); } diff --git a/tests/android/aidl/tests/ITestService.aidl b/tests/android/aidl/tests/ITestService.aidl index c6584e1..1c0310e 100644 --- a/tests/android/aidl/tests/ITestService.aidl +++ b/tests/android/aidl/tests/ITestService.aidl @@ -18,6 +18,7 @@ package android.aidl.tests; import android.aidl.tests.INamedCallback; import android.aidl.tests.SimpleParcelable; +import android.os.PersistableBundle; interface ITestService { // Test that constants are accessible @@ -33,8 +34,9 @@ interface ITestService { double RepeatDouble(double token); String RepeatString(String token); - SimpleParcelable RepeatParcelable(in SimpleParcelable input, - out SimpleParcelable repeat); + SimpleParcelable RepeatSimpleParcelable(in SimpleParcelable input, + out SimpleParcelable repeat); + PersistableBundle RepeatPersistableBundle(in PersistableBundle input); // Test that arrays work as parameters and return types. boolean[] ReverseBoolean(in boolean[] input, out boolean[] repeated); @@ -46,8 +48,10 @@ interface ITestService { double[] ReverseDouble (in double[] input, out double[] repeated); String[] ReverseString (in String[] input, out String[] repeated); - SimpleParcelable[] ReverseParcelables (in SimpleParcelable[] input, - out SimpleParcelable[] repeated); + SimpleParcelable[] ReverseSimpleParcelables(in SimpleParcelable[] input, + out SimpleParcelable[] repeated); + PersistableBundle[] ReversePersistableBundles( + in PersistableBundle[] input, out PersistableBundle[] repeated); // Test that clients can send and receive Binders. INamedCallback GetOtherTestService(String name); diff --git a/tests/java_app/src/android/aidl/tests/TestServiceClient.java b/tests/java_app/src/android/aidl/tests/TestServiceClient.java index c8afeb3..76e63a3 100644 --- a/tests/java_app/src/android/aidl/tests/TestServiceClient.java +++ b/tests/java_app/src/android/aidl/tests/TestServiceClient.java @@ -23,6 +23,7 @@ import android.content.Intent; import android.os.ServiceSpecificException; import android.os.Bundle; import android.os.IBinder; +import android.os.PersistableBundle; import android.os.RemoteException; import android.os.ServiceManager; import android.util.Log; @@ -38,8 +39,8 @@ import java.util.Collections; import java.util.List; // Generated -import android.aidl.tests.ITestService; import android.aidl.tests.INamedCallback; +import android.aidl.tests.ITestService; public class TestServiceClient extends Activity { private static final String TAG = "TestServiceClient"; @@ -423,22 +424,22 @@ public class TestServiceClient extends Activity { mLog.log("...service can reverse and return lists."); } - private void checkParcelables(ITestService service) + private void checkSimpleParcelables(ITestService service) throws TestFailException { - mLog.log("Checking that service can repeat and reverse parcelables..."); + mLog.log("Checking that service can repeat and reverse SimpleParcelable objects..."); try { { SimpleParcelable input = new SimpleParcelable("foo", 42); SimpleParcelable out_param = new SimpleParcelable(); SimpleParcelable returned = - service.RepeatParcelable(input, out_param); + service.RepeatSimpleParcelable(input, out_param); if (!input.equals(out_param)) { mLog.log(input.toString() + " != " + out_param.toString()); - mLog.logAndThrow("out param parcelable was not equivalent"); + mLog.logAndThrow("out param SimpleParcelable was not equivalent"); } if (!input.equals(returned)) { mLog.log(input.toString() + " != " + returned.toString()); - mLog.logAndThrow("returned parcelable was not equivalent"); + mLog.logAndThrow("returned SimpleParcelable was not equivalent"); } } { @@ -447,15 +448,15 @@ public class TestServiceClient extends Activity { input[1] = new SimpleParcelable("b", 2); input[2] = new SimpleParcelable("c", 3); SimpleParcelable[] repeated = new SimpleParcelable[3]; - SimpleParcelable[] reversed = service.ReverseParcelables( + SimpleParcelable[] reversed = service.ReverseSimpleParcelables( input, repeated); if (!Arrays.equals(input, repeated)) { mLog.logAndThrow( - "Repeated list of parcelables did not match."); + "Repeated list of SimpleParcelable objects did not match."); } if (input.length != reversed.length) { mLog.logAndThrow( - "Reversed list of parcelables had wrong length."); + "Reversed list of SimpleParcelable objects had wrong length."); } for (int i = 0, k = input.length - 1; i < input.length; @@ -463,16 +464,133 @@ public class TestServiceClient extends Activity { if (!input[i].equals(reversed[k])) { mLog.log(input[i].toString() + " != " + reversed[k].toString()); - mLog.logAndThrow("reversed parcelable was " + - "not equivalent"); + mLog.logAndThrow("reversed SimpleParcelable was not equivalent"); + } + } + } + } catch (Exception ex) { + mLog.log(ex.toString()); + mLog.logAndThrow("Service failed to handle SimpleParcelable objects."); + } + mLog.log("...service can manipulate SimpleParcelable objects."); + } + + private void checkPersistableBundles(ITestService service) + throws TestFailException { + mLog.log("Checking that service can repeat and reverse PersistableBundle objects..."); + try { + { + PersistableBundle emptyBundle = new PersistableBundle(); + PersistableBundle returned = service.RepeatPersistableBundle(emptyBundle); + if (emptyBundle.size() != 0 || returned.size() != 0) { + mLog.log(emptyBundle.toString() + " != " + returned.toString()); + mLog.logAndThrow("returned empty PersistableBundle object was not equivalent"); + } + mLog.log("...service can repeat and reverse empty PersistableBundle objects..."); + } + { + final String testBoolKey = new String("testBool"); + final String testIntKey = new String("testInt"); + final String testNestedIntKey = new String("testNestedInt"); + final String testLongKey = new String("testLong"); + final String testDoubleKey = new String("testDouble"); + final String testStringKey = new String("testString"); + final String testBoolArrayKey = new String("testBoolArray"); + final String testIntArrayKey = new String("testIntArray"); + final String testLongArrayKey = new String("testLongArray"); + final String testDoubleArrayKey = new String("testDoubleArray"); + final String testStringArrayKey = new String("testStringArray"); + final String testPersistableBundleKey = new String("testPersistableBundle"); + PersistableBundle nonEmptyBundle = new PersistableBundle(); + nonEmptyBundle.putBoolean(testBoolKey, false); + nonEmptyBundle.putInt(testIntKey, 33); + nonEmptyBundle.putLong(testLongKey, 34359738368L); + nonEmptyBundle.putDouble(testDoubleKey, 1.1); + nonEmptyBundle.putString(testStringKey, new String("Woot!")); + nonEmptyBundle.putBooleanArray(testBoolArrayKey, new boolean[] {true, false, true}); + nonEmptyBundle.putIntArray(testIntArrayKey, new int[] {33, 44, 55, 142}); + nonEmptyBundle.putLongArray( + testLongArrayKey, new long[] {34L, 8371L, 34359738375L}); + nonEmptyBundle.putDoubleArray(testDoubleArrayKey, new double[] {2.2, 5.4}); + nonEmptyBundle.putStringArray(testStringArrayKey, new String[] {"hello", "world!"}); + PersistableBundle testNestedPersistableBundle = new PersistableBundle(); + testNestedPersistableBundle.putInt(testNestedIntKey, 345); + nonEmptyBundle.putPersistableBundle( + testPersistableBundleKey, testNestedPersistableBundle); + PersistableBundle returned = service.RepeatPersistableBundle(nonEmptyBundle); + if (returned.size() != nonEmptyBundle.size() + || returned.getBoolean(testBoolKey) != nonEmptyBundle.getBoolean(testBoolKey) + || returned.getInt(testIntKey) != nonEmptyBundle.getInt(testIntKey) + || returned.getLong(testLongKey) != nonEmptyBundle.getLong(testLongKey) + || returned.getDouble(testDoubleKey) != nonEmptyBundle.getDouble(testDoubleKey) + || !returned.getString(testStringKey) + .equals(nonEmptyBundle.getString(testStringKey)) + || !Arrays.equals(nonEmptyBundle.getBooleanArray(testBoolArrayKey), + returned.getBooleanArray(testBoolArrayKey)) + || !Arrays.equals(nonEmptyBundle.getIntArray(testIntArrayKey), + returned.getIntArray(testIntArrayKey)) + || !Arrays.equals(nonEmptyBundle.getLongArray(testLongArrayKey), + returned.getLongArray(testLongArrayKey)) + || !Arrays.equals(nonEmptyBundle.getDoubleArray(testDoubleArrayKey), + returned.getDoubleArray(testDoubleArrayKey)) + || !Arrays.equals(nonEmptyBundle.getStringArray(testStringArrayKey), + returned.getStringArray(testStringArrayKey))) { + PersistableBundle temp = + returned.getPersistableBundle(testPersistableBundleKey); + if (temp == null + || temp.getInt(testNestedIntKey) + != testNestedPersistableBundle.getInt(testNestedIntKey)) { + mLog.log(nonEmptyBundle.toString() + " != " + returned.toString()); + mLog.logAndThrow("returned non-empty PersistableBundle " + + "object was not equivalent"); } } + mLog.log("...service can repeat and reverse non-empty " + + "PersistableBundle objects..."); + } + { + PersistableBundle[] input = new PersistableBundle[3]; + PersistableBundle first = new PersistableBundle(); + PersistableBundle second = new PersistableBundle(); + PersistableBundle third = new PersistableBundle(); + final String testIntKey = new String("testInt"); + final String testLongKey = new String("testLong"); + final String testDoubleKey = new String("testDouble"); + first.putInt(testIntKey, 1231); + second.putLong(testLongKey, 222222L); + third.putDouble(testDoubleKey, 10.8); + input[0] = first; + input[1] = second; + input[2] = third; + final int original_input_size = input.length; + PersistableBundle[] repeated = new PersistableBundle[input.length]; + PersistableBundle[] reversed = service.ReversePersistableBundles(input, repeated); + if (input.length != repeated.length || input.length != original_input_size) { + mLog.logAndThrow("Repeated list of PersistableBundle objects had " + + "wrong length."); + } + if (input[0].getInt(testIntKey) != repeated[0].getInt(testIntKey) + || input[1].getLong(testLongKey) != repeated[1].getLong(testLongKey) + || input[2].getDouble(testDoubleKey) != repeated[2].getDouble(testDoubleKey)) { + mLog.logAndThrow("Repeated list of PersistableBundle objects did not match."); + } + if (input.length != reversed.length || input.length != original_input_size) { + mLog.logAndThrow("Reversed list of PersistableBundle objects had " + + "wrong length."); + } + if (input[0].getInt(testIntKey) != reversed[2].getInt(testIntKey) + || input[1].getLong(testLongKey) != reversed[1].getLong(testLongKey) + || input[2].getDouble(testDoubleKey) != reversed[0].getDouble(testDoubleKey)) { + mLog.logAndThrow("reversed PersistableBundle objects were not equivalent"); + } + mLog.log("...service can repeat and reverse arrays of " + + "non-empty PersistableBundle objects..."); } } catch (Exception ex) { mLog.log(ex.toString()); - mLog.logAndThrow("Service failed to handle Parcelables."); + mLog.logAndThrow("Service failed to handle PersistableBundle objects."); } - mLog.log("...service can manipulate parcelables."); + mLog.log("...service can manipulate PersistableBundle objects."); } private void checkFileDescriptorPassing(ITestService service) @@ -542,7 +660,8 @@ public class TestServiceClient extends Activity { checkArrayReversal(service); checkBinderExchange(service); checkListReversal(service); - checkParcelables(service); + checkSimpleParcelables(service); + checkPersistableBundles(service); checkFileDescriptorPassing(service); checkServiceSpecificExceptions(service); mLog.log(mSuccessSentinel); |