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 <future> 17 18 #include <gtest/gtest.h> 19 20 #include "uds_client.h" 21 22 23 namespace OHOS { 24 namespace MMI { 25 namespace { 26 using namespace testing::ext; 27 } // namespace 28 29 class UDSClientTest : public testing::Test { 30 public: SetUpTestCase(void)31 static void SetUpTestCase(void) {} TearDownTestCase(void)32 static void TearDownTestCase(void) {} 33 }; 34 35 class UDSClientUnitTest : public UDSClient { 36 public: SetFd(int32_t fd)37 void SetFd(int32_t fd) 38 { 39 fd_ = fd; 40 } Socket()41 int32_t Socket() 42 { 43 return fd_; 44 } 45 }; 46 47 HWTEST_F(UDSClientTest, ConnectTo_01, TestSize.Level1) 48 { 49 UDSClientUnitTest udsClient; 50 int32_t retResult = udsClient.ConnectTo(); 51 ASSERT_EQ(RET_ERR, retResult); 52 } 53 54 HWTEST_F(UDSClientTest, ConnectTo_02, TestSize.Level1) 55 { 56 UDSClientUnitTest udsClient; 57 udsClient.SetFd(0); 58 int32_t retResult = udsClient.ConnectTo(); 59 ASSERT_EQ(RET_OK, retResult); 60 } 61 62 HWTEST_F(UDSClientTest, SendMsg_001, TestSize.Level1) 63 { 64 const char *buf = nullptr; 65 size_t size = 0; 66 67 UDSClientUnitTest udsClientUt; 68 auto retResult = udsClientUt.SendMsg(buf, size); 69 ASSERT_FALSE(retResult); 70 } 71 72 HWTEST_F(UDSClientTest, SendMsg_002, TestSize.Level1) 73 { 74 const char *buf = "1234#"; 75 size_t size = 5; 76 77 UDSClientUnitTest udsClientUt; 78 auto retResult = udsClientUt.SendMsg(buf, size); 79 ASSERT_FALSE(retResult); 80 } 81 82 HWTEST_F(UDSClientTest, SendMsg_type2_001, TestSize.Level1) 83 { 84 NetPacket pkt(MmiMessageId::INVALID); 85 86 UDSClientUnitTest udsClientUt; 87 auto retResult = udsClientUt.SendMsg(pkt); 88 ASSERT_FALSE(retResult); 89 } 90 91 HWTEST_F(UDSClientTest, SendMsg_type2_002, TestSize.Level1) 92 { 93 NetPacket pkt(static_cast<MmiMessageId>(222)); 94 95 UDSClientUnitTest udsClientUt; 96 auto retResult = udsClientUt.SendMsg(pkt); 97 ASSERT_FALSE(retResult); 98 } 99 100 HWTEST_F(UDSClientTest, Stop_001, TestSize.Level1) 101 { 102 UDSClientUnitTest udsClientUt; 103 udsClientUt.Stop(); 104 } 105 } // namespace MMI 106 } // namespace OHOS 107