• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *    http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "asset_test_common.h"
17 
18 #include <string>
19 #include <gtest/gtest.h>
20 
21 #include "asset_api.h"
22 
RemoveByAlias(const char * alias)23 int32_t RemoveByAlias(const char *alias)
24 {
25     Asset_Attr attr[] = {
26         {
27             .tag = ASSET_TAG_ALIAS,
28             .value.blob = {
29                 .size = strlen(alias),
30                 .data = reinterpret_cast<uint8_t*>(const_cast<char*>(alias))
31             }
32         }
33     };
34     return OH_Asset_Remove(attr, ARRAY_SIZE(attr));
35 }
36 
QueryByAlias(const char * alias,Asset_ResultSet * resultSet)37 int32_t QueryByAlias(const char *alias, Asset_ResultSet *resultSet)
38 {
39     Asset_Attr attr[] = {
40         {
41             .tag = ASSET_TAG_ALIAS,
42             .value.blob = {
43                 .size = strlen(alias),
44                 .data = reinterpret_cast<uint8_t*>(const_cast<char*>(alias))
45             }
46         }, {
47             .tag = ASSET_TAG_RETURN_TYPE,
48             .value.u32 = ASSET_RETURN_ALL
49         }
50     };
51     return OH_Asset_Query(attr, ARRAY_SIZE(attr), resultSet);
52 }
53 
CompareBlob(const Asset_Blob * blob1,const Asset_Blob * blob2)54 bool CompareBlob(const Asset_Blob *blob1, const Asset_Blob *blob2)
55 {
56     if (blob1->size != blob2->size) {
57         return false;
58     }
59     return memcmp(blob1->data, blob2->data, blob1->size) == 0;
60 }