File indexing completed on 2024-09-01 03:47:41
0001 /* 0002 This file is part of the KDE project 0003 0004 SPDX-FileCopyrightText: 2001, 2003 Peter Kelly <pmk@post.com> 0005 SPDX-FileCopyrightText: 2006, 2007 Leo Savernik <l.savernik@aon.at> 0006 0007 SPDX-License-Identifier: LGPL-2.0-or-later 0008 */ 0009 0010 #ifndef TESTUTILS_H 0011 #define TESTUTILS_H 0012 0013 #include "katescriptview.h" 0014 0015 #include "katescriptdocument.h" 0016 #include <QJSEngine> 0017 0018 namespace KTextEditor 0019 { 0020 class ViewPrivate; 0021 } 0022 class RegressionTest; 0023 class KCmdLineArgs; 0024 class OutputObject; 0025 class KateViewObject; 0026 class KateDocumentObject; 0027 0028 /** 0029 * @internal 0030 * The backbone of Kate's automatic regression tests. 0031 */ 0032 class TestScriptEnv : public QObject 0033 { 0034 public: 0035 explicit TestScriptEnv(KTextEditor::DocumentPrivate *part, bool &cflag); 0036 ~TestScriptEnv() override; 0037 0038 QJSEngine *engine() const 0039 { 0040 return m_engine; 0041 } 0042 0043 /** returns the output object */ 0044 OutputObject *output() const 0045 { 0046 return m_output; 0047 } 0048 0049 private: 0050 QJSEngine *m_engine; 0051 KateViewObject *m_viewObj; 0052 KateDocumentObject *m_docObj; 0053 0054 OutputObject *m_output; 0055 }; 0056 0057 /** 0058 * @internal 0059 */ 0060 class KateViewObject : public KateScriptView 0061 { 0062 Q_OBJECT 0063 0064 public: 0065 explicit KateViewObject(QJSEngine *engine, KTextEditor::ViewPrivate *view); 0066 ~KateViewObject() override; 0067 0068 // Edit functions 0069 Q_INVOKABLE void keyReturn(int cnt = 1); 0070 Q_INVOKABLE void backspace(int cnt = 1); 0071 Q_INVOKABLE void deleteWordLeft(int cnt = 1); 0072 Q_INVOKABLE void keyDelete(int cnt = 1); 0073 Q_INVOKABLE void deleteWordRight(int cnt = 1); 0074 Q_INVOKABLE void transpose(int cnt = 1); 0075 Q_INVOKABLE void cursorLeft(int cnt = 1); 0076 Q_INVOKABLE void shiftCursorLeft(int cnt = 1); 0077 Q_INVOKABLE void cursorRight(int cnt = 1); 0078 Q_INVOKABLE void shiftCursorRight(int cnt = 1); 0079 Q_INVOKABLE void wordLeft(int cnt = 1); 0080 Q_INVOKABLE void shiftWordLeft(int cnt = 1); 0081 Q_INVOKABLE void wordRight(int cnt = 1); 0082 Q_INVOKABLE void shiftWordRight(int cnt = 1); 0083 Q_INVOKABLE void home(int cnt = 1); 0084 Q_INVOKABLE void shiftHome(int cnt = 1); 0085 Q_INVOKABLE void end(int cnt = 1); 0086 Q_INVOKABLE void shiftEnd(int cnt = 1); 0087 Q_INVOKABLE void up(int cnt = 1); 0088 Q_INVOKABLE void shiftUp(int cnt = 1); 0089 Q_INVOKABLE void down(int cnt = 1); 0090 Q_INVOKABLE void shiftDown(int cnt = 1); 0091 Q_INVOKABLE void scrollUp(int cnt = 1); 0092 Q_INVOKABLE void scrollDown(int cnt = 1); 0093 Q_INVOKABLE void topOfView(int cnt = 1); 0094 Q_INVOKABLE void shiftTopOfView(int cnt = 1); 0095 Q_INVOKABLE void bottomOfView(int cnt = 1); 0096 Q_INVOKABLE void shiftBottomOfView(int cnt = 1); 0097 Q_INVOKABLE void pageUp(int cnt = 1); 0098 Q_INVOKABLE void shiftPageUp(int cnt = 1); 0099 Q_INVOKABLE void pageDown(int cnt = 1); 0100 Q_INVOKABLE void shiftPageDown(int cnt = 1); 0101 Q_INVOKABLE void top(int cnt = 1); 0102 Q_INVOKABLE void shiftTop(int cnt = 1); 0103 Q_INVOKABLE void bottom(int cnt = 1); 0104 Q_INVOKABLE void shiftBottom(int cnt = 1); 0105 Q_INVOKABLE void toMatchingBracket(int cnt = 1); 0106 Q_INVOKABLE void shiftToMatchingBracket(int cnt = 1); 0107 0108 Q_INVOKABLE void type(const QString &str); 0109 Q_INVOKABLE void paste(const QString &str); 0110 0111 /** 0112 * Toggle auto brackets. If you make use of it, make sure to 0113 * disable them again at the end of your test, otherwise any following tests may fail. 0114 */ 0115 Q_INVOKABLE void setAutoBrackets(bool enable = true); 0116 0117 /* 0118 * Whether to replace tabs with spaces 0119 */ 0120 Q_INVOKABLE void replaceTabs(bool enable = true); 0121 0122 // Aliases 0123 Q_INVOKABLE void enter(int cnt = 1); // KeyReturn 0124 Q_INVOKABLE void cursorPrev(int cnt = 1); // CursorLeft 0125 Q_INVOKABLE void left(int cnt = 1); // CursorLeft 0126 Q_INVOKABLE void prev(int cnt = 1); // CursorLeft 0127 Q_INVOKABLE void shiftCursorPrev(int cnt = 1); // ShiftCursorLeft 0128 Q_INVOKABLE void shiftLeft(int cnt = 1); // ShiftCursorLeft 0129 Q_INVOKABLE void shiftPrev(int cnt = 1); // ShiftCursorLeft 0130 Q_INVOKABLE void cursorNext(int cnt = 1); // CursorRight 0131 Q_INVOKABLE void right(int cnt = 1); // CursorRight 0132 Q_INVOKABLE void next(int cnt = 1); // CursorRight 0133 Q_INVOKABLE void shiftCursorNext(int cnt = 1); // ShiftCursorRight 0134 Q_INVOKABLE void shiftRight(int cnt = 1); // ShiftCursorRight 0135 Q_INVOKABLE void shiftNext(int cnt = 1); // ShiftCursorRight 0136 Q_INVOKABLE void wordPrev(int cnt = 1); // WordLeft 0137 Q_INVOKABLE void shiftWordPrev(int cnt = 1); // ShiftWordLeft 0138 Q_INVOKABLE void wordNext(int cnt = 1); // WordRight 0139 Q_INVOKABLE void shiftWordNext(int cnt = 1); // ShiftWordRight 0140 }; 0141 0142 /** 0143 * @internal 0144 */ 0145 class KateDocumentObject : public KateScriptDocument 0146 { 0147 Q_OBJECT 0148 0149 public: 0150 explicit KateDocumentObject(QJSEngine *engine, KTextEditor::DocumentPrivate *doc); 0151 ~KateDocumentObject() override; 0152 }; 0153 0154 /** 0155 * Customizing output to result-files. Writing any output into result files 0156 * inhibits outputting the content of the katepart after script execution, 0157 * enabling one to check for coordinates and the like. 0158 * @internal 0159 */ 0160 class OutputObject : public QObject 0161 { 0162 Q_OBJECT 0163 0164 public: 0165 OutputObject(KTextEditor::ViewPrivate *v, bool &cflag); 0166 ~OutputObject() override; 0167 0168 void output(bool cp, bool ln); 0169 0170 Q_INVOKABLE void write(); 0171 Q_INVOKABLE void writeln(); 0172 Q_INVOKABLE void writeLn(); 0173 0174 Q_INVOKABLE void print(); 0175 Q_INVOKABLE void println(); 0176 Q_INVOKABLE void printLn(); 0177 0178 Q_INVOKABLE void writeCursorPosition(); 0179 Q_INVOKABLE void writeCursorPositionln(); 0180 0181 Q_INVOKABLE void cursorPosition(); 0182 Q_INVOKABLE void cursorPositionln(); 0183 Q_INVOKABLE void cursorPositionLn(); 0184 0185 Q_INVOKABLE void pos(); 0186 Q_INVOKABLE void posln(); 0187 Q_INVOKABLE void posLn(); 0188 0189 private: 0190 KTextEditor::ViewPrivate *view; 0191 bool &cflag; 0192 }; 0193 #endif // TESTUTILS_H