• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #define private public
16 #define protected public
17 #include "input_method_controller.h"
18 #include "input_method_system_ability.h"
19 #undef private
20 
21 #include <gtest/gtest.h>
22 #include <sys/time.h>
23 #include <unistd.h>
24 
25 #include <string>
26 #include <vector>
27 
28 #include "application_info.h"
29 #include "global.h"
30 using namespace testing::ext;
31 namespace OHOS {
32 namespace MiscServices {
33 class InputMethodPrivateMemberTest : public testing::Test {
34 public:
35     static void SetUpTestCase(void);
36     static void TearDownTestCase(void);
37     void SetUp();
38     void TearDown();
39 };
40 constexpr std::int32_t MAIN_USER_ID = 100;
SetUpTestCase(void)41 void InputMethodPrivateMemberTest::SetUpTestCase(void)
42 {
43     IMSA_HILOGI("InputMethodPrivateMemberTest::SetUpTestCase");
44 }
45 
TearDownTestCase(void)46 void InputMethodPrivateMemberTest::TearDownTestCase(void)
47 {
48     IMSA_HILOGI("InputMethodPrivateMemberTest::TearDownTestCase");
49 }
50 
SetUp(void)51 void InputMethodPrivateMemberTest::SetUp(void)
52 {
53     IMSA_HILOGI("InputMethodPrivateMemberTest::SetUp");
54 }
55 
TearDown(void)56 void InputMethodPrivateMemberTest::TearDown(void)
57 {
58     IMSA_HILOGI("InputMethodPrivateMemberTest::TearDown");
59 }
60 
61 /**
62 * @tc.name: testInputMethodServiceStartAbnormal
63 * @tc.desc: SystemAbility testInputMethodServiceStartAbnormal.
64 * @tc.type: FUNC
65 * @tc.require: issuesI640YZ
66 */
67 HWTEST_F(InputMethodPrivateMemberTest, testInputMethodServiceStartAbnormal, TestSize.Level0)
68 {
69     IMSA_HILOGI("SystemAbility testInputMethodServiceStartAbnormal Test START");
70     auto service = new InputMethodSystemAbility();
71     service->state_ = ServiceRunningState::STATE_RUNNING;
72     service->OnStart();
73 
74     EXPECT_NE(service->userId_, MAIN_USER_ID);
75     EXPECT_TRUE(service->userSessions.empty());
76     EXPECT_TRUE(InputMethodSystemAbility::serviceHandler_ == nullptr);
77     EXPECT_TRUE(service->msgHandlers.empty());
78 
79     service->OnStop();
80     EXPECT_EQ(service->state_, ServiceRunningState::STATE_NOT_START);
81     service->OnStop();
82     delete service;
83     service = nullptr;
84 }
85 
86 /**
87 * @tc.name: testGetExtends
88 * @tc.desc: SystemAbility GetExtends.
89 * @tc.type: FUNC
90 * @tc.require: issuesI640YZ
91 */
92 HWTEST_F(InputMethodPrivateMemberTest, testSystemAbilityGetExtends, TestSize.Level0)
93 {
94     IMSA_HILOGI("SystemAbility testSystemAbilityGetExtends Test START");
95     constexpr int32_t metaDataNums = 5;
96     InputMethodSystemAbility service;
97     std::vector<Metadata> metaData;
98     Metadata metadata[metaDataNums] = { { "language", "english", "" }, { "mode", "mode", "" },
99         { "locale", "local", "" }, { "icon", "icon", "" }, { "", "", "" } };
100     for (auto const &data : metadata) {
101         metaData.emplace_back(data);
102     }
103     auto subProperty = service.GetExtends(metaData);
104     EXPECT_EQ(subProperty.language, "english");
105     EXPECT_EQ(subProperty.mode, "mode");
106     EXPECT_EQ(subProperty.locale, "local");
107     EXPECT_EQ(subProperty.icon, "icon");
108 }
109 
110 /**
111 * @tc.name: testOnPackageRemoved
112 * @tc.desc: SystemAbility OnPackageRemoved.
113 * @tc.type: FUNC
114 * @tc.require: issuesI640YZ
115 */
116 HWTEST_F(InputMethodPrivateMemberTest, testOnPackageRemoved, TestSize.Level0)
117 {
118     IMSA_HILOGI("SystemAbility testOnPackageRemoved Test START");
119     constexpr int32_t messageId = 5;
120     InputMethodSystemAbility service;
121     auto *msg = new Message(messageId, nullptr);
122     auto ret = service.OnPackageRemoved(msg);
123     EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
124     delete msg;
125     msg = nullptr;
126 }
127 } // namespace MiscServices
128 } // namespace OHOS
129