libowfat/test/scan_long.c

32 lines
895 B
C
Raw Normal View History

2016-03-17 11:13:23 +00:00
#include "scan.h"
#include "fmt.h"
#include "buffer.h"
2003-05-04 16:20:08 +00:00
#include <assert.h>
2004-11-25 21:52:35 +00:00
int main() {
2003-05-04 16:20:08 +00:00
char buf[1024];
unsigned long long int i;
2013-09-09 22:09:07 +00:00
unsigned long l;
if (sizeof(unsigned long)==4) {
assert(scan_ulong("4294967295",&l) == 10 && l==4294967295ul);
assert(scan_ulong("4294967296",&l) == 9 && l==429496729);
} else {
assert(scan_ulong("18446744073709551615",&l) == 20 && l==18446744073709551615ull);
assert(scan_ulong("18446744073709551616",&l) == 19 && l==1844674407370955161ull);
}
2003-05-04 16:20:08 +00:00
if (sizeof(unsigned long) != 4)
return 0;
for (i=1; i<0xfffffffffull; i+=i+1) {
int k;
unsigned long test;
buf[k=fmt_ulonglong(buf,i)]=0;
buffer_puts(buffer_1,buf); buffer_putnlflush(buffer_1);
if (buf[scan_ulong(buf,&test)])
/* scan did not like the whole number */
assert(i>0xffffffffull);
else
assert(i<=0xffffffffull);
}
2004-11-25 21:52:35 +00:00
return 0;
2003-05-04 16:20:08 +00:00
}