commit f23cbefa094449452e8352d50c11ab43abc16f33
Author: Laslo Hunhold <[email protected]>
AuthorDate: Sun Jan 9 12:42:47 2022 +0100
Commit: Laslo Hunhold <[email protected]>
CommitDate: Sun Jan 9 12:46:51 2022 +0100
Homogenize and rename some types/functions in gen/ and test/
"segment_test" wasn't very clear wording, given we call them
break tests everywhere. However, the exported type by the generators
was just called "struct test", which is too unspecific. Also, the
naming "st" and "numsegtests" was bad, so it was changed to a homogenous
"test" and "testlen".
This way, the "public" types in gen/types.h can be pulled into
gen/util.h for internal usage, improving overall readability.
Signed-off-by: Laslo Hunhold <[email protected]>
diff --git a/benchmark/util.c b/benchmark/util.c
index 4520125..b5d7e23 100644
--- a/benchmark/util.c
+++ b/benchmark/util.c
@@ -4,27 +4,29 @@
#include <stdio.h>
#include <time.h>
+#include "../gen/types.h"
#include "util.h"
uint_least32_t *
-generate_test_buffer(const struct test *t, size_t tlen, size_t *bufsiz)
+generate_test_buffer(const struct break_test *test, size_t testlen,
+ size_t *bufsiz)
{
size_t i, j, off;
uint_least32_t *buf;
/* allocate and generate buffer */
- for (i = 0, *bufsiz = 0; i < tlen; i++) {
- *bufsiz += t[i].cplen;
+ for (i = 0, *bufsiz = 0; i < testlen; i++) {
+ *bufsiz += test[i].cplen;
}
if (!(buf = calloc(*bufsiz, sizeof(*buf)))) {
fprintf(stderr, "generate_test_buffer: calloc: Out of
memory.\n");
return NULL;
}
- for (i = 0, off = 0; i < tlen; i++) {
- for (j = 0; j < t[i].cplen; j++) {
- buf[off + j] = t[i].cp[j];
+ for (i = 0, off = 0; i < testlen; i++) {
+ for (j = 0; j < test[i].cplen; j++) {
+ buf[off + j] = test[i].cp[j];
}
- off += t[i].cplen;
+ off += test[i].cplen;
}
return buf;
diff --git a/benchmark/util.h b/benchmark/util.h
index 9159327..7451290 100644
--- a/benchmark/util.h
+++ b/benchmark/util.h
@@ -6,7 +6,8 @@
#define LEN(x) (sizeof(x) / sizeof(*(x)))
-uint_least32_t *generate_test_buffer(const struct test *, size_t, size_t *);
+uint_least32_t *generate_test_buffer(const struct break_test *, size_t,
+ size_t *);
void run_benchmark(void (*func)(const void *), const void *, const char *,
const char *, const char *, double *, size_t, size_t);
diff --git a/gen/character-test.c b/gen/character-test.c
index d4235cb..f620935 100644
--- a/gen/character-test.c
+++ b/gen/character-test.c
@@ -6,14 +6,14 @@
int
main(int argc, char *argv[])
{
- struct segment_test *st = NULL;
- size_t numsegtests = 0;
+ struct break_test *test = NULL;
+ size_t testlen = 0;
(void)argc;
- segment_test_list_parse("data/GraphemeBreakTest.txt", &st,
&numsegtests);
- segment_test_list_print(st, numsegtests, "character_test", argv[0]);
- segment_test_list_free(st, numsegtests);
+ break_test_list_parse("data/GraphemeBreakTest.txt", &test, &testlen);
+ break_test_list_print(test, testlen, "character_test", argv[0]);
+ break_test_list_free(test, testlen);
return 0;
}
diff --git a/gen/types.h b/gen/types.h
index 1b09fd8..85379fd 100644
--- a/gen/types.h
+++ b/gen/types.h
@@ -5,7 +5,7 @@
#include <stddef.h>
#include <stdint.h>
-struct test {
+struct break_test {
uint_least32_t *cp;
size_t cplen;
size_t *len;
diff --git a/gen/util.c b/gen/util.c
index ea08588..34f3148 100644
--- a/gen/util.c
+++ b/gen/util.c
@@ -34,10 +34,10 @@ struct properties_major_minor {
size_t minorlen;
};
-struct segment_test_payload
+struct break_test_payload
{
- struct segment_test **st;
- size_t *numsegtests;
+ struct break_test **test;
+ size_t *testlen;
};
static int
@@ -422,7 +422,7 @@ set_value_bp(struct properties_payload *payload,
uint_least32_t cp,
{
if (payload->prop[cp].break_property != 0) {
fprintf(stderr, "set_value_bp: "
- "Character break property overlap.\n");
+ "Character break property overlap.\n");
return 1;
}
payload->prop[cp].break_property = value;
@@ -519,12 +519,12 @@ properties_generate_break_property(const struct
property_spec *spec,
}
static int
-segment_test_callback(const char *fname, char **field, size_t nfields,
+break_test_callback(const char *fname, char **field, size_t nfields,
char *comment, void *payload)
{
- struct segment_test *t,
- **test = ((struct segment_test_payload *)payload)->st;
- size_t i, *ntests = ((struct segment_test_payload
*)payload)->numsegtests;
+ struct break_test *t,
+ **test = ((struct break_test_payload *)payload)->test;
+ size_t i, *testlen = ((struct break_test_payload *)payload)->testlen;
char *token;
(void)fname;
@@ -534,12 +534,12 @@ segment_test_callback(const char *fname, char **field,
size_t nfields,
}
/* append new testcase and initialize with zeroes */
- if ((*test = realloc(*test, ++(*ntests) * sizeof(**test))) == NULL) {
- fprintf(stderr, "segment_test_callback: realloc: %s.\n",
+ if ((*test = realloc(*test, ++(*testlen) * sizeof(**test))) == NULL) {
+ fprintf(stderr, "break_test_callback: realloc: %s.\n",
strerror(errno));
return 1;
}
- t = &(*test)[*ntests - 1];
+ t = &(*test)[*testlen - 1];
memset(t, 0, sizeof(*t));
/* parse testcase "<÷|Ã> <cp> <÷|Ã> ... <cp> <÷|Ã>" */
@@ -555,7 +555,7 @@ segment_test_callback(const char *fname, char **field,
size_t nfields,
*/
if ((t->len = realloc(t->len,
++t->lenlen * sizeof(*t->len))) == NULL) {
- fprintf(stderr, "segment_test_"
+ fprintf(stderr, "break_test_"
"callback: realloc: %s.\n",
strerror(errno));
return 1;
@@ -566,7 +566,7 @@ segment_test_callback(const char *fname, char **field,
size_t nfields,
* 'Ã' indicates a non-breakpoint, do nothing
*/
} else {
- fprintf(stderr, "segment_test_callback: "
+ fprintf(stderr, "break_test_callback: "
"Malformed delimiter '%s'.\n", token);
return 1;
}
@@ -574,7 +574,7 @@ segment_test_callback(const char *fname, char **field,
size_t nfields,
/* add codepoint to cp-array */
if ((t->cp = realloc(t->cp, ++t->cplen *
sizeof(*t->cp))) == NULL) {
- fprintf(stderr, "segment_test_callback: "
+ fprintf(stderr, "break_test_callback: "
"realloc: %s.\n", strerror(errno));
return 1;
}
@@ -592,8 +592,8 @@ segment_test_callback(const char *fname, char **field,
size_t nfields,
}
/* store comment */
- if (((*test)[*ntests - 1].descr = strdup(comment)) == NULL) {
- fprintf(stderr, "segment_test_callback: strdup: %s.\n",
+ if (((*test)[*testlen - 1].descr = strdup(comment)) == NULL) {
+ fprintf(stderr, "break_test_callback: strdup: %s.\n",
strerror(errno));
return 1;
}
@@ -602,21 +602,21 @@ segment_test_callback(const char *fname, char **field,
size_t nfields,
}
void
-segment_test_list_parse(char *fname, struct segment_test **st,
- size_t *numsegtests)
+break_test_list_parse(char *fname, struct break_test **test,
+ size_t *testlen)
{
- struct segment_test_payload pl = {
- .st = st,
- .numsegtests = numsegtests
+ struct break_test_payload pl = {
+ .test = test,
+ .testlen = testlen,
};
- *st = NULL;
- *numsegtests = 0;
+ *test = NULL;
+ *testlen = 0;
- parse_file_with_callback(fname, segment_test_callback, &pl);
+ parse_file_with_callback(fname, break_test_callback, &pl);
}
void
-segment_test_list_print(const struct segment_test *st, size_t numsegtests,
+break_test_list_print(const struct break_test *test, size_t testlen,
const char *identifier, const char *progname)
{
size_t i, j;
@@ -625,31 +625,31 @@ segment_test_list_print(const struct segment_test *st,
size_t numsegtests,
"#include <stdint.h>\n#include <stddef.h>\n\n"
"#include \"../gen/types.h\"\n\n", progname);
- printf("static const struct test %s[] = {\n", identifier);
- for (i = 0; i < numsegtests; i++) {
+ printf("static const struct break_test %s[] = {\n", identifier);
+ for (i = 0; i < testlen; i++) {
printf("\t{\n");
printf("\t\t.cp = (uint_least32_t[]){");
- for (j = 0; j < st[i].cplen; j++) {
- printf(" UINT32_C(0x%06X)", st[i].cp[j]);
- if (j + 1 < st[i].cplen) {
+ for (j = 0; j < test[i].cplen; j++) {
+ printf(" UINT32_C(0x%06X)", test[i].cp[j]);
+ if (j + 1 < test[i].cplen) {
putchar(',');
}
}
printf(" },\n");
- printf("\t\t.cplen = %zu,\n", st[i].cplen);
+ printf("\t\t.cplen = %zu,\n", test[i].cplen);
printf("\t\t.len = (size_t[]){");
- for (j = 0; j < st[i].lenlen; j++) {
- printf(" %zu", st[i].len[j]);
- if (j + 1 < st[i].lenlen) {
+ for (j = 0; j < test[i].lenlen; j++) {
+ printf(" %zu", test[i].len[j]);
+ if (j + 1 < test[i].lenlen) {
putchar(',');
}
}
printf(" },\n");
- printf("\t\t.lenlen = %zu,\n", st[i].lenlen);
+ printf("\t\t.lenlen = %zu,\n", test[i].lenlen);
- printf("\t\t.descr = \"%s\",\n", st[i].descr);
+ printf("\t\t.descr = \"%s\",\n", test[i].descr);
printf("\t},\n");
}
@@ -657,9 +657,9 @@ segment_test_list_print(const struct segment_test *st,
size_t numsegtests,
}
void
-segment_test_list_free(struct segment_test *st, size_t numsegtests)
+break_test_list_free(struct break_test *test, size_t testlen)
{
- (void)numsegtests;
+ (void)testlen;
- free(st);
+ free(test);
}
diff --git a/gen/util.h b/gen/util.h
index 033c572..119bcc4 100644
--- a/gen/util.h
+++ b/gen/util.h
@@ -5,6 +5,8 @@
#include <stddef.h>
#include <stdint.h>
+#include "types.h"
+
#define LEN(x) (sizeof (x) / sizeof *(x))
struct property_spec {
@@ -17,14 +19,6 @@ struct properties {
uint_least8_t break_property;
};
-struct segment_test {
- uint_least32_t *cp;
- size_t cplen;
- size_t *len;
- size_t lenlen;
- char *descr;
-};
-
void parse_file_with_callback(const char *, int (*callback)(const char *,
char **, size_t, char *, void *), void *payload);
@@ -32,9 +26,9 @@ void properties_generate_break_property(const struct
property_spec *,
uint_least8_t, const char *,
const char *);
-void segment_test_list_parse(char *, struct segment_test **, size_t *);
-void segment_test_list_print(const struct segment_test *, size_t,
+void break_test_list_parse(char *, struct break_test **, size_t *);
+void break_test_list_print(const struct break_test *, size_t,
const char *, const char *);
-void segment_test_list_free(struct segment_test *, size_t);
+void break_test_list_free(struct break_test *, size_t);
#endif /* UTIL_H */
diff --git a/test/util.c b/test/util.c
index 6d3d95a..05f5e73 100644
--- a/test/util.c
+++ b/test/util.c
@@ -11,7 +11,7 @@
int
run_break_tests(bool (*is_break)(uint_least32_t, uint_least32_t,
GRAPHEME_STATE *),
- const struct test *test, size_t testlen, const char *argv0)
+ const struct break_test *test, size_t testlen, const char
*argv0)
{
GRAPHEME_STATE state;
size_t i, j, k, len, failed;
diff --git a/test/util.h b/test/util.h
index 02710ba..ef61b18 100644
--- a/test/util.h
+++ b/test/util.h
@@ -8,7 +8,7 @@
#define LEN(x) (sizeof(x) / sizeof(*(x)))
int run_break_tests(bool (*is_break)(uint_least32_t, uint_least32_t,
- GRAPHEME_STATE *), const struct test *test,
+ GRAPHEME_STATE *), const struct break_test *test,
size_t testlen, const char *);
#endif /* UTIL_H */