mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2025-01-01 13:29:32 +00:00
91d33b586d
The main changes made to most tests are: *Declarations always include explicit types, not relying on implicit int. The declaration of main in most test programs is changed to be "int main (void) {...}", adding an explicit return type and a prototype. (There are still some non-prototyped functions, though.) *Functions are always declared before use, either by including a header or by providing a declaration for the specific function. The latter approach is usually used for printf, to avoid requiring ORCA/C to process stdio.h when compiling every test case (which might make test runs noticeably slower). *Make all return statements in non-void functions (e.g. main) return a value. *Avoid some instances of undefined behavior and type errors in printf and scanf calls. Several miscellaneous bugs are also fixed. There are still a couple test cases that intentionally rely on the C89 behavior, to ensure it still works.
110 lines
2.9 KiB
C++
110 lines
2.9 KiB
C++
/* Conformance Test 5.11.0.1: Verification of type equivalence: int types */
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
|
|
int main (void)
|
|
{
|
|
char ch = 'Z';
|
|
int i = 80, k;
|
|
short sh = 5;
|
|
enum E { a, b, c } e = b;
|
|
unsigned char uch = 'm';
|
|
unsigned int ui = 0xff;
|
|
unsigned short ush = 0x80;
|
|
|
|
static void TestCnv (unsigned int ch, unsigned int i, int ui);
|
|
static int TestInt (int ch, int i, int e, int sh, int ui, int ush, int uch);
|
|
static unsigned int TestUnsigned (unsigned int ush, unsigned int ui,
|
|
unsigned int uch, unsigned int e,
|
|
unsigned int sh, unsigned int i,
|
|
unsigned int ch);
|
|
|
|
|
|
k = TestInt (ch, i, e, sh, ui, ush, uch);
|
|
if (k != 0x703)
|
|
goto Fail;
|
|
|
|
k = TestUnsigned (ush, ui, uch, e, sh, i, ch);
|
|
if (k != 0x3739)
|
|
goto Fail;
|
|
|
|
ch = 131;
|
|
i = -32767;
|
|
ui = 0xa123;
|
|
TestCnv (ch, i, ui);
|
|
|
|
|
|
printf ("Passed Conformance Test 6.2.3.1\n");
|
|
return 0;
|
|
|
|
Fail:
|
|
printf ("Failed Conformance Test 6.2.3.1\n");
|
|
}
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static int TestInt (int ch, int i, int e, int sh, int ui, int ush, int uch)
|
|
{
|
|
int j;
|
|
|
|
/* Ensure parameters have not been changed during usual conversions. */
|
|
|
|
if ((ch != 90) || (i != 80) || (e != 1) || (sh != 5) || (ui != 255) ||
|
|
(ush != 128) || (uch != 109))
|
|
goto Fail;
|
|
|
|
/* Compute integral expression and check expected result. */
|
|
|
|
j = (ch + i * e - ui / sh << 4 | ush >> 1) - (uch);
|
|
if (j != 1795)
|
|
goto Fail;
|
|
return j;
|
|
|
|
Fail:
|
|
printf ("Failure in TestInt function in Conformance Test 5.11.0.1\n");
|
|
exit (-1);
|
|
}
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static unsigned int TestUnsigned (unsigned int ush, unsigned int ui,
|
|
unsigned int uch, unsigned int e,
|
|
unsigned int sh, unsigned int i,
|
|
unsigned int ch)
|
|
{
|
|
unsigned int j;
|
|
|
|
/* Ensure parameters have not been changed during usual conversions. */
|
|
|
|
if ((ush != 128) || (ui != 255) || (sh != 5) || (e != 1) || (i != 80) ||
|
|
(ch != 90) || (uch != 109))
|
|
goto Fail;
|
|
|
|
/* Compute integral expression and check expected result. */
|
|
|
|
j = ((ush ^ e) * uch) - (ch / sh >> 2) + (i & ui);
|
|
if (j != 14137)
|
|
goto Fail;
|
|
return j;
|
|
|
|
Fail:
|
|
printf ("Failure in TestUnsigned function in Conformance Test 6.2.3.1\n");
|
|
exit (-1);
|
|
}
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
static void TestCnv (unsigned int ch, unsigned int i, int ui)
|
|
{
|
|
if ((ch != 0x0083) || (i != 0x8001) || (ui != -24285))
|
|
goto Fail;
|
|
return;
|
|
Fail:
|
|
printf ("Failure in TestCnv function in Conformance Test 6.2.3.1\n");
|
|
exit (-1);
|
|
}
|