1e0857b17Sopenharmony_ci/* 2e0857b17Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 3e0857b17Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4e0857b17Sopenharmony_ci * you may not use this file except in compliance with the License. 5e0857b17Sopenharmony_ci * You may obtain a copy of the License at 6e0857b17Sopenharmony_ci * 7e0857b17Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8e0857b17Sopenharmony_ci * 9e0857b17Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10e0857b17Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11e0857b17Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12e0857b17Sopenharmony_ci * See the License for the specific language governing permissions and 13e0857b17Sopenharmony_ci * limitations under the License. 14e0857b17Sopenharmony_ci */ 15e0857b17Sopenharmony_ci 16e0857b17Sopenharmony_ci#include <fstream> 17e0857b17Sopenharmony_ci#include <gtest/gtest.h> 18e0857b17Sopenharmony_ci#include <iostream> 19e0857b17Sopenharmony_ci#include "view_data.h" 20e0857b17Sopenharmony_ci#include "session_info.h" 21e0857b17Sopenharmony_ci 22e0857b17Sopenharmony_ciusing namespace testing; 23e0857b17Sopenharmony_ciusing namespace testing::ext; 24e0857b17Sopenharmony_ci 25e0857b17Sopenharmony_cinamespace OHOS { 26e0857b17Sopenharmony_cinamespace AbilityBase { 27e0857b17Sopenharmony_cinamespace { 28e0857b17Sopenharmony_ci static const std::string TJSON = 29e0857b17Sopenharmony_ci "{\"abilityName\":\"\",\"bundleName\":\"\",\"isOtherAccount\":false,\"isUserSelected\":false," 30e0857b17Sopenharmony_ci "\"moduleName\":\"\",\"nodes\":[],\"pageRect\":\"{\\\"height\\\":0.0,\\\"left\\\":0.0,\\\"top\\\":0.0," 31e0857b17Sopenharmony_ci "\\\"width\\\":0.0}\",\"pageUrl\":\"\"}"; 32e0857b17Sopenharmony_ci} // namespace 33e0857b17Sopenharmony_ciclass ViewDataTest : public testing::Test { 34e0857b17Sopenharmony_cipublic: 35e0857b17Sopenharmony_ci static void SetUpTestCase(); 36e0857b17Sopenharmony_ci static void TearDownTestCase(); 37e0857b17Sopenharmony_ci void SetUp(); 38e0857b17Sopenharmony_ci void TearDown(); 39e0857b17Sopenharmony_ci}; 40e0857b17Sopenharmony_ci 41e0857b17Sopenharmony_civoid ViewDataTest::SetUpTestCase() 42e0857b17Sopenharmony_ci{} 43e0857b17Sopenharmony_ci 44e0857b17Sopenharmony_civoid ViewDataTest::TearDownTestCase() 45e0857b17Sopenharmony_ci{} 46e0857b17Sopenharmony_ci 47e0857b17Sopenharmony_civoid ViewDataTest::SetUp() 48e0857b17Sopenharmony_ci{} 49e0857b17Sopenharmony_ci 50e0857b17Sopenharmony_civoid ViewDataTest::TearDown() 51e0857b17Sopenharmony_ci{} 52e0857b17Sopenharmony_ci 53e0857b17Sopenharmony_ci/** 54e0857b17Sopenharmony_ci * @tc.name: FromJsonString_100 55e0857b17Sopenharmony_ci * @tc.desc: ViewData test for FromJsonString. 56e0857b17Sopenharmony_ci * @tc.type: FUNC 57e0857b17Sopenharmony_ci */ 58e0857b17Sopenharmony_ciHWTEST_F(ViewDataTest, FromJsonString_100, TestSize.Level1) 59e0857b17Sopenharmony_ci{ 60e0857b17Sopenharmony_ci std::string jsonStr = "jsonStr"; 61e0857b17Sopenharmony_ci std::shared_ptr<ViewData> viewdata = std::make_shared<ViewData>(); 62e0857b17Sopenharmony_ci EXPECT_TRUE(viewdata != nullptr); 63e0857b17Sopenharmony_ci viewdata->FromJsonString(jsonStr); 64e0857b17Sopenharmony_ci viewdata->FromJsonString(TJSON); 65e0857b17Sopenharmony_ci std::string ret = viewdata->ToJsonString(); 66e0857b17Sopenharmony_ci EXPECT_EQ(ret, TJSON); 67e0857b17Sopenharmony_ci} 68e0857b17Sopenharmony_ci 69e0857b17Sopenharmony_ci/** 70e0857b17Sopenharmony_ci * @tc.name: Unmarshalling_100 71e0857b17Sopenharmony_ci * @tc.desc: SessionInfo test for Unmarshalling. 72e0857b17Sopenharmony_ci * @tc.type: FUNC 73e0857b17Sopenharmony_ci */ 74e0857b17Sopenharmony_ciHWTEST_F(ViewDataTest, Unmarshalling_100, TestSize.Level1) 75e0857b17Sopenharmony_ci{ 76e0857b17Sopenharmony_ci std::shared_ptr<AAFwk::SessionInfo> sessioninfo = std::make_shared<AAFwk::SessionInfo>(); 77e0857b17Sopenharmony_ci EXPECT_TRUE(sessioninfo != nullptr); 78e0857b17Sopenharmony_ci Parcel parcel; 79e0857b17Sopenharmony_ci auto ret = sessioninfo->Unmarshalling(parcel); 80e0857b17Sopenharmony_ci EXPECT_NE(ret, nullptr); 81e0857b17Sopenharmony_ci} 82e0857b17Sopenharmony_ci} // namespace AbilityBase 83e0857b17Sopenharmony_ci} // namespace OHOS 84