ORCA-C/Tests/Conformance/C4.6.6.1.CC
2017-10-21 18:40:19 -05:00

298 lines
6.8 KiB
C++

/* Conformance Test 4.6.6.1: Verification of static and extern structure */
/* initialization */
#include <stdio.h>
#include <math.h>
struct S1 { int i;
char ch;
long L;
float f;
double d;
extended e;
unsigned int bf1: 8; };
struct S2 { int i1 [5];
char ch1 [10];
long L1 [3];
float f1 [4];
double d1 [3];
extended e1 [3];
unsigned int ui [4];
unsigned long ul [2]; };
struct S3 { struct S1 s1;
struct S2 s2; };
/* Initialization of static & extern structures allowed; each variable */
/* within the structure is subject to the rules for initializing static */
/* and extern variables of the corresponding type. */
struct S1 s4 = { 32767, 'z', 32788, 17.0, 18.0, 19.0, 5 };
struct S2 s5 = { { 10, 20, 30, 40, 50 }, "ORCA/C !!", { 4, 5, 6 },
{ 45.0, 55.0, 65.0, 75.0 }, { 455.0, 555.0, 655.0 },
{ 4555.0, 5555.0 } };
struct S3 s6 = { { 7654, 'x', 65535, 876.0, 877.0, 878.0, 033 },
{ { 10, 9, 8, 7, 6 }, "it's back", { 2000, 2001, 2002 },
{ 7.7, 8.8, 9.9, 11.00 }, { 6.0, 6.0, 6.0 },
{ 1.0, 1.3 }, { 0x7f, 0x80, 0x81, 0x82 },
{ 0x01 } } };
main ()
{
int i, j;
long k;
float f;
double d;
extended e;
unsigned int ui;
int TestStatics1 (void);
int TestStatics2 (void);
extern struct S1 s4;
extern struct S2 s5;
extern struct S3 s6;
if ((s4.i != 32767) || (s4.ch != 'z') || (s4.L != 32788) || (s4.f != 17.0) ||
(s4.d != 18.0) || (s4.e != 19.0) || (s4.bf1 != 5))
goto Fail;
for (j = 10, i = 0; i < 5; i++)
{
if (s5.i1 [i] != j)
goto Fail;
j += 10;
}
if (strcmp (s5.ch1, "ORCA/C !!"))
goto Fail;
for (k = 4, i = 0; i < 3; i++)
if (s5.L1 [i] != k++)
goto Fail;
for (f = 45.0, i = 0; i < 4; i++)
{
if (s5.f1 [i] != f)
goto Fail;
f += 10.0;
}
for (d = 455.0, i = 0; i < 3; i++)
{
if (s5.d1 [i] != d)
goto Fail;
d += 100.0;
}
for (e = 4555.0, i = 0; i < 2; i++)
{
if (s5.e1 [i] != e)
goto Fail;
e += 1000.0;
}
for (i = 0; i < 4; i++)
if (s5.ui [i] != 0)
goto Fail;
for (i = 0; i < 2; i++)
if (s5.ul [i] != 0)
goto Fail;
if ((s6.s1.i != 7654) || (s6.s1.ch != 'x') || (s6.s1.L != 65535) ||
(s6.s1.f != 876.0) || (s6.s1.d != 877.0) || (s6.s1.e != 878.0) ||
(s6.s1.bf1 != 27))
goto Fail;
for (j = 10, i = 0; i < 5; i++)
if (s6.s2.i1 [i] != j--)
goto Fail;
if (strcmp (s6.s2.ch1, "it's back"))
goto Fail;
for (k = 2000, i = 0; i < 3; i++)
if (s6.s2.L1 [i] != k++)
goto Fail;
for (f = 7.7, i = 0; i < 4; i++)
{
if ((s6.s2.f1 [i] - f) > 0.00001)
goto Fail;
f += 1.1;
}
for (d = 6.0, i = 0; i < 3; i++)
if (s6.s2.d1 [i] != d)
goto Fail;
if ((s6.s2.e1 [0] != 1.0) || (s6.s2.e1 [1] != 1.3))
goto Fail;
for (ui = 0x7F, i = 0; i < 4; i++)
if (s6.s2.ui [i] != ui++)
goto Fail;
if ((s6.s2.ul [0] != 1) || (s6.s2.ul [1] != 0))
goto Fail;
if (TestStatics1())
goto Fail;
if (TestStatics2())
goto Fail;
printf ("Passed Conformance Test 4.6.6.1\n");
return;
Fail:
printf ("Failed Conformance Test 4.6.6.1\n");
}
/******************************************************************************/
int TestStatics1 (void)
{
int i, j;
long k;
float f;
double d;
extended e;
unsigned int ui;
static struct S1 s1 = { 1, 'a', -2147483647, 4.3, 4.3e100, 4.3e300, 0xFF };
static struct S2 s2 = { { 1, 2, 3, 4, 5 }, "an array ", { 8, 9, 10 },
{ 5.1, 5.2, 5.3, 5.4 }, { 5.1e50, 5.2e50, 5.3e50 },
{ 5.1e200, 5.2e200, 5.3e200 }, { 0xFFFF, 0xFFFE,
0xFFFD } };
if ((s1.i != 1) || (s1.ch != 'a') || (s1.L != -2147483647) ||
(fabs(s1.f - 4.3) > 0.00001) ||
(fabs(s1.d - 4.3e100) > 1e95) || (s1.bf1 != 0xFF))
goto Fail;
for (i = 0; i < 5; i++)
if (s2.i1 [i] != i + 1)
goto Fail;
if (strcmp (s2.ch1, "an array "))
goto Fail;
for (k = 8, i = 0; i < 3; i++)
if (s2.L1 [i] != k++)
goto Fail;
for (f = 5.1, i = 0; i < 4; i++)
{
if (fabs(s2.f1 [i] - f) > 0.00001)
goto Fail;
f += 0.1;
}
for (d = 5.1e50, i = 0; i < 3; i++)
{
if (fabs(s2.d1 [i] - d) > 1e44)
goto Fail;
d += 0.1e50;
}
for (e = 5.1e200, i = 0; i < 2; i++)
{
if (fabs(s2.e1 [i] - e) > 1e195)
goto Fail;
e += 0.1e200;
}
for (ui = 0xFFFF, i = 0; i < 3; i++)
if (s2.ui [i] != ui--)
goto Fail;
if ((s2.ui [3] != 0) || (s2.ul [0] != 0) || (s2.ul [1] != 0))
goto Fail;
return 0;
Fail:
return 1;
}
/******************************************************************************/
int TestStatics2 (void)
{
int i, j;
long k;
float f;
double d;
extended e;
unsigned int ui;
static struct S3 s1 = { { 9, 'd', 80000, 88.9, 88.99, 888.999, 0x33 },
{ { 9, 8, 7, 6, 5 }, "ten chars",
{ 32768, 32769, 32770 }, { 6.0, 7.0, 8.0, 9.0 },
{ 66.0, 77.0, 88.0, }, { 666.0, 777.0 },
{ 0x7FFF, } } };
if ((s1.s1.i != 9) || (s1.s1.ch != 'd') || (s1.s1.L != 80000) ||
(fabs(s1.s1.f - 88.9) > 0.0001) || (fabs(s1.s1.d - 88.99) > 0.0001) ||
(fabs(s1.s1.e - 888.999) > 0.001) || (s1.s1.bf1 != 0x33))
goto Fail;
for (j = 9, i = 0; i < 5; i++)
if (s1.s2.i1 [i] != j--)
goto Fail;
if (strcmp (s1.s2.ch1, "ten chars"))
goto Fail;
for (k = 32768, i = 0; i < 3; i++)
if (s1.s2.L1 [i] != k++)
goto Fail;
for (f = 6.0, i = 0; i < 4; i++)
{
if (fabs(s1.s2.f1 [i] - f) > 0.00001)
goto Fail;
f += 1.0;
}
for (d = 66.0, i = 0; i < 3; i++)
{
if (fabs(s1.s2.d1 [i] - d) > 0.0001)
goto Fail;
d += 11.0;
}
for (e = 666.0, i = 0; i < 2; i++)
{
if (fabs(s1.s2.e1 [i] - e) > 0.001)
goto Fail;
e += 111.0;
}
if (s1.s2.ui [0] != 0x7FFF)
goto Fail;
for (i = 1; i < 4; i++)
if (s1.s2.ui [i] != 0)
goto Fail;
for (i = 0; i < 2; i++)
if (s1.s2.ul [i] != 0)
goto Fail;
return 0;
Fail:
return 1;
}