1 /******************************************************************************
2  *
3  * Copyright (C) 2021 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19  */
20 #include <C2Config.h>
21 #include <C2ComponentFactory.h>
22 #include <gtest/gtest.h>
23 #include <log/log.h>
24 
25 using namespace android;
26 extern "C" ::C2ComponentFactory* CreateCodec2Factory();
27 extern "C" void DestroyCodec2Factory(::C2ComponentFactory* factory);
28 
29 class C2SoftCodecTest : public ::testing::Test {
30 public:
SetUp()31   void SetUp() override {
32     mFactory = CreateCodec2Factory();
33   }
34 
TearDown()35   void TearDown() override {
36     if (mFactory) {
37       DestroyCodec2Factory(mFactory);
38     }
39   }
40 
createComponent(std::shared_ptr<C2Component> * const comp)41   c2_status_t createComponent(
42         std::shared_ptr<C2Component>* const comp) {
43     if (!mFactory) {
44       return C2_NO_INIT;
45     }
46     return mFactory->createComponent(
47         kPlaceholderId, comp, std::default_delete<C2Component>());
48   }
49 
createInterface(std::shared_ptr<C2ComponentInterface> * const intf)50   c2_status_t createInterface(
51       std::shared_ptr<C2ComponentInterface>* const intf) {
52     if (!mFactory) {
53       return C2_NO_INIT;
54     }
55     return mFactory->createInterface(
56         kPlaceholderId, intf, std::default_delete<C2ComponentInterface>());
57   }
58 
getFactory()59   ::C2ComponentFactory *getFactory() { return mFactory; }
60 
61 private:
62   static constexpr ::c2_node_id_t kPlaceholderId = 0;
63 
64   ::C2ComponentFactory *mFactory;
65 };
66 
TEST_F(C2SoftCodecTest,PictureSizeInfoTest)67 TEST_F(C2SoftCodecTest, PictureSizeInfoTest) {
68   std::shared_ptr<C2ComponentInterface> interface;
69   c2_status_t status = createInterface(&interface);
70   ASSERT_EQ(status, C2_OK) << "Error in createInterface";
71   ASSERT_NE(interface, nullptr) << "interface is null";
72 
73   std::unique_ptr<C2StreamPictureSizeInfo::output> param =
74       std::make_unique<C2StreamPictureSizeInfo::output>();
75   std::vector<C2FieldSupportedValuesQuery> validValueInfos = {
76       C2FieldSupportedValuesQuery::Current(
77           C2ParamField(param.get(), &C2StreamPictureSizeInfo::width)),
78       C2FieldSupportedValuesQuery::Current(
79           C2ParamField(param.get(), &C2StreamPictureSizeInfo::height))};
80   status = interface->querySupportedValues_vb(validValueInfos, C2_MAY_BLOCK);
81   ASSERT_EQ(status, C2_OK) << "Error in querySupportedValues_vb";
82   ASSERT_EQ(validValueInfos.size(), 2) << "querySupportedValues_vb didn't return 2 values";
83 
84   ASSERT_EQ(validValueInfos[0].values.range.max.ref<uint32_t>(), 1920)
85       << "Incorrect maximum value for width";
86   ASSERT_EQ(validValueInfos[1].values.range.max.ref<uint32_t>(), 1920)
87       << "Incorrect maximum value for height";
88   ASSERT_EQ(validValueInfos[0].values.range.min.ref<uint32_t>(), 2)
89       << "Incorrect minimum value for width";
90   ASSERT_EQ(validValueInfos[1].values.range.min.ref<uint32_t>(), 2)
91       << "Incorrect minimum value for height";
92   ASSERT_EQ(validValueInfos[0].values.range.step.ref<uint32_t>(), 2)
93       << "Incorrect alignment value for width";
94   ASSERT_EQ(validValueInfos[1].values.range.step.ref<uint32_t>(), 2)
95       << "Incorrect alignment value for height";
96 
97   return;
98 }
99 
main(int argc,char ** argv)100 int main(int argc, char** argv) {
101   ::testing::InitGoogleTest(&argc, argv);
102   int status = RUN_ALL_TESTS();
103   ALOGV("Test result = %d\n", status);
104   return status;
105 }
106