summaryrefslogtreecommitdiffstats
path: root/kate/part/test_regression.h
blob: ee4f8fdfa4363cdae6550b88fd54ef2c1fc1a31a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/**
 * This file is part of the KDE project
 *
 * Copyright (C) 2001,2003 Peter Kelly (pmk@post.com)
 * Copyright 2006 Leo Savernik (l.savernik@aon.at)
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 *
 */

#ifndef TEST_REGRESSION_H
#define TEST_REGRESSION_H

#include <katejscript.h>
#include <kateview.h>
#include <kurl.h>
#include <tqobject.h>
#include <tqstringlist.h>
#include <kjs/ustring.h>
#include <kjs/object.h>
#include <kjs/interpreter.h>

class KateDocument;
class KateView;
class RegressionTest;
class TQTimer;

namespace KParts {
  class URLArgs;
}

class OutputObject;

/**
 * @internal
 * The backbone of Kate's automatic regression tests.
 */
class TestJScriptEnv : public KateJScript
{
  public:
    TestJScriptEnv(KateDocument *part);
    virtual ~TestJScriptEnv();

    /** returns the global scope */
    KJS::Object global() const { return *m_global; }
    /** returns the script interpreter */
    KJS::Interpreter &interpreter() { return *m_interpreter; }
    /** returns the document scope */
    KJS::Object document() const { return *m_document; }
    /** returns the view scope */
    KJS::Object view() const { return *m_view; }
    /** returns the output object */
    OutputObject *output() const { return m_output; }

  protected:
    OutputObject *m_output;
};

/**
 * @internal
 */
class KateViewObject : public KJS::ObjectImp
{
  public:
    KateViewObject(KJS::ExecState *exec, KateView *v, KJS::ObjectImp *fallback);
    virtual ~KateViewObject();

    virtual const KJS::ClassInfo *classInfo() const;
    virtual KJS::Value get(KJS::ExecState *exec, const KJS::Identifier &propertyName) const;

  private:
    // evil hack I: class layout of katejscript/KateJSView must be duplicated
    // here, structurally as well as functionally
    KateView *view;
    // end evil hack
    KJS::ObjectImp *fallback;
};

/**
 * @internal
 */
class KateViewFunction : public KJS::ObjectImp
{
  public:
    KateViewFunction(KJS::ExecState *exec, KateView *v, int _id, int length);

    bool implementsCall() const;
    KJS::Value call(KJS::ExecState *exec, KJS::Object &thisObj, const KJS::List &args);

    enum { KeyReturn, Type, Backspace, DeleteWordLeft, KeyDelete,
      DeleteWordRight, Transpose, CursorLeft, ShiftCursorLeft, CursorRight,
      ShiftCursorRight, WordLeft, ShiftWordLeft, WordRight, ShiftWordRight,
      Home, ShiftHome, End, ShiftEnd, Up, ShiftUp, Down, ShiftDown, ScrollUp,
      ScrollDown, TopOfView, ShiftTopOfView, BottomOfView, ShiftBottomOfView,
      PageUp, ShiftPageUp, PageDown, ShiftPageDown, Top, ShiftTop, Bottom,
      ShiftBottom, ToMatchingBracket, ShiftToMatchingBracket };
  private:
    KateView *m_view;
    int id;
};

class OutputFunction;

/**
 * Customizing output to result-files. Writing any output into result files
 * inhibits outputting the content of the katepart after script execution, enabling one to check for coordinates and the like.
 * @internal
 */
class OutputObject : public KJS::ObjectImp
{
  public:
    OutputObject(KJS::ExecState *exec, KateDocument *d, KateView *v);
    virtual ~OutputObject();

    virtual KJS::UString className() const;

    void setChangedFlag(bool *flag) { changed = flag; }
    void setOutputString(TQString *s) { outstr = s; }

  private:
    KateDocument *doc;
    KateView *view;
    bool *changed;
    TQString *outstr;

    friend class OutputFunction;
};

/**
 * Customizing output to result-files.
 * @internal
 */
class OutputFunction : public KJS::ObjectImp
{
  public:
    OutputFunction(KJS::ExecState *exec, OutputObject *obj, int _id, int length);

    bool implementsCall() const;
    virtual KJS::Value call(KJS::ExecState *exec, KJS::Object &thisObj, const KJS::List &args);

    enum { Write, Writeln, WriteCursorPosition, WriteCursorPositionln };
  private:
    OutputObject *o;
    int id;
};

/**
 * @internal
 */
class RegressionTest : public QObject
{
  Q_OBJECT
public:

    RegressionTest(KateDocument *part, KConfig *baseConfig,
                   const TQString &baseDir, const TQString &outputDir,
                   bool _genOutput);
    ~RegressionTest();

    enum OutputType { ResultDocument };
    void testStaticFile(const TQString& filename, const TQStringList &commands);
    enum CheckResult { Failure = 0, Success = 1, Ignored = 2 };
    CheckResult checkOutput(const TQString& againstFilename);
    enum FailureType { NoFailure = 0, AllFailure = 1, ResultFailure = 4, NewFailure = 65536 };
    bool runTests(TQString relPath = TQString::null, bool mustExist = false, int known_failure = NoFailure);
    bool reportResult( bool passed, const TQString & description = TQString::null, bool *newfailure = 0 );
    bool reportResult(CheckResult result, const TQString & description = TQString::null, bool *newfailure = 0 );
    void rereadConfig();
    static void createMissingDirs(const TQString &path);

    void setFailureSnapshotConfig(KConfig *cfg, const TQString &snapshotname);
    void setFailureSnapshotSaver(KConfig *cfg, const TQString &snapshotname);

    void createLink( const TQString& test, int failures );
    void doFailureReport( const TQString& test, int failures );

    KateDocument *m_part;
    KateView *m_view;
    KConfig *m_baseConfig;
    TQString m_baseDir;
    TQString m_outputDir;
    bool m_genOutput;
    TQString m_currentBase;
    KConfig *m_failureComp;
    KConfig *m_failureSave;

    TQString m_currentOutput;
    TQString m_currentCategory;
    TQString m_currentTest;

    bool m_keepOutput;
    bool m_getOutput;
    bool m_showGui;
    int m_passes_work;
    int m_passes_fail;
    int m_passes_new;
    int m_failures_work;
    int m_failures_fail;
    int m_failures_new;
    int m_errors;
    bool saw_failure;
    bool ignore_errors;
    int m_known_failures;
    bool m_outputCustomised;
    TQString m_outputString;

    static RegressionTest *curr;

private:
    void printDescription(const TQString& description);

    static bool svnIgnored( const TQString &filename );

private:
    /**
     * evaluate script given by \c filename within the context of \c interp.
     * @param ignore if \c true don't evaluate if script does not exist but
     * return true nonetheless.
     * @return true if script was valid, false otherwise
     */
    bool evalJS( KJS::Interpreter &interp, const TQString &filename, bool ignore = false);
    /**
     * concatenate contents of all list files down to but not including the
     * tests directory.
     * @param relPath relative path against tests-directory
     * @param filename file name of the list files
     */
    TQStringList concatListFiles(const TQString &relPath, const TQString &filename);

private slots:
    void slotOpenURL(const KURL &url, const KParts::URLArgs &args);
    void resizeTopLevelWidget( int, int );

};

#endif