Browse Source

jsoncmp

release/v0.1
jl777 9 years ago
parent
commit
3ac1a2d236
  1. 8
      README.md
  2. 2
      crypto777/iguana_secp.c
  3. 2
      iguana/iguana_bundles.c
  4. BIN
      iguana/tests/.jsoncmp.c.swp
  5. BIN
      iguana/tests/jsoncmp
  6. 44
      iguana/tests/jsoncmp.c
  7. 2
      iguana/tests/test

8
README.md

@ -130,3 +130,11 @@ During the syncing, I have many, many messages like this:
>> >>
Loretta:/Users/volker/SuperNET # ulimit -n 2048 Loretta:/Users/volker/SuperNET # ulimit -n 2048
##### tests
in the SuperNET/iguana/tests directory, there is a jsoncmp.c file, which can be built into the jsoncmp executable via ./make_jsoncmp
once jsoncmp is built, then ./test shows how to use it
./jsoncmp <filename> {\"fields\":[{\"fieldA\":\"requiredvalueA\"},{\"fieldB\":\"requiredvalueB\"},...]}
the idea is to issue a curl command into a /tmp/file and then use jsoncmp to verify the exact value of one or more fields. it will print to stdout JSON with "error" or "result" and to stderr if there is an error

2
crypto777/iguana_secp.c

@ -234,3 +234,5 @@ int32_t bitcoin_verify(uint8_t *sig,int32_t siglen,uint8_t *data,int32_t datalen
} }
return(retval); return(retval);
} }

2
iguana/iguana_bundles.c

@ -441,7 +441,7 @@ void iguana_bundlepurgefiles(struct iguana_info *coin,struct iguana_bundle *bp)
} }
subdir = bp->bundleheight / IGUANA_SUBDIRDIVISOR; subdir = bp->bundleheight / IGUANA_SUBDIRDIVISOR;
sprintf(fname,"%s/%s/%d/%d",GLOBAL_TMPDIR,coin->symbol,subdir,bp->bundleheight), OS_remove_directory(fname); sprintf(fname,"%s/%s/%d/%d",GLOBAL_TMPDIR,coin->symbol,subdir,bp->bundleheight), OS_remove_directory(fname);
printf("purged hdrsi.[%d] subdir.%d lag.%ld\n",bp->hdrsi,subdir,time(NULL) - bp->emitfinish); //printf("purged hdrsi.[%d] subdir.%d lag.%ld\n",bp->hdrsi,subdir,time(NULL) - bp->emitfinish);
bp->purgetime = (uint32_t)time(NULL); bp->purgetime = (uint32_t)time(NULL);
if ( 0 ) if ( 0 )
{ {

BIN
iguana/tests/.jsoncmp.c.swp

Binary file not shown.

BIN
iguana/tests/jsoncmp

Binary file not shown.

44
iguana/tests/jsoncmp.c

@ -9,35 +9,37 @@ int32_t main(int32_t argc,char **argv)
if ( argc > 2 && (argjson= cJSON_Parse(argv[2])) != 0 ) if ( argc > 2 && (argjson= cJSON_Parse(argv[2])) != 0 )
{ {
fname = argv[1]; fname = argv[1];
printf("fname.%s\n",argv[1]); if ( (filestr= OS_filestr(&filesize,fname)) != 0 )
if ( (filestr= OS_filestr(&filesize,fname)) != 0 )
{ {
if ( (filejson= cJSON_Parse(filestr)) != 0 ) if ( (filejson= cJSON_Parse(filestr)) != 0 )
{ {
if ( (array= jarray(&n,argjson,"fields")) == 0 ) if ( (array= jarray(&n,argjson,"fields")) != 0 )
obj = jobj(argjson,"field"), n = 1;
else obj = jitem(array,0);
for (i=0; i<n; i++)
{ {
if ( (field= jfieldname(obj)) != 0 ) for (i=0; i<n; i++)
{ {
if ( (fobj= jobj(filejson,field)) != 0 ) obj = jitem(array,i);
if ( (field= jfieldname(obj)) != 0 && (obj= obj->child) != 0 )
{ {
fstr = jprint(fobj,0); if ( (fobj= jobj(filejson,field)) != 0 )
str = jprint(obj,0); {
if ( strcmp(fstr,str) != 0 ) fstr = jprint(fobj,0);
printf("field.(%s) in (%s) mismatch (%s) != (%s)\n",field,fname,fstr,str); str = jprint(obj,0);
free(str); if ( strcmp(fstr,str) != 0 )
free(fstr); {
} else printf("cant find field.(%s) in (%s)\n",field,fname); printf("{\"error\":\"field.(%s) in (%s) i.%d of n.%d mismatch (%s) != (%s)\"}\n",field,fname,i,n,fstr,str);
fprintf(stderr,"{\"error\":\"field.(%s) in (%s) i.%d of n.%d mismatch (%s) != (%s)\"}\n",field,fname,i,n,fstr,str);
}
else printf("{\"result\":\"MATCHED.[%s] (%s).(%s)\"}\n",fname,field,fstr);
free(str);
free(fstr);
} else fprintf(stderr,"cant find field.(%s) in (%s)\n",field,fname);
} else fprintf(stderr,"no fieldname array[%d]\n",i);
} }
if ( i < n-1 ) } else fprintf(stderr,"no fields array\n");
obj = jitem(array,i+1);
}
free_json(filejson); free_json(filejson);
} } else fprintf(stderr,"cant parse.(%s)\n",filestr);
free(filestr); free(filestr);
} } else fprintf(stderr,"cant load (%s)\n",fname);
} else printf("argc.%d fname.(%s) error\n",argc,argv[1]); } else fprintf(stderr,"argc.%d fname.(%s) error\n",argc,argv[1]);
} }

2
iguana/tests/test

@ -0,0 +1,2 @@
echo "{\"field\":\"requiredvalue\"}" > /tmp/foo
./jsoncmp /tmp/foo {\"fields\":[{\"field\":\"requiredvalue\"}]}
Loading…
Cancel
Save