• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
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 
16 #include <gtest/gtest.h>
17 #include <vector>
18 #include <unistd.h>
19 
20 #include "v1_0/ihuks.h"
21 #include "v1_0/ihuks_types.h"
22 #include "huks_sa_type.h"
23 #include "huks_hdi_test_util.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 namespace Unittest::HuksHdiTest {
28 static struct IHuks *g_huksHdiProxy = nullptr;
29 class HuksHdiApiCompatTest : public testing::Test {
30 public:
31     static void SetUpTestCase(void);
32 
33     static void TearDownTestCase(void);
34 
35     void SetUp();
36 
37     void TearDown();
38 };
39 
SetUpTestCase(void)40 void HuksHdiApiCompatTest::SetUpTestCase(void)
41 {
42     g_huksHdiProxy = IHuksGetInstance("hdi_service", true);
43     int32_t ret = g_huksHdiProxy->ModuleInit(g_huksHdiProxy);
44     HUKS_TEST_LOG_I("ModuleInit = %d", ret);
45 }
46 
TearDownTestCase(void)47 void HuksHdiApiCompatTest::TearDownTestCase(void)
48 {
49     if (g_huksHdiProxy != nullptr) {
50         IHuksReleaseInstance("hdi_service", g_huksHdiProxy, true);
51         g_huksHdiProxy = nullptr;
52     }
53 }
54 
SetUp()55 void HuksHdiApiCompatTest::SetUp()
56 {
57 }
58 
TearDown()59 void HuksHdiApiCompatTest::TearDown()
60 {
61 }
62 
63 /**
64  * @tc.name: HuksHdiApiCompatTest.HdiFuncCompatibilityTest001
65  * @tc.desc: Test hdi func pointer params compatibility;
66  * @tc.require:issueI77AT9
67  * @tc.type: FUNC
68  */
69 HWTEST_F(HuksHdiApiCompatTest, HdiFuncCompatibilityTest001, TestSize.Level0)
70 {
71     ASSERT_EQ((int32_t)HUKS_SUCCESS, 0);
72     ASSERT_EQ((int32_t)HUKS_FAILURE, -1);
73     ASSERT_EQ((int32_t)HUKS_ERROR_NULL_POINTER, -14);
74     ASSERT_EQ((int32_t)HUKS_ERROR_MALLOC_FAIL, -21);
75     ASSERT_EQ((int32_t)HKS_CHIPSET_PLATFORM_DECRYPT_SCENE_TA_TO_TA, 1);
76 }
77 
78 /**
79  * @tc.name: HuksHdiApiCompatTest.HdiFuncCompatibilityTest002
80  * @tc.desc: Test hdi func pointer params compatibility;
81  * @tc.require:issueI77AT9
82  * @tc.type: FUNC
83  */
84 HWTEST_F(HuksHdiApiCompatTest, HdiFuncCompatibilityTest002, TestSize.Level0)
85 {
86     struct HksBlob blob = {0};
87     ASSERT_EQ(blob.data, nullptr);
88     ASSERT_EQ(blob.size, 0);
89 }
90 
91 /**
92  * @tc.name: HuksHdiApiCompatTest.HdiFuncCompatibilityTest003
93  * @tc.desc: Test hdi func pointer params compatibility;
94  * @tc.require:issueI77AT9
95  * @tc.type: FUNC
96  */
97 HWTEST_F(HuksHdiApiCompatTest, HdiFuncCompatibilityTest003, TestSize.Level0)
98 {
99     struct HksParam param = {0};
100     ASSERT_EQ(param.tag, 0);
101     ASSERT_EQ(param.boolParam, false);
102     ASSERT_EQ(param.int32Param, 0);
103     ASSERT_EQ(param.uint32Param, 0);
104     ASSERT_EQ(param.uint64Param, 0);
105     ASSERT_EQ(param.blob.data, nullptr);
106     ASSERT_EQ(param.blob.size, 0);
107 }
108 
109 /**
110  * @tc.name: HuksHdiApiCompatTest.HdiFuncCompatibilityTest004
111  * @tc.desc: Test hdi func pointer params compatibility;
112  * @tc.require:issueI77AT9
113  * @tc.type: FUNC
114  */
115 HWTEST_F(HuksHdiApiCompatTest, HdiFuncCompatibilityTest004, TestSize.Level0)
116 {
117     struct HksParamSet paramSet = {0};
118     ASSERT_EQ(paramSet.paramSetSize, 0);
119     ASSERT_EQ(paramSet.paramsCnt, 0);
120 }
121 }