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.
This commit is contained in:
Simon Tatham 2017-05-28 09:54:05 +01:00
parent f501b2927d
commit fe5eb01f9b
8 changed files with 50 additions and 3 deletions

1
.gitignore vendored
View file

@ -7,6 +7,7 @@
*.a
*.so
*.so.*
/test
/Makefile
/Makefile.in
/aclocal.m4

View file

@ -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:

6
api.h Normal file
View file

@ -0,0 +1,6 @@
#include <stdint.h>
#include <uchar.h>
uint32_t MsiGetFileVersionW(const char16_t *filename,
char16_t *version, uint32_t *version_size,
char16_t *language, uint32_t *language_size);

1
misc.h Normal file
View file

@ -0,0 +1 @@
#define lenof(x) (sizeof(x)/sizeof(*(x)))

33
test.c Normal file
View file

@ -0,0 +1,33 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#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 <file>\n");
return 1;
}
return 0;
}

View file

@ -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) {

View file

@ -3,4 +3,4 @@
#include <stdbool.h>
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);

View file

@ -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,