Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added file argument to test #94

Open
wants to merge 1 commit into from

1 participant

@breese

Makes it easier to run specific test cases from a debugger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 19, 2013
  1. Allow file argument

    Bjorn Reese authored
This page is out of date. Refresh to see the latest.
Showing with 17 additions and 7 deletions.
  1. +17 −7 test/yajl_test.c
View
24 test/yajl_test.c
@@ -168,8 +168,9 @@ int
main(int argc, char ** argv)
{
yajl_handle hand;
- const char * fileName;
+ const char * fileName = NULL;
static unsigned char * fileData = NULL;
+ FILE *file;
size_t bufSize = BUF_SIZE;
yajl_status stat;
size_t rd;
@@ -220,9 +221,8 @@ main(int argc, char ** argv)
} else if (!strcmp("-p", argv[i])) {
yajl_config(hand, yajl_allow_partial_values, 1);
} else {
- fprintf(stderr, "invalid command line option: '%s'\n",
- argv[i]);
- usage(argv[0]);
+ fileName = argv[i];
+ break;
}
}
@@ -236,10 +236,16 @@ main(int argc, char ** argv)
exit(2);
}
- fileName = argv[argc-1];
-
+ if (fileName)
+ {
+ file = fopen(fileName, "r");
+ }
+ else
+ {
+ file = stdin;
+ }
for (;;) {
- rd = fread((void *) fileData, 1, bufSize, stdin);
+ rd = fread((void *) fileData, 1, bufSize, file);
if (rd == 0) {
if (!feof(stdin)) {
@@ -265,6 +271,10 @@ main(int argc, char ** argv)
yajl_free(hand);
free(fileData);
+ if (fileName)
+ {
+ fclose(file);
+ }
/* finally, print out some memory statistics */
/* (lth) only print leaks here, as allocations and frees may vary depending
Something went wrong with that request. Please try again.