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 "message_parcel.h"
19 #include "net_mgr_log_wrapper.h"
20 #include "route.h"
21 
22 namespace OHOS {
23 namespace NetManagerStandard {
24 using namespace testing::ext;
25 class RouteTest : public testing::Test {
26 public:
27     static void SetUpTestCase();
28     static void TearDownTestCase();
29     void SetUp();
30     void TearDown();
31 };
32 
SetUpTestCase()33 void RouteTest::SetUpTestCase() {}
34 
TearDownTestCase()35 void RouteTest::TearDownTestCase() {}
36 
SetUp()37 void RouteTest::SetUp() {}
38 
TearDown()39 void RouteTest::TearDown() {}
40 
41 /**
42  * @tc.name: operatorTest
43  * @tc.desc: Test Route::operator==
44  * @tc.type: FUNC
45  */
HWTEST_F(RouteTest, operatorTest, TestSize.Level1)46 HWTEST_F(RouteTest, operatorTest, TestSize.Level1)
47 {
48     Route routeScr;
49     routeScr.iface_ = "testIface";
50     Route routeDes = routeScr;
51     ASSERT_TRUE(routeDes.iface_ == routeScr.iface_);
52 }
53 
54 /**
55  * @tc.name: UnmarshallingTest
56  * @tc.desc: Test static Route::Marshalling
57  * @tc.type: FUNC
58  */
HWTEST_F(RouteTest, UnmarshallingTest, TestSize.Level1)59 HWTEST_F(RouteTest, UnmarshallingTest, TestSize.Level1)
60 {
61     MessageParcel data;
62     sptr<Route> route = new (std::nothrow) Route();
63     ASSERT_TRUE(route != nullptr);
64     bool bRet = Route::Marshalling(data, route);
65     ASSERT_TRUE(bRet == true);
66 
67     sptr<Route> retRoute = Route::Unmarshalling(data);
68     ASSERT_TRUE(retRoute != nullptr);
69     bRet = route->Marshalling(data);
70     ASSERT_TRUE(bRet == true);
71 }
72 
73 /**
74  * @tc.name: ToStringTest
75  * @tc.desc: Test Route::ToString
76  * @tc.type: FUNC
77  */
HWTEST_F(RouteTest, ToStringTest, TestSize.Level1)78 HWTEST_F(RouteTest, ToStringTest, TestSize.Level1)
79 {
80     sptr<Route> info = new (std::nothrow) Route();
81     ASSERT_TRUE(info != nullptr);
82 
83     std::string str = info->ToString("testTab");
84     NETMGR_LOG_D("Route.ToString string is : [%{public}s]", str.c_str());
85 }
86 } // namespace NetManagerStandard
87 } // namespace OHOS
88