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 "account_adapt_test.h"
17 #include <cerrno>
18 #include <gtest/gtest.h>
19 #include <securec.h>
20 #include "dlp_permission.h"
21 #include "dlp_permission_log.h"
22
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::Security::DlpPermission;
26 using namespace std;
27
28 namespace {
29 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN_DLP_PERMISSION, "AccountAdaptTest"};
30 }
31
SetUpTestCase()32 void AccountAdaptTest::SetUpTestCase() {}
33
TearDownTestCase()34 void AccountAdaptTest::TearDownTestCase() {}
35
SetUp()36 void AccountAdaptTest::SetUp() {}
37
TearDown()38 void AccountAdaptTest::TearDown() {}
39
40 /**
41 * @tc.name: IsAccountLogIn001
42 * @tc.desc: IsAccountLogIn test
43 * @tc.type: FUNC
44 * @tc.require:
45 */
46 HWTEST_F(AccountAdaptTest, IsAccountLogIn001, TestSize.Level1)
47 {
48 DLP_LOG_INFO(LABEL, "IsAccountLogIn001");
49
50 uint32_t osAccountId = 0;
51 AccountType accountType = APPLICATION_ACCOUNT;
52 DlpBlob accountId;
53
54 uint8_t data = 1;
55 accountId.data = &data;
56 accountId.size = 0;
57
58 // accountId != nullptr
59 bool ret = IsAccountLogIn(osAccountId, accountType, &accountId);
60 ASSERT_TRUE(ret);
61
62 accountType = CLOUD_ACCOUNT;
63 ret = IsAccountLogIn(osAccountId, accountType, &accountId);
64 ASSERT_FALSE(ret);
65
66 accountType = DOMAIN_ACCOUNT;
67 ret = IsAccountLogIn(osAccountId, accountType, &accountId);
68 ASSERT_FALSE(ret);
69 }
70
71 /**
72 * @tc.name: GetDomainAccountName001
73 * @tc.desc: GetDomainAccountName test
74 * @tc.type: FUNC
75 * @tc.require:
76 */
77 HWTEST_F(AccountAdaptTest, GetDomainAccountName001, TestSize.Level1)
78 {
79 DLP_LOG_INFO(LABEL, "GetDomainAccountName001");
80
81 char** account = new (std::nothrow) char*[10];
82 if (account != nullptr) {
83 int32_t ret = GetDomainAccountName(account);
84 ASSERT_EQ(DLP_PARSE_ERROR_ACCOUNT_INVALID, ret);
85 delete[] account;
86 }
87 }