1 // Copyright (C) 2022 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <gtest/gtest.h>
16
17 #include "ServiceConfig.h"
18
19 using namespace audio_proxy::service;
20
TEST(ServiceConfigTest,GoodConfig)21 TEST(ServiceConfigTest, GoodConfig) {
22 char* argv[] = {"command", "--name", "service", "--stream", "A:1:2"};
23 auto config =
24 parseServiceConfigFromCommandLine(sizeof(argv) / sizeof(argv[0]), argv);
25
26 ASSERT_TRUE(config);
27 EXPECT_EQ(config->name, "service");
28 EXPECT_EQ(config->streams.size(), 1);
29 EXPECT_EQ(config->streams.begin()->first, "A");
30 EXPECT_EQ(config->streams.begin()->second.bufferSizeMs, 1u);
31 EXPECT_EQ(config->streams.begin()->second.latencyMs, 2u);
32 }
33
TEST(ServiceConfigTest,MultipleStreams)34 TEST(ServiceConfigTest, MultipleStreams) {
35 char* argv[] = {"command", "--name", "service", "--stream",
36 "A:1:2", "--stream", "B:3:4"};
37 auto config =
38 parseServiceConfigFromCommandLine(sizeof(argv) / sizeof(argv[0]), argv);
39
40 ASSERT_TRUE(config);
41 EXPECT_EQ(config->name, "service");
42 EXPECT_EQ(config->streams.size(), 2);
43
44 ASSERT_TRUE(config->streams.count("A"));
45 const auto& streamA = config->streams["A"];
46 EXPECT_EQ(streamA.bufferSizeMs, 1u);
47 EXPECT_EQ(streamA.latencyMs, 2u);
48
49 ASSERT_TRUE(config->streams.count("B"));
50 const auto& streamB = config->streams["B"];
51 EXPECT_EQ(streamB.bufferSizeMs, 3u);
52 EXPECT_EQ(streamB.latencyMs, 4u);
53 }
54
TEST(ServiceConfigTest,NoStreamConfig)55 TEST(ServiceConfigTest, NoStreamConfig) {
56 char* argv[] = {"command", "--name", "service"};
57 auto config =
58 parseServiceConfigFromCommandLine(sizeof(argv) / sizeof(argv[0]), argv);
59
60 EXPECT_FALSE(config);
61 }
62