summaryrefslogtreecommitdiffabout
path: root/tests
Side-by-side diff
Diffstat (limited to 'tests') (more/less context) (ignore whitespace changes)
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am7
-rw-r--r--tests/binpack.c86
3 files changed, 94 insertions, 0 deletions
diff --git a/tests/.gitignore b/tests/.gitignore
index 93f8f46..f689f0d 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,5 +1,6 @@
atconfig
atlocal
+binpack
package.m4
testsuite
testsuite.dir
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7f24aeb..4e3bc7b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -65,6 +65,13 @@ check-local: atconfig atlocal $(TESTSUITE)
#installcheck-local:
# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
+check_PROGRAMS = binpack
+binpack_SOURCES = binpack.c
+binpack_LDADD = ../src/libbinlog.a
+
+binpack_CFLAGS = $(AM_CFLAGS)
+
+AM_CPPFLAGS = -I$(top_srcdir)/src
diff --git a/tests/binpack.c b/tests/binpack.c
new file mode 100644
index 0000000..b54ed80
--- a/dev/null
+++ b/tests/binpack.c
@@ -0,0 +1,86 @@
+/* This file is part of vmod-binlog
+ Copyright (C) 2013 Sergey Poznyakoff
+
+ Vmod-binlog is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ Vmod-binlog is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with vmod-binlog. If not, see <http://www.gnu.org/licenses/>.
+*/
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include "pack.h"
+#include "err.h"
+
+int
+main(int argc, char **argv)
+{
+ enum { mode_packin, mode_packout } mode = mode_packin;
+ struct packinst *pi;
+ struct packenv *env;
+ char *end;
+ int c;
+
+ setprogname(argv[0]);
+
+ while ((c = getopt(argc, argv, "d")) != EOF) {
+ switch (c) {
+ case 'd':
+ mode = mode_packout;
+ break;
+ default:
+ exit(1);
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc == 0) {
+ error("not enough arguments");
+ exit(1);
+ }
+
+ pi = packcomp(argv[0], &end);
+ if (!pi) {
+ error("out of memory");
+ abort();
+ }
+ if (*end) {
+ error("compile error near %s", end);
+ exit(1);
+ }
+ env = packenv_create(packsize(pi));
+ if (!env) {
+ error("out of memory");
+ abort();
+ }
+
+ switch (mode) {
+ case mode_packin:
+ env->argv = argv + 1;
+ env->argc = argc - 1;
+ packin(pi, env);
+ fwrite(env->buf_base, env->buf_size, 1, stdout);
+ break;
+
+ case mode_packout:
+ env->fp = stdout;
+ fread(env->buf_base, env->buf_size, 1, stdin);
+ packout(pi, env);
+ fputc('\n', stdout);
+ break;
+ }
+
+ packenv_free(env);
+ packfree(pi);
+}

Return to:

Send suggestions and report system problems to the System administrator.