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 <gtest/gtest.h>
17
18 #define private public
19 #include "delegator_thread.h"
20 #undef private
21
22 #include "hilog_tag_wrapper.h"
23
24 using namespace testing::ext;
25 using namespace OHOS;
26 using namespace OHOS::AppExecFwk;
27
28 namespace {
29 bool callbackModuleFlag;
30 }
31
32 class DelegatorThreadModuleTest : public ::testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp() override;
37 void TearDown() override;
38 };
39
SetUpTestCase()40 void DelegatorThreadModuleTest::SetUpTestCase()
41 {}
42
TearDownTestCase()43 void DelegatorThreadModuleTest::TearDownTestCase()
44 {}
45
SetUp()46 void DelegatorThreadModuleTest::SetUp()
47 {}
48
TearDown()49 void DelegatorThreadModuleTest::TearDown()
50 {}
51
52 namespace {
CallBackModuleFunc()53 void CallBackModuleFunc()
54 {
55 TAG_LOGI(AAFwkTag::TEST, "CallBackModuleFunc is called");
56 callbackModuleFlag = true;
57 }
58 }
59
60 /**
61 * @tc.number: Delegator_Thread_Module_Test_0100
62 * @tc.name: Run
63 * @tc.desc: Verify the Run is valid.
64 */
65 HWTEST_F(DelegatorThreadModuleTest, Delegator_Thread_Module_Test_0100, Function | MediumTest | Level1)
66 {
67 TAG_LOGI(AAFwkTag::TEST, "Delegator_Thread_Module_Test_0100 is called");
68
69 callbackModuleFlag = false;
70 DelegatorThread threadObj(true);
71 std::function<void()> fun = CallBackModuleFunc;
72 EXPECT_TRUE(threadObj.Run(fun));
73 }
74
75 /**
76 * @tc.number: Delegator_Thread_Module_Test_0200
77 * @tc.name: GetThreadName
78 * @tc.desc: Verify the GetThreadName.
79 */
80 HWTEST_F(DelegatorThreadModuleTest, Delegator_Thread_Module_Test_0200, Function | MediumTest | Level1)
81 {
82 TAG_LOGI(AAFwkTag::TEST, "Delegator_Thread_Module_Test_0200 is called");
83
84 DelegatorThread threadObj(false);
85 EXPECT_EQ(threadObj.GetThreadName(), "");
86 }
87