1 /*
2 * Copyright (c) 2021 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 <iostream>
19 #include "session.h"
20 #include "softbus_error_code.h"
21
22 using namespace testing::ext;
23 namespace OHOS {
24 static const char *UDP_TEST_PKG_NAME = "com.plrdtest.dsoftbus.server";
25 static const char *UDP_TEST_SESSION_NAME = "com.plrdtest.dsoftbus.JtSendRawStream_0";
26 int32_t g_testWay = 0;
27 class TransQosStatServerTest : public testing::Test {
28 public:
TransQosStatServerTest()29 TransQosStatServerTest()
30 {}
~TransQosStatServerTest()31 ~TransQosStatServerTest()
32 {}
33 static void SetUpTestCase(void);
34 static void TearDownTestCase(void);
SetUp()35 void SetUp() override
36 {}
TearDown()37 void TearDown() override
38 {}
39 };
40
SetUpTestCase(void)41 void TransQosStatServerTest::SetUpTestCase(void)
42 {
43 printf("********Qos Test Begin*********\r\n");
44 printf("* 0.with onQosEvent *\r\n");
45 printf("* 1.without onQosEvent *\r\n");
46 printf("********************************\r\n");
47 printf("input the num:");
48 std::cin >> g_testWay;
49 }
50
TearDownTestCase(void)51 void TransQosStatServerTest::TearDownTestCase(void)
52 {}
53
OnSessionOpend(int32_t sessionId,int32_t result)54 static int32_t OnSessionOpend(int32_t sessionId, int32_t result)
55 {
56 printf("on session opened[sessionId = %d, result = %d]\n", sessionId, result);
57 return 0;
58 }
59
OnSessionClosed(int32_t sessionId)60 static void OnSessionClosed(int32_t sessionId)
61 {
62 printf("on session closed[sessionId = %d]\n", sessionId);
63 }
64
OnStreamReceived(int32_t sessionId,const StreamData * data,const StreamData * ext,const StreamFrameInfo * param)65 static void OnStreamReceived(int32_t sessionId, const StreamData *data,
66 const StreamData *ext, const StreamFrameInfo *param)
67 {}
68
OnBytesReceived(int32_t sessionId,const void * data,unsigned int dataLen)69 static void OnBytesReceived(int32_t sessionId, const void *data, unsigned int dataLen)
70 {}
71
OnMessageReceived(int32_t sessionId,const void * data,unsigned int dataLen)72 static void OnMessageReceived(int32_t sessionId, const void *data, unsigned int dataLen)
73 {}
74
OnQosEvent(int32_t sessionId,int32_t eventId,int32_t tvCount,const QosTv * tvList)75 static void OnQosEvent(int32_t sessionId, int32_t eventId, int32_t tvCount, const QosTv *tvList)
76 {
77 printf("on QoS metric retrieved [sessionId = %d] [eventId=%d]!!!!!!\n", sessionId, eventId);
78 printf("pktNum:%u\n", tvList->info.appStatistics.pktNum);
79 printf("periodRecvPkts:%u\n", tvList->info.appStatistics.periodRecvPkts);
80 printf("periodRecvPktLoss:%u\n", tvList->info.appStatistics.periodRecvPktLoss);
81 printf("periodRecvRate:%u\n", tvList->info.appStatistics.periodRecvRate);
82 printf("periodRecvRateBps:%" PRIu64 "\n", tvList->info.appStatistics.periodRecvRateBps);
83 printf("periodRtt:%u\n", tvList->info.appStatistics.periodRtt);
84 printf("periodRecvPktLossHighPrecision:%u\n", tvList->info.appStatistics.periodRecvPktLossHighPrecision);
85 printf("periodSendLostPkts:%u\n", tvList->info.appStatistics.periodSendLostPkts);
86 printf("periodSendPkts:%u\n", tvList->info.appStatistics.periodSendPkts);
87 printf("periodSendPktLossHighPrecision:%u\n", tvList->info.appStatistics.periodSendPktLossHighPrecision);
88 printf("periodSendBits:%" PRIu64 "\n", tvList->info.appStatistics.periodSendBits);
89 printf("periodSendRateBps:%" PRIu64 "\n", tvList->info.appStatistics.periodSendRateBps);
90 }
91
92 static ISessionListener g_hasQosCb = {
93 .OnSessionOpened = OnSessionOpend,
94 .OnSessionClosed = OnSessionClosed,
95 .OnStreamReceived = OnStreamReceived,
96 .OnBytesReceived = OnBytesReceived,
97 .OnMessageReceived = OnMessageReceived,
98 .OnQosEvent = OnQosEvent,
99 };
100
101 static ISessionListener g_noQosCb = {
102 .OnSessionOpened = OnSessionOpend,
103 .OnSessionClosed = OnSessionClosed,
104 .OnStreamReceived = OnStreamReceived,
105 .OnBytesReceived = OnBytesReceived,
106 .OnMessageReceived = OnMessageReceived,
107 .OnQosEvent = nullptr,
108 };
109
110 /**
111 * @tc.name: TransQosStatServerTest001
112 * @tc.desc: receive with onQosEvent
113 * @tc.type: FUNC
114 * @tc.require:
115 */
116 HWTEST_F(TransQosStatServerTest, QosStatServerTest001, TestSize.Level0)
117 {
118 int32_t ret;
119 if (g_testWay == 0) {
120 ret = CreateSessionServer(UDP_TEST_PKG_NAME, UDP_TEST_SESSION_NAME, &g_hasQosCb);
121 } else {
122 ret = CreateSessionServer(UDP_TEST_PKG_NAME, UDP_TEST_SESSION_NAME, &g_noQosCb);
123 }
124 EXPECT_EQ(ret, SOFTBUS_OK);
125 if (ret == SOFTBUS_OK) {
126 while (1) {
127 sleep(3);
128 }
129 }
130 }
131 } // namespace OHOS
132