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