• 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 <gtest/gtest.h>
17 
18 #include "b_file_info.h"
19 #include "parcel.h"
20 
21 namespace OHOS::FileManagement::Backup {
22 using namespace std;
23 using namespace testing;
24 
25 namespace {
26 const string BUNDLE_NAME = "com.example.app2backup";
27 const string FILE_NAME = "1.tar";
28 } // namespace
29 
30 class BFileInfoTest : public testing::Test {
31 public:
SetUpTestCase(void)32     static void SetUpTestCase(void) {};
TearDownTestCase()33     static void TearDownTestCase() {};
SetUp()34     void SetUp() override {};
TearDown()35     void TearDown() override {};
36 };
37 
38 /**
39  * @tc.number: SUB_BFile_Info_Marshalling_0100
40  * @tc.name: SUB_BFile_Info_Marshalling_0100
41  * @tc.desc: Test function of Marshalling interface for SUCCESS.
42  * @tc.size: MEDIUM
43  * @tc.type: FUNC
44  * @tc.level Level 1
45  * @tc.require: I6F3GV
46  */
47 HWTEST_F(BFileInfoTest, SUB_BFile_Info_Marshalling_0100, testing::ext::TestSize.Level1)
48 {
49     GTEST_LOG_(INFO) << "BFileInfoTest-begin SUB_BFile_Info_Marshalling_0100";
50     BFileInfo bFileInfo(BUNDLE_NAME, FILE_NAME, -1);
51     Parcel parcel;
52     // marshalling
53     EXPECT_EQ(bFileInfo.Marshalling(parcel), true);
54     // unmarshalling
55     auto infoPtr = bFileInfo.Unmarshalling(parcel);
56     EXPECT_NE(infoPtr, nullptr);
57     GTEST_LOG_(INFO) << "BFileInfoTest-end SUB_BFile_Info_Marshalling_0100";
58 }
59 
60 /**
61  * @tc.number: SUB_BFile_Info_ReadFromParcel_0100
62  * @tc.name: SUB_BFile_Info_ReadFromParcel_0100
63  * @tc.desc: Test function of ReadFromParcel interface for SUCCESS.
64  * @tc.size: MEDIUM
65  * @tc.type: FUNC
66  * @tc.level Level 1
67  * @tc.require: I6F3GV
68  */
69 HWTEST_F(BFileInfoTest, SUB_BFile_Info_ReadFromParcel_0100, testing::ext::TestSize.Level1)
70 {
71     GTEST_LOG_(INFO) << "BFileInfoTest-begin SUB_BFile_Info_ReadFromParcel_0100";
72     BFileInfo bFileInfo(BUNDLE_NAME, FILE_NAME, -1);
73     Parcel parcel;
74     // marshalling
75     EXPECT_EQ(bFileInfo.Marshalling(parcel), true);
76 
77     // ReadFromParcel
78     BFileInfo bFileInfoTemp {"", "", -1};
79     bFileInfoTemp.ReadFromParcel(parcel);
80     GTEST_LOG_(INFO) << "BFileInfoTest-end SUB_BFile_Info_ReadFromParcel_0100";
81 }
82 
83 /**
84  * @tc.number: SUB_BFile_Info_Unmarshalling_0100
85  * @tc.name: SUB_BFile_Info_Unmarshalling_0100
86  * @tc.desc: Test function of Unmarshalling interface for SUCCESS.
87  * @tc.size: MEDIUM
88  * @tc.type: FUNC
89  * @tc.level Level 1
90  * @tc.require: I6F3GV
91  */
92 HWTEST_F(BFileInfoTest, SUB_BFile_Info_Unmarshalling_0100, testing::ext::TestSize.Level1)
93 {
94     GTEST_LOG_(INFO) << "BFileInfoTest-begin SUB_BFile_Info_Unmarshalling_0100";
95     BFileInfo bFileInfo(BUNDLE_NAME, FILE_NAME, -1);
96     Parcel parcel;
97     // marshalling
98     EXPECT_EQ(bFileInfo.Marshalling(parcel), true);
99     // unmarshalling
100     BFileInfo bFileInfoTemp {"", "", -1};
101     auto infoPtr = bFileInfoTemp.Unmarshalling(parcel);
102     EXPECT_NE(infoPtr, nullptr);
103     GTEST_LOG_(INFO) << "BFileInfoTest-end SUB_BFile_Info_Unmarshalling_0100";
104 }
105 
106 /**
107  * @tc.number: SUB_BFile_Info_0200
108  * @tc.name: SUB_BFile_Info_0200
109  * @tc.desc: 分支测试
110  * @tc.size: MEDIUM
111  * @tc.type: FUNC
112  * @tc.level Level 1
113  * @tc.require: I6F3GV
114  */
115 HWTEST_F(BFileInfoTest, SUB_BFile_Info_0200, testing::ext::TestSize.Level1)
116 {
117     GTEST_LOG_(INFO) << "BFileInfoTest-begin SUB_BFile_Info_0200";
118     BFileInfo bFileInfo(BUNDLE_NAME, FILE_NAME, -1);
119     Parcel parcel;
120     ResetParcelState();
121     MockWriteUint32(false);
122     EXPECT_EQ(bFileInfo.Marshalling(parcel), false);
123     MockWriteUint32(true);
124     MockWriteString(false, 1);
125     EXPECT_EQ(bFileInfo.Marshalling(parcel), false);
126     EXPECT_EQ(bFileInfo.Marshalling(parcel), false);
127 
128     ResetParcelState();
129     MockWriteUint32(false);
130     EXPECT_EQ(bFileInfo.ReadFromParcel(parcel), false);
131     MockWriteUint32(true);
132     MockWriteString(false, 1);
133     EXPECT_EQ(bFileInfo.ReadFromParcel(parcel), false);
134     EXPECT_EQ(bFileInfo.ReadFromParcel(parcel), false);
135 
136     auto infoPtr = bFileInfo.Unmarshalling(parcel);
137     EXPECT_EQ(infoPtr, nullptr);
138 
139     GTEST_LOG_(INFO) << "BFileInfoTest-end SUB_BFile_Info_0200";
140 }
141 } // namespace OHOS::FileManagement::Backup