[master] 8b66fc6 Add a VSL tag globbing functions test program.

Martin Blix Grydeland martin at varnish-cache.org
Tue Oct 1 14:48:18 CEST 2013


commit 8b66fc69ed998a0b343e62cc117f05f3be2bc7c8
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Tue Sep 24 12:36:41 2013 +0200

    Add a VSL tag globbing functions test program.

diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am
index 375ab29..6f36ef6 100644
--- a/lib/libvarnishapi/Makefile.am
+++ b/lib/libvarnishapi/Makefile.am
@@ -65,7 +65,7 @@ vxp_fixed_token.c vxp_tokens.h: \
 	$(srcdir)/generate.py
 	@PYTHON@ $(srcdir)/generate.py $(srcdir) $(top_builddir)
 
-EXTRA_PROGRAMS = vxp_test
+EXTRA_PROGRAMS = vxp_test vsl_glob_test
 
 vxp_test_LDADD = @PCRE_LIBS@ \
 	${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
@@ -77,3 +77,10 @@ vxp_test_CFLAGS = \
 vxp_test_SOURCES = \
 	$(libvarnishapi_la_SOURCES) \
 	vxp_test.c
+
+vsl_glob_test_SOURCES = \
+	vsl_glob_test.c
+
+vsl_glob_test_LDADD = @PCRE_LIBS@ ${RT_LIBS} ${LIBM} libvarnishapi.la
+
+vsl_glob_test_CFLAGS = -I$(top_srcdir)/include
diff --git a/lib/libvarnishapi/vsl_glob_test.c b/lib/libvarnishapi/vsl_glob_test.c
new file mode 100644
index 0000000..87bb6fa
--- /dev/null
+++ b/lib/libvarnishapi/vsl_glob_test.c
@@ -0,0 +1,73 @@
+/*-
+ * Copyright (c) 2013 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Martin Blix Grydeland <martin at varnish-software.com>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * Test what VSL_Name2Tag and VSL_Glob2Tags produces
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+
+#include "vas.h"
+#include "vapi/vsl.h"
+
+static void
+cb(int tag, void *priv)
+{
+	(void)priv;
+
+	printf("\t%d (%s)\n", tag, VSL_tags[tag]);
+}
+
+int
+main(int argc, char *argv[])
+{
+	int i;
+
+	if (argc != 2) {
+		fprintf(stderr, "vsl_glob_test <tagname/glob>\n");
+		exit(1);
+	}
+
+	i = VSL_Name2Tag(argv[1], -1);
+	printf("VSL_Name2Tag returns %d", i);
+	if (i >= 0)
+		printf(" (%s)", VSL_tags[i]);
+	printf("\n");
+
+	printf("VSL_Glob2Tags:\n");
+	i = VSL_Glob2Tags(argv[1], -1, cb, NULL);
+	printf("VSL_Glob2Tags returns %d\n", i);
+
+	printf("VSL_List2Tags:\n");
+	i = VSL_List2Tags(argv[1], -1, cb, NULL);
+	printf("VSL_List2Tags returns %d\n", i);
+
+	return (0);
+}



More information about the varnish-commit mailing list