mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2025-02-19 22:11:04 +00:00
add ut
Signed-off-by: shihaojie6128 <shihaojie10@huawei.com>
This commit is contained in:
parent
31a8016023
commit
e035832c40
@ -651,8 +651,10 @@ ohos_unittest("dschedcontinuestatetest") {
|
||||
module_out_path = module_output_path
|
||||
cflags = [ "-Dprivate=public" ]
|
||||
sources = [
|
||||
"unittest/continue/dsched_continue_manager_test.cpp",
|
||||
"unittest/continue/dsched_continue_state_test.cpp",
|
||||
"unittest/continue/dsched_continue_test.cpp",
|
||||
"unittest/mock_distributed_sched.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
configs = [
|
||||
|
@ -0,0 +1,238 @@
|
||||
/*
|
||||
* 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 "dsched_continue_manager_test.h"
|
||||
|
||||
#include "datetime_ex.h"
|
||||
#include "test_log.h"
|
||||
#include "mock_distributed_sched.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
|
||||
namespace {
|
||||
const std::string LOCAL_DEVICEID = "192.168.43.100";
|
||||
const std::string REMOTE_DEVICEID = "192.168.44.100";
|
||||
constexpr int32_t MISSION_ID = 1;
|
||||
const std::string BUNDLE_NAME = "com.ohos.permissionmanager";
|
||||
}
|
||||
|
||||
void DSchedContinueManagerTest::SetUpTestCase()
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest::SetUpTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void DSchedContinueManagerTest::TearDownTestCase()
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest::TearDownTestCase" << std::endl;
|
||||
}
|
||||
|
||||
void DSchedContinueManagerTest::TearDown()
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest::TearDown" << std::endl;
|
||||
}
|
||||
|
||||
void DSchedContinueManagerTest::SetUp()
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest::SetUp" << std::endl;
|
||||
}
|
||||
|
||||
sptr<IRemoteObject> DSchedContinueManagerTest::GetDSchedService() const
|
||||
{
|
||||
sptr<IRemoteObject> dsched = new MockDistributedSched();
|
||||
return dsched;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Init_001
|
||||
* @tc.desc: test Init func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, Init_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest Init_001 begin" << std::endl;
|
||||
DSchedContinueManager::GetInstance().Init();
|
||||
std::shared_ptr<OHOS::AppExecFwk::EventHandler> eventHandler =
|
||||
DSchedContinueManager::GetInstance().eventHandler_;
|
||||
EXPECT_NE(eventHandler, nullptr);
|
||||
DTEST_LOG << "DSchedContinueManagerTest Init_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueMission_001
|
||||
* @tc.desc: test ContinueMission func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, ContinueMission_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_001 begin" << std::endl;
|
||||
auto callback = GetDSchedService();
|
||||
OHOS::AAFwk::WantParams wantParams;
|
||||
int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueMission_002
|
||||
* @tc.desc: test ContinueMission func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, ContinueMission_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_002 begin" << std::endl;
|
||||
OHOS::AAFwk::WantParams wantParams;
|
||||
auto callback = GetDSchedService();
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission("", REMOTE_DEVICEID, MISSION_ID, callback, wantParams);
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, "", MISSION_ID, callback, wantParams);
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
nullptr, wantParams);
|
||||
|
||||
int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, MISSION_ID,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueMission_003
|
||||
* @tc.desc: test ContinueMission func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, ContinueMission_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_003 begin" << std::endl;
|
||||
auto callback = GetDSchedService();
|
||||
OHOS::AAFwk::WantParams wantParams;
|
||||
int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, BUNDLE_NAME,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ContinueMission_004
|
||||
* @tc.desc: test ContinueMission func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, ContinueMission_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_004 begin" << std::endl;
|
||||
OHOS::AAFwk::WantParams wantParams;
|
||||
auto callback = GetDSchedService();
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission("", REMOTE_DEVICEID, BUNDLE_NAME, callback, wantParams);
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, "", BUNDLE_NAME, callback, wantParams);
|
||||
DSchedContinueManager::GetInstance().HandleContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, BUNDLE_NAME,
|
||||
nullptr, wantParams);
|
||||
|
||||
int32_t ret = DSchedContinueManager::GetInstance().ContinueMission(LOCAL_DEVICEID, REMOTE_DEVICEID, BUNDLE_NAME,
|
||||
callback, wantParams);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
DTEST_LOG << "DSchedContinueManagerTest ContinueMission_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: HandleContinueMissionWithBundleName_001
|
||||
* @tc.desc: test HandleContinueMissionWithBundleName func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, HandleContinueMissionWithBundleName_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest HandleContinueMissionWithBundleName_001 begin" << std::endl;
|
||||
DTEST_LOG << "DSchedContinueManagerTest HandleContinueMissionWithBundleName_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: SetTimeOut_001
|
||||
* @tc.desc: test SetTimeOut func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, SetTimeOut_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest SetTimeOut_001 begin" << std::endl;
|
||||
DSchedContinueInfo info;
|
||||
int32_t timeout = 0;
|
||||
DSchedContinueManager::GetInstance().continues_.clear();
|
||||
DSchedContinueManager::GetInstance().SetTimeOut(info, timeout);
|
||||
EXPECT_EQ(DSchedContinueManager::GetInstance().continues_.empty(), true);
|
||||
DTEST_LOG << "DSchedContinueManagerTest SetTimeOut_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: StartContinuation_001
|
||||
* @tc.desc: test StartContinuation func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, StartContinuation_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest StartContinuation_001 begin" << std::endl;
|
||||
OHOS::AAFwk::Want want;
|
||||
int32_t missionId = 0;
|
||||
int32_t callerUid = 0;
|
||||
int32_t status = 0;
|
||||
uint32_t accessToken = 0;
|
||||
int32_t ret1 = DSchedContinueManager::GetInstance().StartContinuation(want, missionId,
|
||||
callerUid, status, accessToken);
|
||||
EXPECT_EQ(ret1, ERR_OK);
|
||||
DTEST_LOG << "DSchedContinueManagerTest StartContinuation_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: CheckContinuationLimit_001
|
||||
* @tc.desc: test CheckContinuationLimit func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, CheckContinuationLimit_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest CheckContinuationLimit_001 begin" << std::endl;
|
||||
int32_t ret = DSchedContinueManager::GetInstance().CheckContinuationLimit(LOCAL_DEVICEID, REMOTE_DEVICEID);
|
||||
EXPECT_EQ(ret, GET_LOCAL_DEVICE_ERR);
|
||||
DTEST_LOG << "DSchedContinueManagerTest CheckContinuationLimit_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetLocalDeviceId_001
|
||||
* @tc.desc: test GetLocalDeviceId func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, GetLocalDeviceId_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetLocalDeviceId_001 begin" << std::endl;
|
||||
std::string localDeviceId = "192.168.43.100";
|
||||
int32_t ret = DSchedContinueManager::GetInstance().GetLocalDeviceId(localDeviceId);
|
||||
EXPECT_EQ(ret, false);
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetLocalDeviceId_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: GetContinueInfo_001
|
||||
* @tc.desc: test GetContinueInfo func
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DSchedContinueManagerTest, GetContinueInfo_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetContinueInfo_001 begin" << std::endl;
|
||||
std::string localDeviceId = "192.168.43.100";
|
||||
std::string remoteDeviceId = "192.168.44.100";
|
||||
int32_t ret = DSchedContinueManager::GetInstance().GetContinueInfo(localDeviceId, remoteDeviceId);
|
||||
EXPECT_EQ(ret, ERR_OK);
|
||||
DTEST_LOG << "DSchedContinueManagerTest GetContinueInfo_001 end" << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
@ -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 DMS_CONTINUE_MANAGER_TEST_H
|
||||
#define DMS_CONTINUE_MANAGER_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "dsched_continue_manager.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
|
||||
class DSchedContinueManagerTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
sptr<IRemoteObject> GetDSchedService() const;
|
||||
};
|
||||
} // namespace DistributedSchedule
|
||||
} // namespace OHOS
|
||||
#endif // DMS_CONTINUE_MANAGER_TEST_H
|
@ -151,33 +151,6 @@ HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Parcelable_0400, F
|
||||
EXPECT_STREQ(std::to_string(valueLong).c_str(), outString.c_str());
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: DistributedWantParams_Parcelable_0600
|
||||
* @tc.name: Marshalling/Unmarshalling
|
||||
* @tc.desc: marshalling nested WantParams, and then check result.
|
||||
*/
|
||||
HWTEST_F(DistributedWantParamsBaseTest, DistributedWantParams_Parcelable_0600, Function | MediumTest | Level3)
|
||||
{
|
||||
DistributedWantParams wp;
|
||||
wp.SetParam("hello", String::Box("World"));
|
||||
wp.SetParam("welcome", String::Box("NY"));
|
||||
|
||||
DistributedWantParams l1;
|
||||
l1.SetParam("l1", DistributedWantParamWrapper::Box(wp));
|
||||
wantParamsIn_->SetParam("l2", DistributedWantParamWrapper::Box(l1));
|
||||
Parcel in;
|
||||
wantParamsIn_->Marshalling(in);
|
||||
std::shared_ptr<DistributedWantParams> wantParamsOut_(DistributedWantParams::Unmarshalling(in));
|
||||
DistributedWantParams l1Out =
|
||||
DistributedWantParamWrapper::Unbox(IDistributedWantParams::Query(wantParamsOut_->GetParam("l2")));
|
||||
DistributedWantParams wpOut =
|
||||
DistributedWantParamWrapper::Unbox(IDistributedWantParams::Query(l1.GetParam("l1")));
|
||||
std::string hello(String::Unbox(IString::Query(wpOut.GetParam("hello"))));
|
||||
EXPECT_EQ(hello, "World");
|
||||
std::string welcome(String::Unbox(IString::Query(wpOut.GetParam("welcome"))));
|
||||
EXPECT_EQ(welcome, "NY");
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.number: DistributedWantParams_Parcelable_0700
|
||||
* @tc.name: Marshalling/Unmarshalling
|
||||
|
Loading…
x
Reference in New Issue
Block a user