Files Classes Functions Hierarchy
#include <stringserializationtest.h>
Static Public Member Functions | |
| static void | test01 () |
| Write and read a double array. | |
| static void | test02 () |
| Write and read a 2D array of points. | |
| static void | test03 () |
| Test file serialization. | |
| static void | test04 () |
| Test vectorfile serialization. | |
| static int | unittest01 () |
| Unit test htmlstring. | |
Static Public Attributes | |
| static string | doc [] |
| Brief description of each test. | |
Definition at line 8 of file stringserializationtest.h.
| void stringserializationtest::test01 | ( | ) | [static] |
Write and read a double array.
Definition at line 21 of file stringserializationtest.cpp.
References vectorstring::deserialize(), vectorstring::serialize(), and SHOW.
Referenced by main().
00022 { 00023 double data[5] = {1.0,3.0,5.0,7.0,9.0}; 00024 vector<double> v1(data,data+5); 00025 00026 cout << "Writing a vector to a string." << endl; 00027 00028 bool result; 00029 string str; 00030 result=vectorstring::serialize(str,v1); 00031 cout << SHOW(result) << endl; 00032 cout << "*" << str << "*" << endl; 00033 cout << endl; 00034 00035 cout << "Reading a vector from a string - expecting result=1." << endl; 00036 vector<double> v3; 00037 result=vectorstring::deserialize(v3,str); 00038 cout << SHOW(result) << endl; 00039 cout << SHOW(v3.size()) << endl; 00040 cout << v3 << endl; 00041 cout << endl; 00042 00043 cout << "Putting some garbage on the end of the string - expecting result=0." << endl; 00044 str += " crap"; 00045 cout << "Reading a vector from a string." << endl; 00046 vector<double> v2; 00047 result=vectorstring::deserialize(v2,str); 00048 cout << SHOW(result) << endl; 00049 cout << SHOW(v2.size()) << endl; 00050 cout << v2 << endl; 00051 }
| void stringserializationtest::test02 | ( | ) | [static] |
Write and read a 2D array of points.
Definition at line 53 of file stringserializationtest.cpp.
References vectorstring::deserialize(), print(), vectorstring::serialize(), and SHOW.
Referenced by main().
00054 { 00055 cout << "Testing vectorstring serialization with a point2<double> type." << endl; 00056 00057 typedef point2<double> pt2; 00058 00059 pt2 data[3] = { pt2(.2,.3), pt2(-.1,0.0), pt2(5.0,4.0) }; 00060 vector<pt2> v1(data,data+3); 00061 00062 bool result; 00063 string str; 00064 result=vectorstring::serialize(str,v1); 00065 cout << SHOW(result) << endl; 00066 cout << "*" << str << "*" << endl; 00067 cout << endl; 00068 00069 cout << "Reading a vector from a string - expecting result=1." << endl; 00070 vector<pt2> v3; 00071 result=vectorstring::deserialize(v3,str); 00072 cout << SHOW(result) << endl; 00073 cout << SHOW(v3.size()) << endl; 00074 cout << print(v3,"\n") << endl; 00075 cout << endl; 00076 }
| void stringserializationtest::test03 | ( | ) | [static] |
Test file serialization.
Definition at line 78 of file stringserializationtest.cpp.
References filestring::deserialize(), filestring::serialize(), and SHOW.
Referenced by main().
00079 { 00080 string s1; 00081 s1 += "This is a silly sentence. I have to make a\n"; 00082 s1 += "file from a string. Hopefully this will be\n"; 00083 s1 += "written out as a file and converted back as\n"; 00084 s1 += " a string. Then I will compare the strings."; 00085 00086 cout << "Writing a string to a file." << endl; 00087 cout << "string begin:" << endl; 00088 cout << s1; 00089 cout << "string end:" << endl; 00090 cout << endl; 00091 stringc filename("temp01.txt"); 00092 cout << "filename: " << filename << endl; 00093 cout << "Writing " << filename << endl; 00094 filestring::deserialize(filename,s1); 00095 string s2; 00096 filestring::serialize(s2,filename); 00097 cout << s2 << endl; 00098 cout << SHOW(s1.size()) << endl; 00099 cout << SHOW(s2.size()) << endl; 00100 cout << SHOW((s1==s2)) << endl; 00101 }
| void stringserializationtest::test04 | ( | ) | [static] |
Test vectorfile serialization.
Definition at line 104 of file stringserializationtest.cpp.
References vectorfile::deserialize(), vectorfile::serialize(), and SHOW.
Referenced by main().
00105 { 00106 typedef point2<double> pt2; 00107 00108 pt2 data[3] = { pt2(.2,.3), pt2(-.1,0.0), pt2(5.0,4.0) }; 00109 vector<pt2> v1(data,data+3); 00110 00111 bool result; 00112 string filename="temp02.txt"; 00113 00114 cout << "Writing 2D vector to file " << filename << endl; 00115 result=vectorfile::serialize(filename,v1); 00116 assert(result); 00117 vector<pt2> v2; 00118 result=vectorfile::deserialize(v2,filename); 00119 cout << v2 << endl; 00120 00121 cout << SHOW(v1.size()) << endl; 00122 cout << SHOW(v2.size()) << endl; 00123 cout << "Testing if the two vectors are equal." << endl; 00124 cout << SHOW((v1==v2)) << endl; 00125 }
| int stringserializationtest::unittest01 | ( | ) | [static] |
Unit test htmlstring.
Definition at line 128 of file stringserializationtest.cpp.
References assertreturnOS, htmlstring::ishtml(), htmlstring::serialize(), htmlstring::serializeInverse(), and SHOW.
Referenced by main().
00129 { 00130 00131 string s1="&x1->free_mem();"; 00132 00133 assertreturnOS(htmlstring::ishtml(s1)); 00134 00135 string s2; 00136 htmlstring::serialize(s2,s1); 00137 cout << SHOW(s1) << endl; 00138 cout << SHOW(s2) << endl; 00139 string s3; 00140 htmlstring::serializeInverse(s3,s2); 00141 cout << SHOW(s3) << endl; 00142 00143 assertreturnOS(s1==s3); 00144 00145 return 0; 00146 }
string stringserializationtest::doc [static] |
Initial value:
{
"",
"Write and read a double array.",
"Write and read a 2D array of points.",
"Test file serialization.",
"Test vectorfile serialization.",
"Unit test htmlstring."
}
Definition at line 14 of file stringserializationtest.h.
Referenced by main().
1.5.8