• 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 "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_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, HksExistTest);
36 
37 /**
38  * @tc.setup: define a setup for test suit, format:"CalcMultiTest + SetUp"
39  * @return: true——setup success
40  */
HksExistTestSetUp()41 static BOOL HksExistTestSetUp()
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  */
HksExistTestTearDown()53 static BOOL HksExistTestTearDown()
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: HksExistTest.HksExistTest001
68  * @tc.desc: The static function will return true;
69  * @tc.type: FUNC
70  */
LITE_TEST_CASE(HksExistTest,HksExistTest001,Level1)71 LITE_TEST_CASE(HksExistTest, HksExistTest001, Level1)
72 {
73     int32_t ret;
74     struct HksBlob *keyAlias = NULL;
75     if (g_testKeyExistParams[0].isGenKey) {
76         TEST_ASSERT_TRUE(TestGenDefaultKeyAndGetAlias(&keyAlias) == 0);
77         ret = HksKeyExistRun(keyAlias, 1);
78         TEST_ASSERT_TRUE(ret == g_testKeyExistParams[0].expectResult);
79         TEST_ASSERT_TRUE(HksDeleteKey(keyAlias, NULL) == HKS_SUCCESS);
80     } else {
81         ret = TestConstuctBlob(&keyAlias,
82                                g_testKeyExistParams[0].keyAliasParams.blobExist,
83                                g_testKeyExistParams[0].keyAliasParams.blobSize,
84                                g_testKeyExistParams[0].keyAliasParams.blobDataExist,
85                                g_testKeyExistParams[0].keyAliasParams.blobDataSize);
86         TEST_ASSERT_TRUE(ret == 0);
87         ret = HksKeyExistRun(keyAlias, 1);
88         if (ret != g_testKeyExistParams[0].expectResult) {
89             HKS_TEST_LOG_I("HksKeyExistRun 2 failed, ret[%u] = %d", g_testKeyExistParams[0].testId, ret);
90         }
91         TEST_ASSERT_TRUE(ret == g_testKeyExistParams[0].expectResult);
92     }
93     TestFreeBlob(&keyAlias);
94     TEST_ASSERT_TRUE(ret == 0);
95 }
96 RUN_TEST_SUITE(HksExistTest);
97 #endif /* _CUT_AUTHENTICATE_ */
98 
99