00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00058 if (cs.length() != NumStrings) {
00059 cerr << "\n Error: incorrect length " << cs.length()
00060 << "; should be " << NumStrings << endl;
00061 }
00062
00063
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;
00082 chars_seq cs2(10, 100);
00083 chars_seq cs3(NumStrings);
00084 chars_seq cs4(NumStrings, (MaxLen/2)*NumStrings);
00085
00086
00087 cerr << "Initializing sequences...";
00088 for (int i = 0; i < NumStrings; i++) {
00089
00090 UpdateBuff(i % MaxLen);
00091
00092
00093 cs1.append(buff);
00094 cs2.append(buff);
00095 cs3.append(buff);
00096 cs4.append(buff);
00097 }
00098 cerr << "done\n";
00099
00100
00101 Verify(cs1, "cs1");
00102 Verify(cs2, "cs2");
00103 Verify(cs3, "cs3");
00104 Verify(cs4, "cs4");
00105 }