rename binderParcelTest binderUnitTest
This is a host test, and I would like to have more tests here which can
also work on the host.
Bug: 192023359
Test: binderUnitTest
Change-Id: Ie4e7e25d99fd87ef81b1da4345fc9dfe1cc2da6d
diff --git a/libs/binder/tests/Android.bp b/libs/binder/tests/Android.bp
index d5a2b61..8faa3b8 100644
--- a/libs/binder/tests/Android.bp
+++ b/libs/binder/tests/Android.bp
@@ -77,14 +77,14 @@
// unit test only, which can run on host and doesn't use /dev/binder
cc_test {
- name: "binderParcelTest",
+ name: "binderUnitTest",
host_supported: true,
target: {
darwin: {
enabled: false,
},
},
- srcs: ["binderParcelTest.cpp"],
+ srcs: ["binderParcelUnitTest.cpp"],
shared_libs: [
"libbinder",
"libutils",
diff --git a/libs/binder/tests/binderParcelTest.cpp b/libs/binder/tests/binderParcelUnitTest.cpp
similarity index 65%
rename from libs/binder/tests/binderParcelTest.cpp
rename to libs/binder/tests/binderParcelUnitTest.cpp
index 1764228..fb49d7a 100644
--- a/libs/binder/tests/binderParcelTest.cpp
+++ b/libs/binder/tests/binderParcelUnitTest.cpp
@@ -14,20 +14,21 @@
* limitations under the License.
*/
-#include <binder/Parcel.h>
#include <binder/IPCThreadState.h>
+#include <binder/Parcel.h>
#include <gtest/gtest.h>
using android::IPCThreadState;
using android::OK;
using android::Parcel;
+using android::status_t;
using android::String16;
using android::String8;
-using android::status_t;
// Tests a second operation results in a parcel at the same location as it
// started.
-void parcelOpSameLength(const std::function<void(Parcel*)>& a, const std::function<void(Parcel*)>& b) {
+void parcelOpSameLength(const std::function<void(Parcel*)>& a,
+ const std::function<void(Parcel*)>& b) {
Parcel p;
a(&p);
size_t end = p.dataPosition();
@@ -38,33 +39,30 @@
TEST(Parcel, InverseInterfaceToken) {
const String16 token = String16("asdf");
- parcelOpSameLength([&] (Parcel* p) {
- p->writeInterfaceToken(token);
- }, [&] (Parcel* p) {
- EXPECT_TRUE(p->enforceInterface(token, IPCThreadState::self()));
- });
+ parcelOpSameLength([&](Parcel* p) { p->writeInterfaceToken(token); },
+ [&](Parcel* p) {
+ EXPECT_TRUE(p->enforceInterface(token, IPCThreadState::self()));
+ });
}
TEST(Parcel, Utf8FromUtf16Read) {
const char* token = "asdf";
- parcelOpSameLength([&] (Parcel* p) {
- p->writeString16(String16(token));
- }, [&] (Parcel* p) {
- std::string s;
- EXPECT_EQ(OK, p->readUtf8FromUtf16(&s));
- EXPECT_EQ(token, s);
- });
+ parcelOpSameLength([&](Parcel* p) { p->writeString16(String16(token)); },
+ [&](Parcel* p) {
+ std::string s;
+ EXPECT_EQ(OK, p->readUtf8FromUtf16(&s));
+ EXPECT_EQ(token, s);
+ });
}
TEST(Parcel, Utf8AsUtf16Write) {
std::string token = "asdf";
- parcelOpSameLength([&] (Parcel* p) {
- p->writeUtf8AsUtf16(token);
- }, [&] (Parcel* p) {
- String16 s;
- EXPECT_EQ(OK, p->readString16(&s));
- EXPECT_EQ(s, String16(token.c_str()));
- });
+ parcelOpSameLength([&](Parcel* p) { p->writeUtf8AsUtf16(token); },
+ [&](Parcel* p) {
+ String16 s;
+ EXPECT_EQ(OK, p->readString16(&s));
+ EXPECT_EQ(s, String16(token.c_str()));
+ });
}
template <typename T>
@@ -77,13 +75,12 @@
template <typename T, typename WRITE_FUNC>
void readWriteInverse(std::vector<T>&& ts, readFunc<T> r, WRITE_FUNC w) {
for (const T& value : ts) {
- parcelOpSameLength([&] (Parcel* p) {
- (*p.*w)(value);
- }, [&] (Parcel* p) {
- T outValue;
- EXPECT_EQ(OK, (*p.*r)(&outValue));
- EXPECT_EQ(value, outValue);
- });
+ parcelOpSameLength([&](Parcel* p) { (*p.*w)(value); },
+ [&](Parcel* p) {
+ T outValue;
+ EXPECT_EQ(OK, (*p.*r)(&outValue));
+ EXPECT_EQ(value, outValue);
+ });
}
}
@@ -96,8 +93,8 @@
readWriteInverse<T, copyWriteFunc<T>>(std::move(ts), r, w);
}
-#define TEST_READ_WRITE_INVERSE(type, name, ...) \
- TEST(Parcel, Inverse##name) { \
+#define TEST_READ_WRITE_INVERSE(type, name, ...) \
+ TEST(Parcel, Inverse##name) { \
readWriteInverse<type>(__VA_ARGS__, &Parcel::read##name, &Parcel::write##name); \
}