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>
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"
42 class PartMonitor
: public QObject
46 PartMonitor(KHTMLPart
*_part
);
48 void waitForCompletion();
51 static PartMonitor
* sm_highestMonitor
;
52 QStack
<QEventLoop
*> m_eventLoopStack
;
56 QTimer
*m_timeout_timer
;
66 class RegTestObject
: public KJS::JSObject
69 RegTestObject(KJS::ExecState
*exec
, RegressionTest
*_regTest
);
72 RegressionTest
*m_regTest
;
78 class RegTestFunction
: public KJS::JSObject
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
};
89 RegressionTest
*m_regTest
;
96 class KHTMLPartObject
: public KJS::JSObject
99 KHTMLPartObject(KJS::ExecState
*exec
, KHTMLPart
*_part
);
101 virtual bool getOwnPropertySlot(KJS::ExecState
*exec
, const KJS::Identifier
& propertyName
, KJS::PropertySlot
& slot
);
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
&);
111 class KHTMLPartFunction
: public KJS::JSObject
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
};
126 class ScriptInterpreter
;
132 class RegressionTest
: public QObject
137 RegressionTest(KHTMLPart
*part
, const QString
&baseDir
, const QString
&outputDir
,
138 bool _genOutput
, bool runJS
, bool runHTML
);
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
);
166 QString m_currentBase
;
168 QString m_currentOutput
;
169 QString m_currentCategory
;
170 QString m_currentTest
;
171 QPixmap
* m_paintBuffer
;
183 int m_known_failures
;
185 static RegressionTest
*curr
;
188 void printDescription(const QString
& description
);
190 static bool svnIgnored( const QString
&filename
);
193 void evalJS( KJS::ScriptInterpreter
&interp
, const QString
&filename
, bool report
); // used by testJS
196 void slotOpenURL(const KUrl
&url
, const KParts::OpenUrlArguments
& args
, const KParts::BrowserArguments
& browserArgs
);
197 void resizeTopLevelWidget( int, int );