00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <iostream>
00016
00017 static const char* list[]={
00018 "ru_001.wav", "ru_002.wav", "ru_003.wav",
00019 "ru_004.wav", "ru_005.wav", NULL
00020 };
00021
00022 static const char* list_non_uniform_format[]={
00023 "ru_001.wav", "ru_2.wav", "ru_003.wav",
00024 "ru_004.wav", "ru_005.wav", NULL
00025 };
00026
00027 static const char* list_with_gaps []={
00028 "ru_001.wav", "gap", "ru_003.wav",
00029 "ru_004.wav", "gap", "ru_006.wav", NULL
00030 };
00031
00032 static const char* list_bad_format []={
00033 "ru_001.wav", "en_002.wav", "ru_003.wav",
00034 "ru_004.wav", "", "ru_006.wav", NULL
00035 };
00036
00037
00038
00039
00040 int main()
00041 {
00042 int i;
00043 string format;
00044 vector<string> v;
00045
00046 cout << '\n' << "Testing parse_format() ...";
00047
00048 i = 0;
00049 while (list [i]) { v.push_back (list [i++]); }
00050
00051 format = parse_format ("ru_", v);
00052 if (format != "%03d") {
00053 cout << "failed valid list\n";
00054 cout << "(expected \"%03\", returned \"" << format << "\"\n\n";
00055 return 1;
00056 }
00057
00058 v.clear ();
00059 i = 0;
00060 while (list_with_gaps [i]) { v.push_back (list_with_gaps [i++]); }
00061
00062 format = parse_format ("ru_", v);
00063 if (format != "%03d") {
00064 cout << "failed list with gaps\n";
00065 return 1;
00066 }
00067
00068 v.clear ();
00069 i = 0;
00070 while (list_non_uniform_format [i]) {
00071 v.push_back (list_non_uniform_format [i++]);
00072 }
00073
00074 format = parse_format ("ru_", v);
00075 if (format != "%d") {
00076 cout << "failed list with non-uniform format\n";
00077 cout << "(expected \"\", returned \"" << format << "\"\n\n";
00078 return 1;
00079 }
00080 v.clear ();
00081
00082 i = 0;
00083 while (list_bad_format [i]) {
00084 v.push_back (list_bad_format [i++]);
00085 }
00086
00087 format = parse_format ("ru_", v);
00088 if (format != "") {
00089 cout << "failed list with bad format\n";
00090 cout << "(expected \"\", returned \"" << format << "\"\n\n";
00091 return 1;
00092 }
00093 cout << "ok\n";
00094
00095 cout << "\nTesting parse_seq_num() ";
00096 string res;
00097 string name;
00098 name = "ru_00034.wav";
00099 res = parse_seq_number (name, "ru_");
00100 if (res != "00034") {
00101 cout << "failed (expected \"00034\", returned \"" << res << "\"\n\n";
00102 return 1;
00103 }
00104 res = parse_seq_number (name, "en_");
00105 if (res != "") {
00106 cout << "failed (expected \"\", returned \"" << res << "\"\n\n";
00107 return 1;
00108 }
00109 name = "ru_0999";
00110 res = parse_seq_number (name, "ru_");
00111 if (res != "") {
00112 cout << "failed (expected \"\", returned \"" << res << "\"\n\n";
00113 return 1;
00114 }
00115 name = "ru_0999.wav";
00116 res = parse_seq_number (name, "ru_");
00117 if (res != "0999") {
00118 cout << "failed (expected \"0999\", returned \"" << res << "\"\n\n";
00119 return 1;
00120 }
00121 cout << "ok\n";
00122
00123 cout << "\nTesting format_seqnum () ";
00124 res = format_seqnum (54, "%03d");
00125 if (res != "054") {
00126 cout << "failed (expected \"054\", returned \"" << res << "\"\n\n";
00127 return 1;
00128 }
00129
00130 res = format_seqnum (54, "%d");
00131 if (res != "54") {
00132 cout << "failed (expected \"54\", returned \"" << res << "\"\n\n";
00133 return 1;
00134 }
00135 cout << "ok\n";
00136
00137 cout << "\nTesting make_name_with_offset () ";
00138 string dirpath ("/English/Test/");
00139 format = "%04d";
00140 name = "ru_0999.wav";
00141 res = make_name_with_offset (name, format, "ru_", dirpath, 0);
00142
00143 if (res != dirpath + "ru_0999.wav") {
00144 cout << "failed\n\t(expected \"/English/Test/ru_0999.wav\""
00145 << ", returned \"" << res << "\")\n\n";
00146 return 1;
00147 }
00148 cout << "ok\n";
00149
00150 cout << "\nTesting make_prev_name () ";
00151 res = make_prev_name (name, format, "ru_", dirpath);
00152 if (res != dirpath + "ru_0998.wav") {
00153 cout << "failed\n\t(expected \"/English/Test/ru_0998.wav\""
00154 << ", returned \"" << res << "\")\n\n";
00155 return 1;
00156 }
00157 res.erase (0, dirpath.length ());
00158 name = res;
00159 res = make_prev_name (name, format, "ru_", dirpath);
00160 if (res != dirpath + "ru_0997.wav") {
00161 cout << "failed\n\t(expected \"/English/Test/ru_0997.wav\""
00162 << ", returned \"" << res << "\")\n\n";
00163 return 1;
00164 }
00165 cout << "ok\n";
00166
00167 cout << "\n";
00168 }
00169
00170