1 /*
2  * Copyright (c) 2024 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 #include <gtest/gtest.h>
16 #include "softbus_error_code.h"
17 
18 #include "session_mock.h"
19 #include "session_set_timer.h"
20 
21 using namespace testing::ext;
22 namespace OHOS {
23 class SessionMockTest : public testing::Test {
24     public:
SessionMockTest()25     SessionMockTest()
26     {}
~SessionMockTest()27     ~SessionMockTest()
28     {}
29     static void SetUpTestCase(void);
30     static void TearDownTestCase(void);
SetUp()31     void SetUp() override
32     {}
TearDown()33     void TearDown() override
34     {}
35 };
36 
SetUpTestCase(void)37 void SessionMockTest::SetUpTestCase(void) { }
38 
TearDownTestCase(void)39 void SessionMockTest::TearDownTestCase(void) { }
40 constexpr int INVALID_ID = -1;
41 /*
42  * @tc.name: SessionMockTest
43  * @tc.desc: SessionMock functions test.
44  * @tc.type: FUNC
45  * @tc.require:
46  */
47 HWTEST_F(SessionMockTest, SessionMockTest001, TestSize.Level1)
48 {
49     int32_t sessionId = INVALID_ID;
50     char *data = NULL;
51     uint16_t len = 0; // len initializes to 0
52     int32_t ret = GetPkgNameInner(sessionId, data, len);
53     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
54 
55     ret = GetPeerDeviceIdInner(sessionId, data, len);
56     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
57 
58     ret = GetPeerSessionNameInner(sessionId, data, len);
59     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
60 
61     ret = GetMySessionNameInner(sessionId, data, len);
62     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
63 
64     int *pData = NULL;
65     ret = GetPeerPidInner(sessionId, pData);
66     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
67 
68     ret = GetPeerUidInner(sessionId, pData);
69     EXPECT_EQ(ret, SOFTBUS_INVALID_PARAM);
70 }
71 
72 /*
73  * @tc.name: SessionMockTest
74  * @tc.desc: SetTimer test.
75  * @tc.type: FUNC
76  * @tc.require:
77  */
78 HWTEST_F(SessionMockTest, SessionMockTest002, TestSize.Level1)
79 {
80     const char *name = NULL;
81     unsigned int timeout = 0; // timeout initializes to 0
82     int ret = SetTimer(name, timeout);
83     EXPECT_EQ(ret, INVALID_ID);
84 }
85 }