diff options
author | Steven Moreland <smoreland@google.com> | 2018-10-19 07:26:03 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-10-19 07:26:03 -0700 |
commit | 55614707fcf367cceb5642c1dad44a57d6202857 (patch) | |
tree | 03688c43dd674a6e85a5ab4f3885e7086372e419 | |
parent | 5c837ef5ced2947e0b517b151214155c6c31ba16 (diff) | |
parent | 7f0f7cc62d56d4e18573aaa95c8a55a2a6f3f6ca (diff) | |
download | cts-55614707fcf367cceb5642c1dad44a57d6202857.tar.gz |
Merge "Tests for reading/writing primitive arrays."
am: 7f0f7cc62d
Change-Id: Icbdd74eab295e5f0c4d8a069821e8d428f496e88
6 files changed, 252 insertions, 15 deletions
diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h b/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h index a2f2b8962e3..2992628d633 100644 --- a/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h +++ b/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h @@ -96,4 +96,54 @@ class MyTest : public ::aidl::test_package::BnTest, value->name = newName; return ::ndk::ScopedAStatus(AStatus_newOk()); } + ::ndk::ScopedAStatus RepeatBooleanArray( + const std::vector<bool>& in_value, std::vector<bool>* out_repeated, + std::vector<bool>* _aidl_return) override { + *out_repeated = in_value; + *_aidl_return = in_value; + return ::ndk::ScopedAStatus(AStatus_newOk()); + } + ::ndk::ScopedAStatus RepeatByteArray( + const std::vector<int8_t>& in_value, std::vector<int8_t>* out_repeated, + std::vector<int8_t>* _aidl_return) override { + *out_repeated = in_value; + *_aidl_return = in_value; + return ::ndk::ScopedAStatus(AStatus_newOk()); + } + ::ndk::ScopedAStatus RepeatCharArray( + const std::vector<char16_t>& in_value, + std::vector<char16_t>* out_repeated, + std::vector<char16_t>* _aidl_return) override { + *out_repeated = in_value; + *_aidl_return = in_value; + return ::ndk::ScopedAStatus(AStatus_newOk()); + } + ::ndk::ScopedAStatus RepeatIntArray( + const std::vector<int32_t>& in_value, std::vector<int32_t>* out_repeated, + std::vector<int32_t>* _aidl_return) override { + *out_repeated = in_value; + *_aidl_return = in_value; + return ::ndk::ScopedAStatus(AStatus_newOk()); + } + ::ndk::ScopedAStatus RepeatLongArray( + const std::vector<int64_t>& in_value, std::vector<int64_t>* out_repeated, + std::vector<int64_t>* _aidl_return) override { + *out_repeated = in_value; + *_aidl_return = in_value; + return ::ndk::ScopedAStatus(AStatus_newOk()); + } + ::ndk::ScopedAStatus RepeatFloatArray( + const std::vector<float>& in_value, std::vector<float>* out_repeated, + std::vector<float>* _aidl_return) override { + *out_repeated = in_value; + *_aidl_return = in_value; + return ::ndk::ScopedAStatus(AStatus_newOk()); + } + ::ndk::ScopedAStatus RepeatDoubleArray( + const std::vector<double>& in_value, std::vector<double>* out_repeated, + std::vector<double>* _aidl_return) override { + *out_repeated = in_value; + *_aidl_return = in_value; + return ::ndk::ScopedAStatus(AStatus_newOk()); + } };
\ No newline at end of file diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/test_native_aidl_client.cpp b/tests/tests/binder_ndk/libbinder_ndk_test/test_native_aidl_client.cpp index 099ea1cdba3..0959952c819 100644 --- a/tests/tests/binder_ndk/libbinder_ndk_test/test_native_aidl_client.cpp +++ b/tests/tests/binder_ndk/libbinder_ndk_test/test_native_aidl_client.cpp @@ -15,11 +15,11 @@ */ #define LOG_TAG "Cts-NdkBinderTest" -#include <android/binder_ibinder_jni.h> -#include <gtest/gtest.h> #include <aidl/test_package/BnEmpty.h> #include <aidl/test_package/BpTest.h> #include <aidl/test_package/RegularPolygon.h> +#include <android/binder_ibinder_jni.h> +#include <gtest/gtest.h> #include "itest_impl.h" #include "utilities.h" @@ -176,6 +176,69 @@ TEST_P(NdkBinderTest_Aidl, InsAndOuts) { EXPECT_EQ("Jerry", defaultPolygon.name); } +template <typename T> +using RepeatMethod = ScopedAStatus (ITest::*)(const std::vector<T>&, + std::vector<T>*, std::vector<T>*); + +template <typename T> +void testRepeat(const std::shared_ptr<ITest>& i, RepeatMethod<T> repeatMethod, + std::vector<std::vector<T>> tests) { + for (const auto& input : tests) { + std::vector<T> out1; + out1.resize(input.size()); + std::vector<T> out2; + + ASSERT_OK((i.get()->*repeatMethod)(input, &out1, &out2)) << input.size(); + EXPECT_EQ(input, out1); + EXPECT_EQ(input, out2); + } +} + +TEST_P(NdkBinderTest_Aidl, PrimitiveArrays) { + testRepeat<bool>(iface, &ITest::RepeatBooleanArray, + { + {}, + {true}, + {false, true, false}, + }); + testRepeat<int8_t>(iface, &ITest::RepeatByteArray, + { + {}, + {1}, + {1, 2, 3}, + }); + testRepeat<char16_t>(iface, &ITest::RepeatCharArray, + { + {}, + {L'@'}, + {L'@', L'!', L'A'}, + }); + testRepeat<int32_t>(iface, &ITest::RepeatIntArray, + { + {}, + {1}, + {1, 2, 3}, + }); + testRepeat<int64_t>(iface, &ITest::RepeatLongArray, + { + {}, + {1}, + {1, 2, 3}, + }); + testRepeat<float>(iface, &ITest::RepeatFloatArray, + { + {}, + {1.0f}, + {1.0f, 2.0f, 3.0f}, + }); + testRepeat<double>(iface, &ITest::RepeatDoubleArray, + { + {}, + {1.0}, + {1.0, 2.0, 3.0}, + }); +} + std::shared_ptr<ITest> getLocalService() { // BpTest -> AIBinder -> test std::shared_ptr<MyTest> test = SharedRefBase::make<MyTest>(); diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/test_package/ITest.aidl b/tests/tests/binder_ndk/libbinder_ndk_test/test_package/ITest.aidl index 54792a4e9a8..ef0faf4f440 100644 --- a/tests/tests/binder_ndk/libbinder_ndk_test/test_package/ITest.aidl +++ b/tests/tests/binder_ndk/libbinder_ndk_test/test_package/ITest.aidl @@ -53,4 +53,14 @@ interface ITest { // Testing inout void RenamePolygon(inout RegularPolygon value, String newName); + + // Arrays + boolean[] RepeatBooleanArray(in boolean[] input, out boolean[] repeated); + byte[] RepeatByteArray(in byte[] input, out byte[] repeated); + char[] RepeatCharArray(in char[] input, out char[] repeated); + int[] RepeatIntArray(in int[] input, out int[] repeated); + long[] RepeatLongArray(in long[] input, out long[] repeated); + float[] RepeatFloatArray(in float[] input, out float[] repeated); + double[] RepeatDoubleArray(in double[] input, out double[] repeated); + } diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/utilities.h b/tests/tests/binder_ndk/libbinder_ndk_test/utilities.h index d254a45c997..4699636a09c 100644 --- a/tests/tests/binder_ndk/libbinder_ndk_test/utilities.h +++ b/tests/tests/binder_ndk/libbinder_ndk_test/utilities.h @@ -33,7 +33,10 @@ inline ::testing::AssertionResult isOk(::ndk::ScopedAStatus t) { if (AStatus_isOk(t.get())) { return ::testing::AssertionSuccess(); } else { - return ::testing::AssertionFailure(); + return ::testing::AssertionFailure() + << "exception: " << AStatus_getExceptionCode(t.get()) + << " service specific: " << AStatus_getServiceSpecificError(t.get()) + << " status: " << AStatus_getStatus(t.get()); } } diff --git a/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java b/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java index 4aec6645af5..0e62f8ab270 100644 --- a/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java +++ b/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java @@ -37,6 +37,7 @@ import test_package.RegularPolygon; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -151,4 +152,72 @@ public class JavaClientTest { mInterface.RenamePolygon(polygon, "Jerry"); assertEquals("Jerry", polygon.name); } + + @Test + public void testPrimitiveArrays() throws RemoteException { + { + boolean[] value = {}; + boolean[] out1 = new boolean[0]; + boolean[] out2 = mInterface.RepeatBooleanArray(value, out1); + + Assert.assertArrayEquals(value, out1); + Assert.assertArrayEquals(value, out2); + } + { + boolean[] value = {false, true, false}; + boolean[] out1 = new boolean[3]; + boolean[] out2 = mInterface.RepeatBooleanArray(value, out1); + + Assert.assertArrayEquals(value, out1); + Assert.assertArrayEquals(value, out2); + } + { + byte[] value = {1, 2, 3}; + byte[] out1 = new byte[3]; + byte[] out2 = mInterface.RepeatByteArray(value, out1); + + Assert.assertArrayEquals(value, out1); + Assert.assertArrayEquals(value, out2); + } + { + char[] value = {'h', 'a', '!'}; + char[] out1 = new char[3]; + char[] out2 = mInterface.RepeatCharArray(value, out1); + + Assert.assertArrayEquals(value, out1); + Assert.assertArrayEquals(value, out2); + } + { + int[] value = {1, 2, 3}; + int[] out1 = new int[3]; + int[] out2 = mInterface.RepeatIntArray(value, out1); + + Assert.assertArrayEquals(value, out1); + Assert.assertArrayEquals(value, out2); + } + { + long[] value = {1, 2, 3}; + long[] out1 = new long[3]; + long[] out2 = mInterface.RepeatLongArray(value, out1); + + Assert.assertArrayEquals(value, out1); + Assert.assertArrayEquals(value, out2); + } + { + float[] value = {1.0f, 2.0f, 3.0f}; + float[] out1 = new float[3]; + float[] out2 = mInterface.RepeatFloatArray(value, out1); + + Assert.assertArrayEquals(value, out1, 0.0f); + Assert.assertArrayEquals(value, out2, 0.0f); + } + { + double[] value = {1.0, 2.0, 3.0}; + double[] out1 = new double[3]; + double[] out2 = mInterface.RepeatDoubleArray(value, out1); + + Assert.assertArrayEquals(value, out1, 0.0); + Assert.assertArrayEquals(value, out2, 0.0); + } + } } diff --git a/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java b/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java index fb3788f9e9d..acef22af067 100644 --- a/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java +++ b/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java @@ -36,61 +36,103 @@ public class TestImpl extends ITest.Stub { @Override public int RepeatInt(int in_value) { - return in_value; + return in_value; } @Override public long RepeatLong(long in_value) { - return in_value; + return in_value; } @Override public float RepeatFloat(float in_value) { - return in_value; + return in_value; } @Override public double RepeatDouble(double in_value) { - return in_value; + return in_value; } @Override public boolean RepeatBoolean(boolean in_value) { - return in_value; + return in_value; } @Override public char RepeatChar(char in_value) { - return in_value; + return in_value; } @Override public byte RepeatByte(byte in_value) { - return in_value; + return in_value; } @Override public IBinder RepeatBinder(IBinder in_value) { - return in_value; + return in_value; } @Override public IEmpty RepeatInterface(IEmpty in_value) { - return in_value; + return in_value; } @Override public String RepeatString(String in_value) { - return in_value; + return in_value; } @Override public RegularPolygon RepeatPolygon(RegularPolygon in_value) { - return in_value; + return in_value; } @Override public void RenamePolygon(RegularPolygon value, String name) { - value.name = name; + value.name = name; + } + + @Override + public boolean[] RepeatBooleanArray(boolean[] in_value, boolean[] repeated) { + System.arraycopy(in_value, 0, repeated, 0, in_value.length); + return in_value; + } + + @Override + public byte[] RepeatByteArray(byte[] in_value, byte[] repeated) { + System.arraycopy(in_value, 0, repeated, 0, in_value.length); + return in_value; + } + + @Override + public char[] RepeatCharArray(char[] in_value, char[] repeated) { + System.arraycopy(in_value, 0, repeated, 0, in_value.length); + return in_value; + } + + @Override + public int[] RepeatIntArray(int[] in_value, int[] repeated) { + System.arraycopy(in_value, 0, repeated, 0, in_value.length); + return in_value; + } + + @Override + public long[] RepeatLongArray(long[] in_value, long[] repeated) { + System.arraycopy(in_value, 0, repeated, 0, in_value.length); + return in_value; + } + + @Override + public float[] RepeatFloatArray(float[] in_value, float[] repeated) { + System.arraycopy(in_value, 0, repeated, 0, in_value.length); + return in_value; + } + + @Override + public double[] RepeatDoubleArray(double[] in_value, double[] repeated) { + System.arraycopy(in_value, 0, repeated, 0, in_value.length); + return in_value; } } |