StringTest.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "StringTest.h"
00018 #include <assert.h>
00019
00020
00021 int main(int argc, char ** argv)
00022 {
00023
00024 testAsInteger();
00025
00026 testReadLine();
00027 }
00028
00029 void testAsInteger()
00030 {
00031
00032 String intString = "123";
00033 String negIntString = "-123";
00034 assert(intString.AsInteger() == 123);
00035 assert(negIntString.AsInteger() == -123);
00036
00037
00038
00039 long retValue;
00040 assert(intString.AsInteger(retValue));
00041 assert(retValue == 123);
00042 assert(negIntString.AsInteger(retValue));
00043 assert(retValue == -123);
00044
00045
00046
00047
00048
00049
00050 String nonIntString = "abd";
00051 assert(nonIntString.AsInteger() == 0);
00052 assert(!nonIntString.AsInteger(retValue));
00053
00054 nonIntString = "12ab33";
00055 assert(nonIntString.AsInteger() == 12);
00056 assert(!nonIntString.AsInteger(retValue));
00057 assert(retValue == 12);
00058 nonIntString = "as12ab3a4sd";
00059 assert(nonIntString.AsInteger() == 0);
00060 assert(!nonIntString.AsInteger(retValue));
00061 assert(retValue == 0);
00062
00063 nonIntString = "-12ab3a4sd";
00064 assert(nonIntString.AsInteger() == -12);
00065 assert(!nonIntString.AsInteger(retValue));
00066 assert(retValue == -12);
00067 nonIntString = "-as12ab3a4sd";
00068 assert(nonIntString.AsInteger() == 0);
00069 assert(!nonIntString.AsInteger(retValue));
00070 assert(retValue == 0);
00071 nonIntString = "as-12ab3a4sd";
00072 assert(nonIntString.AsInteger() == 0);
00073 assert(!nonIntString.AsInteger(retValue));
00074 assert(retValue == 0);
00075 nonIntString = "as12-ab3a4sd";
00076 assert(nonIntString.AsInteger() == 0);
00077 assert(!nonIntString.AsInteger(retValue));
00078 assert(retValue == 0);
00079 }
00080
00081 int temp1 = 0;
00082
00083 void testReadLine()
00084 {
00085 IFILE filePtr = ifopen("testFiles/testFile.txt", "rb");
00086 assert(filePtr != NULL);
00087
00088 String line = "";
00089 line.ReadLine(filePtr);
00090
00091 assert(line == " Hello, I am a testFile. ");
00092
00093 line.Trim();
00094 assert(line == "Hello, I am a testFile.");
00095
00096
00097
00098
00099
00100
00101 line.ReadLine(filePtr);
00102 assert(temp1 == 0);
00103 testMethod(line);
00104 assert(temp1 == 1);
00105
00106
00107 line.ReadLine(filePtr);
00108 line.Trim();
00109
00110 assert(line == "ThirdLine.");
00111
00112 ifclose(filePtr);
00113 }
00114
00115
00116 void testMethod(String temp)
00117 {
00118 temp1 = 1;
00119 }