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 #ifndef NET_STATS_CALLBACK_TEST_H 17 #define NET_STATS_CALLBACK_TEST_H 18 19 #include <mutex> 20 #include <condition_variable> 21 22 #include "net_stats_callback_stub.h" 23 #include "net_stats_constants.h" 24 25 namespace OHOS { 26 namespace NetManagerStandard { 27 class NetStatsCallbackTest : public NetStatsCallbackStub { 28 public: 29 NetStatsCallbackTest(); 30 ~NetStatsCallbackTest() override; 31 int32_t NetIfaceStatsChanged(const std::string &iface) override; 32 int32_t NetUidStatsChanged(const std::string &iface, uint32_t uid) override; 33 void WaitFor(int32_t timeoutSecond); 34 GetIface()35 std::string GetIface() const 36 { 37 return iface_; 38 } GetUid()39 uint32_t GetUid() const 40 { 41 return uid_; 42 } 43 44 private: 45 void NotifyAll(); 46 std::string iface_ = "eth0"; 47 uint32_t uid_ = 0; 48 std::mutex callbackMutex_; 49 std::condition_variable cv_; 50 }; 51 } // namespace NetManagerStandard 52 } // namespace OHOS 53 #endif // NET_STATS_CALLBACK_TEST_H 54