aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tk@the-tk.com>2021-06-03 16:14:25 +0100
committerTomasz Kramkowski <tk@the-tk.com>2021-06-03 22:11:07 +0100
commitc9a8313e7c883cd864f5fe8e1a527c876f5913f2 (patch)
tree710f3fa456e69af1ad6499b7eaa280a7e01da0c2
parentfd74dae4817aedeecbb5a2b9782378db1a3d9e3d (diff)
downloadpack-c9a8313e7c883cd864f5fe8e1a527c876f5913f2.tar.gz
pack-c9a8313e7c883cd864f5fe8e1a527c876f5913f2.tar.xz
pack-c9a8313e7c883cd864f5fe8e1a527c876f5913f2.zip
test_gen: unpack_gen now takes const struct fmtinfo *fi
Also not sure why this wasn't the case from the beginning. The code is shorter now.
-rw-r--r--test_gen.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/test_gen.c b/test_gen.c
index e23f86c..809b1ba 100644
--- a/test_gen.c
+++ b/test_gen.c
@@ -122,16 +122,11 @@ static void unpack_unsigned(FILE *out, const struct fmtinfo *fi, enum endian e,
fprintf(out, "\tCHECK_EQUAL(PRIdMAX, (uintmax_t)v[%d], UINTMAX_C(%" PRIuMAX "));\n", i, testval);
}
-static void unpack_gen(FILE *out, size_t fmt, int arraysize)
+static void unpack_gen(FILE *out, const struct fmtinfo *fi, int arraysize)
{
int realsize = arraysize == 0 ? 1 : arraysize;
- struct fmtinfo *fi;
bool sign;
- assert(fmt < sizeof fmtinfo / sizeof fmtinfo[0]);
-
- fi = &fmtinfo[fmt];
-
sign = islower(fi->fmt);
fprintf(out, "TEST(unpack_simple%d_%s, \"unpack simple", arraysize, cname(fi->type));
@@ -157,9 +152,9 @@ static void unpack_gen(FILE *out, size_t fmt, int arraysize)
int main(void)
{
FILE *out = stdout;
- for (size_t fmt = 0; fmt < sizeof fmtinfo / sizeof fmtinfo[0]; fmt++) {
- unpack_gen(out, fmt, 0);
- for (int i = 2; i < 4; i++)
- unpack_gen(out, fmt, i);
+ for (size_t i = 0; i < sizeof fmtinfo / sizeof fmtinfo[0]; i++) {
+ unpack_gen(out, &fmtinfo[i], 0);
+ for (int j = 2; j < 4; j++)
+ unpack_gen(out, &fmtinfo[i], j);
}
}