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 
18 #include "client_trans_auth_manager.c"
19 #include "softbus_adapter_mem.h"
20 #include "securec.h"
21 #include "softbus_def.h"
22 #include "softbus_errcode.h"
23 
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 
28 const char *g_invalidSessionName = "invalid sessionName";
29 
30 class TransClientSdkAuthManagerTest : public testing::Test {
31 public:
TransClientSdkAuthManagerTest()32     TransClientSdkAuthManagerTest() {}
~TransClientSdkAuthManagerTest()33     ~TransClientSdkAuthManagerTest() {}
34     static void SetUpTestCase(void);
35     static void TearDownTestCase(void);
SetUp()36     void SetUp() override {}
TearDown()37     void TearDown() override {}
38 };
39 
SetUpTestCase(void)40 void TransClientSdkAuthManagerTest::SetUpTestCase(void) {}
41 
TearDownTestCase(void)42 void TransClientSdkAuthManagerTest::TearDownTestCase(void) {}
43 
44 /**
45  * @tc.name: TransClientSdkAuthManagerTest001
46  * @tc.desc: client trans auth init use wrong param.
47  * @tc.type: FUNC
48  * @tc.require:
49  */
50 HWTEST_F(TransClientSdkAuthManagerTest, TransClientSdkAuthManagerTest001, TestSize.Level0)
51 {
52     int32_t ret = ClientTransAuthInit(NULL);
53     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
54 }
55 
56 /**
57  * @tc.name: TransClientSdkAuthManagerTest002
58  * @tc.desc: client trans auth init use wrong param.
59  * @tc.type: FUNC
60  * @tc.require:
61  */
62 HWTEST_F(TransClientSdkAuthManagerTest, TransClientSdkAuthManagerTest002, TestSize.Level0)
63 {
64     ChannelInfo channel;
65     int32_t ret = ClientTransAuthOnChannelOpened(NULL, &channel);
66     EXPECT_EQ(SOFTBUS_INVALID_PARAM, ret);
67 }
68 
69 /**
70  * @tc.name: TransClientSdkAuthManagerTest003
71  * @tc.desc: client trans auth init use wrong param.
72  * @tc.type: FUNC
73  * @tc.require:
74  */
75 HWTEST_F(TransClientSdkAuthManagerTest, TransClientSdkAuthManagerTest003, TestSize.Level0)
76 {
77     int32_t channelId = 0;
78     uint32_t len = -1;
79     SessionPktType type = TRANS_SESSION_BYTES;
80     int32_t ret = ClientTransAuthOnDataReceived(channelId, NULL, len, type);
81     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
82 
83     ret = ClientTransAuthOnDataReceived(channelId, NULL, len, type);
84     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
85 }
86 } // namespace OHOS