]> git.draconx.ca Git - dxcommon.git/blobdiff - tests/scripts.at
gen-options.awk: Add a more compact data representation.
[dxcommon.git] / tests / scripts.at
index f4a4a105fb057ede633b10df765502855e9e3066..70df38844813f9bdcf8f9a16935c0206ccc8bed1 100644 (file)
@@ -220,6 +220,72 @@ p
 
 AT_CLEANUP
 
+AT_SETUP([gen-options.awk packed format])
+AT_KEYWORDS([gen-options awk script scripts])
+
+AT_DATA([test.c], [[#include <stdio.h>
+struct option { const char *name; int has_arg; int *flag; int val; };
+
+#include "options.h"
+
+static unsigned opts[] = { LOPTS_PACKED_INITIALIZER };
+
+int main(void)
+{
+  unsigned i;
+  int x =
+#if !LOPT_PACK_BITS
+  0
+#elif LOPT_PACK_BITS <= 8
+  1
+#elif LOPT_PACK_BITS <= 16
+  2
+#elif LOPT_PACK_BITS <= 32
+  3
+#else
+#  error too big
+#endif
+  ;
+  printf("%d\n", x);
+  for (i = 0; i < sizeof opts / sizeof opts[0]; i++) {
+    struct option o;
+
+    LOPT_UNPACK(o, opts[i]);
+    printf("--%s, %d, ", o.name, o.has_arg);
+    if (o.val > UCHAR_MAX)
+      printf("%d\n", o.val - UCHAR_MAX - 1);
+    else
+      printf("'%c'\n", o.val);
+  }
+}
+]])
+
+AT_DATA([single.dat],
+[[--single-option
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <single.dat >options.h])
+AT_CHECK([$CC -o single$EXEEXT test.c && ./single$EXEEXT], [0],
+[[0
+--single-option, 0, 0
+]])
+
+AT_DATA([16bit.dat],
+[[-a, --the-first-option
+-b, --the-second-option=ARG
+-c, --the-third-option[=ARG]
+-d, --the-fourth-option
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-options.awk" <16bit.dat >options.h])
+AT_CHECK([$CC -o 16bit$EXEEXT test.c && ./16bit$EXEEXT], [0],
+[[2
+--the-first-option, 0, 'a'
+--the-second-option, 1, 'b'
+--the-third-option, 2, 'c'
+--the-fourth-option, 0, 'd'
+]])
+
+AT_CLEANUP
+
 AT_SETUP([gen-strtab.awk])
 AT_KEYWORDS([gen-strtab awk script scripts])
 
@@ -328,6 +394,58 @@ AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
   [0], [[1 hello
 ]])
 
+AT_CLEANUP
+
+AT_SETUP([gen-strtab.awk l10n options])
+AT_KEYWORDS([gen-strtab awk script scripts])
+
+AT_DATA([l10n.sed], dnl (
+[[/^#/b
+s/.*N_(\([^)]*\)).*/\1/p
+]])
+
+AT_DATA([test0.def],
+[[&a hello world
+&b world
+&c goodbye
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test0.def >test0.h])
+AT_CHECK([sed -n -f l10n.sed test0.h | LC_ALL=C sort], [0],
+[["goodbye"
+"hello world"
+"world"
+]])
+
+AT_DATA([test1.def],
+[[&a hello world
+&&b world
+&&c goodbye
+]])
+AT_CHECK([$AWK -f "$builddir/scripts/gen-strtab.awk" <test1.def >test1.h])
+AT_CHECK([sed -n -f l10n.sed test1.h], [0],
+[["hello world"
+]])
+
+AT_DATA([test.c],
+[[#include <stdio.h>
+#include HEADER
+
+int main(void)
+{
+  printf("%s %s %s\n", strtab+a, strtab+b, strtab+c);
+  return 0;
+}
+]])
+
+AT_CHECK([$CC -DHEADER='"test0.h"' -o test0$EXEEXT test.c && ./test0$EXEEXT],
+  [0], [[hello world world goodbye
+]])
+
+AT_CHECK([$CC -DHEADER='"test1.h"' -o test1$EXEEXT test.c && ./test1$EXEEXT],
+  [0], [[hello world world goodbye
+]])
+
+
 AT_CLEANUP
 
 AT_SETUP([gen-tree.awk])