Commit 191ccd56 authored by Michael Meyling's avatar Michael Meyling

[trackrdrd] a little bit of test refactoring for test_config

parent 78fccf0a
......@@ -9,7 +9,9 @@ check_PROGRAMS = test_parse test_data test_hash test_mq test_spmcq test_config \
test_parse_SOURCES = \
minunit.h \
test_parse.c \
../trackrdrd.h
../trackrdrd.h \
testing.h \
testing.c
test_parse_LDADD = \
-lm \
......@@ -75,7 +77,9 @@ test_config_SOURCES = \
../trackrdrd.h
test_config_LDADD = \
$(VARNISHSRC)/lib/libvarnish/libvarnish.la
$(VARNISHSRC)/lib/libvarnish/libvarnish.la \
testing.$(OBJEXT)
test_worker_SOURCES = \
minunit.h \
......
......@@ -105,12 +105,3 @@ main(int argc, char **argv) \
#endif
/** debugging output */
#define VERBOSE 1
#ifdef VERBOSE
#define verbose(fmt, ...) \
do { printf("%s:%d:%s: \n>>> "fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while (0)
#else
#define verbose(fmt, ...) do{ } while ( 0 )
#endif
......@@ -34,6 +34,7 @@
#include <string.h>
#include "minunit.h"
#include "testing.h"
#include "../trackrdrd.h"
#include "config_common.h"
......@@ -42,53 +43,11 @@ int tests_run = 0;
#define DEFAULT_USER "nobody"
#define DEFAULT_PID_FILE "/var/run/trackrdrd.pid"
int compareFiles(const char * fname1, const char * fname2);
char verbose_buffer[9000];
char * getConfigContent(void);
int saveConfig(const char * fname);
int compareFiles(const char * fname1, const char * fname2)
{
FILE *fp1, *fp2;
int ch1, ch2;
int line = 1;
int col = 1;
fp1 = fopen( fname1, "r" );
if ( fp1 == NULL )
{
printf("Cannot open %s for reading ", fname1 );
return -2;
}
fp2 = fopen( fname2, "r" ) ;
if (fp2 == NULL)
{
printf("Cannot open %s for reading ", fname2 );
fclose ( fp1 );
return -3;
}
do
{
col++;
ch1 = getc( fp1 );
ch2 = getc( fp2 );
if ( ch1 == '\n' )
{
line++;
col = 0;
}
} while ((ch1 != EOF) && (ch2 != EOF) && (ch1 == ch2));
fclose ( fp1 );
fclose ( fp2 );
if ( ch1 != ch2 ) {
printf(" files differ at line: %i col: %i \n", line, col);
}
return ch1 == ch2;
}
#define confdump(str,val) \
i += sprintf(verbose_buffer + i, str"\n", (val))
......@@ -166,7 +125,6 @@ static char
{
printf("... testing CONF_ReadDefault\n");
// CONF_Init();
strcpy(config.log_file, "testing.log");
LOG_Open("trackrdrd");
LOG_SetLevel(7);
......@@ -176,9 +134,9 @@ static char
VMASSERT(err == 0, "Error code during reading default config: %i", err);
err = CONF_ReadFile("trackrdrd.conf", CONF_Add);
VMASSERT(err == 0, "Error code during reading config: %i", err);
verbose("Config is:\n%s", getConfigContent());
// verbose("Config is:\n%s", getConfigContent());
saveConfig("trackrdrd.conf.new");
VMASSERT(compareFiles("trackrdrd.conf", "trackrdrd.conf.new"),
VMASSERT(TEST_compareFiles("trackrdrd.conf", "trackrdrd.conf.new"),
"Files are not equal: %s %s", "trackrdrd.conf", "trackrdrd.conf.new");
// CONF_Dump();
......
/*-
* Copyright (c) 2012-2014 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2012-2014 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
* Author: Michael Meyling <michael@meyling.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.
*
*/
/**
* Module: testing.c
* Description: Contains utilities for testing.
*/
/***** includes ***************************************************************/
#include "testing.h"
/***** functions **************************************************************/
int TEST_compareFiles(const char * fname1, const char * fname2)
{
FILE *fp1, *fp2;
int ch1, ch2;
int line = 1;
int col = 1;
fp1 = fopen( fname1, "r" );
if ( fp1 == NULL )
{
printf("Cannot open %s for reading ", fname1 );
return -2;
}
fp2 = fopen( fname2, "r" ) ;
if (fp2 == NULL)
{
printf("Cannot open %s for reading ", fname2 );
fclose ( fp1 );
return -3;
}
do
{
col++;
ch1 = getc( fp1 );
ch2 = getc( fp2 );
if ( ch1 == '\n' )
{
line++;
col = 0;
}
} while ((ch1 != EOF) && (ch2 != EOF) && (ch1 == ch2));
fclose ( fp1 );
fclose ( fp2 );
if ( ch1 != ch2 ) {
printf(" files differ at line: %i col: %i \n", line, col);
}
return ch1 == ch2;
}
/*-
* Copyright (c) 2012-2014 UPLEX Nils Goroll Systemoptimierung
* Copyright (c) 2012-2014 Otto Gmbh & Co KG
* All rights reserved
* Use only with permission
*
* Author: Michael Meyling <michael@meyling.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.
*
*/
/**
* Module: testing.h
* Description: Contains utilities for testing.
*/
#ifndef _TESTING_H
#define _TESTING_H
/***** includes ***************************************************************/
#include <stdio.h>
/***** defines ****************************************************************/
/** debugging output */
#define VERBOSE 1
#ifdef VERBOSE
#define verbose(fmt, ...) \
do { printf("%8s:%4d:%20s:>>> "fmt"\n", __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__); } while (0)
#else
#define verbose(fmt, ...) do{ } while ( 0 )
#endif
/***** variables **************************************************************/
extern long global_line_pos; /* actual position in input line */
/***** structures *************************************************************/
/***** functions **************************************************************/
extern int TEST_compareFiles(const char * fname1, const char * fname2);
#endif /* _TESTING_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment