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

TestCharsSeq.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 Tue Mar 22 13:01:41 EST 2005 by ken@xorian.net  
00020 //      modified on Sat Feb 12 17:42:46 PST 2000 by mann  
00021 //      modified on Fri Jun 13 11:08:50 PDT 1997 by heydon
00022 
00023 // Program to test the "chars_seq.H" interface
00024 
00025 #include <Basics.H>
00026 #include <chars_seq.H>
00027 
00028 using std::endl;
00029 using std::cout;
00030 using std::cerr;
00031 
00032 const int MaxLen = 76;
00033 const int NumStrings = 10000;
00034 
00035 static char buff[MaxLen+1];
00036 
00037 void UpdateBuff(int len) throw ()
00038 {
00039     if (len > 0) {
00040         int modTen = len % 10;
00041         if (modTen != 0) {
00042             buff[len-1] = '0' + modTen;
00043         } else {
00044             for (int j = len - 10; j < len - 1; j++) {
00045                 buff[j] = '.';
00046                 buff[len - 1] = '0' + (len / 10);
00047             }
00048         }
00049     }
00050     buff[len] = '\0';
00051 }
00052 
00053 void Verify(const chars_seq &cs, char *nm) throw ()
00054 {
00055     cerr << "Verifying chars_seq " << nm << "...";
00056 
00057     // verify length
00058     if (cs.length() != NumStrings) {
00059         cerr << "\n  Error: incorrect length " << cs.length()
00060              << "; should be " << NumStrings << endl;
00061     }
00062 
00063     // verify contents
00064     for (int i = 0; i < cs.length(); i ++) {
00065         if (cs[i] == NULL)
00066           {
00067             cerr << "\n Error: string " << i << " is NULL" << endl;
00068           }
00069         UpdateBuff(i % MaxLen);
00070         if (strcmp(buff, cs[i]) != 0) {
00071           cerr << "\n Error: string " << i << " is incorrect:" << endl
00072                << "  is:        " << cs[i] << endl
00073                << "  should be: " << buff << endl;
00074         }
00075     }
00076     cerr << "done\n";
00077 }
00078 
00079 int main() 
00080 {
00081     chars_seq cs1;                // zero initial storage
00082     chars_seq cs2(10, 100);       // small initial storage
00083     chars_seq cs3(NumStrings);    // correct len, but no bytes
00084     chars_seq cs4(NumStrings, (MaxLen/2)*NumStrings); // no expansion reqd
00085 
00086     // add strings to sequences
00087     cerr << "Initializing sequences...";
00088     for (int i = 0; i < NumStrings; i++) {
00089         // form string
00090         UpdateBuff(i % MaxLen);
00091 
00092         // add string to each "chars_seq"
00093         cs1.append(buff);
00094         cs2.append(buff);
00095         cs3.append(buff);
00096         cs4.append(buff);
00097     }
00098     cerr << "done\n";
00099 
00100     // verify results
00101     Verify(cs1, "cs1");
00102     Verify(cs2, "cs2");
00103     Verify(cs3, "cs3");
00104     Verify(cs4, "cs4");
00105 }

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