FileSpec_T.cpp
Go to the documentation of this file.
1 //==============================================================================
2 //
3 // This file is part of GNSSTk, the ARL:UT GNSS Toolkit.
4 //
5 // The GNSSTk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Lesser General Public License as published
7 // by the Free Software Foundation; either version 3.0 of the License, or
8 // any later version.
9 //
10 // The GNSSTk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with GNSSTk; if not, write to the Free Software Foundation,
17 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 //
19 // This software was developed by Applied Research Laboratories at the
20 // University of Texas at Austin.
21 // Copyright 2004-2022, The Board of Regents of The University of Texas System
22 //
23 //==============================================================================
24 
25 //==============================================================================
26 //
27 // This software was developed by Applied Research Laboratories at the
28 // University of Texas at Austin, under contract to an agency or agencies
29 // within the U.S. Department of Defense. The U.S. Government retains all
30 // rights to use, duplicate, distribute, disclose, or release this software.
31 //
32 // Pursuant to DoD Directive 523024
33 //
34 // DISTRIBUTION STATEMENT A: This software has been approved for public
35 // release, distribution is unlimited.
36 //
37 //==============================================================================
38 
39 #include "FileSpec.hpp"
40 #include "YDSTime.hpp"
41 #include "GPSWeekZcount.hpp"
42 #include "SystemTime.hpp"
43 #include "TestUtil.hpp"
44 #include <iostream>
45 #include <set>
46 
47 using namespace std;
48 using namespace gnsstk;
49 
51 {
52 public:
53 
54  // constructor
55  FileSpec_T() { init(); }
56 
57  // destructor
59 
60  // initialize tests
61  void init();
62 
63  // test conversion of file spec type values to strings and vice-versa.
64  // Also test that no duplicate file spec types exist.
65  // @return number of failures, i.e., 0=PASS, !0=FAIL
66  unsigned testConvertFileSpecType();
67 
68  // test operator++() and operator--() for FileSpecType
69  // @return number of failures, i.e., 0=PASS, !0=FAIL
70  unsigned testFileSpecTypeOps();
71 
72  // test creation of invalid FileSpec objects
73  // @return number of failures, i.e., 0=PASS, !0=FAIL
74  unsigned testInitInvalid();
75 
76  // test creation of valid FileSpec objects and test a few methods
77  // that get the state of FileSpec objects
78  // @return number of failures, i.e., 0=PASS, !0=FAIL
79  unsigned testInitValid();
80 
81  // test FileSpec method newSpec()
82  // @return number of failures, i.e., 0=PASS, !0=FAIL
83  unsigned testNewSpec();
84 
85  // test FileSpec method hasField()
86  // @return number of failures, i.e., 0=PASS, !0=FAIL
87  unsigned testHasField();
88 
89  // test FileSpec method getSpecString()
90  // @return number of failures, i.e., 0=PASS, !0=FAIL
91  unsigned testGetSpecString();
92 
93  // test FileSpec method createSearchString()
94  // @return number of failures, i.e., 0=PASS, !0=FAIL
95  unsigned testCreateSearchString();
96 
97  // test FileSpec method extractField()
98  // @return number of failures, i.e., 0=PASS, !0=FAIL
99  unsigned testExtractField();
100 
101  // test FileSpec method extractCommonTime()
102  // @return number of failures, i.e., 0=PASS, !0=FAIL
103  unsigned testExtractCommonTime();
104 
105  // test FileSpec method toString()
106  // @return number of failures, i.e., 0=PASS, !0=FAIL
107  unsigned testToString();
108 
109  // test FileSpec method sortList()
110  // @return number of failures, i.e., 0=PASS, !0=FAIL
111  unsigned testSortList();
112 
113  // test FileSpec method hasTimeField()
114  unsigned testHasTimeField();
115 
116 }; // class FileSpec_T
117 
118 
119 //---------------------------------------------------------------------------
121 {
122  // empty
123 }
124 
125 
126 //---------------------------------------------------------------------------
128 {
129  TUDEF( "FileSpec", "convertFileSpecType" );
130 
131  set<std::string> fstSet;
132  FileSpec::FileSpecType fst = FileSpec::unknown;
133  fst++; // skip unknown
134  for ( ; fst < FileSpec::end; fst++)
135  {
136  string fstStr;
137 
138  // attempt to convert from a FileSpecType to a string
139  try
140  {
141  fstStr = FileSpec::convertFileSpecType(fst);
142 
143  ostringstream oss;
144  oss << "duplicate file spec type string: " << fstStr;
145  TUASSERT(fstSet.find(fstStr) == fstSet.end());
146 
147  // check for empty file spec type string
148  if (fstStr.size() == 0)
149  {
150  if (fst == FileSpec::fixed)
151  {
152  // Special Case : 'fixed' should convert to "" to denote
153  // no future value substitution, don't try to convert
154  // from "" to fixed though
155  TUPASS("fixed FileSpecType");
156  }
157  else
158  {
159  ostringstream oss;
160  oss << "empty file spec type string for value: " << fst;
161  TUFAIL(oss.str());
162  }
163  continue; // don't test with an empty file spec type string
164  }
165 
166  // check that file spec type string is exactly one character
167  {
168  ostringstream oss;
169  oss << "file spec type string should be a single character: "
170  << fstStr;
171  TUASSERTE(string::size_type, 1, fstStr.size());
172  }
173 
174  // store the file spec type string so it can be checked
175  // for duplication
176  switch (fst)
177  {
178  // Special Case : 'y' and 'Y' should both denote year
179  case FileSpec::year:
180  if ((fstStr[0] == 'y') || (fstStr[0] == 'Y'))
181  {
182  fstSet.insert("y");
183  fstSet.insert("Y");
184  }
185  else
186  {
187  ostringstream oss;
188  oss << "special case failed for file spec type: y / Y";
189  TUFAIL(oss.str());
190  }
191  break;
192 
193  // Special Case : 'c' and 'C' should both denote
194  // full GPS zcount
195  case FileSpec::fullzcount:
196  if ((fstStr[0] == 'c') || (fstStr[0] == 'C'))
197  {
198  fstSet.insert("c");
199  fstSet.insert("C");
200  }
201  else
202  {
203  ostringstream oss;
204  oss << "special case failed for file spec type: c / C";
205  TUFAIL(oss.str());
206  }
207  break;
208 
209  default:
210  fstSet.insert(fstStr);
211  }
212  }
213  catch (FileSpecException& fse)
214  {
215  ostringstream oss;
216  oss << "unexpected exception for file spec type value: " << fst;
217  TUFAIL(oss.str());
218  }
219 
220  // attempt to convert from a string to a FileSpecType
221  try
222  {
223  FileSpec::FileSpecType fstPost = FileSpec::convertFileSpecType(fstStr);
224 
225  ostringstream oss;
226  oss << "file spec type value/string/value mismatch: "
227  << fst << "/" + fstStr + "/" << fstPost;
228 
229  TUASSERTE(FileSpec::FileSpecType, fst, fstPost);
230  }
231  catch (FileSpecException& fse)
232  {
233  TUFAIL("unexpected exception for file spec type string: " + fstStr);
234  }
235  }
236 
237  // Special Case : check that 'y' and 'Y' both denote year
238  try
239  {
240  FileSpec::FileSpecType fsty = FileSpec::convertFileSpecType("y");
241  FileSpec::FileSpecType fstY = FileSpec::convertFileSpecType("Y");
242  TUASSERTE(FileSpec::FileSpecType, fsty, fstY);
243  }
244  catch (FileSpecException& fse)
245  {
246  TUFAIL("unexpected exception for file spec type: y / Y");
247  }
248 
249  // Special Case : check that 'c' and 'C' both denote full GPS zcount
250  try
251  {
252  FileSpec::FileSpecType fstc = FileSpec::convertFileSpecType("c");
253  FileSpec::FileSpecType fstC = FileSpec::convertFileSpecType("C");
254  TUASSERTE(FileSpec::FileSpecType, fstc, fstC);
255  }
256  catch (FileSpecException& fse)
257  {
258  TUFAIL("unexpected exception for file spec type: c / C");
259  }
260 
261  // check for file spec type value underflow
262  try
263  {
264  string fstStr = FileSpec::convertFileSpecType(FileSpec::unknown);
265  TUFAIL("exception expected for file spec type: unknown");
266  }
267  catch (FileSpecException& fse)
268  {
269  TUPASS("expected exception for invalid FileSpecType");
270  }
271 
272  // check for file spec type value overflow
273  try
274  {
275  string fstStr = FileSpec::convertFileSpecType(FileSpec::end);
276  TUFAIL("exception expected for file spec type: end");
277  }
278  catch (FileSpecException& fse)
279  {
280  TUPASS("expected exception for invalid FileSpecType");
281  }
282 
283  TURETURN();
284 }
285 
286 
287 //---------------------------------------------------------------------------
289 {
290  TUDEF( "FileSpecType", "operators" );
291 
293 
294  TURETURN();
295 }
296 
297 
298 //---------------------------------------------------------------------------
300 {
301  TUDEF( "FileSpec", "init (invalid)" );
302 
303  const string PCT("%");
304 
305  // assemble a list of invalid file spec strings
306  vector<string> invalidSpecs;
307 
308  invalidSpecs.push_back("%%");
309 
310  string s;
311  for (char c = 'A'; c <= 'Z'; ++c)
312  {
313  s = c;
314  try
315  {
316  FileSpec::FileSpecType fst = FileSpec::convertFileSpecType(s);
317 
318  // this specified is valid, ignore it
319  }
320  catch (FileSpecException& fse)
321  {
322  // this is not a valid specifier, add it
323  invalidSpecs.push_back(PCT + s);
324  }
325  }
326  for (char c = 'a'; c <= 'z'; ++c)
327  {
328  s = c;
329  try
330  {
331  FileSpec::FileSpecType fst = FileSpec::convertFileSpecType(s);
332 
333  // this specified is valid, ignore it
334  }
335  catch (FileSpecException& fse)
336  {
337  // this is not a valid specifier, add it
338  invalidSpecs.push_back(PCT + s);
339  }
340  }
341 
342  // create objects from invalid file spec strings (and hopefully fail)
343  vector<string>::const_iterator specIter = invalidSpecs.begin();
344  for ( ; specIter != invalidSpecs.end(); ++specIter)
345  {
346  try
347  {
348  FileSpec fs(*specIter);
349  ostringstream oss;
350  oss << "missing expected exception creating FileSpec(\""
351  << *specIter << "\")";
352  TUFAIL(oss.str());
353  }
354  catch (FileSpecException& fse)
355  {
356  TUPASS("expected exception for invalid FileSpec");
357  }
358  }
359 
360  TURETURN();
361 }
362 
363 
364 //---------------------------------------------------------------------------
366 {
367  TUDEF( "FileSpec", "init (valid)" );
368 
369  try // create a default object
370  {
371  FileSpec fs;
372  TUPASS("FileSpec created");
373  }
374  catch (FileSpecException& fse)
375  {
376  ostringstream oss;
377  oss << "exception creating default, empty FileSpec: " << fse;
378  TUFAIL(oss.str());
379  }
380 
381 
382  vector<string> validSpecs;
383 
384  const string PCT("%");
385 
386  validSpecs.push_back("");
387  validSpecs.push_back(" ");
389  //validSpecs.push_back(PCT + PCT);
390 
391  FileSpec::FileSpecType fst = FileSpec::unknown;
392  fst++; // skip unknown
393  for ( ; fst < FileSpec::end; fst++)
394  {
395  string s = FileSpec::convertFileSpecType(fst);
396  if (s.length() > 0)
397  {
398  validSpecs.push_back(s);
399  validSpecs.push_back(PCT + s);
400  validSpecs.push_back(PCT + s + PCT + s);
401  validSpecs.push_back(" " + PCT + s + " " + PCT + s + " ");
402  validSpecs.push_back(PCT + "4" + s);
403  validSpecs.push_back(PCT + "04" + s);
404  validSpecs.push_back(PCT + "-8" + s);
405  validSpecs.push_back(PCT + "16" + s);
406  validSpecs.push_back(PCT + "-12" + s);
408  //validSpecs.push_back(PCT + "10.4" + s);
409  validSpecs.push_back(PCT + "4" + s + PCT + "12" + s);
410  validSpecs.push_back(PCT + "-8" + s + PCT + "06" + s);
411 
412  // @note - FileSpec does not support precision, for example "%2.4g"
413 
414  // @note - FileSpec does not support '+', #', or ' ' as flags,
415  // for example "%+2g", "%#2g", and "% 2g"
416  }
417  }
418 
419  // test all of the specs - they should result in a valid FileSpec
420  vector<string>::const_iterator specIter = validSpecs.begin();
421  for ( ; specIter != validSpecs.end(); ++specIter)
422  {
423  try
424  {
425  FileSpec fs(*specIter);
426  TUPASS("FileSpec created");
427  }
428  catch (FileSpecException& fse)
429  {
430  ostringstream oss;
431  oss << "exception creating FileSpec(\""
432  << *specIter << "\"): " << fse;
433  TUFAIL(oss.str());
434  }
435  }
436 
437  TURETURN();
438 }
439 
440 
441 //---------------------------------------------------------------------------
443 {
444  TUDEF( "FileSpec", "newSpec" );
445 
446  try
447  {
448  FileSpec spec;
449  TUASSERTE(string::size_type, 0, spec.getSpecString().size());
450 
451  string str1("test-%y-spec");
452  spec.newSpec(str1);
453  TUASSERTE(int, 0, str1.compare(spec.getSpecString()));
454 
455  string str2("another-%y-one");
456  spec.newSpec(str2);
457  TUASSERTE(int, 0, str2.compare(spec.getSpecString()));
458  }
459  catch (FileSpecException& fse)
460  {
461  ostringstream oss;
462  oss << "unexpected exception: " << fse;
463  TUFAIL(oss.str());
464  }
465  TURETURN();
466 }
467 
468 
469 //---------------------------------------------------------------------------
471 {
472  TUDEF( "FileSpec", "hasField" );
473 
474  try // empty spec
475  {
476  FileSpec spec;
477  bool found = spec.hasField(FileSpec::year);
478  TUASSERT(!found);
479  }
480  catch (FileSpecException& fse)
481  {
482  ostringstream oss;
483  oss << "unexpected exception: " << fse;
484  TUFAIL(oss.str());
485  }
486 
487  try // non-empty spec containing field
488  {
489  string str("test-%y-spec");
490  FileSpec spec(str);
491  bool found = spec.hasField(FileSpec::year);
492  TUASSERT(found);
493  }
494  catch (FileSpecException& fse)
495  {
496  ostringstream oss;
497  oss << "unexpected exception: " << fse;
498  TUFAIL(oss.str());
499  }
500 
501  try // non-empty spec missing field
502  {
503  string str("test-%p-spec");
504  FileSpec spec(str);
505  bool found = spec.hasField(FileSpec::year);
506  TUASSERT(!found);
507  }
508  catch (FileSpecException& fse)
509  {
510  ostringstream oss;
511  oss << "unexpected exception: " << fse;
512  TUFAIL(oss.str());
513  }
514  TURETURN();
515 }
516 
517 
518 //---------------------------------------------------------------------------
520 {
521  TUDEF( "FileSpec", "getSpecString" );
522 
523  try
524  {
525  FileSpec spec;
526  TUASSERTE(string::size_type, 0, spec.getSpecString().size());
527  }
528  catch (FileSpecException& fse)
529  {
530  ostringstream oss;
531  oss << "unexpected exception: " << fse;
532  TUFAIL(oss.str());
533  }
534 
535  try
536  {
537  string str("test-%y-spec");
538  FileSpec spec(str);
539  TUASSERTE(int, 0, str.compare(spec.getSpecString()));
540  }
541  catch (FileSpecException& fse)
542  {
543  ostringstream oss;
544  oss << "unexpected exception: " << fse;
545  TUFAIL(oss.str());
546  }
547  TURETURN();
548 }
549 
550 
551 //---------------------------------------------------------------------------
553 {
554  TUDEF( "FileSpec", "createSearchString" );
555 
556  try // empty spec
557  {
558  FileSpec spec;
559  TUASSERTE(string::size_type, 0, spec.createSearchString().size());
560  }
561  catch (FileSpecException& fse)
562  {
563  ostringstream oss;
564  oss << "unexpected exception: " << fse;
565  TUFAIL(oss.str());
566  }
567 
568  try // fixed spec
569  {
570  string str("test-spec");
571  FileSpec spec(str);
572  TUASSERTE(int, 0, str.compare(spec.createSearchString()));
573  }
574  catch (FileSpecException& fse)
575  {
576  ostringstream oss;
577  oss << "unexpected exception: " << fse;
578  TUFAIL(oss.str());
579  }
580 
581  try // non-fixed spec, single substitution
582  {
583  string str("test-%y-spec");
584  string expect("test-?-spec");
585  FileSpec spec(str);
586  TUASSERTE(int, 0, expect.compare(spec.createSearchString()));
587  }
588  catch (FileSpecException& fse)
589  {
590  ostringstream oss;
591  oss << "unexpected exception: " << fse;
592  TUFAIL(oss.str());
593  }
594 
595  try // non-fixed spec, multiple substitution
596  {
597  string str("test-%y-spec-%y.%y");
598  string expect("test-?-spec-?.?");
599  FileSpec spec(str);
600  TUASSERTE(int, 0, expect.compare(spec.createSearchString()));
601  }
602  catch (FileSpecException& fse)
603  {
604  ostringstream oss;
605  oss << "unexpected exception: " << fse;
606  TUFAIL(oss.str());
607  }
608  TURETURN();
609 }
610 
611 
612 //---------------------------------------------------------------------------
614 {
615  TUDEF( "FileSpec", "extractField" );
616 
617  try // extract a field that is present (single)
618  {
619  FileSpec spec("test-%4y-spec");
620 
621  string field = spec.extractField("test-1999-spec", FileSpec::year);
622  TUASSERTE(int, 0, field.compare("1999"));
623  }
624  catch (FileSpecException& fse)
625  {
626  ostringstream oss;
627  oss << "unexpected exception: " << fse;
628  TUFAIL(oss.str());
629  }
630 
631  try // extract a field that is present multiple times
632  {
633  FileSpec spec("test-%2y-spec-%2y");
634 
635  string field = spec.extractField("test-97-spec-96", FileSpec::year);
636  TUASSERTE(string, "97", field);
637  }
638  catch (FileSpecException& fse)
639  {
640  ostringstream oss;
641  oss << "unexpected exception: " << fse;
642  TUFAIL(oss.str());
643  }
644 
645  try // extract multiple different fields
646  {
647  FileSpec spec("test-%4y%03j%05s-spec.%3x");
648 
649  string yField = spec.extractField("test-200412312345-spec.pdf",
651  TUASSERTE(string, "2004", yField);
652 
653  string jField = spec.extractField("test-200412312345-spec.pdf",
654  FileSpec::day);
655  TUASSERTE(string, "123", jField);
656 
657  string sField = spec.extractField("test-200412312345-spec.pdf",
658  FileSpec::doysecond);
659  TUASSERTE(string, "12345", sField);
660 
661  string xField = spec.extractField("test-200412312345-spec.pdf",
662  FileSpec::text);
663  TUASSERTE(string, "pdf", xField);
664  }
665  catch (FileSpecException& fse)
666  {
667  ostringstream oss;
668  oss << "unexpected exception: " << fse;
669  TUFAIL(oss.str());
670  }
671 
672  try // extract a field that isn't there
673  {
674  FileSpec spec("test-%y-spec");
675 
676  string field = spec.extractField("test-1999-spec", FileSpec::station);
677  ostringstream oss;
678  oss << "missing expected exception";
679  TUFAIL(oss.str());
680  }
681  catch (FileSpecException& fse)
682  {
683  ostringstream oss;
684  oss << "received expected exception: " << fse;
685  TUPASS(oss.str());
686  }
687 
688  /* // @todo - The following tests currently fail, but it's possible
689  // that things might work better in the future.
690 
691  try // extract fields without explicit width
692  {
693  FileSpec spec("test_%y_%j_%s_spec.%x");
694 
695  string yField = spec.extractField("test_2004_12_345_spec.pdf",
696  FileSpec::year);
697  TUASSERTE(string, "2004", yField);
698 
699  string jField = spec.extractField("test_2004_12_345_spec.pdf",
700  FileSpec::day);
701  TUASSERTE(string, "12", jField);
702 
703  string sField = spec.extractField("test_2004_12_345_spec.pdf",
704  FileSpec::doysecond);
705  TUASSERTE(string, "345", sField);
706 
707  string xField = spec.extractField("test_2004_12_345_spec.pdf",
708  FileSpec::text);
709  TUASSERTE(string, "pdf", xField);
710  }
711  catch (FileSpecException& fse)
712  {
713  ostringstream oss;
714  oss << "unexpected exception: " << fse;
715  TUFAIL(oss.str());
716  }
717  */
718 
719  TURETURN();
720 }
721 
722 
723 //---------------------------------------------------------------------------
725 {
726  TUDEF( "FileSpec", "extractCommonTime" );
727 
728  try // extract a valid time
729  {
730  FileSpec spec("test-%4Y%03j%05s-spec");
731 
732  CommonTime t = spec.extractCommonTime("test-200412312345-spec");
733  YDSTime ydst(2004, 123, 12345.0);
734  TUASSERT(ydst == t);
735  }
736  catch (FileSpecException& fse)
737  {
738  ostringstream oss;
739  oss << "unexpected exception: " << fse;
740  TUFAIL(oss.str());
741  }
742 
743  try // extract an invalid time
744  {
745  FileSpec spec("test-%4Y%03j%05s-spec");
746 
747  CommonTime t = spec.extractCommonTime("test-101043299999-spec");
748  TUFAIL("expected exception for invalid time");
749  }
750  catch (FileSpecException& fse)
751  {
752  ostringstream oss;
753  oss << "expected exception for invalid time: " << fse;
754  TUPASS(oss.str());
755  }
756 
757 /* This test would have worked with the old DayTime implementation,
758  * however CommonTime performs no such checks.
759 
760  try // extract an incomplete time
761  {
762  FileSpec spec("test-%4Y-%05s-spec");
763 
764  CommonTime t = spec.extractCommonTime("test-1999-12345-spec");
765  TUFAIL("expected exception for incomplete time");
766  }
767  catch (FileSpecException& fse)
768  {
769  ostringstream oss;
770  oss << "expected exception for incomplete time: " << fse;
771  TUPASS(oss.str());
772  }
773 */
774 
775  try // extract a missing time
776  {
777  FileSpec spec("test-%4Y%03j%05s-spec");
778 
779  CommonTime t = spec.extractCommonTime("test-spec");
780  TUFAIL("expected exception for missing time");
781  }
782  catch (FileSpecException& fse)
783  {
784  ostringstream oss;
785  oss << "expected exception for missing time: " << fse;
786  TUPASS(oss.str());
787  }
788 
789 /* Really? Was it ever requried that a FileSpec have a time?
790  try // extract from a time-less spec
791  {
792  FileSpec spec("test-%2p-%2r-spec");
793 
794  CommonTime t = spec.extractCommonTime("test-24-01-spec");
795  TUFAIL("expected exception for missing time in spec");
796  }
797  catch (FileSpecException& fse)
798  {
799  ostringstream oss;
800  oss << "expected exception for missing time in spec: " << fse;
801  TUPASS(oss.str());
802  }
803 */
804 
805  TURETURN();
806 }
807 
808 
809 //---------------------------------------------------------------------------
811 {
813  TUDEF( "FileSpec", "toString" );
814 
815  try // default GPSWeekZcount
816  {
817  FileSpec spec("test-%04F%06Z-spec");
818 
819  GPSWeekZcount wz;
820  CommonTime t(wz);
821  string str = spec.toString(t);
822  TUASSERTE(string, "test-0000000000-spec", str);
823  }
824  catch (FileSpecException& fse)
825  {
826  ostringstream oss;
827  oss << "unexpected exception: " << fse;
828  TUFAIL(oss.str());
829  }
830 
831  try // non-default GPSWeekZcount
832  {
833  FileSpec spec("test-%04F%06Z-spec");
834 
835  GPSWeekZcount wz(1234,56789);
836  CommonTime t(wz);
837  string str = spec.toString(t);
838  TUASSERTE(string, "test-1234056789-spec", str);
839  }
840  catch (FileSpecException& fse)
841  {
842  ostringstream oss;
843  oss << "unexpected exception: " << fse;
844  TUFAIL(oss.str());
845  }
846 
847  try // non-default GPSWeekZcount plus missing other stuff
848  {
849  FileSpec spec("test-%04F%06Z-%p-%n-%k-%I-spec");
850 
851  GPSWeekZcount wz(1234,56789);
852  CommonTime t(wz);
853  string str = spec.toString(t);
854  TUASSERTE(string, "test-1234056789-%1p-%1n-%1k-%1I-spec", str);
855  }
856  catch (FileSpecException& fse)
857  {
858  ostringstream oss;
859  oss << "unexpected exception: " << fse;
860  TUFAIL(oss.str());
861  }
862 
863  try // non-default GPSWeekZcount plus supplied other stuff
864  {
865  FileSpec spec("test-%04F%06Z-%02p-%05n-%02r-%02k-spec");
866 
867  GPSWeekZcount wz(1234,56789);
868  CommonTime t(wz);
870  stuff[FileSpec::prn] = "12";
871  stuff[FileSpec::station] = "96344";
872  stuff[FileSpec::receiver] = "1";
873  stuff[FileSpec::clock] = "1";
874  string str = spec.toString(t, stuff);
875  TUASSERTE(string, "test-1234056789-12-96344-01-01-spec", str);
876  }
877  catch (FileSpecException& fse)
878  {
879  ostringstream oss;
880  oss << "unexpected exception: " << fse;
881  TUFAIL(oss.str());
882  }
883 
884  try // test the text type
885  {
886  GPSWeekZcount wz(1234,56789); // dummy time
887  CommonTime t(wz);
888 
889  FileSpec spec0("test%x");
890  FileSpec spec1("test%1x");
891  FileSpec spec2("test%2x");
892 
894  string str;
895 
896  // empty text
897  stuff[FileSpec::text] = "";
898  str = spec0.toString(t, stuff);
899  TUASSERTE(string, "test", str); // 0 == width == size
900  str = spec1.toString(t, stuff);
901  TUASSERTE(string, "test ", str); // width > size == 0
902  str = spec2.toString(t, stuff);
903  TUASSERTE(string, "test ", str); // width > size == 0
904 
905  // short text
906  stuff[FileSpec::text] = "A";
907  str = spec0.toString(t, stuff);
908  TUASSERTE(string, "testA", str); // 0 == width < size
909  str = spec1.toString(t, stuff);
910  TUASSERTE(string, "testA", str); // width == size
911  str = spec2.toString(t, stuff);
912  TUASSERTE(string, "testA ", str); // width > size
913 
914  // long text
915  stuff[FileSpec::text] = "ABCD";
916  str = spec0.toString(t, stuff);
917  TUASSERTE(string, "testABCD", str); // 0 == width < size
918  str = spec1.toString(t, stuff);
919  TUASSERTE(string, "testA", str); // width < size
920  str = spec2.toString(t, stuff);
921  TUASSERTE(string, "testAB", str); // width < size
922  }
923  catch (FileSpecException& fse)
924  {
925  ostringstream oss;
926  oss << "unexpected exception: " << fse;
927  TUFAIL(oss.str());
928  }
929 
931 /*
932  try // default CommonTime
933  {
934  FileSpec spec("test-%04Y%03j%05.0s-spec");
935 
936  CommonTime t;
937  string str = spec.toString(t);
938  testFramework.assert( (str.compare("test-000000000000-spec") == 0),
939  "toString failed: " + str);
940  }
941  catch (FileSpecException& fse)
942  {
943  ostringstream oss;
944  oss << "unexpected exception: " << fse;
945  TUFAIL(oss.str());
946  }
947 
948  try // non-default CommonTime
949  {
950  FileSpec spec("test-%04Y%03j%05.0s-spec");
951 
952  YDSTime ydst(1991, 234, 23456);
953  string str = spec.toString(ydst);
954  testFramework.assert( (str.compare("test-199123423456-spec") == 0),
955  "toString failed: " + str);
956  }
957  catch (FileSpecException& fse)
958  {
959  ostringstream oss;
960  oss << "unexpected exception: " << fse;
961  TUFAIL(oss.str());
962  }
963 
964  try // non-default CommonTime plus missing other stuff
965  {
966  FileSpec spec("test-%04Y%03j%05.0s-%p-%n-%k-spec");
967 
968  YDSTime ydst(1991, 234, 23456);
969  string str = spec.toString(ydst);
970  testFramework.assert( (str.compare("test-199123423456-spec") == 0),
971  "toString failed: " + str);
972  }
973  catch (FileSpecException& fse)
974  {
975  ostringstream oss;
976  oss << "unexpected exception: " << fse;
977  TUFAIL(oss.str());
978  }
979 
980  try // non-default CommonTime plus supplied other stuff
981  {
982  FileSpec spec("test-%04Y%03j%05.0s-%02p-%05n-%02r-%02k-spec");
983 
984  YDSTime ydst(1991, 234, 23456);
985  FileSpec::FSTStringMap stuff;
986  stuff[FileSpec::prn] = "12";
987  stuff[FileSpec::station] = "96344";
988  stuff[FileSpec::receiver] = "1";
989  stuff[FileSpec::clock] = "1";
990  string str = spec.toString(ydst, stuff);
991  testFramework.assert( (str.compare("test-199123423456-12-96344-01-01-spec") == 0),
992  "toString failed: " + str);
993  }
994  catch (FileSpecException& fse)
995  {
996  ostringstream oss;
997  oss << "unexpected exception: " << fse;
998  TUFAIL(oss.str());
999  }
1000 */
1001 
1002  TURETURN();
1003 }
1004 
1005 
1006 //---------------------------------------------------------------------------
1008 {
1009  TUDEF( "FileSpec", "sortList" );
1010 
1011  try // sort an empty list
1012  {
1013  FileSpec spec("test-%04Y%03j%05s-%p-%n-%r-%k-spec");
1014  vector<string> fileList;
1015  spec.sortList(fileList);
1016  TUASSERT(fileList.empty());
1017  }
1018  catch (FileSpecException& fse)
1019  {
1020  ostringstream oss;
1021  oss << "unexpected exception: " << fse;
1022  TUFAIL(oss.str());
1023  }
1024 
1025  try // sort a list with one element
1026  {
1027  FileSpec spec("test-%04Y%03j%05s-%p-%n-%r-%k-spec");
1028  vector<string> fileList;
1029  fileList.push_back("test-1997020030000-23-96344-1-1-spec");
1030  spec.sortList(fileList);
1031  TUASSERTE(vector<string>::size_type, 1, fileList.size());
1032  TUASSERTE(string, "test-1997020030000-23-96344-1-1-spec", fileList[0]);
1033  }
1034  catch (FileSpecException& fse)
1035  {
1036  ostringstream oss;
1037  oss << "unexpected exception: " << fse;
1038  TUFAIL(oss.str());
1039  }
1040 
1041  try // sort a list with several elements differentiated only by time
1042  {
1043  // This only ever worked because the prn, station, receiver
1044  // and clock were all the same. You really need to specify
1045  // the length of the fields.
1048  //FileSpec spec("test-%04Y%03j%05s-%p-%n-%r-%k-spec");
1049  FileSpec spec("test-%04Y%03j%05s-%02p-%05n-%1r-%1k-spec");
1050 
1051  vector<string> sortedFileList;
1052  // YYYYDDDSSSSS PP NNNNN R K
1053  sortedFileList.push_back("test-199702001000-23-96344-1-1-spec");
1054  sortedFileList.push_back("test-199702003000-23-96344-1-1-spec");
1055  sortedFileList.push_back("test-199703003000-23-96344-1-1-spec");
1056  sortedFileList.push_back("test-199802003000-23-96344-1-1-spec");
1057  sortedFileList.push_back("test-199803003000-23-96344-1-1-spec");
1058  sortedFileList.push_back("test-199902003000-23-96344-1-1-spec");
1059  vector<string> fileList;
1060  fileList.push_back(sortedFileList[4]);
1061  fileList.push_back(sortedFileList[0]);
1062  fileList.push_back(sortedFileList[2]);
1063  fileList.push_back(sortedFileList[5]);
1064  fileList.push_back(sortedFileList[1]);
1065  fileList.push_back(sortedFileList[3]);
1066  spec.sortList(fileList);
1067  TUASSERT(equal(fileList.begin(), fileList.end(), sortedFileList.begin()));
1068  }
1069  catch (FileSpecException& fse)
1070  {
1071  ostringstream oss;
1072  oss << "unexpected exception: " << fse;
1073  TUFAIL(oss.str());
1074  }
1075 
1076  // sort a list with several elements differentiated by non-time
1077  // elements
1078  try
1079  {
1080  FileSpec spec("test-%04Y%03j%05s-%02p-%05n-%02r-%02k-spec");
1081 
1082  vector<string> sortedFileList;
1083  // index
1084  // v v v1 v vv 2v vv v3 v
1085  // 01234567890123456789012345678901234567
1086  // ("test-199702001000-13-96344-01-01-spec");
1087  // field sort order and name
1088  // 4 6 7 8 3 1 2 5 4
1089  // fixd YYYYDDDSSSSS PP NNNNN RR KKfixed
1090  sortedFileList.push_back("test-199702001000-13-96344-01-01-spec");
1091  sortedFileList.push_back("test-199702001000-23-96344-01-01-spec");
1092  sortedFileList.push_back("test-199702001000-13-96344-02-02-spec");
1093  sortedFileList.push_back("test-199702001000-23-96344-02-01-spec");
1094  sortedFileList.push_back("test-199702001000-13-96346-01-01-spec");
1095  sortedFileList.push_back("test-199702001000-13-96346-01-02-spec");
1096  sortedFileList.push_back("test-199702001000-13-96347-01-01-spec");
1097  sortedFileList.push_back("test-199702001000-23-96347-01-01-spec");
1098  sortedFileList.push_back("test-199702001000-13-96347-02-01-spec");
1099  vector<string> fileList;
1100  fileList.push_back(sortedFileList[8]);
1101  fileList.push_back(sortedFileList[4]);
1102  fileList.push_back(sortedFileList[1]);
1103  fileList.push_back(sortedFileList[6]);
1104  fileList.push_back(sortedFileList[0]);
1105  fileList.push_back(sortedFileList[2]);
1106  fileList.push_back(sortedFileList[5]);
1107  fileList.push_back(sortedFileList[7]);
1108  fileList.push_back(sortedFileList[3]);
1109  spec.sortList(fileList);
1110  TUASSERT(equal(fileList.begin(), fileList.end(), sortedFileList.begin()));
1111  }
1112  catch (FileSpecException& fse)
1113  {
1114  ostringstream oss;
1115  oss << "unexpected exception: " << fse;
1116  TUFAIL(oss.str());
1117  }
1118 
1119  TURETURN();
1120 }
1121 
1122 
1123 unsigned FileSpec_T ::
1125 {
1126  TUDEF("FileSpec", "hasTimeField");
1127 
1128  try
1129  {
1130  for (unsigned i = gnsstk::FileSpec::unknown; i < gnsstk::FileSpec::end; i++)
1131  {
1132  // Skip unknown and fixed.
1134  continue;
1135  // FileSpecType enums are expected to be "separated" into
1136  // two groups, the first group being the non-time fields
1137  // and the second group being nothing but time fields. So
1138  // we expect hasTimeField to return true for all enums >=
1139  // firstTime.
1141  string specString = "Some-junk-%" +
1143  gnsstk::FileSpec fs(specString);
1145  }
1146  }
1147  catch (gnsstk::Exception& exc)
1148  {
1149  cerr << exc << endl;
1150  TUFAIL("Unexpected exception");
1151  }
1152  catch (std::exception& exc)
1153  {
1154  cerr << exc.what() << endl;
1155  TUFAIL("Unexpected exception");
1156  }
1157  catch (...)
1158  {
1159  TUFAIL("Unknown exception");
1160  }
1161  TURETURN();
1162 }
1163 
1164 
1169 int main(int argc, char *argv[])
1170 {
1171  int errorTotal = 0;
1172 
1173  FileSpec_T testClass;
1174 
1175  errorTotal += testClass.testConvertFileSpecType();
1176  errorTotal += testClass.testFileSpecTypeOps();
1177  errorTotal += testClass.testInitInvalid();
1178  errorTotal += testClass.testInitValid();
1179  errorTotal += testClass.testNewSpec();
1180  errorTotal += testClass.testHasField();
1181  errorTotal += testClass.testGetSpecString();
1182  errorTotal += testClass.testCreateSearchString();
1183  errorTotal += testClass.testExtractField();
1184  errorTotal += testClass.testExtractCommonTime();
1185  errorTotal += testClass.testToString();
1186  errorTotal += testClass.testSortList();
1187  errorTotal += testClass.testHasTimeField();
1188 
1189  cout << "Total Failures for " << __FILE__ << ": " << errorTotal << endl;
1190 
1191  return errorTotal;
1192 }
gnsstk::FileSpec::FSTStringMap
std::map< FileSpecType, std::string > FSTStringMap
Definition: FileSpec.hpp:136
GPSWeekZcount.hpp
FileSpec_T::testGetSpecString
unsigned testGetSpecString()
Definition: FileSpec_T.cpp:519
YDSTime.hpp
example6.day
day
Definition: example6.py:66
FileSpec_T::testCreateSearchString
unsigned testCreateSearchString()
Definition: FileSpec_T.cpp:552
FileSpec_T::~FileSpec_T
~FileSpec_T()
Definition: FileSpec_T.cpp:58
example6.year
year
Definition: example6.py:64
gnsstk::YDSTime
Definition: YDSTime.hpp:58
FileSpec_T::testConvertFileSpecType
unsigned testConvertFileSpecType()
Definition: FileSpec_T.cpp:127
TUASSERTE
#define TUASSERTE(TYPE, EXP, GOT)
Definition: TestUtil.hpp:81
gnsstk::FileSpec::hasTimeField
bool hasTimeField() const
Return true if this FileSpec has any time fields.
Definition: FileSpec.hpp:194
TUFAIL
#define TUFAIL(MSG)
Definition: TestUtil.hpp:228
FileSpec_T::testNewSpec
unsigned testNewSpec()
Definition: FileSpec_T.cpp:442
gnsstk::FileSpec::end
@ end
A place holder for the end of this list.
Definition: FileSpec.hpp:131
main
int main(int argc, char *argv[])
Definition: FileSpec_T.cpp:1169
FileSpec_T::testSortList
unsigned testSortList()
Definition: FileSpec_T.cpp:1007
gnsstk
For Sinex::InputHistory.
Definition: BasicFramework.cpp:50
gnsstk::FileSpec::unknown
@ unknown
Unknown type.
Definition: FileSpec.hpp:95
gnsstk::FileSpec
Definition: FileSpec.hpp:80
gnsstk::Exception
Definition: Exception.hpp:151
gnsstk::FileSpec::firstTime
@ firstTime
First enumeration value pertaining to time.
Definition: FileSpec.hpp:111
TUASSERT
#define TUASSERT(EXPR)
Definition: TestUtil.hpp:63
FileSpec_T::testExtractField
unsigned testExtractField()
Definition: FileSpec_T.cpp:613
TestUtil.hpp
FileSpec.hpp
gnsstk::FileSpec::extractCommonTime
virtual gnsstk::CommonTime extractCommonTime(const std::string &filename) const
Definition: FileSpec.cpp:247
TURETURN
#define TURETURN()
Definition: TestUtil.hpp:232
gnsstk::FileSpec::extractField
virtual std::string extractField(const std::string &filename, const FileSpecType) const
Definition: FileSpec.cpp:216
TUPASS
#define TUPASS(MSG)
Definition: TestUtil.hpp:230
SystemTime.hpp
gnsstk::FileSpec::createSearchString
virtual std::string createSearchString() const
Definition: FileSpec.cpp:184
FileSpec_T
Definition: FileSpec_T.cpp:50
gnsstk::CommonTime
Definition: CommonTime.hpp:84
gnsstk::FileSpec::getSpecString
virtual std::string getSpecString(void) const
Returns the string of the filespec.
Definition: FileSpec.hpp:164
FileSpec_T::testHasField
unsigned testHasField()
Definition: FileSpec_T.cpp:470
gnsstk::FileSpec::hasField
virtual bool hasField(FileSpecType fst) const
Definition: FileSpec.hpp:190
FileSpec_T::testHasTimeField
unsigned testHasTimeField()
Definition: FileSpec_T.cpp:1124
TUDEF
#define TUDEF(CLASS, METHOD)
Definition: TestUtil.hpp:56
gnsstk::glo::str1
@ str1
Definition: GLOFBits.hpp:53
gnsstk::GPSWeekZcount
Definition: GPSWeekZcount.hpp:55
gnsstk::FileSpec::FileSpecType
FileSpecType
Definition: FileSpec.hpp:93
FileSpec_T::testInitInvalid
unsigned testInitInvalid()
Definition: FileSpec_T.cpp:299
FileSpec_T::testExtractCommonTime
unsigned testExtractCommonTime()
Definition: FileSpec_T.cpp:724
FileSpec_T::testInitValid
unsigned testInitValid()
Definition: FileSpec_T.cpp:365
FileSpec_T::init
void init()
Definition: FileSpec_T.cpp:120
gnsstk::FileSpec::toString
virtual std::string toString(const gnsstk::CommonTime &dt, const FSTStringMap &fstsMap=FSTStringMap()) const
Definition: FileSpec.cpp:278
gnsstk::FileSpec::sortList
virtual void sortList(std::vector< std::string > &fileList, const FileSpecSortType fsst=ascending) const
Definition: FileSpec.cpp:336
std
Definition: Angle.hpp:142
gnsstk::FileSpec::fixed
@ fixed
A field for fixed characters.
Definition: FileSpec.hpp:103
FileSpec_T::testToString
unsigned testToString()
Definition: FileSpec_T.cpp:810
FileSpec_T::testFileSpecTypeOps
unsigned testFileSpecTypeOps()
Definition: FileSpec_T.cpp:288
FileSpec_T::FileSpec_T
FileSpec_T()
Definition: FileSpec_T.cpp:55
gnsstk::glo::str2
@ str2
Definition: GLOFBits.hpp:54
gnsstk::FileSpec::newSpec
virtual FileSpec & newSpec(const std::string &fileSpec)
Definition: FileSpec.hpp:160
gnsstk::FileSpec::convertFileSpecType
static std::string convertFileSpecType(const FileSpecType)
Definition: FileSpec.cpp:106


gnsstk
Author(s):
autogenerated on Wed Oct 25 2023 02:40:39