ARB
cb.cxx
Go to the documentation of this file.
1 // ============================================================== //
2 // //
3 // File : cb.cxx //
4 // Purpose : currently only a test sandbox //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in August 2011 //
7 // Institute of Microbiology (Technical University Munich) //
8 // http://www.arb-home.de/ //
9 // //
10 // ============================================================== //
11 
12 #include <cb.h>
13 #include <string>
14 #include <stdint.h>
15 
16 using namespace std;
17 
18 STATIC_ASSERT(sizeof(int*) == sizeof(AW_CL)); // important for casted db-callback type (GB_CB vs GB_CB_wanted..)
19 
20 // --------------------------------------------------------------------------------
21 
22 #ifdef UNIT_TESTS
23 #include <test_unit.h>
24 
25 // ---------------------------------------------
26 // compile time test of type inspection
27 
28 #define COMPILE_ASSERT_POINTER_TO(ISTYPE,POINTER) \
29  STATIC_ASSERT(TypeT<POINTER>::IsPtrT && \
30  TypeT<CompountT<POINTER>::BaseT>::ISTYPE)
31 
32 typedef int (*somefun)(const char *);
33 static int myfun(const char *) { return 0; }
34 static somefun sfun = myfun;
35 
36 enum someenum { A, B };
37 
38 class someclass { public : int memfun() { return -1; } };
39 
40 
46 
48 COMPILE_ASSERT_POINTER_TO(IsFundaT, int*);
49 COMPILE_ASSERT_POINTER_TO(IsPtrT, int**);
51 
53 STATIC_ASSERT(IsFundaT<typeof(myfun)>::No);
55 
56 STATIC_ASSERT(IsFunctionT<typeof(myfun)>::Yes);
57 
58 STATIC_ASSERT(IsFunctionT<somefun>::No); // somefun is pointer to functiontype
59 COMPILE_ASSERT_POINTER_TO(IsFuncT, somefun);
60 STATIC_ASSERT(IsFunctionT<typeof(sfun)>::No); // sfun is pointer to functiontype
61 COMPILE_ASSERT_POINTER_TO(IsFuncT, typeof(sfun));
65 
68 
70 COMPILE_ASSERT_POINTER_TO(IsEnumT, someenum*);
71 
76 STATIC_ASSERT(IsEnumT<typeof(myfun)>::No);
77 
79 COMPILE_ASSERT_POINTER_TO(IsClassT, someclass*);
80 
86 STATIC_ASSERT(IsClassT<typeof(myfun)>::No);
87 
91 STATIC_ASSERT(TypeT<int[]>::IsArrayT);
92 STATIC_ASSERT(TypeT<int[7]>::IsArrayT);
93 STATIC_ASSERT(TypeT<typeof(myfun)>::IsFuncT);
94 STATIC_ASSERT(TypeT<typeof(&someclass::memfun)>::IsPtrMemT);
97 
98 // -------------------------------------------------------
99 // compile time test of RequiresConstVariant
100 // (should be true, when parameter is mutable)
101 
102 # define CONST_VARIANT_REQUIRED_TESTED CONST_VARIANT_REQUIRED
103 
104 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int) == false);
105 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int) == false);
106 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(volatile int) == false);
107 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const volatile int) == false);
108 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(volatile const int) == false);
109 
110 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int&) == true);
111 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int&) == false);
112 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int*) == true);
113 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int*) == false);
114 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int*const) == true);
115 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int*const) == false);
116 
117 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(GBDATA&) == true);
118 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const GBDATA&) == false);
119 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(GBDATA*) == true);
120 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const GBDATA*) == false);
121 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(GBDATA*const) == true);
122 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const GBDATA*const) == false);
123 
124 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(GB_CB_TYPE) == false);
125 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const GB_CB_TYPE) == false);
126 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(volatile GB_CB_TYPE) == false);
127 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const volatile GB_CB_TYPE) == false);
128 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(volatile const GB_CB_TYPE) == false);
129 
130 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(GB_CB_TYPE&) == true);
131 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const GB_CB_TYPE&) == false);
132 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(GB_CB_TYPE*) == true);
133 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const GB_CB_TYPE*) == false);
134 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(GB_CB_TYPE*const) == true);
135 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const GB_CB_TYPE*const) == false);
136 
137 // not so important (may accept wrong behavior below, because there is no need to use such types as callback parameters!)
138 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int*&) == true);
139 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int*&) == true); // (callers data is 'const int *' and the pointer is mutable)
140 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int*const&) == false); // (callers data is 'int *' and the pointer is immutable)
141 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int*const&) == false);
142 
143 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int**) == true);
144 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int**) == true); // (callers data is 'const int *' and the pointer is mutable)
145 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int*const*) == false); // (callers data is 'int * const' and the pointer is immutable; it's content is mutable but that is out-of-scope here)
146 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int*const*) == false);
147 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int**const) == true); // (callers data is 'const int *' and the pointer is mutable)
148 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int**const) == true);
149 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(int*const*const) == false);
150 STATIC_ASSERT(CONST_VARIANT_REQUIRED_TESTED(const int*const*const) == false);
151 
152 
153 // -----------------------
154 // test callbacks
155 
156 #define TRACE
157 
158 DECLARE_CBTYPE_VV_AND_BUILDERS(CustomCallback, void); // defines makeCustomCallback
159 
160 static uint32_t traceChecksum;
161 const int BUFFERSIZE = 100;
162 static char traceBuffer[BUFFERSIZE];
163 
164 __ATTR__FORMAT(1) static void tracef(const char *format, ...) {
165  va_list parg;
166  va_start(parg, format);
167  int printed = vsnprintf(traceBuffer, BUFFERSIZE, format, parg);
168  va_end(parg);
169 
170 #if defined(TRACE)
171  fputs(traceBuffer, stdout);
172 #endif
173  if (printed >= BUFFERSIZE) {
174  printf("\nprinted=%i\n", printed);
175  }
176  TEST_EXPECT(printed<BUFFERSIZE);
177 
178  traceChecksum = 0;
179  for (int p = 0; p<printed; ++p) {
180  traceChecksum = (traceChecksum<<1)^(traceChecksum>>31)^traceBuffer[p];
181  }
182 }
183 
184 static AW_root *fake_root = (AW_root*)1;
185 static AW_window *fake_win = (AW_window*)2;
186 static GBDATA *fake_gbd = (GBDATA*)3;
187 static AW_awar *fake_awar = (AW_awar*)4;
188 static bool fake_bool = false;
189 static GB_CB_TYPE fake_gbtype = GB_CB_CHANGED;
190 
191 static void rcb0(AW_root *r) {
192  TEST_EXPECT(r == fake_root);
193  tracef("rcb0()\n");
194 }
195 static void rcb1(AW_root *r, const char *name) {
196  TEST_EXPECT(r == fake_root);
197  tracef("rcb1(%s)\n", name);
198 }
199 static void rcb2(AW_root *r, const char *name, int val) {
200  TEST_EXPECT(r == fake_root);
201  tracef("rcb2(%s=%i) [int]\n", name, val);
202 }
203 static void rcb2(AW_root *r, const char *name, long val) {
204  TEST_EXPECT(r == fake_root);
205  tracef("rcb2(%s=%li) [long]\n", name, val);
206 }
207 
208 static void wcb0(AW_window *w) {
209  TEST_EXPECT(w == fake_win);
210  tracef("wcb0()\n");
211 }
212 static void wcb1(AW_window *w, const char *name) {
213  TEST_EXPECT(w == fake_win);
214  tracef("wcb1(%s)\n", name);
215 }
216 static void wcb1(AW_window *w, string *name) {
217  TEST_EXPECT(w == fake_win);
218  tracef("wcb1(%s) [string]\n", name->c_str());
219 }
220 static void wcb2(AW_window *w, const char *name, const char *val) {
221  TEST_EXPECT(w == fake_win);
222  tracef("wcb2(%s=%s) [const char/const char]\n", name, val);
223 }
224 static void wcb2(AW_window *w, const string *name, const string *val) {
225  TEST_EXPECT(w == fake_win);
226  tracef("wcb2(%s=%s) [string/string]\n", name->c_str(), val->c_str());
227 }
228 static void wcb2(AW_window *w, const char *name, int val) {
229  TEST_EXPECT(w == fake_win);
230  tracef("wcb2(%s=%i) [int]\n", name, val);
231 }
232 static void wcb2(AW_window *w, const char *name, long val) {
233  TEST_EXPECT(w == fake_win);
234  tracef("wcb2(%s=%li) [long]\n", name, val);
235 }
236 static void wcb2(AW_window *w, char c, long long val) {
237  TEST_EXPECT(w == fake_win);
238  tracef("wcb2(%c=%lli) [long long]\n", c, val);
239 }
240 
241 static void tacb0(AW_awar *a) {
242  TEST_EXPECT(a == fake_awar);
243  tracef("tacb0()\n");
244 }
245 static void tacb1(AW_awar *a, bool b) {
246  TEST_EXPECT(a == fake_awar);
247  TEST_EXPECT(b == fake_bool);
248  tracef("tacb1()\n");
249 }
250 static void tacb2(AW_awar *a, bool b, const char *name) {
251  TEST_EXPECT(a == fake_awar);
252  TEST_EXPECT(b == fake_bool);
253  tracef("tacb2(%s)\n", name);
254 }
255 static void tacb2(AW_awar *a, bool b, int val) {
256  TEST_EXPECT(a == fake_awar);
257  TEST_EXPECT(b == fake_bool);
258  tracef("tacb2(%i)\n", val);
259 }
260 
261 static void ucb0(UNFIXED) {
262  tracef("ucb0()\n");
263 }
264 static void ucb1(UNFIXED, const char *name) {
265  tracef("ucb1(%s)\n", name);
266 }
267 static void ucb2(UNFIXED, const char *name, int val) {
268  tracef("ucb2(%s=%i) [int]\n", name, val);
269 }
270 static void ucb2(UNFIXED, const char *name, long val) {
271  tracef("ucb2(%s=%li) [long]\n", name, val);
272 }
273 
274 static AW_window *cwcb0(AW_root *r) {
275  TEST_EXPECT(r == fake_root);
276  tracef("cwcb0()\n");
277  return fake_win;
278 }
279 static AW_window *cwcb1(AW_root *r, int x) {
280  TEST_EXPECT(r == fake_root);
281  tracef("cwcb1(%i)\n", x);
282  return fake_win;
283 }
284 static AW_window *cwcb1(AW_root *r, const long *lp) {
285  TEST_EXPECT(r == fake_root);
286  tracef("cwcb1(%li) [long ptr]\n", *lp);
287  return fake_win;
288 }
289 static AW_window *cwcb1(AW_root *r, const int *x) {
290  TEST_EXPECT(r == fake_root);
291  tracef("cwcb1(%i) [const ptr]\n", *x);
292  return fake_win;
293 }
294 static AW_window *cwcb1(AW_root *r, int *x) {
295  TEST_EXPECT(r == fake_root);
296  tracef("cwcb1(%i) [mutable ptr]\n", *x);
297  *x *= 2; // modify callback argument!
298  return fake_win;
299 }
300 static AW_window *cwcb1(AW_root *r, char* s) {
301  TEST_EXPECT(r == fake_root);
302  tracef("cwcb1(%s) [mutable]\n", s);
303  return fake_win;
304 }
305 static AW_window *cwcb1(AW_root *r, const char* s) {
306  TEST_EXPECT(r == fake_root);
307  tracef("cwcb1(%s) [const]\n", s);
308  return fake_win;
309 }
310 static AW_window *cwcb2(AW_root *r, const char *s1, const char *s2) {
311  TEST_EXPECT(r == fake_root);
312  tracef("cwcb2(%s,%s) [const const]\n", s1, s2);
313  return fake_win;
314 }
315 static AW_window *cwcb2(AW_root *r, const char *s1, char *s2) {
316  TEST_EXPECT(r == fake_root);
317  tracef("cwcb2(%s,%s) [const mutable]\n", s1, s2);
318  return fake_win;
319 }
320 
321 static AW_window *cwcb3(AW_root *r, const char *s1, const char *s2) {
322  TEST_EXPECT(r == fake_root);
323  tracef("cwcb3(%s,%s) [const const]\n", s1, s2);
324  return fake_win;
325 }
326 static AW_window *cwcb3(AW_root *r, const char *s1, char *s2) {
327  TEST_EXPECT(r == fake_root);
328  tracef("cwcb3(%s,%s) [const mutable]\n", s1, s2);
329  return fake_win;
330 }
331 static AW_window *cwcb3(AW_root *r, char *s1, const char *s2) {
332  TEST_EXPECT(r == fake_root);
333  tracef("cwcb3(%s,%s) [mutable const]\n", s1, s2);
334  return fake_win;
335 }
336 static AW_window *cwcb3(AW_root *r, char *s1, char *s2) {
337  TEST_EXPECT(r == fake_root);
338  tracef("cwcb3(%s,%s) [mutable mutable]\n", s1, s2);
339  return fake_win;
340 }
341 
342 static void dbcb01(GBDATA *gbd) {
343  TEST_EXPECT(gbd == fake_gbd);
344  tracef("dbcb01()\n");
345 }
346 static void dbcb012(GBDATA *gbd, GB_CB_TYPE t) {
347  TEST_EXPECT(gbd == fake_gbd && t == fake_gbtype);
348  tracef("dbcb012()\n");
349 }
350 static void dbcb02(GB_CB_TYPE t) {
351  tracef("dbcb02(%i)\n", int(t));
352 }
353 static void dbcb1(GBDATA *gbd, int x, GB_CB_TYPE t) {
354  TEST_EXPECT(gbd == fake_gbd && t == fake_gbtype);
355  tracef("dbcb1(%i) [int]\n", x);
356 }
357 static void dbcb1(GBDATA *gbd, const char *n, GB_CB_TYPE t) {
358  TEST_EXPECT(gbd == fake_gbd && t == fake_gbtype);
359  tracef("dbcb1(%s) [const char]\n", n);
360 }
361 
362 static void ccb11(const char *str) {
363  tracef("ccb11(%s)\n", str);
364 }
365 static void ccb12(int i) {
366  tracef("ccb12(%i)\n", i);
367 }
368 static void ccb2(int i, const char *str) {
369  tracef("ccb2(%i,%s)\n", i, str);
370 }
371 
372 static void plaincb() {
373  tracef("plaincb()\n");
374 }
375 static AW_window *cwcb_plain() {
376  tracef("cwcb_plain()\n");
377  return fake_win;
378 }
379 
380 inline void call(const RootCallback& rcb) { rcb(fake_root); }
381 inline void call(const WindowCallback& wcb) { wcb(fake_win); }
382 inline void call(const CreateWindowCallback& cwcb) { TEST_EXPECT(cwcb(fake_root) == fake_win); }
383 inline void call(const DatabaseCallback& dbcb) { dbcb(fake_gbd, fake_gbtype); }
384 inline void call(const TreeAwarCallback& tacb) { tacb(fake_awar, fake_bool); }
385 inline void call(const CustomCallback& ccb) { ccb(); }
386 
387 #define TEST_CB(cb,expectedChecksum) do { \
388  traceChecksum = -666; \
389  call(cb); \
390  TEST_EXPECT_EQUAL(traceChecksum, (uint32_t)expectedChecksum); \
391  } while(0)
392 
393 #define TEST_CB_TRACE(cb,expectedOutput) do { \
394  call(cb); \
395  TEST_EXPECT_EQUAL(traceBuffer, expectedOutput); \
396  } while(0)
397 
398 #define TEST_CB_TRACE__BROKEN(cb,expectedOutput) do { \
399  call(cb); \
400  TEST_EXPECT_EQUAL__BROKEN(traceBuffer, expectedOutput); \
401  } while(0)
402 
403 
404 static void freeCharp(char *str) { free(str); }
405 static void freeCharp(char *str1, char *str2) { free(str1); free(str2); }
406 static void deleteString(string *str) { delete str; }
407 static void deleteString(string *str1, string *str2) { delete str1; delete str2; }
408 
409 void TEST_cbs() {
410  // MISSING_TEST("please log");
411  // for (int i = 0; i<100000; ++i)
412  {
413  TEST_CB_TRACE(makeRootCallback(plaincb), "plaincb()\n");
414  TEST_CB_TRACE(makeRootCallback(rcb0), "rcb0()\n");
415  TEST_CB_TRACE(makeRootCallback(rcb1, "dispatched"), "rcb1(dispatched)\n");
416  TEST_CB_TRACE(makeRootCallback(rcb2, "age", 46), "rcb2(age=46) [int]\n");
417  TEST_CB_TRACE(makeRootCallback(rcb2, "size", 178L), "rcb2(size=178) [long]\n");
418 
419  TEST_CB_TRACE(makeWindowCallback(plaincb), "plaincb()\n");
420  TEST_CB_TRACE(makeWindowCallback(wcb0), "wcb0()\n");
421  TEST_CB_TRACE(makeWindowCallback(wcb1, "dispatched"), "wcb1(dispatched)\n");
422  TEST_CB_TRACE(makeWindowCallback(wcb2, "age", 46), "wcb2(age=46) [int]\n");
423  TEST_CB_TRACE(makeWindowCallback(wcb2, "size", 178L), "wcb2(size=178) [long]\n");
424 
425  TEST_CB_TRACE(makeTreeAwarCallback(plaincb), "plaincb()\n");
426  TEST_CB_TRACE(makeTreeAwarCallback(tacb0), "tacb0()\n");
427  TEST_CB_TRACE(makeTreeAwarCallback(tacb1), "tacb1()\n");
428  TEST_CB_TRACE(makeTreeAwarCallback(tacb2, "dispatched"), "tacb2(dispatched)\n");
429  TEST_CB_TRACE(makeTreeAwarCallback(tacb2, 46), "tacb2(46)\n");
430 
431  // declaring a cb with UNFIXED as fixed-argument allows to use callbacks as RootCallback AND as WindowCallback
432  // (when we use sigc++ in the future this should be changed to allowing functions w/o the UNFIXED-parameter)
433 
434  TEST_CB_TRACE(makeRootCallback(ucb0), "ucb0()\n");
435  TEST_CB_TRACE(makeRootCallback(ucb1, "dispatched"), "ucb1(dispatched)\n");
436  TEST_CB_TRACE(makeRootCallback(ucb2, "age", 46), "ucb2(age=46) [int]\n");
437  TEST_CB_TRACE(makeRootCallback(ucb2, "size", 178L), "ucb2(size=178) [long]\n");
438 
439  TEST_CB_TRACE(makeWindowCallback(ucb0), "ucb0()\n");
440  TEST_CB_TRACE(makeWindowCallback(ucb1, "dispatched"), "ucb1(dispatched)\n");
441  TEST_CB_TRACE(makeWindowCallback(ucb2, "age", 46), "ucb2(age=46) [int]\n");
442  TEST_CB_TRACE(makeWindowCallback(ucb2, "size", 178L), "ucb2(size=178) [long]\n");
443 
444 #if defined(ARB_64)
445  TEST_CB_TRACE(makeWindowCallback(wcb2, 'l', 49710827735915452LL), "wcb2(l=49710827735915452) [long long]\n");
446 #endif
447 
448  TEST_CB_TRACE(makeCreateWindowCallback(cwcb_plain), "cwcb_plain()\n");
449  TEST_CB_TRACE(makeCreateWindowCallback(cwcb0), "cwcb0()\n");
450  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, 77), "cwcb1(77)\n");
451 
452  // TEST_CB(makeDatabaseCallback(plaincb), 44760); // does not work (ambiguous due to 2 fixed arguments of DatabaseCallback)
453  TEST_CB_TRACE(makeDatabaseCallback(dbcb01), "dbcb01()\n");
454  TEST_CB_TRACE(makeDatabaseCallback(dbcb012), "dbcb012()\n");
455  TEST_CB_TRACE(makeDatabaseCallback(dbcb02), "dbcb02(2)\n"); // call dbcb02 with fixed argument (i.e. with argument normally passed by ARBDB)
456  TEST_CB_TRACE(makeDatabaseCallback(dbcb1, 77), "dbcb1(77) [int]\n");
457 
458  TEST_CB_TRACE(makeDatabaseCallback(dbcb1, freeCharp, strdup("test")), "dbcb1(test) [const char]\n");
459 
460  // callbacks with deallocator
461 
462  // TEST_CB(makeWindowCallback(wcb1, strdup("leak")), 0x163ac); // leaks
463  TEST_CB_TRACE(makeWindowCallback(wcb1, freeCharp, strdup("leak")), "wcb1(leak)\n");
464  // TEST_CB(makeWindowCallback(wcb1, freeCharp, "leak"), 0x163ac); // does not compile (can't call freeCharp with const char *)
465  TEST_CB_TRACE(makeWindowCallback(wcb1, deleteString, new string("leak")), "wcb1(leak) [string]\n");
466  // TEST_CB(makeWindowCallback(wcb2, strdup("hue"), strdup("hott")), 0xe09d7b1); // leaks
467  TEST_CB_TRACE(makeWindowCallback(wcb2, freeCharp, strdup("hue"), strdup("hott")), "wcb2(hue=hott) [const char/const char]\n");
468  TEST_CB_TRACE(makeWindowCallback(wcb2, deleteString, new string("hue"), new string("hott")), "wcb2(hue=hott) [string/string]\n");
469 
470  // test const vs non-const pointers:
471  char *mut = strdup("mut");
472  const char *con = "con";
473 
474  // if only const/const and const/mutable exists -> shall always select as much mutable as possible
475  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2, con, con), "cwcb2(con,con) [const const]\n"); // exact match
476  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2, mut, con), "cwcb2(mut,con) [const const]\n"); // fallback to const/const
477  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2, con, mut), "cwcb2(con,mut) [const mutable]\n"); // exact match
478  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2, mut, mut), "cwcb2(mut,mut) [const mutable]\n"); // fallback to const/mutable
479 
480  // if all const/nonconst combinations exist -> shall always pick exact match
481  TEST_CB_TRACE(makeCreateWindowCallback(cwcb3, con, con), "cwcb3(con,con) [const const]\n"); // exact match
482  TEST_CB_TRACE(makeCreateWindowCallback(cwcb3, mut, con), "cwcb3(mut,con) [mutable const]\n"); // exact match
483  TEST_CB_TRACE(makeCreateWindowCallback(cwcb3, con, mut), "cwcb3(con,mut) [const mutable]\n"); // exact match
484  TEST_CB_TRACE(makeCreateWindowCallback(cwcb3, mut, mut), "cwcb3(mut,mut) [mutable mutable]\n"); // exact match
485 
486  // test reference arguments
487  int imut = 17;
488  const int icon = 23;
489 
490  const long lcon = 775L;
491 
492  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, imut), "cwcb1(17)\n");
493  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, icon), "cwcb1(23)\n");
494  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &lcon), "cwcb1(775) [long ptr]\n");
495 
496  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &icon), "cwcb1(23) [const ptr]\n");
497  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &icon), "cwcb1(23) [const ptr]\n");
498 
499  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &imut), "cwcb1(17) [mutable ptr]\n"); // modifies 'imut'
500  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &imut), "cwcb1(34) [mutable ptr]\n"); // modifies 'imut'
501  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &imut), "cwcb1(68) [mutable ptr]\n"); // modifies 'imut'
502 
503  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, mut), "cwcb1(mut) [mutable]\n");
504  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, con), "cwcb1(con) [const]\n");
505 
506  free(mut);
507 
508  // test callbacks w/o fixed argument
509  TEST_CB_TRACE(makeCustomCallback(plaincb), "plaincb()\n");
510  TEST_CB_TRACE(makeCustomCallback(ccb11, "helo"), "ccb11(helo)\n");
511  TEST_CB_TRACE(makeCustomCallback(ccb12, 4711), "ccb12(4711)\n");
512  TEST_CB_TRACE(makeCustomCallback(ccb2, 4711, "helo"), "ccb2(4711,helo)\n");
513 
514  TEST_CB_TRACE(makeCustomCallback(ccb11, freeCharp, strdup("dup")), "ccb11(dup)\n");
515  }
516 
517 }
518 TEST_PUBLISH(TEST_cbs);
519 
520 #endif // UNIT_TESTS
521 
522 
AliDataPtr format(AliDataPtr data, const size_t wanted_len, GB_ERROR &error)
Definition: insdel.cxx:615
Definition: ttypes.h:198
Definition: trnsprob.h:20
#define __ATTR__FORMAT(pos)
Definition: attributes.h:60
STL namespace.
struct Unfixed_cb_parameter * UNFIXED
Definition: cb_base.h:15
#define TEST_PUBLISH(testfunction)
Definition: test_unit.h:1517
#define TEST_EXPECT(cond)
Definition: test_unit.h:1328
DECLARE_CBTYPE_VV_AND_BUILDERS(StoreConfigCallback, char *)
char * str
Definition: defines.h:20
va_end(argPtr)
fputs(TRACE_PREFIX, stderr)
long AW_CL
Definition: cb.h:21
const size_t BUFFERSIZE
va_start(argPtr, format)
STATIC_ASSERT(sizeof(int *)==sizeof(AW_CL))
GB_CB_TYPE
Definition: arbdb_base.h:46
GB_write_int const char s
Definition: AW_awar.cxx:154