25 #include "helpers.hpp"
30 printf(
"\ntesting basic function: f0() ...\n");
39 printf(
"\ntesting primitive type functions: fxx(0) ...\n");
77 printf(
"\ntesting basic functions: f1xx(f0xx()) ...\n");
79 for (
int i = 0;
i < 2;
i++) {
111 printf(
"\ntesting basic functions: f3xx(f2xx()) ...\n");
113 for (
int i = 0;
i < 2;
i++) {
145 printf(
"\ntesting basic functions: f5xx(f4xx()) ...\n");
147 for (
int i = 0;
i < 2;
i++) {
205 printf(
"\ntesting basic functions: f7xx(f6xx()) ...\n");
207 for (
int i = 0;
i < 2;
i++) {
265 printf(
"\ntesting instance wrappers: ...\n");
268 printf(
"\ncalling A...\n");
270 printf(
"... new A() = %p\n", &a);
272 printf(
"... delete new A(int)\n");
274 printf(
"... A::f0s() = %d\n", n);
277 printf(
"... a->f0s() = %d\n", n);
280 printf(
"... a->f0n() = %d\n", n);
283 printf(
"... a->f0v() = %d\n", n);
286 printf(
"\nA::take_ptr(A::deliver_ptr())...\n");
287 A::take_ptr(A::deliver_ptr());
289 printf(
"\nA::take_null_ptr(A::deliver_null_ptr())...\n");
290 A::take_null_ptr(A::deliver_null_ptr());
292 printf(
"\nA::take_ref(A::deliver_ref())...\n");
293 A::take_ref(A::deliver_ref());
295 printf(
"\nA::take_null_ref(A::deliver_null_ref())...\n");
296 A::take_null_ref(A::deliver_null_ref());
298 printf(
"\nA::print(A *)...\n");
302 printf(
"\naccessing A...\n");
304 printf(
"... ++A::d0s = %d\n", n);
307 printf(
"... A::d0sc = %d\n", n);
310 printf(
"... ++a->d0s = %d\n", n);
313 printf(
"... a->d0sc = %d\n", n);
316 printf(
"... ++a->d0 = %d\n", n);
319 printf(
"... a->d0c = %d\n", n);
322 printf(
"\ncalling B0...\n");
323 B0 & b0b0 = *a->newB0();
324 printf(
"... a->newB0() = %p\n", &b0b0);
326 printf(
"... B0::f0s() = %d\n", n);
329 printf(
"... b0b0.f0s() = %d\n", n);
332 printf(
"... b0b0.f0n() = %d\n", n);
335 printf(
"... b0b0.f0v() = %d\n", n);
338 printf(
"... a->del(b0b0)\n");
340 printf(
"\naccessing B0...\n");
341 B0 & b0 = *a->newB0();
342 printf(
"... a->newB0() = %p\n", &b0);
344 printf(
"... ++B0::d0s = %d\n", n);
347 printf(
"... B0::d0sc = %d\n", n);
350 printf(
"... ++b0.d0s = %d\n", n);
353 printf(
"... b0.d0sc = %d\n", n);
356 printf(
"... ++b0.d0 = %d\n", n);
359 printf(
"... b0.d0c = %d\n", n);
362 printf(
"... a->del(b0)\n");
364 printf(
"\ncalling B1...\n");
365 B1 & b1b1 = *a->newB1();
367 printf(
"... a->newB1() = %p\n", &b0b1);
369 printf(
"... B1::f0s() = %d\n", n);
372 printf(
"... b0b1.f0s() = %d\n", n);
375 printf(
"... b0b1.f0n() = %d\n", n);
378 printf(
"... b0b1.f0v() = %d\n", n);
381 printf(
"... a->del(b1b1)\n");
383 printf(
"\naccessing B1...\n");
384 B1 & b1 = *a->newB1();
385 printf(
"... a->newB1() = %p\n", &b1);
387 printf(
"... ++B1::d0s = %d\n", n);
390 printf(
"... B1::d0sc = %d\n", n);
393 printf(
"... ++b1.d0s = %d\n", n);
396 printf(
"... b1.d0sc = %d\n", n);
399 printf(
"... ++b1.d0 = %d\n", n);
402 printf(
"... b1.d0c = %d\n", n);
405 printf(
"... a->del(b1)\n");
407 printf(
"\ndelete A...\n");
414 printf(
"\ntesting string/byte array functions: sxxx(sxxx) ...\n");
468 printf(
"\ntesting n-ary array functions: g(), h() ...\n");
471 printf(
"\ncreating A...\n");
520 n = ac->g3rc(1, 2, 3);
535 printf(
"delete A...\n");
542 printf(
"\ntesting const & inheritance: ...\n");
545 const C0 & c0c = *C0::cc;
547 const C1 & c1c = *C1::cc;
551 printf(
"\nc0.print()... c0c.print()...\n");
555 printf(
"\nc1.print()... c1c.print()...\n");
560 printf(
"\nc0.check(c0.id);\n");
563 printf(
"\nc0c.check(c0c.id);\n");
566 printf(
"\nc1.check(c1.id);\n");
569 printf(
"\nc1c.check(c1c.id);\n");
573 printf(
"\nc0c.take_C0Cp(c0c.deliver_C0Cp())...\n");
574 c0c.take_C0Cp(c0c.deliver_C0Cp());
576 printf(
"\nc0c.take_C0Cr(c0c.deliver_C0Cr())...\n");
577 c0c.take_C0Cr(c0c.deliver_C0Cr());
579 printf(
"\nc0c.take_C0Cp(c0.deliver_C0p())...\n");
580 c0c.take_C0Cp(c0.deliver_C0p());
582 printf(
"\nc0c.take_C0Cr(c0.deliver_C0r())...\n");
583 c0c.take_C0Cr(c0.deliver_C0r());
585 printf(
"\nc0.take_C0p(c0.deliver_C0p())...\n");
586 c0.take_C0p(c0.deliver_C0p());
588 printf(
"\nc0.take_C0r(c0.deliver_C0r())...\n");
589 c0.take_C0r(c0.deliver_C0r());
592 printf(
"\nc0c.take_C0Cp(c1c.deliver_C1Cp())...\n");
593 c0c.take_C0Cp(c1c.deliver_C1Cp());
595 printf(
"\nc0c.take_C0Cr(c1c.deliver_C1Cr())...\n");
596 c0c.take_C0Cr(c1c.deliver_C1Cr());
598 printf(
"\nc0c.take_C0Cp(c1.deliver_C1p())...\n");
599 c0c.take_C0Cp(c1.deliver_C1p());
601 printf(
"\nc0c.take_C0Cr(c1.deliver_C1r())...\n");
602 c0c.take_C0Cr(c1.deliver_C1r());
604 printf(
"\nc0.take_C0p(c1.deliver_C1p())...\n");
605 c0.take_C0p(c1.deliver_C1p());
607 printf(
"\nc0.take_C0r(c1.deliver_C1r())...\n");
608 c0.take_C0r(c1.deliver_C1r());
611 printf(
"\nc1c.take_C1Cp(c1c.deliver_C1Cp())...\n");
612 c1c.take_C1Cp(c1c.deliver_C1Cp());
614 printf(
"\nc1c.take_C1Cr(c1c.deliver_C1Cr())...\n");
615 c1c.take_C1Cr(c1c.deliver_C1Cr());
617 printf(
"\nc1c.take_C1Cp(c1.deliver_C1p())...\n");
618 c1c.take_C1Cp(c1.deliver_C1p());
620 printf(
"\nc1c.take_C1Cr(c1.deliver_C1r())...\n");
621 c1c.take_C1Cr(c1.deliver_C1r());
623 printf(
"\nc1.take_C1p(c1.deliver_C1p())...\n");
624 c1.take_C1p(c1.deliver_C1p());
626 printf(
"\nc1.take_C1r(c1.deliver_C1r())...\n");
627 c1.take_C1r(c1.deliver_C1r());
633 printf(
"\ntesting object array functions ...\n\n");
635 printf(
"\ndelete[] (new C0[0])\n");
636 C0 * c0a0 =
new C0[0];
637 assert(c0a0 != NULL);
641 C0 * c0a =
new C0[
n];
642 const C0 * c0ca = c0a;
643 C1 * c1a =
new C1[
n];
644 const C1 * c1ca = c1a;
648 for (
int i = 0;
i < 0;
i++) {
649 printf(
"\nc0a[i].print()\n");
652 printf(
"\nc0ca[i].print()\n");
655 printf(
"\nc1a[i].print()\n");
658 printf(
"\nc1ca[i].print()\n");
662 for (
int i = 0;
i <
n;
i++) {
663 printf(
"\nc0a[i].check(c0a[i].id)\n");
664 c0a[
i].check(c0a[
i].
id);
666 printf(
"\nc0ca[i].check(c0ca[i].id)\n");
667 c0ca[
i].check(c0ca[
i].
id);
669 printf(
"\nc1a[i].check(c1a[i].id)\n");
670 c1a[
i].check(c1a[
i].
id);
672 printf(
"\nc1ca[i].check(c1ca[i].id)\n");
673 c1ca[
i].check(c1ca[
i].
id);
676 printf(
"\nC0::hash(c0a, n) == C0::hash(C0::pass(c0a), n)...\n");
677 assert(C0::hash(c0a, n) == C0::hash(C0::pass(c0a), n));
679 printf(
"\nC0::hash(c0ca, n) == C0::hash(C0::pass(c0ca), n)...\n");
680 assert(C0::hash(c0ca, n) == C0::hash(C0::pass(c0ca), n));
682 printf(
"\nC1::hash(c1a, n) == C1::hash(C1::pass(c1a), n)...\n");
683 assert(C1::hash(c1a, n) == C1::hash(C1::pass(c1a), n));
685 printf(
"\nC1::hash(c1ca, n) == C1::hash(C1::pass(c1ca), n)...\n");
686 assert(C1::hash(c1ca, n) == C1::hash(C1::pass(c1ca), n));
695 printf(
"\ntesting function dispatch ...\n\n");
697 assert(D0::sub()->f_d0() == 20);
698 assert(D0::sub()->f_nv() == 31);
699 assert(D0::sub()->f_v() == 32);
701 assert(D1::sub()->f_d0() == 20);
702 assert(D1::sub()->f_d1() == 30);
703 assert(D1::sub()->f_nv() == 31);
704 assert(D1::sub()->f_v() == 42);
706 assert(D2::sub() == NULL);
709 template<
typename E,
void (F)(E) >
710 inline void call(
E e)
715 template<
typename E, E (F)() >
724 printf(
"\ntesting enums: ...\n");
727 printf(
"\nE::take_EE1(E::deliver_EE1())...\n");
728 E::take_EE1(E::deliver_EE1());
730 printf(
"\ncall< E::EE, E::deliver_EE1 >()...\n");
731 E::EE e = call< E::EE, E::deliver_EE1 >();
734 printf(
"\ncall< E::EE, E::take_EE1 >(e)...\n");
735 call< E::EE, E::take_EE1 >(e);
737 printf(
"\nE::take_EE1c(E::deliver_EE1c())...\n");
738 E::take_EE1c(E::deliver_EE1c());
740 printf(
"\ncall< E::EE, E::deliver_EE1c >()...\n");
741 const E::EE ec = call< const E::EE, E::deliver_EE1c >();
742 assert(ec == E::EE1);
744 printf(
"\ncall< E::EE, E::take_EE1c >(e)...\n");
745 call< const E::EE, E::take_EE1c >(ec);
749 main(
int argc,
const char* argv[])
751 printf(
"\n--> main()\n");
752 (void)argc; (void)argv;
776 printf(
"\n<-- main()\n");