• 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 <gtest/gtest.h>
17 
18 #include "cert_manager_api.h"
19 
20 #include "cm_test_common.h"
21 
22 using namespace testing::ext;
23 using namespace CertmanagerTest;
24 namespace {
25 static uint32_t g_selfTokenId = 0;
26 static MockHapToken* g_MockHap = nullptr;
27 static constexpr uint32_t DEFAULT_INDATA_SIZE = 10;
28 static constexpr uint32_t DEFAULT_HANDLE_SIZE = 8;
29 
30 class CmUpdateTest : 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 CmUpdateTest::SetUpTestCase(void)
42 {
43     g_selfTokenId = GetSelfTokenID();
44     CmTestCommon::SetTestEnvironment(g_selfTokenId);
45 }
46 
TearDownTestCase(void)47 void CmUpdateTest::TearDownTestCase(void)
48 {
49     CmTestCommon::ResetTestEnvironment();
50 }
51 
SetUp()52 void CmUpdateTest::SetUp()
53 {
54     g_MockHap = new (std::nothrow) MockHapToken();
55 }
56 
TearDown()57 void CmUpdateTest::TearDown()
58 {
59     if (g_MockHap != nullptr) {
60         delete g_MockHap;
61         g_MockHap = nullptr;
62     }
63 }
64 
65 static const uint8_t g_inDataBuf[DEFAULT_INDATA_SIZE] = {0};
66 static const uint8_t g_handleBuf[DEFAULT_HANDLE_SIZE] = {0};
67 static const struct CmBlob g_inData = { DEFAULT_INDATA_SIZE, (uint8_t *)g_inDataBuf };
68 static const struct CmBlob g_handle = { DEFAULT_HANDLE_SIZE, (uint8_t *)g_handleBuf };
69 
70 /**
71 * @tc.name: CmUpdateTest001
72 * @tc.desc: Test CmIsAuthorizedApp handle is null
73 * @tc.type: FUNC
74 * @tc.require: AR000H0MIA /SR000H09NA
75 */
76 HWTEST_F(CmUpdateTest, CmUpdateTest001, TestSize.Level0)
77 {
78     struct CmBlob *handle = nullptr;
79     int32_t ret = CmUpdate(handle, &g_inData);
80     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
81 }
82 
83 /**
84  * @tc.name: CmUpdateTest002
85  * @tc.desc: Test CmIsAuthorizedApp handle size is 0
86  * @tc.type: FUNC
87  * @tc.require: AR000H0MIA /SR000H09NA
88  */
89 HWTEST_F(CmUpdateTest, CmUpdateTest002, TestSize.Level0)
90 {
91     struct CmBlob handle = { 0, (uint8_t *)g_handleBuf };
92     int32_t ret = CmUpdate(&handle, &g_inData);
93     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
94 }
95 
96 /**
97  * @tc.name: CmUpdateTest003
98  * @tc.desc: Test CmIsAuthorizedApp handle data is null
99  * @tc.type: FUNC
100  * @tc.require: AR000H0MIA /SR000H09NA
101  */
102 HWTEST_F(CmUpdateTest, CmUpdateTest003, TestSize.Level0)
103 {
104     struct CmBlob handle = { DEFAULT_HANDLE_SIZE, nullptr };
105     int32_t ret = CmUpdate(&handle, &g_inData);
106     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
107 }
108 
109 /**
110 * @tc.name: CmUpdateTest004
111 * @tc.desc: Test CmIsAuthorizedApp inData is null
112 * @tc.type: FUNC
113 * @tc.require: AR000H0MIA /SR000H09NA
114 */
115 HWTEST_F(CmUpdateTest, CmUpdateTest004, TestSize.Level0)
116 {
117     struct CmBlob *inData = nullptr;
118     int32_t ret = CmUpdate(&g_handle, inData);
119     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
120 }
121 
122 /**
123  * @tc.name: CmUpdateTest005
124  * @tc.desc: Test CmIsAuthorizedApp inData size is 0
125  * @tc.type: FUNC
126  * @tc.require: AR000H0MIA /SR000H09NA
127  */
128 HWTEST_F(CmUpdateTest, CmUpdateTest005, TestSize.Level0)
129 {
130     struct CmBlob inData = { 0, (uint8_t *)g_inDataBuf };
131     int32_t ret = CmUpdate(&g_handle, &inData);
132     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
133 }
134 
135 /**
136 * @tc.name: CmUpdateTest006
137 * @tc.desc: Test CmIsAuthorizedApp inData data is null
138 * @tc.type: FUNC
139 * @tc.require: AR000H0MIA /SR000H09NA
140 */
141 HWTEST_F(CmUpdateTest, CmUpdateTest006, TestSize.Level0)
142 {
143     struct CmBlob inData = { DEFAULT_INDATA_SIZE, nullptr };
144     int32_t ret = CmUpdate(&g_handle, &inData);
145     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
146 }
147 
148 /**
149 * @tc.name: CmUpdateTest007
150 * @tc.desc: Test CmIsAuthorizedApp handle not exist
151 * @tc.type: FUNC
152 * @tc.require: AR000H0MIA /SR000H09NA
153 */
154 HWTEST_F(CmUpdateTest, CmUpdateTest007, TestSize.Level0)
155 {
156     int32_t ret = CmUpdate(&g_handle, &g_inData);
157     EXPECT_EQ(ret, CMR_ERROR_NOT_EXIST);
158 }
159 } // end of namespace
160