summaryrefslogtreecommitdiffstats
path: root/ipapython/ipavalidate.py
diff options
context:
space:
mode:
Diffstat (limited to 'ipapython/ipavalidate.py')
0 files changed, 0 insertions, 0 deletions
ref='#n60'>60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
/* This test checks runtime initialization and exit. Other than that, it
 * also serves as the most simplistic sample of how a test can be coded.
 *
 * Part of the testbench for rsyslog.
 *
 * Copyright 2008 Rainer Gerhards and Adiscon GmbH.
 *
 * This file is part of rsyslog.
 *
 * Rsyslog 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 of the License, or
 * (at your option) any later version.
 *
 * Rsyslog 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 Rsyslog.  If not, see <http://www.gnu.org/licenses/>.
 *
 * A copy of the GPL can be found in the file "COPYING" in this distribution.
 */
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <glob.h>
#include <sys/stat.h>

#include "rsyslog.h"
#include "testbench.h"
#include "ctok.h"
#include "expr.h"

MODULE_TYPE_TESTBENCH
/* define addtional objects we need for our tests */
DEFobjCurrIf(expr)
DEFobjCurrIf(ctok)
DEFobjCurrIf(ctok_token)
DEFobjCurrIf(vmprg)


BEGINInit
CODESTARTInit
	pErrObj = "expr"; CHKiRet(objUse(expr, CORE_COMPONENT));
	pErrObj = "ctok"; CHKiRet(objUse(ctok, CORE_COMPONENT));
	pErrObj = "ctok_token"; CHKiRet(objUse(ctok_token, CORE_COMPONENT));
	pErrObj = "vmprg"; CHKiRet(objUse(vmprg, CORE_COMPONENT));
ENDInit

BEGINExit
CODESTARTExit
ENDExit


/* perform a single test. This involves compiling the test script,
 * checking the result of the compilation (iRet) and a check of the
 * generated program (via a simple strcmp). The resulting program
 * check is only done if the test should not detect a syntax error
 * (for obvious reasons, there is no point in checking the result of
 * a failed compilation).
 * rgerhards, 2008-07--07
 */
static rsRetVal
PerformTest(cstr_t *pstrIn, rsRetVal iRetExpected, cstr_t *pstrOut)
{
	cstr_t *pstrPrg = NULL;
	ctok_t *tok = NULL;
	ctok_token_t *pToken = NULL;
	expr_t *pExpr;
	rsRetVal localRet;
	DEFiRet;

	/* we first need a tokenizer... */
	CHKiRet(ctok.Construct(&tok));
	CHKiRet(ctok.Setpp(tok, rsCStrGetSzStr(pstrIn)));
	CHKiRet(ctok.ConstructFinalize(tok));

	/* now construct our expression */
	CHKiRet(expr.Construct(&pExpr));
	CHKiRet(expr.ConstructFinalize(pExpr));

	/* ready to go... */
	localRet = expr.Parse(pExpr, tok);

	/* check if we expected an error */
	if(localRet != iRetExpected) {
		printf("Error in compile return code. Expected %d, received %d\n",
		       iRetExpected, localRet);
		CHKiRet(rsCStrConstruct(&pstrPrg));
		CHKiRet(vmprg.Obj2Str(pExpr->pVmprg, pstrPrg));
		printf("generated vmprg:\n%s\n", rsCStrGetSzStr(pstrPrg));
		ABORT_FINALIZE(iRetExpected == RS_RET_OK ? localRet : RS_RET_ERR);
	}

	if(iRetExpected != RS_RET_OK)
		FINALIZE; /* if we tested an error case, we are done */
	
	/* OK, we got a compiled program, so now let's compare that */

	CHKiRet(rsCStrConstruct(&pstrPrg));
	CHKiRet(vmprg.Obj2Str(pExpr->pVmprg, pstrPrg));

	if(strcmp((char*)rsCStrGetSzStr(pstrPrg), (char*)rsCStrGetSzStr(pstrOut))) {
		printf("error: compiled program different from expected result!\n");
		printf("generated vmprg (%d bytes):\n%s\n", (int)strlen((char*)rsCStrGetSzStr(pstrPrg)), rsCStrGetSzStr(pstrPrg));
		printf("expected (%d bytes):\n%s\n", (int)strlen((char*)rsCStrGetSzStr(pstrOut)), rsCStrGetSzStr(pstrOut));
		ABORT_FINALIZE(RS_RET_ERR);
	}

finalize_it:
	/* we are done, so we now need to restore things */
	if(pToken != NULL)
		ctok_token.Destruct(&pToken); /* no longer needed */
	if(pstrPrg != NULL)
		rsCStrDestruct(&pstrPrg);
	if(tok != NULL)
		ctok.Destruct(&tok);
	RETiRet;
}


/* a helper macro to generate some often-used code... */
#define CHKEOF \
	if(feof(fp)) { \
		printf("error: unexpected end of control file %s\n", pszFileName); \
		ABORT_FINALIZE(RS_RET_ERR); \
	}
/* process a single test file
 * Note that we do not do a real parser here. The effort is not
 * justified by what we need to do. So it is a quick shot.
 * rgerhards, 2008-07-07
 */
static rsRetVal
ProcessTestFile(uchar *pszFileName)
{
	FILE *fp;
	char *lnptr = NULL;
	size_t lenLn;
	cstr_t *pstrIn = NULL;
	cstr_t *pstrOut = NULL;
	int iParse;
	rsRetVal iRetExpected;
	DEFiRet;

	if((fp = fopen((char*)pszFileName, "r")) == NULL) {
		perror((char*)pszFileName);
		ABORT_FINALIZE(RS_RET_FILE_NOT_FOUND);
	}

	/* skip comments at start of file */

	getline(&lnptr, &lenLn, fp);
	while(!feof(fp)) {
		if(*lnptr == '#')