1 /* 2 * Copyright (c) 2021-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 <gtest/gtest.h> 17 18 #include "proto.h" 19 #include "uds_server.h" 20 21 namespace OHOS { 22 namespace MMI { 23 namespace { 24 using namespace testing::ext; 25 using namespace OHOS::MMI; 26 } // namespace 27 28 class UDSServerTest : public testing::Test { 29 public: SetUpTestCase(void)30 static void SetUpTestCase(void) {} TearDownTestCase(void)31 static void TearDownTestCase(void) {} 32 }; 33 34 #if BINDER_TODO 35 class UDSServerUnitTest : public UDSServer { 36 public: SetFd(int32_t fd)37 void SetFd(int32_t fd) 38 { 39 fd_ = fd; 40 } 41 OnRecvUnitTest(int32_t fd,const char * buf,size_t size)42 void OnRecvUnitTest(int32_t fd, const char *buf, size_t size) 43 { 44 OnRecv(fd, buf, size); 45 } 46 }; 47 48 HWTEST_F(UDSServerTest, Init_001, TestSize.Level1) 49 { 50 const std::string path = "./test"; 51 UDSServer serObj; 52 serObj.Init(path); 53 } 54 55 HWTEST_F(UDSServerTest, Init_002, TestSize.Level1) 56 { 57 const std::string path = ""; 58 UDSServer serObj; 59 serObj.Init(path); 60 } 61 62 HWTEST_F(UDSServerTest, SendMsg_001, TestSize.Level1) 63 { 64 MmiMessageId msgId = MmiMessageId::INVALID; 65 NetPacket pkt(msgId); 66 67 int32_t fd = 1000; 68 UDSServer serObj; 69 bool retResult = serObj.SendMsg(fd, pkt); 70 EXPECT_FALSE(retResult); 71 } 72 73 HWTEST_F(UDSServerTest, SendMsg_002, TestSize.Level1) 74 { 75 MmiMessageId msgId = MmiMessageId::INVALID; 76 NetPacket pkt(msgId); 77 78 int32_t fd = -1001; 79 UDSServer serObj; 80 bool retResult = serObj.SendMsg(fd, pkt); 81 ASSERT_FALSE(retResult); 82 } 83 84 HWTEST_F(UDSServerTest, SendMsg_003, TestSize.Level1) 85 { 86 MmiMessageId msgId = MmiMessageId::INVALID; 87 NetPacket pkt(msgId); 88 89 int32_t fd = 3333; 90 UDSServer serObj; 91 bool retResult = serObj.SendMsg(fd, pkt); 92 ASSERT_FALSE(retResult); 93 } 94 95 HWTEST_F(UDSServerTest, Multicast, TestSize.Level1) 96 { 97 MmiMessageId msgId = MmiMessageId::INVALID; 98 NetPacket pkt(msgId); 99 std::vector<int32_t> fds; 100 fds.push_back(1); 101 102 UDSServer serObj; 103 serObj.Multicast(fds, pkt); 104 } 105 106 HWTEST_F(UDSServerTest, OnRecv, TestSize.Level1) 107 { 108 int32_t fd = 1; 109 const char *buf = "333"; 110 size_t size = 3; 111 112 UDSServerUnitTest serObjUt; 113 serObjUt.OnRecvUnitTest(fd, buf, size); 114 } 115 116 HWTEST_F(UDSServerTest, Stop_001, TestSize.Level1) 117 { 118 UDSServer serObj; 119 serObj.Stop(); 120 } 121 122 HWTEST_F(UDSServerTest, GetSession_001, TestSize.Level1) 123 { 124 UDSServer UDS_server; 125 int32_t fd = 0; 126 auto retResult = UDS_server.GetSession(fd); 127 EXPECT_TRUE(retResult == nullptr); 128 } 129 130 HWTEST_F(UDSServerTest, GetSession_002, TestSize.Level1) 131 { 132 UDSServer UDS_server; 133 int32_t fd = 1000000; 134 auto retResult = UDS_server.GetSession(fd); 135 EXPECT_TRUE(retResult == nullptr); 136 } 137 138 HWTEST_F(UDSServerTest, GetSession_003, TestSize.Level1) 139 { 140 UDSServer UDS_server; 141 int32_t fd = -1; 142 auto retResult = UDS_server.GetSession(fd); 143 EXPECT_TRUE(retResult == nullptr); 144 } 145 #endif 146 } // namespace MMI 147 } // namespace OHOS 148