fix logic
[personal-kdelibs.git] / khtml / test_regression.h
blob7e0408f24bd7d1c9e4019b9bb4260c570567327c
1 /**
2 * This file is part of the KDE project
4 * Copyright (C) 2001,2003 Peter Kelly (pmk@post.com)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef TEST_REGRESSION_H
24 #define TEST_REGRESSION_H
26 #include <khtml_part.h>
27 #include <kurl.h>
28 #include <QtCore/QObject>
29 #include <QtCore/QStack>
30 #include <kjs/ustring.h>
31 #include <kjs/object.h>
32 #include <kjs/interpreter.h>
33 #include "ecma/kjs_binding.h"
35 class RegressionTest;
36 class QTimer;
37 class QEventLoop;
39 /**
40 * @internal
42 class PartMonitor : public QObject
44 Q_OBJECT
45 public:
46 PartMonitor(KHTMLPart *_part);
47 ~PartMonitor();
48 void waitForCompletion();
49 void enterLoop();
50 void exitLoop();
51 static PartMonitor* sm_highestMonitor;
52 QStack<QEventLoop*> m_eventLoopStack;
53 bool m_completed;
54 KHTMLPart *m_part;
55 int m_timer_waits;
56 QTimer *m_timeout_timer;
57 public Q_SLOTS:
58 void partCompleted();
59 void timeout();
60 void finishTimers();
63 /**
64 * @internal
66 class RegTestObject : public KJS::JSObject
68 public:
69 RegTestObject(KJS::ExecState *exec, RegressionTest *_regTest);
71 private:
72 RegressionTest *m_regTest;
75 /**
76 * @internal
78 class RegTestFunction : public KJS::JSObject
80 public:
81 RegTestFunction(KJS::ExecState *exec, RegressionTest *_regTest, int _id, int length);
83 bool implementsCall() const;
84 KJS::JSValue* callAsFunction(KJS::ExecState *exec, KJS::JSObject* thisObj, const KJS::List &args);
86 enum { Print, ReportResult, CheckOutput, Quit };
88 private:
89 RegressionTest *m_regTest;
90 int id;
93 /**
94 * @internal
96 class KHTMLPartObject : public KJS::JSObject
98 public:
99 KHTMLPartObject(KJS::ExecState *exec, KHTMLPart *_part);
101 virtual bool getOwnPropertySlot(KJS::ExecState *exec, const KJS::Identifier& propertyName, KJS::PropertySlot& slot);
102 private:
103 static KJS::JSValue *winGetter(KJS::ExecState *, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);
104 static KJS::JSValue *docGetter(KJS::ExecState *, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);
105 KHTMLPart *m_part;
109 * @internal
111 class KHTMLPartFunction : public KJS::JSObject
113 public:
114 KHTMLPartFunction(KJS::ExecState *exec, KHTMLPart *_part, int _id, int length);
116 bool implementsCall() const;
117 KJS::JSValue* callAsFunction(KJS::ExecState *exec, KJS::JSObject* thisObj, const KJS::List &args);
119 enum { OpenPage, OpenPageAsUrl, Begin, Write, End, ExecuteScript, ProcessEvents };
120 private:
121 KHTMLPart *m_part;
122 int id;
125 namespace KJS {
126 class ScriptInterpreter;
130 * @internal
132 class RegressionTest : public QObject
134 Q_OBJECT
135 public:
137 RegressionTest(KHTMLPart *part, const QString &baseDir, const QString &outputDir,
138 bool _genOutput, bool runJS, bool runHTML);
139 ~RegressionTest();
141 enum OutputType { DOMTree, RenderTree };
142 QString getPartOutput( OutputType type );
143 void getPartDOMOutput( QTextStream &outputStream, KHTMLPart* part, uint indent );
144 void dumpRenderTree( QTextStream &outputStream, KHTMLPart* part );
145 void testStaticFile(const QString& filename);
146 void testJSFile(const QString& filename);
147 enum CheckResult { Failure = 0, Success = 1, Ignored = 2 };
148 CheckResult checkOutput(const QString& againstFilename);
149 CheckResult checkPaintdump( const QString& againstFilename);
150 enum FailureType { NoFailure = 0, AllFailure = 1, RenderFailure = 2, DomFailure = 4, PaintFailure = 8, JSFailure = 16};
151 bool runTests(QString relPath = QString(), bool mustExist = false, QStringList failureFileList = QStringList());
152 bool reportResult( bool passed, const QString & description = QString() );
153 bool reportResult(CheckResult result, const QString & description = QString() );
154 void createMissingDirs(const QString &path);
156 QImage renderToImage();
157 bool imageEqual( const QImage &lhs, const QImage &rhs );
158 void createLink( const QString& test, int failures );
159 void doJavascriptReport( const QString &test );
160 void doFailureReport( const QString& test, int failures );
162 KHTMLPart *m_part;
163 QString m_baseDir;
164 QString m_outputDir;
165 bool m_genOutput;
166 QString m_currentBase;
168 QString m_currentOutput;
169 QString m_currentCategory;
170 QString m_currentTest;
171 QPixmap* m_paintBuffer;
173 bool m_getOutput;
174 bool m_runJS;
175 bool m_runHTML;
176 int m_passes_work;
177 int m_passes_fail;
178 int m_failures_work;
179 int m_failures_fail;
180 int m_errors;
181 bool saw_failure;
182 bool ignore_errors;
183 int m_known_failures;
185 static RegressionTest *curr;
187 private:
188 void printDescription(const QString& description);
190 static bool svnIgnored( const QString &filename );
192 private:
193 void evalJS( KJS::ScriptInterpreter &interp, const QString &filename, bool report ); // used by testJS
195 private Q_SLOTS:
196 void slotOpenURL(const KUrl &url, const KParts::OpenUrlArguments& args, const KParts::BrowserArguments& browserArgs);
197 void resizeTopLevelWidget( int, int );
201 #endif