!507 修改&增加tdd测试用例

Merge pull request !507 from cy7717/master
This commit is contained in:
openharmony_ci 2022-12-15 08:10:30 +00:00 committed by Gitee
commit 52627190b3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 272 additions and 19 deletions

View File

@ -91,7 +91,10 @@ ohos_unittest("InputMethodAbilityTest") {
ohos_unittest("InputMethodServiceTest") {
module_out_path = module_output_path
sources = [ "src/input_method_service_test.cpp" ]
sources = [
"src/input_method_service_test.cpp",
"src/permission_verification_execption_test.cpp",
]
configs = [ ":module_private_config" ]
@ -193,6 +196,7 @@ ohos_unittest("InputMethodPrivateMemberTest") {
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"hiviewdfx_hilog_native:libhilog",
"imf:inputmethod_client",
"ipc:ipc_core",
"ipc:ipc_single",
]

View File

@ -14,13 +14,15 @@
*/
#define private public
#define protected public
#include "input_method_controller.h"
#include "input_method_system_ability.h"
#undef private
#include <gtest/gtest.h>
#include <string>
#include <sys/time.h>
#include <unistd.h>
#include <string>
#include <vector>
#include "application_info.h"
@ -57,14 +59,13 @@ void InputMethodPrivateMemberTest::TearDown(void)
}
/**
* @tc.name: testInputMethodServiceStartAbnormal
* @tc.desc: SystemAbility testInputMethodServiceStartAbnormal.
* @tc.name: SA_ServiceStartAbnormal
* @tc.desc: SA Service Start Abnormal.
* @tc.type: FUNC
* @tc.require: issuesI640YZ
*/
HWTEST_F(InputMethodPrivateMemberTest, testInputMethodServiceStartAbnormal, TestSize.Level0)
HWTEST_F(InputMethodPrivateMemberTest, SA_ServiceStartAbnormal, TestSize.Level0)
{
IMSA_HILOGI("SystemAbility testInputMethodServiceStartAbnormal Test START");
auto service = new InputMethodSystemAbility();
service->state_ = ServiceRunningState::STATE_RUNNING;
service->OnStart();
@ -82,14 +83,13 @@ HWTEST_F(InputMethodPrivateMemberTest, testInputMethodServiceStartAbnormal, Test
}
/**
* @tc.name: testGetExtends
* @tc.desc: SystemAbility GetExtends.
* @tc.name: SA_GetExtends
* @tc.desc: SA GetExtends.
* @tc.type: FUNC
* @tc.require: issuesI640YZ
*/
HWTEST_F(InputMethodPrivateMemberTest, testSystemAbilityGetExtends, TestSize.Level0)
HWTEST_F(InputMethodPrivateMemberTest, SA_GetExtends, TestSize.Level0)
{
IMSA_HILOGI("SystemAbility testSystemAbilityGetExtends Test START");
constexpr int32_t metaDataNums = 5;
InputMethodSystemAbility service;
std::vector<Metadata> metaData;
@ -106,14 +106,13 @@ HWTEST_F(InputMethodPrivateMemberTest, testSystemAbilityGetExtends, TestSize.Lev
}
/**
* @tc.name: testOnHandleMessage
* @tc.desc: SystemAbility OnHandleMessage.
* @tc.name: SA_OnHandleMessageWithoutMessageHandler
* @tc.desc: SA OnHandleMessage Without MessageHandler.
* @tc.type: FUNC
* @tc.require: issuesI640YZ
*/
HWTEST_F(InputMethodPrivateMemberTest, testOnHandleMessage, TestSize.Level0)
HWTEST_F(InputMethodPrivateMemberTest, SA_OnHandleMessageWithoutMessageHandler, TestSize.Level0)
{
IMSA_HILOGI("SystemAbility testOnHandleMessage Test START");
constexpr int32_t messageId = 5;
InputMethodSystemAbility service;
auto *parcel = new MessageParcel();
@ -126,21 +125,159 @@ HWTEST_F(InputMethodPrivateMemberTest, testOnHandleMessage, TestSize.Level0)
}
/**
* @tc.name: testOnPackageRemoved
* @tc.desc: SystemAbility OnPackageRemoved.
* @tc.name: SA_OnPackageRemovedWithNullMessage
* @tc.desc: SA OnPackageRemoved With Null Message.
* @tc.type: FUNC
* @tc.require: issuesI640YZ
*/
HWTEST_F(InputMethodPrivateMemberTest, testOnPackageRemoved, TestSize.Level0)
HWTEST_F(InputMethodPrivateMemberTest, SA_OnPackageRemovedWithNullMessage, TestSize.Level0)
{
IMSA_HILOGI("SystemAbility testOnPackageRemoved Test START");
constexpr int32_t messageId = 5;
InputMethodSystemAbility service;
constexpr int32_t messageId = 5;
auto *msg = new Message(messageId, nullptr);
auto ret = service.OnPackageRemoved(msg);
EXPECT_EQ(ret, ErrorCode::ERROR_NULL_POINTER);
delete msg;
msg = nullptr;
}
/**
* @tc.name: SA_OnUserStartedWithNullMessage
* @tc.desc: SA OnUserStarted With Null Message.
* @tc.type: FUNC
* @tc.require: issuesI669E8
*/
HWTEST_F(InputMethodPrivateMemberTest, SA_OnUserStartedWithNullMessage, TestSize.Level0)
{
InputMethodSystemAbility service;
constexpr int32_t messageId = 5;
auto *msg = new Message(messageId, nullptr);
auto ret = service.OnUserStarted(msg);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
delete msg;
msg = nullptr;
}
/**
* @tc.name: SA_ListDisabledInputMethodWithInexistentUserId
* @tc.desc: SA ListDisabledInputMethod With Inexistent UserId.
* @tc.type: FUNC
* @tc.require: issuesI669E8
*/
HWTEST_F(InputMethodPrivateMemberTest, SA_ListDisabledInputMethodWithInexistentUserId, TestSize.Level0)
{
InputMethodSystemAbility service;
constexpr int32_t userId = 1;
std::vector<Property> props;
auto ret = service.ListDisabledInputMethod(userId, props);
EXPECT_EQ(ret, ErrorCode::ERROR_PACKAGE_MANAGER);
EXPECT_TRUE(props.empty());
}
/**
* @tc.name: SA_ListInputMethodInfoWithInexistentUserId
* @tc.desc: SA ListInputMethodInfo With Inexistent UserId.
* @tc.type: FUNC
* @tc.require: issuesI669E8
*/
HWTEST_F(InputMethodPrivateMemberTest, SA_ListInputMethodInfoWithInexistentUserId, TestSize.Level0)
{
InputMethodSystemAbility service;
constexpr int32_t userId = 1;
auto inputMethodInfos = service.ListInputMethodInfo(userId);
EXPECT_TRUE(inputMethodInfos.empty());
}
/**
* @tc.name: SA_ListSubtypeByBundleNameWithInexistentUserId
* @tc.desc: SA ListSubtypeByBundleName With Inexistent UserId.
* @tc.type: FUNC
* @tc.require: issuesI669E8
*/
HWTEST_F(InputMethodPrivateMemberTest, SA_ListSubtypeByBundleNameWithInexistentUserId, TestSize.Level0)
{
InputMethodSystemAbility service;
constexpr int32_t userId = 1;
std::vector<SubProperty> subProps;
auto ret = service.ListSubtypeByBundleName(userId, "", subProps);
EXPECT_EQ(ret, ErrorCode::ERROR_PACKAGE_MANAGER);
EXPECT_TRUE(subProps.empty());
}
/**
* @tc.name: SA_GetUserSessionWithInexistentUserId
* @tc.desc: SA GetUserSession With Inexistent UserId.
* @tc.type: FUNC
* @tc.require: issuesI669E8
*/
HWTEST_F(InputMethodPrivateMemberTest, SA_GetUserSessionWithInexistentUserId, TestSize.Level0)
{
InputMethodSystemAbility service;
constexpr int32_t userId = 1;
auto perUserSession = service.GetUserSession(userId);
EXPECT_TRUE(perUserSession == nullptr);
}
/**
* @tc.name: SA_FindSubPropertyWithInexistentSubLabel
* @tc.desc: SA ListSubtypeByBundleName With Inexistent UserId.
* @tc.type: FUNC
* @tc.require: issuesI669E8
*/
HWTEST_F(InputMethodPrivateMemberTest, SA_FindSubPropertyWithInexistentSubLabel, TestSize.Level0)
{
InputMethodSystemAbility service;
auto prop = service.GetCurrentInputMethod();
ASSERT_TRUE(prop != nullptr);
auto subProp = service.FindSubProperty(prop->name, "");
EXPECT_EQ(subProp.name, "");
}
/**
* @tc.name: SA_FindSubPropertyByCompareWithNullBundleName
* @tc.desc: SA FindSubPropertyByCompare With Null BundleName
* @tc.type: FUNC
* @tc.require: issuesI669E8
*/
HWTEST_F(InputMethodPrivateMemberTest, SA_FindSubPropertyByCompareWithNullBundleName, TestSize.Level0)
{
InputMethodSystemAbility service;
InputMethodSystemAbility::CompareHandler compare;
auto subProp = service.FindSubPropertyByCompare("", compare);
EXPECT_EQ(subProp.label, "");
}
/**
* @tc.name: SA_FindSubPropertyByCompare
* @tc.desc: SA FindSubPropertyByCompare
* @tc.type: FUNC
* @tc.require: issuesI669E8
*/
HWTEST_F(InputMethodPrivateMemberTest, SA_FindSubPropertyByCompare, TestSize.Level0)
{
InputMethodSystemAbility service;
auto prop = service.GetCurrentInputMethod();
ASSERT_TRUE(prop != nullptr);
auto subProp = service.GetCurrentInputMethodSubtype();
ASSERT_TRUE(subProp != nullptr);
auto subProp1 = service.FindSubPropertyByCompare(
prop->name, [subProp](const SubProperty &subProperty) { return subProperty.mode == subProp->mode; });
EXPECT_EQ(subProp1.mode, subProp->mode);
EXPECT_EQ(subProp1.label, subProp->label);
}
/**
* @tc.name: IMC_ListInputMethodCommonWithErrorStatus
* @tc.desc: IMC ListInputMethodCommon With Error Status.
* @tc.type: FUNC
* @tc.require: issuesI669E8
*/
HWTEST_F(InputMethodPrivateMemberTest, IMC_ListInputMethodCommonWithErrorStatus, TestSize.Level0)
{
std::vector<Property> props;
auto ret = InputMethodController::GetInstance()->ListInputMethodCommon(static_cast<InputMethodStatus>(5), props);
EXPECT_EQ(ret, ErrorCode::ERROR_BAD_PARAMETERS);
EXPECT_TRUE(props.empty());
}
} // namespace MiscServices
} // namespace OHOS

View File

@ -0,0 +1,112 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <gtest/gtest.h>
#include <sys/time.h>
#include <unistd.h>
#include <cstdint>
#include <string>
#include "global.h"
#include "input_method_controller.h"
#include "securec.h"
using namespace testing::ext;
namespace OHOS {
namespace MiscServices {
class PermissionVerficationExceptionTest : public testing::Test {
public:
static void SetUpTestCase(void);
static void TearDownTestCase(void);
void SetUp();
void TearDown();
static sptr<InputMethodController> imc_;
};
sptr<InputMethodController> PermissionVerficationExceptionTest::imc_;
void PermissionVerficationExceptionTest::SetUpTestCase(void)
{
IMSA_HILOGI("PermissionVerficationExceptionTest::SetUpTestCase");
}
void PermissionVerficationExceptionTest::TearDownTestCase(void)
{
IMSA_HILOGI("PermissionVerficationExceptionTest::TearDownTestCase");
}
void PermissionVerficationExceptionTest::SetUp(void)
{
imc_ = InputMethodController::GetInstance();
IMSA_HILOGI("PermissionVerficationExceptionTest::SetUp");
}
void PermissionVerficationExceptionTest::TearDown(void)
{
IMSA_HILOGI("PermissionVerficationExceptionTest::TearDown");
}
/**
* @tc.name: ShowSoftKeyboard
* @tc.desc: PermissionVerficationExceptionTest ShowSoftKeyboard.
* @tc.type: FUNC
* @tc.require: issuesI640YZ
*/
HWTEST_F(PermissionVerficationExceptionTest, ShowSoftKeyboard, TestSize.Level0)
{
int32_t ret = PermissionVerficationExceptionTest::imc_->ShowSoftKeyboard();
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
}
/**
* @tc.name: HideSoftKeyboard
* @tc.desc: PermissionVerficationExceptionTest HideSoftKeyboard.
* @tc.type: FUNC
* @tc.require: issuesI640YZ
*/
HWTEST_F(PermissionVerficationExceptionTest, HideSoftKeyboard, TestSize.Level0)
{
int32_t ret = PermissionVerficationExceptionTest::imc_->HideSoftKeyboard();
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
}
/**
* @tc.name: DisplayOptionalInputMethod
* @tc.desc: PermissionVerficationExceptionTest DisplayOptionalInputMethod.
* @tc.type: FUNC
* @tc.require: issuesI640YZ
*/
HWTEST_F(PermissionVerficationExceptionTest, DisplayOptionalInputMethod, TestSize.Level0)
{
int32_t ret = PermissionVerficationExceptionTest::imc_->ShowOptionalInputMethod();
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
}
/**
* @tc.name: SwitchInputMethod
* @tc.desc: PermissionVerficationExceptionTest SwitchInputMethod.
* @tc.type: FUNC
* @tc.require: issuesI640YZ
*/
HWTEST_F(PermissionVerficationExceptionTest, SwitchInputMethod, TestSize.Level0)
{
auto property = PermissionVerficationExceptionTest::imc_->GetCurrentInputMethod();
ASSERT_TRUE(property != nullptr);
auto subProperty = PermissionVerficationExceptionTest::imc_->GetCurrentInputMethodSubtype();
ASSERT_TRUE(subProperty != nullptr);
int32_t ret = PermissionVerficationExceptionTest::imc_->SwitchInputMethod(property->name, subProperty->label);
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
}
} // namespace MiscServices
} // namespace OHOS