Engauge Digitizer  2
 All Classes Files Functions Variables Enumerations Enumerator Friends Pages
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 DEBUG_FLAG = false;
28  const QStringList NO_LOAD_STARTUP_FILES;
29 
30  initializeLogging ("engauge_test",
31  "engauge_test.log",
32  DEBUG_FLAG);
33 
34  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
35  NO_REGRESSION_OPEN_FILE,
36  NO_GNUPLOT_LOG_FILES,
37  NO_REGRESSION_IMPORT,
38  NO_LOAD_STARTUP_FILES);
39  w.show ();
40 }
41 
42 bool TestValidators::stateDateTime (const QString &string,
43  QValidator::State expectedState)
44 {
45  int pos;
46 
47  DlgValidatorDateTime validator (COORD_SCALE_LOG,
48  COORD_UNITS_DATE_YEAR_MONTH_DAY,
49  COORD_UNITS_TIME_HOUR_MINUTE_SECOND);
50 
51  QString stringLocal = string;
52  return (validator.validate (stringLocal,
53  pos) == expectedState);
54 }
55 
56 bool TestValidators::stateDegreesMinutesSeconds (const QString &string,
57  QValidator::State expectedState)
58 {
59  int pos;
60 
61  DlgValidatorDegreesMinutesSeconds validator (COORD_SCALE_LOG);
62 
63  QString stringLocal = string;
64  return (validator.validate (stringLocal,
65  pos) == expectedState);
66 }
67 
68 bool TestValidators::stateNumber(const QString &string,
69  QValidator::State expectedState)
70 {
71  int pos;
72  const QLocale locale;
73 
74  DlgValidatorNumber validator (COORD_SCALE_LOG,
75  locale);
76 
77  QString stringLocal = string;
78  return (validator.validate (stringLocal,
79  pos) == expectedState);
80 }
81 
82 void TestValidators::testDateTimeDate ()
83 {
84  QVERIFY (stateDateTime ("2015/01/02", QValidator::Acceptable));
85 }
86 
87 void TestValidators::testDateTimeDateTime ()
88 {
89  QVERIFY (stateDateTime ("2015/01/02 01:02:03", QValidator::Acceptable));
90 }
91 
92 void TestValidators::testDateTimeDateTimePm ()
93 {
94  QVERIFY (stateDateTime ("2015/01/02 01:02:03 PM", QValidator::Acceptable));
95 }
96 
97 void TestValidators::testDateTimeTime ()
98 {
99  QVERIFY (stateDateTime ("01:02:03", QValidator::Acceptable));
100 }
101 
102 void TestValidators::testDegreesMinutesSecondsDegrees ()
103 {
104  QVERIFY (stateDegreesMinutesSeconds ("180", QValidator::Acceptable));
105 }
106 
107 void TestValidators::testDegreesMinutesSecondsDegreesMinutes ()
108 {
109  QVERIFY (stateDegreesMinutesSeconds ("180 10", QValidator::Acceptable));
110 }
111 
112 void TestValidators::testDegreesMinutesSecondsDegreesMinutesSeconds ()
113 {
114  QVERIFY (stateDegreesMinutesSeconds ("180 10 20", QValidator::Acceptable));
115 }
116 
117 void TestValidators::testNumberInteger ()
118 {
119  QVERIFY (stateNumber ("1", QValidator::Acceptable));
120 }
121 
122 void TestValidators::testNumberReal ()
123 {
124  QVERIFY (stateNumber ("1.1", QValidator::Acceptable));
125 }
126 
127 void TestValidators::testNumberRealBad ()
128 {
129  QVERIFY (stateNumber ("1.1.", QValidator::Invalid));
130 }
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...
Unit tests of validators.
Validator for generic (=simple) numbers.
Main window consisting of menu, graphics scene, status bar and optional toolbars as a Single Document...
Definition: MainWindow.h:82