00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "BUnit.h"
00021 #include "CSV_line.h"
00022
00023 #define C_CSV // truco para que compile "CSV.c"
00024
00025
00026 class test_CSV : public TestCase {
00027 public:
00028 test_CSV() {}
00029 bool run();
00030 private:
00031 void test_setData();
00032 void test_op_data();
00033 void test_trim();
00034 void test_trimCSV();
00035 void test_chop();
00036 void test_istringstream();
00037 void test_setQuotedCSV();
00038 void test_getNextCSV();
00039
00040 #ifdef C_CSV
00041 void test_trim_C();
00042 void test_chop_C();
00043 #endif
00044 };
00045
00046
00047 bool test_CSV::run() {
00048 test_setData();
00049 test_op_data();
00050 test_trim();
00051 test_trimCSV();
00052 test_chop();
00053 test_istringstream();
00054 test_setQuotedCSV();
00055 test_getNextCSV();
00056
00057 #ifdef C_CSV
00058 test_trim_C();
00059 test_chop_C();
00060 #endif
00061 return wasSuccessful();
00062 }
00063
00064 #include <iostream>
00065 #include <sstream>
00066
00067
00068
00069 #define DIM(V) (sizeof(V) / sizeof(*V)) // *V == *(V+0) == V[0]
00070
00071
00072 void test_CSV::test_setData() {
00073 {{
00074 CSV_line csv;
00075
00076 csv.setData( ",,a,b,\"c,d\",\"e f \"\"g\"\r\n" );
00077 assertTrue( csv[0] == "" );
00078 assertTrue( csv[1] == "" );
00079 assertTrue( csv[2] == "a" );
00080 assertTrue( csv[3] == "b" );
00081 assertTrue( csv[4] == "c,d" );
00082 assertTrue( csv[5] == "e f \"g" );
00083 assertTrue( csv.size() == 6 );
00084 }}
00085 if (true) {
00086 char* t[13]; std::string str;
00087
00088
00089 t[0] = "\",\""; t[ 6] = "6";
00090 t[1] = "\"\""; t[ 7] = " 7";
00091 t[2] = "\" \""; t[ 8] = " 8 ";
00092 t[3] = " \"\""; t[ 9] = "9\"";
00093 t[4] = " \"\" "; t[10] = "\" \r, \"";
00094 t[5] = " \" \" "; t[11] = "\",11,\"";
00095 t[12] = "x\r\n";
00096 for (int i=0; i<12; ++i) {
00097 str += t[i];
00098 str += ',';
00099 }
00100 str += t[12];
00101
00102 CSV_line csv; csv.setData( str.data() , str.length() );
00103 assertTrue( csv.size() == 13 );
00104
00105 assertTrue( csv[ 0] == "," );
00106 assertTrue( csv[ 1] == "" );
00107 assertTrue( csv[ 2] == " " );
00108 for (int i=3; i<=9; ++i) {
00109 assertTrue_Msg( "t["+toString(i)+"] == ["+t[i]+"] ==> ["+csv[i]+']', t[i] == csv[i] );
00110 }
00111 assertTrue( csv[10] == " \r, " );
00112 assertTrue( csv[11] == ",11," );
00113 assertTrue( csv[12] != "x\r\n" ); assertTrue( csv[12] == "x" );
00114 }
00115 { using namespace std;
00116 string s; s += '"'; s += '"';
00117 assertTrue( s == string("\"\"") );
00118 assertTrue( "" == string("""") );
00119 assertTrue( string("\"\"") != """" );
00120
00121 }
00122 if (false) {
00123 char* t[13]; std::string str; CSV_line csv;
00124 std::cout << std::endl << '[' << str << ']' << std::endl;
00125 std::cout << "csv.size() == " << unsigned(csv.size()) << std::endl;
00126 for (size_t i=0; i<csv.size(); ++i) {
00127 std::cout << "csv[" << unsigned(i) << "] == [" << csv[i] << ']' << std::endl;
00128 }
00129 for (size_t i=0; i<csv.size(); ++i) {
00130 std::cout << "csv[" << unsigned(i) << "] == [" << csv[i] << ']';
00131 std::string s = csv[i]; trimCSV( s );
00132 std::cout << " ==> [" << s << ']' << std::endl;
00133 }
00134 for (int i=0; i<9; ++i) {
00135 assertTrue_Msg( "t["+toString(i)+"]["+t[i]+"] == ["+csv[i]+']', t[i] == csv[i] );
00136 }
00137 { int i=0; std::cout << __LINE__ << " csv[" << i << "] == [" << csv[i] << ']' << std::endl; }
00138 }
00139 {
00140 std::string res;
00141 setQuotedCSV(res,"2"); assertTrue(res == "2" );
00142 setQuotedCSV(res,"4,5"); assertTrue(res == "\"4,5\"" );
00143
00144 setQuotedCSV( res, "," ); assertTrue(res == "\",\"");
00145 setQuotedCSV( res, "2" ); assertTrue(res == "2");
00146 setQuotedCSV( res, "" ); assertTrue(res == "");
00147 setQuotedCSV( res, "4,5" ); assertTrue(res == "\"4,5\"");
00148 }
00149 {
00150 CSV_line csv( ",\" ... \"\" \"3x,list" );
00151 assertTrue( csv.size() == 3 );
00152 assertTrue( csv[0] == "" );
00153 assertTrue( csv[1] == "\" ... \"\" \"3x" );
00154 assertTrue( csv[2] == "list" );
00155 }
00156 {
00157 CSV_line csv( ",\".\r\n\"" );
00158 assertTrue( csv.size() == 2 );
00159 assertTrue( csv[0] == "" );
00160 assertTrue( csv[1] == ".\r\n" );
00161 }
00162 {
00163
00164 CSV_line csv; char * t[4]; std::string str;
00165 t[0] = "0";
00166 t[1] = "\" ,,\r\n .. \"";
00167 t[2] = "\",,\r\n\"\",\"";
00168 t[3] = "123\r\n";
00169 for (int i=0; i<=2; ++i) {
00170 str += t[i];
00171 str += ',';
00172 }
00173 str += t[3];
00174
00175 csv.setData( str.data() , str.length() );
00176 assertTrue( csv.size() == 4 ); assertTrue( csv.size() != 5 );
00177 assertTrue( csv[0] == "0" );
00178 assertTrue( csv[1] == " ,,\r\n .. " );
00179 assertTrue( csv[2] == ",,\r\n\"," );
00180 assertTrue( csv[3] == "123" );
00181 assertTrue( csv[3] != "123\r\n" ); assertTrue( csv[3] != "123\r" );
00182 }
00183 {
00184 CSV_line csv( "123\r\n" );
00185 assertTrue( csv[0] == "123" );
00186 assertTrue( csv[0] != "123\r\n" ); assertTrue( csv[0] != "123\r" );
00187 }
00188 {
00189 CSV_line csv( ", \" 3rd\" \r\n" );
00190 assertTrue( csv[0] == "" );
00191 assertTrue( csv[1] == " \" 3rd\" " );
00192 std::string copy = csv[1];
00193 trimCSV( copy );
00194 assertTrue( copy == " 3rd" );
00195 }
00196 if (false) {
00197 const char * in[11]; const char * out[11];
00198 in[ 0] = "\"zero\""; out[ 0] = "zero";
00199 in[ 1] = ", \"if \"\" 1\" "; out[ 1] = " \"if \"\" 1\" ";
00200 in[ 2] = ", "; out[ 2] = " ";
00201 in[ 3] = ", \" 3xt\" \r\n"; out[ 3] = " \" 3xt\" ";
00202 in[ 4] = ",\"png\"\"\n\"\"\n"; out[ 4] = "png\"\n\"";
00203 in[ 5] = ",12345"; out[ 5] = "12345";
00204 in[ 6] = ",\"\"\r\n"; out[ 6] = "\"\"";
00205 in[ 7] = ",12\r666\r\n"; out[ 7] = "12\r666";
00206 in[ 8] = ",12\r\n"; out[ 8] = "12";
00207 in[ 9] = ",\"con blanco\""; out[ 9] = "con blanco";
00208 in[10] = ",\"con,coma\""; out[10] = "con,coma";
00209
00210 std::string str;
00211 for (int i=0; i<=10; ++i) {
00212 str += in[i];
00213 }
00214
00215 {
00216 std::vector<std::string> VEC;
00217 VEC.clear();
00218 std::string csv;
00219 bool eol_CIN = false;
00220 std::istringstream ist( str , std::ios::binary );
00221 while ( ! ist.fail() ) {
00222 eol_CIN = getNextCSV( csv, ist );
00223 VEC.push_back( csv );
00224 }
00225
00226 for (int i=0; i<=10; ++i) {
00227 assertTrue_Msg( std::string()+in[i]+" ==> "+out[i] , VEC[i]==out[i] );
00228 }
00229 }
00230 return;
00231 }
00232 {
00233 CSV_line csv( "\"\"\"n\"" );
00234 assertTrue( csv[0] == "\"n" );
00235 assertTrue( csv.size() == 1 );
00236 }
00237 {
00238 const int N_COUT = 0;
00239 std::string s, str;
00240
00241
00242 str = ",\"\n\",\"pa\"\"pa\",\"ce\nro\", \"el \"\" 1\" , ,\n";
00243 CSV_line csv; csv.setData( str.data() ); {
00244 assertTrue( csv[0] == "" );
00245 assertTrue( csv[1] == "\n" );
00246 assertTrue( csv[2] == "pa\"pa" );
00247 assertTrue( csv[3] == "ce\nro" );
00248 assertTrue( csv[4] == " \"el \"\" 1\" " );
00249 assertTrue( csv[5] == " " );
00250 assertTrue( csv[6] == "" );
00251 assertTrue( csv.size() == 7 );
00252 for ( int i=0; i<csv.size()*N_COUT; ++i ) {
00253 std::cout << "csv[" << i << "] == [" << csv[i] << ']' << std::endl;
00254 }
00255 }
00256
00257
00258 str = ",\"\r\",\"pato\",\"perro\"\r\n";
00259 csv.setData( str.data() ); {
00260 assertTrue( csv[0] == "" );
00261 assertTrue( csv[1] == "\r" );
00262 assertTrue( csv[2] == "pato");
00263 assertTrue( csv[3] == "perro");
00264 assertTrue( csv[3] != "\"perro\"\n"); assertTrue( csv[3] != "\"perro\"\r\n");
00265 assertTrue( csv.size() == 4 );
00266 for ( int i=0; i<csv.size()*N_COUT; ++i ) {
00267 std::cout << "csv[" << i << "] == [" << csv[i] << ']' << std::endl;
00268 }
00269 }
00270 str = "perro\n,pato\n";
00271 csv.setData( str.data() ); {
00272 assertTrue( csv[0] == "perro" ); assertTrue( csv[0] != "perro\n" );
00273 assertTrue( csv.size() == 1 );
00274
00275
00276 for ( int i=0; i<csv.size()*N_COUT; ++i ) {
00277 std::cout << "csv[" << i << "] == [" << csv[i] << ']' << std::endl;
00278 }
00279 }
00280 }
00281 {
00282 CSV_line csv;
00283 char *ch1 = "a";
00284 char *ch2 = ",";
00285 char *ch3 = "\"2,3\"";
00286 char *ch4 = "\n";
00287
00288 csv.setData(ch1,1); assertTrue(csv[0] == "a");
00289 csv.setData(ch2,1); assertTrue(csv[1] == "");
00290 csv.setData(ch3,5); assertTrue(csv[0] == "2,3");
00291 csv.setData(ch4,1); assertTrue(csv[0] == "");
00292 }
00293 {
00294 CSV_line csv;
00295 csv.setData(","); assertTrue( csv[0] == "");
00296
00297 csv.setData("\r\n"); {
00298 assertTrue( csv[0] == "");
00299 assertTrue( csv.size()== 1 );
00300 }
00301
00302 csv.setData("0,1,2,\"\"\n"); {
00303 assertTrue( csv[0] == "0");
00304 assertTrue( csv[1] == "1");
00305 assertTrue( csv[2] == "2");
00306 assertTrue( csv[3] == "" );
00307 assertTrue( csv.size()== 4 );
00308 }
00309
00310 csv.setData("abcdef\nghijk\r\nlmnop"); {
00311 assertTrue( csv[0] == "abcdef" ); assertTrue( csv[0] != "abcdef\n" );
00312 assertTrue( csv.size()== 1 );
00313
00314
00315 }
00316
00317 csv.setData("abcdef\rghijk\r\nlmnop"); {
00318 assertTrue( csv[0] != "abcdef\rghijk\r\n" );
00319 assertTrue( csv[0] == "abcdef\rghijk" );
00320 assertTrue( csv.size()== 1 );
00321
00322 }
00323 }
00324 {
00325 {
00326 CSV_line csv( "\n" );
00327 assertTrue( csv.size() == 1 );
00328 assertTrue( csv[0] == "" );
00329 }
00330 {
00331 CSV_line csv( ",\".\"\rab," );
00332 assertTrue( csv.size() == 3 );
00333 assertTrue( csv[0] == "" );
00334 assertTrue( csv[1] == "\".\"\rab" );
00335 assertTrue( csv[1] != ".\rab" );
00336 assertTrue( csv[2] == "" );
00337 }
00338 {
00339 CSV_line csv( ",\".\"ab,\"hola\"\n" );
00340 assertTrue( csv.size() == 3 );
00341 assertTrue( csv[0] == "" );
00342 assertTrue( csv[1] == "\".\"ab" );
00343 }
00344 }
00345 }
00346
00347
00348 void test_CSV::test_op_data() {
00349
00350 {{
00351 CSV_line csv ("a,b,c,d,e,f,g"); {
00352 assertTrue(csv[0] == "a");
00353 assertTrue(csv[1] == "b");
00354 assertTrue(csv[2] == "c");
00355 assertTrue(csv[3] == "d");
00356 assertTrue(csv[4] == "e");
00357 assertTrue(csv[5] == "f");
00358 assertTrue( csv.size() == 7 );
00359 }
00360 }}
00361 {
00362 CSV_line csv2 ( "poll, m, ts, 08" ); {
00363 assertTrue(csv2[0] == "poll");
00364 assertTrue(csv2[1] == " m");
00365 assertTrue(csv2[2] == " ts");
00366 assertTrue(csv2[3] == " 08");
00367 assertTrue(csv2.size() == 4 );
00368 }
00369
00370 CSV_line csv3 ("fsd,ah,que,pi,som,b,aaana"); {
00371 assertTrue(csv3[0] == "fsd");
00372 assertTrue(csv3[1] == "ah");
00373 assertTrue(csv3[2] == "que");
00374 assertTrue(csv3[3] == "pi");
00375 assertTrue(csv3[4] == "som");
00376 assertTrue(csv3[5] == "b");
00377 assertTrue( csv3.size() == 7 );
00378 }
00379 }
00380 }
00381
00382
00383 void test_CSV::test_setQuotedCSV() {
00384
00385 {{
00386 std::string res;
00387 setQuotedCSV( res, "," ); assertTrue( res == "\",\"" );
00388 setQuotedCSV( res, "2" ); assertTrue( res == "2" );
00389 setQuotedCSV( res, "" ); assertTrue( res == "" );
00390 setQuotedCSV( res, "4,5" ); assertTrue( res == "\"4,5\"" );
00391 setQuotedCSV( res, "K\"" ); assertTrue( res == "\"K\"\"\"" );
00392 setQuotedCSV( res, "\r\n" ); assertTrue( res == "\"\r\n\"" );
00393 }}
00394 {
00395 std::string dest, str;
00396 str = "valor1"; setQuotedCSV(dest, str);
00397 assertTrue( dest == "valor1" );
00398 str = "valor 1"; setQuotedCSV(dest, str);
00399 assertTrue( dest == "\"valor 1\"" );
00400 str = "valor,1"; setQuotedCSV(dest, str);
00401 assertTrue( dest == "\"valor,1\"" );
00402 str = "valor\"1"; setQuotedCSV(dest, str);
00403 assertTrue( dest == "\"valor\"\"1\"" );
00404 str = "valor,\"1\""; setQuotedCSV(dest, str);
00405 assertTrue( dest == "\"valor,\"\"1\"\"\"" );
00406 }
00407 {
00408 std::string res;
00409 setQuotedCSV( res, "" ); assertTrue( res == "" );
00410 setQuotedCSV( res, "2" ); assertTrue( res == "2" );
00411 setQuotedCSV( res, "4,5" ); assertTrue( res == "\"4,5\"" );
00412 setQuotedCSV( res, "& _ ()" ); assertTrue( res == "\"& _ ()\"" );
00413 }
00414 {
00415 std::string res, str;
00416 res = str = "1 2 3 4 5 6"; {
00417 assertTrue ( res == "1 2 3 4 5 6" );
00418 setQuotedCSV (res, str);
00419 assertTrue ( res != str );
00420 assertTrue ( res == "\"1 2 3 4 5 6\"" );
00421 }
00422 res = str = "1,2,3,4,5,6"; {
00423 assertTrue ( res == "1,2,3,4,5,6" );
00424 setQuotedCSV (res, str);
00425 assertTrue ( res != str );
00426 assertTrue ( res == "\"1,2,3,4,5,6\"" );
00427 }
00428 res = str = "123\"456"; {
00429 assertTrue ( res == "123\"456" );
00430 setQuotedCSV (res, str);
00431 assertTrue ( res != str );
00432 assertTrue ( res == "\"123\"\"456\"" );
00433 }
00434 res = str = "123456"; {
00435 assertTrue ( res == "123456" );
00436 setQuotedCSV (res, str);
00437 assertTrue ( res == str );
00438 assertTrue ( res == "123456" );
00439 }
00440 res = str = "\""; {
00441 assertTrue ( res == "\"" );
00442 setQuotedCSV (res, str);
00443 assertTrue ( res != str );
00444 assertTrue ( res == "\"\"\"\"" );
00445 }
00446 }
00447 }
00448
00449
00450 void test_CSV::test_getNextCSV() {
00451 {
00452 std::string prueba1 = "PSL,ITE,AMCY";
00453 std::istringstream ist(prueba1);
00454 bool getn1 = getNextCSV(prueba1,ist);
00455 assertFalse (getn1);
00456 assertTrue (prueba1 == "PSL");
00457
00458 if (false) {
00459 {
00460 int error;
00461 std::string res;
00462 std::cout << "Digite una letra para provocar un error";
00463 std::cin >> error;
00464 bool fallo = getNextCSV(res,std::cin);
00465 assertTrue(!fallo);
00466 }
00467 {
00468 int error1;
00469 std::string res1;
00470 std::cin >> error1;
00471 bool fallo1 = getNextCSV(res1,std::cin);
00472 assertTrue(!fallo1);
00473 }
00474 {
00475 int error2;
00476 std::string res2;
00477 std::cin >> error2;
00478 bool fallo2 = getNextCSV(res2,std::cin);
00479 assertTrue(!fallo2);
00480 }
00481 {
00482 std::string prueba2 = "PSL\n";
00483 std::istringstream ist2 (prueba2);
00484 bool getn1 = getNextCSV(prueba2,ist2);
00485 assertTrue (getn1);
00486 assertTrue (prueba2 == "PSL");
00487 }
00488 }
00489 }
00490 {
00491 std::string csv; {
00492 std::string str1 = "a";
00493 std::istringstream ist1(str1);
00494 getNextCSV( csv, ist1 ); assertTrue( csv == "a" );
00495
00496 std::string str2 = "\"2,3\"";
00497 std::istringstream ist2(str2);
00498 getNextCSV( csv, ist2 ); assertTrue( csv == "2,3" );
00499
00500 std::string str3 = "\n";
00501 std::istringstream ist3(str3);
00502 getNextCSV( csv, ist3 ); assertTrue( csv == "" );
00503 }
00504 }
00505 }
00506
00507
00508 void test_CSV::test_trim() {
00509 {{
00510 std::string str;
00511 str = " a b "; trim(str); assertTrue( str == "a b" );
00512 str = " a\nb "; trim(str); assertTrue( str == "a\nb" );
00513 str = ""; trim(str); assertTrue( str == "" );
00514 str = "\r\t\n "; trim(str); assertTrue( str == "" );
00515 str = " a b "; trim(str); assertTrue( str == "a b" );
00516 str = " ab " ; trim(str); assertTrue( str == "ab" );
00517 }}
00518 }
00519
00520
00521 void test_CSV::test_trimCSV() {
00522 {{
00523 CSV_line csv("\"zero\", \"if \"\" 1\" , , \" 3xt\" \r\f"); std::string s;
00524 s=csv[0]; assertTrue( s == "zero" ); trimCSV(s); assertTrue( s == "zero" );
00525 s=csv[1]; assertTrue( s == " \"if \"\" 1\" " ); trimCSV(s); assertTrue( s == "if \" 1" );
00526 s=csv[2]; assertTrue( s == " " ); trimCSV(s); assertTrue( s == "" );
00527 s=csv[3]; assertTrue( s == " \" 3xt\" \r\f" ); trimCSV(s); assertTrue( s == " 3xt" );
00528 }}
00529 {{
00530
00531 CSV_line csv ("\"zero\", \"if \"\" 1\" , , \" 3xt\" \r\n");
00532 std::vector<std::string> cpy = csv;
00533 assertTrue( csv[0] == "zero" );
00534 assertTrue( csv[1] == " \"if \"\" 1\" " );
00535 assertTrue( csv[2] == " " );
00536 assertTrue( csv[3] == " \" 3xt\" " );
00537
00538 trimCSV( cpy[0] ); assertTrue( cpy[0] == "zero" );
00539 trimCSV( cpy[1] ); assertTrue( cpy[1] == "if \" 1" );
00540 trimCSV( cpy[2] ); assertTrue( cpy[2] == "" );
00541 trimCSV( cpy[3] ); assertTrue( cpy[3] == " 3xt" );
00542 }}
00543 }
00544
00545 #ifdef C_CSV
00546
00547 #include "CSV.c"
00548
00549
00550 void test_CSV::test_trim_C() {
00551 #define googa std::cout << "trim(" << str << ")==> ["; std::cout << trim(str) << ']' << std::endl;
00552 {{
00553 char str[20];
00554 strcpy( str , " a b " ); assertTrue( strcmp( trim(str), "a b" ) == 0 );
00555 strcpy( str , " a\nb " ); assertTrue( strcmp( trim(str), "a\nb") == 0 );
00556 strcpy( str , "" ); assertTrue( strcmp( trim(str), "" ) == 0 );
00557 strcpy( str , "\r\t\n " ); assertTrue( strcmp( trim(str), "" ) == 0 );
00558 strcpy( str , " a b " ); assertTrue( strcmp( trim(str), "a b" ) == 0 );
00559 strcpy( str , " ab " ); assertTrue( strcmp( trim(str), "ab" ) == 0 );
00560
00561 }}
00562 }
00563
00564
00565 void test_CSV::test_chop_C() {
00566 {{
00567 char str[20]; char ch;
00568 strcpy( str , "12345") ; assertTrue( strcmp(str ,"12345")==0 );
00569 chop(str,'0'); assertTrue( strcmp(str ,"12345")==0 );
00570
00571 for ( ch='5'; ch != '0'; --ch ) {
00572 assertTrue( str[strlen(str)-1] == ch );
00573 chop(str,ch);
00574 }
00575
00576 assertTrue( *str == 0 );
00577 chop(str,'3'); assertTrue( *str == 0 );
00578 }}
00579 }
00580 #endif
00581
00582
00583 void test_CSV::test_chop() {
00584 {{
00585 std::string str; char ch;
00586 str = "12345"; assertTrue( str == "12345" );
00587 chop(str,'0'); assertTrue( str == "12345" );
00588
00589 for ( ch='5'; ch != '0'; --ch ) {
00590 assertTrue( str[str.size()-1] == ch );
00591 chop(str,ch);
00592 }
00593
00594 assertTrue( str == "" );
00595 chop(str,'3'); assertTrue( str == "" );
00596 }}
00597 }
00598
00599 #include <sstream>
00600
00601 #ifdef English_dox
00602
00603
00604
00605
00606 #endif
00607 #ifdef Spanish_dox
00608
00609
00610
00611
00612 #endif
00613 void mem_istring( std::string & res , std::string & str ) {
00614
00615 {
00616 std::istringstream ist(str);
00617 getNextCSV( res, ist );
00618 }
00619 {
00620 res.clear();
00621 std::basic_istringstream<char> ist(str);
00622 char ch='%'; int i =0;
00623 while ( ! ist.eof() ) {
00624 ist >> ch; ++i;
00625 res += ch;
00626 ch = '!';
00627 }
00628
00629 }
00630 {
00631 res.clear();
00632 std::istringstream ist(str);
00633 char ch='%'; int i =0;
00634 for (;;) {
00635 ist.get( ch ); ++i;
00636 if ( ist.eof() ) {
00637 break;
00638 }
00639 res += ch;
00640 ch = '!';
00641 }
00642
00643 }
00644 {
00645 res.clear();
00646 std::istringstream ist(str);
00647 char ch='%'; int i =0;
00648 for (;;) {
00649 ist >> ch; ++i;
00650 if ( ist.eof() ) {
00651 break;
00652 }
00653 res += ch;
00654 ch = '!';
00655 }
00656
00657 }
00658 }
00659
00660
00661 void test_CSV::test_istringstream() {
00662 {
00663 std::string res, str = " 1 2 3 4 5 6 ";
00664 mem_istring( res , str );
00665 assertTrue( res != "1234566" );
00666 assertTrue( res != " 1 2 3 4 5 6 " );
00667 assertTrue( res == "123456" );
00668 }
00669 }
00670
00671
00672 #ifdef English_dox
00673
00674 #endif
00675 #ifdef Spanish_dox
00676
00677 #endif
00678 int main() {
00679 test_CSV tester;
00680 tester.run();
00681 std::cout << tester.report();
00682 return 0;
00683 }
00684
00685