• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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 <cstdio>
17 #include <gtest/gtest.h>
18 
19 #include "b_error/b_error.h"
20 
21 namespace OHOS::FileManagement::Backup {
22 class BErrorTest : public testing::Test {
23 public:
SetUpTestCase(void)24     static void SetUpTestCase(void) {};
TearDownTestCase()25     static void TearDownTestCase() {};
SetUp()26     void SetUp() {};
TearDown()27     void TearDown() {};
28 };
29 
30 /**
31  * @tc.number: SUB_backup_b_error_construction_0100
32  * @tc.name: b_error_construction_0100
33  * @tc.desc: Test function of construction interface for SUCCESS.
34  * @tc.size: MEDIUM
35  * @tc.type: FUNC
36  * @tc.level Level 0
37  * @tc.require: I6F3GV
38  */
39 HWTEST_F(BErrorTest, b_error_construction_0100, testing::ext::TestSize.Level0)
40 {
41     GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0100";
42     try {
43         BError be(BError::Codes::OK);
44     } catch (...) {
45         EXPECT_TRUE(false);
46         GTEST_LOG_(INFO) << "BErrorTest-an exception occurred by construction.";
47     }
48     GTEST_LOG_(INFO) << "BErrorTest-end b_error_construction_0100";
49 }
50 
51 /**
52  * @tc.number: SUB_backup_b_error_construction_0300
53  * @tc.name: b_error_construction_0300
54  * @tc.desc: Test function of construction interface for SUCCESS.
55  * @tc.size: MEDIUM
56  * @tc.type: FUNC
57  * @tc.level Level 0
58  * @tc.require: I6F3GV
59  */
60 HWTEST_F(BErrorTest, b_error_construction_0300, testing::ext::TestSize.Level0)
61 {
62     GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0300";
63     try {
64         std::string_view extraMsg;
65         BError be(BError::Codes::OK, extraMsg);
66     } catch (...) {
67         EXPECT_TRUE(false);
68         GTEST_LOG_(INFO) << "BErrorTest-an exception occurred by construction.";
69     }
70     GTEST_LOG_(INFO) << "BErrorTest-end b_error_construction_0300";
71 }
72 
73 /**
74  * @tc.number: SUB_backup_b_error_construction_0500
75  * @tc.name: b_error_construction_0500
76  * @tc.desc: Test function of construction interface for SUCCESS.
77  * @tc.size: MEDIUM
78  * @tc.type: FUNC
79  * @tc.level Level 0
80  * @tc.require: I6F3GV
81  */
82 HWTEST_F(BErrorTest, b_error_construction_0500, testing::ext::TestSize.Level0)
83 {
84     GTEST_LOG_(INFO) << "BErrorTest-begin b_error_construction_0500";
85     try {
86         throw BError(BError::Codes::UTILS_INVAL_JSON_ENTITY);
87         EXPECT_TRUE(false);
88     } catch (const BError &e) {
89     } catch (...) {
90         EXPECT_TRUE(false);
91         GTEST_LOG_(INFO) << "BErrorTest-an exception occurred by construction.";
92     }
93     GTEST_LOG_(INFO) << "BErrorTest-end b_error_construction_0500";
94 }
95 
96 /**
97  * @tc.number: SUB_backup_b_error_GetCode_0100
98  * @tc.name: b_error_GetCode_0100
99  * @tc.desc: Test function of GetCode interface for SUCCESS.
100  * @tc.size: MEDIUM
101  * @tc.type: FUNC
102  * @tc.level Level 0
103  * @tc.require: I6F3GV
104  */
105 HWTEST_F(BErrorTest, b_error_GetCode_0100, testing::ext::TestSize.Level0)
106 {
107     GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetCode_0100";
108     BError be(BError::Codes::OK);
109     int result = be.GetCode();
110     EXPECT_EQ(result, 0);
111     GTEST_LOG_(INFO) << "BErrorTest-end b_error_GetCode_0100";
112 }
113 
114 /**
115  * @tc.number: SUB_backup_b_error_GetRawCode_0100
116  * @tc.name: b_error_GetRawCode_0100
117  * @tc.desc: Test function of GetRawCode interface for SUCCESS.
118  * @tc.size: MEDIUM
119  * @tc.type: FUNC
120  * @tc.level Level 0
121  * @tc.require: I6F3GV
122  */
123 HWTEST_F(BErrorTest, b_error_GetRawCode_0100, testing::ext::TestSize.Level0)
124 {
125     GTEST_LOG_(INFO) << "BErrorTest-begin b_error_GetRawCode_0100";
126     BError be(BError::Codes::OK);
127     BError::Codes result = be.GetRawCode();
128     EXPECT_EQ(result, BError::Codes::OK);
129     GTEST_LOG_(INFO) << "BErrorTest-end b_error_GetRawCode_0100";
130 }
131 
132 /**
133  * @tc.number: SUB_backup_b_error_what_0100
134  * @tc.name: b_error_what_0100
135  * @tc.desc: Test function of what interface for SUCCESS.
136  * @tc.size: MEDIUM
137  * @tc.type: FUNC
138  * @tc.level Level 0
139  * @tc.require: I6F3GV
140  */
141 HWTEST_F(BErrorTest, b_error_what_0100, testing::ext::TestSize.Level0)
142 {
143     GTEST_LOG_(INFO) << "BErrorTest-begin b_error_what_0100";
144     BError be(BError::Codes::OK);
145     auto result = be.what();
146     EXPECT_NE(result, nullptr);
147     GTEST_LOG_(INFO) << "BErrorTest-end b_error_what_0100";
148 }
149 
150 /**
151  * @tc.number: SUB_backup_b_error_bool_0100
152  * @tc.name: b_error_bool_0100
153  * @tc.desc: Test function of bool interface for SUCCESS.
154  * @tc.size: MEDIUM
155  * @tc.type: FUNC
156  * @tc.level Level 0
157  * @tc.require: I6F3GV
158  */
159 HWTEST_F(BErrorTest, b_error_bool_0100, testing::ext::TestSize.Level0)
160 {
161     GTEST_LOG_(INFO) << "BErrorTest-begin b_error_bool_0100";
162     bool result = BError();
163     EXPECT_FALSE(result);
164     GTEST_LOG_(INFO) << "BErrorTest-end b_error_bool_0100";
165 }
166 
167 /**
168  * @tc.number: SUB_backup_b_error_int_0100
169  * @tc.name: b_error_int_0100
170  * @tc.desc: Test function of int interface for SUCCESS.
171  * @tc.size: MEDIUM
172  * @tc.type: FUNC
173  * @tc.level Level 0
174  * @tc.require: I6F3GV
175  */
176 HWTEST_F(BErrorTest, b_error_int_0100, testing::ext::TestSize.Level0)
177 {
178     GTEST_LOG_(INFO) << "BErrorTest-begin b_error_int_0100";
179     int result = BError();
180     EXPECT_EQ(result, 0);
181     GTEST_LOG_(INFO) << "BErrorTest-end b_error_int_0100";
182 }
183 } // namespace OHOS::FileManagement::Backup