From 24b1be749e65dc1966a1fbce46facb4f9a9bf73c Mon Sep 17 00:00:00 2001 From: teodor Date: Tue, 30 Sep 2008 13:49:53 +0000 Subject: [PATCH] add tests --- tmpltest.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 tmpltest.c diff --git a/tmpltest.c b/tmpltest.c new file mode 100644 index 0000000..6b54a3d --- /dev/null +++ b/tmpltest.c @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2008 Teodor Sigaev + * All rights reserved. + * + * 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. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY 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 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. + */ + +#include +#include +#include +#include + + +#include "tmalloc.h" +#include "tlog.h" +#include "tools.h" +#include "template.h" + +static void +usage() { + puts( + "Usage:\n" + "memtest [-t TEMPLATENAME]\n" + ); + exit(1); +} + + +static void +outfunc(char *str, int len) { + fputs( str, stdout ); +} + +extern char *optarg; +extern int opterr; + +int +main(int argn, char *argv[]) { + MemoryContext *base; + char *name = NULL; + TemplateData template; + int i; + + opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL); + opterr=0; + + while((i=getopt(argn,argv,"ht:")) != EOF) { + switch(i) { + case 't': + name = tstrdup(optarg); + break; + case 'h': + default: + usage(); + break; + } + } + + if (!name) + usage(); + + base = allocMemoryContext(NULL, MC_DEBUG); + + printf("initTemplate: %d\n", initTemplate(&template, base, ".", name) ); + /* dumpTemplate(&template); */ + + setTemplateValueInt(&template, "ID", 17); + setTemplateValueUndefined(&template, "emptyID"); + setTemplateValueInt(&template, "zeroid", 0); + + addTemplateRow(&template, "outerLoop"); + setTemplateValueString(&template, "outerLoop.data1", "ha1"); + setTemplateValueUndefined(&template, "outerLoop.data2"); + + addTemplateRow(&template, "outerLoop"); + setTemplateValueInt(&template, "outerLoop.data1", 10); + setTemplateValueString(&template, "outerLoop.data2", "WOW"); + addTemplateRow(&template, "outerLoop.innerLoop"); + setTemplateValueString(&template, "outerLoop.innerLoop.camenty", "Number 1"); + addTemplateRow(&template, "outerLoop.innerLoop"); + setTemplateValueString(&template, "outerLoop.innerLoop.camenty", "Number 2"); + + addTemplateRow(&template, "outerLoop"); + setTemplateValueString(&template, "outerLoop.data1", "ha3"); + + template.printString = outfunc; + printTemplate( &template ); + + resetTemplate(&template); + freeTemplate(&template); + return 0; +} + + + -- 2.37.3