StringUtilsTest.cpp

Go to the documentation of this file.
00001 #include <gtest/gtest.h>
00002 #include <utils/common/StringUtils.h>
00003 
00004 using namespace std;
00005 
00006 /*
00007 Tests StringUtils class from <SUMO>/src/utils/common
00008 */
00009 
00010 /* Tests the method replace with empty second_argument */
00011 //TODO correct the error with the second argument 
00012 /*
00013 TEST(StringUtils, test_method_replace_empty_second_argument ) {
00014     EXPECT_EQ("hello", StringUtils::replace("hello","","a"));
00015 }
00016 */
00017 
00018 /* Tests the method prune. Cut the blanks at the beginning and at the end of a string*/
00019 TEST(StringUtils, test_method_prune) {
00020     EXPECT_EQ("result", StringUtils::prune("  result ")) << "Blanks at the beginning and at the end of a string must be removed.";
00021 }
00022 
00023 /* Tests the method to_lower_case.*/
00024 TEST(StringUtils, test_method_to_lower_case) {
00025     EXPECT_EQ("hello", StringUtils::to_lower_case("HELLO"))<< "String should be converted into small letter.";
00026     EXPECT_EQ("world", StringUtils::to_lower_case("World"))<< "String should be converted into small letter.";
00027     string str;
00028     EXPECT_EQ("", StringUtils::to_lower_case(str));
00029 }
00030 
00031 /* Tests the method convertUmlaute.*/
00032 TEST(StringUtils, test_method_convertUmlaute) {
00033     EXPECT_EQ("ae", StringUtils::convertUmlaute("ä"));
00034     EXPECT_EQ("Ae", StringUtils::convertUmlaute("Ä"));
00035     EXPECT_EQ("oe", StringUtils::convertUmlaute("ö"));
00036     EXPECT_EQ("Oe", StringUtils::convertUmlaute("Ö"));
00037     EXPECT_EQ("ue", StringUtils::convertUmlaute("ü"));
00038     EXPECT_EQ("Ue", StringUtils::convertUmlaute("Ü"));
00039     EXPECT_EQ("ss", StringUtils::convertUmlaute("ß"));
00040     EXPECT_EQ("E", StringUtils::convertUmlaute("É"));
00041     EXPECT_EQ("e", StringUtils::convertUmlaute("é"));
00042     EXPECT_EQ("E", StringUtils::convertUmlaute("È"));
00043     EXPECT_EQ("e", StringUtils::convertUmlaute("è"));
00044 }
00045 
00046 /* Tests the method replace. */
00047 TEST(StringUtils, test_method_replace) {    
00048     EXPECT_EQ("helt", StringUtils::replace("hello","lo","t"));
00049     EXPECT_EQ("heststo", StringUtils::replace("hello","l","st"));
00050     EXPECT_EQ("", StringUtils::replace("","l","st"));
00051 }
00052 
00053 /* Tests the method replace with empty string. */
00054 TEST(StringUtils, test_method_replace_empty_string) {       
00055     EXPECT_EQ("", StringUtils::replace("","l","st"));
00056 }
00057 
00058 /* Tests the method replace with empty third_argument */
00059 TEST(StringUtils, test_method_replace_empty_third_argument ) {
00060     EXPECT_EQ("hello", StringUtils::replace("hello","a",""));
00061 }
00062 
00063 
00064 /* Tests the method upper. */
00065 TEST(StringUtils, test_method_upper) {
00066     string toUpper = "halloWelt123-?";
00067     StringUtils::upper(toUpper);
00068     EXPECT_EQ("HALLOWELT123-?", toUpper) << "It should consist only of capital letters.";
00069     string str;
00070     StringUtils::upper(str);
00071     EXPECT_EQ("",str );
00072 }
00073 
00074 /* Tests the method toTimeString. */
00075 //TODO correct the errors
00076 TEST(StringUtils, test_method_toTimeString) {   
00077     //EXPECT_EQ("00:00:-1", StringUtils::toTimeString(-1)) << "Something better should happen.";
00078     EXPECT_EQ("00:00:00", StringUtils::toTimeString(0));
00079     EXPECT_EQ("01:00:00", StringUtils::toTimeString(3600));
00080     EXPECT_EQ("00:00:01", StringUtils::toTimeString(1));
00081     EXPECT_EQ("49:40:00", StringUtils::toTimeString(178800));
00082     //EXPECT_EQ("49:40:00", StringUtils::toTimeString(1178800)) << "Something should happen and no error.";
00083 }
00084 
00085 /* Tests the method escapeXML. */
00086 TEST(StringUtils, test_method_escapeXML) {  
00087     string str;
00088     EXPECT_EQ("", StringUtils::escapeXML(str));
00089     EXPECT_EQ("test", StringUtils::escapeXML("test"))<< "nothing to be replaced.";
00090     EXPECT_EQ("test&apos;s", StringUtils::escapeXML("test's"))<< "' must be replaced.";
00091     EXPECT_EQ("1&lt;2", StringUtils::escapeXML("1<2"))<< "< must be replaced.";
00092     EXPECT_EQ("2&gt;1", StringUtils::escapeXML("2>1"))<< "> must be replaced.";
00093     EXPECT_EQ("M&amp;M", StringUtils::escapeXML("M&M"))<< "& must be replaced.";
00094     EXPECT_EQ("&quot;test&quot;", StringUtils::escapeXML("\"test\""))<< "\" must be replaced.";
00095 }

Generated on Wed May 5 00:06:36 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6