00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <Basics.H>
00025 #include "Atom.H"
00026
00027 using std::cerr;
00028 using std::endl;
00029
00030 static int error_cnt = 0;
00031
00032 static void failure(char *msg) throw ()
00033 {
00034 cerr << "Failure: " << msg << endl;
00035 error_cnt++;
00036 }
00037
00038 int main()
00039 {
00040
00041 Atom a1, a2, a3(""), a4("");
00042 if (a1 != a2) failure("default (empty) atoms not equal");
00043 if (a1 != a3) failure("default atom and empty atom not equal");
00044 if (a3 != a4) failure("empty atoms not equal");
00045
00046
00047 const char *str = "atom test";
00048 Atom a5(str), a6(str), a7("ATOM TEST");
00049 if (a5 != a6) failure("equal atoms not considered equal");
00050 if (!(a5 == a6)) failure("equal atoms not considered equal");
00051 if (a5 == a7) failure("unequal atoms considered equal");
00052 if (!(a5 != a7)) failure("unequal atoms considered equal");
00053
00054
00055 Text txt(str);
00056 Atom a8(a5), a9(txt), a10('c'), a11("c"), a12(str), a13(str, strlen(str));
00057 if (a5 != a8) failure("atom constructor from atom failed");
00058 if (a5 != a9) failure("atom constructor from text failed");
00059 if (a10 != a11) failure("atom constructor from char failed");
00060 if (a5 != a12) failure("atom constructor from string failed");
00061 if (a5 != a13) failure("atom constructor from bytes failed");
00062
00063
00064 Atom a14;
00065 a14 = str;
00066 if (a5 != a14) failure("atom assignment operator from string failed");
00067 a14 = txt;
00068 if (a5 != a14) failure("atom assignment operator from text failed");
00069 a14 = a5;
00070 if (a5 != a14) failure("atom assignment operator from atom failed");
00071
00072
00073 char *cat = "cat", *dog = "dog";
00074 Text t1(cat), t2(dog), t3 = t1 + t2;
00075 Atom a15(t3), a16(cat), a17(cat), a18(cat), a19(dog);
00076 a16 += dog;
00077 if (a15 != a16) failure("atom += on string failed");
00078 a17 += t2;
00079 if (a15 != a17) failure("atom += on text failed");
00080 a18 += a19;
00081 if (a15 != a18) failure("atom += on atom failed");
00082
00083 if (error_cnt > 0)
00084 cerr << error_cnt << " failures reported\n";
00085 else
00086 cerr << "All tests passed!\n";
00087 return error_cnt;
00088 }