Engauge Digitizer  2
TestValidators.cpp
1 #include "CoordUnitsNonPolarTheta.h"
2 #include "DlgValidatorDateTime.h"
3 #include "DlgValidatorDegreesMinutesSeconds.h"
4 #include "DlgValidatorNumber.h"
5 #include "Logger.h"
6 #include "MainWindow.h"
7 #include <QtTest/QtTest>
8 #include "Test/TestValidators.h"
9 
10 QTEST_MAIN (TestValidators)
11 
12 TestValidators::TestValidators(QObject *parent) :
13  QObject(parent)
14 {
15 }
16 
17 void TestValidators::cleanupTestCase ()
18 {
19 }
20 
21 void TestValidators::initTestCase ()
22 {
23  const QString NO_ERROR_REPORT_LOG_FILE;
24  const QString NO_REGRESSION_OPEN_FILE;
25  const bool NO_GNUPLOT_LOG_FILES = false;
26  const bool NO_REGRESSION_IMPORT = false;
27  const bool NO_RESET = false;
28  const bool DEBUG_FLAG = false;
29  const QStringList NO_LOAD_STARTUP_FILES;
30 
31  initializeLogging ("engauge_test",
32  "engauge_test.log",
33  DEBUG_FLAG);
34 
35  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
36  NO_REGRESSION_OPEN_FILE,
37  NO_GNUPLOT_LOG_FILES,
38  NO_REGRESSION_IMPORT,
39  NO_RESET,
40  NO_LOAD_STARTUP_FILES);
41  w.show ();
42 }
43 
44 bool TestValidators::stateDateTime (const QString &string,
45  QValidator::State expectedState)
46 {
47  int pos;
48 
49  DlgValidatorDateTime validator (COORD_SCALE_LOG,
50  COORD_UNITS_DATE_YEAR_MONTH_DAY,
51  COORD_UNITS_TIME_HOUR_MINUTE_SECOND);
52 
53  QString stringLocal = string;
54  return (validator.validate (stringLocal,
55  pos) == expectedState);
56 }
57 
58 bool TestValidators::stateDegreesMinutesSeconds (const QString &string,
59  QValidator::State expectedState)
60 {
61  int pos;
62 
63  DlgValidatorDegreesMinutesSeconds validator (COORD_SCALE_LOG);
64 
65  QString stringLocal = string;
66  return (validator.validate (stringLocal,
67  pos) == expectedState);
68 }
69 
70 bool TestValidators::stateNumber(const QString &string,
71  QValidator::State expectedState)
72 {
73  int pos;
74  const QLocale locale;
75 
76  DlgValidatorNumber validator (COORD_SCALE_LOG,
77  locale);
78 
79  QString stringLocal = string;
80  return (validator.validate (stringLocal,
81  pos) == expectedState);
82 }
83 
84 void TestValidators::testDateTimeDate ()
85 {
86  QVERIFY (stateDateTime ("2015/01/02", QValidator::Acceptable));
87 }
88 
89 void TestValidators::testDateTimeDateTime ()
90 {
91  QVERIFY (stateDateTime ("2015/01/02 01:02:03", QValidator::Acceptable));
92 }
93 
94 void TestValidators::testDateTimeDateTimePm ()
95 {
96  QVERIFY (stateDateTime ("2015/01/02 01:02:03 PM", QValidator::Acceptable));
97 }
98 
99 void TestValidators::testDateTimeTime ()
100 {
101  QVERIFY (stateDateTime ("01:02:03", QValidator::Acceptable));
102 }
103 
104 void TestValidators::testDegreesMinutesSecondsDegrees ()
105 {
106  QVERIFY (stateDegreesMinutesSeconds ("180", QValidator::Acceptable));
107 }
108 
109 void TestValidators::testDegreesMinutesSecondsDegreesMinutes ()
110 {
111  QVERIFY (stateDegreesMinutesSeconds ("180 10", QValidator::Acceptable));
112 }
113 
114 void TestValidators::testDegreesMinutesSecondsDegreesMinutesSeconds ()
115 {
116  QVERIFY (stateDegreesMinutesSeconds ("180 10 20", QValidator::Acceptable));
117 }
118 
119 void TestValidators::testNumberInteger ()
120 {
121  QVERIFY (stateNumber ("1", QValidator::Acceptable));
122 }
123 
124 void TestValidators::testNumberReal ()
125 {
126  QVERIFY (stateNumber ("1.1", QValidator::Acceptable));
127 }
128 
129 void TestValidators::testNumberRealBad ()
130 {
131  QVERIFY (stateNumber ("1.1.", QValidator::Invalid));
132 }
Validator for numeric value expressed as date and/or time.
Validator for angles in real degrees, integer degrees and real minutes, or integer degrees with integ...
virtual QValidator::State validate(QString &input, int &pos) const
Validate according to the numeric format specific to the leaf class.
virtual QValidator::State validate(QString &input, int &pos) const
Validate according to the numeric format specific to the leaf class.
Unit tests of validators.
virtual QValidator::State validate(QString &input, int &pos) const
Apply the standard validation with 0 as the exclusive minimum. Call setCoordScale just before calling...
Validator for generic (=simple) numbers.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:89