!828 Add switch UT

Merge pull request !828 from chenbin/master
This commit is contained in:
openharmony_ci 2024-03-31 12:48:56 +00:00 committed by Gitee
commit f7289faca5
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
5 changed files with 323 additions and 0 deletions

View File

@ -564,10 +564,59 @@ ohos_unittest("dmsbasetest") {
subsystem_name = "ability"
}
ohos_unittest("dschedswitchstatustest") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
module_out_path = module_output_path
sources = [ "unittest/switch_status_dependency_test.cpp" ]
sources += dtbschedmgr_sources
configs = [
":test_config",
"${dms_path}/services/dtbschedmgr/test/resource:coverage_flags",
]
configs += dsched_configs
deps = [ "${distributed_service}/dtbschedmgr:distributedschedsvr" ]
if (is_standard_system) {
external_deps = dsched_external_deps
public_deps = dsched_public_deps
}
part_name = "dmsfwk"
subsystem_name = "ability"
}
ohos_unittest("datasharemanagertest") {
sanitize = {
cfi = true
cfi_cross_dso = true
debug = false
}
module_out_path = module_output_path
sources = [ "unittest/datashare_manager_test.cpp" ]
sources += dtbschedmgr_sources
configs = [
":test_config",
"${dms_path}/services/dtbschedmgr/test/resource:coverage_flags",
]
configs += dsched_configs
deps = [ "${distributed_service}/dtbschedmgr:distributedschedsvr" ]
if (is_standard_system) {
external_deps = dsched_external_deps
public_deps = dsched_public_deps
}
part_name = "dmsfwk"
subsystem_name = "ability"
}
group("unittest") {
testonly = true
deps = [
":bundlemanagerinternaltest",
":datasharemanagertest",
":distributedcalltest",
":distributedschedsvrtest",
":distributeduidtest",
@ -576,6 +625,7 @@ group("unittest") {
":dmsfreeinstallcbtest",
":dschedconnecttest",
":dschedcontinuetest",
":dschedswitchstatustest",
":softbusadaptertest",
"${dms_path}/common/test/unittest:distributed_sched_utils_test",
]

View File

@ -0,0 +1,100 @@
/*
* 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 "datashare_manager_test.h"
#include "test_log.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
void DataShareManagerTest::SetUpTestCase()
{
DTEST_LOG << "DataShareManagerTest::SetUpTestCase" << std::endl;
}
void DataShareManagerTest::TearDownTestCase()
{
DTEST_LOG << "DataShareManagerTest::TearDownTestCase" << std::endl;
}
void DataShareManagerTest::TearDown()
{
DTEST_LOG << "DataShareManagerTest::TearDown" << std::endl;
}
void DataShareManagerTest::SetUp()
{
DTEST_LOG << "DataShareManagerTest::SetUp" << std::endl;
}
/**
* @tc.name: CreateDataShareHelper_001
* @tc.desc: CreateDataShareHelper
* @tc.type: FUNC
* @tc.require: SR20240116513791
*/
HWTEST_F(DataShareManagerTest, CreateDataShareHelper_001, TestSize.Level3)
{
DTEST_LOG << "DataShareManagerTest CreateDataShareHelper_001 begin" << std::endl;
DataShareManager::GetInstance().CreateDataShareHelper();
DTEST_LOG << "DataShareManagerTest CreateDataShareHelper_001 end" << std::endl;
}
/**
* @tc.name: IsCreateDataShareHelper_001
* @tc.desc: IsCreateDataShareHelper
* @tc.type: FUNC
* @tc.require: SR20240116513791
*/
HWTEST_F(DataShareManagerTest, IsCreateDataShareHelper_001, TestSize.Level3)
{
DTEST_LOG << "DataShareManagerTest IsCreateDataShareHelper_001 begin" << std::endl;
DataShareManager::GetInstance().IsCreateDataShareHelper(SETTINGS_DATA_URI);
DTEST_LOG << "DataShareManagerTest IsCreateDataShareHelper_001 end" << std::endl;
}
/**
* @tc.name: RegisterObserver_001
* @tc.desc: RegisterObserver
* @tc.type: FUNC
* @tc.require: SR20240116513791
*/
HWTEST_F(DataShareManagerTest, RegisterObserver_001, TestSize.Level3)
{
DTEST_LOG << "DataShareManagerTest RegisterObserver_001 begin" << std::endl;
DataShareManager::GetInstance().RegisterObserver("");
DataShareManager::GetInstance().RegisterObserver(SETTINGS_DATA_URI);
DTEST_LOG << "DataShareManagerTest RegisterObserver_001 end" << std::endl;
}
/**
* @tc.name: OnChange_001
* @tc.desc: OnChange
* @tc.type: FUNC
* @tc.require: SR20240116513791
*/
HWTEST_F(DataShareManagerTest, OnChange_001, TestSize.Level3)
{
DTEST_LOG << "DataShareManagerTest OnChange_001 begin" << std::endl;
DataShareRegisterObserver dataShareRegisterObserver;
ChangeInfo changeInfo;
dataShareRegisterObserver.OnChange(changeInfo);
DTEST_LOG << "DataShareManagerTest OnChange_001 end" << std::endl;
}
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.
*/
#ifndef DATASHARE_MANAGER_TEST_H
#define DATASHARE_MANAGER_TEST_H
#include <gtest/gtest.h>
#define private public
#include "datashare_manager.h"
#undef private
namespace OHOS {
namespace DistributedSchedule {
class DataShareManagerTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // DATASHARE_MANAGER_TEST_H

View File

@ -0,0 +1,101 @@
/*
* 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 "switch_status_dependency_test.h"
#include "test_log.h"
using namespace testing;
using namespace testing::ext;
namespace OHOS {
namespace DistributedSchedule {
namespace {
const std::string CONTINUE_SWITCH_STATUS_KEY = "Continue_Switch_Status";
const std::string CONTINUE_SWITCH_OFF = "continue_switch_off";
const std::string CONTINUE_SWITCH_ON = "continue_switch_on";
}
void SwitchStatusDependencyTest::SetUpTestCase()
{
DTEST_LOG << "SwitchStatusDependencyTest::SetUpTestCase" << std::endl;
}
void SwitchStatusDependencyTest::TearDownTestCase()
{
DTEST_LOG << "SwitchStatusDependencyTest::TearDownTestCase" << std::endl;
}
void SwitchStatusDependencyTest::TearDown()
{
DTEST_LOG << "SwitchStatusDependencyTest::TearDown" << std::endl;
}
void SwitchStatusDependencyTest::SetUp()
{
DTEST_LOG << "SwitchStatusDependencyTest::SetUp" << std::endl;
}
/**
* @tc.name: IsContinueSwitchOn_001
* @tc.desc: IsContinueSwitchOn
* @tc.type: FUNC
* @tc.require: SR20240116513791
*/
HWTEST_F(SwitchStatusDependencyTest, IsContinueSwitchOn_001, TestSize.Level3)
{
DTEST_LOG << "SwitchStatusDependencyTest IsContinueSwitchOn_001 begin" << std::endl;
EXPECT_TRUE(SwitchStatusDependency::GetInstance().IsContinueSwitchOn());
DTEST_LOG << "SwitchStatusDependencyTest IsContinueSwitchOn_001 end" << std::endl;
}
/**
* @tc.name: IsCreateDataShareHelper_001
* @tc.desc: IsCreateDataShareHelper
* @tc.type: FUNC
* @tc.require: SR20240116513791
*/
HWTEST_F(SwitchStatusDependencyTest, IsCreateDataShareHelper_001, TestSize.Level3)
{
DTEST_LOG << "SwitchStatusDependencyTest IsCreateDataShareHelper_001 begin" << std::endl;
std::string key = "";
std::string defaultValue = CONTINUE_SWITCH_ON;
EXPECT_EQ(CONTINUE_SWITCH_ON,
SwitchStatusDependency::GetInstance().GetSwitchStatus(key, defaultValue));
key = CONTINUE_SWITCH_STATUS_KEY;
defaultValue = CONTINUE_SWITCH_ON;
EXPECT_EQ(CONTINUE_SWITCH_ON,
SwitchStatusDependency::GetInstance().GetSwitchStatus(key, defaultValue));
key = CONTINUE_SWITCH_STATUS_KEY;
defaultValue = CONTINUE_SWITCH_OFF;
EXPECT_EQ(CONTINUE_SWITCH_ON,
SwitchStatusDependency::GetInstance().GetSwitchStatus(key, defaultValue));
DTEST_LOG << "SwitchStatusDependencyTest IsCreateDataShareHelper_001 end" << std::endl;
}
/**
* @tc.name: GetDataShareHelper_001
* @tc.desc: GetDataShareHelper
* @tc.type: FUNC
* @tc.require: SR20240116513791
*/
HWTEST_F(SwitchStatusDependencyTest, GetDataShareHelper_001, TestSize.Level3)
{
DTEST_LOG << "SwitchStatusDependencyTest GetDataShareHelper_001 begin" << std::endl;
SwitchStatusDependency::GetInstance().GetDataShareHelper();
DTEST_LOG << "SwitchStatusDependencyTest GetDataShareHelper_001 end" << std::endl;
}
}
}

View File

@ -0,0 +1,36 @@
/*
* 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.
*/
#ifndef SWITCH_STATUS_DEPENDENCY_TEST_H
#define SWITCH_STATUS_DEPENDENCY_TEST_H
#include <gtest/gtest.h>
#define private public
#include "switch_status_dependency.h"
#undef private
namespace OHOS {
namespace DistributedSchedule {
class SwitchStatusDependencyTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // SWITCH_STATUS_DEPENDENCY_TEST_H