Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
a031112b
Commit
a031112b
authored
Nov 01, 2010
by
con
Browse files
Add auto test for file search.
parent
77008bc4
Changes
5
Hide whitespace changes
Inline
Side-by-side
tests/auto/auto.pro
View file @
a031112b
...
...
@@ -9,7 +9,8 @@ SUBDIRS += \
generichighlighter
\
#
icheckbuild
\
#
profilewriter
\
utils_stringutils
utils_stringutils
\
filesearch
contains
(
QT_CONFIG
,
declarative
)
{
SUBDIRS
+=
qml
...
...
tests/auto/filesearch/filesearch.pro
0 → 100644
View file @
a031112b
CONFIG
+=
qtestlib
testcase
TEMPLATE
=
app
CONFIG
-=
app_bundle
DEFINES
+=
QTCREATOR_UTILS_LIB
include
(..
/../../
qtcreator
.
pri
)
UTILS_PATH
=
$$
IDE_SOURCE_TREE
/
src
/
libs
/
utils
INCLUDEPATH
+=
$$
UTILS_PATH
#
Input
SOURCES
+=
tst_filesearch
.
cpp
\
$$
UTILS_PATH
/
filesearch
.
cpp
HEADERS
+=
$$
UTILS_PATH
/
filesearch
.
h
\
$$
UTILS_PATH
/
utils_global
.
h
TARGET
=
tst_
$$
TARGET
OTHER_FILES
+=
testfile
.
txt
RESOURCES
+=
\
tst_filesearch
.
qrc
tests/auto/filesearch/testfile.txt
0 → 100644
View file @
a031112b
wholeWordAtStart bla foo blubb wholeWordAtEnd
search to find multiple find results
search CaseSensitively for casesensitive
here you find another result
wholeWordAtVeryEnd
tests/auto/filesearch/tst_filesearch.cpp
0 → 100644
View file @
a031112b
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include <filesearch.h>
#include <QtTest/QtTest>
bool
operator
==
(
const
Utils
::
FileSearchResult
&
r1
,
const
Utils
::
FileSearchResult
&
r2
)
{
return
r1
.
fileName
==
r2
.
fileName
&&
r1
.
lineNumber
==
r2
.
lineNumber
&&
r1
.
matchingLine
==
r2
.
matchingLine
&&
r1
.
matchStart
==
r2
.
matchStart
&&
r1
.
matchLength
==
r2
.
matchLength
&&
r1
.
regexpCapturedTexts
==
r2
.
regexpCapturedTexts
;
}
class
tst_FileSearch
:
public
QObject
{
Q_OBJECT
private
slots
:
void
multipleResults
();
void
caseSensitive
();
void
caseInSensitive
();
};
namespace
{
const
char
*
const
FILENAME
=
":/tst_filesearch/testfile.txt"
;
void
test_helper
(
const
Utils
::
FileSearchResultList
&
expectedResults
,
const
QString
&
term
,
QTextDocument
::
FindFlags
flags
)
{
Utils
::
FileIterator
*
it
=
new
Utils
::
FileIterator
(
QStringList
()
<<
QLatin1String
(
FILENAME
),
QList
<
QTextCodec
*>
()
<<
QTextCodec
::
codecForLocale
());
QFutureWatcher
<
Utils
::
FileSearchResultList
>
watcher
;
QSignalSpy
ready
(
&
watcher
,
SIGNAL
(
resultsReadyAt
(
int
,
int
)));
watcher
.
setFuture
(
Utils
::
findInFiles
(
term
,
it
,
flags
));
watcher
.
future
().
waitForFinished
();
QTest
::
qWait
(
100
);
// process events
QCOMPARE
(
ready
.
count
(),
1
);
Utils
::
FileSearchResultList
results
=
watcher
.
resultAt
(
0
);
QCOMPARE
(
results
.
count
(),
expectedResults
.
count
());
for
(
int
i
=
0
;
i
<
expectedResults
.
size
();
++
i
)
{
QCOMPARE
(
results
.
at
(
i
),
expectedResults
.
at
(
i
));
}
}
}
void
tst_FileSearch
::
multipleResults
()
{
Utils
::
FileSearchResultList
expectedResults
;
expectedResults
<<
Utils
::
FileSearchResult
(
QLatin1String
(
FILENAME
),
2
,
QLatin1String
(
"search to find multiple find results"
),
10
,
4
,
QStringList
());
expectedResults
<<
Utils
::
FileSearchResult
(
QLatin1String
(
FILENAME
),
2
,
QLatin1String
(
"search to find multiple find results"
),
24
,
4
,
QStringList
());
expectedResults
<<
Utils
::
FileSearchResult
(
QLatin1String
(
FILENAME
),
4
,
QLatin1String
(
"here you find another result"
),
9
,
4
,
QStringList
());
test_helper
(
expectedResults
,
QLatin1String
(
"find"
),
QTextDocument
::
FindFlags
(
0
));
}
void
tst_FileSearch
::
caseSensitive
()
{
Utils
::
FileSearchResultList
expectedResults
;
expectedResults
<<
Utils
::
FileSearchResult
(
QLatin1String
(
FILENAME
),
3
,
QLatin1String
(
"search CaseSensitively for casesensitive"
),
7
,
13
,
QStringList
());
test_helper
(
expectedResults
,
QLatin1String
(
"CaseSensitive"
),
QTextDocument
::
FindCaseSensitively
);
}
void
tst_FileSearch
::
caseInSensitive
()
{
Utils
::
FileSearchResultList
expectedResults
;
expectedResults
<<
Utils
::
FileSearchResult
(
QLatin1String
(
FILENAME
),
3
,
QLatin1String
(
"search CaseSensitively for casesensitive"
),
7
,
13
,
QStringList
());
expectedResults
<<
Utils
::
FileSearchResult
(
QLatin1String
(
FILENAME
),
3
,
QLatin1String
(
"search CaseSensitively for casesensitive"
),
27
,
13
,
QStringList
());
test_helper
(
expectedResults
,
QLatin1String
(
"CaseSensitive"
),
QTextDocument
::
FindFlags
(
0
));
}
QTEST_MAIN
(
tst_FileSearch
)
#include "tst_filesearch.moc"
tests/auto/filesearch/tst_filesearch.qrc
0 → 100644
View file @
a031112b
<RCC>
<qresource prefix="/tst_filesearch">
<file>testfile.txt</file>
</qresource>
</RCC>
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment