mirror of
https://gitee.com/openharmony/distributeddatamgr_pasteboard
synced 2024-11-23 07:59:55 +00:00
commit
d8b13d6ad5
@ -22,7 +22,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "parcel.h"
|
||||
#include "paste_data_record.h"
|
||||
#include "pasteboard_hilog.h"
|
||||
#include "tlv_object.h"
|
||||
@ -50,7 +49,7 @@ struct PasteDataProperty : public TLVObject {
|
||||
size_t Count() override;
|
||||
};
|
||||
|
||||
class PasteData : public Parcelable, public TLVObject {
|
||||
class PasteData : public TLVObject {
|
||||
public:
|
||||
static constexpr const std::uint32_t MAX_RECORD_NUM = 512;
|
||||
PasteData();
|
||||
@ -95,8 +94,6 @@ public:
|
||||
std::string GetTag();
|
||||
void SetAdditions(AAFwk::WantParams &additions);
|
||||
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
static PasteData *Unmarshalling(Parcel &parcel);
|
||||
bool Encode(std::vector<std::uint8_t> &buffer) override;
|
||||
bool Decode(const std::vector<std::uint8_t> &buffer) override;
|
||||
size_t Count() override;
|
||||
@ -113,8 +110,6 @@ public:
|
||||
static const std::string SHARE_PATH_PREFIX_ACCOUNT;
|
||||
|
||||
private:
|
||||
bool MarshallingProps(Parcel &parcel) const;
|
||||
static bool UnMarshalling(Parcel &parcel, PasteDataProperty &props);
|
||||
void RefreshMimeProp();
|
||||
|
||||
PasteDataProperty props_;
|
||||
|
@ -20,7 +20,6 @@
|
||||
#include <string>
|
||||
|
||||
#include "message_parcel.h"
|
||||
#include "parcel.h"
|
||||
#include "pixel_map.h"
|
||||
#include "string_ex.h"
|
||||
#include "tlv_object.h"
|
||||
@ -40,13 +39,11 @@ const std::string MIMETYPE_TEXT_WANT = "text/want";
|
||||
|
||||
enum ResultCode : int32_t { OK = 0, IPC_NO_DATA, IPC_ERROR };
|
||||
|
||||
class MineCustomData : public Parcelable, public TLVObject {
|
||||
class MineCustomData : public TLVObject {
|
||||
public:
|
||||
MineCustomData() = default;
|
||||
std::map<std::string, std::vector<uint8_t>> GetItemData();
|
||||
void AddItemData(const std::string &mimeType, const std::vector<uint8_t> &arrayBuffer);
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
static MineCustomData *Unmarshalling(Parcel &parcel);
|
||||
bool Encode(std::vector<std::uint8_t> &buffer) override;
|
||||
bool Decode(const std::vector<std::uint8_t> &buffer) override;
|
||||
size_t Count() override;
|
||||
@ -66,7 +63,7 @@ private:
|
||||
int32_t fd_ = -1;
|
||||
};
|
||||
|
||||
class PasteDataRecord : public Parcelable, public TLVObject {
|
||||
class PasteDataRecord : public TLVObject {
|
||||
public:
|
||||
PasteDataRecord();
|
||||
PasteDataRecord(std::string mimeType, std::shared_ptr<std::string> htmlText,
|
||||
@ -91,8 +88,6 @@ public:
|
||||
|
||||
std::string ConvertToText() const;
|
||||
|
||||
virtual bool Marshalling(Parcel &parcel) const override;
|
||||
static PasteDataRecord *Unmarshalling(Parcel &parcel);
|
||||
bool Encode(std::vector<std::uint8_t> &buffer) override;
|
||||
bool Decode(const std::vector<std::uint8_t> &buffer) override;
|
||||
size_t Count() override;
|
||||
@ -119,11 +114,6 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
static bool Marshalling(Parcel &parcel, std::shared_ptr<std::string> item);
|
||||
static bool Marshalling(Parcel &parcel, std::shared_ptr<Parcelable> item);
|
||||
template<typename T>
|
||||
static ResultCode UnMarshalling(Parcel &parcel, std::shared_ptr<T> &item);
|
||||
static ResultCode UnMarshalling(Parcel &parcel, std::shared_ptr<std::string> &item);
|
||||
inline static bool CheckResult(ResultCode resultCode)
|
||||
{
|
||||
return resultCode == ResultCode::OK;
|
||||
|
@ -318,110 +318,6 @@ void PasteData::RefreshMimeProp()
|
||||
props_.mimeTypes = mimeTypes;
|
||||
}
|
||||
|
||||
bool PasteData::MarshallingProps(Parcel &parcel) const
|
||||
{
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "props.shareOption = %{public}d.", props_.shareOption);
|
||||
return parcel.WriteParcelable(&props_.additions) && parcel.WriteStringVector(props_.mimeTypes) &&
|
||||
parcel.WriteString(props_.tag) && parcel.WriteInt64(props_.timestamp) &&
|
||||
parcel.WriteInt32(static_cast<int32_t>(props_.shareOption));
|
||||
}
|
||||
|
||||
bool PasteData::UnMarshalling(Parcel &parcel, PasteDataProperty &props)
|
||||
{
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "start.");
|
||||
|
||||
std::shared_ptr<AAFwk::WantParams> wantParams(parcel.ReadParcelable<AAFwk::WantParams>());
|
||||
if (wantParams != nullptr) {
|
||||
props.additions = *wantParams;
|
||||
}
|
||||
if (!parcel.ReadStringVector(&props.mimeTypes)) {
|
||||
return false;
|
||||
}
|
||||
props.tag = parcel.ReadString();
|
||||
props.timestamp = parcel.ReadInt64();
|
||||
props.shareOption = static_cast<ShareOption>(parcel.ReadInt32());
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "props.shareOption = %{public}d.", props.shareOption);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PasteData::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
auto length = records_.size();
|
||||
if (length == 0) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "length == 0.");
|
||||
return false;
|
||||
}
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "start, length = %{public}zu.", length);
|
||||
if (!parcel.WriteUint32(static_cast<uint32_t>(length))) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "write length failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto &item : records_) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "for.");
|
||||
if (!parcel.WriteParcelable(item.get())) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "WriteParcelable failed.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
auto ret = MarshallingProps(parcel);
|
||||
if (!ret) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "MarshallingProps failed.");
|
||||
return false;
|
||||
}
|
||||
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "end.");
|
||||
return true;
|
||||
}
|
||||
|
||||
PasteData *PasteData::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "start.");
|
||||
auto *pasteData = new (std::nothrow) PasteData();
|
||||
if (pasteData == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "pasteData is nullptr.");
|
||||
return pasteData;
|
||||
}
|
||||
|
||||
auto length = parcel.ReadUint32();
|
||||
if (length <= 0) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "length error.");
|
||||
delete pasteData;
|
||||
pasteData = nullptr;
|
||||
return pasteData;
|
||||
}
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "length = %{public}u.", length);
|
||||
|
||||
uint32_t failedNum = 0;
|
||||
for (uint32_t i = 0; i < length; i++) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "for.");
|
||||
std::unique_ptr<PasteDataRecord> record(parcel.ReadParcelable<PasteDataRecord>());
|
||||
if (!record) {
|
||||
failedNum++;
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "ReadParcelable failed, i = %{public}d.", i);
|
||||
continue;
|
||||
}
|
||||
pasteData->AddRecord(*record);
|
||||
}
|
||||
if (failedNum == length) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "all failed.");
|
||||
delete pasteData;
|
||||
pasteData = nullptr;
|
||||
return pasteData;
|
||||
}
|
||||
|
||||
auto ret = UnMarshalling(parcel, pasteData->props_);
|
||||
if (!ret) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "UnMarshallingProps failed.");
|
||||
delete pasteData;
|
||||
pasteData = nullptr;
|
||||
}
|
||||
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "end.");
|
||||
return pasteData;
|
||||
}
|
||||
|
||||
bool PasteData::Encode(std::vector<std::uint8_t> &buffer)
|
||||
{
|
||||
Init(buffer);
|
||||
|
@ -215,177 +215,6 @@ std::string PasteDataRecord::ConvertToText() const
|
||||
}
|
||||
}
|
||||
|
||||
bool PasteDataRecord::Marshalling(Parcel &parcel, std::shared_ptr<std::string> item)
|
||||
{
|
||||
if (!parcel.WriteBool(item != nullptr)) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "WriteBool failed.");
|
||||
return false;
|
||||
}
|
||||
if (item == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "no data provide.");
|
||||
return true;
|
||||
}
|
||||
return parcel.WriteString16(Str8ToStr16(*item));
|
||||
}
|
||||
|
||||
bool PasteDataRecord::Marshalling(Parcel &parcel, std::shared_ptr<Parcelable> item)
|
||||
{
|
||||
if (!parcel.WriteBool(item != nullptr)) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "WriteBool failed.");
|
||||
return false;
|
||||
}
|
||||
if (item == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "no data provide.");
|
||||
return true;
|
||||
}
|
||||
return parcel.WriteParcelable(item.get());
|
||||
}
|
||||
|
||||
bool PasteDataRecord::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
if (!parcel.WriteString16(Str8ToStr16(mimeType_))) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "write mimeType failed, mimeType = %{public}s.", mimeType_.c_str());
|
||||
return false;
|
||||
}
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "mimeType = %{public}s,", mimeType_.c_str());
|
||||
bool ret = Marshalling(parcel, htmlText_);
|
||||
ret = Marshalling(parcel, want_) && ret;
|
||||
ret = Marshalling(parcel, plainText_) && ret;
|
||||
ret = Marshalling(parcel, uri_) && ret;
|
||||
ret = Marshalling(parcel, pixelMap_) && ret;
|
||||
ret = Marshalling(parcel, customData_) && ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
ResultCode PasteDataRecord::UnMarshalling(Parcel &parcel, std::shared_ptr<T> &item)
|
||||
{
|
||||
if (!parcel.ReadBool()) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "no data provide.");
|
||||
return ResultCode::IPC_NO_DATA;
|
||||
}
|
||||
std::shared_ptr<T> parcelAble(parcel.ReadParcelable<T>());
|
||||
if (!parcelAble) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "ReadParcelable failed.");
|
||||
return ResultCode::IPC_ERROR;
|
||||
}
|
||||
item = move(parcelAble);
|
||||
return ResultCode::OK;
|
||||
}
|
||||
|
||||
ResultCode PasteDataRecord::UnMarshalling(Parcel &parcel, std::shared_ptr<std::string> &item)
|
||||
{
|
||||
if (!parcel.ReadBool()) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "no data provide.");
|
||||
return ResultCode::IPC_NO_DATA;
|
||||
}
|
||||
item = std::make_shared<std::string>(Str16ToStr8(parcel.ReadString16()));
|
||||
if (!item) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "ReadString16 failed.");
|
||||
return ResultCode::IPC_ERROR;
|
||||
}
|
||||
return ResultCode::OK;
|
||||
}
|
||||
|
||||
PasteDataRecord *PasteDataRecord::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "start.");
|
||||
auto pasteDataRecord = new (std::nothrow) PasteDataRecord();
|
||||
|
||||
if (pasteDataRecord == nullptr) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "pasteDataRecord is nullptr.");
|
||||
return pasteDataRecord;
|
||||
}
|
||||
|
||||
pasteDataRecord->mimeType_ = Str16ToStr8(parcel.ReadString16());
|
||||
if (pasteDataRecord->mimeType_.empty()) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "ReadString16 failed.");
|
||||
delete pasteDataRecord;
|
||||
pasteDataRecord = nullptr;
|
||||
return pasteDataRecord;
|
||||
}
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "mimeType = %{public}s,", pasteDataRecord->mimeType_.c_str());
|
||||
|
||||
ResultCode resultCode = UnMarshalling(parcel, pasteDataRecord->htmlText_);
|
||||
auto ret = CheckResult(resultCode);
|
||||
resultCode = UnMarshalling(parcel, pasteDataRecord->want_);
|
||||
ret = CheckResult(resultCode) || ret;
|
||||
resultCode = UnMarshalling(parcel, pasteDataRecord->plainText_);
|
||||
ret = CheckResult(resultCode) || ret;
|
||||
resultCode = UnMarshalling(parcel, pasteDataRecord->uri_);
|
||||
ret = CheckResult(resultCode) || ret;
|
||||
resultCode = UnMarshalling(parcel, pasteDataRecord->pixelMap_);
|
||||
ret = CheckResult(resultCode) || ret;
|
||||
resultCode = UnMarshalling(parcel, pasteDataRecord->customData_);
|
||||
ret = CheckResult(resultCode) || ret;
|
||||
if (!ret) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "UnMarshalling failed.");
|
||||
delete pasteDataRecord;
|
||||
pasteDataRecord = nullptr;
|
||||
}
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "end.");
|
||||
return pasteDataRecord;
|
||||
}
|
||||
|
||||
bool MineCustomData::Marshalling(Parcel &parcel) const
|
||||
{
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "begin.");
|
||||
auto len = itemData_.size();
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "itemData_len = %{public}zu,", len);
|
||||
if (!parcel.WriteUint32(static_cast<uint32_t>(len))) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "len Marshalling failed.");
|
||||
return false;
|
||||
}
|
||||
for (const auto &item : itemData_) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "dataLen = %{public}zu!", item.second.size());
|
||||
if (!parcel.WriteString(item.first) || !parcel.WriteUInt8Vector(item.second)) {
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "write failed.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "end.");
|
||||
return true;
|
||||
}
|
||||
|
||||
MineCustomData *MineCustomData::Unmarshalling(Parcel &parcel)
|
||||
{
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "begin.");
|
||||
auto *mineCustomData = new (std::nothrow) MineCustomData();
|
||||
|
||||
if (mineCustomData == nullptr) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "mineCustomData is nullptr.");
|
||||
return mineCustomData;
|
||||
}
|
||||
|
||||
uint32_t failedNums = 0;
|
||||
auto len = parcel.ReadUint32();
|
||||
if (len <= 0) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "length error");
|
||||
delete mineCustomData;
|
||||
mineCustomData = nullptr;
|
||||
return mineCustomData;
|
||||
}
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
std::string mimeType = parcel.ReadString();
|
||||
std::vector<uint8_t> arrayBuffer;
|
||||
if (!parcel.ReadUInt8Vector(&arrayBuffer) || arrayBuffer.empty()) {
|
||||
failedNums++;
|
||||
continue;
|
||||
}
|
||||
mineCustomData->AddItemData(mimeType, arrayBuffer);
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "dataLen = %{public}zu.", arrayBuffer.size());
|
||||
}
|
||||
|
||||
if (failedNums == len) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "mineCustomData is nullptr.");
|
||||
delete mineCustomData;
|
||||
mineCustomData = nullptr;
|
||||
}
|
||||
PASTEBOARD_HILOGD(PASTEBOARD_MODULE_CLIENT, "end.");
|
||||
return mineCustomData;
|
||||
}
|
||||
|
||||
bool MineCustomData::Encode(std::vector<std::uint8_t> &buffer)
|
||||
{
|
||||
return TLVObject::Write(buffer, TAG_ITEM_DATA, itemData_);
|
||||
|
@ -174,53 +174,6 @@ HWTEST_F(PasteDataTest, GetRealPathFailed002, TestSize.Level0)
|
||||
EXPECT_EQ(ret, INVALID_FD);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PasteDataMarshallingUnMarshalling001
|
||||
* @tc.desc: PasteData: Marshalling unMarshalling
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AROOOH5R5G
|
||||
* @tc.author: chenyu
|
||||
*/
|
||||
HWTEST_F(PasteDataTest, PasteDataMarshallingUnMarshalling001, TestSize.Level0)
|
||||
{
|
||||
std::string htmlText = "<div class='disabled item tip user-programs'>";
|
||||
auto pasteData = PasteboardClient::GetInstance()->CreateHtmlData(htmlText);
|
||||
Parcel parcel;
|
||||
auto ret = pasteData->Marshalling(parcel);
|
||||
ASSERT_TRUE(ret);
|
||||
std::shared_ptr<PasteData> pasteData1(pasteData->Unmarshalling(parcel));
|
||||
ASSERT_TRUE(pasteData1 != nullptr);
|
||||
auto html = pasteData1->GetPrimaryHtml();
|
||||
ASSERT_TRUE(html != nullptr);
|
||||
EXPECT_EQ(*html, htmlText);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PasteDataRecordMarshallingUnMarshalling001
|
||||
* @tc.desc: PasteDataRecord: Marshalling unMarshalling
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AROOOH5R5G
|
||||
* @tc.author: chenyu
|
||||
*/
|
||||
HWTEST_F(PasteDataTest, PasteDataRecordMarshallingUnMarshalling001, TestSize.Level0)
|
||||
{
|
||||
std::shared_ptr<OHOS::AAFwk::Want> want = std::make_shared<OHOS::AAFwk::Want>();
|
||||
std::string key = "id";
|
||||
int32_t id = 456;
|
||||
Want wantIn = want->SetParam(key, id);
|
||||
auto record = PasteboardClient::GetInstance()->CreateWantRecord(want);
|
||||
ASSERT_TRUE(record != nullptr);
|
||||
Parcel parcel;
|
||||
auto ret = record->Marshalling(parcel);
|
||||
ASSERT_TRUE(ret);
|
||||
std::shared_ptr<PasteDataRecord> record1(record->Unmarshalling(parcel));
|
||||
ASSERT_TRUE(record1 != nullptr);
|
||||
auto newWant = record->GetWant();
|
||||
ASSERT_TRUE(newWant != nullptr);
|
||||
int32_t defaultValue = 333;
|
||||
EXPECT_EQ(newWant->GetIntParam(key, defaultValue), id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: ConvertToText001
|
||||
* @tc.desc: PasteDataRecord: ConvertToText
|
||||
|
@ -503,7 +503,7 @@ HWTEST_F(PasteboardServiceTest, PasteDataTest004, TestSize.Level0)
|
||||
|
||||
/**
|
||||
* @tc.name: PasteDataTest005
|
||||
* @tc.desc: marshalling test.
|
||||
* @tc.desc: CreateHtmlData test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000HEECD
|
||||
*/
|
||||
@ -551,7 +551,7 @@ HWTEST_F(PasteboardServiceTest, PasteDataTest005, TestSize.Level0)
|
||||
|
||||
/**
|
||||
* @tc.name: PasteDataTest006
|
||||
* @tc.desc: marshalling test.
|
||||
* @tc.desc: CreatePlainTextData test.
|
||||
* @tc.type: FUNC
|
||||
*/
|
||||
HWTEST_F(PasteboardServiceTest, PasteDataTest006, TestSize.Level0)
|
||||
@ -584,7 +584,7 @@ HWTEST_F(PasteboardServiceTest, PasteDataTest006, TestSize.Level0)
|
||||
|
||||
/**
|
||||
* @tc.name: PasteDataTest007
|
||||
* @tc.desc: marshalling test.
|
||||
* @tc.desc: PixelMap test.
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000H5GKU
|
||||
*/
|
||||
@ -775,44 +775,6 @@ HWTEST_F(PasteboardServiceTest, PasteDataTest0012, TestSize.Level0)
|
||||
ASSERT_TRUE(secondRecordMimeType == MIMETYPE_TEXT_PLAIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PasteDataTest0013
|
||||
* @tc.desc: MineCustomData: Marshalling unMarshalling
|
||||
* @tc.type: FUNC
|
||||
* @tc.require: AR000HEECD
|
||||
*/
|
||||
HWTEST_F(PasteboardServiceTest, PasteDataTest0013, TestSize.Level0)
|
||||
{
|
||||
std::string plainText = "plain text";
|
||||
auto pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(plainText);
|
||||
ASSERT_TRUE(pasteData != nullptr);
|
||||
std::vector<uint8_t> arrayBuffer(46);
|
||||
arrayBuffer = { 2, 7, 6, 8, 9 };
|
||||
std::string mimeType = "image/jpg";
|
||||
pasteData->AddKvRecord(mimeType, arrayBuffer);
|
||||
auto record = pasteData->GetRecordAt(0);
|
||||
ASSERT_TRUE(record != nullptr);
|
||||
std::string mimeType1 = "img/png";
|
||||
std::vector<uint8_t> arrayBuffer1(54);
|
||||
arrayBuffer1 = { 4, 7, 9, 8, 7 };
|
||||
auto customData = record->GetCustomData();
|
||||
ASSERT_TRUE(customData != nullptr);
|
||||
customData->AddItemData(mimeType1, arrayBuffer1);
|
||||
Parcel parcel;
|
||||
auto ret = customData->Marshalling(parcel);
|
||||
ASSERT_TRUE(ret == true);
|
||||
std::shared_ptr<MineCustomData> customDataGet(customData->Unmarshalling(parcel));
|
||||
ASSERT_TRUE(customDataGet != nullptr);
|
||||
auto itemData = customDataGet->GetItemData();
|
||||
ASSERT_TRUE(itemData.size() == 2);
|
||||
auto item = itemData.find(mimeType);
|
||||
ASSERT_TRUE(item != itemData.end());
|
||||
ASSERT_TRUE(item->second == arrayBuffer);
|
||||
item = itemData.find(mimeType1);
|
||||
ASSERT_TRUE(item != itemData.end());
|
||||
ASSERT_TRUE(item->second == arrayBuffer1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @tc.name: PasteDataTest0014
|
||||
* @tc.desc: Create paste board data test.
|
||||
|
Loading…
Reference in New Issue
Block a user