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 bool NO_GNUPLOT_LOG_FILES = false;
25  const bool DEBUG_FLAG = false;
26 
27  initializeLogging ("engauge_test",
28  "engauge_test.log",
29  DEBUG_FLAG);
30 
31  MainWindow w (NO_ERROR_REPORT_LOG_FILE,
32  NO_GNUPLOT_LOG_FILES);
33  w.show ();
34 }
35 
36 bool TestValidators::stateDateTime (const QString &string,
37  QValidator::State expectedState)
38 {
39  int pos;
40 
41  DlgValidatorDateTime validator (COORD_SCALE_LOG,
42  COORD_UNITS_DATE_YEAR_MONTH_DAY,
43  COORD_UNITS_TIME_HOUR_MINUTE_SECOND);
44 
45  QString stringLocal = string;
46  return (validator.validate (stringLocal,
47  pos) == expectedState);
48 }
49 
50 bool TestValidators::stateDegreesMinutesSeconds (const QString &string,
51  QValidator::State expectedState)
52 {
53  int pos;
54 
55  DlgValidatorDegreesMinutesSeconds validator (COORD_SCALE_LOG);
56 
57  QString stringLocal = string;
58  return (validator.validate (stringLocal,
59  pos) == expectedState);
60 }
61 
62 bool TestValidators::stateNumber(const QString &string,
63  QValidator::State expectedState)
64 {
65  int pos;
66 
67  DlgValidatorNumber validator (COORD_SCALE_LOG);
68 
69  QString stringLocal = string;
70  return (validator.validate (stringLocal,
71  pos) == expectedState);
72 }
73 
74 void TestValidators::testDateTimeDate ()
75 {
76  QVERIFY (stateDateTime ("2015/01/02", QValidator::Acceptable));
77 }
78 
79 void TestValidators::testDateTimeDateTime ()
80 {
81  QVERIFY (stateDateTime ("2015/01/02 01:02:03", QValidator::Acceptable));
82 }
83 
84 void TestValidators::testDateTimeDateTimePm ()
85 {
86  QVERIFY (stateDateTime ("2015/01/02 01:02:03 PM", QValidator::Acceptable));
87 }
88 
89 void TestValidators::testDateTimeTime ()
90 {
91  QVERIFY (stateDateTime ("01:02:03", QValidator::Acceptable));
92 }
93 
94 void TestValidators::testDegreesMinutesSecondsDegrees ()
95 {
96  QVERIFY (stateDegreesMinutesSeconds ("180", QValidator::Acceptable));
97 }
98 
99 void TestValidators::testDegreesMinutesSecondsDegreesMinutes ()
100 {
101  QVERIFY (stateDegreesMinutesSeconds ("180 10", QValidator::Acceptable));
102 }
103 
104 void TestValidators::testDegreesMinutesSecondsDegreesMinutesSeconds ()
105 {
106  QVERIFY (stateDegreesMinutesSeconds ("180 10 20", QValidator::Acceptable));
107 }
108 
109 void TestValidators::testNumberInteger ()
110 {
111  QVERIFY (stateNumber ("1", QValidator::Acceptable));
112 }
113 
114 void TestValidators::testNumberReal ()
115 {
116  QVERIFY (stateNumber ("1.1", QValidator::Acceptable));
117 }
118 
119 void TestValidators::testNumberRealBad ()
120 {
121  QVERIFY (stateNumber ("1.1.", QValidator::Invalid));
122 }
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:60