From fe5eb01f9b84b344bd1d476f409626fd7b4cd5f9 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 28 May 2017 09:54:05 +0100 Subject: 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. --- .gitignore | 1 + Makefile.am | 7 ++++++- api.h | 6 ++++++ misc.h | 1 + test.c | 33 +++++++++++++++++++++++++++++++++ uchars.c | 2 +- uchars.h | 2 +- version.c | 1 + 8 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 api.h create mode 100644 misc.h create mode 100644 test.c diff --git a/.gitignore b/.gitignore index df4b72b..740825f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,7 @@ *.a *.so *.so.* +/test /Makefile /Makefile.in /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) ACLOCAL_AMFLAGS = -I m4 +noinst_PROGRAMS = test + lib_LTLIBRARIES = libwinterop.la libmsi.la libpreload.la libwinterop_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 \ uchars.h libmsi_la_SOURCES = makemsi.c md5.c memory.c memory.h version.c \ -dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h +dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h api.h libpreload_la_SOURCES = preload.c libpreload_la_LDFLAGS = -ldl +test_SOURCES = test.c api.h misc.h +test_LDADD = libmsi.la + bin_SCRIPTS = wrapper.py makecab.py install-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 @@ +#include +#include + +uint32_t MsiGetFileVersionW(const char16_t *filename, + char16_t *version, uint32_t *version_size, + 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 @@ +#include +#include +#include +#include +#include + +#include "misc.h" +#include "uchars.h" +#include "api.h" + +int main(int argc, char **argv) +{ + if (argc > 2 && !strcmp(argv[1], "version")) { + const char *filename8 = argv[2]; + char16_t filename16[4096]; + uint32_t filename16size = lenof(filename16); + c16cpy(filename16, &filename16size, filename8); + char16_t version[4096], language[4096]; + uint32_t versionsize = lenof(version), languagesize = lenof(language); + uint32_t retd = + MsiGetFileVersionW(filename16, version, &versionsize, + language, &languagesize); + printf("MsiGetFileVersionW(\"%s\") = %"PRId32"\n", filename8, retd); + if (retd == 0) { + printf(" version = \"%s\"\n language = \"%s\"\n", + ascii(version, false), ascii(language, false)); + } + } else { + fprintf(stderr, "usage: ./test version \n"); + return 1; + } + return 0; +} 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) return ret; } -void c16cpy(char16_t *out, uint32_t *outsize, char *s) +void c16cpy(char16_t *out, uint32_t *outsize, const char *s) { uint32_t retlen = 0; 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 @@ #include char *ascii(const char16_t *wstr, bool translate_slashes); -void c16cpy(char16_t *out, uint32_t *outsize, char *s); +void 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 @@ #include "memory.h" #include "uchars.h" +#include "api.h" uint32_t MsiGetFileVersionW(const char16_t *filename, char16_t *version, uint32_t *version_size, -- cgit v1.2.3-55-g6feb