1 /*
2  * Copyright (c) 2024 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 <gmock/gmock.h>
17 #include <gtest/gtest.h>
18 
19 #include "trans_mananger.h"
20 
21 namespace OHOS::Storage::DistributedFile::Test {
22 using namespace testing;
23 using namespace testing::ext;
24 using namespace std;
25 
26 class TransManagerTest : public testing::Test {
27 public:
28     static void SetUpTestCase(void);
29     static void TearDownTestCase(void);
30     void SetUp();
31     void TearDown();
32     std::shared_ptr<TransManager> transManager_;
33 };
34 
SetUpTestCase(void)35 void TransManagerTest::SetUpTestCase(void)
36 {
37     GTEST_LOG_(INFO) << "SetUpTestCase";
38 }
39 
TearDownTestCase(void)40 void TransManagerTest::TearDownTestCase(void)
41 {
42     GTEST_LOG_(INFO) << "TearDownTestCase";
43 }
44 
SetUp(void)45 void TransManagerTest::SetUp(void)
46 {
47     transManager_ = std::make_shared<TransManager>();
48     GTEST_LOG_(INFO) << "SetUp";
49 }
50 
TearDown(void)51 void TransManagerTest::TearDown(void)
52 {
53     GTEST_LOG_(INFO) << "TearDown";
54 }
55 
56 HWTEST_F(TransManagerTest, DfsService_AddTransTask_001, TestSize.Level1)
57 {
58     GTEST_LOG_(INFO) << "DfsService_AddTransTask_001_Start";
59     string sessionName;
60     sptr<IFileTransListener> listener;
61     transManager_->AddTransTask(sessionName, listener);
62     EXPECT_TRUE(true);
63     GTEST_LOG_(INFO) << "DfsService_AddTransTask_001_End";
64 }
65 
66 HWTEST_F(TransManagerTest, DfsService_AddTransTask_002, TestSize.Level1)
67 {
68     GTEST_LOG_(INFO) << "DfsService_AddTransTask_002_Start";
69     string sessionName;
70     sptr<IFileTransListener> listener;
71     TransManager::GetInstance().AddTransTask(sessionName, listener);
72     EXPECT_TRUE(true);
73     GTEST_LOG_(INFO) << "DfsService_AddTransTask_002_End";
74 }
75 
76 HWTEST_F(TransManagerTest, DfsService_DeleteTransTask_001, TestSize.Level1)
77 {
78     GTEST_LOG_(INFO) << "DfsService_DeleteTransTask_001_Start";
79     string sessionName;
80     transManager_->DeleteTransTask(sessionName);
81     EXPECT_TRUE(true);
82     GTEST_LOG_(INFO) << "DfsService_DeleteTransTask_001_End";
83 }
84 
85 HWTEST_F(TransManagerTest, DfsService_DeleteTransTask_002, TestSize.Level1)
86 {
87     GTEST_LOG_(INFO) << "DfsService_DeleteTransTask_002_Start";
88     string sessionName;
89     TransManager::GetInstance().DeleteTransTask(sessionName);
90     EXPECT_TRUE(true);
91     GTEST_LOG_(INFO) << "DfsService_DeleteTransTask_002_End";
92 }
93 
94 HWTEST_F(TransManagerTest, DfsService_GetInstance_001, TestSize.Level1)
95 {
96     GTEST_LOG_(INFO) << "DfsService_GetInstance_001_Start";
97     TransManager::GetInstance();
98     EXPECT_TRUE(true);
99     GTEST_LOG_(INFO) << "DfsService_GetInstance_001_End";
100 }
101 
102 HWTEST_F(TransManagerTest, DfsService_NotifyFileFailed_001, TestSize.Level1)
103 {
104     GTEST_LOG_(INFO) << "DfsService_NotifyFileFailed_001_Start";
105     string sessionName;
106     int32_t errorCode = 0;
107     transManager_->NotifyFileFailed(sessionName, errorCode);
108     EXPECT_TRUE(errorCode == 0);
109     GTEST_LOG_(INFO) << "DfsService_NotifyFileFailed_001_End";
110 }
111 
112 HWTEST_F(TransManagerTest, DfsService_NotifyFileFailed_002, TestSize.Level1)
113 {
114     GTEST_LOG_(INFO) << "DfsService_NotifyFileFailed_002_Start";
115     string sessionName;
116     int32_t errorCode = 0;
117     TransManager::GetInstance().NotifyFileFailed(sessionName, errorCode);
118     EXPECT_TRUE(errorCode == 0);
119     GTEST_LOG_(INFO) << "DfsService_NotifyFileFailed_002_End";
120 }
121 
122 HWTEST_F(TransManagerTest, DfsService_NotifyFileFinished_001, TestSize.Level1)
123 {
124     GTEST_LOG_(INFO) << "DfsService_NotifyFileFinished_001_Start";
125     string sessionName;
126     transManager_->NotifyFileFinished(sessionName);
127     EXPECT_TRUE(true);
128     GTEST_LOG_(INFO) << "DfsService_NotifyFileFinished_001_End";
129 }
130 
131 HWTEST_F(TransManagerTest, DfsService_NotifyFileFinished_002, TestSize.Level1)
132 {
133     GTEST_LOG_(INFO) << "DfsService_NotifyFileFinished_002_Start";
134     string sessionName;
135     TransManager::GetInstance().NotifyFileFinished(sessionName);
136     EXPECT_TRUE(true);
137     GTEST_LOG_(INFO) << "DfsService_NotifyFileFinished_002_End";
138 }
139 
140 HWTEST_F(TransManagerTest, DfsService_NotifyFileProgress_001, TestSize.Level1)
141 {
142     GTEST_LOG_(INFO) << "DfsService_NotifyFileProgress_001_Start";
143     string sessionName;
144     uint64_t total = 0;
145     uint64_t processed = 0;;
146     transManager_->NotifyFileProgress(sessionName, total, processed);
147     EXPECT_TRUE(true);
148     GTEST_LOG_(INFO) << "DfsService_NotifyFileProgress_001_End";
149 }
150 
151 HWTEST_F(TransManagerTest, DfsService_NotifyFileProgress_002, TestSize.Level1)
152 {
153     GTEST_LOG_(INFO) << "DfsService_NotifyFileProgress_002_Start";
154     string sessionName;
155     uint64_t total = 0;
156     uint64_t processed = 0;;
157     TransManager::GetInstance().NotifyFileProgress(sessionName, total, processed);
158     EXPECT_TRUE(true);
159     GTEST_LOG_(INFO) << "DfsService_NotifyFileProgress_002_End";
160 }
161 }