2020-03-12 10:47:09 +00:00
|
|
|
#include "test-harness.h"
|
|
|
|
|
|
|
|
typedef struct foo {
|
|
|
|
int x;
|
|
|
|
float y;
|
|
|
|
} foo;
|
|
|
|
|
|
|
|
int x, y;
|
|
|
|
int z = 42;
|
|
|
|
foo bar, baz;
|
|
|
|
foo foo_init = { 5, 6.25 };
|
|
|
|
|
|
|
|
int test_simple_global (void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
x = y = z;
|
|
|
|
if (x != z || y != z) {
|
|
|
|
printf ("test_simple_global: x=%d y=%d z=%d\n", x, y, z);
|
|
|
|
ret |= 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_struct_global (void)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
bar = baz = foo_init;
|
|
|
|
if (bar.x != foo_init.x || bar.y != foo_init.y) {
|
2020-03-13 16:28:00 +00:00
|
|
|
printf ("test_struct_global: bar={%d %g} foo_init={%d %g}\n",
|
2020-03-12 10:47:09 +00:00
|
|
|
bar.x, bar.y, foo_init.x, foo_init.y);
|
|
|
|
ret |= 1;
|
|
|
|
}
|
|
|
|
if (baz.x != foo_init.x || baz.y != foo_init.y) {
|
2020-03-13 16:28:00 +00:00
|
|
|
printf ("test_struct_global: baz={%d %g} foo_init={%d %g}\n",
|
2020-03-12 10:47:09 +00:00
|
|
|
baz.x, baz.y, foo_init.x, foo_init.y);
|
|
|
|
ret |= 1;
|
|
|
|
}
|
|
|
|
bar = baz = nil;
|
|
|
|
if (bar.x || baz.x || bar.y || baz.y) {
|
2020-03-13 16:28:00 +00:00
|
|
|
printf ("test_struct_global: bar={%d %g} baz={%d %g}\n",
|
2020-03-12 10:47:09 +00:00
|
|
|
bar.x, bar.y, baz.x, baz.y);
|
|
|
|
ret |= 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_simple_pointer (int *x, int *y)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
*x = *y = z;
|
|
|
|
if (*x != z || *y != z) {
|
2020-03-13 16:28:00 +00:00
|
|
|
printf ("test_simple_pointer: *x=%d *y=%d z=%d\n", *x, *y, z);
|
2020-03-12 10:47:09 +00:00
|
|
|
ret |= 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int test_struct_pointer (foo *bar, foo *baz)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
*bar = *baz = foo_init;
|
|
|
|
if (bar.x != foo_init.x || bar.y != foo_init.y) {
|
2020-03-13 16:28:00 +00:00
|
|
|
printf ("test_struct_pointer: bar={%d %g} foo_init={%d %g}\n",
|
2020-03-12 10:47:09 +00:00
|
|
|
bar.x, bar.y, foo_init.x, foo_init.y);
|
|
|
|
ret |= 1;
|
|
|
|
}
|
|
|
|
if (baz.x != foo_init.x || baz.y != foo_init.y) {
|
2020-03-13 16:28:00 +00:00
|
|
|
printf ("test_struct_pointer: baz={%d %g} foo_init={%d %g}\n",
|
2020-03-12 10:47:09 +00:00
|
|
|
baz.x, baz.y, foo_init.x, foo_init.y);
|
|
|
|
ret |= 1;
|
|
|
|
}
|
2020-03-12 10:53:15 +00:00
|
|
|
*bar = foo_init;
|
|
|
|
*baz = foo_init;
|
2020-03-12 10:47:09 +00:00
|
|
|
*bar = *baz = nil;
|
|
|
|
if (bar.x || baz.x || bar.y || baz.y) {
|
|
|
|
printf ("test_struct: bar={%d %g} baz={%d %g}\n",
|
|
|
|
bar.x, bar.y, baz.x, baz.y);
|
|
|
|
ret |= 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
ret |= test_simple_global ();
|
|
|
|
ret |= test_struct_global ();
|
2020-03-13 11:47:57 +00:00
|
|
|
x = 0; y = 0;
|
2020-03-12 10:47:09 +00:00
|
|
|
ret |= test_simple_pointer (&x, &y);
|
|
|
|
ret |= test_struct_pointer (&bar, &baz);
|
|
|
|
return ret;
|
|
|
|
}
|