• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <thread>
18 
19 #include "iptables_wrapper.h"
20 #include "net_manager_constants.h"
21 #include "netnative_log_wrapper.h"
22 
23 namespace OHOS {
24 namespace NetsysNative {
25 using namespace testing::ext;
26 using namespace OHOS::nmd;
27 class IptablesWrapperTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp();
32     void TearDown();
33 };
34 
SetUpTestCase()35 void IptablesWrapperTest::SetUpTestCase() {}
36 
TearDownTestCase()37 void IptablesWrapperTest::TearDownTestCase() {}
38 
SetUp()39 void IptablesWrapperTest::SetUp() {}
40 
TearDown()41 void IptablesWrapperTest::TearDown() {}
42 
43 HWTEST_F(IptablesWrapperTest, RunCommandTest001, TestSize.Level1)
44 {
45     NETNATIVE_LOGI("RunCommandTest001 enter");
46     std::shared_ptr<IptablesWrapper> wrapper = DelayedSingleton<IptablesWrapper>::GetInstance();
47     std::string comdLine = "-L -n";
48     std::string str = wrapper->RunCommandForRes(IpType::IPTYPE_IPV4, comdLine);
49     const uint32_t waiteMS1 = 500;
50     std::this_thread::sleep_for(std::chrono::milliseconds(waiteMS1));
51     std::cout << str << std::endl;
52     int32_t ret = wrapper->RunCommand(IpType::IPTYPE_IPV4, comdLine);
53     EXPECT_EQ(ret, NetManagerStandard::NETMANAGER_SUCCESS);
54     const uint32_t waiteMS2 = 100;
55     std::this_thread::sleep_for(std::chrono::milliseconds(waiteMS2));
56 }
57 } // namespace NetsysNative
58 } // namespace OHOS
59