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