• 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 "gtest/gtest.h"
17 #include "group_data_manager.h"
18 #include "device_auth_defines.h"
19 #include "device_auth.h"
20 #include "common_defs.h"
21 using namespace testing::ext;
22 namespace {
23 static const int32_t TEST_OS_ACCOUNT_ID = 0;
24 static const char *TEST_OWNER = "test_owner";
25 static const char *TEST_GROUP_ID = "test_group_id";
26 static const char *TEST_GROUP_NAME = "test_group_name";
27 static const char *TEST_USER_ID = "0";
28 static const char *TEST_SHARED_USER_ID = "test_sharedUser_id";
29 class GroupDataManagerTest : public testing::Test {
30 public:
31     static void SetUpTestCase(void);
32     static void TearDownTestCase(void);
33     void SetUp();
34     void TearDown();
35 };
36 
SetUpTestCase(void)37 void GroupDataManagerTest::SetUpTestCase(void) {}
TearDownTestCase(void)38 void GroupDataManagerTest::TearDownTestCase(void) {}
39 
SetUp(void)40 void GroupDataManagerTest::SetUp(void)
41 {
42     InitDatabase();
43 }
44 
TearDown(void)45 void GroupDataManagerTest::TearDown(void)
46 {
47     DestroyDatabase();
48 }
49 
generateTestGroupEntry(void)50 static TrustedGroupEntry *generateTestGroupEntry(void)
51 {
52     TrustedGroupEntry *entry = CreateGroupEntry();
53     if (entry == NULL) {
54         return NULL;
55     }
56     entry->type = ALL_GROUP;
57     entry->visibility = ALL_GROUP_VISIBILITY;
58     HcString ownerName = CreateString();
59     StringSetPointer(&(ownerName), TEST_OWNER);
60     entry->managers.pushBack(&entry->managers, &ownerName);
61     StringSetPointer(&(entry->name), TEST_GROUP_NAME);
62     StringSetPointer(&(entry->id), TEST_GROUP_ID);
63     StringSetPointer(&(entry->userId), TEST_USER_ID);
64     StringSetPointer(&(entry->sharedUserId), TEST_SHARED_USER_ID);
65     return entry;
66 }
67 
68 HWTEST_F(GroupDataManagerTest, DelGroupTEST001, TestSize.Level0)
69 {
70     QueryGroupParams param = InitQueryGroupParams();
71     TrustedGroupEntry *entry = generateTestGroupEntry();
72     GroupEntryVec vec = CreateGroupEntryVec();
73     ASSERT_NE(entry, nullptr);
74     EXPECT_EQ(AddGroup(TEST_OS_ACCOUNT_ID, entry), HC_SUCCESS);
75     EXPECT_EQ(DelGroup(TEST_OS_ACCOUNT_ID, nullptr), HC_ERR_NULL_PTR);
76     EXPECT_EQ(QueryGroups(TEST_OS_ACCOUNT_ID, &param, &vec), HC_SUCCESS);
77     EXPECT_EQ(HC_VECTOR_SIZE(&vec), 1);
78     ClearGroupEntryVec(&vec);
79     DestroyGroupEntry(entry);
80 }
81 }