• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 iSoftStone Information Technology (Group) 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 "gtest/gtest.h"
17 
18 #define private public
19 #define protected public
20 #include "test/mock/base/mock_task_executor.h"
21 #include "test/mock/core/common/mock_container.h"
22 
23 #include "core/common/thread_checker.h"
24 #undef private
25 #undef protected
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS::Ace {
31 class ThreadCheckerTest : public testing::Test {
32 public:
33     static void SetUpTestSuite();
34     static void TearDownTestSuite();
35 };
36 
SetUpTestSuite()37 void ThreadCheckerTest::SetUpTestSuite()
38 {
39     MockContainer::SetUp();
40 }
41 
TearDownTestSuite()42 void ThreadCheckerTest::TearDownTestSuite()
43 {
44     MockContainer::TearDown();
45 }
46 
47 /**
48  * @tc.name: ThreadCheckerGetThread
49  * @tc.desc: Test cast to ThreadCheckerTest
50  * @tc.type: FUNC
51  */
52 HWTEST_F(ThreadCheckerTest, ThreadCheckerGetThread, TestSize.Level1)
53 {
54     MockContainer::Current()->taskExecutor_ = AceType::MakeRefPtr<MockTaskExecutor>();
55     EXPECT_TRUE(CheckThread(TaskExecutor::TaskType::UI));
56     EXPECT_TRUE(CheckThread(TaskExecutor::TaskType::JS));
57     EXPECT_FALSE(CheckThread(TaskExecutor::TaskType::UNKNOWN));
58 }
59 } // namespace OHOS::Ace
60