1 /*
2 * Copyright (c) 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 #include "securec.h"
18
19 #include "client_trans_pending.h"
20 #include "client_trans_proxy_file_manager.h"
21 #include "softbus_def.h"
22 #include "softbus_errcode.h"
23
24 #define TEST_SESSION_ID 0
25 #define TEST_SEQ 1
26 #define TEST_SESSION_ID_SECOND 2
27 #define TEST_SEQ_SECOND 2
28 #define TEST_WAIT_ACK_TIME 10
29
30 using namespace std;
31 using namespace testing::ext;
32
33 namespace OHOS {
34 class ClientTransProxyTest : public testing::Test {
35 public:
ClientTransProxyTest()36 ClientTransProxyTest() {}
~ClientTransProxyTest()37 ~ClientTransProxyTest() {}
38 static void SetUpTestCase(void);
39 static void TearDownTestCase(void);
SetUp()40 void SetUp() override {}
TearDown()41 void TearDown() override {}
42 };
43
SetUpTestCase(void)44 void ClientTransProxyTest::SetUpTestCase(void) {}
TearDownTestCase(void)45 void ClientTransProxyTest::TearDownTestCase(void) {}
46
47 /**
48 * @tc.name: TransPendingTest001
49 * @tc.desc: client trans pending test,use the wrong or normal parameter.
50 * @tc.type: FUNC
51 * @tc.require:
52 */
53 HWTEST_F(ClientTransProxyTest, TransPendingTest, TestSize.Level0)
54 {
55 uint32_t id = 1;
56 uint64_t seq = 0;
57
58 int ret = CreatePendingPacket(id, seq);
59 EXPECT_EQ(SOFTBUS_OK, ret);
60
61 ret = CreatePendingPacket(TEST_SESSION_ID, seq);
62 EXPECT_EQ(SOFTBUS_OK, ret);
63
64 ret = CreatePendingPacket(id, TEST_SEQ);
65 EXPECT_EQ(SOFTBUS_OK, ret);
66
67 ret = CreatePendingPacket(id, seq);
68 EXPECT_EQ(SOFTBUS_ALREADY_EXISTED, ret);
69
70 uint32_t waitMillis = TEST_WAIT_ACK_TIME;
71 ret = GetPendingPacketData(id, seq, waitMillis, true, nullptr);
72 EXPECT_EQ(SOFTBUS_ERR, ret);
73
74 TransPendData pendDate = {0};
75 ret = GetPendingPacketData(TEST_SESSION_ID_SECOND, TEST_SEQ_SECOND, waitMillis, true, &pendDate);
76 EXPECT_EQ(SOFTBUS_NOT_FIND, ret);
77
78 ret = GetPendingPacketData(TEST_SESSION_ID_SECOND, seq, waitMillis, true, &pendDate);
79 EXPECT_EQ(SOFTBUS_NOT_FIND, ret);
80
81 ret = GetPendingPacketData(id, TEST_SEQ_SECOND, waitMillis, true, &pendDate);
82 EXPECT_EQ(SOFTBUS_NOT_FIND, ret);
83
84 ret = SetPendingPacketData(id, seq, &pendDate);
85 EXPECT_EQ(SOFTBUS_OK, ret);
86
87 ret = SetPendingPacketData(id, seq, nullptr);
88 EXPECT_EQ(SOFTBUS_OK, ret);
89
90 ret = SetPendingPacketData(TEST_SESSION_ID_SECOND, TEST_SEQ_SECOND, &pendDate);
91 EXPECT_EQ(SOFTBUS_ERR, ret);
92
93 ret = SetPendingPacketData(TEST_SESSION_ID_SECOND, seq, &pendDate);
94 EXPECT_EQ(SOFTBUS_ERR, ret);
95
96 ret = SetPendingPacketData(id, TEST_SEQ_SECOND, &pendDate);
97 EXPECT_EQ(SOFTBUS_ERR, ret);
98
99 ret = GetPendingPacketData(id, seq, waitMillis, false, &pendDate);
100 EXPECT_EQ(SOFTBUS_ALREADY_TRIGGERED, ret);
101
102 ret = GetPendingPacketData(id, TEST_SEQ, waitMillis, true, &pendDate);
103 EXPECT_EQ(SOFTBUS_TIMOUT, ret);
104
105 DeletePendingPacket(id, seq);
106
107 DeletePendingPacket(TEST_SESSION_ID, seq);
108
109 DeletePendingPacket(id, TEST_SEQ);
110
111 DeletePendingPacket(TEST_SESSION_ID_SECOND, TEST_SEQ_SECOND);
112 }
113 } // namespace OHOS nvv