1 /*
2  * Copyright (c) 2022 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 <gmock/gmock.h>
17 #include "account_log_wrapper.h"
18 #include "ohos_account_kits.h"
19 
20 namespace OHOS {
21 namespace AccountTest {
22 namespace {
23 const std::string TEST_ACCOUNT_NAME = "TestAccountNameOS";
24 const std::string TEST_ACCOUNT_UID = "123456789os";
25 }
26 
27 using namespace testing;
28 using namespace testing::ext;
29 using namespace OHOS::AccountSA;
30 
31 class AccountOhosProxyMockTest : 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 AccountOhosProxyMockTest::SetUpTestCase(void)
40 {}
41 
TearDownTestCase(void)42 void AccountOhosProxyMockTest::TearDownTestCase(void)
43 {}
44 
SetUp(void)45 void AccountOhosProxyMockTest::SetUp(void) __attribute__((no_sanitize("cfi")))
46 {
47     testing::UnitTest *test = testing::UnitTest::GetInstance();
48     ASSERT_NE(test, nullptr);
49     const testing::TestInfo *testinfo = test->current_test_info();
50     ASSERT_NE(testinfo, nullptr);
51     string testCaseName = string(testinfo->name());
52     ACCOUNT_LOGI("[SetUp] %{public}s start", testCaseName.c_str());
53 }
54 
TearDown(void)55 void AccountOhosProxyMockTest::TearDown(void)
56 {}
57 
58 /**
59  * @tc.name: GetOhosAccountInfoTest
60  * @tc.desc: Test with proxy is nullptr
61  * @tc.type: FUNC
62  * @tc.require:
63  */
64 HWTEST_F(AccountOhosProxyMockTest, GetOhosAccountInfoTest, TestSize.Level0)
65 {
66     auto ret = OhosAccountKits::GetInstance().QueryOhosAccountInfo();
67     ASSERT_EQ(false, ret.first);
68 }
69 
70 /**
71  * @tc.name: GetOhosAccountInfoByUserIdTest
72  * @tc.desc: Test with proxy is nullptr
73  * @tc.type: FUNC
74  * @tc.require:
75  */
76 HWTEST_F(AccountOhosProxyMockTest, GetOhosAccountInfoByUserIdTest, TestSize.Level0)
77 {
78     OhosAccountInfo accountInfo;
79     std::int32_t testUserId = 200; // 200 is test user id.
80     ErrCode ret = OhosAccountKits::GetInstance().GetOhosAccountInfoByUserId(testUserId, accountInfo);
81     ASSERT_EQ(ERR_ACCOUNT_COMMON_GET_PROXY, ret);
82 }
83 
84 /**
85  * @tc.name: QueryOhosAccountInfoByUserIdTest
86  * @tc.desc: Test with proxy is nullptr
87  * @tc.type: FUNC
88  * @tc.require:
89  */
90 HWTEST_F(AccountOhosProxyMockTest, QueryOhosAccountInfoByUserIdTest, TestSize.Level0)
91 {
92     std::int32_t testUserId = 200; // 200 is test user id.
93     auto ret = OhosAccountKits::GetInstance().QueryOhosAccountInfoByUserId(testUserId);
94     ASSERT_EQ(false, ret.first);
95 }
96 
97 /**
98  * @tc.name: UpdateOhosAccountInfoTest
99  * @tc.desc: Test with proxy is nullptr
100  * @tc.type: FUNC
101  * @tc.require:
102  */
103 HWTEST_F(AccountOhosProxyMockTest, UpdateOhosAccountInfoTest, TestSize.Level0)
104 {
105     bool ret = OhosAccountKits::GetInstance().UpdateOhosAccountInfo(
106         TEST_ACCOUNT_NAME, TEST_ACCOUNT_UID, OHOS_ACCOUNT_EVENT_LOGIN);
107     ASSERT_EQ(false, ret);
108 }
109 
110 /**
111  * @tc.name: SetOhosAccountInfoTest
112  * @tc.desc: Test with proxy is nullptr
113  * @tc.type: FUNC
114  * @tc.require:
115  */
116 HWTEST_F(AccountOhosProxyMockTest, SetOhosAccountInfoTest, TestSize.Level0)
117 {
118     OhosAccountInfo accountInfo;
119     accountInfo.name_ = "TestAccountName";
120     ErrCode ret = OhosAccountKits::GetInstance().SetOhosAccountInfo(accountInfo, OHOS_ACCOUNT_EVENT_LOGIN);
121     ASSERT_EQ(ERR_ACCOUNT_COMMON_GET_PROXY, ret);
122 }
123 
124 /**
125  * @tc.name: QueryDeviceAccountIdTest
126  * @tc.desc: Test with proxy is nullptr
127  * @tc.type: FUNC
128  * @tc.require:
129  */
130 HWTEST_F(AccountOhosProxyMockTest, QueryDeviceAccountIdTest, TestSize.Level0)
131 {
132     std::int32_t id;
133     ErrCode ret = OhosAccountKits::GetInstance().QueryDeviceAccountId(id);
134     ASSERT_EQ(ERR_ACCOUNT_COMMON_GET_PROXY, ret);
135 }
136 }  // namespace AccountTest
137 }  // namespace OHOS