• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_callback_stub.h"
25 #include "devicestatus_define.h"
26 #include "devicestatus_delayed_sp_singleton.h"
27 #include "drag_manager.h"
28 #include "i_context.h"
29 #include "timer_manager.h"
30 
31 #include "intention_dumper.h"
32 #include "intention_service.h"
33 #include "stationary_server.h"
34 #include "socket_session_manager.h"
35 
36 namespace OHOS {
37 namespace Msdp {
38 namespace DeviceStatus {
39 class MockDelegateTasks : public IDelegateTasks {
40 public:
41     int32_t PostSyncTask(DTaskCallback callback) override;
42     int32_t PostAsyncTask(DTaskCallback callback) override;
43 };
44 
45 class ContextService final : public IContext {
46 public:
47     ContextService();
48     ~ContextService() = default;
49     DISALLOW_COPY_AND_MOVE(ContextService);
50 
51     IDelegateTasks& GetDelegateTasks() override;
52     IDeviceManager& GetDeviceManager() override;
53     ITimerManager& GetTimerManager() override;
54     IDragManager& GetDragManager() override;
55     IDDMAdapter& GetDDM() override;
56     IPluginManager& GetPluginManager() override;
57     ISocketSessionManager& GetSocketSessionManager() override;
58     IInputAdapter& GetInput() override;
59     IDSoftbusAdapter& GetDSoftbus() override;
60     static ContextService* GetInstance();
61 private:
62     MockDelegateTasks delegateTasks_;
63     DeviceManager devMgr_;
64     TimerManager timerMgr_;
65     DragManager dragMgr_;
66     SocketSessionManager socketSessionMgr_;
67     std::unique_ptr<IDDMAdapter> ddm_ { nullptr };
68     std::unique_ptr<IInputAdapter> input_ { nullptr };
69     std::unique_ptr<IPluginManager> pluginMgr_ { nullptr };
70     std::unique_ptr<IDSoftbusAdapter> dsoftbus_ { nullptr };
71     sptr<IntentionService> intention_ { nullptr };
72 };
73 
74 class TestDevStaCallback : public DeviceStatusCallbackStub {
75 public:
76     TestDevStaCallback() = default;
77     virtual ~TestDevStaCallback() = default;
OnDeviceStatusChanged(const Data & devicestatusData)78     void OnDeviceStatusChanged(const Data &devicestatusData) {}
79 };
80 
81 class IntentionServiceTest : public testing::Test {
82 public:
83     static void SetUpTestCase();
84     static void TearDownTestCase();
85     void SetUp();
86     void TearDown();
87     static std::shared_ptr<Media::PixelMap> CreatePixelMap(int32_t width, int32_t height);
88     static std::optional<DragData> CreateDragData(int32_t sourceType, int32_t pointerId, int32_t dragNum,
89         bool hasCoordinateCorrected, int32_t shadowNum);
90     void AssignToAnimation(PreviewAnimation &animation);
91 };
92 } // namespace DeviceStatus
93 } // namespace Msdp
94 } // namespace OHOS
95 #endif // INTENTION_SERVICE_TEST_H