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
16 #include <fstream>
17 #include <gtest/gtest.h>
18 #include <iostream>
19 #include "view_data.h"
20 #include "session_info.h"
21
22 using namespace testing;
23 using namespace testing::ext;
24
25 namespace OHOS {
26 namespace AbilityBase {
27 namespace {
28 static const std::string TJSON =
29 "{\"abilityName\":\"\",\"bundleName\":\"\",\"isOtherAccount\":false,\"isUserSelected\":false,"
30 "\"moduleName\":\"\",\"nodes\":[],\"pageRect\":\"{\\\"height\\\":0.0,\\\"left\\\":0.0,\\\"top\\\":0.0,"
31 "\\\"width\\\":0.0}\",\"pageUrl\":\"\"}";
32 } // namespace
33 class ViewDataTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36 static void TearDownTestCase();
37 void SetUp();
38 void TearDown();
39 };
40
SetUpTestCase()41 void ViewDataTest::SetUpTestCase()
42 {}
43
TearDownTestCase()44 void ViewDataTest::TearDownTestCase()
45 {}
46
SetUp()47 void ViewDataTest::SetUp()
48 {}
49
TearDown()50 void ViewDataTest::TearDown()
51 {}
52
53 /**
54 * @tc.name: FromJsonString_100
55 * @tc.desc: ViewData test for FromJsonString.
56 * @tc.type: FUNC
57 */
58 HWTEST_F(ViewDataTest, FromJsonString_100, TestSize.Level1)
59 {
60 std::string jsonStr = "jsonStr";
61 std::shared_ptr<ViewData> viewdata = std::make_shared<ViewData>();
62 EXPECT_TRUE(viewdata != nullptr);
63 viewdata->FromJsonString(jsonStr);
64 std::string ret = viewdata->ToJsonString();
65 EXPECT_EQ(ret, TJSON);
66 }
67
68 /**
69 * @tc.name: Unmarshalling_100
70 * @tc.desc: SessionInfo test for Unmarshalling.
71 * @tc.type: FUNC
72 */
73 HWTEST_F(ViewDataTest, Unmarshalling_100, TestSize.Level1)
74 {
75 std::shared_ptr<AAFwk::SessionInfo> sessioninfo = std::make_shared<AAFwk::SessionInfo>();
76 EXPECT_TRUE(sessioninfo != nullptr);
77 Parcel parcel;
78 auto ret = sessioninfo->Unmarshalling(parcel);
79 EXPECT_NE(ret, nullptr);
80 }
81 } // namespace AbilityBase
82 } // namespace OHOS
83