/* * Copyright (C) 2024 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "binder/IInterface.h" #include "testserver/TestServerClient.h" namespace android { namespace { class TestServerTest : public ::testing::Test { protected: TestServerTest() { ProcessState::self()->startThreadPool(); } }; } // namespace TEST_F(TestServerTest, Create) { EXPECT_NE(nullptr, TestServerClient::Create()); } TEST_F(TestServerTest, CreateProducer) { sp client = TestServerClient::Create(); EXPECT_NE(nullptr, client->CreateProducer()); } TEST_F(TestServerTest, KillServer) { class DeathWaiter : public IBinder::DeathRecipient { public: virtual void binderDied(const wp&) override { mPromise.set_value(true); } std::future getFuture() { return mPromise.get_future(); } std::promise mPromise; }; sp client = TestServerClient::Create(); sp producer = client->CreateProducer(); EXPECT_NE(nullptr, producer); sp deathWaiter = sp::make(); EXPECT_EQ(OK, IInterface::asBinder(producer)->linkToDeath(deathWaiter)); auto deathWaiterFuture = deathWaiter->getFuture(); EXPECT_EQ(OK, client->Kill()); EXPECT_EQ(nullptr, client->CreateProducer()); EXPECT_TRUE(deathWaiterFuture.get()); } } // namespace android