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 #include "hctest.h"
18 #include "hi_watchdog.h"
19 #include "hks_delete_test.h"
20
21 #include "hks_api.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, HksDeleteTest);
35
36 /**
37 * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
38 * @return: true——setup success
39 */
HksDeleteTestSetUp()40 static BOOL HksDeleteTestSetUp()
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 */
HksDeleteTestTearDown()52 static BOOL HksDeleteTestTearDown()
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: HksDeleteTest.HksDeleteTest001
67 * @tc.desc: The static function will return true;
68 * @tc.type: FUNC
69 */
LITE_TEST_CASE(HksDeleteTest,HksDeleteTest001,Level1)70 LITE_TEST_CASE(HksDeleteTest, HksDeleteTest001, Level1)
71 {
72 int32_t ret;
73 struct HksBlob *keyAlias = NULL;
74 if (g_testKeyExistParams[0].isGenKey) {
75 HKS_TEST_ASSERT(TestGenDefaultKeyAndGetAlias(&keyAlias) == 0);
76 } else {
77 ret = TestConstuctBlob(&keyAlias,
78 g_testKeyExistParams[0].keyAliasParams.blobExist,
79 g_testKeyExistParams[0].keyAliasParams.blobSize,
80 g_testKeyExistParams[0].keyAliasParams.blobDataExist,
81 g_testKeyExistParams[0].keyAliasParams.blobDataSize);
82 HKS_TEST_ASSERT(ret == 0);
83 }
84
85 ret = HksDeleteKeyRun(keyAlias, 1);
86 HKS_TEST_ASSERT(ret == g_testKeyExistParams[0].expectResult);
87
88 TestFreeBlob(&keyAlias);
89 TEST_ASSERT_TRUE(ret == 0);
90 }
91
92 RUN_TEST_SUITE(HksDeleteTest);
93 #endif /* _CUT_AUTHENTICATE_ */
94
95