forked from json-c/json-c
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extend test1 and test2 to run using json_object_to_json_string_ext() …
…based on an additional command line parameter. Extend the run_output_test() function so we actually can pass command line parameters and so we can support different output files for the same test executable. Also provide some hints about what to do if a test fails (i.e. set VERBOSE=1).
- Loading branch information
Showing
14 changed files
with
293 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "json.h" | ||
#include "parse_flags.h" | ||
|
||
static struct { | ||
const char *arg; | ||
int flag; | ||
} format_args[] = { | ||
{ "plain", JSON_C_TO_STRING_PLAIN }, | ||
{ "spaced", JSON_C_TO_STRING_SPACED }, | ||
{ "pretty", JSON_C_TO_STRING_PRETTY }, | ||
}; | ||
|
||
#ifndef NELEM | ||
#define NELEM(x) (sizeof(x) / sizeof(&x[0])) | ||
#endif | ||
|
||
int parse_flags(int argc, char **argv) | ||
{ | ||
int arg_idx; | ||
int sflags = 0; | ||
for (arg_idx = 1; arg_idx < argc ; arg_idx++) | ||
{ | ||
int jj; | ||
for (jj = 0; jj < NELEM(format_args); jj++) | ||
{ | ||
if (strcasecmp(argv[arg_idx], format_args[jj].arg) == 0) | ||
{ | ||
sflags |= format_args[jj].flag; | ||
break; | ||
} | ||
} | ||
if (jj == NELEM(format_args)) | ||
{ | ||
printf("Unknown arg: %s\n", argv[arg_idx]); | ||
exit(1); | ||
} | ||
} | ||
return sflags; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef __parse_flags_h | ||
#define __parse_flags_h | ||
int parse_flags(int argc, char **argv); | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
my_string= | ||
my_string.to_string()="\t" | ||
my_string=\ | ||
my_string.to_string()="\\" | ||
my_string=foo | ||
my_string.to_string()="foo" | ||
my_int=9 | ||
my_int.to_string()=9 | ||
my_array= | ||
[0]=1 | ||
[1]=2 | ||
[2]=3 | ||
[3]=null | ||
[4]=5 | ||
my_array.to_string()=[1,2,3,null,5] | ||
my_array= | ||
[0]=3 | ||
[1]=1 | ||
[2]=2 | ||
[3]=null | ||
[4]=0 | ||
my_array.to_string()=[3,1,2,null,0] | ||
my_array= | ||
[0]=null | ||
[1]=0 | ||
[2]=1 | ||
[3]=2 | ||
[4]=3 | ||
my_array.to_string()=[null,0,1,2,3] | ||
my_object= | ||
abc: 12 | ||
foo: "bar" | ||
bool0: false | ||
bool1: true | ||
my_object.to_string()={"abc":12,"foo":"bar","bool0":false,"bool1":true} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
my_string= | ||
my_string.to_string()="\t" | ||
my_string=\ | ||
my_string.to_string()="\\" | ||
my_string=foo | ||
my_string.to_string()="foo" | ||
my_int=9 | ||
my_int.to_string()=9 | ||
my_array= | ||
[0]=1 | ||
[1]=2 | ||
[2]=3 | ||
[3]=null | ||
[4]=5 | ||
my_array.to_string()=[ | ||
1, | ||
2, | ||
3, | ||
null, | ||
5 | ||
] | ||
my_array= | ||
[0]=3 | ||
[1]=1 | ||
[2]=2 | ||
[3]=null | ||
[4]=0 | ||
my_array.to_string()=[ | ||
3, | ||
1, | ||
2, | ||
null, | ||
0 | ||
] | ||
my_array= | ||
[0]=null | ||
[1]=0 | ||
[2]=1 | ||
[3]=2 | ||
[4]=3 | ||
my_array.to_string()=[ | ||
null, | ||
0, | ||
1, | ||
2, | ||
3 | ||
] | ||
my_object= | ||
abc: 12 | ||
foo: "bar" | ||
bool0: false | ||
bool1: true | ||
my_object.to_string()={ | ||
"abc":12, | ||
"foo":"bar", | ||
"bool0":false, | ||
"bool1":true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
my_string= | ||
my_string.to_string()="\t" | ||
my_string=\ | ||
my_string.to_string()="\\" | ||
my_string=foo | ||
my_string.to_string()="foo" | ||
my_int=9 | ||
my_int.to_string()=9 | ||
my_array= | ||
[0]=1 | ||
[1]=2 | ||
[2]=3 | ||
[3]=null | ||
[4]=5 | ||
my_array.to_string()=[ 1, 2, 3, null, 5 ] | ||
my_array= | ||
[0]=3 | ||
[1]=1 | ||
[2]=2 | ||
[3]=null | ||
[4]=0 | ||
my_array.to_string()=[ 3, 1, 2, null, 0 ] | ||
my_array= | ||
[0]=null | ||
[1]=0 | ||
[2]=1 | ||
[3]=2 | ||
[4]=3 | ||
my_array.to_string()=[ null, 0, 1, 2, 3 ] | ||
my_object= | ||
abc: 12 | ||
foo: "bar" | ||
bool0: false | ||
bool1: true | ||
my_object.to_string()={ "abc": 12, "foo": "bar", "bool0": false, "bool1": true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.