1 #ifndef QT_NO_DEBUG
2 #include "testmanager.h"
3 //hel
4 #include "smallUsefulFunctions_t.h"
5 #include "latexparser_t.h"
6 #include "latexparsing_t.h"
7 #include "encoding_t.h"
8 #include "execprogram_t.h"
9 #include "buildmanager_t.h"
10 #include "codesnippet_t.h"
11 #include "qdocumentcursor_t.h"
12 #include "qdocumentline_t.h"
13 #include "qdocumentsearch_t.h"
14 #include "qsearchreplacepanel_t.h"
15 #include "qeditor_t.h"
16 #include "latexcompleter_t.h"
17 #include "latexeditorview_t.h"
18 #include "latexeditorview_bm.h"
19 #include "latexstyleparser_t.h"
20 #include "scriptengine_t.h"
21 #include "structureview_t.h"
22 #include "tablemanipulation_t.h"
23 #include "syntaxcheck_t.h"
24 #include "updatechecker_t.h"
25 #include "utilsui_t.h"
26 #include "utilsversion_t.h"
27 #include "help_t.h"
28 #include "usermacro_t.h"
29 #include "latexoutputfilter_t.h"
30 #include "git_t.h"
31 #include <QtTest/QtTest>
32 
33 const QRegExp TestToken::simpleTextRegExp ("[A-Z'a-z0-9]+.?");
34 const QRegExp TestToken::commandRegExp ("\\\\([A-Za-z]+|.)");
35 const QRegExp TestToken::ignoredTextRegExp ("[$\t *!{}.\\][]+");
36 const QRegExp TestToken::specialCharTextRegExp ("[A-Z'\"\\\\\\{\\}a-z0-9ö]+");
37 const QRegExp TestToken::punctationRegExp("[!():\"?,.;-]");
38 
39 long long totalTestTime;
40 char* tempResult;
41 bool globalExecuteAllTests;
42 
43 
performTest(QObject * obj)44 QString TestManager::performTest(QObject* obj){
45 	char* argv[3];
46 	argv[0]=(char*)"texstudio";
47 	argv[1]=(char*)"-o";
48 	argv[2]=tempResult;
49 	QElapsedTimer timing;
50 	timing.start();
51 	QTest::qExec(obj,3,argv);
52 	delete obj;
53 	long long time = timing.elapsed();
54 	totalTestTime += time;
55 	QString testTime = QString("Time: %1 ms\n\n" ).arg(time);
56 	QFile f(QFile::decodeName(tempResult));
57 	if (!f.open(QIODevice::ReadOnly))
58 		return "\n\n!!!!!!!!!!! Couldn't find test result !!!!!!!!!!!! \n\n";
59 	return f.readAll()+testTime;
60 }
61 
execute(TestLevel level,LatexEditorView * edView,QCodeEdit * codeedit,QEditor * editor,BuildManager * buildManager)62 QString TestManager::execute(TestLevel level, LatexEditorView* edView, QCodeEdit* codeedit, QEditor* editor, BuildManager* buildManager){
63 	QTemporaryFile tf;
64 	tf.setAutoRemove(false);
65 	tf.open();
66 	QByteArray tfn = QFile::encodeName(tf.fileName());
67 	tf.close();
68 	tempResult = tfn.data();
69 
70 	globalExecuteAllTests = level == TL_ALL;
71 
72 	//codeedit, editor are passed as extra parameters and not extracted from edView, so we don't have
73 	//to include latexeditorview.h here
74 	totalTestTime = 0;
75 	QString tr;
76 	QList<QObject*> tests=QList<QObject*>()
77             << new SmallUsefulFunctionsTest()
78             << new LatexParserTest()
79             << new LatexParsingTest()
80             << new EncodingTest()
81             << new ExecProgramTest()
82             << new LatexOutputFilterTest()
83             << new BuildManagerTest(buildManager)
84             << new CodeSnippetTest(editor)
85             << new QDocumentLineTest()
86             << new QDocumentCursorTest(level==TL_AUTO)
87             << new QDocumentSearchTest(editor,level==TL_ALL)
88             << new QSearchReplacePanelTest(codeedit,level==TL_ALL)
89             << new QEditorTest(editor,level==TL_ALL)
90             << new LatexEditorViewTest(edView)
91             << new LatexCompleterTest(edView)
92             << new LatexStyleParserTest(level==TL_ALL)
93             << new ScriptEngineTest(edView,level==TL_ALL)
94             << new LatexEditorViewBenchmark(edView,level==TL_ALL)
95             << new StructureViewTest(edView,edView->document,level==TL_ALL)
96             << new TableManipulationTest(editor)
97             << new SyntaxCheckTest(edView)
98             << new UpdateCheckerTest(level==TL_ALL)
99             << new UtilsUITest(level==TL_ALL)
100             << new VersionTest(level==TL_ALL)
101             << new HelpTest(buildManager)
102             << new UserMacroTest()
103             << new GitTest(buildManager,level!=TL_AUTO);
104 	bool allPassed=true;
105 	if (level!=TL_ALL)
106 		tr="There are skipped tests. Please rerun with --execute-all-tests\n\n";
107 	QCoreApplication *app = QCoreApplication::instance();
108     TestmanagerEventFilter eventFilter;
109     app->installNativeEventFilter(&eventFilter);
110 	for (int i=0; i <tests.size();i++){
111 		emit newMessage(tests[i]->metaObject()->className());
112 		qDebug()<<tests[i]->metaObject()->className();
113 		QString res=performTest(tests[i]);
114 		tr+=res;
115 		if (!res.contains(", 0 failed, 0 skipped")) allPassed=false;
116 	}
117     app->removeNativeEventFilter(&eventFilter);
118 
119 	tr+=QString("\nTotal testing time: %1 ms\n").arg(totalTestTime);
120 
121 	if (!allPassed)
122 		tr="*** THERE SEEM TO BE FAILED TESTS! ***\n\n\n\n"+tr;
123 
124 	QFile(QFile::decodeName(tempResult)).remove();
125 
126 	return tr;
127 }
128 
nativeEventFilter(const QByteArray &,void *,long *)129 bool TestManager::nativeEventFilter(const QByteArray &, void *, long *)
130 {
131 	return true;
132 }
133 #if (QT_VERSION>=QT_VERSION_CHECK(6,0,0))
nativeEventFilter(const QByteArray &,void *,qintptr *)134 bool TestmanagerEventFilter::nativeEventFilter(const QByteArray &, void *, qintptr *)
135 #else
136 bool TestmanagerEventFilter::nativeEventFilter(const QByteArray &, void *, long *)
137 #endif
138 {
139     return true;
140 }
141 #endif
142 
143 
144