summaryrefslogtreecommitdiffstats
path: root/Source/kwsys/testSystemTools.cxx
diff options
context:
space:
mode:
authorKen Martin <ken.martin@kitware.com>2006-07-25 16:08:05 (GMT)
committerKen Martin <ken.martin@kitware.com>2006-07-25 16:08:05 (GMT)
commitb379666b395622384e95d4eb39c59da6d40cd398 (patch)
tree72bcef9eed7605b7542ef526dda66f400b7dbf3c /Source/kwsys/testSystemTools.cxx
parentc3412def5d4456291eb2afad0404d984e2d32fa5 (diff)
downloadCMake-b379666b395622384e95d4eb39c59da6d40cd398.zip
CMake-b379666b395622384e95d4eb39c59da6d40cd398.tar.gz
CMake-b379666b395622384e95d4eb39c59da6d40cd398.tar.bz2
BUG: some bug fixes, better docs, and more coverage
Diffstat (limited to 'Source/kwsys/testSystemTools.cxx')
-rw-r--r--Source/kwsys/testSystemTools.cxx147
1 files changed, 147 insertions, 0 deletions
diff --git a/Source/kwsys/testSystemTools.cxx b/Source/kwsys/testSystemTools.cxx
index 2106f7a..f5550ae 100644
--- a/Source/kwsys/testSystemTools.cxx
+++ b/Source/kwsys/testSystemTools.cxx
@@ -119,6 +119,151 @@ bool CheckDetectFileType()
}
//----------------------------------------------------------------------------
+bool CheckStringOperations()
+{
+ bool res = true;
+
+ kwsys_stl::string test = "mary had a little lamb.";
+ if (kwsys::SystemTools::CapitalizedWords(test) != "Mary Had A Little Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with CapitalizedWords "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ test = "Mary Had A Little Lamb.";
+ if (kwsys::SystemTools::UnCapitalizedWords(test) !=
+ "mary had a little lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with UnCapitalizedWords "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ test = "MaryHadTheLittleLamb.";
+ if (kwsys::SystemTools::AddSpaceBetweenCapitalizedWords(test) !=
+ "Mary Had The Little Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with AddSpaceBetweenCapitalizedWords "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ const char * cres =
+ kwsys::SystemTools::AppendStrings("Mary Had A"," Little Lamb.");
+ if (strcmp(cres,"Mary Had A Little Lamb."))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with AppendStrings "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ cres =
+ kwsys::SystemTools::AppendStrings("Mary Had"," A ","Little Lamb.");
+ if (strcmp(cres,"Mary Had A Little Lamb."))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with AppendStrings "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ if (kwsys::SystemTools::CountChar("Mary Had A Little Lamb.",'a') != 3)
+ {
+ kwsys_ios::cerr
+ << "Problem with CountChar "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ cres =
+ kwsys::SystemTools::RemoveChars("Mary Had A Little Lamb.","aeiou");
+ if (strcmp(cres,"Mry Hd A Lttl Lmb."))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with RemoveChars "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ cres =
+ kwsys::SystemTools::RemoveCharsButUpperHex("Mary Had A Little Lamb.");
+ if (strcmp(cres,"A"))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with RemoveCharsButUpperHex "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ char *cres2 = new char [strlen("Mary Had A Little Lamb.")+1];
+ strcpy(cres2,"Mary Had A Little Lamb.");
+ kwsys::SystemTools::ReplaceChars(cres2,"aeiou",'X');
+ if (strcmp(cres2,"MXry HXd A LXttlX LXmb."))
+ {
+ delete [] cres2;
+ kwsys_ios::cerr
+ << "Problem with ReplaceChars "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres2;
+
+ if (!kwsys::SystemTools::StringStartsWith("Mary Had A Little Lamb.",
+ "Mary "))
+ {
+ kwsys_ios::cerr
+ << "Problem with StringStartsWith "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ if (!kwsys::SystemTools::StringEndsWith("Mary Had A Little Lamb.",
+ " Lamb."))
+ {
+ kwsys_ios::cerr
+ << "Problem with StringEndsWith "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ cres = kwsys::SystemTools::DuplicateString("Mary Had A Little Lamb.");
+ if (strcmp(cres,"Mary Had A Little Lamb."))
+ {
+ delete [] cres;
+ kwsys_ios::cerr
+ << "Problem with DuplicateString "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+ delete [] cres;
+
+ test = "Mary Had A Little Lamb.";
+ if (kwsys::SystemTools::CropString(test,13) !=
+ "Mary ...Lamb.")
+ {
+ kwsys_ios::cerr
+ << "Problem with CropString "
+ << TEST_SYSTEMTOOLS_SRC_FILE << kwsys_ios::endl;
+ res = false;
+ }
+
+ return res;
+}
+
+//----------------------------------------------------------------------------
int main(/*int argc, char* argv*/)
{
bool res = true;
@@ -145,5 +290,7 @@ int main(/*int argc, char* argv*/)
res &= CheckDetectFileType();
+ res &= CheckStringOperations();
+
return res ? 0 : 1;
}