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