• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_detection_callback_test.h"
17 
18 #include <iostream>
19 
20 namespace OHOS {
21 namespace NetManagerStandard {
NetDetectionCallbackTest()22 NetDetectionCallbackTest::NetDetectionCallbackTest() {}
23 
~NetDetectionCallbackTest()24 NetDetectionCallbackTest::~NetDetectionCallbackTest() {}
25 
NotifyAll()26 void NetDetectionCallbackTest::NotifyAll()
27 {
28     std::unique_lock<std::mutex> callbackLock(callbackMutex_);
29     cv_.notify_all();
30 }
31 
WaitFor(int timeoutSecond)32 void NetDetectionCallbackTest::WaitFor(int timeoutSecond)
33 {
34     std::unique_lock<std::mutex> callbackLock(callbackMutex_);
35     netDetectionResult_ = static_cast<int32_t>(NetDetectionResultCode::NET_DETECTION_FAIL);
36     urlRedirect_.clear();
37     cv_.wait_for(callbackLock, std::chrono::seconds(timeoutSecond));
38 }
39 
OnNetDetectionResultChanged(NetDetectionResultCode detectionResult,const std::string & urlRedirect)40 int32_t NetDetectionCallbackTest::OnNetDetectionResultChanged(
41     NetDetectionResultCode detectionResult, const std::string &urlRedirect)
42 {
43     netDetectionResult_ = static_cast<int32_t>(detectionResult);
44     urlRedirect_ = urlRedirect;
45     switch (detectionResult) {
46         case NetDetectionResultCode::NET_DETECTION_FAIL:
47             std::cout << "NetDetectionResultCode::NET_DETECTION_FAIL" << std::endl;
48             break;
49         case NetDetectionResultCode::NET_DETECTION_SUCCESS:
50             std::cout << "NetDetectionResultCode::NET_DETECTION_SUCCESS" << std::endl;
51             break;
52         case NetDetectionResultCode::NET_DETECTION_CAPTIVE_PORTAL:
53             std::cout << "NetDetectionResultCode::NET_DETECTION_CAPTIVE_PORTAL" << std::endl;
54             break;
55         default:
56             break;
57     }
58     std::cout << "TestNetConnCallback::OnNetDetectionResultChanged detectionResult:" << netDetectionResult_
59               << " urlRedirect:" << urlRedirect_ << std::endl;
60     NotifyAll();
61     return 0;
62 }
63 } // namespace NetManagerStandard
64 } // namespace OHOS
65