• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 <gtest/gtest.h>
17 
18 #include "account_log_wrapper.h"
19 #define private public
20 #include "os_account_subscribe_info.h"
21 #undef private
22 
23 using namespace testing::ext;
24 using namespace OHOS;
25 using namespace OHOS::AccountSA;
26 
27 namespace {
28 const std::string STRING_NAME = "account";
29 }  // namespace
30 class OsAccountSubscribeInfoTest : 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 OsAccountSubscribeInfoTest::SetUpTestCase(void)
39 {}
40 
TearDownTestCase(void)41 void OsAccountSubscribeInfoTest::TearDownTestCase(void)
42 {}
43 
SetUp(void)44 void OsAccountSubscribeInfoTest::SetUp(void) __attribute__((no_sanitize("cfi")))
45 {
46     testing::UnitTest *test = testing::UnitTest::GetInstance();
47     ASSERT_NE(test, nullptr);
48     const testing::TestInfo *testinfo = test->current_test_info();
49     ASSERT_NE(testinfo, nullptr);
50     string testCaseName = string(testinfo->name());
51     ACCOUNT_LOGI("[SetUp] %{public}s start", testCaseName.c_str());
52 }
53 
TearDown(void)54 void OsAccountSubscribeInfoTest::TearDown(void)
55 {}
56 
57 /**
58  * @tc.name: OsAccountSubscribeInfoTestTest01
59  * @tc.desc: Test osaccount subscribe info marshalling/unmarshalling
60  * @tc.type: FUNC
61  * @tc.require:
62  */
63 HWTEST_F(OsAccountSubscribeInfoTest, OsAccountSubscribeInfoTestTest01, TestSize.Level3)
64 {
65     OsAccountSubscribeInfo osAccountSubscribeInfo(ACTIVATED, STRING_NAME);
66 
67     Parcel parcel;
68     EXPECT_EQ(true, osAccountSubscribeInfo.Marshalling(parcel));
69 
70     std::shared_ptr<OsAccountSubscribeInfo> readedData(OsAccountSubscribeInfo::Unmarshalling(parcel));
71     EXPECT_NE(nullptr, readedData);
72 
73     EXPECT_EQ(osAccountSubscribeInfo.osAccountSubscribeType_, readedData->osAccountSubscribeType_);
74     EXPECT_EQ(osAccountSubscribeInfo.name_, readedData->name_);
75 }
76