• 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 <memory>
17 #include <unistd.h>
18 
19 #include "gtest/gtest.h"
20 #include "network/devsl_dispatcher.h"
21 #include "network/kernel_talker.h"
22 #include "utils_log.h"
23 
24 namespace OHOS {
25 namespace Storage {
26 namespace DistributedFile {
27 namespace Test {
28 using namespace testing::ext;
29 using namespace std;
30 
31 class DevslDispatcherTest : public testing::Test {
32 public:
SetUpTestCase(void)33     static void SetUpTestCase(void) {};
TearDownTestCase(void)34     static void TearDownTestCase(void) {};
SetUp()35     void SetUp() {};
TearDown()36     void TearDown() {};
37 };
38 
39 /**
40  * @tc.name: DevslDispatcherTest_Start_Stop_0100
41  * @tc.desc: Verify the Start/Stop function.
42  * @tc.type: FUNC
43  * @tc.require: SR000H0387
44  */
45 HWTEST_F(DevslDispatcherTest, DevslDispatcherTest_Start_Stop_0100, TestSize.Level1)
46 {
47     GTEST_LOG_(INFO) << "DevslDispatcherTest_Start_Stop_0100 start";
48     bool res = true;
49     try {
50         DevslDispatcher::Start();
51         DevslDispatcher::Stop();
52     } catch (const exception &e) {
53         res = false;
54         LOGE("%{public}s", e.what());
55     }
56     EXPECT_TRUE(res == true);
57     GTEST_LOG_(INFO) << "DevslDispatcherTest_Start_Stop_0100 end";
58 }
59 
60 /**
61  * @tc.name: DevslDispatcherTest_DevslGottonCallback_0100
62  * @tc.desc: Verify the DevslGottonCallback function.
63  * @tc.type: FUNC
64  * @tc.require: SR000H0387
65  */
66 HWTEST_F(DevslDispatcherTest, DevslDispatcherTest_DevslGottonCallback_0100, TestSize.Level1)
67 {
68     GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGottonCallback_0100 start";
69     bool res = true;
70     uint32_t level = 0;
71     DEVSLQueryParams queryParam = {
72         .udid = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0},
73         .udidLen = 10
74     };
75 
76     try {
77         DevslDispatcher::DevslGottonCallback(&queryParam, 0, level);
78         DevslDispatcher::DevslGottonCallback(&queryParam, 1, level);
79     } catch (const exception &e) {
80         res = false;
81         LOGE("%{public}s", e.what());
82     }
83 
84     EXPECT_TRUE(res == true);
85     GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGottonCallback_0100 end";
86 }
87 
88 /**
89  * @tc.name: DevslDispatcherTest_DevslGetRegister_0100
90  * @tc.desc: Verify the DevslGetRegister function.
91  * @tc.type: FUNC
92  * @tc.require: SR000H0387
93  */
94 HWTEST_F(DevslDispatcherTest, DevslDispatcherTest_DevslGetRegister_0100, TestSize.Level1)
95 {
96     GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGetRegister_0100 start";
97     bool res = true;
98     const string cid = "scid";
99     constexpr int userId = 100;
100     auto smp = make_shared<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(userId, "account"));
101     weak_ptr<MountPoint> wmp = smp;
__anond0e0725c0202(const std::string &cid) 102     auto kernelTalker = std::make_shared<KernelTalker>(wmp, [](NotifyParam &param) {}, [](const std::string &cid) {});
103 
104     try {
105         DevslDispatcher::DevslGetRegister(cid, kernelTalker);
106     } catch (const exception &e) {
107         res = false;
108         LOGE("%{public}s", e.what());
109     }
110 
111     EXPECT_TRUE(res == true);
112     GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGetRegister_0100 end";
113 }
114 } // namespace Test
115 } // namespace DistributedFile
116 } // namespace Storage
117 } // namespace OHOS
118