• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "udp_wrap.h"
21 
22 namespace OHOS {
23 namespace MMI {
24 namespace {
25 using namespace testing::ext;
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 class UDSServerUnitTest : public UDSServer {
35 public:
SetFd(int32_t fd)36     void SetFd(int32_t fd)
37     {
38         fd_ = fd;
39     }
40 };
41 
42 HWTEST_F(UDSServerTest, SendMsg_001, TestSize.Level1)
43 {
44     MmiMessageId msgId = MmiMessageId::INVALID;
45     NetPacket pkt(msgId);
46     int32_t fd = 1000;
47     UDSServer serObj;
48     bool retResult = serObj.SendMsg(fd, pkt);
49     EXPECT_FALSE(retResult);
50 }
51 
52 HWTEST_F(UDSServerTest, SendMsg_002, TestSize.Level1)
53 {
54     MmiMessageId msgId = MmiMessageId::INVALID;
55     NetPacket pkt(msgId);
56 
57     int32_t fd = -1001;
58     UDSServer serObj;
59     bool retResult = serObj.SendMsg(fd, pkt);
60     ASSERT_FALSE(retResult);
61 }
62 
63 HWTEST_F(UDSServerTest, SendMsg_003, TestSize.Level1)
64 {
65     MmiMessageId msgId = MmiMessageId::INVALID;
66     NetPacket pkt(msgId);
67 
68     int32_t fd = 3333;
69     UDSServer serObj;
70     bool retResult = serObj.SendMsg(fd, pkt);
71     ASSERT_FALSE(retResult);
72 }
73 
74 HWTEST_F(UDSServerTest, Multicast, TestSize.Level1)
75 {
76     MmiMessageId msgId = MmiMessageId::INVALID;
77     NetPacket pkt(msgId);
78     std::vector<int32_t> fds;
79     fds.push_back(1);
80 
81     UDSServer serObj;
82     serObj.Multicast(fds, pkt);
83 }
84 
85 HWTEST_F(UDSServerTest, Stop_001, TestSize.Level1)
86 {
87     UDSServer serObj;
88     ASSERT_NO_FATAL_FAILURE(serObj.UdsStop());
89 }
90 
91 HWTEST_F(UDSServerTest, GetSession_001, TestSize.Level1)
92 {
93     UDSServer UDS_server;
94     int32_t fd = 0;
95     auto retResult = UDS_server.GetSession(fd);
96     EXPECT_TRUE(retResult == nullptr);
97 }
98 
99 HWTEST_F(UDSServerTest, GetSession_002, TestSize.Level1)
100 {
101     UDSServer UDS_server;
102     int32_t fd = 1000000;
103     auto retResult = UDS_server.GetSession(fd);
104     EXPECT_TRUE(retResult == nullptr);
105 }
106 
107 HWTEST_F(UDSServerTest, GetSession_003, TestSize.Level1)
108 {
109     UDSServer UDS_server;
110     int32_t fd = -1;
111     auto retResult = UDS_server.GetSession(fd);
112     EXPECT_TRUE(retResult == nullptr);
113 }
114 } // namespace MMI
115 } // namespace OHOS
116