kdenonbeta/kdedebian/kapture/kapture
CVS commit by domi:
proper unit tests for the stl_util stuff
M +36 -21 stl_test.cpp 1.2
M +0 -42 stl_util.cpp 1.5
--- kdenonbeta/kdedebian/kapture/kapture/stl_test.cpp #1.1:1.2
@@ -1,29 +1,44 @@
#include "stl_util.h"
#include <iostream>
+#include <assert.h>
using namespace std;
using namespace capture;
-int main ()
-{
+int main() {
+ {
+ argmap test;
+ test["test1"] = "test2";
+ test["fjioj @,,ping"] = "jfdiosqj @@,,";
+ test[",,"] = "#@@@";
+ string out = argmap2string( test );
+ argmap test2 = string2argmap( out );
+ assert( test2.size() == 3 );
+ assert( test2["test1"] == "test2" );
+ assert( test2["fjioj @,,ping"] == "jfdiosqj @@,," );
+ assert( test2[",,"] == "#@@@" );
+ }
+ {
list <string> test;
test . push_back (string ("test, #1"));
test . push_back (string ("test, #2"));
- test . push_back (join (test, ","));
- cout << join (test, ",") << endl;
- test = explode (join (test, ","), ",");
- for (list<string>::iterator it = test . begin (); it != test . end (); it ++)
- cout << *it << endl;
- cout << "-------" << endl;
- test . push_back (join (test, ","));
+ string joinedf2 = join( test, "," );
+ test . push_back ( joinedf2 );
+ list<string> testret = explode (join (test, ","), ",");
+ assert( test.size() == testret.size() );
+ list<string>::iterator i, j;
+ i = test.begin();
+ j = testret.begin();
+ for ( ; i != test.end(); ++i, ++j )
+ assert( *i == *j );
+
+ string joinedf3 = join( test, "," );
+ test.push_back( joinedf3 );
string str = join (test, "::");
- cout << str << endl;
- test = explode (str, "::");
- for (list<string>::iterator it = test . begin (); it != test . end (); it ++) {
- cout << *it << "( ";
- list<string> test1 = explode (*it, ",");
- for (list<string>::iterator jt = test1 . begin (); jt != test1 . end (); jt ++)
- cout << "'" << (*jt) << "' ";
- cout << ")" << endl;
+ testret = explode (str, "::");
+ i = test.begin();
+ j = testret.begin();
+ for ( ; i != test.end(); ++i, ++j )
+ assert( *i == *j );
}
return 0;
--- kdenonbeta/kdedebian/kapture/kapture/stl_util.cpp #1.4:1.5
@@ -20,8 +20,4 @@
#include <iostream>
-#ifdef DOMI_DEBUG
-#include <algorithm>
-#include <iterator>
-#endif
#include "stl_util.h"
@@ -133,16 +129,4 @@ list<string> capture::explode (string s,
}
-static string join_helper (list<string> l, string delim)
-{
- string res;
- for (list<string>::iterator it = l . begin (), next; it != l . end (); it ++) {
- res . append (*it);
- next = it; next ++;
- if (next != l . end ())
- res . append (delim);
- }
- return res;
-}
-
string capture::join (list<string> l, string delim)
{
@@ -187,28 +171,2 @@ argmap capture::string2argmap (string s)
return res;
}
-
-#ifdef DOMI_DEBUG
-int main() {
- {
- string test = "appels@::met@::::frieten!!@@";
- cout << escape( test, "::" ) << endl;
- cout << unescape( escape( test, "::" ), "::" ) << endl;
- }
- cout << endl;
- {
- argmap test;
- test["test1"] = "test2";
- test["fjioj @,,ping"] = "jfdiosqj @@,,";
- test[",,"] = "#@@@";
- string out = argmap2string( test );
- cout << out << endl;
- argmap test2 = string2argmap( out );
- cout << test2.size() << endl;
- cout << test2["test1"] << endl;
- cout << test2["fjioj @,,ping"] << endl;
- cout << test2[",,"] << endl;
- }
- cout << endl;
- return 0;
-}
-#endif
Reply to: