• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "huks_nullptr_test.h"
17 #include <gtest/gtest.h>
18 
19 using namespace testing::ext;
20 namespace Unittest::NullPtrTest{
21 class HuksNullptrTest : public testing::Test{
22 public:
23     static void SetUpTestCase(void);
24 
25     static void TearDownTestCase(void);
26 
27     void SetUp();
28 
29     void TearDown();
30 };
31 
SetUpTestCase(void)32 void HuksNullptrTest::SetUpTestCase(void)
33 {
34 }
35 
TearDownTestCase(void)36 void HuksNullptrTest::TearDownTestCase(void)
37 {
38 }
39 
SetUp()40 void HuksNullptrTest::SetUp()
41 {
42 
43 }
44 
TearDown()45 void HuksNullptrTest::TearDown()
46 {
47 }
48 
49 static struct OH_Huks_ParamSet *paramSetNullptr=nullptr;
50 static struct OH_Huks_Param *paramNullptr=nullptr;
51 static struct OH_Huks_Blob *blobNullptr=nullptr;
52 static struct OH_Huks_CertChain *certChainNullptr=nullptr;
53 
54 /**
55  * @tc.name: HuksNullptrTest.Security_HUKS_NAPI_nullptr_0100
56  * @tc.desc: use nullptr.
57  * @tc.type: FUNC
58  */
59 HWTEST_F(HuksNullptrTest, Security_HUKS_NAPI_nullptr_0100, TestSize.Level0)
60 {
61     OH_Huks_Result ret=OH_Huks_InitParamSet(&paramSetNullptr);
62     EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
63 
64     ret=OH_Huks_AddParams(paramSetNullptr,paramNullptr,0);
65     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
66 
67     ret=OH_Huks_BuildParamSet(&paramSetNullptr);
68     EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
69 
70     ret=OH_Huks_CopyParamSet(paramSetNullptr,0,&paramSetNullptr);
71     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
72 
73     ret=OH_Huks_GetParam(paramSetNullptr,0,&paramNullptr);
74     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
75 
76     ret=OH_Huks_FreshParamSet(paramSetNullptr,0);
77     EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
78 
79     ret=OH_Huks_IsParamSetTagValid(paramSetNullptr);
80     EXPECT_EQ(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
81 
82     ret=OH_Huks_IsParamSetValid(paramSetNullptr,0);
83     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
84 
85     struct OH_Huks_Param baseParam = { .tag = OH_HUKS_TAG_ALGORITHM, .uint64Param = (uint64_t)1 };
86     struct OH_Huks_Param otherParam = { .tag = OH_HUKS_TAG_ALGORITHM, .uint64Param = (uint64_t)2 };
87     ret=OH_Huks_CheckParamMatch(&baseParam,&otherParam);
88     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
89 
90     ret=OH_Huks_GetSdkVersion(blobNullptr);
91     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
92 
93     ret=OH_Huks_GenerateKeyItem(blobNullptr,paramSetNullptr,paramSetNullptr);
94     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
95 
96     ret=OH_Huks_ImportWrappedKeyItem(blobNullptr,blobNullptr,paramSetNullptr,blobNullptr);
97     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
98 
99     ret=OH_Huks_ExportPublicKeyItem(blobNullptr,paramSetNullptr,blobNullptr);
100     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
101 
102     ret=OH_Huks_DeleteKeyItem(blobNullptr,paramSetNullptr);
103     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
104 
105     ret=OH_Huks_GetKeyItemParamSet(blobNullptr,paramSetNullptr,paramSetNullptr);
106     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
107 
108     ret=OH_Huks_IsKeyItemExist(blobNullptr,paramSetNullptr);
109     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
110 
111     ret=OH_Huks_AttestKeyItem(blobNullptr,paramSetNullptr,certChainNullptr);
112     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
113 
114     ret=OH_Huks_InitSession(blobNullptr,paramSetNullptr,blobNullptr,blobNullptr);
115     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
116 
117     ret=OH_Huks_UpdateSession(blobNullptr,paramSetNullptr,blobNullptr,blobNullptr);
118     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
119 
120     ret=OH_Huks_FinishSession(blobNullptr,paramSetNullptr,blobNullptr,blobNullptr);
121     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
122 
123     ret=OH_Huks_AbortSession(blobNullptr,paramSetNullptr);
124     EXPECT_NE(ret.errorCode, OH_HUKS_SUCCESS) << "this case failed.";
125 }
126 };
127