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 "sms_mms_test_helper.h"
17
18 #include "tel_event_handler.h"
19 #include "telephony_log_wrapper.h"
20
21 namespace OHOS {
22 namespace Telephony {
Run(void (* func)(SmsMmsTestHelper &),SmsMmsTestHelper & helper,int32_t waitTime)23 bool SmsMmsTestHelper::Run(void (*func)(SmsMmsTestHelper &), SmsMmsTestHelper &helper, int32_t waitTime)
24 {
25 TelFFRTUtils::Submit([&]() { func(helper); });
26 TELEPHONY_LOGI("Thread running");
27 return WaitForResult(waitTime);
28 }
29
NotifyAll()30 void SmsMmsTestHelper::NotifyAll()
31 {
32 std::unique_lock<std::mutex> lock(mtx_);
33 cv_.notify_all();
34 TELEPHONY_LOGI("Thread NotifyAll");
35 }
36
WaitForResult(int32_t timeoutSecond)37 bool SmsMmsTestHelper::WaitForResult(int32_t timeoutSecond)
38 {
39 std::unique_lock<std::mutex> lock(mtx_);
40 if (cv_.wait_for(lock, std::chrono::seconds(timeoutSecond)) == std::cv_status::timeout) {
41 TELEPHONY_LOGI("Interface overtime");
42 return false;
43 }
44 return true;
45 }
46
SetBoolResult(bool result)47 void SmsMmsTestHelper::SetBoolResult(bool result)
48 {
49 boolResult_ = result;
50 TELEPHONY_LOGI("Set boolResult_ : %{public}d ", boolResult_);
51 }
52
SetSendSmsIntResult(int32_t result)53 void SmsMmsTestHelper::SetSendSmsIntResult(int32_t result)
54 {
55 sendSmsResult_ = result;
56 TELEPHONY_LOGI("Set sendSmsResult_ : %{public}d ", sendSmsResult_);
57 }
58
SetDeliverySmsIntResult(int32_t result)59 void SmsMmsTestHelper::SetDeliverySmsIntResult(int32_t result)
60 {
61 deliverySmsResult_ = result;
62 TELEPHONY_LOGI("Set deliverySmsResult_ : %{public}d ", deliverySmsResult_);
63 }
64
SetIntResult(int32_t result)65 void SmsMmsTestHelper::SetIntResult(int32_t result)
66 {
67 result_ = result;
68 }
69
SetStringResult(const std::string & str)70 void SmsMmsTestHelper::SetStringResult(const std::string &str)
71 {
72 strResult_ = str;
73 }
74
GetBoolResult()75 bool SmsMmsTestHelper::GetBoolResult()
76 {
77 TELEPHONY_LOGI("Get boolResult_ : %{public}d ", boolResult_);
78 return boolResult_;
79 }
80
GetSendSmsIntResult()81 int32_t SmsMmsTestHelper::GetSendSmsIntResult()
82 {
83 TELEPHONY_LOGI("Get sendSmsResult_ : %{public}d ", sendSmsResult_);
84 return sendSmsResult_;
85 }
86
GetDeliverySmsIntResult()87 int32_t SmsMmsTestHelper::GetDeliverySmsIntResult()
88 {
89 TELEPHONY_LOGI("Get deliverySmsResult_ : %{public}d ", deliverySmsResult_);
90 return deliverySmsResult_;
91 }
92
GetIntResult()93 int32_t SmsMmsTestHelper::GetIntResult()
94 {
95 TELEPHONY_LOGI("Get IntResult : %{public}d ", result_);
96 return result_;
97 }
98
GetStringResult()99 std::string SmsMmsTestHelper::GetStringResult()
100 {
101 return strResult_;
102 }
103 } // namespace Telephony
104 } // namespace OHOS
105