add scan_netstring
This commit is contained in:
@@ -6,6 +6,14 @@
|
||||
int main() {
|
||||
char buf[1024];
|
||||
unsigned long long int i;
|
||||
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);
|
||||
}
|
||||
if (sizeof(unsigned long) != 4)
|
||||
return 0;
|
||||
for (i=1; i<0xfffffffffull; i+=i+1) {
|
||||
|
||||
11
test/scan_netstring.c
Normal file
11
test/scan_netstring.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "scan.h"
|
||||
#include <assert.h>
|
||||
|
||||
int main() {
|
||||
char* s;
|
||||
size_t l;
|
||||
const char* orig;
|
||||
orig="3:foo,"; assert(scan_netstring(orig,6,&s,&l)==6); assert(s==orig+2);
|
||||
orig="4294967295:foo,"; assert(scan_netstring(orig,15,&s,&l)==0);
|
||||
orig="18446744073709551615:foo,"; assert(scan_netstring(orig,25,&s,&l)==0);
|
||||
}
|
||||
Reference in New Issue
Block a user