From a23190085e57b0bfdebf6e5c6701b7e6cc9decd6 Mon Sep 17 00:00:00 2001 From: redking-zhong Date: Wed, 1 Nov 2023 09:21:36 +0800 Subject: [PATCH 1/3] tdd Signed-off-by: redking-zhong --- .../test/unittest/screen_session_test.cpp | 201 +++++++++++++++++- 1 file changed, 200 insertions(+), 1 deletion(-) diff --git a/window_scene/test/unittest/screen_session_test.cpp b/window_scene/test/unittest/screen_session_test.cpp index 0a49c70974..95f7d6e1e9 100644 --- a/window_scene/test/unittest/screen_session_test.cpp +++ b/window_scene/test/unittest/screen_session_test.cpp @@ -283,7 +283,7 @@ HWTEST_F(ScreenSessionTest, GetChildPosition, Function | SmallTest | Level2) ScreenId screenId = 1; Point res = sessionGroup.GetChildPosition(screenId); ASSERT_EQ(res.posX_, 0); - GTEST_LOG_(INFO) << "ScreenSessionTest: GetRSDisplayNodeConfig end"; + GTEST_LOG_(INFO) << "ScreenSessionTest: GetChildPosition end"; } /** @@ -299,6 +299,205 @@ HWTEST_F(ScreenSessionTest, ConvertToScreenGroupInfo, Function | SmallTest | Lev ASSERT_NE(res, nullptr); GTEST_LOG_(INFO) << "ScreenSessionTest: ConvertToScreenGroupInfo end"; } + +/** + * @tc.name: RegisterScreenChangeListener + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, RegisterScreenChangeListener, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: RegisterScreenChangeListener start"; + int res = 0; + IScreenChangeListener* screenChangeListener = nullptr; + sptr session = new(std::nothrow) ScreenSession(); + session->RegisterScreenChangeListener(screenChangeListener); + ASSERT_EQ(res, 0); + GTEST_LOG_(INFO) << "ScreenSessionTest: RegisterScreenChangeListener end"; +} + +/** + * @tc.name: UpdatePropertyByActiveMode + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, UpdatePropertyByActiveMode, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: UpdatePropertyByActiveMode start"; + int res = 0; + sptr session = new(std::nothrow) ScreenSession(); + session->UpdatePropertyByActiveMode(); + ASSERT_EQ(res, 0); + GTEST_LOG_(INFO) << "ScreenSessionTest: UpdatePropertyByActiveMode end"; +} + +/** + * @tc.name: Disconnect + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, Disconnect, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: Disconnect start"; + int res = 0; + sptr session = new(std::nothrow) ScreenSession(); + session->Disconnect(); + ASSERT_EQ(res, 0); + GTEST_LOG_(INFO) << "ScreenSessionTest: Disconnect end"; +} + +/** + * @tc.name: SensorRotationChange + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, SensorRotationChange, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: SensorRotationChange start"; + int res = 0; + Rotation sensorRotation = Rotation::ROTATION_0; + sptr session = new(std::nothrow) ScreenSession(); + session->SensorRotationChange(sensorRotation); + ASSERT_EQ(res, 0); + GTEST_LOG_(INFO) << "ScreenSessionTest: SensorRotationChange end"; +} + +/** + * @tc.name: SetOrientation + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, SetOrientation, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: SetOrientation start"; + sptr session = new(std::nothrow) ScreenSession(); + Orientation orientation = Orientation::UNSPECIFIED; + session->SetOrientation(orientation); + Orientation res = session->GetOrientation(); + ASSERT_EQ(res, orientation); + GTEST_LOG_(INFO) << "ScreenSessionTest: SetOrientation end"; +} + +/** + * @tc.name: SetScreenRequestedOrientation + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, SetScreenRequestedOrientation, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRequestedOrientation start"; + sptr session = new(std::nothrow) ScreenSession(); + Orientation orientation = session->GetOrientation(); + Orientation res = orientation; + session->SetScreenRequestedOrientation(res); + session->property_.SetScreenRequestedOrientation(orientation); + ASSERT_EQ(res, orientation); + GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRequestedOrientation end"; +} + +/** + * @tc.name: SetScreenRotationLocked + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, SetScreenRotationLocked, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLocked start"; + bool isLocked = true; + int res = 0; + sptr session = new(std::nothrow) ScreenSession(); + session->SetScreenRotationLocked(isLocked); + ASSERT_EQ(res, 0); + GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLocked end"; +} + +/** + * @tc.name: SetScreenRotationLockedFromJs + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, SetScreenRotationLockedFromJs, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLockedFromJs start"; + bool isLocked = true; + int res = 0; + sptr session = new(std::nothrow) ScreenSession(); + session->SetScreenRotationLockedFromJs(isLocked); + ASSERT_EQ(res, 0); + GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLockedFromJs end"; +} + +/** + * @tc.name: IsScreenRotationLocked + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, IsScreenRotationLocked, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: IsScreenRotationLocked start"; + sptr session = new(std::nothrow) ScreenSession(); + bool res = session->IsScreenRotationLocked(); + ASSERT_EQ(res, session->isScreenLocked_); + GTEST_LOG_(INFO) << "ScreenSessionTest: IsScreenRotationLocked end"; +} + +/** + * @tc.name: GetScreenRequestedOrientation + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, GetScreenRequestedOrientation, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenRequestedOrientation start"; + sptr session = new(std::nothrow) ScreenSession(); + Orientation res = session->GetScreenRequestedOrientation(); + ASSERT_EQ(res, session->property_.GetScreenRequestedOrientation()); + GTEST_LOG_(INFO) << "ScreenSessionTest: GetScreenRequestedOrientation end"; +} + +/** + * @tc.name: SetVirtualPixelRatio + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, SetVirtualPixelRatio, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: SetVirtualPixelRatio start"; + sptr session = new(std::nothrow) ScreenSession(); + float virtualPixelRatio = 1; + float res = virtualPixelRatio; + session->SetVirtualPixelRatio(virtualPixelRatio); + session->property_.SetVirtualPixelRatio(res); + ASSERT_EQ(res, virtualPixelRatio); + GTEST_LOG_(INFO) << "ScreenSessionTest: SetVirtualPixelRatio end"; +} + +/** + * @tc.name: CalcRotation + * @tc.desc: normal function + * @tc.type: FUNC + */ +HWTEST_F(ScreenSessionTest, CalcRotation, Function | SmallTest | Level2) +{ + GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation start"; + sptr session = new(std::nothrow) ScreenSession(); + Orientation orientation = Orientation::UNSPECIFIED; + Rotation res = session->CalcRotation(orientation); + ASSERT_EQ(res, Rotation::ROTATION_0); + orientation = Orientation::VERTICAL; + res = session->CalcRotation(orientation); + ASSERT_EQ(res, Rotation::ROTATION_0); + orientation = Orientation::HORIZONTAL; + res = session->CalcRotation(orientation); + ASSERT_EQ(res, Rotation::ROTATION_0); + orientation = Orientation::REVERSE_VERTICAL; + res = session->CalcRotation(orientation); + ASSERT_EQ(res, Rotation::ROTATION_0); + orientation = Orientation::REVERSE_HORIZONTAL; + res = session->CalcRotation(orientation); + ASSERT_EQ(res, Rotation::ROTATION_0); + GTEST_LOG_(INFO) << "ScreenSessionTest: CalcRotation end"; +} } // namespace } // namespace Rosen } // namespace OHOS -- Gitee From 018973a7a0b6fdc1244ef8292b166aa59186d2e6 Mon Sep 17 00:00:00 2001 From: redking-zhong Date: Wed, 1 Nov 2023 15:40:48 +0800 Subject: [PATCH 2/3] updata tdd Signed-off-by: redking-zhong --- .../test/unittest/screen_session_test.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/window_scene/test/unittest/screen_session_test.cpp b/window_scene/test/unittest/screen_session_test.cpp index 95f7d6e1e9..8865dc682c 100644 --- a/window_scene/test/unittest/screen_session_test.cpp +++ b/window_scene/test/unittest/screen_session_test.cpp @@ -387,10 +387,9 @@ HWTEST_F(ScreenSessionTest, SetScreenRequestedOrientation, Function | SmallTest { GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRequestedOrientation start"; sptr session = new(std::nothrow) ScreenSession(); - Orientation orientation = session->GetOrientation(); - Orientation res = orientation; - session->SetScreenRequestedOrientation(res); - session->property_.SetScreenRequestedOrientation(orientation); + Orientation orientation = Orientation::UNSPECIFIED; + session->SetScreenRequestedOrientation(orientation); + Orientation res =session->GetScreenRequestedOrientation(); ASSERT_EQ(res, orientation); GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRequestedOrientation end"; } @@ -404,10 +403,10 @@ HWTEST_F(ScreenSessionTest, SetScreenRotationLocked, Function | SmallTest | Leve { GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLocked start"; bool isLocked = true; - int res = 0; sptr session = new(std::nothrow) ScreenSession(); session->SetScreenRotationLocked(isLocked); - ASSERT_EQ(res, 0); + bool res = session->IsScreenRotationLocked(); + ASSERT_EQ(res, isLocked); GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLocked end"; } @@ -420,10 +419,10 @@ HWTEST_F(ScreenSessionTest, SetScreenRotationLockedFromJs, Function | SmallTest { GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLockedFromJs start"; bool isLocked = true; - int res = 0; sptr session = new(std::nothrow) ScreenSession(); session->SetScreenRotationLockedFromJs(isLocked); - ASSERT_EQ(res, 0); + bool res = session->IsScreenRotationLocked(); + ASSERT_EQ(res, isLocked); GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRotationLockedFromJs end"; } @@ -465,9 +464,8 @@ HWTEST_F(ScreenSessionTest, SetVirtualPixelRatio, Function | SmallTest | Level2) GTEST_LOG_(INFO) << "ScreenSessionTest: SetVirtualPixelRatio start"; sptr session = new(std::nothrow) ScreenSession(); float virtualPixelRatio = 1; - float res = virtualPixelRatio; session->SetVirtualPixelRatio(virtualPixelRatio); - session->property_.SetVirtualPixelRatio(res); + float res = session->property_.GetVirtualPixelRatio(); ASSERT_EQ(res, virtualPixelRatio); GTEST_LOG_(INFO) << "ScreenSessionTest: SetVirtualPixelRatio end"; } -- Gitee From db84ef5e1074b766700437b268841a74e68b551c Mon Sep 17 00:00:00 2001 From: redking-zhong Date: Thu, 2 Nov 2023 10:25:58 +0800 Subject: [PATCH 3/3] updata Signed-off-by: redking-zhong --- window_scene/test/unittest/screen_session_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/window_scene/test/unittest/screen_session_test.cpp b/window_scene/test/unittest/screen_session_test.cpp index 8865dc682c..3f6575626c 100644 --- a/window_scene/test/unittest/screen_session_test.cpp +++ b/window_scene/test/unittest/screen_session_test.cpp @@ -389,7 +389,7 @@ HWTEST_F(ScreenSessionTest, SetScreenRequestedOrientation, Function | SmallTest sptr session = new(std::nothrow) ScreenSession(); Orientation orientation = Orientation::UNSPECIFIED; session->SetScreenRequestedOrientation(orientation); - Orientation res =session->GetScreenRequestedOrientation(); + Orientation res = session->GetScreenRequestedOrientation(); ASSERT_EQ(res, orientation); GTEST_LOG_(INFO) << "ScreenSessionTest: SetScreenRequestedOrientation end"; } -- Gitee