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 "tester.h"
17
18 #include <thread>
19 #include <unistd.h>
20
21 #include "window_manager_hilog.h"
22
23 namespace OHOS {
24 namespace {
25 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0, "WMTester"};
26 } // namespace
27
Get()28 Tester &Tester::Get()
29 {
30 static Tester instance;
31 return instance;
32 }
33
NeedReturnTestNew(const std::string & str)34 bool Tester::NeedReturnTestNew(const std::string &str)
35 {
36 bool isFound = set.find(str) != set.end();
37 WMLOGFD("NeedReturnTestNew: %{public}s %{public}d", str.c_str(), isFound);
38 return isFound;
39 }
40
ReturnTestNew(const std::string & str)41 void *Tester::ReturnTestNew(const std::string &str)
42 {
43 auto ret = ptrs[str];
44 WMLOGFD("ReturnTestNew: %{public}s %{public}p", str.c_str(), ret);
45 set.erase(str);
46 ptrs.erase(str);
47 return ret;
48 }
49
SetTestNew(const std::string & str,void * ptr)50 void Tester::SetTestNew(const std::string &str, void *ptr)
51 {
52 WMLOGFD("SetTestNew: %{public}s %{public}p", str.c_str(), ptr);
53 set.insert(str);
54 ptrs[str] = ptr;
55 }
56
ScheduleForConcurrent()57 void Tester::ScheduleForConcurrent()
58 {
59 if (needSchedule == true) {
60 WMLOGFD("need schedule");
61 needSchedule = false;
62 sleep(0);
63 }
64 }
65
SetSchedule()66 void Tester::SetSchedule()
67 {
68 WMLOGFD("set schedule");
69 needSchedule = true;
70 }
71 } // namespace OHOS
72