using namespace csvpp;␍␊ |
int main()␍␊ |
{␍␊ |
␉int test = 1;␍␊ |
␉// Test 1␍␊ |
␉{␍␊ |
RowReader tmp;␍␊ |
stringstream ss;␍␊ |
ss << "field1,field2,field3\r\n123,234,345\r\n999,000,111\r\n";␍␊ |
|
{␍␊ |
cout << tmp["field1"] << endl;␍␊ |
cerr << "Failed at row " << row << endl;␍␊ |
␉␉␉␉␉␉␉␉␉␉cerr << "Failed at test " << test << endl;␍␊ |
return 1;␍␊ |
}␍␊ |
break;␍␊ |
|
if (tmp["field1"] != "999")␍␊ |
{␍␊ |
cerr << "Failed at row " << row << endl;␍␊ |
␉␉␉␉␉␉␉␉␉␉cerr << "Failed at test " << test << endl;␍␊ |
return 1;␍␊ |
}␍␊ |
break;␍␊ |
}␍␊ |
row++;␍␊ |
}␍␊ |
␉}␍␊ |
␉␍␊ |
␉test++;␍␊ |
␉// Test 2␍␊ |
␉{␍␊ |
RowReader tmp;␍␊ |
stringstream ss;␍␊ |
ss << "field1,field2,field3\n123,234,345\n999,000,111\n";␍␊ |
ss >> tmp;␍␊ |
rowiterator it;␍␊ |
int row = 0;␍␊ |
while(ss >> tmp)␍␊ |
{␍␊ |
switch (row)␍␊ |
{␍␊ |
case 0:␍␊ |
if (tmp["field1"] != "123")␍␊ |
{␍␊ |
cout << tmp["field1"] << endl;␍␊ |
cerr << "Failed at row " << row << endl;␍␊ |
␉␉␉␉␉␉␉␉␉␉cerr << "Failed at test " << test << endl;␍␊ |
return 1;␍␊ |
}␍␊ |
break;␍␊ |
case 1:␍␊ |
if (tmp["field1"] != "999")␍␊ |
{␍␊ |
cerr << "Failed at row " << row << endl;␍␊ |
␉␉␉␉␉␉␉␉␉␉cerr << "Failed at test " << test << endl;␍␊ |
return 1;␍␊ |
}␍␊ |
break;␍␊ |
}␍␊ |
row++;␍␊ |
}␍␊ |
␉}␍␊ |
␉␍␊ |
␉test++;␍␊ |
␉// Test 3␍␊ |
␉// Testing patch provided by Hanifa␍␊ |
␉// https://code.google.com/p/csvpp/issues/detail?id=2␍␊ |
␉{␍␊ |
␉␉RowReader tmp('|');␍␊ |
stringstream ss;␍␊ |
ss << "field1|field2|field3\r\n123|234|345\r\n999|000|111\r\n";␍␊ |
ss >> tmp;␍␊ |
rowiterator it;␍␊ |
int row = 0;␍␊ |
␉␉␍␊ |
␉␉while(ss >> tmp)␍␊ |
{␍␊ |
switch (row)␍␊ |
{␍␊ |
case 0:␍␊ |
if (tmp["field1"] != "123")␍␊ |
{␍␊ |
cout << tmp["field1"] << endl;␍␊ |
cerr << "Failed at row " << row << endl;␍␊ |
␉␉␉␉␉␉␉␉␉␉cerr << "Failed at test " << test << endl;␍␊ |
return 1;␍␊ |
}␍␊ |
break;␍␊ |
case 1:␍␊ |
if (tmp["field1"] != "999")␍␊ |
{␍␊ |
cerr << "Failed at row " << row << endl;␍␊ |
␉␉␉␉␉␉␉␉␉␉cerr << "Failed at test " << test << endl;␍␊ |
return 1;␍␊ |
}␍␊ |
break;␍␊ |
}␍␊ |
row++;␍␊ |
}␍␊ |
␉␍␊ |
␉}␍␊ |
␍␊ |
cout << "All tests ran successfully" << endl;␍␊ |
return 0;␍␊ |