添加Metadata与字节流的互相转换,修改单元测试

Signed-off-by: wanganjie <wanganjie1@huawei.com>
This commit is contained in:
wanganjie 2023-10-30 19:21:39 +08:00
parent 3375c6804c
commit 3b495ddebe
4 changed files with 68 additions and 7 deletions

3
bundle.json Executable file → Normal file
View File

@ -185,7 +185,8 @@
"header": {
"header_files": [
"graphic_common.h",
"graphic_common_c.h"
"graphic_common_c.h",
"metadata_convertor.h"
],
"header_base": "//foundation/graphic/graphic_2d/interfaces/inner_api/common"
}

View File

@ -189,7 +189,12 @@ ohos_unittest("surface_buffer_impl_test") {
deps = [ ":surface_test_common" ]
public_deps = [
"//foundation/graphic/graphic_2d/utils:libgraphic_utils",
]
external_deps = [
"drivers_interface_display:display_commontype_idl_headers",
"c_utils:utils",
"hilog:libhilog",
]

View File

@ -182,23 +182,27 @@ HWTEST_F(SurfaceBufferImplTest, Metadata001, Function | MediumTest | Level2)
ASSERT_EQ(sret, OHOS::GSERROR_OK);
BufferHandleAttrKey metadataKey = ATTRKEY_COLORSPACE_TYPE;
CM_ColorSpaceType metadataValue = CM_BT709_LIMIT;
std::vector<uint8_t> setValue = Uint32ToVector(metadataValue);
sret = sbi->SetMetadata(metadataKey, setValue);
CM_ColorSpaceType setMetadata = CM_BT709_LIMIT;
std::vector<uint8_t> setData;
ASSERT_EQ(MetadataManager::ConvertMetadataToVec(setMetadata, setData), 0);
sret = sbi->SetMetadata(metadataKey, setData);
ASSERT_EQ(sret, OHOS::GSERROR_OK);
std::vector<uint8_t> getValue;
sret = sbi->GetMetadata(metadataKey, getValue);
std::vector<uint8_t> getData;
sret = sbi->GetMetadata(metadataKey, getData);
ASSERT_EQ(sret, OHOS::GSERROR_OK);
CM_ColorSpaceType getMetadata;
ASSERT_EQ(MetadataManager::ConvertVecToMetadata(getData, getMetadata), 0);
ASSERT_EQ(VectorToUint32(getValue), metadataValue);
ASSERT_EQ(setMetadata, getMetadata);
std::vector<uint32_t> keys;
sret = sbi->ListMetadataKeys(keys);
ASSERT_EQ(sret, OHOS::GSERROR_OK);
ASSERT_EQ(keys.size(), 1);
ASSERT_EQ(keys[0], metadataKey);
sret = sbi->EraseMetadataKey(metadataKey);
ASSERT_EQ(sret, OHOS::GSERROR_OK);

View File

@ -0,0 +1,51 @@
/*
* Copyright (c) 2021-2023 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 METADATA_CONVERTOR_H
#define METADATA_CONVERTOR_H
#include <vector>
#include <securec.h>
namespace OHOS {
namespace MetadataManager {
// 0 for success, -1 for fail
template <typename T>
static int32_t ConvertMetadataToVec(const T& metadata, std::vector<uint8_t>& data)
{
data.resize(sizeof(T));
if (memcpy_s(data.data(), data.size(), &metadata, sizeof(T)) != EOK) {
return -1;
}
return 0;
}
template <typename T>
static int32_t ConvertVecToMetadata(const std::vector<uint8_t>& data, T& metadata)
{
if (data.size() != sizeof(T)) {
return -1;
}
if (memcpy_s(&metadata, sizeof(T), data.data(), data.size()) != EOK) {
return -1;
}
return 0;
}
} // namespace MetadataManager
} // namespace OHOS
#endif // METADATA_CONVERTOR_H