Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

TestAtom.C

Go to the documentation of this file.
00001 // Copyright (C) 2001, Compaq Computer Corporation
00002 
00003 // This file is part of Vesta.
00004 
00005 // Vesta is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public
00007 // License as published by the Free Software Foundation; either
00008 // version 2.1 of the License, or (at your option) any later version.
00009 
00010 // Vesta is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013 // Lesser General Public License for more details.
00014 
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with Vesta; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 
00019 // Last modified on Thu May 27 00:26:34 EDT 2004 by ken@xorian.net
00020 //      modified on Mon May  3 16:04:42 PDT 1999 by heydon
00021 
00022 // Program to test the implementation of the Atom interface
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     // Test equality of empty strings.
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     // Test general equality and inequality
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     // Test various constructors
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     // Test assignment
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     // Test destructive concatenation
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 }

Generated on Mon May 8 00:48:30 2006 for Vesta by  doxygen 1.4.2