• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #include "host_uds_server_test.h"
16 #ifdef __OHOS__
17 #include "server_for_client.h"
18 #include "uv.h"
19 #include <securec.h>
20 #include "define_enum.h"
21 #include "server.h"
22 #endif
23 
24 using namespace testing::ext;
25 
26 namespace Hdc {
SetUpTestCase()27 void HdcHostUdsServerTest::SetUpTestCase() {}
TearDownTestCase()28 void HdcHostUdsServerTest::TearDownTestCase() {}
SetUp()29 void HdcHostUdsServerTest::SetUp() {}
TearDown()30 void HdcHostUdsServerTest::TearDown() {}
31 
32 
33 HWTEST_F(HdcHostUdsServerTest, Test_AcceptUdsClient, TestSize.Level0)
34 {
35 #ifdef __OHOS__
36     uv_loop_t loopMain;
37     uv_loop_init(&loopMain);
38     HdcServerForClient *cls = new HdcServerForClient(true, std::string("uds"), nullptr, &loopMain);
39     EXPECT_TRUE(!cls->SetUdsListen());
40     sleep(1);
41     HdcServerForClient::AcceptUdsClient((uv_stream_t *)&cls->udsListen, 0);
42     EXPECT_TRUE(cls->mapChannel.size() == 1);
43 
44     delete cls;
45 #endif
46 }
47 
48 HWTEST_F(HdcHostUdsServerTest, Test_AttachChannelInnerForUds, TestSize.Level0)
49 {
50 #ifdef __OHOS__
51     uv_loop_t loopMain;
52     uv_loop_init(&loopMain);
53 
54     HdcServer server(true);
55     HdcServerForClient *clsServerForClient = new HdcServerForClient(true, "uds", &server, &loopMain);
56     server.clsServerForClient = clsServerForClient;
57     HSession hSession = server.MallocSession(true, CONN_USB, nullptr);
58     HChannel hChannel = new HdcChannel();
59     clsServerForClient->AdminChannel(OP_ADD, hChannel->channelId, hChannel);
60     server.AttachChannelInnerForUds(hSession, hChannel->channelId);
61     EXPECT_TRUE(hChannel->targetSessionId == hSession->sessionId);
62     delete hChannel;
63 #endif
64 }
65 
66 }