1 /*
2  * Copyright (c) 2024, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 3-Clause Clear License
5  * and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
6  * License was not distributed with this source code in the LICENSE file, you
7  * can obtain it at www.aomedia.org/license/software-license/bsd-3-c-c. If the
8  * Alliance for Open Media Patent License 1.0 was not distributed with this
9  * source code in the PATENTS file, you can obtain it at
10  * www.aomedia.org/license/patent.
11  */
12 #include "iamf/cli/renderer/loudspeakers_renderer.h"
13 
14 #include <cstddef>
15 
16 #include "absl/status/status_matchers.h"
17 #include "absl/status/statusor.h"
18 #include "absl/strings/string_view.h"
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 
22 namespace iamf_tools {
23 namespace {
24 
25 using ::absl_testing::IsOk;
26 
27 constexpr absl::string_view kFOAInputKey = "A1";
28 constexpr size_t kExpectedFOAMatrixRows = 4;
29 
30 constexpr absl::string_view kStereoOutputKey = "0+2+0";
31 constexpr size_t kExpectedStereoColumns = 2;
32 
33 constexpr absl::string_view kUnknownInputKey = "UNKNOWN";
34 constexpr absl::string_view kUnknownOutputKey = "UNKNOWN";
35 
TEST(LookupPrecomputedGains,SucceedsForKnownPrecomputedGains)36 TEST(LookupPrecomputedGains, SucceedsForKnownPrecomputedGains) {
37   EXPECT_THAT(LookupPrecomputedGains(kFOAInputKey, kStereoOutputKey), IsOk());
38 }
39 
TEST(LookupPrecomputedGains,FirstDimensionAgreesWithInputKey)40 TEST(LookupPrecomputedGains, FirstDimensionAgreesWithInputKey) {
41   const auto gains = LookupPrecomputedGains(kFOAInputKey, kStereoOutputKey);
42   ASSERT_THAT(gains, IsOk());
43 
44   EXPECT_EQ(gains->size(), kExpectedFOAMatrixRows);
45 }
46 
TEST(LookupPrecomputedGains,SecondDimensionAgreesWithOutputKey)47 TEST(LookupPrecomputedGains, SecondDimensionAgreesWithOutputKey) {
48   const auto gains = LookupPrecomputedGains(kFOAInputKey, kStereoOutputKey);
49   ASSERT_THAT(gains, IsOk());
50   ASSERT_FALSE(gains->empty());
51 
52   EXPECT_EQ(gains->at(0).size(), kExpectedStereoColumns);
53 }
54 
TEST(LookupPrecomputedGains,ReturnsErrorWhenInputKeyIsUnknown)55 TEST(LookupPrecomputedGains, ReturnsErrorWhenInputKeyIsUnknown) {
56   EXPECT_FALSE(LookupPrecomputedGains(kUnknownInputKey, kStereoOutputKey).ok());
57 }
58 
TEST(LookupPrecomputedGains,ReturnsErrorWhenOutputKeyIsUnknown)59 TEST(LookupPrecomputedGains, ReturnsErrorWhenOutputKeyIsUnknown) {
60   EXPECT_FALSE(LookupPrecomputedGains(kFOAInputKey, kUnknownOutputKey).ok());
61 }
62 
63 }  // namespace
64 }  // namespace iamf_tools
65