mirror of
https://gitee.com/openharmony/distributeddatamgr_pasteboard
synced 2024-11-27 01:52:01 +00:00
UT of JS multi style interface
Signed-off-by: cuile4 <cuile4@huawei.com> Change-Id: Ia78b22708964e34e8446a05a311317993d73ca97 Signed-off-by: cuile4 <cuile4@huawei.com>
This commit is contained in:
parent
9cf36c4ebc
commit
24bd49a48b
@ -77,6 +77,7 @@ public:
|
||||
static std::string Convert2MimeType(const std::string &utdId);
|
||||
static UDType Convert(int32_t uDType, const std::string &mimeType);
|
||||
static std::string Convert2UtdId(int32_t uDType, const std::string &mimeType);
|
||||
static bool IsFileUri(const std::string &utdId);
|
||||
};
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
||||
|
@ -127,6 +127,10 @@ std::vector<std::shared_ptr<PasteDataEntry>> ConvertUtils::Convert(
|
||||
|
||||
UDMF::ValueType ConvertUtils::Convert(const std::shared_ptr<PasteDataEntry>& entry)
|
||||
{
|
||||
if (entry == nullptr) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "entry is null, convert failed.");
|
||||
return nullptr;
|
||||
}
|
||||
auto utdId = entry->GetUtdId();
|
||||
auto value = entry->GetValue();
|
||||
if (std::holds_alternative<std::monostate>(value) || std::holds_alternative<std::shared_ptr<Object>>(value)) {
|
||||
@ -155,7 +159,7 @@ UDMF::ValueType ConvertUtils::Convert(const std::shared_ptr<PasteDataEntry>& ent
|
||||
object->value_[UDMF::PIXEL_MAP] = std::get<std::shared_ptr<OHOS::Media::PixelMap>>(value);
|
||||
}
|
||||
} else if (mimeType == MIMETYPE_TEXT_WANT) {
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "mimeType is want,udmf not surpport");
|
||||
PASTEBOARD_HILOGW(PASTEBOARD_MODULE_CLIENT, "mimeType is want, udmf not support");
|
||||
} else {
|
||||
object->value_[UDMF::UNIFORM_DATA_TYPE] = utdId;
|
||||
if (std::holds_alternative<std::vector<uint8_t>>(value)) {
|
||||
|
@ -233,7 +233,7 @@ std::shared_ptr<std::string> PasteDataEntry::ConvertToHtml() const
|
||||
std::shared_ptr<Uri> PasteDataEntry::ConvertToUri() const
|
||||
{
|
||||
std::string res;
|
||||
if (!UDMF::UnifiedDataUtils::IsFileUri(GetUtdId())) {
|
||||
if (!CommonUtils::IsFileUri(GetUtdId())) {
|
||||
PASTEBOARD_HILOGE(PASTEBOARD_MODULE_CLIENT, "type error, utdId:%{public}s", GetUtdId().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
@ -384,7 +384,7 @@ std::string CommonUtils::Convert2MimeType(const std::string &utdId)
|
||||
if (utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::HTML)) {
|
||||
return MIMETYPE_TEXT_HTML;
|
||||
}
|
||||
if (UDMF::UnifiedDataUtils::IsFileUri(utdId)) {
|
||||
if (IsFileUri(utdId)) {
|
||||
return MIMETYPE_TEXT_URI;
|
||||
}
|
||||
if (utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::SYSTEM_DEFINED_PIXEL_MAP)) {
|
||||
@ -446,5 +446,15 @@ UDMF::UDType CommonUtils::Convert(int32_t uDType, const std::string &mimeType)
|
||||
}
|
||||
return UDMF::APPLICATION_DEFINED_RECORD;
|
||||
}
|
||||
|
||||
bool CommonUtils::IsFileUri(const std::string &utdId)
|
||||
{
|
||||
return utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::FILE_URI) ||
|
||||
utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::FILE) ||
|
||||
utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::AUDIO) ||
|
||||
utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::IMAGE) ||
|
||||
utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::FOLDER) ||
|
||||
utdId == UDMF::UtdUtils::GetUtdIdFromUtdEnum(UDType::VIDEO);
|
||||
}
|
||||
} // namespace MiscServices
|
||||
} // namespace OHOS
|
@ -739,7 +739,8 @@ std::shared_ptr<PasteDataEntry> PasteDataRecord::GetEntry(const std::string& utd
|
||||
return entry;
|
||||
}
|
||||
for (auto const &entry : entries_) {
|
||||
if (entry->GetUtdId() == utdType) {
|
||||
if (entry->GetUtdId() == utdType ||
|
||||
(CommonUtils::IsFileUri(utdType) && CommonUtils::IsFileUri(entry->GetUtdId()))) {
|
||||
if (isDelay_ && !entry->HasContent(utdType)) {
|
||||
PASTEBOARD_HILOGI(PASTEBOARD_MODULE_CLIENT, "Begin GetRecordValueByType2");
|
||||
PasteboardClient::GetInstance()->GetRecordValueByType(dataId_, recordId_, *entry);
|
||||
|
@ -188,7 +188,7 @@ HWTEST_F(PasteDataTest, uriConvertTest001, TestSize.Level0)
|
||||
bool result = data.ReadUriFd(parcel, copyHandler);
|
||||
EXPECT_TRUE(result);
|
||||
auto distributedUri = data.GetPrimaryUri()->ToString();
|
||||
EXPECT_FALSE(uriStr == distributedUri);
|
||||
EXPECT_TRUE(uriStr == distributedUri);
|
||||
|
||||
MessageParcel parcel1;
|
||||
PasteUriHandler pasteHandler;
|
||||
@ -202,7 +202,7 @@ HWTEST_F(PasteDataTest, uriConvertTest001, TestSize.Level0)
|
||||
ASSERT_TRUE(data.GetPrimaryUri() != nullptr);
|
||||
auto convertedUri = data.GetPrimaryUri()->ToString();
|
||||
EXPECT_EQ(distributedUri, convertedUri);
|
||||
EXPECT_FALSE(uriStr == convertedUri);
|
||||
EXPECT_TRUE(uriStr == convertedUri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user