mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-21 03:01:15 +00:00
Add some more tests.
structptr.r is actually usable for automated testing when I get around to it.
This commit is contained in:
parent
87121b4cf1
commit
793112de9a
4 changed files with 73 additions and 0 deletions
21
tools/qfcc/test/gcd.r
Normal file
21
tools/qfcc/test/gcd.r
Normal file
|
@ -0,0 +1,21 @@
|
|||
void printf (string fmt, ...) = #0;
|
||||
void traceon (void) = #0;
|
||||
|
||||
int x, y;
|
||||
|
||||
int
|
||||
gcd (int a, int b)
|
||||
{
|
||||
if (b == 0) return a;
|
||||
else return gcd (b, a % b);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, string *argv)
|
||||
{
|
||||
traceon ();
|
||||
x = 130;
|
||||
y = 120;
|
||||
printf ("%d\n", gcd (x, y));
|
||||
return 0;
|
||||
}
|
10
tools/qfcc/test/obj.r
Normal file
10
tools/qfcc/test/obj.r
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include <Object.h>
|
||||
|
||||
@implementation Object
|
||||
- (void) doesNotRecognizeSelector: (SEL)aSelector
|
||||
{
|
||||
[self error: "%s does not recognize %s",
|
||||
object_get_class_name (self),
|
||||
sel_get_name (aSelector)];
|
||||
}
|
||||
@end
|
|
@ -1,3 +1,4 @@
|
|||
int y;
|
||||
void
|
||||
ptrderef (int *to, int *from)
|
||||
{
|
||||
|
@ -13,4 +14,5 @@ ptrderef (int *to, int *from)
|
|||
*to = *++from;
|
||||
*to = x;
|
||||
*to++ = *from++;
|
||||
y = *to++;
|
||||
}
|
||||
|
|
40
tools/qfcc/test/structptr.r
Normal file
40
tools/qfcc/test/structptr.r
Normal file
|
@ -0,0 +1,40 @@
|
|||
void printf (string fmt, ...) = #0;
|
||||
void *obj_malloc (int size) = #0;
|
||||
|
||||
typedef struct {
|
||||
int val;
|
||||
int cap;
|
||||
int ofs;
|
||||
int res;
|
||||
} valstruct_t;
|
||||
|
||||
int
|
||||
printval (int val)
|
||||
{
|
||||
printf ("%d\n", val);
|
||||
return val;
|
||||
}
|
||||
|
||||
void
|
||||
test (valstruct_t *v)
|
||||
{
|
||||
if (v.val == v.cap) {
|
||||
v.val += v.ofs;
|
||||
v.res = printval (v.val * @sizeof (int));
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
valstruct_t *vs;
|
||||
|
||||
vs = obj_malloc (@sizeof (valstruct_t));
|
||||
vs.val = 1;
|
||||
vs.cap = 1;
|
||||
vs.ofs = 2;
|
||||
printf ("before: %d\nafter: ", vs.val);
|
||||
test (vs);
|
||||
printf ("val vs res: %d %d\n", vs.val, vs.res);
|
||||
return vs.val != vs.res;
|
||||
}
|
Loading…
Reference in a new issue