!9822 [tdd]add tdd to ability stage context

Merge pull request !9822 from 张亚菲/zyfContext
This commit is contained in:
openharmony_ci
2024-08-09 08:35:47 +00:00
committed by Gitee
3 changed files with 269 additions and 1 deletions
+2 -1
View File
@@ -358,7 +358,8 @@ group("unittest") {
"ability_service_extension_test:unittest",
"ability_service_log_test:unittest",
"ability_service_start_test:unittest",
"ability_timeout_test:unittest",
"ability_stage_context_test:unittest",
"ability_timeout_test",
"ability_token_proxy_test:unittest",
"ability_token_stub_test:unittest",
"advanced_security_mode_manager_test:unittest",
@@ -0,0 +1,80 @@
# Copyright (c) 2024 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/ohos.gni")
import("//build/test.gni")
import("//foundation/ability/ability_runtime/ability_runtime.gni")
ohos_unittest("ability_stage_context_test") {
module_out_path = "ability_runtime/context"
cflags_cc = []
include_dirs = [
"${ability_runtime_innerkits_path}/app_manager/include/appmgr",
"${ability_runtime_test_path}/mock/frameworks_kits_ability_native_test/include",
"${ability_runtime_test_path}/mock/common/include",
]
sources = [ "ability_stage_context_test.cpp" ]
configs = [ "${ability_runtime_services_path}/abilitymgr:abilityms_config" ]
cflags = []
if (target_cpu == "arm") {
cflags += [ "-DBINDER_IPC_32BIT" ]
}
deps = [
"${ability_runtime_innerkits_path}/ability_manager:ability_manager",
"${ability_runtime_innerkits_path}/ability_manager:ability_start_options",
"${ability_runtime_innerkits_path}/app_manager:app_manager",
"${ability_runtime_innerkits_path}/deps_wrapper:ability_deps_wrapper",
"${ability_runtime_innerkits_path}/runtime:runtime",
"${ability_runtime_native_path}/appkit:app_context",
"${ability_runtime_native_path}/appkit:appkit_manager_helper",
"//third_party/googletest:gmock_main",
"//third_party/googletest:gtest_main",
]
external_deps = [
"ability_base:configuration",
"ability_base:extractortool",
"ability_base:session_info",
"ability_base:want",
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"common_event_service:cesfwk_innerkits",
"hilog:libhilog",
"hitrace:hitrace_meter",
"init:libbegetutil",
"ipc:ipc_core",
"json:nlohmann_json_static",
"napi:ace_napi",
"resource_management:global_resmgr",
"samgr:samgr_proxy",
]
if (ability_runtime_graphics) {
external_deps += [
"i18n:intl_util",
"icu:shared_icuuc",
]
}
}
group("unittest") {
testonly = true
deps = [ ":ability_stage_context_test" ]
}
@@ -0,0 +1,187 @@
/*
* Copyright (c) 2024 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 "hilog_tag_wrapper.h"
#include "ability_stage_context.h"
#include "application_context.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace AbilityRuntime {
class AbilityStageContextTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp() override;
void TearDown() override;
};
void AbilityStageContextTest::SetUpTestCase(void)
{}
void AbilityStageContextTest::TearDownTestCase(void)
{}
void AbilityStageContextTest::SetUp()
{}
void AbilityStageContextTest::TearDown()
{}
/**
* @tc.name: AbilityStageContextTest_0100
* @tc.desc: Ability stage basic func test.
* @tc.type: FUNC
* @tc.require: issue
*/
HWTEST_F(AbilityStageContextTest, AbilityStageContextTest_0100, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "begin.");
auto context = AbilityRuntime::ApplicationContext::GetInstance();
auto abilityStageContext = std::make_shared<AbilityStageContext>();
abilityStageContext->SetParentContext(context);
auto abilityInfo = std::make_shared<AppExecFwk::AbilityInfo>();
abilityStageContext->InitHapModuleInfo(abilityInfo);
AppExecFwk::HapModuleInfo hapModuleInfo;
abilityStageContext->InitHapModuleInfo(hapModuleInfo);
auto gotHapModuleInfo = abilityStageContext->GetHapModuleInfo();
EXPECT_NE(gotHapModuleInfo, nullptr);
auto config = std::make_shared<AppExecFwk::Configuration>();
abilityStageContext->SetConfiguration(config);
auto gotConfig = abilityStageContext->GetConfiguration();
EXPECT_NE(gotConfig, nullptr);
std::shared_ptr<Global::Resource::ResourceManager> resMgr(Global::Resource::CreateResourceManager());
abilityStageContext->SetResourceManager(resMgr);
auto gotResMgr = abilityStageContext->GetResourceManager();
EXPECT_NE(gotResMgr, nullptr);
auto gotBundleName = abilityStageContext->GetBundleName();
EXPECT_EQ(gotBundleName, "");
auto gotAppInfo = abilityStageContext->GetApplicationInfo();
EXPECT_EQ(gotAppInfo, nullptr);
TAG_LOGI(AAFwkTag::TEST, "end.");
}
/**
* @tc.name: AbilityStageContextTest_0200
* @tc.desc: Ability stage basic func test.
* @tc.type: FUNC
* @tc.require: issue
*/
HWTEST_F(AbilityStageContextTest, AbilityStageContextTest_0200, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "begin.");
auto context = AbilityRuntime::ApplicationContext::GetInstance();
auto abilityStageContext = std::make_shared<AbilityStageContext>();
abilityStageContext->SetParentContext(context);
auto bundleContext = abilityStageContext->CreateBundleContext("com.test.bundleName");
EXPECT_EQ(bundleContext, nullptr);
auto moduleContext1 = abilityStageContext->CreateModuleContext("moudleName");
EXPECT_EQ(moduleContext1, nullptr);
auto moduleContext2 = abilityStageContext->CreateModuleContext("com.test.bundleName", "moudleName");
EXPECT_EQ(moduleContext2, nullptr);
auto moduleResMgr = abilityStageContext->CreateModuleResourceManager("com.test.bundleName", "moudleName");
EXPECT_EQ(moduleResMgr, nullptr);
std::shared_ptr<Global::Resource::ResourceManager> hspResMgr(Global::Resource::CreateResourceManager());
auto ret = abilityStageContext->CreateSystemHspModuleResourceManager("com.test.bundleName", "moudleName",
hspResMgr);
EXPECT_NE(ret, ERR_OK);
EXPECT_NE(hspResMgr, nullptr);
TAG_LOGI(AAFwkTag::TEST, "end.");
}
/**
* @tc.name: AbilityStageContextTest_0300
* @tc.desc: Ability stage basic func test.
* @tc.type: FUNC
* @tc.require: issue
*/
HWTEST_F(AbilityStageContextTest, AbilityStageContextTest_0300, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "begin.");
auto context = AbilityRuntime::ApplicationContext::GetInstance();
auto abilityStageContext = std::make_shared<AbilityStageContext>();
abilityStageContext->SetParentContext(context);
EXPECT_EQ(abilityStageContext->GetBundleCodePath(), "");
EXPECT_EQ(abilityStageContext->GetBundleCodeDir(), "");
EXPECT_EQ(abilityStageContext->GetCacheDir(), "/data/storage/el2/base/haps//cache");
EXPECT_EQ(abilityStageContext->GetTempDir(), "/data/storage/el2/base/haps//temp");
EXPECT_EQ(abilityStageContext->GetResourceDir(), "");
EXPECT_EQ(abilityStageContext->GetFilesDir(), "/data/storage/el2/base/haps//files");
EXPECT_EQ(abilityStageContext->GetDatabaseDir(), "/data/storage/el2/database/");
EXPECT_EQ(abilityStageContext->GetPreferencesDir(), "/data/storage/el2/base/haps//preferences");
EXPECT_EQ(abilityStageContext->GetGroupDir("1"), "");
std::string sysDatabaseDir;
auto ret = abilityStageContext->GetSystemDatabaseDir("1", false, sysDatabaseDir);
EXPECT_NE(ret, ERR_OK);
EXPECT_EQ(sysDatabaseDir, "");
std::string sysPreferencesDir;
ret = abilityStageContext->GetSystemPreferencesDir("1", false, sysPreferencesDir);
EXPECT_EQ(sysDatabaseDir, "");
EXPECT_EQ(abilityStageContext->GetDistributedFilesDir(), "/data/storage/el2/distributedfiles");
EXPECT_EQ(abilityStageContext->GetCloudFileDir(), "/data/storage/el2/cloud");
EXPECT_EQ(abilityStageContext->GetBaseDir(), "/data/storage/el2/base/haps/");
TAG_LOGI(AAFwkTag::TEST, "end.");
}
/**
* @tc.name: AbilityStageContextTest_0400
* @tc.desc: Ability stage basic func test.
* @tc.type: FUNC
* @tc.require: issue
*/
HWTEST_F(AbilityStageContextTest, AbilityStageContextTest_0400, TestSize.Level1)
{
TAG_LOGI(AAFwkTag::TEST, "begin.");
auto context = AbilityRuntime::ApplicationContext::GetInstance();
auto abilityStageContext = std::make_shared<AbilityStageContext>();
abilityStageContext->SetParentContext(context);
EXPECT_EQ(abilityStageContext->IsUpdatingConfigurations(), false);
EXPECT_EQ(abilityStageContext->PrintDrawnCompleted(), false);
auto token = abilityStageContext->GetToken();
abilityStageContext->SetToken(token);
abilityStageContext->SwitchArea(1);
EXPECT_EQ(abilityStageContext->GetArea(), 1);
EXPECT_EQ(abilityStageContext->GetDeviceType(), Global::Resource::DeviceType::DEVICE_PHONE);
TAG_LOGI(AAFwkTag::TEST, "end.");
}
} // namespace AbilityRuntime
} // namespace OHOS