test_regression.h
00001 00024 #ifndef TEST_REGRESSION_H 00025 #define TEST_REGRESSION_H 00026 00027 #include <katejscript.h> 00028 #include <kateview.h> 00029 #include <kurl.h> 00030 #include <tqobject.h> 00031 #include <tqstringlist.h> 00032 #include <kjs/ustring.h> 00033 #include <kjs/object.h> 00034 #include <kjs/interpreter.h> 00035 00036 class KateDocument; 00037 class KateView; 00038 class RegressionTest; 00039 class TQTimer; 00040 00041 namespace KParts { 00042 class URLArgs; 00043 } 00044 00045 class OutputObject; 00046 00051 class TestJScriptEnv : public KateJScript 00052 { 00053 public: 00054 TestJScriptEnv(KateDocument *part); 00055 virtual ~TestJScriptEnv(); 00056 00058 KJS::Object global() const { return *m_global; } 00060 KJS::Interpreter &interpreter() { return *m_interpreter; } 00062 KJS::Object document() const { return *m_document; } 00064 KJS::Object view() const { return *m_view; } 00066 OutputObject *output() const { return m_output; } 00067 00068 protected: 00069 OutputObject *m_output; 00070 }; 00071 00075 class KateViewObject : public KJS::ObjectImp 00076 { 00077 public: 00078 KateViewObject(KJS::ExecState *exec, KateView *v, KJS::ObjectImp *fallback); 00079 virtual ~KateViewObject(); 00080 00081 virtual const KJS::ClassInfo *classInfo() const; 00082 virtual KJS::Value get(KJS::ExecState *exec, const KJS::Identifier &propertyName) const; 00083 00084 private: 00085 // evil hack I: class layout of katejscript/KateJSView must be duplicated 00086 // here, structurally as well as functionally 00087 KateView *view; 00088 // end evil hack 00089 KJS::ObjectImp *fallback; 00090 }; 00091 00095 class KateViewFunction : public KJS::ObjectImp 00096 { 00097 public: 00098 KateViewFunction(KJS::ExecState *exec, KateView *v, int _id, int length); 00099 00100 bool implementsCall() const; 00101 KJS::Value call(KJS::ExecState *exec, KJS::Object &thisObj, const KJS::List &args); 00102 00103 enum { KeyReturn, Type, Backspace, DeleteWordLeft, KeyDelete, 00104 DeleteWordRight, Transpose, CursorLeft, ShiftCursorLeft, CursorRight, 00105 ShiftCursorRight, WordLeft, ShiftWordLeft, WordRight, ShiftWordRight, 00106 Home, ShiftHome, End, ShiftEnd, Up, ShiftUp, Down, ShiftDown, ScrollUp, 00107 ScrollDown, TopOfView, ShiftTopOfView, BottomOfView, ShiftBottomOfView, 00108 PageUp, ShiftPageUp, PageDown, ShiftPageDown, Top, ShiftTop, Bottom, 00109 ShiftBottom, ToMatchingBracket, ShiftToMatchingBracket }; 00110 private: 00111 KateView *m_view; 00112 int id; 00113 }; 00114 00115 class OutputFunction; 00116 00122 class OutputObject : public KJS::ObjectImp 00123 { 00124 public: 00125 OutputObject(KJS::ExecState *exec, KateDocument *d, KateView *v); 00126 virtual ~OutputObject(); 00127 00128 virtual KJS::UString className() const; 00129 00130 void setChangedFlag(bool *flag) { changed = flag; } 00131 void setOutputString(TQString *s) { outstr = s; } 00132 00133 private: 00134 KateDocument *doc; 00135 KateView *view; 00136 bool *changed; 00137 TQString *outstr; 00138 00139 friend class OutputFunction; 00140 }; 00141 00146 class OutputFunction : public KJS::ObjectImp 00147 { 00148 public: 00149 OutputFunction(KJS::ExecState *exec, OutputObject *obj, int _id, int length); 00150 00151 bool implementsCall() const; 00152 virtual KJS::Value call(KJS::ExecState *exec, KJS::Object &thisObj, const KJS::List &args); 00153 00154 enum { Write, Writeln, WriteCursorPosition, WriteCursorPositionln }; 00155 private: 00156 OutputObject *o; 00157 int id; 00158 }; 00159 00163 class RegressionTest : public TQObject 00164 { 00165 Q_OBJECT 00166 public: 00167 00168 RegressionTest(KateDocument *part, KConfig *baseConfig, 00169 const TQString &baseDir, const TQString &outputDir, 00170 bool _genOutput); 00171 ~RegressionTest(); 00172 00173 enum OutputType { ResultDocument }; 00174 void testStaticFile(const TQString& filename, const TQStringList &commands); 00175 enum CheckResult { Failure = 0, Success = 1, Ignored = 2 }; 00176 CheckResult checkOutput(const TQString& againstFilename); 00177 enum FailureType { NoFailure = 0, AllFailure = 1, ResultFailure = 4, NewFailure = 65536 }; 00178 bool runTests(TQString relPath = TQString::null, bool mustExist = false, int known_failure = NoFailure); 00179 bool reportResult( bool passed, const TQString & description = TQString::null, bool *newfailure = 0 ); 00180 bool reportResult(CheckResult result, const TQString & description = TQString::null, bool *newfailure = 0 ); 00181 void rereadConfig(); 00182 static void createMissingDirs(const TQString &path); 00183 00184 void setFailureSnapshotConfig(KConfig *cfg, const TQString &snapshotname); 00185 void setFailureSnapshotSaver(KConfig *cfg, const TQString &snapshotname); 00186 00187 void createLink( const TQString& test, int failures ); 00188 void doFailureReport( const TQString& test, int failures ); 00189 00190 KateDocument *m_part; 00191 KateView *m_view; 00192 KConfig *m_baseConfig; 00193 TQString m_baseDir; 00194 TQString m_outputDir; 00195 bool m_genOutput; 00196 TQString m_currentBase; 00197 KConfig *m_failureComp; 00198 KConfig *m_failureSave; 00199 00200 TQString m_currentOutput; 00201 TQString m_currentCategory; 00202 TQString m_currentTest; 00203 00204 bool m_keepOutput; 00205 bool m_getOutput; 00206 bool m_showGui; 00207 int m_passes_work; 00208 int m_passes_fail; 00209 int m_passes_new; 00210 int m_failures_work; 00211 int m_failures_fail; 00212 int m_failures_new; 00213 int m_errors; 00214 bool saw_failure; 00215 bool ignore_errors; 00216 int m_known_failures; 00217 bool m_outputCustomised; 00218 TQString m_outputString; 00219 00220 static RegressionTest *curr; 00221 00222 private: 00223 void printDescription(const TQString& description); 00224 00225 static bool svnIgnored( const TQString &filename ); 00226 00227 private: 00234 bool evalJS( KJS::Interpreter &interp, const TQString &filename, bool ignore = false); 00241 TQStringList concatListFiles(const TQString &relPath, const TQString &filename); 00242 00243 private slots: 00244 void slotOpenURL(const KURL &url, const KParts::URLArgs &args); 00245 void resizeTopLevelWidget( int, int ); 00246 00247 }; 00248 00249 #endif