Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 28318606 authored by Steven Moreland's avatar Steven Moreland
Browse files

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
parent 41c93883
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
      "name": "binderTextOutputTest"
    },
    {
      "name": "binderParcelTest"
      "name": "binderUnitTest"
    },
    {
      "name": "binderLibTest"
+2 −2
Original line number Diff line number Diff line
@@ -77,14 +77,14 @@ cc_test {

// 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",
+28 −31
Original line number Diff line number Diff line
@@ -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,18 +39,16 @@ void parcelOpSameLength(const std::function<void(Parcel*)>& a, const std::functi

TEST(Parcel, InverseInterfaceToken) {
    const String16 token = String16("asdf");
    parcelOpSameLength([&] (Parcel* p) {
        p->writeInterfaceToken(token);
    }, [&] (Parcel* p) {
    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) {
    parcelOpSameLength([&](Parcel* p) { p->writeString16(String16(token)); },
                       [&](Parcel* p) {
                           std::string s;
                           EXPECT_EQ(OK, p->readUtf8FromUtf16(&s));
                           EXPECT_EQ(token, s);
@@ -58,9 +57,8 @@ TEST(Parcel, Utf8FromUtf16Read) {

TEST(Parcel, Utf8AsUtf16Write) {
    std::string token = "asdf";
    parcelOpSameLength([&] (Parcel* p) {
        p->writeUtf8AsUtf16(token);
    }, [&] (Parcel* p) {
    parcelOpSameLength([&](Parcel* p) { p->writeUtf8AsUtf16(token); },
                       [&](Parcel* p) {
                           String16 s;
                           EXPECT_EQ(OK, p->readString16(&s));
                           EXPECT_EQ(s, String16(token.c_str()));
@@ -77,9 +75,8 @@ using copyWriteFunc = status_t (Parcel::*)(T in);
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) {
        parcelOpSameLength([&](Parcel* p) { (*p.*w)(value); },
                           [&](Parcel* p) {
                               T outValue;
                               EXPECT_EQ(OK, (*p.*r)(&outValue));
                               EXPECT_EQ(value, outValue);