1 /*
2  * Copyright (c) 2024 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 #include <string>
16 
17 #include <gtest/gtest.h>
18 #include "errors.h"
19 #include "os_account.h"
20 #include "os_account_common.h"
21 
22 namespace OHOS {
23 namespace AccountSA {
24 using namespace testing::ext;
25 using namespace OHOS::AccountSA;
26 using namespace OHOS;
27 using namespace AccountSA;
28 namespace {
29 static const uint32_t MAX_NAME_LENGTH = 1024;
30 }
31 class OsAccountNDKTest : public testing::Test {
32 public:
33     static void SetUpTestCase(void);
34     static void TearDownTestCase(void);
35     void SetUp(void) override;
36     void TearDown(void) override;
37 };
38 
SetUpTestCase(void)39 void OsAccountNDKTest::SetUpTestCase(void)
40 {
41 }
42 
TearDownTestCase(void)43 void OsAccountNDKTest::TearDownTestCase(void)
44 {}
45 
SetUp(void)46 void OsAccountNDKTest::SetUp(void) __attribute__((no_sanitize("cfi")))
47 {
48     testing::UnitTest *test = testing::UnitTest::GetInstance();
49     ASSERT_NE(test, nullptr);
50     const testing::TestInfo *testinfo = test->current_test_info();
51     ASSERT_NE(testinfo, nullptr);
52     string testCaseName = string(testinfo->name());
53     GTEST_LOG_(INFO) <<"[SetUp] " << testCaseName.c_str() << " start." << std::endl;
54 }
55 
TearDown(void)56 void OsAccountNDKTest::TearDown(void)
57 {}
58 
59 /**
60  * @tc.name: GetOsAccountNameTest001
61  * @tc.desc: Test invalid paramter.
62  * @tc.type: FUNC
63  * @tc.require:
64  */
65 HWTEST_F(OsAccountNDKTest, GetOsAccountNameTest001, TestSize.Level0)
66 {
67     char str[MAX_NAME_LENGTH] = { 0 };
68     EXPECT_EQ(OH_OsAccount_GetName(nullptr, MAX_NAME_LENGTH), OsAccount_ErrCode::OS_ACCOUNT_ERR_INVALID_PARAMETER);
69     EXPECT_EQ(OH_OsAccount_GetName(str, 0), OsAccount_ErrCode::OS_ACCOUNT_ERR_INVALID_PARAMETER);
70     EXPECT_EQ(OH_OsAccount_GetName(str, MAX_NAME_LENGTH), OsAccount_ErrCode::OS_ACCOUNT_ERR_OK);
71 }
72 }  // namespace AccountTest
73 }  // namespace OHOS