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