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
00031 #ifndef __VGTL_TEST_H
00032 #define __VGTL_TEST_H
00033
00034 #include <algorithm>
00035 #include <vgtl_helpers.h>
00036 #include <vgtl_gdata.h>
00037
00038 __VGTL_BEGIN_NAMESPACE
00039
00040 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00041 #pragma set woff 1209
00042 #endif
00043
00048 template <class _Walker, class _Test>
00049 void recursive_consistency_test(_Walker __w, const _Test& __t)
00050 {
00051 typename _Walker::children_iterator __cit, __ec, __ccit;
00052 typename _Walker::parents_iterator __pit, __ep, __ppit;
00053 _Walker __wc, __wp;
00054 bool am_ground, am_sky, have_virtual;
00055 unsigned int n_cids, n_pids;
00056
00057 am_ground = __w.is_ground();
00058 am_sky = __w.is_sky();
00059 if(!am_sky)
00060 {
00061 __ec = __w.child_end();
00062 for(__cit = __w.child_begin(); __cit != __ec; ++__cit)
00063 {
00064 __wc = __w >> __cit;
00065 have_virtual = __wc.is_sky();
00066 for(__ccit = __w.child_begin(); __ccit != __cit; ++__ccit)
00067 if(__wc == __w >> __ccit)
00068 break;
00069 if(__ccit != __cit)
00070 continue;
00071 n_cids = 1;
00072 for(++__ccit; __ccit != __ec; ++__ccit)
00073 if(__wc == __w >> __ccit) n_cids++;
00074 if(am_ground && __wc.n_parents() != 1)
00075 {
00076 if(__wc.is_sky())
00077 std::cerr << "sky has parent ground && n_parents != 1" << std::endl;
00078 else
00079 std::cerr << __t(*__wc) << " has n_parents != 1 && parent ground!"
00080 << std::endl;
00081 }
00082 __ep = __wc.parent_end();
00083 n_pids = 0;
00084 for(__pit = __wc.parent_begin(); __pit != __ep; ++__pit)
00085 {
00086 if(__w == __wc << __pit)
00087 n_pids++;
00088 }
00089 if(n_cids != n_pids)
00090 {
00091 if(__wc.is_sky())
00092 {
00093 if(am_ground)
00094 std::cerr << "child sky has " << n_pids <<
00095 " parent(s) ground, needs " << n_cids << "!" << std::endl;
00096 else
00097 std::cerr << "child sky has " << n_pids << " parent(s) " <<
00098 __t(*__w) << ", needs " << n_cids << "!" << std::endl;
00099 }
00100 else if(am_ground)
00101 std::cerr << "child " << __t(*__wc) << " has " << n_pids <<
00102 " parent(s) ground, needs " << n_cids << "!" << std::endl;
00103 else
00104 std::cerr << "child " << __t(*__wc) << " has " << n_pids <<
00105 " parent(s) " << __t(*__w) << ", needs " << n_cids << "!" <<
00106 std::endl;
00107 }
00108 recursive_consistency_test(__wc, __t);
00109 }
00110 if(have_virtual && __w.n_children() != 1)
00111 {
00112 if(am_ground)
00113 std::cerr << "ground has child sky && n_children != 1" << std::endl;
00114 else
00115 std::cerr << __t(*__w) << " has n_children != 1 && child sky!"
00116 << std::endl;
00117 }
00118 }
00119 if(!am_ground)
00120 {
00121 __ep = __w.parent_end();
00122 for(__pit = __w.parent_begin(); __pit != __ep; ++__pit)
00123 {
00124 __wp = __w << __pit;
00125 have_virtual = __wp.is_ground();
00126 for(__ppit = __w.parent_begin(); __ppit != __pit; ++__ppit)
00127 if(__wp == __w << __ppit)
00128 break;
00129 if(__ppit != __pit)
00130 continue;
00131 n_pids = 1;
00132 for(++__ppit; __ppit != __ep; ++__ppit)
00133 if(__wp == __w << __ppit) n_pids++;
00134 if(am_sky && __wp.n_children() != 1)
00135 {
00136 if(__wp.is_ground())
00137 std::cerr << "ground has child sky && n_children != 1" << std::endl;
00138 else
00139 std::cerr << __t(*__wp) << " has n_children != 1 && child sky!"
00140 << std::endl;
00141 }
00142 __ec = __wp.child_end();
00143 n_cids = 0;
00144 for(__cit = __wp.child_begin(); __cit != __ec; ++__cit)
00145 {
00146 if(__w == __wp >> __cit)
00147 n_cids++;
00148 }
00149 if(n_cids != n_pids)
00150 {
00151 if(__wp.is_ground())
00152 {
00153 if(am_sky)
00154 std::cerr << "parent ground has " << n_cids <<
00155 " child(ren) sky, needs " << n_pids << "!" << std::endl;
00156 else
00157 std::cerr << "parent ground has " << n_cids << " child(ren) " <<
00158 __t(*__w) << ", needs " << n_pids << "!" << std::endl;
00159 }
00160 else if(am_ground)
00161 std::cerr << "parent " << __t(*__wp) << " has " << n_cids <<
00162 " child(ren) sky, needs " << n_pids << "!" << std::endl;
00163 else
00164 std::cerr << "parent " << __t(*__wp) << " has " << n_cids <<
00165 " child(ren) " << __t(*__w) << ", needs " << n_pids << "!" <<
00166 std::endl;
00167 }
00168 }
00169 if(have_virtual && __w.n_parents() != 1)
00170 {
00171 if(am_sky)
00172 std::cerr << "sky has parent ground && n_parents != 1" << std::endl;
00173 else
00174 std::cerr << __t(*__w) << " has n_parents != 1 && parent ground!"
00175 << std::endl;
00176 }
00177 }
00178 }
00179
00180 #if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
00181 #pragma reset woff 1209
00182 #endif
00183
00184 __VGTL_END_NAMESPACE
00185
00186 #endif
00187
00188
00189
00190