aboutsummaryrefslogtreecommitdiff
path: root/src/test/modules/test_json_parser/test_json_parser_incremental.c
diff options
context:
space:
mode:
authorAndrew Dunstan <andrew@dunslane.net>2024-04-23 15:27:40 -0400
committerAndrew Dunstan <andrew@dunslane.net>2024-04-23 15:32:06 -0400
commitba3e6e2bca97df14920375b0a1ebf4eab95b78b5 (patch)
treeee3e960a3d3ae2ff28dc719f5aa86aeea8b2173b /src/test/modules/test_json_parser/test_json_parser_incremental.c
parentb7d35d393edbe2d4333dde81496e8a362abc85bd (diff)
downloadpostgresql-ba3e6e2bca97df14920375b0a1ebf4eab95b78b5.tar.gz
postgresql-ba3e6e2bca97df14920375b0a1ebf4eab95b78b5.zip
Post review fixes for test_json_parser test module
. Add missing copytight notices . improve code coverage . put work files in a temp directory in the standard location . improve error checking in C code . indent perl files with perltidy . add some comments per comments from Michael Paquier Discussion: https://postgr.es/m/ZiC3-cdFys4-6xSk@paquier.xyz
Diffstat (limited to 'src/test/modules/test_json_parser/test_json_parser_incremental.c')
-rw-r--r--src/test/modules/test_json_parser/test_json_parser_incremental.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/test/modules/test_json_parser/test_json_parser_incremental.c b/src/test/modules/test_json_parser/test_json_parser_incremental.c
index 835cdc9efd3..b2195cb8113 100644
--- a/src/test/modules/test_json_parser/test_json_parser_incremental.c
+++ b/src/test/modules/test_json_parser/test_json_parser_incremental.c
@@ -15,6 +15,9 @@
* If the "-c SIZE" option is provided, that chunk size is used instead
* of the default of 60.
*
+ * If the -s flag is given, the program does semantic processing. This should
+ * just mirror back the json, albeit with white space changes.
+ *
* The argument specifies the file containing the JSON input.
*
*-------------------------------------------------------------------------
@@ -28,6 +31,7 @@
#include <unistd.h>
#include "common/jsonapi.h"
+#include "common/logging.h"
#include "lib/stringinfo.h"
#include "mb/pg_wchar.h"
#include "pg_getopt.h"
@@ -92,10 +96,7 @@ main(int argc, char **argv)
case 'c': /* chunksize */
sscanf(optarg, "%zu", &chunk_size);
if (chunk_size > BUFSIZE)
- {
- fprintf(stderr, "chunk size cannot exceed %d\n", BUFSIZE);
- exit(1);
- }
+ pg_fatal("chunk size cannot exceed %d", BUFSIZE);
break;
case 's': /* do semantic processing */
testsem = &sem;
@@ -121,13 +122,25 @@ main(int argc, char **argv)
makeJsonLexContextIncremental(&lex, PG_UTF8, need_strings);
initStringInfo(&json);
- json_file = fopen(testfile, "r");
- fstat(fileno(json_file), &statbuf);
+ if ((json_file = fopen(testfile, "r")) == NULL)
+ pg_fatal("error opening input: %m");
+
+ if (fstat(fileno(json_file), &statbuf) != 0)
+ pg_fatal("error statting input: %m");
+
bytes_left = statbuf.st_size;
for (;;)
{
+ /* We will break when there's nothing left to read */
+
+ if (bytes_left < chunk_size)
+ chunk_size = bytes_left;
+
n_read = fread(buff, 1, chunk_size, json_file);
+ if (n_read < chunk_size)
+ pg_fatal("error reading input file: %d", ferror(json_file));
+
appendBinaryStringInfo(&json, buff, n_read);
/*