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 #include "rootAsWin.h"
25 
26 // ---------------------------------------------
27 // compile time test of type inspection
28 
29 #define COMPILE_ASSERT_POINTER_TO(ISTYPE,POINTER) \
30  STATIC_ASSERT(TypeT<POINTER>::IsPtrT && \
31  TypeT<CompountT<POINTER>::BaseT>::ISTYPE)
32 
33 typedef int (*somefun)(const char *);
34 static int myfun(const char *) { return 0; }
35 static somefun sfun = myfun;
36 
37 enum someenum { A, B };
38 
39 class someclass { public : int memfun() { return -1; } };
40 
41 
47 
49 COMPILE_ASSERT_POINTER_TO(IsFundaT, int*);
50 COMPILE_ASSERT_POINTER_TO(IsPtrT, int**);
52 
54 STATIC_ASSERT(IsFundaT<typeof(myfun)>::No);
56 
57 STATIC_ASSERT(IsFunctionT<typeof(myfun)>::Yes);
58 
59 STATIC_ASSERT(IsFunctionT<somefun>::No); // somefun is pointer to functiontype
60 COMPILE_ASSERT_POINTER_TO(IsFuncT, somefun);
61 STATIC_ASSERT(IsFunctionT<typeof(sfun)>::No); // sfun is pointer to functiontype
62 COMPILE_ASSERT_POINTER_TO(IsFuncT, typeof(sfun));
66 
69 
71 COMPILE_ASSERT_POINTER_TO(IsEnumT, someenum*);
72 
77 STATIC_ASSERT(IsEnumT<typeof(myfun)>::No);
78 
80 COMPILE_ASSERT_POINTER_TO(IsClassT, someclass*);
81 
87 STATIC_ASSERT(IsClassT<typeof(myfun)>::No);
88 
92 STATIC_ASSERT(TypeT<int[]>::IsArrayT);
93 STATIC_ASSERT(TypeT<int[7]>::IsArrayT);
94 STATIC_ASSERT(TypeT<typeof(myfun)>::IsFuncT);
95 STATIC_ASSERT(TypeT<typeof(&someclass::memfun)>::IsPtrMemT);
98 
99 // -------------------------------------------------------
100 // compile time test of RequiresConstVariant
101 // (should be true, when parameter is mutable)
102 
104 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int) == false);
105 STATIC_ASSERT(CONST_VARIANT_REQUIRED(volatile int) == false);
106 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const volatile int) == false);
107 STATIC_ASSERT(CONST_VARIANT_REQUIRED(volatile const int) == false);
108 
110 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int&) == false);
112 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int*) == false);
113 STATIC_ASSERT(CONST_VARIANT_REQUIRED(int*const) == true);
114 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int*const) == false);
115 
121 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const GBDATA*const) == false);
122 
126 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const volatile GB_CB_TYPE) == false);
127 STATIC_ASSERT(CONST_VARIANT_REQUIRED(volatile const GB_CB_TYPE) == false);
128 
134 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const GB_CB_TYPE*const) == false);
135 
136 // not so important (may accept wrong behavior below, because there is no need to use such types as callback parameters!)
137 STATIC_ASSERT(CONST_VARIANT_REQUIRED(int*&) == true);
138 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int*&) == true); // (callers data is 'const int *' and the pointer is mutable)
139 STATIC_ASSERT(CONST_VARIANT_REQUIRED(int*const&) == false); // (callers data is 'int *' and the pointer is immutable)
140 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int*const&) == false);
141 
142 STATIC_ASSERT(CONST_VARIANT_REQUIRED(int**) == true);
143 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int**) == true); // (callers data is 'const int *' and the pointer is mutable)
144 STATIC_ASSERT(CONST_VARIANT_REQUIRED(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)
145 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int*const*) == false);
146 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int**const) == true); // (callers data is 'const int *' and the pointer is mutable)
147 STATIC_ASSERT(CONST_VARIANT_REQUIRED(int**const) == true);
148 STATIC_ASSERT(CONST_VARIANT_REQUIRED(int*const*const) == false);
149 STATIC_ASSERT(CONST_VARIANT_REQUIRED(const int*const*const) == false);
150 
151 // test callbacks as parameters (as used in RootAsWindowCallback):
152 class TREE_canvas;
154 STATIC_ASSERT(CONST_VARIANT_REQUIRED(void (*)(AW_root*, const TREE_canvas*)) == false);
155 STATIC_ASSERT(CONST_VARIANT_REQUIRED(void (*)(const AW_root*, TREE_canvas*)) == false);
156 STATIC_ASSERT(CONST_VARIANT_REQUIRED(void (*)(const AW_root*, const TREE_canvas*)) == false);
157 
158 
159 // -----------------------
160 // test callbacks
161 
162 #define TRACE
163 
164 DECLARE_CBTYPE_VV_AND_BUILDERS(CustomCallback, void); // defines makeCustomCallback
165 
166 static uint32_t traceChecksum;
167 const int BUFFERSIZE = 100;
168 static char traceBuffer[BUFFERSIZE];
169 
170 __ATTR__FORMAT(1) static void tracef(const char *format, ...) {
171  va_list parg;
172  va_start(parg, format);
173  int printed = vsnprintf(traceBuffer, BUFFERSIZE, format, parg);
174  va_end(parg);
175 
176 #if defined(TRACE)
177  fputs(traceBuffer, stdout);
178 #endif
179  if (printed >= BUFFERSIZE) {
180  printf("\nprinted=%i\n", printed);
181  }
182  TEST_EXPECT(printed<BUFFERSIZE);
183 
184  traceChecksum = 0;
185  for (int p = 0; p<printed; ++p) {
186  traceChecksum = (traceChecksum<<1)^(traceChecksum>>31)^traceBuffer[p];
187  }
188 }
189 
190 static AW_root *fake_root = (AW_root*)1;
191 
192 struct AW_fake_window : public AW_window { AW_fake_window() { root = fake_root; } };
193 static AW_fake_window instance_fake_win;
194 static AW_window *fake_win = &instance_fake_win;
195 
196 static GBDATA *fake_gbd = (GBDATA*)3;
197 static AW_awar *fake_awar = (AW_awar*)4;
198 static bool fake_bool = false;
199 static GB_CB_TYPE fake_gbtype = GB_CB_CHANGED;
200 
201 static void rcb0(AW_root *r) {
202  TEST_EXPECT(r == fake_root);
203  tracef("rcb0()\n");
204 }
205 static void rcb1_con(AW_root *r, const char *name) {
206  TEST_EXPECT(r == fake_root);
207  tracef("rcb1_con(%s)\n", name);
208 }
209 static void rcb1_mut(AW_root *r, char *name) {
210  TEST_EXPECT(r == fake_root);
211  tracef("rcb1_mut(%s)\n", name);
212 }
213 static void rcb2(AW_root *r, const char *name, int val) {
214  TEST_EXPECT(r == fake_root);
215  tracef("rcb2(%s=%i) [int]\n", name, val);
216 }
217 static void rcb2(AW_root *r, const char *name, long val) {
218  TEST_EXPECT(r == fake_root);
219  tracef("rcb2(%s=%li) [long]\n", name, val);
220 }
221 
222 static void wcb0(AW_window *w) {
223  TEST_EXPECT(w == fake_win);
224  tracef("wcb0()\n");
225 }
226 static void wcb1(AW_window *w, const char *name) {
227  TEST_EXPECT(w == fake_win);
228  tracef("wcb1(%s)\n", name);
229 }
230 static void wcb1(AW_window *w, string *name) {
231  TEST_EXPECT(w == fake_win);
232  tracef("wcb1(%s) [string]\n", name->c_str());
233 }
234 static void wcb2(AW_window *w, const char *name, const char *val) {
235  TEST_EXPECT(w == fake_win);
236  tracef("wcb2(%s=%s) [const char/const char]\n", name, val);
237 }
238 static void wcb2(AW_window *w, const string *name, const string *val) {
239  TEST_EXPECT(w == fake_win);
240  tracef("wcb2(%s=%s) [string/string]\n", name->c_str(), val->c_str());
241 }
242 static void wcb2(AW_window *w, const char *name, int val) {
243  TEST_EXPECT(w == fake_win);
244  tracef("wcb2(%s=%i) [int]\n", name, val);
245 }
246 static void wcb2(AW_window *w, const char *name, long val) {
247  TEST_EXPECT(w == fake_win);
248  tracef("wcb2(%s=%li) [long]\n", name, val);
249 }
250 static void wcb2(AW_window *w, char c, long long val) {
251  TEST_EXPECT(w == fake_win);
252  tracef("wcb2(%c=%lli) [long long]\n", c, val);
253 }
254 
255 static void tacb0(AW_awar *a) {
256  TEST_EXPECT(a == fake_awar);
257  tracef("tacb0()\n");
258 }
259 static void tacb1(AW_awar *a, bool b) {
260  TEST_EXPECT(a == fake_awar);
261  TEST_EXPECT(b == fake_bool);
262  tracef("tacb1()\n");
263 }
264 static void tacb2(AW_awar *a, bool b, const char *name) {
265  TEST_EXPECT(a == fake_awar);
266  TEST_EXPECT(b == fake_bool);
267  tracef("tacb2(%s)\n", name);
268 }
269 static void tacb2(AW_awar *a, bool b, int val) {
270  TEST_EXPECT(a == fake_awar);
271  TEST_EXPECT(b == fake_bool);
272  tracef("tacb2(%i)\n", val);
273 }
274 
275 static void ucb0(UNFIXED) {
276  tracef("ucb0()\n");
277 }
278 static void ucb1(UNFIXED, const char *name) {
279  tracef("ucb1(%s)\n", name);
280 }
281 static void ucb2(UNFIXED, const char *name, int val) {
282  tracef("ucb2(%s=%i) [int]\n", name, val);
283 }
284 static void ucb2(UNFIXED, const char *name, long val) {
285  tracef("ucb2(%s=%li) [long]\n", name, val);
286 }
287 
288 static AW_window *cwcb0(AW_root *r) {
289  TEST_EXPECT(r == fake_root);
290  tracef("cwcb0()\n");
291  return fake_win;
292 }
293 static AW_window *cwcb1(AW_root *r, int x) {
294  TEST_EXPECT(r == fake_root);
295  tracef("cwcb1(%i)\n", x);
296  return fake_win;
297 }
298 static AW_window *cwcb1(AW_root *r, const long *lp) {
299  TEST_EXPECT(r == fake_root);
300  tracef("cwcb1(%li) [long ptr]\n", *lp);
301  return fake_win;
302 }
303 static AW_window *cwcb1(AW_root *r, const int *x) {
304  TEST_EXPECT(r == fake_root);
305  tracef("cwcb1(%i) [const ptr]\n", *x);
306  return fake_win;
307 }
308 static AW_window *cwcb1(AW_root *r, int *x) {
309  TEST_EXPECT(r == fake_root);
310  tracef("cwcb1(%i) [mutable ptr]\n", *x);
311  *x *= 2; // modify callback argument!
312  return fake_win;
313 }
314 static AW_window *cwcb1(AW_root *r, char* s) {
315  TEST_EXPECT(r == fake_root);
316  tracef("cwcb1(%s) [mutable]\n", s);
317  return fake_win;
318 }
319 static AW_window *cwcb1(AW_root *r, const char* s) {
320  TEST_EXPECT(r == fake_root);
321  tracef("cwcb1(%s) [const]\n", s);
322  return fake_win;
323 }
324 static AW_window *cwcb2_cc(AW_root *r, const char *s1, const char *s2) {
325  TEST_EXPECT(r == fake_root);
326  tracef("cwcb2_cc(%s,%s) [const const]\n", s1, s2);
327  return fake_win;
328 }
329 static AW_window *cwcb2_cm(AW_root *r, const char *s1, char *s2) {
330  TEST_EXPECT(r == fake_root);
331  tracef("cwcb2_cm(%s,%s) [const mutable]\n", s1, s2);
332  return fake_win;
333 }
334 static AW_window *cwcb2_mc(AW_root *r, char *s1, const char *s2) {
335  TEST_EXPECT(r == fake_root);
336  tracef("cwcb2_mc(%s,%s) [mutable const]\n", s1, s2);
337  return fake_win;
338 }
339 static AW_window *cwcb2_mm(AW_root *r, char *s1, char *s2) {
340  TEST_EXPECT(r == fake_root);
341  tracef("cwcb2_mm(%s,%s) [mutable mutable]\n", s1, s2);
342  return fake_win;
343 }
344 
345 static void dbcb01(GBDATA *gbd) {
346  TEST_EXPECT(gbd == fake_gbd);
347  tracef("dbcb01()\n");
348 }
349 static void dbcb012(GBDATA *gbd, GB_CB_TYPE t) {
350  TEST_EXPECT(gbd == fake_gbd && t == fake_gbtype);
351  tracef("dbcb012()\n");
352 }
353 static void dbcb02(GB_CB_TYPE t) {
354  tracef("dbcb02(%i)\n", int(t));
355 }
356 static void dbcb1(GBDATA *gbd, int x, GB_CB_TYPE t) {
357  TEST_EXPECT(gbd == fake_gbd && t == fake_gbtype);
358  tracef("dbcb1(%i) [int]\n", x);
359 }
360 static void dbcb1(GBDATA *gbd, const char *n, GB_CB_TYPE t) {
361  TEST_EXPECT(gbd == fake_gbd && t == fake_gbtype);
362  tracef("dbcb1(%s) [const char]\n", n);
363 }
364 
365 static void ccb11(const char *str) {
366  tracef("ccb11(%s)\n", str);
367 }
368 static void ccb12(int i) {
369  tracef("ccb12(%i)\n", i);
370 }
371 static void ccb13(const double *d) {
372  tracef("ccb13(%5.2f)\n", *d);
373 }
374 static void ccb2(int i, const char *str) {
375  tracef("ccb2(%i,%s)\n", i, str);
376 }
377 
378 static void plaincb() {
379  tracef("plaincb()\n");
380 }
381 static AW_window *cwcb_plain() {
382  tracef("cwcb_plain()\n");
383  return fake_win;
384 }
385 
386 inline void call(const RootCallback& rcb) { rcb(fake_root); }
387 inline void call(const WindowCallback& wcb) { wcb(fake_win); }
388 inline void call(const CreateWindowCallback& cwcb) { TEST_EXPECT(cwcb(fake_root) == fake_win); }
389 inline void call(const DatabaseCallback& dbcb) { dbcb(fake_gbd, fake_gbtype); }
390 inline void call(const TreeAwarCallback& tacb) { tacb(fake_awar, fake_bool); }
391 inline void call(const CustomCallback& ccb) { ccb(); }
392 
393 #define TEST_CB(cb,expectedChecksum) do { \
394  traceChecksum = -666; \
395  call(cb); \
396  TEST_EXPECT_EQUAL(traceChecksum, (uint32_t)expectedChecksum); \
397  } while(0)
398 
399 #define TEST_CB_TRACE(cb,expectedOutput) do { \
400  call(cb); \
401  TEST_EXPECT_EQUAL(traceBuffer, expectedOutput); \
402  } while(0)
403 
404 #define TEST_CB_TRACE__BROKEN(cb,expectedOutput) do { \
405  call(cb); \
406  TEST_EXPECT_EQUAL__BROKEN(traceBuffer, expectedOutput); \
407  } while(0)
408 
409 
410 static void freeCharp(char *str) { free(str); }
411 static void freeCharp(char *str1, char *str2) { free(str1); free(str2); }
412 static void deleteString(string *str) { delete str; }
413 static void deleteString(string *str1, string *str2) { delete str1; delete str2; }
414 
415 void TEST_cbs() {
416  // MISSING_TEST("please log");
417  // for (int i = 0; i<100000; ++i)
418  {
419  char patched[] = "patched";
420 
421  TEST_CB_TRACE(makeRootCallback(plaincb), "plaincb()\n");
422  TEST_CB_TRACE(makeRootCallback(rcb0), "rcb0()\n");
423 
424  TEST_CB_TRACE(makeRootCallback(rcb1_con, patched), "rcb1_con(patched)\n");
425  TEST_CB_TRACE(makeRootCallback(rcb1_mut, patched), "rcb1_mut(patched)\n");
426  TEST_CB_TRACE(makeRootCallback(rcb1_con, "dispatched"), "rcb1_con(dispatched)\n");
427  // TEST_CB_TRACE(makeRootCallback(rcb1_mut, "dispatched"), "rcb1_mut(dispatched)\n"); // triggers expected compile error: no matching function for call to 'makeRootCallback(void (&)(AW_root*, char*), const char [11])'
428 
429  TEST_CB_TRACE(makeRootCallback(rcb2, "age", 46), "rcb2(age=46) [int]\n");
430  TEST_CB_TRACE(makeRootCallback(rcb2, "size", 178L), "rcb2(size=178) [long]\n");
431 
432  TEST_CB_TRACE(makeWindowCallback(plaincb), "plaincb()\n");
433  TEST_CB_TRACE(makeWindowCallback(wcb0), "wcb0()\n");
434  TEST_CB_TRACE(makeWindowCallback(wcb1, "dispatched"), "wcb1(dispatched)\n");
435  TEST_CB_TRACE(makeWindowCallback(wcb2, "age", 46), "wcb2(age=46) [int]\n");
436  TEST_CB_TRACE(makeWindowCallback(wcb2, "size", 178L), "wcb2(size=178) [long]\n");
437 
438  TEST_CB_TRACE(makeTreeAwarCallback(plaincb), "plaincb()\n");
439  TEST_CB_TRACE(makeTreeAwarCallback(tacb0), "tacb0()\n");
440  TEST_CB_TRACE(makeTreeAwarCallback(tacb1), "tacb1()\n");
441  TEST_CB_TRACE(makeTreeAwarCallback(tacb2, "dispatched"), "tacb2(dispatched)\n");
442  TEST_CB_TRACE(makeTreeAwarCallback(tacb2, 46), "tacb2(46)\n");
443 
444  // declaring a cb with UNFIXED as fixed-argument allows to use callbacks as RootCallback AND as WindowCallback
445  // (when we use sigc++ in the future this should be changed to allowing functions w/o the UNFIXED-parameter)
446 
447  TEST_CB_TRACE(makeRootCallback(ucb0), "ucb0()\n");
448  TEST_CB_TRACE(makeRootCallback(ucb1, "dispatched"), "ucb1(dispatched)\n");
449  TEST_CB_TRACE(makeRootCallback(ucb2, "age", 46), "ucb2(age=46) [int]\n");
450  TEST_CB_TRACE(makeRootCallback(ucb2, "size", 178L), "ucb2(size=178) [long]\n");
451 
452  TEST_CB_TRACE(makeWindowCallback(ucb0), "ucb0()\n");
453  TEST_CB_TRACE(makeWindowCallback(ucb1, "dispatched"), "ucb1(dispatched)\n");
454  TEST_CB_TRACE(makeWindowCallback(ucb2, "age", 46), "ucb2(age=46) [int]\n");
455  TEST_CB_TRACE(makeWindowCallback(ucb2, "size", 178L), "ucb2(size=178) [long]\n");
456 
457 #if defined(ARB_64)
458  TEST_CB_TRACE(makeWindowCallback(wcb2, 'l', 49710827735915452LL), "wcb2(l=49710827735915452) [long long]\n");
459 #endif
460 
461  TEST_CB_TRACE(makeCreateWindowCallback(cwcb_plain), "cwcb_plain()\n");
462  TEST_CB_TRACE(makeCreateWindowCallback(cwcb0), "cwcb0()\n");
463  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, 77), "cwcb1(77)\n");
464 
465  // TEST_CB(makeDatabaseCallback(plaincb), 44760); // does not work (ambiguous due to 2 fixed arguments of DatabaseCallback)
466  TEST_CB_TRACE(makeDatabaseCallback(dbcb01), "dbcb01()\n");
467  TEST_CB_TRACE(makeDatabaseCallback(dbcb012), "dbcb012()\n");
468  TEST_CB_TRACE(makeDatabaseCallback(dbcb02), "dbcb02(2)\n"); // call dbcb02 with fixed argument (i.e. with argument normally passed by ARBDB)
469  TEST_CB_TRACE(makeDatabaseCallback(dbcb1, 77), "dbcb1(77) [int]\n");
470 
471  TEST_CB_TRACE(makeDatabaseCallback(dbcb1, freeCharp, strdup("test")), "dbcb1(test) [const char]\n");
472 
473  // callbacks with deallocator
474 
475  // TEST_CB(makeWindowCallback(wcb1, strdup("leak")), 0x163ac); // leaks
476  TEST_CB_TRACE(makeWindowCallback(wcb1, freeCharp, strdup("leak")), "wcb1(leak)\n");
477  // TEST_CB(makeWindowCallback(wcb1, freeCharp, "leak"), 0x163ac); // does not compile (can't call freeCharp with const char *)
478  TEST_CB_TRACE(makeWindowCallback(wcb1, deleteString, new string("leak")), "wcb1(leak) [string]\n");
479  // TEST_CB(makeWindowCallback(wcb2, strdup("hue"), strdup("hott")), 0xe09d7b1); // leaks
480  TEST_CB_TRACE(makeWindowCallback(wcb2, freeCharp, strdup("hue"), strdup("hott")), "wcb2(hue=hott) [const char/const char]\n");
481  TEST_CB_TRACE(makeWindowCallback(wcb2, deleteString, new string("hue"), new string("hott")), "wcb2(hue=hott) [string/string]\n");
482 
483  // test const vs non-const pointers:
484  char *mut = strdup("mut");
485  const char *con = "con";
486 
487  // It is not possible to deduce one of multiple overloaded callbacks just by differences in constness
488  // (that was done here until r19976; clang 21 correctly omplains about ambiguities)
489  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_cc, con, con), "cwcb2_cc(con,con) [const const]\n");
490  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_cc, mut, con), "cwcb2_cc(mut,con) [const const]\n");
491  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_cc, con, mut), "cwcb2_cc(con,mut) [const const]\n");
492  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_cc, mut, mut), "cwcb2_cc(mut,mut) [const const]\n");
493 
494  // TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_mc, con, con), "cwcb2_mc(con,con) [mutable const]\n"); // triggers expected compile error: const argument passed to non-const callback parameter
495  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_mc, mut, con), "cwcb2_mc(mut,con) [mutable const]\n");
496  // TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_mc, con, mut), "cwcb2_mc(con,mut) [mutable const]\n"); // triggers expected compile error: const argument passed to non-const callback parameter
497  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_mc, mut, mut), "cwcb2_mc(mut,mut) [mutable const]\n");
498 
499  // TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_cm, con, con), "cwcb2_cm(con,con) [const mutable]\n"); // triggers expected compile error: const argument passed to non-const callback parameter
500  // TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_cm, mut, con), "cwcb2_cm(mut,con) [const mutable]\n"); // triggers expected compile error: const argument passed to non-const callback parameter
501  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_cm, con, mut), "cwcb2_cm(con,mut) [const mutable]\n");
502  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_cm, mut, mut), "cwcb2_cm(mut,mut) [const mutable]\n");
503 
504  // TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_mm, con, con), "cwcb2_mm(con,con) [mutable mutable]\n"); // triggers expected compile error: const argument passed to non-const callback parameter
505  // TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_mm, mut, con), "cwcb2_mm(mut,con) [mutable mutable]\n"); // triggers expected compile error: const argument passed to non-const callback parameter
506  // TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_mm, con, mut), "cwcb2_mm(con,mut) [mutable mutable]\n"); // triggers expected compile error: const argument passed to non-const callback parameter
507  TEST_CB_TRACE(makeCreateWindowCallback(cwcb2_mm, mut, mut), "cwcb2_mm(mut,mut) [mutable mutable]\n");
508 
509  // test reference arguments
510  int imut = 17;
511  const int icon = 23;
512 
513  const long lcon = 775L;
514 
515  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, imut), "cwcb1(17)\n");
516  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, icon), "cwcb1(23)\n");
517  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &lcon), "cwcb1(775) [long ptr]\n");
518 
519  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &icon), "cwcb1(23) [const ptr]\n");
520  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &icon), "cwcb1(23) [const ptr]\n");
521 
522  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &imut), "cwcb1(17) [mutable ptr]\n"); // modifies 'imut'
523  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &imut), "cwcb1(34) [mutable ptr]\n"); // modifies 'imut'
524  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, &imut), "cwcb1(68) [mutable ptr]\n"); // modifies 'imut'
525 
526  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, mut), "cwcb1(mut) [mutable]\n");
527  TEST_CB_TRACE(makeCreateWindowCallback(cwcb1, con), "cwcb1(con) [const]\n");
528 
529  free(mut);
530 
531  // test callbacks w/o fixed argument
532  double d = 3.1415;
533  TEST_CB_TRACE(makeCustomCallback(plaincb), "plaincb()\n");
534  TEST_CB_TRACE(makeCustomCallback(ccb11, "helo"), "ccb11(helo)\n");
535  TEST_CB_TRACE(makeCustomCallback(ccb12, 4711), "ccb12(4711)\n");
536  TEST_CB_TRACE(makeCustomCallback(ccb13, &d), "ccb13( 3.14)\n");
537  TEST_CB_TRACE(makeCustomCallback(ccb2, 4711, "helo"), "ccb2(4711,helo)\n");
538 
539  TEST_CB_TRACE(makeCustomCallback(ccb11, freeCharp, strdup("dup")), "ccb11(dup)\n");
540  }
541 
542 }
543 
544 void TEST_RootAsWindowCallback() {
545  char mutableText[] = "mutable";
546 
547  TEST_CB_TRACE(RootAsWindowCallback::simple(rcb0), "rcb0()\n");
548 
549  TEST_CB_TRACE(RootAsWindowCallback::simple(rcb1_con, mutableText), "rcb1_con(mutable)\n");
550  TEST_CB_TRACE(RootAsWindowCallback::simple(rcb1_mut, mutableText), "rcb1_mut(mutable)\n");
551  TEST_CB_TRACE(RootAsWindowCallback::simple(rcb1_con, "const"), "rcb1_con(const)\n");
552  // TEST_CB_TRACE(RootAsWindowCallback::simple(rcb1_mut, "const"), "rcb1_mut(const)\n"); // triggers expected compile error: no matching function for call to 'RootAsWindowCallback::simple(void (&)(AW_root*, char*), const char [6])'
553 
554  // TEST_CB_TRACE(RootAsWindowCallback::simple(rcb1_con, 7), "xxx"); // triggers expected compile error: no matching function for call to 'RootAsWindowCallback::simple(void (&)(AW_root*, const char*), int)'
555  // TEST_CB_TRACE(RootAsWindowCallback::simple(rcb1_con, &mutableText), "xxx"); // triggers expected compile error: no matching function for call to 'RootAsWindowCallback::simple(void (&)(AW_root*, const char*), char (*)[8])'
556 
557 }
558 
559 TEST_PUBLISH(TEST_cbs);
560 
561 #endif // UNIT_TESTS
562 
563 
AliDataPtr format(AliDataPtr data, const size_t wanted_len, GB_ERROR &error)
Definition: insdel.cxx:615
#define CONST_VARIANT_REQUIRED(T)
Definition: cbtypes.h:297
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
static WindowCallback simple(void(*root_cb)(AW_root *))
Definition: rootAsWin.h:77
GB_write_int const char s
Definition: AW_awar.cxx:154