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
00026
00027
00028
00029 #include <iostream>
00030 #include <algorithm>
00031 #include <sstream>
00032 #include <stdexcept>
00033 #include <functional>
00034
00035 #include "TList.h"
00036 #include "TObjString.h"
00037 #include "TObjArray.h"
00038 #include "TMap.h"
00039 #include "TBtree.h"
00040 #include "TOrdCollection.h"
00041 #include "TRefArray.h"
00042
00043 #include "stressIterators.h"
00044
00045 const char * const cszValue("value");
00046
00047 using namespace std;
00048
00049 template<class __T>
00050 void fill_container(__T* _container, Int_t _count)
00051 {
00052 _container->SetOwner();
00053
00054 ostringstream ss;
00055 for (int i = 0; i < _count; ++i) {
00056 ss << "test string #" << i;
00057 TObjString *s(new TObjString(ss.str().c_str()));
00058 _container->Add(s);
00059 ss.str("");
00060 }
00061 }
00062
00063 template<>
00064 void fill_container<TMap>(TMap* _container, Int_t _count)
00065 {
00066 _container->SetOwner();
00067
00068 ostringstream ss;
00069 for (int i = 0; i < _count; ++i) {
00070 ss << "test string #" << i;
00071 TObjString *s(new TObjString(ss.str().c_str()));
00072 _container->Add(s, new TObjString(cszValue));
00073 ss.str("");
00074 }
00075 }
00076
00077
00078 void stressIterators() throw(exception)
00079 {
00080 const Int_t size = 15;
00081
00082 ostringstream ss;
00083
00084 {
00085
00086 TList list;
00087 fill_container(&list, size);
00088
00089 cout << "#1 ====================================" << endl;
00090 cout << "-----> " << "TestContainer_for_each<TList>(list, list.GetSize())" << endl;
00091 TestContainer_for_each<TList>(list, list.GetSize());
00092
00093 cout << "\n#2 ====================================" << endl;
00094 cout << "-----> " << "TestContainer_find_if<TList>(list, \"test string #3\")" << endl;
00095 TestContainer_find_if<TList>(list, "test string #3");
00096
00097 cout << "\n#3 ====================================" << endl;
00098 cout << "-----> " << "TestContainer_count_if<TList>(list, \"test string #3\", 1)" << endl;
00099
00100 TestContainer_count_if<TList>(list, "test string #3", 1);
00101 }
00102
00103 {
00104
00105 TObjArray obj_array(size);
00106 fill_container(&obj_array, size);
00107
00108 cout << "\n#4 ====================================" << endl;
00109 cout << "-----> " << "TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize())" << endl;
00110 TestContainer_for_each<TObjArray>(obj_array, obj_array.GetSize());
00111
00112 cout << "\n#5 ====================================" << endl;
00113 cout << "-----> " << "TestContainer_find_if<TObjArray>(obj_array, \"test string #3\")" << endl;
00114 TestContainer_find_if<TObjArray>(obj_array, "test string #3");
00115
00116 cout << "\n#6 ====================================" << endl;
00117 cout << "-----> " << "TestContainer_count_if<TObjArray>(obj_array, \"test string #3\", 1)" << endl;
00118
00119 TestContainer_count_if<TObjArray>(obj_array, "test string #3", 1);
00120 }
00121
00122 {
00123
00124 TMap map_container(size);
00125 fill_container(&map_container, size);
00126
00127 cout << "\n#7 ====================================" << endl;
00128 cout << "-----> " << "TestContainer_for_each<TMap>(map_container, map_container.GetSize())" << endl;
00129 TestContainer_for_each<TMap>(map_container, map_container.GetSize());
00130 cout << "\n#8 ====================================" << endl;
00131 cout << "-----> " << "TestContainer_for_each2<TMap>(map_container)" << endl;
00132 TestContainer_for_each2<TMap>(map_container);
00133 cout << "\n#9 ====================================" << endl;
00134 cout << "-----> " << "TestContainer_find_if<TMap>(map_container, cszValue)" << endl;
00135 TestContainer_find_if<TMap>(map_container, cszValue);
00136 cout << "\n#10 ====================================" << endl;
00137 cout << "-----> " << "TestContainer_count_if<TMap>(map_container, cszValue, map_container.GetSize())" << endl;
00138 TestContainer_count_if<TMap>(map_container, cszValue, map_container.GetSize());
00139 }
00140
00141 {
00142
00143 TBtree btree_container;
00144 fill_container(&btree_container, size);
00145
00146 cout << "\n#11 ====================================" << endl;
00147 cout << "-----> " << "TestContainer_for_each<TBtree>(btree_container, btree_container.GetSize())" << endl;
00148 TestContainer_for_each<TBtree>(btree_container, btree_container.GetSize());
00149 cout << "\n#12 ====================================" << endl;
00150 cout << "-----> " << "TestContainer_find_if<TBtree>(btree_container, \"test string #3\")" << endl;
00151 TestContainer_find_if<TBtree>(btree_container, "test string #3");
00152 cout << "\n#13 ====================================" << endl;
00153 cout << "-----> " << "TestContainer_count_if<TBtree>(btree_container, \"test string #3\", 1)" << endl;
00154 TestContainer_count_if<TBtree>(btree_container, "test string #3", 1);
00155 }
00156
00157 {
00158
00159 TOrdCollection container;
00160 fill_container(&container, size);
00161
00162 cout << "\n#14 ====================================" << endl;
00163 cout << "-----> " << "TestContainer_for_each<TOrdCollection>(container, container.GetSize())" << endl;
00164 TestContainer_for_each<TOrdCollection>(container, container.GetSize());
00165 cout << "\n#15 ====================================" << endl;
00166 cout << "-----> " << "TestContainer_find_if<TOrdCollection>(container, \"test string #3\");" << endl;
00167 TestContainer_find_if<TOrdCollection>(container, "test string #3");
00168 cout << "\n#16 ====================================" << endl;
00169 cout << "-----> " << "TestContainer_count_if<TOrdCollection>(container, \"test string #3\", 1)" << endl;
00170 TestContainer_count_if<TOrdCollection>(container, "test string #3", 1);
00171 }
00172
00173 {
00174
00175 TRefArray container;
00176 fill_container(&container, size);
00177
00178 cout << "\n#17 ====================================" << endl;
00179 cout << "-----> " << "TestContainer_for_each<TRefArray>(container, container.GetSize())" << endl;
00180 TestContainer_for_each<TRefArray>(container, container.GetLast()+1);
00181 cout << "\n#18 ====================================" << endl;
00182 cout << "-----> " << "TestContainer_find_if<TOrdCollection>(container, \"test string #3\");" << endl;
00183 TestContainer_find_if<TRefArray>(container, "test string #3");
00184 cout << "\n#19 ====================================" << endl;
00185 cout << "-----> " << "TestContainer_count_if<TOrdCollection>(container, \"test string #3\", 1)" << endl;
00186 TestContainer_count_if<TRefArray>(container, "test string #3", 1);
00187 }
00188
00189 }
00190
00191
00192
00193 int main()
00194 {
00195 try {
00196
00197 stressIterators();
00198
00199 } catch (const exception &e) {
00200 cerr << "Test has failed!" << endl;
00201 cerr << "Detailes: " << e.what() << endl;
00202 return 1;
00203 } catch (...) {
00204 cerr << "Test has failed!" << endl;
00205 cerr << "Unexpected error occurred." << endl;
00206 return 1;
00207 }
00208
00209 cout << "\nTest successfully finished!" << endl;
00210 return 0;
00211 }