2 * Copyright (c) 2024 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <gtest/gtest.h>
20 #include <halcc/hal-compatibility-checker.h>
21 #include "../../halcc/src/halcc-object.h"
22 #include "../../halcc/src/halcc-parser.h"
26 static char g_manifest_xml[] =
27 "<manifest version=\"1.0\" type=\"platform\" level=\"7\">"
29 " <name>hal.device.display</name>"
30 " <version>1.5</version>"
31 " <transport>passthrough</transport>"
33 " <name>hal_backend_device_display_data</name>"
37 " <name>hal.device.board</name>"
38 " <version>1.0</version>"
39 " <transport>passthrough</transport>"
41 " <name>hal_backend_device_board_data</name>"
45 " <name>hal.tdm</name>"
46 " <version>1.0</version>"
47 " <transport>passthrough</transport>"
49 " <name>hal_backend_tdm_data</name>"
55 " <name>hal.something</name>"
56 " <version>2.34</version>"
57 " <transport>passthrough</transport>"
59 " <name>hal_backend_something_data</name>"
63 " <name>hal.test</name>"
64 " <version>4.8</version>"
65 " <transport>passthrough</transport>"
67 " <name>hal_backend_test_data</name>"
72 class HalccObjectTest : public ::testing::Test
75 static void SetUpTestSuite() {
78 ret = halcc_manifest_new(&g_manifest);
81 ret = halcc_parse_string(g_manifest_xml, sizeof(g_manifest_xml), g_manifest);
84 ret = halcc_manifest_find_hal(g_manifest, "hal.test", 4, 8, &g_hal);
88 static void TearDownTestSuite() {
89 halcc_manifest_free(g_manifest);
94 void SetUp() override {
98 void TearDown() override {
102 static halcc_manifest *g_manifest;
103 static halcc_hal *g_hal;
104 static halcc_interface *g_interface;
107 halcc_manifest* HalccObjectTest::g_manifest = NULL;
108 halcc_hal* HalccObjectTest::g_hal = NULL;
109 halcc_interface* HalccObjectTest::g_interface = NULL;
111 TEST_F(HalccObjectTest, manifest_get_type)
113 halcc_manifest_type_e type;
116 ret = halcc_manifest_get_type(g_manifest, &type);
118 ASSERT_EQ(type, HALCC_MANIFEST_TYPE_HAL_API);
121 TEST_F(HalccObjectTest, manifest_get_version)
126 ret = halcc_manifest_get_version(g_manifest, &major, &minor);
132 TEST_F(HalccObjectTest, manifest_get_level)
137 ret = halcc_manifest_get_level(g_manifest, &level);
142 TEST_F(HalccObjectTest, manifest_find_hal_success)
144 halcc_hal *hal = NULL;
147 ret = halcc_manifest_find_hal(g_manifest, "hal.device.display", 1, 5, &hal);
151 TEST_F(HalccObjectTest, manifest_find_hal_fail)
153 halcc_hal *hal = NULL;
156 ret = halcc_manifest_find_hal(g_manifest, "hal.device.display", 1, 4, &hal);
157 ASSERT_EQ(ret, -ENOTSUP);
159 ret = halcc_manifest_find_hal(g_manifest, "hal.device.display", 1, 6, &hal);
160 ASSERT_EQ(ret, -ENOTSUP);
162 ret = halcc_manifest_find_hal(g_manifest, "hal.device.display", 2, 4, &hal);
163 ASSERT_EQ(ret, -ENOTSUP);
166 TEST_F(HalccObjectTest, manifest_find_hal_backward_compatible_success)
168 halcc_hal *hal = NULL;
171 ret = halcc_manifest_find_hal_backward_compatible(g_manifest, "hal.device.display", 1, 5, &hal);
174 ret = halcc_manifest_find_hal_backward_compatible(g_manifest, "hal.device.display", 1, 6, &hal);
177 ret = halcc_manifest_find_hal_backward_compatible(g_manifest, "hal.device.display", 1, 100, &hal);
181 TEST_F(HalccObjectTest, manifest_find_hal_backward_compatible_fail)
183 halcc_hal *hal = NULL;
186 ret = halcc_manifest_find_hal_backward_compatible(g_manifest, "hal.device.display", 1, 4, &hal);
187 ASSERT_EQ(ret, -ENOTSUP);
189 ret = halcc_manifest_find_hal_backward_compatible(g_manifest, "hal.device.display", 2, 4, &hal);
190 ASSERT_EQ(ret, -ENOTSUP);
192 ret = halcc_manifest_find_hal_backward_compatible(g_manifest, "hal.device.display", 2, 5, &hal);
193 ASSERT_EQ(ret, -ENOTSUP);
196 TEST_F(HalccObjectTest, manifest_find_hal_steal_success)
198 halcc_hal *hal = NULL;
199 const char *hal_name;
203 ret = halcc_manifest_steal_hal(g_manifest, "hal.something", 2, 34, &hal);
206 ret = halcc_hal_get_name(hal, &hal_name);
208 ASSERT_STREQ(hal_name, "hal.something");
210 ret = halcc_hal_get_version(hal, &major, &minor, NULL);
213 ASSERT_EQ(minor, 34);
215 // Shouldn't be there
216 ret = halcc_manifest_find_hal(g_manifest, "hal.something", 2, 34, &hal);
217 ASSERT_EQ(ret, -ENOTSUP);
219 ret = halcc_manifest_add_hal(g_manifest, hal);
222 ret = halcc_manifest_find_hal(g_manifest, "hal.something", 2, 34, &hal);
225 ret = halcc_hal_get_name(hal, &hal_name);
227 ASSERT_STREQ(hal_name, "hal.something");
229 ret = halcc_hal_get_version(hal, &major, &minor, NULL);
232 ASSERT_EQ(minor, 34);