• 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 constexpr uint32_t DEFAULT_INDATA_SIZE = 10;
26 static constexpr uint32_t DEFAULT_HANDLE_SIZE = 8;
27 
28 class CmUpdateTest : public testing::Test {
29 public:
30     static void SetUpTestCase(void);
31 
32     static void TearDownTestCase(void);
33 
34     void SetUp();
35 
36     void TearDown();
37 };
38 
SetUpTestCase(void)39 void CmUpdateTest::SetUpTestCase(void)
40 {
41     SetATPermission();
42 }
43 
TearDownTestCase(void)44 void CmUpdateTest::TearDownTestCase(void)
45 {
46 }
47 
SetUp()48 void CmUpdateTest::SetUp()
49 {
50 }
51 
TearDown()52 void CmUpdateTest::TearDown()
53 {
54 }
55 
56 static const uint8_t g_inDataBuf[DEFAULT_INDATA_SIZE] = {0};
57 static const uint8_t g_handleBuf[DEFAULT_HANDLE_SIZE] = {0};
58 static const struct CmBlob g_inData = { DEFAULT_INDATA_SIZE, (uint8_t *)g_inDataBuf };
59 static const struct CmBlob g_handle = { DEFAULT_HANDLE_SIZE, (uint8_t *)g_handleBuf };
60 
61 /**
62 * @tc.name: CmUpdateTest001
63 * @tc.desc: Test CmIsAuthorizedApp handle is null
64 * @tc.type: FUNC
65 * @tc.require: AR000H0MIA /SR000H09NA
66 */
67 HWTEST_F(CmUpdateTest, CmUpdateTest001, TestSize.Level0)
68 {
69     struct CmBlob *handle = nullptr;
70     int32_t ret = CmUpdate(handle, &g_inData);
71     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
72 }
73 
74 /**
75  * @tc.name: CmUpdateTest002
76  * @tc.desc: Test CmIsAuthorizedApp handle size is 0
77  * @tc.type: FUNC
78  * @tc.require: AR000H0MIA /SR000H09NA
79  */
80 HWTEST_F(CmUpdateTest, CmUpdateTest002, TestSize.Level0)
81 {
82     struct CmBlob handle = { 0, (uint8_t *)g_handleBuf };
83     int32_t ret = CmUpdate(&handle, &g_inData);
84     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
85 }
86 
87 /**
88  * @tc.name: CmUpdateTest003
89  * @tc.desc: Test CmIsAuthorizedApp handle data is null
90  * @tc.type: FUNC
91  * @tc.require: AR000H0MIA /SR000H09NA
92  */
93 HWTEST_F(CmUpdateTest, CmUpdateTest003, TestSize.Level0)
94 {
95     struct CmBlob handle = { DEFAULT_HANDLE_SIZE, nullptr };
96     int32_t ret = CmUpdate(&handle, &g_inData);
97     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
98 }
99 
100 /**
101 * @tc.name: CmUpdateTest004
102 * @tc.desc: Test CmIsAuthorizedApp inData is null
103 * @tc.type: FUNC
104 * @tc.require: AR000H0MIA /SR000H09NA
105 */
106 HWTEST_F(CmUpdateTest, CmUpdateTest004, TestSize.Level0)
107 {
108     struct CmBlob *inData = nullptr;
109     int32_t ret = CmUpdate(&g_handle, inData);
110     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
111 }
112 
113 /**
114  * @tc.name: CmUpdateTest005
115  * @tc.desc: Test CmIsAuthorizedApp inData size is 0
116  * @tc.type: FUNC
117  * @tc.require: AR000H0MIA /SR000H09NA
118  */
119 HWTEST_F(CmUpdateTest, CmUpdateTest005, TestSize.Level0)
120 {
121     struct CmBlob inData = { 0, (uint8_t *)g_inDataBuf };
122     int32_t ret = CmUpdate(&g_handle, &inData);
123     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
124 }
125 
126 /**
127 * @tc.name: CmUpdateTest006
128 * @tc.desc: Test CmIsAuthorizedApp inData data is null
129 * @tc.type: FUNC
130 * @tc.require: AR000H0MIA /SR000H09NA
131 */
132 HWTEST_F(CmUpdateTest, CmUpdateTest006, TestSize.Level0)
133 {
134     struct CmBlob inData = { DEFAULT_INDATA_SIZE, nullptr };
135     int32_t ret = CmUpdate(&g_handle, &inData);
136     EXPECT_EQ(ret, CMR_ERROR_INVALID_ARGUMENT);
137 }
138 
139 /**
140 * @tc.name: CmUpdateTest007
141 * @tc.desc: Test CmIsAuthorizedApp handle not exist
142 * @tc.type: FUNC
143 * @tc.require: AR000H0MIA /SR000H09NA
144 */
145 HWTEST_F(CmUpdateTest, CmUpdateTest007, TestSize.Level0)
146 {
147     int32_t ret = CmUpdate(&g_handle, &g_inData);
148     EXPECT_EQ(ret, CMR_ERROR_NOT_EXIST);
149 }
150 } // end of namespace
151