2 * See the file LICENSE for redistribution information.
4 * Copyright: 2010- 1stclass.co.jp. All rights reserved.
6 * Created by Hajime Kurita
12 #include "../1stclass.hpp"
13 #include "../1stclass.h"
18 tester(){ok=0;bad=0;};
30 // Judge whether this is number or not
32 if(fst.is_num("2") && fst.is_num("test")==0){
33 cout << "is_num/C++: ok "<< endl;
37 cout << "is_num/C++: bad" << endl;
41 if(is_num("2") && is_num("test")==0){
42 cout << "is_num/C: ok "<< endl;
46 cout << "is_num/C: bad" << endl;
51 // Get IP from host name
53 string server="www.yahoo.co.jp";
54 string ip=fst.host2ip(server);
55 if( (ip.at(0) - '1'>=0) && (ip.at(0) - '1'<=9) ){
56 cout << "host2ip/C++: ok" << endl;
60 cout << "host2ip/C++: bad" << endl;
64 char c_server[]="www.yahoo.co.jp";
66 host2ip(c_server, c_ip);
67 if( (c_ip[0] - '1' >=0) && (c_ip[0] - '1' <=9) ){
68 cout << "host2ip/C: ok" << endl;
72 cout << "host2ip/C: bad" << endl;
77 // Get absolute path from relative path
79 string rel_path="../lib1stclass/1/2/3";
80 string abs_path=fst.rel2abs(rel_path);
81 if( abs_path.find("/")==0 && abs_path.find("lib1stclass/1/2/3")!=string::npos){
82 cout << "rel2abs/C++: ok" << endl;
86 cout << "rel2abs/C++: bad" << endl;
90 char rel_path_char[]="../lib1stclass/1/2/3";
91 char abs_path_char[1024]="";
92 rel2abs(rel_path_char, abs_path_char);
93 if( abs_path_char[0]=='/' && strstr(abs_path_char, "lib1stclass/1/2/3")!=NULL){
94 cout << "rel2abs/C: ok" << endl;
98 cout << "rel2abs/C: bad" << "/" << abs_path_char << endl;
102 string rel_path2="lib1stclass/1/2/3";
103 string abs_path2=fst.rel2abs(rel_path2);
104 if( abs_path2.find("/")==0 && abs_path2.find("/lib1stclass/1/2/3")!=string::npos){
105 cout << "rel2abs/C++: ok" << endl;
109 cout << "rel2abs/C++: bad" << endl;
113 char rel_path_char2[]="lib1stclass/1/2/3";
114 char abs_path_char2[1024]="";
115 rel2abs(rel_path_char2, abs_path_char2);
116 if( abs_path_char2[0]=='/' && strstr(abs_path_char2, "/lib1stclass/1/2/3")!=NULL){
117 cout << "rel2abs 2/C: ok" << endl;
121 cout << "rel2abs 2/C: bad" << endl;
125 string rel_path3="/tmp/1/2/3";
126 string abs_path3=fst.rel2abs(rel_path3);
127 if( abs_path3=="/tmp/1/2/3"){
128 cout << "rel2abs 3/C++: ok" << endl;
132 cout << "rel2abs 3/C++: bad" << endl;
136 char rel_path_char3[]="/tmp/1/2/3";
137 char abs_path_char3[1024]="";
138 rel2abs(rel_path_char3, abs_path_char3);
139 if( strcmp(abs_path_char3, "/tmp/1/2/3")==0){
140 cout << "rel2abs 3/C: ok" << endl;
144 cout << "rel2abs 3/C: bad" << endl;
151 fst.rmkdir("test_dir/depth2");
152 if(stat("test_dir/depth2", &st)==0){
153 cout << "rmkdir/C++: ok" << endl;
157 // Remove path completely
158 // パス全体を消去(ディレクトリを再帰的に消去)
159 fst.remove_path("test_dir");
160 if(stat("test_dir", &st)!=0){
161 cout << "remove_path/C++: ok" << endl;
165 cout << "remove_path/C++: bad" << endl;
170 cout << "rmkdir/C++: bad" << endl;
174 rmkdir("test_dir/depth_2");
175 if(stat("test_dir/depth_2", &st)==0){
176 cout << "rmkdir/C: ok" << endl;
178 remove_path("test_dir");
179 if(stat("test_dir", &st)!=0){
180 cout << "remove_path/C: ok" << endl;
184 cout << "remove_path/C: bad" << endl;
189 cout << "rmkdir/C: bad" << endl;
194 // Convert int to char
199 fst.itoa(integer, itoa_str);
200 if (strcmp(itoa_str,"12345") == 0){
201 cout << "itoa/C++: ok" << endl;
205 cout << "itoa/C++: bad" << endl;
210 itoa(integer, itoa_str);
211 if (strcmp(itoa_str,"12345") == 0){
212 cout << "itoa/C: ok" << endl;
216 cout << "itoa/C: bad" << endl;
223 char example1[]="1234";
224 fst.reverse_char(example1);
225 if (strcmp(example1,"4321") == 0){
226 cout << "reverse_char/C++: ok" << endl;
230 cout << "reverse_char/C++: bad" << endl;
234 char example2[]="1234";
235 reverse_char(example2);
236 if (strcmp(example2,"4321") == 0){
237 cout << "reverse_char/C: ok" << endl;
241 cout << "reverse_char/C: bad" << endl;
245 // remove_not_file_char:
246 // Convert ascii characters which cannot be used for file name into "_"
247 // ファイルシステムに使えないアスキー文字を「_」に変換
248 string not_file_str="bk\\sl/sm:as*qt?dq\"lt<rt>vt|";
249 string file_str=fst.remove_not_file_char(¬_file_str);
250 if (file_str=="bk_sl_sm_as_qt_dq_lt_rt_vt_"){
251 cout << "remove_not_file_char/C++: ok" << endl;
255 cout << "remove_not_file_char/C++: bad" << endl;
259 char not_file_char[]="bk\\sl/sm:as*qt?dq\"lt<rt>vt|";
260 char file_char[1024]="";
261 remove_not_file_char(not_file_char, file_char);
262 if (strcmp(file_char,"bk_sl_sm_as_qt_dq_lt_rt_vt_")==0){
263 cout << "remove_not_file_char/C: ok" << endl;
267 cout << "remove_not_file_char/C: bad" << endl;
272 // Create temporary file on /dev/shm/
273 // /dev/shm/上への一時ファイル生成
274 string file="/tmp/test.txt";
275 if(fst.shmf(file)=="/dev/shm/_tmp_test.txt"){
276 cout << "shmf/C++: ok" << endl;
280 cout << "shmf/C++: bad" << endl;
284 char tfile[]="/tmp/test.txt";
287 if(strcmp(sfile, "/dev/shm/_tmp_test.txt")==0){
288 cout << "shmf/C: ok" << endl;
292 cout << "shmf/C: bad" << endl;
301 fst.safe_strcat(a1, b1, sizeof(a1));
302 if(strcmp(a1,b1)==0){
303 cout << "safe_strcat 1/C++: ok" << endl;
307 cout << "safe_strcat 1/C++: bad" << endl;
313 safe_strcat(a2, b2, sizeof(a2));
314 if(strcmp(a2,b2)==0){
315 cout << "safe_strcat 2/C: ok" << endl;
319 cout << "safe_strcat 2/C: bad" << endl;
325 fst.safe_strcat(a3, b3, sizeof(a3));
326 if(strcmp(a3,"1")==0){
327 cout << "safe_strcat 3/C++: ok" << endl;
331 cout << "safe_strcat 3/C++: bad" << endl;
337 safe_strcat(a4, b4, sizeof(a4));
338 if(strcmp(a4,"1")==0){
339 cout << "safe_strcat 4/C: ok" << endl;
343 cout << "safe_strcat 4/C: bad" << endl;
348 void tester::report(){
349 cout << "ok=" << ok << "\t" << "bad=" << bad << endl;