Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

/home/vlg/develop/gwavmerger/tests/test.cpp File Reference

Go to the source code of this file.

Functions

string parse_format (const string &prefix_, vector< string > &vs_)
string parse_seq_number (const string &name_, const string &prefix_)
string format_seqnum (int seqnum_, const string &fmt_)
string make_name_with_offset (const string &name_, const string &fmt_, const string &prefix_, const string &dirpath_, int offset_)
string make_prev_name (const string &name_, const string &fmt_, const string &prefix_, const string &dirpath_)
string make_next_name (const string &name_, const string &fmt_, const string &prefix_, const string &dirpath_)
int main ()

Variables

const char * list []
const char * list_non_uniform_format []
const char * list_with_gaps []
const char * list_bad_format []


Function Documentation

string format_seqnum int    seqnum_,
const string &    fmt_
 

Definition at line 124 of file test.cpp.

Referenced by main, and make_name_with_offset.

00125 {
00126     char buf [PATH_MAX];
00127 
00128     snprintf (buf, PATH_MAX, fmt_.c_str (), seqnum_);
00129     return string (buf);
00130 }

int main  
 

Definition at line 212 of file test.cpp.

References format_seqnum, list, list_bad_format, list_non_uniform_format, list_with_gaps, make_name_with_offset, make_prev_name, parse_format, and parse_seq_number.

00213 {
00214     int i;
00215     string format;
00216     vector<string> v;
00217 
00218     cout << '\n' << "Testing parse_format() ...";
00219 
00220     i = 0;
00221     while (list [i]) { v.push_back (list [i++]); }
00222 
00223     format = parse_format ("ru_", v);
00224     if (format != "%03d") {
00225         cout << "failed valid list\n";
00226         cout << "(expected \"%03\", returned \"" << format << "\"\n\n";
00227         return 1;
00228     }
00229     
00230     v.clear ();
00231     i = 0;
00232     while (list_with_gaps [i]) { v.push_back (list_with_gaps [i++]); }
00233 
00234     format = parse_format ("ru_", v);
00235     if (format != "%03d") {
00236         cout << "failed list with gaps\n";
00237         return 1;
00238     }
00239 
00240     v.clear ();
00241     i = 0;
00242     while (list_non_uniform_format [i]) { 
00243         v.push_back (list_non_uniform_format [i++]); 
00244     }
00245 
00246     format = parse_format ("ru_", v);
00247     if (format != "%d") {
00248         cout << "failed list with non-uniform format\n";
00249         cout << "(expected \"\", returned \"" << format << "\"\n\n";
00250         return 1;
00251     }
00252     v.clear ();
00253 
00254     i = 0;
00255     while (list_bad_format [i]) { 
00256         v.push_back (list_bad_format [i++]); 
00257     }
00258 
00259     format = parse_format ("ru_", v);
00260     if (format != "") {
00261         cout << "failed list with bad format\n";
00262         cout << "(expected \"\", returned \"" << format << "\"\n\n";
00263         return 1;
00264     }
00265     cout << "ok\n";
00266 
00267     cout << "\nTesting parse_seq_num() ";
00268     string res;
00269     string name;
00270     name = "ru_00034.wav";
00271     res = parse_seq_number (name, "ru_");
00272     if (res != "00034") {
00273         cout << "failed (expected \"00034\", returned \"" << res << "\"\n\n";
00274         return 1;
00275     }
00276     res = parse_seq_number (name, "en_");
00277     if (res != "") {
00278         cout << "failed (expected \"\", returned \"" << res << "\"\n\n";
00279         return 1;
00280     }
00281     name = "ru_0999";
00282     res = parse_seq_number (name, "ru_");
00283     if (res != "") {
00284         cout << "failed (expected \"\", returned \"" << res << "\"\n\n";
00285         return 1;
00286     }
00287     name = "ru_0999.wav";
00288     res = parse_seq_number (name, "ru_");
00289     if (res != "0999") {
00290         cout << "failed (expected \"0999\", returned \"" << res << "\"\n\n";
00291         return 1;
00292     }
00293     cout << "ok\n";
00294 
00295     cout << "\nTesting format_seqnum () ";
00296     res = format_seqnum (54, "%03d");
00297     if (res != "054") {
00298         cout << "failed (expected \"054\", returned \"" << res << "\"\n\n";
00299         return 1;
00300     }
00301 
00302     res = format_seqnum (54, "%d");
00303     if (res != "54") {
00304         cout << "failed (expected \"54\", returned \"" << res << "\"\n\n";
00305         return 1;
00306     }
00307     cout << "ok\n";
00308 
00309     cout << "\nTesting make_name_with_offset () ";
00310     string dirpath ("/English/Test/");
00311     format = "%04d";
00312     name = "ru_0999.wav";
00313     res = make_name_with_offset (name, format, "ru_", dirpath, 0);
00314 
00315     if (res != dirpath + "ru_0999.wav") {
00316         cout << "failed\n\t(expected \"/English/Test/ru_0999.wav\""
00317              << ", returned \"" << res << "\")\n\n";
00318         return 1;
00319     }
00320     cout << "ok\n";
00321 
00322     cout << "\nTesting make_prev_name () ";
00323     res = make_prev_name (name, format, "ru_", dirpath);
00324     if (res != dirpath + "ru_0998.wav") {
00325         cout << "failed\n\t(expected \"/English/Test/ru_0998.wav\""
00326              << ", returned \"" << res << "\")\n\n";
00327         return 1;
00328     }
00329     res.erase (0, dirpath.length ());
00330     name = res;
00331     res = make_prev_name (name, format, "ru_", dirpath);
00332     if (res != dirpath + "ru_0997.wav") {
00333         cout << "failed\n\t(expected \"/English/Test/ru_0997.wav\""
00334              << ", returned \"" << res << "\")\n\n";
00335         return 1;
00336     }
00337     cout << "ok\n";
00338 
00339     cout << "\n";
00340 }

string make_name_with_offset const string &    name_,
const string &    fmt_,
const string &    prefix_,
const string &    dirpath_,
int    offset_
 

Definition at line 141 of file test.cpp.

References format_seqnum, and parse_seq_number.

Referenced by main, make_next_name, and make_prev_name.

00144 {
00145     string s (name_);
00146     string::size_type idx;
00147 
00148     cout << '\n';
00149     s = parse_seq_number (s, prefix_);
00150     cout << "\tparsed sequence number: " << s << '\n';
00151     if (s.length () == 0) {
00152         return s;
00153     }
00154     return (dirpath_ + prefix_ 
00155             + format_seqnum (atoi (s.c_str ()) + offset_, fmt_) 
00156             + string (".wav"));
00157 }

string make_next_name const string &    name_,
const string &    fmt_,
const string &    prefix_,
const string &    dirpath_
 

Definition at line 181 of file test.cpp.

References make_name_with_offset.

Referenced by ActionsMenu::shift.

00183 {
00184     return make_name_with_offset (name_, fmt_, prefix_, dirpath_, +1);
00185 }

string make_prev_name const string &    name_,
const string &    fmt_,
const string &    prefix_,
const string &    dirpath_
 

Definition at line 167 of file test.cpp.

References make_name_with_offset.

Referenced by main, and ActionsMenu::shift.

00169 {
00170     return make_name_with_offset (name_, fmt_, prefix_, dirpath_, -1);
00171 }

string parse_format const string &    prefix_,
vector< string > &    vs_
 

Definition at line 38 of file test.cpp.

References parse_seq_number.

Referenced by main, and ActionsMenu::shift.

00039 {
00040     string ret;
00041     int i = 0;
00042     bool is_varlen = false;
00043     int len = 0;
00044     bool is_numeric = true;
00045     string name;
00046 
00047     vector<string>::const_iterator cit = vs_.begin ();
00048     name = parse_seq_number (*cit, prefix_);
00049 
00050     if ((len = name.length ()) == 0) {
00051         return ret;
00052     }
00053 
00054     while (cit != vs_.end ()) {
00055         if (*cit != "gap") {
00056             name = parse_seq_number (*cit, prefix_);
00057             if (name.length () == 0) {
00058                 return ret;
00059             }
00060             i = strtol (name.c_str (), (char **) NULL, 10);
00061             if (i == LONG_MIN || i == LONG_MAX) {
00062                 is_numeric = false;
00063                 break;
00064             }
00065             if (name.length () != len) {
00066                 is_varlen = true;
00067             }
00068         }
00069         cit++;
00070     }
00071     if (is_numeric) {
00072         if (!is_varlen) {
00073             ostringstream os;
00074             os << "%0" << len << "d";
00075             ret = os.str ();
00076         }
00077         else {
00078             ret = "%d";
00079         }
00080     }
00081     return ret;
00082 }

string parse_seq_number const string &    name_,
const string &    prefix_
 

Definition at line 98 of file test.cpp.

Referenced by main, make_name_with_offset, and parse_format.

00099 {
00100     string s (name_);
00101     string::size_type idx = string::npos;
00102 
00103     if ((idx = s.find (prefix_)) == 0) {
00104         s.erase (0, prefix_.length ());
00105         idx = s.find ('.');
00106         if (idx != string::npos) {
00107             if (s.substr (idx) == ".wav") {
00108                 s.replace (idx, name_.size (), "");
00109                 return s;
00110             }
00111         }
00112     }
00113     return ("");
00114 }


Variable Documentation

const char* list[] [static]
 

Initial value:

{ 
    "ru_001.wav", "ru_002.wav", "ru_003.wav", 
    "ru_004.wav", "ru_005.wav", NULL 
}

Definition at line 189 of file test.cpp.

Referenced by main.

const char* list_bad_format[] [static]
 

Initial value:

{ 
    "ru_001.wav", "en_002.wav", "ru_003.wav", 
    "ru_004.wav", "", "ru_006.wav", NULL 
}

Definition at line 204 of file test.cpp.

Referenced by main.

const char* list_non_uniform_format[] [static]
 

Initial value:

{ 
    "ru_001.wav", "ru_2.wav", "ru_003.wav", 
    "ru_004.wav", "ru_005.wav", NULL 
}

Definition at line 194 of file test.cpp.

Referenced by main.

const char* list_with_gaps[] [static]
 

Initial value:

{ 
    "ru_001.wav", "gap", "ru_003.wav", 
    "ru_004.wav", "gap", "ru_006.wav", NULL 
}

Definition at line 199 of file test.cpp.

Referenced by main.


Generated on Tue Feb 11 23:05:31 2003 for gwavmerger by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002