00001 /*----------------------------------------------------------------------------- 00002 Name: TestStringTrim.cpp 00003 Project: xmlBlaster.org 00004 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file 00005 Comment: Testing the Timeout Features 00006 -----------------------------------------------------------------------------*/ 00007 #include <util/StringTrim.h> 00008 #include <util/XmlBlasterException.h> 00009 #include <util/Global.h> 00010 #include "TestSuite.h" 00011 #include <iostream> 00012 00013 using namespace std; 00014 using namespace org::xmlBlaster::util; 00015 00016 00017 namespace org { namespace xmlBlaster { namespace test { 00018 00019 class TestStringTrim 00020 { 00021 private: 00022 string ME; 00023 Global& global_; 00024 I_Log& log_; 00025 00026 public: 00027 TestStringTrim(Global& glob) 00028 : ME("TestStringTrim"), 00029 global_(glob), 00030 log_(glob.getLog("test")) 00031 { 00032 } 00033 00034 00035 void tearDown() 00036 { 00037 } 00038 00039 virtual ~TestStringTrim() 00040 { 00041 } 00042 00043 void setUp() 00044 { 00045 } 00046 00047 void testTrim() 00048 { 00049 string me = ME + "::testConnectQos"; 00050 log_.info(me, "testing parsing of a return connect qos: start"); 00051 StringTrim trimmer; 00052 00053 // Test const char * variant 00054 assertEquals(log_, me, string("ab"), StringTrim::trimStart(" \t\n ab"), string("Start test")); 00055 assertEquals(log_, me, string("OK"), trimmer.trimStart("OK"), string("Start test")); 00056 assertEquals(log_, me, string(""), trimmer.trimStart(0), string("Start test")); 00057 assertEquals(log_, me, string(""), trimmer.trimStart(""), string("Start test")); 00058 assertEquals(log_, me, string("A A "), trimmer.trimStart("A A "), string("Start test")); 00059 00060 assertEquals(log_, me, string("ab"), trimmer.trimEnd("ab \t\n "), string("End test")); 00061 assertEquals(log_, me, string("OK"), trimmer.trimEnd("OK"), string("End test")); 00062 assertEquals(log_, me, string(""), trimmer.trimEnd(0), string("End test")); 00063 assertEquals(log_, me, string(""), trimmer.trimEnd(""), string("End test")); 00064 assertEquals(log_, me, string(" A A"), trimmer.trimEnd(" A A"), string("End test")); 00065 00066 assertEquals(log_, me, string("ab"), trimmer.trim(" \t\n ab \t\n "), string("Trim test")); 00067 assertEquals(log_, me, string("OK"), trimmer.trim("OK"), string("Trim test")); 00068 assertEquals(log_, me, string(""), trimmer.trim(0), string("Trim test")); 00069 assertEquals(log_, me, string(""), trimmer.trim(""), string("Trim test")); 00070 assertEquals(log_, me, string("A A"), trimmer.trim(" A A"), string("Trim test")); 00071 00072 // Test string variant 00073 string result; 00074 result = " \t\n ab"; 00075 trimmer.trimStart(result); 00076 assertEquals(log_, me, string("ab"), result, string("string - Start test")); 00077 result = "OK"; 00078 trimmer.trimStart(result); 00079 assertEquals(log_, me, string("OK"), result, string("string - Start test")); 00080 result = ""; 00081 trimmer.trimStart(result); 00082 assertEquals(log_, me, string(""), result, string("string - Start test")); 00083 result = "A A "; 00084 trimmer.trimStart(result); 00085 assertEquals(log_, me, string("A A "), result, string("string - Start test")); 00086 00087 result = "ab \t\n "; 00088 trimmer.trimEnd(result); 00089 assertEquals(log_, me, string("ab"), result, string("string - End test")); 00090 result = "OK"; 00091 trimmer.trimEnd(result); 00092 assertEquals(log_, me, string("OK"), result, string("string - End test")); 00093 result = ""; 00094 trimmer.trimEnd(result); 00095 assertEquals(log_, me, string(""), result, string("string - End test")); 00096 result = " A A"; 00097 trimmer.trimEnd(result); 00098 assertEquals(log_, me, string(" A A"), result, string("string - End test")); 00099 00100 result = " \t\n ab \t\n "; 00101 trimmer.trim(result); 00102 assertEquals(log_, me, string("ab"), result, string("string - Trim test")); 00103 result = "OK"; 00104 trimmer.trim(result); 00105 assertEquals(log_, me, string("OK"), result, string("string - Trim test")); 00106 result = ""; 00107 trimmer.trim(result); 00108 assertEquals(log_, me, string(""), result, string("string - Trim test")); 00109 result = " A A"; 00110 trimmer.trim(result); 00111 assertEquals(log_, me, string("A A"), result, string("string - Trim test")); 00112 cout << "DONE" << endl; 00113 // assertEquals(log_, log_, me, string("127.0.0.2"), address.getHostname(), "address hostname check"); 00114 } 00115 }; 00116 00117 }}} // namespace 00118 00119 00120 using namespace org::xmlBlaster::test; 00121 00129 int main(int args, char ** argv) 00130 { 00131 try { 00132 org::xmlBlaster::util::Object_Lifetime_Manager::init(); 00133 Global& glob = Global::getInstance(); 00134 glob.initialize(args, argv); 00135 00136 TestStringTrim test(glob); 00137 00138 test.setUp(); 00139 test.testTrim(); 00140 test.tearDown(); 00141 org::xmlBlaster::util::Object_Lifetime_Manager::fini(); 00142 } 00143 catch (XmlBlasterException& ex) { 00144 std::cout << ex.toXml() << std::endl; 00145 } 00146 catch (bad_exception& ex) { 00147 cout << "bad_exception: " << ex.what() << endl; 00148 } 00149 catch (exception& ex) { 00150 cout << " exception: " << ex.what() << endl; 00151 } 00152 catch (string& ex) { 00153 cout << "string: " << ex << endl; 00154 } 00155 catch (char* ex) { 00156 cout << "char* : " << ex << endl; 00157 } 00158 00159 catch (...) 00160 { 00161 cout << "unknown exception occured" << endl; 00162 XmlBlasterException e(INTERNAL_UNKNOWN, "main", "main thread"); 00163 cout << e.toXml() << endl; 00164 } 00165 return 0; 00166 }