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