• 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 #include <gtest/gtest.h>
17 
18 #include "hks_delete_test.h"
19 
20 #include "hks_api.h"
21 #include "hks_param.h"
22 #include "hks_test_api_performance.h"
23 #include "hks_test_common.h"
24 #include "hks_test_log.h"
25 #include "hks_type.h"
26 
27 using namespace testing::ext;
28 namespace {
29 #ifndef _CUT_AUTHENTICATE_
30 class HksDeleteTest : public testing::Test {
31 public:
32     static void SetUpTestCase(void);
33 
34     static void TearDownTestCase(void);
35 
36     void SetUp();
37 
38     void TearDown();
39 };
40 
SetUpTestCase(void)41 void HksDeleteTest::SetUpTestCase(void)
42 {
43 }
44 
TearDownTestCase(void)45 void HksDeleteTest::TearDownTestCase(void)
46 {
47 }
48 
SetUp()49 void HksDeleteTest::SetUp()
50 {
51     EXPECT_EQ(HksInitialize(), 0);
52 }
53 
TearDown()54 void HksDeleteTest::TearDown()
55 {
56 }
57 
58 const struct HksTestKeyExistParams g_testKeyExistParams[] = {
59     /* normal case */
60     { 0, HKS_SUCCESS, true, { true, DEFAULT_KEY_ALIAS_SIZE, true, DEFAULT_KEY_ALIAS_SIZE } },
61 };
62 
63 /**
64  * @tc.name: HksDeleteTest.HksDeleteTest001
65  * @tc.desc: The static function will return true;
66  * @tc.type: FUNC
67  */
68 HWTEST_F(HksDeleteTest, HksDeleteTest001, TestSize.Level1)
69 {
70     int32_t ret;
71     struct HksBlob *keyAlias = NULL;
72     if (g_testKeyExistParams[0].isGenKey) {
73         HKS_TEST_ASSERT(TestGenDefaultKeyAndGetAlias(&keyAlias) == 0);
74     } else {
75         ret = TestConstuctBlob(&keyAlias,
76                                g_testKeyExistParams[0].keyAliasParams.blobExist,
77                                g_testKeyExistParams[0].keyAliasParams.blobSize,
78                                g_testKeyExistParams[0].keyAliasParams.blobDataExist,
79                                g_testKeyExistParams[0].keyAliasParams.blobDataSize);
80         HKS_TEST_ASSERT(ret == 0);
81     }
82 
83     ret = HksDeleteKeyRun(keyAlias, 1);
84     HKS_TEST_ASSERT(ret == g_testKeyExistParams[0].expectResult);
85 
86     TestFreeBlob(&keyAlias);
87     ASSERT_TRUE(ret == 0);
88 }
89 
90 #endif /* _CUT_AUTHENTICATE_ */
91 }