aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2017-05-28 09:54:05 +0100
committerSimon Tatham <anakin@pobox.com>2017-05-28 09:54:05 +0100
commitfe5eb01f9b84b344bd1d476f409626fd7b4cd5f9 (patch)
treed378e92065fa90a1cce69eb38b3b3351ea6b3d50
parentf501b2927d7e4bf6b26c1e348270e6f4a48ffb27 (diff)
downloadwix-on-linux-fe5eb01f9b84b344bd1d476f409626fd7b4cd5f9.tar.gz
wix-on-linux-fe5eb01f9b84b344bd1d476f409626fd7b4cd5f9.tar.bz2
wix-on-linux-fe5eb01f9b84b344bd1d476f409626fd7b4cd5f9.zip
Add a command-line test program.
At the moment it only tests MsiGetFileVersion, because that's the piece I just found a problem in, but I could easily extend it to have convenient command-line test rigs for other parts of this setup too.
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am7
-rw-r--r--api.h6
-rw-r--r--misc.h1
-rw-r--r--test.c33
-rw-r--r--uchars.c2
-rw-r--r--uchars.h2
-rw-r--r--version.c1
8 files changed, 50 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index df4b72b..740825f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@
7*.a 7*.a
8*.so 8*.so
9*.so.* 9*.so.*
10/test
10/Makefile 11/Makefile
11/Makefile.in 12/Makefile.in
12/aclocal.m4 13/aclocal.m4
diff --git a/Makefile.am b/Makefile.am
index f2695f1..e952730 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,6 +2,8 @@ libdir = $(bindir)
2 2
3ACLOCAL_AMFLAGS = -I m4 3ACLOCAL_AMFLAGS = -I m4
4 4
5noinst_PROGRAMS = test
6
5lib_LTLIBRARIES = libwinterop.la libmsi.la libpreload.la 7lib_LTLIBRARIES = libwinterop.la libmsi.la libpreload.la
6 8
7libwinterop_la_SOURCES = makecab.c readcab.c winterop-stubs.c \ 9libwinterop_la_SOURCES = makecab.c readcab.c winterop-stubs.c \
@@ -9,11 +11,14 @@ memory.c memory.h dupstr.c dupstr.h subproc.c subproc.h uchars.c \
9uchars.h 11uchars.h
10 12
11libmsi_la_SOURCES = makemsi.c md5.c memory.c memory.h version.c \ 13libmsi_la_SOURCES = makemsi.c md5.c memory.c memory.h version.c \
12dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h 14dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h api.h
13 15
14libpreload_la_SOURCES = preload.c 16libpreload_la_SOURCES = preload.c
15libpreload_la_LDFLAGS = -ldl 17libpreload_la_LDFLAGS = -ldl
16 18
19test_SOURCES = test.c api.h misc.h
20test_LDADD = libmsi.la
21
17bin_SCRIPTS = wrapper.py makecab.py 22bin_SCRIPTS = wrapper.py makecab.py
18 23
19install-exec-hook: 24install-exec-hook:
diff --git a/api.h b/api.h
new file mode 100644
index 0000000..5fc2d27
--- /dev/null
+++ b/api.h
@@ -0,0 +1,6 @@
1#include <stdint.h>
2#include <uchar.h>
3
4uint32_t MsiGetFileVersionW(const char16_t *filename,
5 char16_t *version, uint32_t *version_size,
6 char16_t *language, uint32_t *language_size);
diff --git a/misc.h b/misc.h
new file mode 100644
index 0000000..3050bab
--- /dev/null
+++ b/misc.h
@@ -0,0 +1 @@
#define lenof(x) (sizeof(x)/sizeof(*(x)))
diff --git a/test.c b/test.c
new file mode 100644
index 0000000..bc1bdb8
--- /dev/null
+++ b/test.c
@@ -0,0 +1,33 @@
1#include <stdio.h>
2#include <string.h>
3#include <stdlib.h>
4#include <stdint.h>
5#include <inttypes.h>
6
7#include "misc.h"
8#include "uchars.h"
9#include "api.h"
10
11int main(int argc, char **argv)
12{
13 if (argc > 2 && !strcmp(argv[1], "version")) {
14 const char *filename8 = argv[2];
15 char16_t filename16[4096];
16 uint32_t filename16size = lenof(filename16);
17 c16cpy(filename16, &filename16size, filename8);
18 char16_t version[4096], language[4096];
19 uint32_t versionsize = lenof(version), languagesize = lenof(language);
20 uint32_t retd =
21 MsiGetFileVersionW(filename16, version, &versionsize,
22 language, &languagesize);
23 printf("MsiGetFileVersionW(\"%s\") = %"PRId32"\n", filename8, retd);
24 if (retd == 0) {
25 printf(" version = \"%s\"\n language = \"%s\"\n",
26 ascii(version, false), ascii(language, false));
27 }
28 } else {
29 fprintf(stderr, "usage: ./test version <file>\n");
30 return 1;
31 }
32 return 0;
33}
diff --git a/uchars.c b/uchars.c
index 5f09f60..7e7967f 100644
--- a/uchars.c
+++ b/uchars.c
@@ -16,7 +16,7 @@ char *ascii(const char16_t *wstr, bool translate_slashes)
16 return ret; 16 return ret;
17} 17}
18 18
19void c16cpy(char16_t *out, uint32_t *outsize, char *s) 19void c16cpy(char16_t *out, uint32_t *outsize, const char *s)
20{ 20{
21 uint32_t retlen = 0; 21 uint32_t retlen = 0;
22 while (retlen < *outsize) { 22 while (retlen < *outsize) {
diff --git a/uchars.h b/uchars.h
index 6e68e7c..925593b 100644
--- a/uchars.h
+++ b/uchars.h
@@ -3,4 +3,4 @@
3#include <stdbool.h> 3#include <stdbool.h>
4 4
5char *ascii(const char16_t *wstr, bool translate_slashes); 5char *ascii(const char16_t *wstr, bool translate_slashes);
6void c16cpy(char16_t *out, uint32_t *outsize, char *s); 6void c16cpy(char16_t *out, uint32_t *outsize, const char *s);
diff --git a/version.c b/version.c
index 2ba7372..7a48a5f 100644
--- a/version.c
+++ b/version.c
@@ -11,6 +11,7 @@
11 11
12#include "memory.h" 12#include "memory.h"
13#include "uchars.h" 13#include "uchars.h"
14#include "api.h"
14 15
15uint32_t MsiGetFileVersionW(const char16_t *filename, 16uint32_t MsiGetFileVersionW(const char16_t *filename,
16 char16_t *version, uint32_t *version_size, 17 char16_t *version, uint32_t *version_size,