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_MakeDevslQueryParams_0100 62 * @tc.desc: Verify the MakeDevslQueryParams function. 63 * @tc.type: FUNC 64 * @tc.require: SR000H0387 65 */ 66 HWTEST_F(DevslDispatcherTest, DevslDispatcherTest_MakeDevslQueryParams_0100, TestSize.Level1) 67 { 68 GTEST_LOG_(INFO) << "DevslDispatcherTest_MakeDevslQueryParams_0100 start"; 69 bool res = true; 70 string udid = "0123"; 71 try { 72 DEVSLQueryParams queryParam = DevslDispatcher::MakeDevslQueryParams(udid); 73 EXPECT_TRUE(queryParam.udidLen == udid.size()); 74 } catch (const exception &e) { 75 res = false; 76 LOGE("%{public}s", e.what()); 77 } 78 EXPECT_TRUE(res == true); 79 GTEST_LOG_(INFO) << "DevslDispatcherTest_MakeDevslQueryParams_0100 end"; 80 } 81 82 /** 83 * @tc.name: DevslDispatcherTest_DevslGottonCallbackAsync_0100 84 * @tc.desc: Verify the DevslGottonCallbackAsync function. 85 * @tc.type: FUNC 86 * @tc.require: SR000H0387 87 */ 88 HWTEST_F(DevslDispatcherTest, DevslDispatcherTest_DevslGottonCallbackAsync_0100, TestSize.Level1) 89 { 90 GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGottonCallbackAsync_0100 start"; 91 bool res = true; 92 string udid = "0"; 93 uint32_t devsl = 1; 94 try { 95 DevslDispatcher::DevslGottonCallbackAsync(udid, devsl); 96 } catch (const exception &e) { 97 res = false; 98 LOGE("%{public}s", e.what()); 99 } 100 EXPECT_TRUE(res == true); 101 GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGottonCallbackAsync_0100 end"; 102 } 103 104 /** 105 * @tc.name: DevslDispatcherTest_DevslGottonCallback_0100 106 * @tc.desc: Verify the DevslGottonCallback function. 107 * @tc.type: FUNC 108 * @tc.require: SR000H0387 109 */ 110 HWTEST_F(DevslDispatcherTest, DevslDispatcherTest_DevslGottonCallback_0100, TestSize.Level1) 111 { 112 GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGottonCallback_0100 start"; 113 bool res = true; 114 uint32_t level = 0; 115 DEVSLQueryParams queryParam = { 116 .udid = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}, 117 .udidLen = 10 118 }; 119 120 try { 121 DevslDispatcher::DevslGottonCallback(&queryParam, 0, level); 122 DevslDispatcher::DevslGottonCallback(&queryParam, 1, level); 123 } catch (const exception &e) { 124 res = false; 125 LOGE("%{public}s", e.what()); 126 } 127 128 EXPECT_TRUE(res == true); 129 GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGottonCallback_0100 end"; 130 } 131 132 /** 133 * @tc.name: DevslDispatcherTest_DevslGetRegister_0100 134 * @tc.desc: Verify the DevslGetRegister function. 135 * @tc.type: FUNC 136 * @tc.require: SR000H0387 137 */ 138 HWTEST_F(DevslDispatcherTest, DevslDispatcherTest_DevslGetRegister_0100, TestSize.Level1) 139 { 140 GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGetRegister_0100 start"; 141 bool res = true; 142 const string cid = "scid"; 143 constexpr int userId = 100; 144 auto smp = make_shared<MountPoint>(Utils::DfsuMountArgumentDescriptors::Alpha(userId, "account")); 145 weak_ptr<MountPoint> wmp = smp; __anonaf5940d30102(NotifyParam ¶m) 146 auto kernelTalker = std::make_shared<KernelTalker>(wmp, [](NotifyParam ¶m) {}, [](const std::string &) {}); 147 148 try { 149 DevslDispatcher::DevslGetRegister(cid, kernelTalker); 150 } catch (const exception &e) { 151 res = false; 152 LOGE("%{public}s", e.what()); 153 } 154 155 EXPECT_TRUE(res == true); 156 GTEST_LOG_(INFO) << "DevslDispatcherTest_DevslGetRegister_0100 end"; 157 } 158 } // namespace Test 159 } // namespace DistributedFile 160 } // namespace Storage 161 } // namespace OHOS 162