From 8d69c5c898c2aa49f81e27d4817e0b57750c53b9 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Wed, 9 Mar 2011 20:34:23 +0900 Subject: [PATCH] More tests --- tools/qfcc/test/entity-field2.r | 13 +++++++++++++ tools/qfcc/test/entity-struct.r | 30 ++++++++++++++++++++++++++++++ tools/qfcc/test/forward.r | 10 ++++++++++ tools/qfcc/test/local-func.r | 10 ++++++++++ tools/qfcc/test/move.r | 12 ++++++++++++ tools/qfcc/test/offset.r | 17 ++++++++++++----- tools/qfcc/test/storage.r | 8 ++++++++ tools/qfcc/test/vector.r | 23 +++++++++++++++++++++++ tools/qfcc/test/void-return.qc | 4 ++++ 9 files changed, 122 insertions(+), 5 deletions(-) create mode 100644 tools/qfcc/test/entity-field2.r create mode 100644 tools/qfcc/test/entity-struct.r create mode 100644 tools/qfcc/test/forward.r create mode 100644 tools/qfcc/test/local-func.r create mode 100644 tools/qfcc/test/move.r create mode 100644 tools/qfcc/test/storage.r create mode 100644 tools/qfcc/test/vector.r create mode 100644 tools/qfcc/test/void-return.qc diff --git a/tools/qfcc/test/entity-field2.r b/tools/qfcc/test/entity-field2.r new file mode 100644 index 000000000..6cf08a105 --- /dev/null +++ b/tools/qfcc/test/entity-field2.r @@ -0,0 +1,13 @@ +float (float val, float inc, float max) inc = #0; +entity self; +float (.string fld) foo = { return 0; }; + +float (.float fld) inc_field = +{ + local float new; + new = inc (self.fld, 2, 3); + if (new == self.fld) + return 0; + self.fld = new; + return 1; +} diff --git a/tools/qfcc/test/entity-struct.r b/tools/qfcc/test/entity-struct.r new file mode 100644 index 000000000..6d6d4fc73 --- /dev/null +++ b/tools/qfcc/test/entity-struct.r @@ -0,0 +1,30 @@ +typedef struct foo_s { + integer a, b; +} foo_t; + +entity self; +foo_t a, b; +vector x, y; +integer i, j; + +.vector v; +.foo_t foo; + +void bar (entity other) +{ +#if 0 + self.foo = a; + b = self.foo; + self.foo = other.foo; + a = b; + + self.v = x; + y = self.v; + self.v = other.v; + x = y; +#endif + self.foo.b = i; + j = self.foo.b; + self.foo.a = self.foo.b; + self.foo.b = self.foo.a; +} diff --git a/tools/qfcc/test/forward.r b/tools/qfcc/test/forward.r new file mode 100644 index 000000000..5fb0d560d --- /dev/null +++ b/tools/qfcc/test/forward.r @@ -0,0 +1,10 @@ +@extern void a (void); + +void b (void) +{ + a (); +} + +void a (void) +{ +} diff --git a/tools/qfcc/test/local-func.r b/tools/qfcc/test/local-func.r new file mode 100644 index 000000000..58a926a2c --- /dev/null +++ b/tools/qfcc/test/local-func.r @@ -0,0 +1,10 @@ +.float () th_takeitem; + +void (entity e1, entity e2) +_override_swap = +{ + local float () t_f_v; + t_f_v = e1.th_takeitem; + e1.th_takeitem = e2.th_takeitem; + e2.th_takeitem = t_f_v; +} diff --git a/tools/qfcc/test/move.r b/tools/qfcc/test/move.r new file mode 100644 index 000000000..2719766bb --- /dev/null +++ b/tools/qfcc/test/move.r @@ -0,0 +1,12 @@ +struct plitem_s {integer dummy;}; +typedef struct plitem_s plitem_t; + +typedef struct foo_s { + integer x; + plitem_t i; +} foo_t; + +void bar (foo_t *foo, plitem_t item) +{ + foo.i = item; +} diff --git a/tools/qfcc/test/offset.r b/tools/qfcc/test/offset.r index d5e16e51e..4b6b915c9 100644 --- a/tools/qfcc/test/offset.r +++ b/tools/qfcc/test/offset.r @@ -1,12 +1,19 @@ -struct foobar_s = { - integer a; - (struct foobar_s [])[4]b; +struct foobar_s { + float a; + struct foobar_s *b[2]; + float c; }; typedef struct foobar_s foobar_t; -typedef foobar_t [] foobar_p; +typedef foobar_t *foobar_p; -void (foobar_p foo, vector x, integer y) bar = +void (foobar_p foo, vector x, integer y, foobar_t z) bar = { foo.a = x.z; foo.b[1] = (foobar_p)(integer)x.y; + z.a = x_z; + z.c = x.x; + x.y = z.c; + x_x = 0; + x_y = 0; + x.z = 0; }; diff --git a/tools/qfcc/test/storage.r b/tools/qfcc/test/storage.r new file mode 100644 index 000000000..8e166f5da --- /dev/null +++ b/tools/qfcc/test/storage.r @@ -0,0 +1,8 @@ +@extern { + float x; + void () main = + { + x = 1; + return; + }; +}; diff --git a/tools/qfcc/test/vector.r b/tools/qfcc/test/vector.r new file mode 100644 index 000000000..816389f90 --- /dev/null +++ b/tools/qfcc/test/vector.r @@ -0,0 +1,23 @@ +entity self; +.vector velocity; +.vector oldorigin; +.float speed; +@extern .vector avel; +@extern vector vel; + +void (vector tdest, float speed, void () func) SUB_CalcMove = {} +vector normalize (vector x) = #0; +float vlen (vector x) = #0; + +void oof (void) +{ +} + +void foo (void) +{ + float forward = vlen (self.velocity); + forward *= 0.8; + self.velocity = forward * normalize (self.velocity); + SUB_CalcMove(self.oldorigin, self.speed, oof); + self.avel_y = vel_z; +} diff --git a/tools/qfcc/test/void-return.qc b/tools/qfcc/test/void-return.qc new file mode 100644 index 000000000..ce4e0f708 --- /dev/null +++ b/tools/qfcc/test/void-return.qc @@ -0,0 +1,4 @@ +void () foo = +{ + return; +};