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 #include "PipeRunner.h"
29
30 using namespace android::automotive::computepipe::router;
31 using namespace android::automotive::computepipe::router::V1_0::implementation;
32 using namespace android::automotive::computepipe::tests;
33 using namespace aidl::android::automotive::computepipe::runner;
34 using namespace aidl::android::automotive::computepipe::registry;
35 /**
36 * Test fixture that manages the underlying registry creation and tear down
37 */
38 class PipeRegistrationTest : public ::testing::Test {
39 protected:
SetUp()40 void SetUp() override {
41 mRegistry = std::make_shared<PipeRegistry<PipeRunner>>();
42 ASSERT_THAT(mRegistry, testing::NotNull());
43 }
44
TearDown()45 void TearDown() override {
46 mRegistry = nullptr;
47 }
48 std::shared_ptr<PipeRegistry<PipeRunner>> mRegistry;
49 };
50
51 // Valid registration succeeds
TEST_F(PipeRegistrationTest,RegisterFakeRunner)52 TEST_F(PipeRegistrationTest, RegisterFakeRunner) {
53 std::shared_ptr<IPipeRunner> fake = ndk::SharedRefBase::make<FakeRunner>();
54 std::shared_ptr<IPipeRegistration> rIface =
55 ndk::SharedRefBase::make<PipeRegistration>(this->mRegistry);
56 EXPECT_TRUE(rIface->registerPipeRunner("fake", fake).isOk());
57 }
58
59 // Duplicate registration fails
TEST_F(PipeRegistrationTest,RegisterDuplicateRunner)60 TEST_F(PipeRegistrationTest, RegisterDuplicateRunner) {
61 std::shared_ptr<IPipeRunner> fake = ndk::SharedRefBase::make<FakeRunner>();
62 std::shared_ptr<IPipeRegistration> rIface =
63 ndk::SharedRefBase::make<PipeRegistration>(this->mRegistry);
64 ASSERT_TRUE(rIface->registerPipeRunner("fake", fake).isOk());
65 EXPECT_FALSE(rIface->registerPipeRunner("fake", fake).isOk());
66 }
67