• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2025 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 #include "ime_state_manager_factory.h"
16 #include <gtest/gtest.h>
17 
18 using namespace testing::ext;
19 namespace OHOS {
20 namespace MiscServices {
21 class ImeStateManagerFactoryTest : public testing::Test {
22 protected:
SetUp()23     void SetUp() override
24     {
25         // Reset to default state before each test
26         ImeStateManagerFactory::GetInstance().SetDynamicStartIme(false);
27     }
28 };
29 
30 /**
31  * @tc.name: SetGetDynamicStartIme
32  * @tc.desc: Test Set/Get for boolean flag
33  * @tc.type: FUNC
34  */
35 HWTEST_F(ImeStateManagerFactoryTest, SetGetDynamicStartIme, TestSize.Level1)
36 {
37     auto &factory = ImeStateManagerFactory::GetInstance();
38 
39     factory.SetDynamicStartIme(true);
40     EXPECT_TRUE(factory.GetDynamicStartIme());
41 
42     factory.SetDynamicStartIme(false);
43     EXPECT_FALSE(factory.GetDynamicStartIme());
44 }
45 
46 /**
47  * @tc.name: SingletonInstance
48  * @tc.desc: Test singleton instance consistency
49  * @tc.type: FUNC
50  */
51 HWTEST_F(ImeStateManagerFactoryTest, SingletonInstance, TestSize.Level1)
52 {
53     auto &instance1 = ImeStateManagerFactory::GetInstance();
54     auto &instance2 = ImeStateManagerFactory::GetInstance();
55     ASSERT_EQ(&instance1, &instance2);
56 }
57 
58 /**
59  * @tc.name: CreateImeLifecycleManagerWhenDynamic
60  * @tc.desc: Test object creation in dynamic mode
61  * @tc.type: FUNC
62  */
63 HWTEST_F(ImeStateManagerFactoryTest, CreateImeLifecycleManagerWhenDynamic, TestSize.Level1)
64 {
65     auto &factory = ImeStateManagerFactory::GetInstance();
66     factory.SetDynamicStartIme(true);
__anon42cd14a20102null67     auto manager = factory.CreateImeStateManager(0, [] {
68         return;
69     });
70 
71     EXPECT_NE(manager.get(), nullptr);
72 }
73 
74 /**
75  * @tc.name: CreateFreezeManagerWhenNotDynamic
76  * @tc.desc: Test object creation in non-dynamic mode
77  * @tc.type: FUNC
78  */
79 HWTEST_F(ImeStateManagerFactoryTest, CreateFreezeManagerWhenNotDynamic, TestSize.Level1)
80 {
81     auto &factory = ImeStateManagerFactory::GetInstance();
82     factory.SetDynamicStartIme(false); // Explicit set for clarity
83     // stopFunc should be ignored in this mode
__anon42cd14a20202null84     auto manager = factory.CreateImeStateManager(0, [] {
85         FAIL() << "Should not be called";
86     });
87 
88     // Verify type
89     EXPECT_NE(manager.get(), nullptr);
90 }
91 } // namespace MiscServices
92 } // namespace OHOS