00001 #pragma ident "$Id: gpszcounttest.cpp 1895 2009-05-12 19:34:29Z afarris $"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00031 #include <limits>
00032 #include "GPSZcount.hpp"
00033 #include "CommandOptionParser.hpp"
00034
00035 using namespace std;
00036 using namespace gpstk;
00037
00038 bool failure = false;
00039 int verboseLevel = 0;
00040 void say(const string& foo);
00041 void process(bool result);
00042
00043
00044
00045
00046 int main (int argc, char *argv[])
00047 {
00048
00049 CommandOptionNoArg hOption('h', "help", "Display this helpful information.",
00050 false);
00051 CommandOptionNoArg vOption('v', "verbose", "Increase the verbosity.",
00052 false);
00053 CommandOptionNoArg qOption('q', "quiet", "Only issue a return code.",
00054 false);
00055 CommandOptionParser cop("GPSZcount Test Suite");
00056 cop.parseOptions(argc, argv);
00057 if (cop.hasErrors())
00058 {
00059 cop.dumpErrors(cout);
00060 cop.displayUsage(cout);
00061 return 1;
00062 }
00063
00064 if(hOption.getCount())
00065 {
00066 cop.displayUsage(cout);
00067 return 0;
00068 }
00069
00070 verboseLevel = vOption.getCount();
00071
00072 try
00073 {
00074
00075 GPSZcount one, two;
00076
00077 say("Equality Test: ");
00078 process (one == two);
00079
00080 say("Assignment Test 1: ");
00081 one = GPSZcount(1000, 5);
00082 process(one.getWeek() == 1000 &&
00083 one.getZcount() == 5);
00084
00085 say("Assignment Test 2: ");
00086 try
00087 {
00088
00089 one.setZcount(GPSZcount::ZCOUNT_WEEK);
00090
00091 process(false);
00092 }
00093 catch (InvalidParameter& ip)
00094 {
00095 process(true);
00096 }
00097
00098 say("Addition Test: ");
00099 one += GPSZcount::ZCOUNT_WEEK + 5 ;
00100 process(one.getWeek() == 1001 &&
00101 one.getZcount() == 10) ;
00102
00103 say("Subtraction Test: ");
00104 one -= GPSZcount::ZCOUNT_WEEK + 5 ;
00105 process(one.getWeek() == 1000 &&
00106 one.getZcount() == 5) ;
00107
00108 say("Invalid Week Test 1: ");
00109 one.setWeek(numeric_limits<short>::max());
00110 try
00111 {
00112
00113 one += GPSZcount::ZCOUNT_WEEK;
00114
00115 process(false);
00116 }
00117 catch (InvalidRequest& ir)
00118 {
00119 process(true);
00120 }
00121
00122 say("Invalid Week Test 2: " );
00123 one.setWeek(0);
00124 try
00125 {
00126
00127 one -= GPSZcount::ZCOUNT_WEEK;
00128
00129 process(false);
00130 }
00131 catch (InvalidRequest& ir)
00132 {
00133 process(true);
00134 }
00135
00136 say("Less-Than Test: ");
00137 one.setWeek(1000).setZcount(GPSZcount::ZCOUNT_WEEK / 2) ;
00138 two = one + 5 ;
00139 process(two >= one) ;
00140
00141 say("Greater-Than Test: ") ;
00142 two = one - 5 ;
00143 process(two <= one) ;
00144
00145 say("SameTimeBlock Test 1: ") ;
00146
00147 one.setWeek(1200).setZcount(4 * GPSZcount::ZCOUNT_HOUR
00148 + 20 * GPSZcount::ZCOUNT_MINUTE) ;
00149 two.setWeek(1200).setZcount(4 * GPSZcount::ZCOUNT_HOUR) ;
00150
00151 process(one.inSameTimeBlock(two, GPSZcount::ZCOUNT_HOUR)) ;
00152
00153 say("SameTimeBlock Test 2: ") ;
00154
00155 process(! one.inSameTimeBlock(two, GPSZcount::ZCOUNT_MINUTE)) ;
00156
00157 say("SameTimeBlock Test 3: ") ;
00158
00159 process(! one.inSameTimeBlock(two, GPSZcount::ZCOUNT_HOUR,
00160 15 * GPSZcount::ZCOUNT_MINUTE)) ;
00161
00162 say("Dump Test: ") ;
00163 if (verboseLevel)
00164 {
00165 cout << endl << one << endl;
00166 one.dump(cout, 1);
00167 }
00168
00169 say("String Test: ");
00170 one.setWeek(1200).setZcount(123456);
00171 process(string(one) == string("1200w123456z"));
00172
00173 if (qOption.getCount() == 0)
00174 {
00175
00176 cout << "GPSZcount Overall results: "
00177 << (failure ? "Fail" : "Pass") << endl;
00178 }
00179
00180 return failure ? 1 : 0 ;
00181 }
00182 catch(gpstk::Exception& exc)
00183 {
00184 cout << endl << endl << "Caught a " << exc.getName() << " exception:"
00185 << endl << exc << endl ;
00186 return 1 ;
00187 }
00188 }
00189
00190 void say(const string& foo)
00191 {
00192 if (verboseLevel)
00193 cout << foo << flush;
00194 }
00195
00196 void process(bool result)
00197 {
00198 failure |= !result;
00199
00200 if(verboseLevel)
00201 {
00202 cout << (result ? "Pass" : "Fail") << endl;
00203 }
00204 }