• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_system_api_test.h"
17 
18 #include <cstring>
19 #include <gtest/gtest.h>
20 
21 #include "nativetoken_kit.h"
22 #include "token_setproc.h"
23 
24 #include "asset_system_api.h"
25 #include "asset_system_type.h"
26 #include "asset_test_common.h"
27 #include "asset_mem.h"
28 
29 using namespace testing::ext;
30 namespace UnitTest::AssetSystemApiWithoutPermissionTest {
31 class AssetSystemApiWithoutPermissionTest : public testing::Test {
32 public:
33     static void SetUpTestCase(void);
34 
35     static void TearDownTestCase(void);
36 
37     void SetUp(void);
38 
39     void TearDown(void);
40 };
41 
SetUpTestCase(void)42 void AssetSystemApiWithoutPermissionTest::SetUpTestCase(void)
43 {
44 }
45 
TearDownTestCase(void)46 void AssetSystemApiWithoutPermissionTest::TearDownTestCase(void)
47 {
48 }
49 
SetUp(void)50 void AssetSystemApiWithoutPermissionTest::SetUp(void)
51 {
52 }
53 
TearDown(void)54 void AssetSystemApiWithoutPermissionTest::TearDown(void)
55 {
56 }
57 
58 /**
59  * @tc.name: AssetSystemApiWithoutPermissionTest.AssetSystemApiWithoutPermissionTest001
60  * @tc.desc: Test asset func AssetParseAttr, expect nullptr
61  * @tc.type: FUNC
62  * @tc.result:0
63  */
64 HWTEST_F(AssetSystemApiWithoutPermissionTest, AssetSystemApiWithoutPermissionTest001, TestSize.Level0)
65 {
66     uint32_t numAttrs = 2;
67 
68     // allocate memory for AssetResult
69     AssetResult result;
70     result.count = numAttrs;
71     result.attrs = (AssetAttr *)AssetMalloc(numAttrs * sizeof(AssetAttr));
72 
73     if (result.attrs == nullptr) {
74         return;
75     }
76 
77     // initialize result
78     result.attrs[0].tag = 1;
79     result.attrs[0].value.u32 = 42;
80 
81     result.attrs[1].tag = 2;
82     result.attrs[1].value.boolean = true;
83     ASSERT_EQ(nullptr, AssetParseAttr(&result, SEC_ASSET_TAG_WRAP_TYPE));
84     AssetFree(result.attrs);
85 }
86 }