1 /*
2  * Copyright (c) 2024 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 #ifndef INTENTION_SERVICE_TEST_H
17 #define INTENTION_SERVICE_TEST_H
18 
19 #include <gtest/gtest.h>
20 #include "nocopyable.h"
21 
22 #include "delegate_tasks.h"
23 #include "device_manager.h"
24 #include "devicestatus_define.h"
25 #include "devicestatus_delayed_sp_singleton.h"
26 #include "drag_manager.h"
27 #include "i_context.h"
28 #include "timer_manager.h"
29 
30 #include "intention_service.h"
31 #include "socket_session_manager.h"
32 
33 namespace OHOS {
34 namespace Msdp {
35 namespace DeviceStatus {
36 class MockDelegateTasks : public IDelegateTasks {
37 public:
38     int32_t PostSyncTask(DTaskCallback callback) override;
39     int32_t PostAsyncTask(DTaskCallback callback) override;
40 };
41 
42 class ContextService final : public IContext {
43 public:
44     ContextService();
45     ~ContextService() = default;
46     DISALLOW_COPY_AND_MOVE(ContextService);
47 
48     IDelegateTasks& GetDelegateTasks() override;
49     IDeviceManager& GetDeviceManager() override;
50     ITimerManager& GetTimerManager() override;
51     IDragManager& GetDragManager() override;
52     IDDMAdapter& GetDDM() override;
53     IPluginManager& GetPluginManager() override;
54     ISocketSessionManager& GetSocketSessionManager() override;
55     IInputAdapter& GetInput() override;
56     IDSoftbusAdapter& GetDSoftbus() override;
57     static ContextService* GetInstance();
58 private:
59     MockDelegateTasks delegateTasks_;
60     DeviceManager devMgr_;
61     TimerManager timerMgr_;
62     DragManager dragMgr_;
63     SocketSessionManager socketSessionMgr_;
64     std::unique_ptr<IDDMAdapter> ddm_ { nullptr };
65     std::unique_ptr<IInputAdapter> input_ { nullptr };
66     std::unique_ptr<IPluginManager> pluginMgr_ { nullptr };
67     std::unique_ptr<IDSoftbusAdapter> dsoftbus_ { nullptr };
68     sptr<IntentionService> intention_ { nullptr };
69 };
70 
71 class IntentionServiceTest : public testing::Test {
72 public:
73     static void SetUpTestCase();
74     static void TearDownTestCase();
75     void SetUp();
76     void TearDown();
77     static std::shared_ptr<Media::PixelMap> CreatePixelMap(int32_t width, int32_t height);
78     static std::optional<DragData> CreateDragData(int32_t sourceType, int32_t pointerId, int32_t dragNum,
79         bool hasCoordinateCorrected, int32_t shadowNum);
80     void AssignToAnimation(PreviewAnimation &animation);
81 };
82 } // namespace DeviceStatus
83 } // namespace Msdp
84 } // namespace OHOS
85 #endif // INTENTION_SERVICE_TEST_H