1/*
2 * Copyright (c) 2021 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 ECMASCRIPT_TOOLING_TEST_UTILS_TEST_EVENTS_H
17#define ECMASCRIPT_TOOLING_TEST_UTILS_TEST_EVENTS_H
18
19#include <utility>
20
21#include "agent/runtime_impl.h"
22#include "backend/js_pt_hooks.h"
23#include "test/utils/test_channel.h"
24
25namespace panda::ecmascript::tooling::test {
26using DebuggerStmtCallback = std::function<bool(const JSPtLocation &)>;
27using BreakpointCallback = std::function<bool(const JSPtLocation &)>;
28using LoadModuleCallback = std::function<bool(std::string_view)>;
29using ExceptionCallback = std::function<bool(const JSPtLocation &)>;
30using SingleStepCallback = std::function<bool(const JSPtLocation &)>;
31using NativeOutCallback = std::function<bool()>;
32using VmStartCallback = std::function<bool()>;
33using VmDeathCallback = std::function<bool()>;
34using Scenario = std::function<bool()>;
35
36enum class DebugEvent {
37    BREAKPOINT,
38    LOAD_MODULE,
39    PAUSED,
40    STEP_COMPLETE,
41    EXCEPTION,
42    METHOD_ENTRY,
43    SINGLE_STEP,
44    VM_START,
45    VM_INITIALIZATION,
46    VM_DEATH,
47    UNINITIALIZED,
48    DROPFRAME,
49    CHECK_COMPLETE
50};
51
52std::ostream &operator<<(std::ostream &out, DebugEvent value);
53
54struct TestEvents {
55    DebuggerStmtCallback debuggerStmt;
56    BreakpointCallback breakpoint;
57    LoadModuleCallback loadModule;
58    ExceptionCallback exception;
59    SingleStepCallback singleStep;
60    NativeOutCallback nativeOut;
61    VmStartCallback vmStart;
62    VmDeathCallback vmDeath;
63
64    Scenario scenario;
65    const EcmaVM *vm_ {nullptr};
66    JSDebugger *debugInterface_ {nullptr};
67    DebuggerImpl *debugger_ {nullptr};
68    RuntimeImpl *runtime_ {nullptr};
69    TestChannel *channel_ {nullptr};
70    TestEvents();
71    virtual ~TestEvents() = default;
72
73    virtual std::pair<std::string, std::string> GetEntryPoint() = 0;
74};
75}  // namespace panda::ecmascript::tooling::test
76
77#endif  // ECMASCRIPT_TOOLING_TEST_UTILS_TEST_EVENTS_H
78