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

Commit 28d6c35d authored by Yifan Hong's avatar Yifan Hong
Browse files

Use result-gmock.h.

Use the matchers defined in libbase.

Test: pass
Change-Id: I1a79ddb1ceabe1d5235f7ba1fbdbab79e36ecc8a
parent 5a993157
Loading
Loading
Loading
Loading
+5 −12
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@
#include <gtest/gtest.h>

#include <android-base/properties.h>
#include <android-base/result-gmock.h>
#include <android-base/result.h>
#include <android-base/unique_fd.h>
#include <binder/Binder.h>
@@ -52,6 +53,7 @@
using namespace android;
using namespace std::string_literals;
using namespace std::chrono_literals;
using android::base::testing::HasValue;
using testing::ExplainMatchResult;
using testing::Not;
using testing::WithParamInterface;
@@ -62,15 +64,6 @@ MATCHER_P(StatusEq, expected, (negation ? "not " : "") + statusToString(expected
    return expected == arg;
}

// e.g. Result<int32_t> v = 0; EXPECT_THAT(result, ResultHasValue(0));
MATCHER_P(ResultHasValue, resultMatcher, "") {
    if (!arg.ok()) {
        *result_listener << "contains error " << arg.error();
        return false;
    }
    return ExplainMatchResult(resultMatcher, arg.value(), result_listener);
}

static ::testing::AssertionResult IsPageAligned(void *buf) {
    if (((unsigned long)buf & ((unsigned long)PAGE_SIZE - 1)) == 0)
        return ::testing::AssertionSuccess();
@@ -514,7 +507,7 @@ TEST_F(BinderLibTest, SetError) {
}

TEST_F(BinderLibTest, GetId) {
    EXPECT_THAT(GetId(m_server), ResultHasValue(0));
    EXPECT_THAT(GetId(m_server), HasValue(0));
}

TEST_F(BinderLibTest, PtrSize) {
@@ -1279,7 +1272,7 @@ TEST_P(BinderLibRpcClientTest, Test) {
    sp<IBinder> server = isRemote ? sp<IBinder>(CreateRemoteService(id))
                                  : sp<IBinder>(sp<BinderLibTestService>::make(id, false));
    ASSERT_EQ(isRemote, !!server->remoteBinder());
    ASSERT_THAT(GetId(server), ResultHasValue(id));
    ASSERT_THAT(GetId(server), HasValue(id));

    unsigned int port = 0;
    // Fake servicedispatcher.
@@ -1309,7 +1302,7 @@ TEST_P(BinderLibRpcClientTest, Test) {
        EXPECT_EQ(OK, rpcServerBinder->pingBinder());

        // Check that |rpcServerBinder| and |server| points to the same service.
        EXPECT_THAT(GetId(rpcServerBinder), ResultHasValue(id));
        EXPECT_THAT(GetId(rpcServerBinder), HasValue(id));

        // Occupy the server thread. The server should still have enough threads to handle
        // other connections.