1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-28 06:30:16 +00:00
cc65/test/val/sub3.c
2023-11-13 10:32:27 +01:00

193 lines
2.4 KiB
C

/*
!!DESCRIPTION!! Subtraction Test
!!ORIGIN!! SDCC regression tests
!!LICENCE!! GPL, read COPYING.GPL
*/
#include <stdio.h>
#include <limits.h>
unsigned char failures=0;
int int0 = 5;
unsigned int int1 = 5;
void pre_dec_test(void)
{
if(int0 != 5)
failures++;
if(int1 != 5)
failures++;
--int0;
--int1;
if(int0 != 4)
failures++;
if(int1 != 4)
failures++;
--int0;
--int1;
--int0;
--int1;
--int0;
--int1;
--int0;
--int1;
if(int0 != 0)
failures++;
if(int1 != 0)
failures++;
--int0;
--int1;
if(int0 != -1)
failures++;
if(int1 != 65535U)
failures++;
}
void post_dec_test(void)
{
if(int0 != 5)
failures++;
if(int1 != 5)
failures++;
int0--;
int1--;
if(int0 != 4)
failures++;
if(int1 != 4)
failures++;
int0--;
int1--;
int0--;
int1--;
int0--;
int1--;
int0--;
int1--;
if(int0 != 0)
failures++;
if(int1 != 0)
failures++;
int0--;
int1--;
if(int0 != -1)
failures++;
if(int1 != 65535U)
failures++;
}
void pre_dec_assign_test(void)
{
int a;
unsigned int b;
if(int0 != 5)
failures++;
if(int1 != 5)
failures++;
a = --int0;
b = --int1;
if(int0 != 4 || a != int0)
failures++;
if(int1 != 4 || b != int1)
failures++;
a = --int0;
b = --int1;
a = --int0;
b = --int1;
a = --int0;
b = --int1;
a = --int0;
b = --int1;
if(int0 != 0 || a != int0)
failures++;
if(int1 != 0 || b != int1)
failures++;
a = --int0;
b = --int1;
if(int0 != -1 || a != int0)
failures++;
if(int1 != 65535U || b != int1)
failures++;
}
void post_dec_assign_test(void)
{
int a;
unsigned int b;
if(int0 != 5)
failures++;
if(int1 != 5)
failures++;
a = int0--;
b = int1--;
if(int0 != 4 || a != 5)
failures++;
if(int1 != 4 || b != 5)
failures++;
a = int0--;
b = int1--;
a = int0--;
b = int1--;
a = int0--;
b = int1--;
a = int0--;
b = int1--;
if(int0 != 0 || a != 1)
failures++;
if(int1 != 0 || b != 1)
failures++;
a = int0--;
b = int1--;
if(int0 != -1 || a != 0)
failures++;
if(int1 != 65535U || b != 0)
failures++;
}
int main(void)
{
int0 = 5;
int1 = 5;
pre_dec_test();
int0 = 5;
int1 = 5;
post_dec_test();
int0 = 5;
int1 = 5;
pre_dec_assign_test();
int0 = 5;
int1 = 5;
post_dec_assign_test();
printf("failures: %d\n",failures);
return failures;
}