Hanumant Singh | ed9a273 | 2019-10-25 20:30:51 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <gmock/gmock.h> |
| 18 | #include <gtest/gtest.h> |
| 19 | #include <stdio.h> |
| 20 | |
| 21 | #include <list> |
| 22 | #include <memory> |
| 23 | #include <string> |
| 24 | #include <utility> |
| 25 | |
| 26 | #include "FakeRunner.h" |
| 27 | #include "PipeRegistration.h" |
| 28 | |
| 29 | using namespace android::automotive::computepipe::router; |
| 30 | using namespace android::automotive::computepipe::router::V1_0::implementation; |
| 31 | using namespace android::automotive::computepipe::tests; |
| 32 | using namespace android::automotive::computepipe::runner::V1_0; |
| 33 | using namespace android::automotive::computepipe::registry::V1_0; |
| 34 | using namespace android::automotive::computepipe::V1_0; |
| 35 | |
| 36 | /** |
| 37 | * Test fixture that manages the underlying registry creation and tear down |
| 38 | */ |
| 39 | class PipeRegistrationTest : public ::testing::Test { |
| 40 | protected: |
| 41 | void SetUp() override { |
| 42 | mRegistry = std::make_shared<PipeRegistry<IPipeRunner>>(); |
| 43 | ASSERT_THAT(mRegistry, testing::NotNull()); |
| 44 | } |
| 45 | |
| 46 | void TearDown() override { |
| 47 | mRegistry = nullptr; |
| 48 | } |
| 49 | std::shared_ptr<PipeRegistry<IPipeRunner>> mRegistry; |
| 50 | }; |
| 51 | |
| 52 | // Valid registration succeeds |
| 53 | TEST_F(PipeRegistrationTest, RegisterFakeRunner) { |
| 54 | sp<IPipeRunner> dummy = new FakeRunner(); |
| 55 | std::unique_ptr<IPipeRegistration> rIface(new PipeRegistration(this->mRegistry)); |
| 56 | EXPECT_THAT(rIface->registerPipeRunner("dummy", dummy), testing::Eq(PipeStatus::OK)); |
| 57 | } |
| 58 | |
| 59 | // Duplicate registration fails |
| 60 | TEST_F(PipeRegistrationTest, RegisterDuplicateRunner) { |
| 61 | sp<IPipeRunner> dummy = new FakeRunner(); |
| 62 | std::unique_ptr<IPipeRegistration> rIface(new PipeRegistration(this->mRegistry)); |
| 63 | ASSERT_THAT(rIface->registerPipeRunner("dummy", dummy), testing::Eq(PipeStatus::OK)); |
| 64 | EXPECT_THAT(rIface->registerPipeRunner("dummy", dummy), testing::Eq(PipeStatus::INTERNAL_ERR)); |
| 65 | } |
| 66 | |
| 67 | // Reregistration of dead runner succeeds |
| 68 | TEST_F(PipeRegistrationTest, RegisterDeadRunner) { |
| 69 | sp<IPipeRunner> dummy = new FakeRunner(); |
| 70 | std::unique_ptr<IPipeRegistration> rIface(new PipeRegistration(this->mRegistry)); |
| 71 | ASSERT_THAT(rIface->registerPipeRunner("dummy", dummy), testing::Eq(PipeStatus::OK)); |
| 72 | dummy.clear(); |
| 73 | dummy = new FakeRunner(); |
| 74 | EXPECT_THAT(rIface->registerPipeRunner("dummy", dummy), testing::Eq(PipeStatus::OK)); |
| 75 | } |