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