summaryrefslogtreecommitdiffstats
path: root/kspread/tests/testrunner.cpp
blob: d16dc1661ce75e1fe4afbdfcd937c28f683782b3 (plain)
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
/* This file is part of the KDE project
   Copyright 2004 Ariya Hidayat <ariya@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#include "testrunner.h"

#include <tqapplication.h>
#include <tqdict.h>
#include <tqlabel.h>
#include <tqlayout.h>
#include <tqtextedit.h>

#include <kcombobox.h>
#include <kdialogbase.h>
#include <kpushbutton.h>

#include "tester.h"
#include "value_tester.h"
#include "formula_tester.h"
//#include "stylecluster_tester.h"

namespace KSpread
{

class TestRunner::Private
{
public:
  TQDict<Tester> testers;
  KComboBox* testType;
  KPushButton* runButton;
  TQTextEdit* logView;
};

}

using namespace KSpread;


TestRunner::TestRunner():
  KDialogBase( KDialogBase::Plain, "Internal Tests", KDialogBase::Close,
  KDialogBase::Close )
{
  d = new Private;

  TQFrame* mainWidget = plainPage();
  TQGridLayout* layout = new TQGridLayout( mainWidget, 3, 4, marginHint(), spacingHint() );
  setMinimumSize( 360, 230 );

  TQLabel* typeLabel = new TQLabel( "Type of Test:", mainWidget );
  layout->addWidget( typeLabel, 0, 0 );

  d->testType = new KComboBox( mainWidget );
  layout->addWidget( d->testType, 0, 1 );

  TQSpacerItem* spacerItem = new TQSpacerItem( 10, 10, TQSizePolicy::Expanding, TQSizePolicy::Minimum );
  layout->addItem( spacerItem, 0, 2 );

  d->runButton = new KPushButton( "Run", mainWidget );
  layout->addWidget( d->runButton, 0, 3 );

  d->logView = new TQTextEdit( mainWidget );
  layout->addMultiCellWidget( d->logView, 2, 2, 0, 3 );
  d->logView->setTextFormat( TQt::LogText );

  TQObject::connect( d->runButton, TQT_SIGNAL( clicked() ), this, TQT_SLOT( runTest() ) );

  // add all tests here !!
  addTester( new ValueTester() );
  // addTester( new StyleClusterTester() );
  addTester( new FormulaParserTester() );
  addTester( new FormulaEvalTester() );
  addTester( new FormulaOasisConversionTester() );
}

TestRunner::~TestRunner()
{
  TQDictIterator<Tester> it( d->testers );
  for( ; it.current(); ++it ) delete it.current();
  delete d;
}

void TestRunner::addTester( Tester* tester )
{
  if( !tester ) return;
  d->testers.insert( tester->name(), tester );
  d->testType->insertItem( tester->name() );
}

void TestRunner::runTest()
{
  TQString testName = d->testType->currentText();
  Tester* tester = d->testers.find( testName );
  if( tester )
  {
    d->logView->clear();
    d->logView->append( TQString("Test: %1").arg( testName ) );

    TQApplication::setOverrideCursor(TQt::waitCursor);
    tester->run();
    TQApplication::restoreOverrideCursor();

    TQStringList errorList = tester->errors();
    if( tester->failed() )
    {
      d->logView->append( TQString( "%1 tests, <b>%2 failed.</b>").arg( tester->count() ).
        arg(  tester->failed() ) );
      for( unsigned k = 0; k < errorList.count(); k++ )
        d->logView->append( errorList[k] );
    }
    else
      d->logView->append( TQString( "%1 tests, everything is OK. ").arg( tester->count() ) );

    d->logView->append( "Test finished." );
  }
}

#include "testrunner.moc"