Merge changes from topic "ndk-aidl-parcelable-array" am: d38a30a6f9 am: 638282c8c8
am: c23b16a97a
Change-Id: I2b4861efc14064aebd35cda6707f2585598a9541
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg
index e781861..47f12b8 100644
--- a/PREUPLOAD.cfg
+++ b/PREUPLOAD.cfg
@@ -1,3 +1,10 @@
+[Builtin Hooks]
+clang_format = true
+
+[Builtin Hooks Options]
+clang_format = --commit ${PREUPLOAD_COMMIT} --style file --extensions c,h,cc,cpp
+ tests/tests/binder_ndk
+
[Hook Scripts]
checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT}
-fw apps/CtsVerifier/src/com/android/cts/verifier/usb/
diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/.clang-format b/tests/tests/binder_ndk/libbinder_ndk_test/.clang-format
new file mode 100644
index 0000000..42714cd
--- /dev/null
+++ b/tests/tests/binder_ndk/libbinder_ndk_test/.clang-format
@@ -0,0 +1,7 @@
+BasedOnStyle: Google
+ColumnLimit: 100
+IndentWidth: 2
+PointerAlignment: Left
+AllowShortFunctionsOnASingleLine: Inline
+PointerAlignment: Left
+UseTab: Never
diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/api/1/test_package/ITest.aidl b/tests/tests/binder_ndk/libbinder_ndk_test/api/1/test_package/ITest.aidl
index c212607..9a07405 100644
--- a/tests/tests/binder_ndk/libbinder_ndk_test/api/1/test_package/ITest.aidl
+++ b/tests/tests/binder_ndk/libbinder_ndk_test/api/1/test_package/ITest.aidl
@@ -33,6 +33,7 @@
float[] RepeatFloatArray(in float[] input, out float[] repeated);
double[] RepeatDoubleArray(in double[] input, out double[] repeated);
String[] RepeatStringArray(in String[] input, out String[] repeated);
+ RegularPolygon[] RepeatRegularPolygonArray(in RegularPolygon[] input, out RegularPolygon[] repeated);
@nullable boolean[] RepeatNullableBooleanArray(in @nullable boolean[] input);
@nullable byte[] RepeatNullableByteArray(in @nullable byte[] input);
@nullable char[] RepeatNullableCharArray(in @nullable char[] input);
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 b780f49..228759d 100644
--- a/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h
+++ b/tests/tests/binder_ndk/libbinder_ndk_test/itest_impl.h
@@ -232,6 +232,13 @@
*_aidl_return = in_value;
return ::ndk::ScopedAStatus(AStatus_newOk());
}
+ ::ndk::ScopedAStatus RepeatRegularPolygonArray(
+ const std::vector<RegularPolygon>& in_value, std::vector<RegularPolygon>* out_repeated,
+ std::vector<RegularPolygon>* _aidl_return) override {
+ *out_repeated = in_value;
+ *_aidl_return = in_value;
+ return ::ndk::ScopedAStatus(AStatus_newOk());
+ }
::ndk::ScopedAStatus RepeatNullableBooleanArray(
const std::optional<std::vector<bool>>& in_value,
std::optional<std::vector<bool>>* _aidl_return) override {
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 3491f69..5a24284 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
@@ -316,6 +316,22 @@
using RepeatMethod = ScopedAStatus (ITest::*)(const std::vector<T>&,
std::vector<T>*, std::vector<T>*);
+namespace aidl {
+namespace test_package {
+inline bool operator==(const RegularPolygon& lhs, const RegularPolygon& rhs) {
+ return lhs.name == rhs.name && lhs.numSides == rhs.numSides && lhs.sideLength == rhs.sideLength;
+}
+inline bool operator==(const std::vector<RegularPolygon>& lhs,
+ const std::vector<RegularPolygon>& rhs) {
+ if (lhs.size() != rhs.size()) return false;
+ for (size_t i = 0; i < lhs.size(); i++) {
+ if (!(lhs[i] == rhs[i])) return false;
+ }
+ return true;
+}
+} // namespace test_package
+} // namespace aidl
+
template <typename T>
void testRepeat(const std::shared_ptr<ITest>& i, RepeatMethod<T> repeatMethod,
std::vector<std::vector<T>> tests) {
@@ -379,6 +395,12 @@
{"asdf"},
{"", "aoeu", "lol", "brb"},
});
+ testRepeat<RegularPolygon>(iface, &ITest::RepeatRegularPolygonArray,
+ {
+ {},
+ {{"hexagon", 6, 2.0f}},
+ {{"hexagon", 6, 2.0f}, {"square", 4, 7.0f}, {"pentagon", 5, 4.2f}},
+ });
}
template <typename T>
@@ -493,9 +515,9 @@
}
class DefaultImpl : public ::aidl::test_package::ITestDefault {
-public:
+ public:
::ndk::ScopedAStatus NewMethodThatReturns10(int32_t* _aidl_return) override {
- *_aidl_return = 100; // default impl returns different value
+ *_aidl_return = 100; // default impl returns different value
return ::ndk::ScopedAStatus(AStatus_newOk());
}
};
@@ -567,9 +589,7 @@
}
INSTANTIATE_TEST_CASE_P(LocalNative, NdkBinderTest_Aidl,
- ::testing::Values(Params{getLocalService(),
- false /*shouldBeRemote*/,
- "CPP",
+ ::testing::Values(Params{getLocalService(), false /*shouldBeRemote*/, "CPP",
false /*shouldBeOld*/}));
INSTANTIATE_TEST_CASE_P(
LocalNativeFromJava, NdkBinderTest_Aidl,
@@ -577,9 +597,9 @@
getNdkBinderTestJavaService("getLocalNativeService"),
false /*shouldBeRemote*/, "CPP", false /*shouldBeOld*/}));
INSTANTIATE_TEST_CASE_P(LocalJava, NdkBinderTest_Aidl,
- ::testing::Values(Params{
- getNdkBinderTestJavaService("getLocalJavaService"),
- false /*shouldBeRemote*/, "JAVA", false /*shouldBeOld*/}));
+ ::testing::Values(Params{getNdkBinderTestJavaService("getLocalJavaService"),
+ false /*shouldBeRemote*/, "JAVA",
+ false /*shouldBeOld*/}));
INSTANTIATE_TEST_CASE_P(
RemoteNative, NdkBinderTest_Aidl,
::testing::Values(Params{
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 7329271..1061b94 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
@@ -78,6 +78,7 @@
float[] RepeatFloatArray(in float[] input, out float[] repeated);
double[] RepeatDoubleArray(in double[] input, out double[] repeated);
String[] RepeatStringArray(in String[] input, out String[] repeated);
+ RegularPolygon[] RepeatRegularPolygonArray(in RegularPolygon[] input, out RegularPolygon[] repeated);
// Nullable Arrays
@nullable boolean[] RepeatNullableBooleanArray(in @nullable boolean[] input);
diff --git a/tests/tests/binder_ndk/libbinder_ndk_test/test_parcel.cpp b/tests/tests/binder_ndk/libbinder_ndk_test/test_parcel.cpp
index 87279a5..80c7313 100644
--- a/tests/tests/binder_ndk/libbinder_ndk_test/test_parcel.cpp
+++ b/tests/tests/binder_ndk/libbinder_ndk_test/test_parcel.cpp
@@ -211,7 +211,7 @@
// every element of the vector is a prefix of this string
const std::string& element;
// this is the number of characters of the string to write, < element.size()
- size_t elementLen;
+ int32_t elementLen;
binder_status_t writeToParcel(AParcel* p, size_t length) const {
return AParcel_writeStringArray(p, static_cast<const void*>(this), length,
@@ -219,8 +219,7 @@
}
private:
- static const char* ElementGetter(const void* vectorData, size_t /*index*/,
- size_t* outLength) {
+ static const char* ElementGetter(const void* vectorData, size_t /*index*/, int32_t* outLength) {
const PartialStringCycle* vector =
static_cast<const PartialStringCycle*>(vectorData);
@@ -236,7 +235,8 @@
const std::vector<std::string> expectedVector = {expectedString,
expectedString};
- const PartialStringCycle writeVector{.element = kTestcase, .elementLen = i};
+ const PartialStringCycle writeVector{.element = kTestcase,
+ .elementLen = static_cast<int32_t>(i)};
AIBinder* binder = SampleData::newBinder(
[&](transaction_code_t, const AParcel* in, AParcel* /*out*/) {
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 4552c0e..ce71d32 100644
--- a/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java
+++ b/tests/tests/binder_ndk/src/android/binder/cts/JavaClientTest.java
@@ -217,6 +217,18 @@
assertEquals("foo", mInterface.RepeatNullableString("foo"));
}
+ public void assertPolygonEquals(RegularPolygon lhs, RegularPolygon rhs) {
+ assertEquals(lhs.name, rhs.name);
+ assertEquals(lhs.numSides, rhs.numSides);
+ assertEquals(lhs.sideLength, rhs.sideLength, 0.0f);
+ }
+ public void assertPolygonEquals(RegularPolygon[] lhs, RegularPolygon[] rhs) {
+ assertEquals(lhs.length, rhs.length);
+ for (int i = 0; i < lhs.length; i++) {
+ assertPolygonEquals(lhs[i], rhs[i]);
+ }
+ }
+
@Test
public void testRepeatPolygon() throws RemoteException {
RegularPolygon polygon = new RegularPolygon();
@@ -226,9 +238,7 @@
RegularPolygon result = mInterface.RepeatPolygon(polygon);
- assertEquals(polygon.name, result.name);
- assertEquals(polygon.numSides, result.numSides);
- assertEquals(polygon.sideLength, result.sideLength, 0.0f);
+ assertPolygonEquals(polygon, result);
}
@Test
@@ -312,6 +322,20 @@
Assert.assertArrayEquals(value, out1);
Assert.assertArrayEquals(value, out2);
}
+ {
+
+ RegularPolygon septagon = new RegularPolygon();
+ septagon.name = "septagon";
+ septagon.numSides = 7;
+ septagon.sideLength = 1.0f;
+
+ RegularPolygon[] value = {septagon, new RegularPolygon(), new RegularPolygon()};
+ RegularPolygon[] out1 = new RegularPolygon[value.length];
+ RegularPolygon[] out2 = mInterface.RepeatRegularPolygonArray(value, out1);
+
+ assertPolygonEquals(value, out1);
+ assertPolygonEquals(value, out2);
+ }
}
@Test
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 0cd785e..168ee9e 100644
--- a/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java
+++ b/tests/tests/binder_ndk/src/android/binder/cts/TestImpl.java
@@ -222,6 +222,12 @@
}
@Override
+ public RegularPolygon[] RepeatRegularPolygonArray(RegularPolygon[] in_value, RegularPolygon[] repeated) {
+ System.arraycopy(in_value, 0, repeated, 0, in_value.length);
+ return in_value;
+ }
+
+ @Override
public boolean[] RepeatNullableBooleanArray(boolean[] in_value) {
return in_value;
}