/* * Copyright (c) 2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include #include #include #include #include "mock/mock_session_stage.h" #include "mock/mock_window_event_channel.h" #include "mock/mock_pattern_detach_callback.h" #include "session/host/include/extension_session.h" #include "session/host/include/move_drag_controller.h" #include "session/host/include/scene_session.h" #include "session_manager/include/scene_session_manager.h" #include "session/host/include/session.h" #include "session_info.h" #include "key_event.h" #include "wm_common.h" #include "window_manager_hilog.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { namespace { const std::string UNDEFINED = "undefined"; } class SessionLayoutTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; int32_t GetTaskCount(); sptr ssm_; private: RSSurfaceNode::SharedPtr CreateRSSurfaceNode(); sptr session_ = nullptr; static constexpr uint32_t WAIT_SYNC_IN_NS = 500000; sptr mockSessionStage_ = nullptr; sptr mockEventChannel_ = nullptr; }; void SessionLayoutTest::SetUpTestCase() { } void SessionLayoutTest::TearDownTestCase() { } void SessionLayoutTest::SetUp() { SessionInfo info; info.abilityName_ = "testSession1"; info.moduleName_ = "testSession2"; info.bundleName_ = "testSession3"; session_ = sptr::MakeSptr(info); session_->surfaceNode_ = CreateRSSurfaceNode(); ssm_ = sptr::MakeSptr(); session_->SetEventHandler(ssm_->taskScheduler_->GetEventHandler(), ssm_->eventHandler_); auto isScreenLockedCallback = [this]() { return ssm_->IsScreenLocked(); }; session_->RegisterIsScreenLockedCallback(isScreenLockedCallback); mockSessionStage_ = sptr::MakeSptr(); mockEventChannel_ = sptr::MakeSptr(mockSessionStage_); } void SessionLayoutTest::TearDown() { session_ = nullptr; usleep(WAIT_SYNC_IN_NS); } RSSurfaceNode::SharedPtr SessionLayoutTest::CreateRSSurfaceNode() { struct RSSurfaceNodeConfig rsSurfaceNodeConfig; rsSurfaceNodeConfig.SurfaceNodeName = "WindowSessionTestSurfaceNode"; auto surfaceNode = RSSurfaceNode::Create(rsSurfaceNodeConfig); if (surfaceNode == nullptr) { GTEST_LOG_(INFO) << "SessionLayoutTest::CreateRSSurfaceNode surfaceNode is nullptr"; } return surfaceNode; } int32_t SessionLayoutTest::GetTaskCount() { std::string dumpInfo = session_->handler_->GetEventRunner()->GetEventQueue()->DumpCurrentQueueSize(); std::regex pattern("\\d+"); std::smatch matches; int32_t taskNum = 0; while (std::regex_search(dumpInfo, matches, pattern)) { taskNum += std::stoi(matches.str()); dumpInfo = matches.suffix(); } return taskNum; } namespace { /** * @tc.name: SetSingleHandTransform * @tc.desc: SetSingleHandTransform * @tc.type: FUNC */ HWTEST_F(SessionLayoutTest, SetSingleHandTransform, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "SetSingleHandTransform"; info.bundleName_ = "SetSingleHandTransform"; sptr session = sptr::MakeSptr(info); SingleHandTransform transform; session->SetSingleHandTransform(transform); ASSERT_EQ(transform, session->GetSingleHandTransform()); } } } // namespace Rosen } // namespace OHOS