• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 <iostream>
18 #include <memory>
19 #ifdef GTEST_API_
20 #define private public
21 #endif
22 #include "net_factoryreset_callback_stub.h"
23 
24 namespace OHOS {
25 namespace NetManagerStandard {
26 using namespace testing::ext;
27 class MockNetFactoryResetCallbackStubTest : public NetFactoryResetCallbackStub {
28 public:
29     MockNetFactoryResetCallbackStubTest() = default;
~MockNetFactoryResetCallbackStubTest()30     ~MockNetFactoryResetCallbackStubTest() override {}
OnNetFactoryReset()31     int32_t OnNetFactoryReset() override
32     {
33         std::cout << std::endl;
34         std::cout << "OnNetFactoryReset" << std::endl;
35         return 0;
36     }
37 };
38 
39 class NetFactoryResetCallbackStubTest : public testing::Test {
40 public:
41     static void SetUpTestCase();
42     static void TearDownTestCase();
43     void SetUp();
44     void TearDown();
45 
46     static inline std::shared_ptr<NetFactoryResetCallbackStub> instance_ =
47         std::make_shared<MockNetFactoryResetCallbackStubTest>();
48 };
49 
SetUpTestCase()50 void NetFactoryResetCallbackStubTest::SetUpTestCase() {}
51 
TearDownTestCase()52 void NetFactoryResetCallbackStubTest::TearDownTestCase() {}
53 
SetUp()54 void NetFactoryResetCallbackStubTest::SetUp() {}
55 
TearDown()56 void NetFactoryResetCallbackStubTest::TearDown() {}
57 
58 /**
59  * @tc.name: OnRemoteRequest001
60  * @tc.desc: Test NetDetectionCallbackStub OnRemoteRequest.
61  * @tc.type: FUNC
62  */
63 HWTEST_F(NetFactoryResetCallbackStubTest, OnRemoteRequest001, TestSize.Level1)
64 {
65     MessageParcel data;
66     MessageParcel reply;
67     MessageOption option;
68     int32_t ret = instance_->OnRemoteRequest(100, data, reply, option);
69     EXPECT_EQ(ret, NETMANAGER_ERR_DESCRIPTOR_MISMATCH);
70 
71     data.WriteInterfaceToken(NetFactoryResetCallbackStub::GetDescriptor());
72     ret = instance_->OnRemoteRequest(100, data, reply, option);
73     EXPECT_EQ(ret, IPC_STUB_UNKNOW_TRANS_ERR);
74 }
75 
76 /**
77  * @tc.name: OnNetDetectionResult001
78  * @tc.desc: Test NetDetectionCallbackStub OnNetDetectionResult.
79  * @tc.type: FUNC
80  */
81 HWTEST_F(NetFactoryResetCallbackStubTest, OnNetFactoryReset001, TestSize.Level1)
82 {
83     MessageParcel data;
84     MessageParcel reply;
85     MessageOption option;
86     data.WriteInterfaceToken(NetFactoryResetCallbackStub::GetDescriptor());
87     int32_t ret = instance_->OnRemoteRequest(static_cast<uint32_t>(FactoryResetCallbackInterfaceCode::NET_FACTORYRESET),
88                                              data, reply, option);
89     EXPECT_EQ(ret, NETSYS_SUCCESS);
90 }
91 
92 /**
93  * @tc.name: OnNetFactoryReset002
94  * @tc.desc: Test NetDetectionCallbackStub OnNetFactoryReset.
95  * @tc.type: FUNC
96  */
97 HWTEST_F(NetFactoryResetCallbackStubTest, OnNetFactoryReset002, TestSize.Level1)
98 {
99     int32_t ret = instance_->OnNetFactoryReset();
100     EXPECT_EQ(ret, NETMANAGER_SUCCESS);
101 }
102 } // namespace NetManagerStandard
103 } // namespace OHOS
104