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
|
/*
Tests for Kopete::Message::parseEmoticons
Copyright (c) 2004 by Richard Smith <kde@metafoo.co.uk>
Copyright (c) 2005 by Duncan Mac-Vicar <duncan@kde.org>
Kopete (c) 2002-2005 by the Kopete developers <kopete-devel@kde.org>
*************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
*************************************************************************
*/
#include <stdlib.h>
#include <tqstring.h>
#include <tqdir.h>
#include <tqfile.h>
#include <kapplication.h>
#include <kglobal.h>
#include <kstandarddirs.h>
#include <kdebug.h>
#include <kunittest/module.h>
#include "kopeteemoticontest.h"
#include "kopetemessage.h"
#include "kopeteemoticons.h"
using namespace KUnitTest;
KUNITTEST_MODULE( kunittest_kopeteemoticontest, "KopeteSuite");
KUNITTEST_MODULE_REGISTER_TESTER( KopeteEmoticonTest );
/*
There are three sets of tests, the Kopete 0.7 baseline with tests that were
working properly in Kopete 0.7.x. When these fail it's a real regression.
The second set are those known to work in the current codebase.
The last set is the set with tests that are known to fail right now.
the name convention is working|broken-number.input|output
*/
void KopeteEmoticonTest::allTests()
{
// change user data dir to avoid messing with user's .kde dir
setenv( "TDEHOME", TQFile::encodeName( TQDir::homeDirPath() + "/.kopete-unittest" ), true );
//TDEApplication::disableAutoDcopRegistration();
//TDEApplication app;
testEmoticonParser();
}
void KopeteEmoticonTest::testEmoticonParser()
{
Kopete::Emoticons emo("Default");
TQString basePath = TQString::fromLatin1( SRCDIR ) + TQString::fromLatin1("/emoticon-parser-testcases");
TQDir testCasesDir(basePath);
TQStringList inputFileNames = testCasesDir.entryList("*.input");
for ( TQStringList::ConstIterator it = inputFileNames.begin(); it != inputFileNames.end(); ++it)
{
TQString fileName = *it;
kdDebug() << "testcase: " << fileName << endl;
TQString outputFileName = fileName;
outputFileName.replace("input","output");
// open the input file
TQFile inputFile(basePath + TQString::fromLatin1("/") + fileName);
TQFile expectedFile(basePath + TQString::fromLatin1("/") + outputFileName);
// check if the expected output file exists
// if it doesn't, skip the testcase
if ( ! expectedFile.exists() )
{
SKIP("Warning! expected output for testcase "+ *it + " not found. Skiping testcase");
continue;
}
if ( inputFile.open( IO_ReadOnly ) && expectedFile.open( IO_ReadOnly ))
{
TQTextStream inputStream(&inputFile);
TQTextStream expectedStream(&expectedFile);
TQString inputData;
TQString expectedData;
inputData = inputStream.read();
expectedData = expectedStream.read();
inputFile.close();
expectedFile.close();
TQString path = TDEGlobal::dirs()->findResource( "emoticons", "Default/smile.png" ).replace( "smile.png", TQString() );
Kopete::Emoticons::self();
TQString result = emo.parse( inputData ).replace( path, TQString() );
// HACK to know the test case we applied, concatenate testcase name to both
// input and expected string. WIll remove when I can add some sort of metadata
// to a CHECK so debug its origin testcase
result = fileName + TQString::fromLatin1(": ") + result;
expectedData = fileName + TQString::fromLatin1(": ") + expectedData;
// if the test case begins with broken, we expect it to fail, then use XFAIL
// otherwise use CHECK
if ( fileName.section("-", 0, 0) == TQString::fromLatin1("broken") )
{
kdDebug() << "checking known-broken testcase: " << fileName << endl;
XFAIL(result, expectedData);
}
else
{
kdDebug() << "checking known-working testcase: " << fileName << endl;
CHECK(result, expectedData);
}
}
else
{
SKIP("Warning! can't open testcase files for "+ *it + ". Skiping testcase");
continue;
}
}
}
|