~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to tests/scriptdocument_test.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE libraries
2
 
   Copyright (C) 2010 Bernhard Beschow <bbeschow@cs.tu-berlin.de>
3
 
 
4
 
   This library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Library General Public
6
 
   License as published by the Free Software Foundation; either
7
 
   version 2 of the License, or (at your option) any later version.
8
 
 
9
 
   This library is distributed in the hope that it will be useful,
10
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
   Library General Public License for more details.
13
 
 
14
 
   You should have received a copy of the GNU Library General Public License
15
 
   along with this library; see the file COPYING.LIB.  If not, write to
16
 
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17
 
   Boston, MA 02110-1301, USA.
18
 
*/
19
 
 
20
 
#include "scriptdocument_test.h"
21
 
#include "moc_scriptdocument_test.cpp"
22
 
 
23
 
#include <qtest_kde.h>
24
 
 
25
 
#include <ktexteditor/view.h>
26
 
 
27
 
#include <katedocument.h>
28
 
#include <katescriptdocument.h>
29
 
 
30
 
Q_DECLARE_METATYPE(KTextEditor::Cursor)
31
 
 
32
 
QTEST_KDEMAIN(ScriptDocumentTest, GUI)
33
 
 
34
 
namespace QTest {
35
 
  template<>
36
 
  char *toString(const KTextEditor::Cursor &cursor)
37
 
  {
38
 
    QByteArray ba = "Cursor[";
39
 
    ba += QByteArray::number(cursor.line()) + ", " + QByteArray::number(cursor.column());
40
 
    ba += "]";
41
 
    return qstrdup(ba.data());
42
 
  }
43
 
}
44
 
 
45
 
QtMsgHandler ScriptDocumentTest::s_msgHandler = 0;
46
 
 
47
 
void myMessageOutput(QtMsgType type, const char *msg)
48
 
{
49
 
  switch (type) {
50
 
  case QtDebugMsg:
51
 
    /* do nothing */
52
 
    break;
53
 
  default:
54
 
    ScriptDocumentTest::s_msgHandler(type, msg);
55
 
  }
56
 
}
57
 
 
58
 
void ScriptDocumentTest::initTestCase()
59
 
{
60
 
  s_msgHandler = qInstallMsgHandler(myMessageOutput);
61
 
}
62
 
 
63
 
void ScriptDocumentTest::cleanupTestCase()
64
 
{
65
 
  qInstallMsgHandler(0);
66
 
}
67
 
 
68
 
ScriptDocumentTest::ScriptDocumentTest()
69
 
  : QObject()
70
 
  , m_doc(0)
71
 
  , m_view(0)
72
 
  , m_scriptDoc(0)
73
 
{
74
 
}
75
 
 
76
 
ScriptDocumentTest::~ScriptDocumentTest()
77
 
{
78
 
}
79
 
 
80
 
void ScriptDocumentTest::init()
81
 
{
82
 
  m_doc = new KateDocument(false, false, false, 0, this);
83
 
  m_view = m_doc->createView(0);
84
 
  m_scriptDoc = new KateScriptDocument(this);
85
 
  m_scriptDoc->setDocument(m_doc);
86
 
}
87
 
 
88
 
void ScriptDocumentTest::cleanup()
89
 
{
90
 
  delete m_scriptDoc;
91
 
  delete m_view;
92
 
  delete m_doc;
93
 
}
94
 
 
95
 
#if 0
96
 
void ScriptDocumentTest::testRfind_data()
97
 
{
98
 
  QTest::addColumn<KTextEditor::Range>("searchRange");
99
 
  QTest::addColumn<KTextEditor::Range>("expectedResult");
100
 
 
101
 
  QTest::newRow("") << KTextEditor::Range(0, 0, 1, 10) << KTextEditor::Range(1,  6, 1, 10);
102
 
  QTest::newRow("") << KTextEditor::Range(0, 0, 1,  5) << KTextEditor::Range(1,  0, 1,  4);
103
 
  QTest::newRow("") << KTextEditor::Range(0, 0, 1,  0) << KTextEditor::Range(0, 10, 0, 14);
104
 
}
105
 
 
106
 
void ScriptDocumentTest::testRfind()
107
 
{
108
 
  QFETCH(KTextEditor::Range, searchRange);
109
 
  QFETCH(KTextEditor::Range, expectedResult);
110
 
 
111
 
  m_doc->setText("aaaa aaaa aaaa\n"
112
 
                 "aaaa  aaaa");
113
 
 
114
 
  QCOMPARE(m_search->search(searchRange, "aaaa", true), expectedResult);
115
 
}
116
 
#endif
117
 
 
118
 
void ScriptDocumentTest::testRfind_data()
119
 
{
120
 
  QTest::addColumn<KTextEditor::Cursor>("searchStart");
121
 
  QTest::addColumn<KTextEditor::Cursor>("result");
122
 
 
123
 
  QTest::newRow("a a a a a a a a a a a a|") << KTextEditor::Cursor(0, 23) << KTextEditor::Cursor(0, 18);
124
 
  QTest::newRow("a a a a a a a a a a a |a") << KTextEditor::Cursor(0, 22) << KTextEditor::Cursor(0, 16);
125
 
  QTest::newRow("a a a a| a a a a a a a a") << KTextEditor::Cursor(0,  7) << KTextEditor::Cursor(0,  2);
126
 
  QTest::newRow("a a a |a a a a a a a a a") << KTextEditor::Cursor(0,  6) << KTextEditor::Cursor(0,  0);
127
 
  QTest::newRow("a a a| a a a a a a a a a") << KTextEditor::Cursor(0,  5) << KTextEditor::Cursor(0,  0);
128
 
  QTest::newRow("a a |a a a a a a a a a a") << KTextEditor::Cursor(0,  4) << KTextEditor::Cursor::invalid();
129
 
}
130
 
 
131
 
void ScriptDocumentTest::testRfind()
132
 
{
133
 
  QFETCH(KTextEditor::Cursor, searchStart);
134
 
  QFETCH(KTextEditor::Cursor, result);
135
 
 
136
 
  m_scriptDoc->setText("a a a a a a a a a a a a");
137
 
 
138
 
  QCOMPARE(m_scriptDoc->rfind(searchStart.line(), searchStart.column(), "a a a"), result);
139
 
}