!53 add continuation test case

Merge pull request !53 from wangdd_zju/0913
This commit is contained in:
openharmony_ci 2021-09-15 02:07:07 +00:00 committed by Gitee
commit 4bd3493f4b
5 changed files with 972 additions and 5 deletions

View File

@ -84,7 +84,11 @@ ohos_unittest("distributedschedsvrtest") {
ohos_unittest("dschedcontinuetest") {
module_out_path = module_output_path
sources = [ "unittest/distributed_sched_continuation_test.cpp" ]
sources = [
"unittest/distributed_sched_ability_shell_test.cpp",
"unittest/distributed_sched_continuation_test.cpp",
"unittest/mock_distributed_sched.cpp",
]
sources += dtbschedmgr_sources
configs = dsched_configs
deps = dsched_deps

View File

@ -0,0 +1,571 @@
/*
* Copyright (c) 2021 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 "distributed_sched_ability_shell.h"
#include "distributed_sched_service.h"
#include "dtbschedmgr_log.h"
#include "gtest/gtest.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
#include "mock_distributed_sched.h"
#include "ohos/aafwk/content/want.h"
#include "system_ability_definition.h"
#include "test_log.h"
using namespace std;
using namespace testing;
using namespace testing::ext;
using namespace OHOS;
using namespace AAFwk;
using namespace AppExecFwk;
namespace OHOS {
namespace DistributedSchedule {
namespace {
constexpr int32_t LOOP_TIMES = 100;
}
class DistributedSchedAbilityShellTest : public testing::Test {
public:
static void SetUpTestCase();
static void TearDownTestCase();
void SetUp();
void TearDown();
sptr<IDistributedSched> proxy_;
protected:
sptr<IDistributedSched> GetDms();
};
void DistributedSchedAbilityShellTest::SetUpTestCase()
{
}
void DistributedSchedAbilityShellTest::TearDownTestCase()
{
}
void DistributedSchedAbilityShellTest::SetUp()
{
}
void DistributedSchedAbilityShellTest::TearDown()
{
}
sptr<IDistributedSched> DistributedSchedAbilityShellTest::GetDms()
{
if (proxy_ != nullptr) {
return proxy_;
}
auto sm = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
EXPECT_TRUE(sm != nullptr);
if (sm == nullptr) {
DTEST_LOG << "DistributedSchedAbilityShellTest sm is nullptr" << std::endl;
return nullptr;
}
auto distributedObject = sm->GetSystemAbility(DISTRIBUTED_SCHED_SA_ID);
EXPECT_TRUE(distributedObject != nullptr);
proxy_ = iface_cast<IDistributedSched>(distributedObject);
if (proxy_ == nullptr) {
DTEST_LOG << "DistributedSchedAbilityShellTest distributedObject is nullptr" << std::endl;
}
return proxy_;
}
/**
* @tc.name: RegisterAbilityToken001
* @tc.desc: register ability token with null token.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RegisterAbilityToken001, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken001 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token with null token
* @tc.expected: step1. return ERR_NULL_OBJECT.
*/
int result = proxy->RegisterAbilityToken(nullptr, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
EXPECT_EQ(static_cast<int>(ERR_NULL_OBJECT), result);
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken001 end" << std::endl;
}
/**
* @tc.name: RegisterAbilityToken002
* @tc.desc: register ability token with null callback.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RegisterAbilityToken002, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken002 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token with null callback
* @tc.expected: step1. return ERR_NULL_OBJECT.
*/
int result = proxy->RegisterAbilityToken(token, nullptr);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
EXPECT_EQ(static_cast<int>(ERR_NULL_OBJECT), result);
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken002 end" << std::endl;
}
/**
* @tc.name: RegisterAbilityToken003
* @tc.desc: register ability token with callback and token.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RegisterAbilityToken003, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken003 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = proxy->RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
EXPECT_EQ(static_cast<int>(ERR_OK), result);
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken003 end" << std::endl;
}
/**
* @tc.name: RegisterAbilityToken004
* @tc.desc: register ability token with callback and two tokens.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RegisterAbilityToken004, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken004 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> token1 = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = proxy->RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
/**
* @tc.steps: step2. register ability token with callback and token1
* @tc.expected: step2. return ERR_OK.
*/
int result1 = proxy->RegisterAbilityToken(token1, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result1: "<< result1 << std::endl;
EXPECT_EQ(static_cast<int>(ERR_OK), result);
EXPECT_EQ(static_cast<int>(ERR_OK), result1);
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken004 end" << std::endl;
}
/**
* @tc.name: RegisterAbilityToken005
* @tc.desc: register ability token with two callbacks and two tokens.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RegisterAbilityToken005, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken005 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> token1 = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback1 = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = proxy->RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
/**
* @tc.steps: step2. register ability token with callback1 and token1
* @tc.expected: step2. return ERR_OK.
*/
int result1 = proxy->RegisterAbilityToken(token1, continuationCallback1);
DTEST_LOG << "DistributedSchedAbilityShellTest result1: "<< result1 << std::endl;
EXPECT_EQ(static_cast<int>(ERR_OK), result);
EXPECT_EQ(static_cast<int>(ERR_OK), result1);
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken005 end" << std::endl;
}
/**
* @tc.name: RegisterAbilityToken006
* @tc.desc: register ability token with callback and two repeat tokens.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RegisterAbilityToken006, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken006 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = proxy->RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
/**
* @tc.steps: step2. register ability token with callback and repeat token
* @tc.expected: step2. return REG_REPEAT_ABILITY_TOKEN_ERR.
*/
int result1 = proxy->RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result1: "<< result1 << std::endl;
EXPECT_EQ(static_cast<int>(REG_REPEAT_ABILITY_TOKEN_ERR), result1);
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken006 end" << std::endl;
}
/**
* @tc.name: RegisterAbilityToken007
* @tc.desc: register ability token with two callbacks and two tokens with dms.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RegisterAbilityToken007, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken007 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> token1 = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback1 = new MockDistributedSched();
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = DistributedSchedService::GetInstance().RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
/**
* @tc.steps: step2. register ability token with callback1 and token1
* @tc.expected: step2. return ERR_OK.
*/
int result1 = DistributedSchedService::GetInstance().RegisterAbilityToken(token1, continuationCallback1);
DTEST_LOG << "DistributedSchedAbilityShellTest result1: "<< result1 << std::endl;
EXPECT_EQ(static_cast<int>(ERR_OK), result);
EXPECT_EQ(static_cast<int>(ERR_OK), result1);
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken007 end" << std::endl;
}
/**
* @tc.name: RegisterAbilityToken008
* @tc.desc: register ability token with callback and two repeat tokens.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RegisterAbilityToken008, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken008 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = DistributedSchedService::GetInstance().RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
/**
* @tc.steps: step2. register ability token with callback and repeat token
* @tc.expected: step2. return REG_REPEAT_ABILITY_TOKEN_ERR.
*/
int result1 = DistributedSchedService::GetInstance().RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result1: "<< result1 << std::endl;
EXPECT_EQ(static_cast<int>(REG_REPEAT_ABILITY_TOKEN_ERR), result1);
sptr<MockDistributedSched> continuationCallback1 = new MockDistributedSched();
DistributedSchedService::GetInstance().UnregisterAbilityToken(token, continuationCallback1);
DistributedSchedService::GetInstance().UnregisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterAbilityToken008 end" << std::endl;
}
/**
* @tc.name: UnregisterAbilityToken001
* @tc.desc: unregister ability token with null token.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, UnregisterAbilityToken001, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken001 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. unregister ability token with null token
* @tc.expected: step1. return ERR_NULL_OBJECT.
*/
int result = proxy->UnregisterAbilityToken(nullptr, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
EXPECT_EQ(static_cast<int>(ERR_NULL_OBJECT), result);
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken001 end" << std::endl;
}
/**
* @tc.name: UnregisterAbilityToken002
* @tc.desc: unregister ability token with null token.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, UnregisterAbilityToken002, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken002 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. unregister ability token with null callback
* @tc.expected: step1. return ERR_NULL_OBJECT.
*/
int result = proxy->UnregisterAbilityToken(token, nullptr);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
EXPECT_EQ(static_cast<int>(ERR_NULL_OBJECT), result);
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken002 end" << std::endl;
}
/**
* @tc.name: UnregisterAbilityToken003
* @tc.desc: unregister ability token with callback and token.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, UnregisterAbilityToken003, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken003 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = proxy->RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
EXPECT_EQ(static_cast<int>(ERR_OK), result);
/**
* @tc.steps: step2. unregister ability token with token and callback
* @tc.expected: step2. return ERR_OK.
*/
int result1 = proxy->UnregisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result1: "<< result1 << std::endl;
EXPECT_EQ(static_cast<int>(ERR_OK), result1);
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken003 end" << std::endl;
}
/**
* @tc.name: UnregisterAbilityToken004
* @tc.desc: unregister ability token with wrong callback.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, UnregisterAbilityToken004, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken004 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = proxy->RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
EXPECT_EQ(static_cast<int>(ERR_OK), result);
/**
* @tc.steps: step2. unregister ability token with token and callback
* @tc.expected: step2. return NO_APP_THREAD_ERR.
*/
sptr<MockDistributedSched> continuationCallback1 = new MockDistributedSched();
int result1 = proxy->UnregisterAbilityToken(token, continuationCallback1);
DTEST_LOG << "DistributedSchedAbilityShellTest result1: "<< result1 << std::endl;
EXPECT_EQ(static_cast<int>(NO_APP_THREAD_ERR), result1);
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken004 end" << std::endl;
}
/**
* @tc.name: UnregisterAbilityToken005
* @tc.desc: unregister ability token with wrong callback.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, UnregisterAbilityToken005, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken005 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = proxy->RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
EXPECT_EQ(static_cast<int>(ERR_OK), result);
/**
* @tc.steps: step2. unregister ability token with token and callback
* @tc.expected: step2. return NO_ABILITY_TOKEN_ERR.
*/
sptr<MockDistributedSched> token1 = new MockDistributedSched();
int result1 = proxy->UnregisterAbilityToken(token1, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result1: "<< result1 << std::endl;
EXPECT_EQ(static_cast<int>(NO_ABILITY_TOKEN_ERR), result1);
DTEST_LOG << "DistributedSchedAbilityShellTest UnregisterAbilityToken005 end" << std::endl;
}
/**
* @tc.name: RegisterUnregisterAbilityTokenPressure001
* @tc.desc: register and unregister ability token pressure.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RegisterUnregisterAbilityTokenPressure001, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterUnregisterAbilityTokenPressure001 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
sptr<IDistributedSched> proxy = GetDms();
if (proxy == nullptr) {
return;
}
/**
* @tc.steps: step1. register ability token for 100 times
*/
for (int index = 0; index < LOOP_TIMES; ++index) {
proxy->RegisterAbilityToken(token, continuationCallback);
}
/**
* @tc.steps: step2. unregister ability token for 100 times
*/
for (int index = 0; index < LOOP_TIMES; ++index) {
proxy->UnregisterAbilityToken(token, continuationCallback);
}
DTEST_LOG << "DistributedSchedAbilityShellTest RegisterUnregisterAbilityTokenPressure001 end" << std::endl;
}
/**
* @tc.name: RemoveContinuationCallback001
* @tc.desc: remove continuation callback with dms.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, RemoveContinuationCallback001, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest RemoveContinuationCallback001 start" << std::endl;
AppExecFwk::AbilityInfo abilityInfo;
sptr<MockDistributedSched> token = new MockDistributedSched();
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
/**
* @tc.steps: step1. register ability token with callback and token
* @tc.expected: step1. return ERR_OK.
*/
int result = DistributedSchedService::GetInstance().RegisterAbilityToken(token, continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest result: "<< result << std::endl;
/**
* @tc.steps: step2. remove continuation callback with dms
* @tc.expected: step2. return ERR_OK.
*/
DistributedSchedAbilityShell::GetInstance().RemoveContinuationCallback(continuationCallback);
EXPECT_EQ(static_cast<int>(ERR_OK), result);
DTEST_LOG << "DistributedSchedAbilityShellTest RemoveContinuationCallback001 end" << std::endl;
}
/**
* @tc.name: ContinuationCallbackAddDeathRecipient001
* @tc.desc: add death recipient for continuation callback.
* @tc.type: FUNC
*/
HWTEST_F(DistributedSchedAbilityShellTest, ContinuationCallbackAddDeathRecipient001, TestSize.Level1)
{
DTEST_LOG << "DistributedSchedAbilityShellTest ContinuationCallbackAddDeathRecipient001 start" << std::endl;
sptr<MockDistributedSched> continuationCallback = new MockDistributedSched();
/**
* @tc.steps: step1. add death recipient for continuation callback
*/
sptr<IRemoteObject::DeathRecipient>(new ContinuationCallbackDeathRecipient())->OnRemoteDied(continuationCallback);
DTEST_LOG << "DistributedSchedAbilityShellTest ContinuationCallbackAddDeathRecipient001 end" << std::endl;
}
} // DistributedSchedule
} // namespace OHOS

View File

@ -14,7 +14,7 @@
*/
#include "distributed_sched_continuation_test.h"
#include "mock_distributed_sched.h"
using namespace std;
using namespace testing;
using namespace testing::ext;
@ -25,6 +25,9 @@ using namespace AppExecFwk;
namespace OHOS {
namespace DistributedSchedule {
namespace {
const u16string MOCK_DEVICE_ID = u"MOCK_DEVICE_ID";
constexpr int32_t MOCK_SESSION_ID = 123;
const string LOCAL_DEVICE_ID = "192.168.43.100";
}
void DSchedContinuationTest::SetUpTestCase()
@ -47,7 +50,7 @@ void DSchedContinuationTest::TearDown()
sptr<IRemoteObject> DSchedContinuationTest::GetDSchedService() const
{
sptr<IRemoteObject> dsched;
sptr<IRemoteObject> dsched = new MockDistributedSched();
return dsched;
}
@ -95,10 +98,10 @@ int32_t DSchedContinuationTest::StartContinuation(const sptr<IRemoteObject>& abi
/**
* @tc.name: StartContinuation_001
* @tc.desc: input invalid params
* @tc.desc: input invalid params.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, StartContinuation_001, TestSize.Level0)
HWTEST_F(DSchedContinuationTest, StartContinuation_001, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest StartContinuation_001 start" << std::endl;
/**
@ -109,5 +112,239 @@ HWTEST_F(DSchedContinuationTest, StartContinuation_001, TestSize.Level0)
EXPECT_TRUE(ret != ERR_OK);
DTEST_LOG << "DSchedContinuationTest StartContinuation001 end" << std::endl;
}
/**
* @tc.name: StartContinuation_002
* @tc.desc: input invalid params.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, StartContinuation_002, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest StartContinuation_002 start" << std::endl;
/**
* @tc.steps: step1. intent not set continuation flags.
* @tc.expected: step1. return false.
*/
int32_t ret = StartContinuation(GetDSchedService(), 0);
EXPECT_TRUE(ret != ERR_OK);
DTEST_LOG << "DSchedContinuationTest StartContinuation002 end" << std::endl;
}
/**
* @tc.name: StartContinuation_003
* @tc.desc: get remote dms failed.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, StartContinuation_003, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest StartContinuation_003 start" << std::endl;
/**
* @tc.steps: step1. get remote dms failed.
* @tc.expected: step1. return false.
*/
int32_t ret = StartContinuation(GetDSchedService(), Want::FLAG_ABILITY_CONTINUATION);
EXPECT_TRUE(ret != ERR_OK);
DTEST_LOG << "DSchedContinuationTest StartContinuation003 end" << std::endl;
}
/**
* @tc.name: NotifyCompleteContinuation_001
* @tc.desc: input invalid session.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, NotifyCompleteContinuation_001, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 start" << std::endl;
/**
* @tc.steps: step1. input invalid session.
* @tc.expected: step1. return false.
*/
DistributedSchedService::GetInstance().NotifyCompleteContinuation(MOCK_DEVICE_ID, -1, true);
EXPECT_TRUE(!timeoutFlag_);
DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_001 end" << std::endl;
}
/**
* @tc.name: NotifyCompleteContinuation_002
* @tc.desc: get remote dms failed.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, NotifyCompleteContinuation_002, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_002 start" << std::endl;
/**
* @tc.steps: step1. get remote dms failed.
* @tc.expected: step1. return false.
*/
DistributedSchedService::GetInstance().NotifyCompleteContinuation(MOCK_DEVICE_ID, MOCK_SESSION_ID, true);
EXPECT_TRUE(!timeoutFlag_);
DTEST_LOG << "DSchedContinuationTest NotifyCompleteContinuation_002 end" << std::endl;
}
/**
* @tc.name: NotifyContinuationResultFromRemote_001
* @tc.desc: input invalid session.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, NotifyContinuationResultFromRemote_001, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest NotifyContinuationResultFromRemote_001 start" << std::endl;
/**
* @tc.steps: step1. input invalid session.
* @tc.expected: step1. return false.
*/
DistributedSchedService::GetInstance().NotifyContinuationResultFromRemote(-1, true);
EXPECT_TRUE(!timeoutFlag_);
DTEST_LOG << "DSchedContinuationTest NotifyContinuationResultFromRemote_001 end" << std::endl;
}
/**
* @tc.name: NotifyContinuationResultFromRemote_002
* @tc.desc: get remote dms failed.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, NotifyContinuationResultFromRemote_002, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest NotifyContinuationResultFromRemote_002 start" << std::endl;
/**
* @tc.steps: step1. get remote dms failed.
* @tc.expected: step1. return false.
*/
DistributedSchedService::GetInstance().NotifyContinuationResultFromRemote(MOCK_SESSION_ID, true);
EXPECT_TRUE(!timeoutFlag_);
DTEST_LOG << "DSchedContinuationTest NotifyContinuationResultFromRemote_002 end" << std::endl;
}
/**
* @tc.name: PushAbilityToken_001
* @tc.desc: input invalid params.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, PushAbilityToken_001, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_001 start" << std::endl;
/**
* @tc.steps: step1. input invalid abilityToken.
* @tc.expected: step1. return false.
*/
auto sessionId = dschedContinuation_->GenerateSessionId();
bool ret = dschedContinuation_->PushAbilityToken(sessionId, nullptr);
EXPECT_TRUE(!ret);
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_001 end" << std::endl;
}
/**
* @tc.name: PushAbilityToken_002
* @tc.desc: input invalid params.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, PushAbilityToken_002, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_002 start" << std::endl;
/**
* @tc.steps: step1. input invalid sessionId.
* @tc.expected: step1. return false.
*/
bool ret = dschedContinuation_->PushAbilityToken(-1, GetDSchedService());
EXPECT_TRUE(!ret);
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_002 end" << std::endl;
}
/**
* @tc.name: PushAbilityToken_003
* @tc.desc: init not call.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, PushAbilityToken_003, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_003 start" << std::endl;
/**
* @tc.steps: step1. input valid abilityToken and valid sessionId.
* @tc.expected: step1. return false.
*/
auto sessionId = dschedContinuation_->GenerateSessionId();
bool ret = dschedContinuation_->PushAbilityToken(sessionId, GetDSchedService());
EXPECT_TRUE(!ret);
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_003 end" << std::endl;
}
/**
* @tc.name: PushAbilityToken_004
* @tc.desc: Push AbilityToken OK.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, PushAbilityToken_004, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_004 start" << std::endl;
/**
* @tc.steps: step1. input valid params and init.
* @tc.expected: step1. return true.
*/
dschedContinuation_->Init(nullptr);
auto sessionId = dschedContinuation_->GenerateSessionId();
bool ret = dschedContinuation_->PushAbilityToken(sessionId, GetDSchedService());
EXPECT_TRUE(ret);
DTEST_LOG << "DSchedContinuationTest PushAbilityToken_004 end" << std::endl;
}
/**
* @tc.name: PopAbilityToken_001
* @tc.desc: input invalid params.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, PopAbilityToken_001, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest PopAbilityToken_001 start" << std::endl;
/**
* @tc.steps: step1. input invalid sessionId.
* @tc.expected: step1. return false.
*/
sptr<IRemoteObject> abilityToken = dschedContinuation_->PopAbilityToken(-1);
EXPECT_TRUE(abilityToken == nullptr);
DTEST_LOG << "DSchedContinuationTest PopAbilityToken_001 end" << std::endl;
}
/**
* @tc.name: PopAbilityToken_002
* @tc.desc: input invalid params.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, PopAbilityToken_002, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest PopAbilityToken_002 start" << std::endl;
/**
* @tc.steps: step1. pop not exist sessionId.
* @tc.expected: step1. return false.
*/
int32_t sessionId = dschedContinuation_->GenerateSessionId() + 1;
sptr<IRemoteObject> abilityToken = dschedContinuation_->PopAbilityToken(sessionId);
EXPECT_TRUE(abilityToken == nullptr);
DTEST_LOG << "DSchedContinuationTest PopAbilityToken_002 end" << std::endl;
}
/**
* @tc.name: PopAbilityToken_003
* @tc.desc: pop abilityToken success.
* @tc.type: FUNC
*/
HWTEST_F(DSchedContinuationTest, PopAbilityToken_003, TestSize.Level1)
{
DTEST_LOG << "DSchedContinuationTest PopAbilityToken_003 start" << std::endl;
/**
* @tc.steps: step1. pop exist sessionId.
* @tc.expected: step1. return true.
*/
int32_t sessionId =PushAbilityToken();
sptr<IRemoteObject> abilityToken = dschedContinuation_->PopAbilityToken(sessionId);
EXPECT_TRUE(abilityToken != nullptr);
/**
* @tc.steps: step2. duplicate pop abilityToken.
* @tc.expected: step1. return false.
*/
abilityToken = dschedContinuation_->PopAbilityToken(sessionId);
EXPECT_TRUE(abilityToken == nullptr);
DTEST_LOG << "DSchedContinuationTest PopAbilityToken_003 end" << std::endl;
}
} // DistributedSchedule
} // namespace OHOS

View File

@ -0,0 +1,97 @@
/*
* Copyright (c) 2021 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 "mock_distributed_sched.h"
#include "dtbschedmgr_log.h"
#include "string_ex.h"
using namespace std;
using namespace OHOS::AAFwk;
using namespace OHOS::AppExecFwk;
namespace OHOS {
namespace DistributedSchedule {
int32_t MockDistributedSched::StartRemoteAbility(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode)
{
return 0;
}
int32_t MockDistributedSched::StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo,
const AccountInfo& accountInfo)
{
return 0;
}
int32_t MockDistributedSched::StartContinuation(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, const sptr<IRemoteObject>& abilityToken)
{
return 0;
}
void MockDistributedSched::NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess)
{
(void)isSuccess;
}
int32_t MockDistributedSched::NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess)
{
(void)isSuccess;
return 0;
}
int32_t MockDistributedSched::RegisterAbilityToken(const sptr<IRemoteObject>& abilityToken,
const sptr<IRemoteObject>& continuationCallback)
{
return 0;
}
int32_t MockDistributedSched::UnregisterAbilityToken(const sptr<IRemoteObject>& abilityToken,
const sptr<IRemoteObject>& continuationCallback)
{
return 0;
}
int32_t MockDistributedSched::ConnectRemoteAbility(const OHOS::AAFwk::Want& want,
const AppExecFwk::AbilityInfo& abilityInfo, const sptr<IRemoteObject>& connect)
{
return 0;
}
int32_t MockDistributedSched::DisconnectRemoteAbility(const sptr<IRemoteObject>& connect)
{
return 0;
}
int32_t MockDistributedSched::ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want,
const AppExecFwk::AbilityInfo& abilityInfo, const sptr<IRemoteObject>& connect,
const CallerInfo& callerInfo, const AccountInfo& accountInfo)
{
return 0;
}
int32_t MockDistributedSched::DisconnectAbilityFromRemote(const sptr<IRemoteObject>& connect,
int32_t uid, const std::string& sourceDeviceId)
{
return 0;
}
int32_t MockDistributedSched::NotifyProcessDiedFromRemote(const CallerInfo& callerInfo)
{
return 0;
}
} // namespace DistributedSchedule
} // namespace OHOS

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) 2021 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 MOCK_DISTRIBUTED_SCHED_H
#define MOCK_DISTRIBUTED_SCHED_H
#include "distributed_sched_stub.h"
namespace OHOS {
namespace DistributedSchedule {
class MockDistributedSched : public DistributedSchedStub {
public:
explicit MockDistributedSched(bool expectedTrue = false)
{
expectedTrue_ = expectedTrue;
}
~MockDistributedSched() = default;
int32_t StartRemoteAbility(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode) override;
int32_t StartAbilityFromRemote(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, int32_t requestCode, const CallerInfo& callerInfo,
const AccountInfo& accountInfo) override;
int32_t StartContinuation(const OHOS::AAFwk::Want& want,
const OHOS::AppExecFwk::AbilityInfo& abilityInfo, const sptr<IRemoteObject>& abilityToken) override;
void NotifyCompleteContinuation(const std::u16string& devId, int32_t sessionId, bool isSuccess) override;
int32_t NotifyContinuationResultFromRemote(int32_t sessionId, bool isSuccess) override;
int32_t RegisterAbilityToken(const sptr<IRemoteObject>& abilityToken,
const sptr<IRemoteObject>& continuationCallback) override;
int32_t UnregisterAbilityToken(const sptr<IRemoteObject>& abilityToken,
const sptr<IRemoteObject>& continuationCallback) override;
int32_t ConnectRemoteAbility(const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo,
const sptr<IRemoteObject>& connect) override;
int32_t DisconnectRemoteAbility(const sptr<IRemoteObject>& connect) override;
int32_t ConnectAbilityFromRemote(const OHOS::AAFwk::Want& want, const AppExecFwk::AbilityInfo& abilityInfo,
const sptr<IRemoteObject>& connect, const CallerInfo& callerInfo, const AccountInfo& accountInfo) override;
int32_t DisconnectAbilityFromRemote(const sptr<IRemoteObject>& connect,
int32_t uid, const std::string& sourceDeviceId) override;
int32_t NotifyProcessDiedFromRemote(const CallerInfo& callerInfo) override;
private:
bool expectedTrue_ = false;
};
} // namespace DistributedSchedule
} // namespace OHOS
#endif // MOCK_DISTRIBUTED_SCHED_H