1 /*
2 * Copyright (C) 2021 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 "net_stats_callback_test.h"
17
18 #include "net_stats_constants.h"
19 #include "net_mgr_log_wrapper.h"
20
21 namespace OHOS {
22 namespace NetManagerStandard {
NetStatsCallbackTest()23 NetStatsCallbackTest::NetStatsCallbackTest() {}
24
~NetStatsCallbackTest()25 NetStatsCallbackTest::~NetStatsCallbackTest() {}
26
NotifyAll()27 void NetStatsCallbackTest::NotifyAll()
28 {
29 std::unique_lock<std::mutex> callbackLock(callbackMutex_);
30 cv_.notify_all();
31 }
32
WaitFor(int32_t timeoutSecond)33 void NetStatsCallbackTest::WaitFor(int32_t timeoutSecond)
34 {
35 std::unique_lock<std::mutex> callbackLock(callbackMutex_);
36 cv_.wait_for(callbackLock, std::chrono::seconds(timeoutSecond));
37 }
38
NetIfaceStatsChanged(const std::string & iface)39 int32_t NetStatsCallbackTest::NetIfaceStatsChanged(const std::string &iface)
40 {
41 NETMGR_LOG_D("unittest NetIfaceStatsChanged, iface[%{public}s]", iface.c_str());
42
43 iface_ = iface;
44 NotifyAll();
45
46 return 0;
47 }
48
NetUidStatsChanged(const std::string & iface,uint32_t uid)49 int32_t NetStatsCallbackTest::NetUidStatsChanged(const std::string &iface, uint32_t uid)
50 {
51 NETMGR_LOG_D("unittest NetIfaceStatsChanged, iface[%{public}s], uid[%{public}d]", iface.c_str(), uid);
52 iface_ = iface;
53 uid_ = uid;
54 NotifyAll();
55 return 0;
56 }
57 } // namespace NetManagerStandard
58 } // namespace OHOS
59