mirror of
https://gitee.com/openharmony/ability_dmsfwk
synced 2024-11-23 06:20:07 +00:00
commit
027442cc45
@ -52,6 +52,7 @@ ohos_unittest("dmsbasetest") {
|
||||
"${distributed_service}/base/src/deviceManager/dms_device_info.cpp",
|
||||
"${distributed_service}/base/src/distributed_device_node_listener.cpp",
|
||||
"${distributed_service}/base/src/dtbschedmgr_device_info_storage.cpp",
|
||||
"unittest/deviceManager/dms_device_info_test.cpp",
|
||||
"unittest/dms_network_adapter_test.cpp",
|
||||
"unittest/dtbschedmgr_device_info_storage_test.cpp",
|
||||
]
|
||||
|
@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "dms_device_info_test.h"
|
||||
|
||||
#include "deviceManager/dms_device_info.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "DmsDeviceInfo";
|
||||
}
|
||||
void DmsDeviceInfoTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DmsDeviceInfoTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void DmsDeviceInfoTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void DmsDeviceInfoTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testGet_001
|
||||
* @tc.desc: test Get functions.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(DmsDeviceInfoTest, testGet_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "DmsDeviceInfoTest testGet_001 begin" << std::endl;
|
||||
DmsDeviceInfo dmsDeviceInfo("invalid deviceName", 1, "invalid deivceId");
|
||||
/**
|
||||
* @tc.steps: step1. test GetDeviceName;
|
||||
*/
|
||||
EXPECT_EQ("invalid deviceName", dmsDeviceInfo.GetDeviceName());
|
||||
/**
|
||||
* @tc.steps: step2. test GetDeviceId;
|
||||
*/
|
||||
EXPECT_EQ("invalid deivceId", dmsDeviceInfo.GetDeviceId());
|
||||
/**
|
||||
* @tc.steps: step3. test GetDeviceType;
|
||||
*/
|
||||
EXPECT_EQ(1, dmsDeviceInfo.GetDeviceType());
|
||||
/**
|
||||
* @tc.steps: step4. test GetDeviceState;
|
||||
*/
|
||||
EXPECT_EQ(1, dmsDeviceInfo.GetDeviceState());
|
||||
/**
|
||||
* @tc.steps: step5. test Marshalling;
|
||||
*/
|
||||
Parcel parcel;
|
||||
std::u16string deviceId;
|
||||
std::u16string deviceName;
|
||||
int32_t deviceType;
|
||||
int32_t deviceState;
|
||||
EXPECT_TRUE(dmsDeviceInfo.Marshalling(parcel));
|
||||
PARCEL_READ_HELPER_NORET(parcel, String16, deviceId);
|
||||
PARCEL_READ_HELPER_NORET(parcel, String16, deviceName);
|
||||
PARCEL_READ_HELPER_NORET(parcel, Int32, deviceType);
|
||||
PARCEL_READ_HELPER_NORET(parcel, Int32, deviceState);
|
||||
EXPECT_FALSE(deviceId.empty());
|
||||
EXPECT_FALSE(deviceName.empty());
|
||||
EXPECT_EQ(1, deviceType);
|
||||
EXPECT_EQ(1, deviceState);
|
||||
DTEST_LOG << "DmsDeviceInfoTest testGet_001 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
} // namespace OHOS
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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_DEVICE_INFO_TEST_H
|
||||
#define DMS_DEVICE_INFO_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class DmsDeviceInfoTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif /* DMS_DEVICE_INFO_TEST_H */
|
||||
|
@ -1261,6 +1261,108 @@ HWTEST_F(ContinuationManagerTest, Write_Read_ContinuationResultsFromParcel_001,
|
||||
DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsFromParcel_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_001
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when len is less than 0.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_001 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(-1);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_002
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when size > parcel.GetReadableBytes().
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_002, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_002 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(parcel.GetReadableBytes() + 1);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_002 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_003
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when continuationResults.max_size() < size.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_003, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_003 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(continuationResults.max_size() + 1);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_003 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_004
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when continuationResults.max_size() > size.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_004, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_004 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(continuationResults.max_size() - 1);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_004 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadContinuationResultsFromParcel_005
|
||||
* @tc.desc: test ReadContinuationResultsFromParcel when continuationResult is nullptr.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, ReadContinuationResultsFromParcel_005, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_005 start" << std::endl;
|
||||
Parcel parcel;
|
||||
ContinuationResult *continuationResult = nullptr;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
parcel.WriteInt32(VALUE_OBJECT);
|
||||
parcel.WriteInt32(1);
|
||||
parcel.WriteParcelable(continuationResult);
|
||||
bool result = ContinuationResult::ReadContinuationResultsFromParcel(parcel, continuationResults);
|
||||
EXPECT_FALSE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest ReadContinuationResultsFromParcel_005 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: WriteContinuationResultsToParcel_001
|
||||
* @tc.desc: test WriteContinuationResultsToParcel when size == 0.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(ContinuationManagerTest, WriteContinuationResultsToParcel_001, TestSize.Level3)
|
||||
{
|
||||
DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsToParcel_001 start" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<ContinuationResult> continuationResults;
|
||||
bool result = ContinuationResult::WriteContinuationResultsToParcel(parcel, continuationResults);
|
||||
EXPECT_TRUE(result);
|
||||
DTEST_LOG << "ContinuationManagerTest WriteContinuationResultsToParcel_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: Str16VecToStr8Vec_001
|
||||
* @tc.desc: test Str16VecToStr8Vec function.
|
||||
|
@ -269,6 +269,7 @@ ohos_unittest("dschedmissionmanagertest") {
|
||||
"unittest/mission/distributed_data_storage_test.cpp",
|
||||
"unittest/mission/distributed_mission_info_test.cpp",
|
||||
"unittest/mission/dms_mission_manager_test.cpp",
|
||||
"unittest/mission/mission_info_converter_test.cpp",
|
||||
"unittest/mission/snapshot_test.cpp",
|
||||
]
|
||||
sources += dtbschedmgr_sources
|
||||
|
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 "mission_info_converter_test.h"
|
||||
|
||||
#include "mission/distributed_mission_info.h"
|
||||
#include "mission/mission_info_converter.h"
|
||||
#include "parcel_helper.h"
|
||||
#include "test_log.h"
|
||||
|
||||
using namespace testing;
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
namespace {
|
||||
const std::string TAG = "DistributedAbilityManagerService";
|
||||
}
|
||||
|
||||
void MissionInfoConverterTest::SetUpTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void MissionInfoConverterTest::TearDownTestCase()
|
||||
{
|
||||
}
|
||||
|
||||
void MissionInfoConverterTest::SetUp()
|
||||
{
|
||||
}
|
||||
|
||||
void MissionInfoConverterTest::TearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testConvertToDstbMissionInfos_001
|
||||
* @tc.desc: test ConvertToDstbMissionInfos when missionInfos is empty
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, testConvertToDstbMissionInfos_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToDstbMissionInfos_001 begin" << std::endl;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
std::vector<DstbMissionInfo> dstbMissionInfos;
|
||||
int32_t result = MissionInfoConverter::ConvertToDstbMissionInfos(missionInfos, dstbMissionInfos);
|
||||
EXPECT_EQ(ERR_OK, result);
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToDstbMissionInfos_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testConvertToMissionInfos_001
|
||||
* @tc.desc: test ConvertToMissionInfos when missionInfos is empty
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, testConvertToMissionInfos_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToMissionInfos_001 begin" << std::endl;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
std::vector<DstbMissionInfo> dstbMissionInfos;
|
||||
int32_t result = MissionInfoConverter::ConvertToMissionInfos(dstbMissionInfos, missionInfos);
|
||||
EXPECT_EQ(ERR_OK, result);
|
||||
DTEST_LOG << "MissionInfoConverterTest testConvertToMissionInfos_001 end" << std::endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: testWriteMissionInfosToParcel_001
|
||||
* @tc.desc: test WriteMissionInfosToParcel when missionInfos is empty
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, testWriteMissionInfosToParcel_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest testWriteMissionInfosToParcel_001 begin" << std::endl;
|
||||
Parcel parcel;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
/**
|
||||
* @tc.steps: step1. test WriteMissionInfosToParcel when missionInfos.size is 0;
|
||||
*/
|
||||
bool result = MissionInfoConverter::WriteMissionInfosToParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(result);
|
||||
/**
|
||||
* @tc.steps: step2. test ReadMissionInfosFromParcel when empty is not VALUE_OBJECT;
|
||||
*/
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_TRUE(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ReadMissionInfosFromParcel_001
|
||||
* @tc.desc: test ReadMissionInfosFromParcel when missionInfos is empty
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(MissionInfoConverterTest, ReadMissionInfosFromParcel_001, TestSize.Level1)
|
||||
{
|
||||
DTEST_LOG << "MissionInfoConverterTest ReadMissionInfosFromParcel_001 begin" << std::endl;
|
||||
MessageParcel parcel;
|
||||
std::vector<AAFwk::MissionInfo> missionInfos;
|
||||
/**
|
||||
* @tc.steps: step1. test ReadMissionInfosFromParcel when len is less than 0;
|
||||
*/
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, -1);
|
||||
bool result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_TRUE(missionInfos.empty());
|
||||
/**
|
||||
* @tc.steps: step2. test ReadMissionInfosFromParcel when len = parcel.GetReadableBytes() + 1;
|
||||
*/
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, parcel.GetReadableBytes() + 1);
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_TRUE(missionInfos.empty());
|
||||
/**
|
||||
* @tc.steps: step3. test ReadMissionInfosFromParcel when len = missionInfos.max_size() + 1;
|
||||
*/
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, missionInfos.max_size() + 1);
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_TRUE(missionInfos.empty());
|
||||
/**
|
||||
* @tc.steps: step4. test ReadMissionInfosFromParcel when len = missionInfos.max_size() - 1;
|
||||
*/
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, 1);
|
||||
PARCEL_WRITE_HELPER_NORET(parcel, Int32, missionInfos.max_size() - 1);
|
||||
result = MissionInfoConverter::ReadMissionInfosFromParcel(parcel, missionInfos);
|
||||
EXPECT_FALSE(result);
|
||||
EXPECT_TRUE(missionInfos.empty());
|
||||
DTEST_LOG << "MissionInfoConverterTest ReadMissionInfosFromParcel_001 end" << std::endl;
|
||||
}
|
||||
} // DistributedSchedule
|
||||
} // namespace OHOS
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (c) 2022 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 MISSION_INFO_CONVERTER_TEST_H
|
||||
#define MISSION_INFO_CONVERTER_TEST_H
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace OHOS {
|
||||
namespace DistributedSchedule {
|
||||
class MissionInfoConverterTest : public testing::Test {
|
||||
public:
|
||||
static void SetUpTestCase();
|
||||
static void TearDownTestCase();
|
||||
void SetUp();
|
||||
void TearDown();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif /* MISSION_INFO_CONVERTER_TEST_H */
|
||||
|
Loading…
Reference in New Issue
Block a user