mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2025-01-10 02:41:41 +00:00
commit
e1bb941712
@ -22,6 +22,7 @@ group("core_common_unittest") {
|
||||
"clipboard:clip_board_test",
|
||||
"environment:environment_test",
|
||||
"flutter:flutter_test",
|
||||
"form:form_manager_test",
|
||||
"ime:ime_test",
|
||||
"plugin:plugin_manager_test",
|
||||
"register:register_test",
|
||||
|
38
test/unittest/core/common/form/BUILD.gn
Normal file
38
test/unittest/core/common/form/BUILD.gn
Normal file
@ -0,0 +1,38 @@
|
||||
# Copyright (c) 2023 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.
|
||||
|
||||
import("//build/test.gni")
|
||||
import("//foundation/arkui/ace_engine/ace_config.gni")
|
||||
import("//foundation/arkui/ace_engine/test/unittest/ace_unittest.gni")
|
||||
|
||||
ohos_unittest("form_manager_test") {
|
||||
module_out_path = "$basic_test_output_path/common"
|
||||
|
||||
sources = [
|
||||
"$ace_root/frameworks/core/common/form_manager.cpp",
|
||||
"$ace_root/frameworks/core/components_ng/test/pattern/form/mock/mock_sub_container.cpp",
|
||||
"$ace_root/frameworks/core/event/back_end_event_manager.cpp",
|
||||
"form_manager_test.cpp",
|
||||
]
|
||||
deps = [
|
||||
"$ace_root/frameworks/base:ace_memory_monitor_ohos",
|
||||
"$ace_root/test/unittest:ace_unittest_log",
|
||||
"$cjson_root:cjson_static",
|
||||
"//third_party/googletest:gmock_main",
|
||||
]
|
||||
|
||||
if (is_ohos_standard_system) {
|
||||
external_deps = [ "form_fwk:fmskit_native" ]
|
||||
}
|
||||
configs = [ "$ace_root/test/unittest:ace_unittest_config" ]
|
||||
}
|
103
test/unittest/core/common/form/form_manager_test.cpp
Normal file
103
test/unittest/core/common/form/form_manager_test.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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 "core/pipeline/pipeline_base.h"
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "test/unittest/core/common/form/mock_form_utils.h"
|
||||
|
||||
#include "core/common/form_manager.h"
|
||||
#include "core/components/form/sub_container.h"
|
||||
#undef private
|
||||
#undef protected
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS::Ace {
|
||||
namespace {
|
||||
const int64_t CARD_ID = 10000;
|
||||
} // namespace
|
||||
class FormManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase() {}
|
||||
static void TearDownTestCase() {}
|
||||
void SetUp() {}
|
||||
void TearDown() {}
|
||||
};
|
||||
|
||||
/**
|
||||
* @tc.name: AddSubContainer001
|
||||
* @tc.desc: Verify the AddSubContainer Interface of FormManager work correctly.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(FormManagerTest, AddPluginSubContainer001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Build a FormManager.
|
||||
*/
|
||||
FormManager formManager;
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. Add Sub Container.
|
||||
* @tc.expected: step2. Add Sub Container success.
|
||||
*/
|
||||
WeakPtr<PipelineBase> context = WeakPtr<PipelineBase>();
|
||||
RefPtr<SubContainer> subContainer = AceType::MakeRefPtr<SubContainer>(context.Upgrade());
|
||||
EXPECT_NE(subContainer, nullptr);
|
||||
formManager.AddSubContainer(CARD_ID, subContainer);
|
||||
EXPECT_NE(formManager.GetSubContainer(CARD_ID), nullptr);
|
||||
formManager.RemoveSubContainer(CARD_ID);
|
||||
EXPECT_EQ(formManager.GetSubContainer(CARD_ID), nullptr);
|
||||
|
||||
/**
|
||||
* @tc.steps: step3. Add Sub Container.
|
||||
* @tc.expected: step3. When Sub Container id is exsits ,try to replace it.
|
||||
*/
|
||||
RefPtr<SubContainer> secondSubContainer = AceType::MakeRefPtr<SubContainer>(context.Upgrade());
|
||||
EXPECT_NE(secondSubContainer, nullptr);
|
||||
formManager.AddSubContainer(CARD_ID, subContainer);
|
||||
EXPECT_EQ(formManager.GetSubContainer(CARD_ID), subContainer);
|
||||
formManager.AddSubContainer(CARD_ID, secondSubContainer);
|
||||
EXPECT_EQ(formManager.GetSubContainer(CARD_ID), secondSubContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StartAbility001
|
||||
* @tc.desc: Verify the StartAbility Interface of PluginManager work correctly.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(FormManagerTest, StartAbility001, TestSize.Level1)
|
||||
{
|
||||
/**
|
||||
* @tc.steps: step1. Build a FormManager.
|
||||
*/
|
||||
FormManager formManager;
|
||||
|
||||
/**
|
||||
* @tc.steps: step2. SetFormUtils.
|
||||
* @tc.expected: step2. GetFormUtils equals to formUtils.
|
||||
*/
|
||||
formManager.SetFormUtils(nullptr);
|
||||
EXPECT_EQ(formManager.GetFormUtils(), nullptr);
|
||||
|
||||
auto formUtils = std::make_shared<MockFormUtils>();
|
||||
formManager.SetFormUtils(formUtils);
|
||||
EXPECT_EQ(formManager.formUtils_, formUtils);
|
||||
EXPECT_EQ(formManager.GetFormUtils(), formUtils);
|
||||
}
|
||||
} // namespace OHOS::Ace
|
42
test/unittest/core/common/form/mock_form_utils.h
Normal file
42
test/unittest/core/common/form/mock_form_utils.h
Normal file
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2023 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.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_TEST_UNITTEST_CORE_COMMON_FORM_MOCK_FORM_TUILS_H
|
||||
#define FOUNDATION_ACE_TEST_UNITTEST_CORE_COMMON_FORM_MOCK_FORM_TUILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "core/components/form/resource/form_utils.h"
|
||||
|
||||
namespace OHOS::Ace {
|
||||
class MockFormUtils final : public FormUtils {
|
||||
public:
|
||||
MockFormUtils() = default;
|
||||
~MockFormUtils() = default;
|
||||
|
||||
int32_t RouterEvent(const int64_t formId, const std::string& action, const int32_t contianerId,
|
||||
const std::string& defualtbundleName)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int32_t BackgroundEvent(const int64_t formId, const std::string& action, const int32_t contianerId,
|
||||
const std::string& defualtbundleName)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
#endif // FOUNDATION_ACE_TEST_UNITTEST_CORE_COMMON_FORM_MOCK_FORM_TUILS_H
|
@ -13,8 +13,8 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FOUNDATION_ACE_MOCK_PLUGIN_UTILS_H
|
||||
#define FOUNDATION_ACE_MOCK_PLUGIN_UTILS_H
|
||||
#ifndef FOUNDATION_ACE_TEST_UNITTEST_CORE_COMMON_PLUGIN_MOCK_PLUGIN_TUILS_H
|
||||
#define FOUNDATION_ACE_TEST_UNITTEST_CORE_COMMON_PLUGIN_MOCK_PLUGIN_TUILS_H
|
||||
|
||||
#include <string>
|
||||
|
||||
@ -33,4 +33,4 @@ public:
|
||||
}
|
||||
};
|
||||
} // namespace OHOS::Ace
|
||||
#endif // FOUNDATION_ACE_MOCK_PLUGIN_UTILS_H
|
||||
#endif // FOUNDATION_ACE_TEST_UNITTEST_CORE_COMMON_PLUGIN_MOCK_PLUGIN_TUILS_H
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2021 Huawei Device Co., Ltd.
|
||||
* Copyright (c) 2023 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
|
||||
@ -17,7 +17,7 @@
|
||||
|
||||
#define private public
|
||||
#define protected public
|
||||
#include "test/unittest/core/common/plugin/mock_plugin_utils.h"
|
||||
#include "mock_plugin_utils.h"
|
||||
|
||||
#include "core/common/plugin_manager.h"
|
||||
#include "core/components/plugin/plugin_sub_container.h"
|
||||
|
Loading…
Reference in New Issue
Block a user