1 /* 2 * Copyright (c) 2025 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 #include "dm_virtual_screen_option.h" 18 19 using namespace testing::ext; 20 21 namespace OHOS::Rosen { 22 /** 23 * @tc.name: MarshallingUnmarshalling_DefaultValues 24 * @tc.desc: Marshalling and unmarshalling test with default values 25 * @tc.type: FUNC 26 */ 27 HWTEST(DmVirtualScreenOptionTest, MarshallingUnmarshalling_DefaultValues, TestSize.Level1) 28 { 29 DmVirtualScreenOption dmVirtualScreenOption; 30 Parcel parcel; 31 bool ret = dmVirtualScreenOption.Marshalling(parcel); 32 ASSERT_TRUE(ret); 33 34 sptr<DmVirtualScreenOption> option = DmVirtualScreenOption::Unmarshalling(parcel); 35 ASSERT_NE(option, nullptr); 36 EXPECT_EQ(option->GetOption().name_, ""); 37 EXPECT_EQ(option->GetOption().width_, 0); 38 EXPECT_EQ(option->GetOption().height_, 0); 39 } 40 41 /** 42 * @tc.name: MarshallingUnmarshalling_CustomValues 43 * @tc.desc: Marshalling and unmarshalling test with custom values 44 * @tc.type: FUNC 45 */ 46 HWTEST(DmVirtualScreenOptionTest, MarshallingUnmarshalling_CustomValues, TestSize.Level1) 47 { 48 VirtualScreenOption virtualOption{}; 49 virtualOption.name_ = "testVirtualOption"; 50 virtualOption.width_ = 100; 51 virtualOption.height_ = 200; 52 DmVirtualScreenOption dmVirtualScreenOption(virtualOption); 53 54 Parcel parcel; 55 bool ret = dmVirtualScreenOption.Marshalling(parcel); 56 ASSERT_TRUE(ret); 57 58 sptr<DmVirtualScreenOption> option = DmVirtualScreenOption::Unmarshalling(parcel); 59 ASSERT_NE(option, nullptr); 60 EXPECT_EQ(option->GetOption().name_, virtualOption.name_); 61 EXPECT_EQ(option->GetOption().width_, virtualOption.width_); 62 EXPECT_EQ(option->GetOption().height_, virtualOption.height_); 63 } 64 } // namespace OHOS::Rosen 65