From 679c091bf746798e7272ac0842cf3d8dd9dd6251 Mon Sep 17 00:00:00 2001 From: Teddy Date: Sun, 4 May 2014 22:24:42 +0800 Subject: add some custom testcases --- testbed/custom_struct.c | 26 ++++++++++++++++++++++++++ testbed/custom_struct2.c | 41 +++++++++++++++++++++++++++++++++++++++++ testbed/custom_struct3.c | 15 +++++++++++++++ testbed/custom_struct4.c | 28 ++++++++++++++++++++++++++++ testbed/func_pointer.c | 19 +++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 testbed/custom_struct.c create mode 100644 testbed/custom_struct2.c create mode 100644 testbed/custom_struct3.c create mode 100644 testbed/custom_struct4.c create mode 100644 testbed/func_pointer.c (limited to 'testbed') diff --git a/testbed/custom_struct.c b/testbed/custom_struct.c new file mode 100644 index 0000000..0d473f5 --- /dev/null +++ b/testbed/custom_struct.c @@ -0,0 +1,26 @@ +struct D { + int a, b; +}; +struct A { + int a[100]; + struct B { + struct C { + int x, y; + } c; + int z; + struct D *p; + } b; +} s; +int main() { + struct D d; + int n = 0; + s.a[1] = 1; + s.a[2] = 2; + s.b.z = 4; + s.b.c.x = 5; + s.b.c.y = 6; + s.b.p = &d; + s.b.p->a = 7; + s.b.p->b = 8; + printf("%d %d %d %d %d %d %d\n", s.a[1], s.a[2], s.b.z, s.b.c.x, s.b.c.y, s.b.p->a, s.b.p->b); +} diff --git a/testbed/custom_struct2.c b/testbed/custom_struct2.c new file mode 100644 index 0000000..e147186 --- /dev/null +++ b/testbed/custom_struct2.c @@ -0,0 +1,41 @@ +struct A { + int x, y; +} sa; +struct A print(struct A a, struct A b) { + a.x++; + a.y++; + b.x--; + b.y--; + printf("args: %d %d\n", a.x, a.y); + printf("args: %d %d\n", b.x, b.y); + return a; +} +int main() { + int i; + int t; + int *a, *b; + struct A sb, sc; + a = malloc(sizeof(int) * 100); + for (i = 0; i < 100; i++) + a[i] = i; + b = malloc(sizeof(int) * 100); + memcpy(b, a, sizeof(int) * 100); + for (i = 0; i < 100; i++) + printf("%d ", b[i]); + sb.x = 1; + sb.y = 2; + sa = sb; + sc = sa; + printf("\n%d %d\n", sa.x, sa.y); + printf("%d %d\n", sc.x, sc.y); + sa.x = 1; + sa.y = 2; + sb.x = 1; + sb.y = 2; + sa = print(sa, sb); + sb = print(sa, sb); + sa = print(sa, sb); + sb = print(sa, sb); + printf("%d %d\n", sa.x, sa.y); + printf("%d %d\n", sb.x, sb.y); +} diff --git a/testbed/custom_struct3.c b/testbed/custom_struct3.c new file mode 100644 index 0000000..d7060b3 --- /dev/null +++ b/testbed/custom_struct3.c @@ -0,0 +1,15 @@ +struct A { + int x, y; +} a[10]; +struct A f(struct A a) { + a.x++; + a.y++; + return a; +} +int main(){ + int i; + for (i = 1; i < 10; i++) + a[i] = f(a[i - 1]); + for (i = 0; i < 10; i++) + printf("%d %d\n", a[i].x, a[i].y); +} diff --git a/testbed/custom_struct4.c b/testbed/custom_struct4.c new file mode 100644 index 0000000..75f50ea --- /dev/null +++ b/testbed/custom_struct4.c @@ -0,0 +1,28 @@ +struct A { + struct B { + int x, y; + struct C { + int w; + } c; + } b; + int z; +}; + +struct B f(struct A a) { + printf("z: %d\n", a.z); + return a.b; +} + +struct C g(struct B b) { + printf("x: %d\ny: %d\n", b.x, b.y); + return b.c; +} + +int main() { + struct A a; + a.z = 1; + a.b.x = 2; + a.b.y = 3; + a.b.c.w = 4; + printf("w: %d\n", g(f(a)).w); +} diff --git a/testbed/func_pointer.c b/testbed/func_pointer.c new file mode 100644 index 0000000..e7b6484 --- /dev/null +++ b/testbed/func_pointer.c @@ -0,0 +1,19 @@ +typedef void (*Func_t)(); +void f(Func_t func, int step) { + if (!step) return; + printf("i'm f\n"); + func(func, step - 1); +} +void g(void (*func)(), int step) { + if (!step) return; + printf("i'm g\n"); + func(func, step - 1); +} +int main() { + void (*func)(void (*ifunc)(), int step); + int x = 1; + if (x) func = f; + else func = g; + func(func, 5); + return 0; +} -- cgit v1.2.3-70-g09d2