1
0
mirror of https://github.com/cc65/cc65.git synced 2024-07-01 08:29:37 +00:00

Merge pull request #173 from mrdudz/testsuite3

two more tests
This commit is contained in:
Oliver Schmidt 2015-07-09 18:46:07 +02:00
commit bdb01212c2
2 changed files with 122 additions and 0 deletions

73
test/val/add3a.c Executable file
View File

@ -0,0 +1,73 @@
/*
!!DESCRIPTION!! Addition tests - mostly int's
!!ORIGIN!! SDCC regression tests
!!LICENCE!! GPL, read COPYING.GPL
*/
#include <stdio.h>
#include <stdlib.h>
static unsigned int failures = 0;
/*
this test assumes:
sizeof(long) == 4
CAUTION: the wraparound behaviour is actually undefined, to get the "expected"
behaviour with GCC, use -fwrapv or -fno-strict-overflow
see: https://gcc.gnu.org/wiki/FAQ#signed_overflow
*/
#ifdef REFERENCE
/*
make sure the reference output uses types with
proper size
*/
#include <stdint.h>
int32_t long0 = 0;
#else
long long0 = 0;
#endif
void print(void)
{
#if defined(REFERENCE) && defined(REFCC_SIZEOF_LONG_64BIT)
printf("long0: %d\n", long0);
#else
printf("long0: %ld\n", long0);
#endif
}
int main(void)
{
long0 = 0x7f000000L;
/* wrap around zero */
print();
long0 = long0 + 0x2000000L;
if(long0 != -0x7f000000L) {
printf("failed!\n");
failures++;
}
print();
long0 = 0x7f000000L;
/* wrap around zero */
print();
long0 = long0 + 0x2000000L;
print();
if(long0 != -0x7f000000L) {
printf("failed!\n");
failures++;
}
print();
return failures;
}

49
test/val/casttochar.c Executable file
View File

@ -0,0 +1,49 @@
/*
!!DESCRIPTION!! Cast to char
!!ORIGIN!! Piotr Fusik
!!LICENCE!! PD
*/
#include <stdio.h>
#include <stdlib.h>
static unsigned int failures = 0;
int f1(int i, int j) {
return (signed char) (i + 1) == j;
}
int f2(int i, int j) {
return (unsigned char) (i + 1) == j;
}
int f3(int i, int j) {
return (char) (i + 1) == j;
}
int main(void)
{
printf("f1: got :%04x ", f1(0x1234, 0x35));
if(f1(0x1234, 0x35) == 0) {
printf("- failed");
failures++;
}
printf("\n");
printf("f2: got :%04x ", f2(0x1234, 0x35));
if(f2(0x1234, 0x35) == 0) {
printf("- failed");
failures++;
}
printf("\n");
printf("f3: got :%04x ", f3(0x1234, 0x35));
if(f3(0x1234, 0x35) == 0) {
printf("- failed");
failures++;
}
printf("\n");
return failures;
}