1 /*! ========================================================================
2 ** Extended Template and Library Test Suite
3 ** stringf Procedure Test
6 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
25 #include <ETL/stringf>
28 /* === M A C R O S ========================================================= */
33 /* === C L A S S E S ======================================================= */
36 /* === P R O C E D U R E S ================================================= */
41 char mystring[80]="My formatted string!";
42 string myotherstring="my other string!";
44 cout<<strprintf("This is a test of >>%s<<.",mystring)<<endl;
46 myotherstring="5 6.75 George 7";
50 #ifndef ETL_NO_STRSCANF
51 strscanf(myotherstring,"%d %f %s %d",&i, &f, mystring, &i2);
53 cout<<"warning: strscanf() disabled at compile time..."<<endl;
57 cout<<myotherstring+"=="+strprintf("%d %f %s %d",i, f, mystring, i2)<<endl;
59 cout<<stratof(strprintf("32.5849"))<<"==32.5849"<<endl;
63 int base_and_dir_name_test(void)
67 string str(unix_to_local_path("/usr/bin/bleh.exe"));
68 cout<<"Test Case 1 -> "<<str<<endl;
69 cout<<"basename -> "<<basename(str)<<endl;
70 if(basename(str)!="bleh.exe")
71 cerr<<"error:Bad basename"<<endl,ret++;
72 cout<<"dirname -> "<<dirname(str)<<endl;
73 if(dirname(str)!=unix_to_local_path("/usr/bin"))
74 cerr<<"error:Bad dirname"<<endl,ret++;
77 str=unix_to_local_path("/usr/bin/");
78 cout<<"Test Case 2 -> "<<str<<endl;
79 cout<<"basename -> "<<basename(str)<<endl;
80 if(basename(str)!="bin")
81 cerr<<"error:Bad basename"<<endl,ret++;
82 cout<<"dirname -> "<<dirname(str)<<endl;
83 if(dirname(str)!=unix_to_local_path("/usr"))
84 cerr<<"error:Bad dirname"<<endl,ret++;
88 cout<<"Test Case 3 -> "<<str<<endl;
89 cout<<"basename -> "<<basename(str)<<endl;
90 if(basename(str)!="bleh.exe")
91 cerr<<"error:Bad basename"<<endl,ret++;
92 cout<<"dirname -> "<<dirname(str)<<endl;
93 if(dirname(str)!=unix_to_local_path("."))
94 cerr<<"error:Bad dirname"<<endl,ret++;
100 int relative_path_test()
104 string curr_path=unix_to_local_path("/usr/local/bin/.");
105 string dest_path=unix_to_local_path("/usr/share");
107 cout<<"curr_path="<<curr_path<<" dest_path="<<dest_path<<endl;
108 cout<<"relative_path="<<relative_path(curr_path,dest_path)<<endl;
109 if(relative_path(curr_path,dest_path)!=unix_to_local_path("../../share"))
110 cerr<<"Bad relative path"<<endl,ret++;
114 curr_path=unix_to_local_path("/home/darco/projects/voria");
115 dest_path=unix_to_local_path("/home/darco/projects/voria/myfile.txt");
116 cout<<"curr_path="<<curr_path<<" dest_path="<<dest_path<<endl;
117 cout<<"relative_path="<<relative_path(curr_path,dest_path)<<endl;
118 if(relative_path(curr_path,dest_path)!=unix_to_local_path("myfile.txt"))
119 cerr<<"Bad relative path"<<endl,ret++;
123 curr_path=unix_to_local_path("/home/darco/projects/voria");
124 dest_path=unix_to_local_path("/home/darco/projects/voria/files/myfile.txt");
125 cout<<"curr_path="<<curr_path<<" dest_path="<<dest_path<<endl;
126 cout<<"relative_path="<<relative_path(curr_path,dest_path)<<endl;
127 if(relative_path(curr_path,dest_path)!=unix_to_local_path("files/myfile.txt"))
128 cerr<<"Bad relative path"<<endl,ret++;
132 curr_path=unix_to_local_path("/usr/local/../include/sys/../linux/linux.h");
133 cout<<"dirty_path="<<curr_path<<endl;
134 cout<<"clean_path="<<cleanup_path(curr_path)<<endl;
136 cout<<"current_working_directory="<<current_working_directory()<<endl;
141 /* === E N T R Y P O I N T ================================================= */
148 error+=base_and_dir_name_test();
149 error+=relative_path_test();