/* * Copyright (c) 2023 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 "session/host/include/scene_session.h" using namespace testing; using namespace testing::ext; namespace OHOS { namespace Rosen { class SceneSessionTest : public testing::Test { public: static void SetUpTestCase(); static void TearDownTestCase(); void SetUp() override; void TearDown() override; }; void SceneSessionTest::SetUpTestCase() { } void SceneSessionTest::TearDownTestCase() { } void SceneSessionTest::SetUp() { } void SceneSessionTest::TearDown() { } namespace { /** * @tc.name: ForegroundAndBackground01 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest, Foreground01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Foreground01"; info.bundleName_ = "Foreground01"; sptr session_; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); int resultValue = 0; sptr scensession; scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); scensession->isActive_ = true; sptr property = new(std::nothrow) WindowSessionProperty(); ASSERT_NE(nullptr, property); auto result = scensession->Foreground(property); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); specificCallback_->onCreate_ = [&resultValue, specificCallback_](const SessionInfo &info, sptr property) -> sptr { sptr scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback_); EXPECT_NE(scensessionreturn, nullptr); resultValue = 1; return scensessionreturn; }; scensession = new (std::nothrow) SceneSession(info, specificCallback_); EXPECT_NE(scensession, nullptr); scensession->UpdateSessionState(SessionState::STATE_INACTIVE); scensession->isActive_ = true; result = scensession->Foreground(property); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); } /** * @tc.name: Background01 * @tc.desc: normal function * @tc.type: FUNC */ HWTEST_F(SceneSessionTest, Background01, Function | SmallTest | Level2) { SessionInfo info; info.abilityName_ = "Background01"; info.bundleName_ = "Background01"; sptr session_; sptr specificCallback_ = new (std::nothrow) SceneSession::SpecificSessionCallback(); EXPECT_NE(specificCallback_, nullptr); int resultValue = 0; sptr scensession; scensession = new (std::nothrow) SceneSession(info, nullptr); EXPECT_NE(scensession, nullptr); scensession->isActive_ = true; auto result = scensession->Background(); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); specificCallback_->onCreate_ = [&resultValue, specificCallback_](const SessionInfo &info, sptr property) -> sptr { sptr scensessionreturn = new (std::nothrow) SceneSession(info, specificCallback_); EXPECT_NE(scensessionreturn, nullptr); resultValue = 1; return scensessionreturn; }; scensession = new (std::nothrow) SceneSession(info, specificCallback_); EXPECT_NE(scensession, nullptr); scensession->UpdateSessionState(SessionState::STATE_CONNECT); scensession->isActive_ = true; result = scensession->Background(); ASSERT_EQ(result, WSError::WS_ERROR_INVALID_SESSION); } } } }