diff options
author | Teddy <[email protected]> | 2014-05-04 22:24:42 +0800 |
---|---|---|
committer | Teddy <[email protected]> | 2014-05-04 22:24:42 +0800 |
commit | 679c091bf746798e7272ac0842cf3d8dd9dd6251 (patch) | |
tree | 9e1063a686c1536ceb12d4082d15b936ae9568a5 /testbed | |
parent | d44c79c26afd6945d912a4a3423038a5a4594138 (diff) |
add some custom testcases
Diffstat (limited to 'testbed')
-rw-r--r-- | testbed/custom_struct.c | 26 | ||||
-rw-r--r-- | testbed/custom_struct2.c | 41 | ||||
-rw-r--r-- | testbed/custom_struct3.c | 15 | ||||
-rw-r--r-- | testbed/custom_struct4.c | 28 | ||||
-rw-r--r-- | testbed/func_pointer.c | 19 |
5 files changed, 129 insertions, 0 deletions
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; +} |