66 unsigned testConvertFileSpecType();
70 unsigned testFileSpecTypeOps();
74 unsigned testInitInvalid();
79 unsigned testInitValid();
83 unsigned testNewSpec();
87 unsigned testHasField();
91 unsigned testGetSpecString();
95 unsigned testCreateSearchString();
99 unsigned testExtractField();
103 unsigned testExtractCommonTime();
107 unsigned testToString();
111 unsigned testSortList();
114 unsigned testHasTimeField();
129 TUDEF(
"FileSpec",
"convertFileSpecType" );
131 set<std::string> fstSet;
134 for ( ; fst < FileSpec::end; fst++)
141 fstStr = FileSpec::convertFileSpecType(fst);
144 oss <<
"duplicate file spec type string: " << fstStr;
145 TUASSERT(fstSet.find(fstStr) == fstSet.end());
148 if (fstStr.size() == 0)
150 if (fst == FileSpec::fixed)
155 TUPASS(
"fixed FileSpecType");
160 oss <<
"empty file spec type string for value: " << fst;
169 oss <<
"file spec type string should be a single character: "
171 TUASSERTE(string::size_type, 1, fstStr.size());
180 if ((fstStr[0] ==
'y') || (fstStr[0] ==
'Y'))
188 oss <<
"special case failed for file spec type: y / Y";
195 case FileSpec::fullzcount:
196 if ((fstStr[0] ==
'c') || (fstStr[0] ==
'C'))
204 oss <<
"special case failed for file spec type: c / C";
210 fstSet.insert(fstStr);
213 catch (FileSpecException& fse)
216 oss <<
"unexpected exception for file spec type value: " << fst;
226 oss <<
"file spec type value/string/value mismatch: "
227 << fst <<
"/" + fstStr +
"/" << fstPost;
231 catch (FileSpecException& fse)
233 TUFAIL(
"unexpected exception for file spec type string: " + fstStr);
244 catch (FileSpecException& fse)
246 TUFAIL(
"unexpected exception for file spec type: y / Y");
256 catch (FileSpecException& fse)
258 TUFAIL(
"unexpected exception for file spec type: c / C");
264 string fstStr = FileSpec::convertFileSpecType(FileSpec::unknown);
265 TUFAIL(
"exception expected for file spec type: unknown");
267 catch (FileSpecException& fse)
269 TUPASS(
"expected exception for invalid FileSpecType");
275 string fstStr = FileSpec::convertFileSpecType(FileSpec::end);
276 TUFAIL(
"exception expected for file spec type: end");
278 catch (FileSpecException& fse)
280 TUPASS(
"expected exception for invalid FileSpecType");
290 TUDEF(
"FileSpecType",
"operators" );
301 TUDEF(
"FileSpec",
"init (invalid)" );
303 const string PCT(
"%");
306 vector<string> invalidSpecs;
308 invalidSpecs.push_back(
"%%");
311 for (
char c =
'A'; c <=
'Z'; ++c)
320 catch (FileSpecException& fse)
323 invalidSpecs.push_back(PCT + s);
326 for (
char c =
'a'; c <=
'z'; ++c)
335 catch (FileSpecException& fse)
338 invalidSpecs.push_back(PCT + s);
343 vector<string>::const_iterator specIter = invalidSpecs.begin();
344 for ( ; specIter != invalidSpecs.end(); ++specIter)
350 oss <<
"missing expected exception creating FileSpec(\""
351 << *specIter <<
"\")";
354 catch (FileSpecException& fse)
356 TUPASS(
"expected exception for invalid FileSpec");
367 TUDEF(
"FileSpec",
"init (valid)" );
372 TUPASS(
"FileSpec created");
374 catch (FileSpecException& fse)
377 oss <<
"exception creating default, empty FileSpec: " << fse;
382 vector<string> validSpecs;
384 const string PCT(
"%");
386 validSpecs.push_back(
"");
387 validSpecs.push_back(
" ");
393 for ( ; fst < FileSpec::end; fst++)
395 string s = FileSpec::convertFileSpecType(fst);
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);
409 validSpecs.push_back(PCT +
"4" + s + PCT +
"12" + s);
410 validSpecs.push_back(PCT +
"-8" + s + PCT +
"06" + s);
420 vector<string>::const_iterator specIter = validSpecs.begin();
421 for ( ; specIter != validSpecs.end(); ++specIter)
426 TUPASS(
"FileSpec created");
428 catch (FileSpecException& fse)
431 oss <<
"exception creating FileSpec(\""
432 << *specIter <<
"\"): " << fse;
444 TUDEF(
"FileSpec",
"newSpec" );
451 string str1(
"test-%y-spec");
455 string str2(
"another-%y-one");
459 catch (FileSpecException& fse)
462 oss <<
"unexpected exception: " << fse;
472 TUDEF(
"FileSpec",
"hasField" );
480 catch (FileSpecException& fse)
483 oss <<
"unexpected exception: " << fse;
489 string str(
"test-%y-spec");
494 catch (FileSpecException& fse)
497 oss <<
"unexpected exception: " << fse;
503 string str(
"test-%p-spec");
508 catch (FileSpecException& fse)
511 oss <<
"unexpected exception: " << fse;
521 TUDEF(
"FileSpec",
"getSpecString" );
528 catch (FileSpecException& fse)
531 oss <<
"unexpected exception: " << fse;
537 string str(
"test-%y-spec");
541 catch (FileSpecException& fse)
544 oss <<
"unexpected exception: " << fse;
554 TUDEF(
"FileSpec",
"createSearchString" );
561 catch (FileSpecException& fse)
564 oss <<
"unexpected exception: " << fse;
570 string str(
"test-spec");
574 catch (FileSpecException& fse)
577 oss <<
"unexpected exception: " << fse;
583 string str(
"test-%y-spec");
584 string expect(
"test-?-spec");
588 catch (FileSpecException& fse)
591 oss <<
"unexpected exception: " << fse;
597 string str(
"test-%y-spec-%y.%y");
598 string expect(
"test-?-spec-?.?");
602 catch (FileSpecException& fse)
605 oss <<
"unexpected exception: " << fse;
615 TUDEF(
"FileSpec",
"extractField" );
622 TUASSERTE(
int, 0, field.compare(
"1999"));
624 catch (FileSpecException& fse)
627 oss <<
"unexpected exception: " << fse;
638 catch (FileSpecException& fse)
641 oss <<
"unexpected exception: " << fse;
647 FileSpec spec(
"test-%4y%03j%05s-spec.%3x");
649 string yField = spec.
extractField(
"test-200412312345-spec.pdf",
653 string jField = spec.
extractField(
"test-200412312345-spec.pdf",
657 string sField = spec.
extractField(
"test-200412312345-spec.pdf",
658 FileSpec::doysecond);
661 string xField = spec.
extractField(
"test-200412312345-spec.pdf",
665 catch (FileSpecException& fse)
668 oss <<
"unexpected exception: " << fse;
676 string field = spec.
extractField(
"test-1999-spec", FileSpec::station);
678 oss <<
"missing expected exception";
681 catch (FileSpecException& fse)
684 oss <<
"received expected exception: " << fse;
726 TUDEF(
"FileSpec",
"extractCommonTime" );
730 FileSpec spec(
"test-%4Y%03j%05s-spec");
733 YDSTime ydst(2004, 123, 12345.0);
736 catch (FileSpecException& fse)
739 oss <<
"unexpected exception: " << fse;
745 FileSpec spec(
"test-%4Y%03j%05s-spec");
748 TUFAIL(
"expected exception for invalid time");
750 catch (FileSpecException& fse)
753 oss <<
"expected exception for invalid time: " << fse;
777 FileSpec spec(
"test-%4Y%03j%05s-spec");
780 TUFAIL(
"expected exception for missing time");
782 catch (FileSpecException& fse)
785 oss <<
"expected exception for missing time: " << fse;
813 TUDEF(
"FileSpec",
"toString" );
817 FileSpec spec(
"test-%04F%06Z-spec");
822 TUASSERTE(
string,
"test-0000000000-spec", str);
824 catch (FileSpecException& fse)
827 oss <<
"unexpected exception: " << fse;
833 FileSpec spec(
"test-%04F%06Z-spec");
838 TUASSERTE(
string,
"test-1234056789-spec", str);
840 catch (FileSpecException& fse)
843 oss <<
"unexpected exception: " << fse;
849 FileSpec spec(
"test-%04F%06Z-%p-%n-%k-%I-spec");
854 TUASSERTE(
string,
"test-1234056789-%1p-%1n-%1k-%1I-spec", str);
856 catch (FileSpecException& fse)
859 oss <<
"unexpected exception: " << fse;
865 FileSpec spec(
"test-%04F%06Z-%02p-%05n-%02r-%02k-spec");
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);
877 catch (FileSpecException& fse)
880 oss <<
"unexpected exception: " << fse;
897 stuff[FileSpec::text] =
"";
906 stuff[FileSpec::text] =
"A";
915 stuff[FileSpec::text] =
"ABCD";
923 catch (FileSpecException& fse)
926 oss <<
"unexpected exception: " << fse;
1009 TUDEF(
"FileSpec",
"sortList" );
1013 FileSpec spec(
"test-%04Y%03j%05s-%p-%n-%r-%k-spec");
1014 vector<string> fileList;
1018 catch (FileSpecException& fse)
1021 oss <<
"unexpected exception: " << fse;
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");
1031 TUASSERTE(vector<string>::size_type, 1, fileList.size());
1032 TUASSERTE(
string,
"test-1997020030000-23-96344-1-1-spec", fileList[0]);
1034 catch (FileSpecException& fse)
1037 oss <<
"unexpected exception: " << fse;
1049 FileSpec spec(
"test-%04Y%03j%05s-%02p-%05n-%1r-%1k-spec");
1051 vector<string> sortedFileList;
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]);
1067 TUASSERT(equal(fileList.begin(), fileList.end(), sortedFileList.begin()));
1069 catch (FileSpecException& fse)
1072 oss <<
"unexpected exception: " << fse;
1080 FileSpec spec(
"test-%04Y%03j%05s-%02p-%05n-%02r-%02k-spec");
1082 vector<string> sortedFileList;
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]);
1110 TUASSERT(equal(fileList.begin(), fileList.end(), sortedFileList.begin()));
1112 catch (FileSpecException& fse)
1115 oss <<
"unexpected exception: " << fse;
1126 TUDEF(
"FileSpec",
"hasTimeField");
1141 string specString =
"Some-junk-%" +
1149 cerr << exc << endl;
1150 TUFAIL(
"Unexpected exception");
1152 catch (std::exception& exc)
1154 cerr << exc.what() << endl;
1155 TUFAIL(
"Unexpected exception");
1159 TUFAIL(
"Unknown exception");
1189 cout <<
"Total Failures for " << __FILE__ <<
": " << errorTotal << endl;