* Copyright (c) 2026 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.
*/
#define private public
#define protected public
#include "notify_service_impl.h"
#undef private
#include <gtest/gtest.h>
#include "global.h"
#include "ipc_skeleton.h"
#include "os_account_adapter.h"
#include "peruser_session.h"
#include "user_session_manager.h"
using namespace testing::ext;
namespace OHOS {
namespace MiscServices {
class NotifyServiceImplTest : public testing::Test {
public:
static void SetUpTestCase(void) { }
static void TearDownTestCase(void) { }
void SetUp() { }
void TearDown() { }
};
HWTEST_F(NotifyServiceImplTest, NotifyOnInputStopFinished_PidMismatch, TestSize.Level0)
{
IMSA_HILOGI("NotifyOnInputStopFinished_PidMismatch begin");
OnInputStopNotifyServiceImpl service(-1);
auto ret = service.NotifyOnInputStopFinished();
EXPECT_EQ(ret, ErrorCode::ERROR_STATUS_PERMISSION_DENIED);
}
HWTEST_F(NotifyServiceImplTest, NotifyOnInputStopFinished_InvalidUserId, TestSize.Level0)
{
IMSA_HILOGI("NotifyOnInputStopFinished_InvalidUserId begin");
pid_t currentPid = getpid();
OnInputStopNotifyServiceImpl service(currentPid);
auto ret = service.NotifyOnInputStopFinished();
EXPECT_TRUE(ret == ErrorCode::ERROR_EX_ILLEGAL_STATE || ret == ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND);
}
HWTEST_F(NotifyServiceImplTest, NotifyOnInputStopFinished_SessionNotFound, TestSize.Level0)
{
IMSA_HILOGI("NotifyOnInputStopFinished_SessionNotFound begin");
pid_t currentPid = getpid();
OnInputStopNotifyServiceImpl service(currentPid);
auto ret = service.NotifyOnInputStopFinished();
EXPECT_TRUE(ret == ErrorCode::ERROR_EX_ILLEGAL_STATE || ret == ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND);
}
HWTEST_F(NotifyServiceImplTest, NotifyOnInputStopFinished_Normal, TestSize.Level0)
{
IMSA_HILOGI("NotifyOnInputStopFinished_Normal begin");
pid_t currentPid = getpid();
OnInputStopNotifyServiceImpl service(currentPid);
auto ret = service.NotifyOnInputStopFinished();
EXPECT_TRUE(ret == ErrorCode::ERROR_IMSA_USER_SESSION_NOT_FOUND || ret == ERR_OK);
}
}
}