blob: 4af8440bb41a2c2e06235e2b2865ce4526759e48 [file] [log] [blame]
Hanumant Singhed9a2732019-10-25 20:30:51 -07001/*
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"
Hanumant Singh2a2b1a32019-11-05 09:04:59 -080028#include "PipeRunner.h"
Hanumant Singhed9a2732019-10-25 20:30:51 -070029
30using namespace android::automotive::computepipe::router;
31using namespace android::automotive::computepipe::router::V1_0::implementation;
32using namespace android::automotive::computepipe::tests;
Hanumant Singh2d5d2952019-12-17 14:34:15 -080033using namespace aidl::android::automotive::computepipe::runner;
34using namespace aidl::android::automotive::computepipe::registry;
Hanumant Singhed9a2732019-10-25 20:30:51 -070035/**
36 * Test fixture that manages the underlying registry creation and tear down
37 */
38class PipeRegistrationTest : public ::testing::Test {
39 protected:
40 void SetUp() override {
Hanumant Singh2a2b1a32019-11-05 09:04:59 -080041 mRegistry = std::make_shared<PipeRegistry<PipeRunner>>();
Hanumant Singhed9a2732019-10-25 20:30:51 -070042 ASSERT_THAT(mRegistry, testing::NotNull());
43 }
44
45 void TearDown() override {
46 mRegistry = nullptr;
47 }
Hanumant Singh2a2b1a32019-11-05 09:04:59 -080048 std::shared_ptr<PipeRegistry<PipeRunner>> mRegistry;
Hanumant Singhed9a2732019-10-25 20:30:51 -070049};
50
51// Valid registration succeeds
52TEST_F(PipeRegistrationTest, RegisterFakeRunner) {
Kathan Shukla62bda392020-08-06 10:31:01 -070053 std::shared_ptr<IPipeRunner> fake = ndk::SharedRefBase::make<FakeRunner>();
Hanumant Singh2d5d2952019-12-17 14:34:15 -080054 std::shared_ptr<IPipeRegistration> rIface =
55 ndk::SharedRefBase::make<PipeRegistration>(this->mRegistry);
Kathan Shukla62bda392020-08-06 10:31:01 -070056 EXPECT_TRUE(rIface->registerPipeRunner("fake", fake).isOk());
Hanumant Singhed9a2732019-10-25 20:30:51 -070057}
58
59// Duplicate registration fails
60TEST_F(PipeRegistrationTest, RegisterDuplicateRunner) {
Kathan Shukla62bda392020-08-06 10:31:01 -070061 std::shared_ptr<IPipeRunner> fake = ndk::SharedRefBase::make<FakeRunner>();
Hanumant Singh2d5d2952019-12-17 14:34:15 -080062 std::shared_ptr<IPipeRegistration> rIface =
63 ndk::SharedRefBase::make<PipeRegistration>(this->mRegistry);
Kathan Shukla62bda392020-08-06 10:31:01 -070064 ASSERT_TRUE(rIface->registerPipeRunner("fake", fake).isOk());
65 EXPECT_FALSE(rIface->registerPipeRunner("fake", fake).isOk());
Hanumant Singhed9a2732019-10-25 20:30:51 -070066}