1 /*
2 * Copyright (C) 2021 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 #ifndef _CUT_AUTHENTICATE_
17
18 #include "hks_exist_test.h"
19
20 #include "hctest.h"
21 #include "hi_watchdog.h"
22 #include "hks_api.h"
23 #include "hks_param.h"
24 #include "hks_test_adapt_for_de.h"
25 #include "hks_test_api_performance.h"
26 #include "hks_test_common.h"
27 #include "hks_test_log.h"
28 #include "hks_type.h"
29
30 /*
31 * @tc.register: register a test suit named "CalcMultiTest"
32 * @param: test subsystem name
33 * @param: c_example module name
34 * @param: CalcMultiTest test suit name
35 */
36 LITE_TEST_SUIT(husk, huks_lite, HksExistTest);
37
38 /**
39 * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
40 * @return: true——setup success
41 */
HksExistTestSetUp()42 static BOOL HksExistTestSetUp()
43 {
44 LiteTestPrint("setup\n");
45 hi_watchdog_disable();
46 TEST_ASSERT_TRUE(HksInitialize() == 0);
47 return TRUE;
48 }
49
50 /**
51 * @tc.teardown: define a setup for test suit, format:"CalcMultiTest + TearDown"
52 * @return: true——teardown success
53 */
HksExistTestTearDown()54 static BOOL HksExistTestTearDown()
55 {
56 LiteTestPrint("tearDown\n");
57 hi_watchdog_enable();
58 return TRUE;
59 }
60
61
62 static const struct HksTestKeyExistParams g_testKeyExistParams[] = {
63 /* normal case */
64 { 0, HKS_SUCCESS, true, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE } },
65 };
66
67 /**
68 * @tc.name: HksExistTest.HksExistTest001
69 * @tc.desc: The static function will return true;
70 * @tc.type: FUNC
71 */
LITE_TEST_CASE(HksExistTest,HksExistTest001,Level1)72 LITE_TEST_CASE(HksExistTest, HksExistTest001, Level1)
73 {
74 int32_t ret;
75 struct HksBlob *keyAlias = NULL;
76 if (g_testKeyExistParams[0].isGenKey) {
77 TEST_ASSERT_TRUE(TestGenDefaultKeyAndGetAlias(&keyAlias) == 0);
78 ret = HksKeyExistRun(keyAlias, 1);
79 TEST_ASSERT_TRUE(ret == g_testKeyExistParams[0].expectResult);
80 TEST_ASSERT_TRUE(HksDeleteKeyForDe(keyAlias, NULL) == HKS_SUCCESS);
81 } else {
82 ret = TestConstuctBlob(&keyAlias,
83 g_testKeyExistParams[0].keyAliasParams.blobExist,
84 g_testKeyExistParams[0].keyAliasParams.blobSize,
85 g_testKeyExistParams[0].keyAliasParams.blobDataExist,
86 g_testKeyExistParams[0].keyAliasParams.blobDataSize);
87 TEST_ASSERT_TRUE(ret == 0);
88 ret = HksKeyExistRun(keyAlias, 1);
89 if (ret != g_testKeyExistParams[0].expectResult) {
90 HKS_TEST_LOG_I("HksKeyExistRun 2 failed, ret[%u] = %d", g_testKeyExistParams[0].testId, ret);
91 }
92 TEST_ASSERT_TRUE(ret == g_testKeyExistParams[0].expectResult);
93 }
94 TestFreeBlob(&keyAlias);
95 TEST_ASSERT_TRUE(ret == 0);
96 }
97 RUN_TEST_SUITE(HksExistTest);
98 #endif /* _CUT_AUTHENTICATE_ */
99
100