mirror of
https://github.com/json-c/json-c.git
synced 2026-03-30 10:29:06 +08:00
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).
This commit is contained in:
42
tests/parse_flags.c
Normal file
42
tests/parse_flags.c
Normal file
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user