Imported Upstream version 1.4.10

This commit is contained in:
Jan Wagner 2013-11-26 23:54:42 +01:00
parent 6dd54dd8e2
commit cff68b4c0a
203 changed files with 15026 additions and 8063 deletions

View file

@ -7,9 +7,9 @@ check_PROGRAMS = @EXTRA_TEST@
INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
EXTRA_PROGRAMS = test_utils test_disk
EXTRA_PROGRAMS = test_utils test_disk test_tcp test_cmd
EXTRA_DIST = test_utils.t test_disk.t
EXTRA_DIST = test_utils.t test_disk.t test_tcp.t test_cmd.t
LIBS = @LIBINTL@
@ -23,6 +23,16 @@ test_disk_CFLAGS = -g -I..
test_disk_LDFLAGS = -L/usr/local/lib -ltap
test_disk_LDADD = ../utils_disk.o $(top_srcdir)/gl/libgnu.a
test_tcp_SOURCES = test_tcp.c
test_tcp_CFLAGS = -g -I..
test_tcp_LDFLAGS = -L/usr/local/lib -ltap
test_tcp_LDADD = ../utils_tcp.o
test_cmd_SOURCES = test_cmd.c
test_cmd_CFLAGS = -g -I..
test_cmd_LDFLAGS = -L/usr/local/lib -ltap
test_cmd_LDADD = ../utils_cmd.o ../utils_base.o
test: ${noinst_PROGRAMS}
perl -MTest::Harness -e '$$Test::Harness::switches=""; runtests(map {$$_ .= ".t"} @ARGV)' $(EXTRA_PROGRAMS)

View file

@ -1,4 +1,4 @@
# Makefile.in generated by automake 1.9.6 from Makefile.am.
# Makefile.in generated by automake 1.9.5 from Makefile.am.
# @configure_input@
# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
@ -14,6 +14,8 @@
@SET_MAKE@
SOURCES = $(test_cmd_SOURCES) $(test_disk_SOURCES) $(test_tcp_SOURCES) $(test_utils_SOURCES)
srcdir = @srcdir@
top_srcdir = @top_srcdir@
VPATH = @srcdir@
@ -37,7 +39,8 @@ build_triplet = @build@
host_triplet = @host@
noinst_PROGRAMS = @EXTRA_TEST@
check_PROGRAMS = @EXTRA_TEST@
EXTRA_PROGRAMS = test_utils$(EXEEXT) test_disk$(EXEEXT)
EXTRA_PROGRAMS = test_utils$(EXEEXT) test_disk$(EXEEXT) \
test_tcp$(EXEEXT) test_cmd$(EXEEXT)
subdir = lib/tests
DIST_COMMON = README $(srcdir)/Makefile.am $(srcdir)/Makefile.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@ -98,13 +101,19 @@ am__aclocal_m4_deps = $(top_srcdir)/m4/np_mysqlclient.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
mkinstalldirs = $(install_sh) -d
mkinstalldirs = $(SHELL) $(top_srcdir)/build-aux/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/config.h
CONFIG_CLEAN_FILES =
PROGRAMS = $(noinst_PROGRAMS)
am_test_cmd_OBJECTS = test_cmd-test_cmd.$(OBJEXT)
test_cmd_OBJECTS = $(am_test_cmd_OBJECTS)
test_cmd_DEPENDENCIES = ../utils_cmd.o ../utils_base.o
am_test_disk_OBJECTS = test_disk-test_disk.$(OBJEXT)
test_disk_OBJECTS = $(am_test_disk_OBJECTS)
test_disk_DEPENDENCIES = ../utils_disk.o $(top_srcdir)/gl/libgnu.a
am_test_tcp_OBJECTS = test_tcp-test_tcp.$(OBJEXT)
test_tcp_OBJECTS = $(am_test_tcp_OBJECTS)
test_tcp_DEPENDENCIES = ../utils_tcp.o
am_test_utils_OBJECTS = test_utils-test_utils.$(OBJEXT)
test_utils_OBJECTS = $(am_test_utils_OBJECTS)
test_utils_DEPENDENCIES = ../utils_base.o
@ -119,8 +128,10 @@ LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
CCLD = $(CC)
LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
$(AM_LDFLAGS) $(LDFLAGS) -o $@
SOURCES = $(test_disk_SOURCES) $(test_utils_SOURCES)
DIST_SOURCES = $(test_disk_SOURCES) $(test_utils_SOURCES)
SOURCES = $(test_cmd_SOURCES) $(test_disk_SOURCES) $(test_tcp_SOURCES) \
$(test_utils_SOURCES)
DIST_SOURCES = $(test_cmd_SOURCES) $(test_disk_SOURCES) \
$(test_tcp_SOURCES) $(test_utils_SOURCES)
ETAGS = etags
CTAGS = ctags
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
@ -258,6 +269,7 @@ PATH_TO_SWAPINFO = @PATH_TO_SWAPINFO@
PATH_TO_UPTIME = @PATH_TO_UPTIME@
PATH_TO_WHO = @PATH_TO_WHO@
PERL = @PERL@
PERLMODS_DIR = @PERLMODS_DIR@
PGINCLUDE = @PGINCLUDE@
PGLIBS = @PGLIBS@
PKG_ARCH = @PKG_ARCH@
@ -348,7 +360,7 @@ with_trusted_path = @with_trusted_path@
# These two lines support "make check", but we use "make test"
TESTS = @EXTRA_TEST@
INCLUDES = -I$(top_srcdir)/lib -I$(top_srcdir)/gl -I$(top_srcdir)/intl -I$(top_srcdir)/plugins
EXTRA_DIST = test_utils.t test_disk.t
EXTRA_DIST = test_utils.t test_disk.t test_tcp.t test_cmd.t
test_utils_SOURCES = test_utils.c
test_utils_CFLAGS = -g -I..
test_utils_LDFLAGS = -L/usr/local/lib -ltap
@ -357,6 +369,14 @@ test_disk_SOURCES = test_disk.c
test_disk_CFLAGS = -g -I..
test_disk_LDFLAGS = -L/usr/local/lib -ltap
test_disk_LDADD = ../utils_disk.o $(top_srcdir)/gl/libgnu.a
test_tcp_SOURCES = test_tcp.c
test_tcp_CFLAGS = -g -I..
test_tcp_LDFLAGS = -L/usr/local/lib -ltap
test_tcp_LDADD = ../utils_tcp.o
test_cmd_SOURCES = test_cmd.c
test_cmd_CFLAGS = -g -I..
test_cmd_LDFLAGS = -L/usr/local/lib -ltap
test_cmd_LDADD = ../utils_cmd.o ../utils_base.o
all: all-am
.SUFFIXES:
@ -404,9 +424,15 @@ clean-noinstPROGRAMS:
echo " rm -f $$p $$f"; \
rm -f $$p $$f ; \
done
test_cmd$(EXEEXT): $(test_cmd_OBJECTS) $(test_cmd_DEPENDENCIES)
@rm -f test_cmd$(EXEEXT)
$(LINK) $(test_cmd_LDFLAGS) $(test_cmd_OBJECTS) $(test_cmd_LDADD) $(LIBS)
test_disk$(EXEEXT): $(test_disk_OBJECTS) $(test_disk_DEPENDENCIES)
@rm -f test_disk$(EXEEXT)
$(LINK) $(test_disk_LDFLAGS) $(test_disk_OBJECTS) $(test_disk_LDADD) $(LIBS)
test_tcp$(EXEEXT): $(test_tcp_OBJECTS) $(test_tcp_DEPENDENCIES)
@rm -f test_tcp$(EXEEXT)
$(LINK) $(test_tcp_LDFLAGS) $(test_tcp_OBJECTS) $(test_tcp_LDADD) $(LIBS)
test_utils$(EXEEXT): $(test_utils_OBJECTS) $(test_utils_DEPENDENCIES)
@rm -f test_utils$(EXEEXT)
$(LINK) $(test_utils_LDFLAGS) $(test_utils_OBJECTS) $(test_utils_LDADD) $(LIBS)
@ -417,7 +443,9 @@ mostlyclean-compile:
distclean-compile:
-rm -f *.tab.c
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_cmd-test_cmd.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_disk-test_disk.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_tcp-test_tcp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test_utils-test_utils.Po@am__quote@
.c.o:
@ -441,6 +469,20 @@ distclean-compile:
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
test_cmd-test_cmd.o: test_cmd.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_cmd_CFLAGS) $(CFLAGS) -MT test_cmd-test_cmd.o -MD -MP -MF "$(DEPDIR)/test_cmd-test_cmd.Tpo" -c -o test_cmd-test_cmd.o `test -f 'test_cmd.c' || echo '$(srcdir)/'`test_cmd.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/test_cmd-test_cmd.Tpo" "$(DEPDIR)/test_cmd-test_cmd.Po"; else rm -f "$(DEPDIR)/test_cmd-test_cmd.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test_cmd.c' object='test_cmd-test_cmd.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_cmd_CFLAGS) $(CFLAGS) -c -o test_cmd-test_cmd.o `test -f 'test_cmd.c' || echo '$(srcdir)/'`test_cmd.c
test_cmd-test_cmd.obj: test_cmd.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_cmd_CFLAGS) $(CFLAGS) -MT test_cmd-test_cmd.obj -MD -MP -MF "$(DEPDIR)/test_cmd-test_cmd.Tpo" -c -o test_cmd-test_cmd.obj `if test -f 'test_cmd.c'; then $(CYGPATH_W) 'test_cmd.c'; else $(CYGPATH_W) '$(srcdir)/test_cmd.c'; fi`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/test_cmd-test_cmd.Tpo" "$(DEPDIR)/test_cmd-test_cmd.Po"; else rm -f "$(DEPDIR)/test_cmd-test_cmd.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test_cmd.c' object='test_cmd-test_cmd.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_cmd_CFLAGS) $(CFLAGS) -c -o test_cmd-test_cmd.obj `if test -f 'test_cmd.c'; then $(CYGPATH_W) 'test_cmd.c'; else $(CYGPATH_W) '$(srcdir)/test_cmd.c'; fi`
test_disk-test_disk.o: test_disk.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_disk_CFLAGS) $(CFLAGS) -MT test_disk-test_disk.o -MD -MP -MF "$(DEPDIR)/test_disk-test_disk.Tpo" -c -o test_disk-test_disk.o `test -f 'test_disk.c' || echo '$(srcdir)/'`test_disk.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/test_disk-test_disk.Tpo" "$(DEPDIR)/test_disk-test_disk.Po"; else rm -f "$(DEPDIR)/test_disk-test_disk.Tpo"; exit 1; fi
@ -455,6 +497,20 @@ test_disk-test_disk.obj: test_disk.c
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_disk_CFLAGS) $(CFLAGS) -c -o test_disk-test_disk.obj `if test -f 'test_disk.c'; then $(CYGPATH_W) 'test_disk.c'; else $(CYGPATH_W) '$(srcdir)/test_disk.c'; fi`
test_tcp-test_tcp.o: test_tcp.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_tcp_CFLAGS) $(CFLAGS) -MT test_tcp-test_tcp.o -MD -MP -MF "$(DEPDIR)/test_tcp-test_tcp.Tpo" -c -o test_tcp-test_tcp.o `test -f 'test_tcp.c' || echo '$(srcdir)/'`test_tcp.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/test_tcp-test_tcp.Tpo" "$(DEPDIR)/test_tcp-test_tcp.Po"; else rm -f "$(DEPDIR)/test_tcp-test_tcp.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test_tcp.c' object='test_tcp-test_tcp.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_tcp_CFLAGS) $(CFLAGS) -c -o test_tcp-test_tcp.o `test -f 'test_tcp.c' || echo '$(srcdir)/'`test_tcp.c
test_tcp-test_tcp.obj: test_tcp.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_tcp_CFLAGS) $(CFLAGS) -MT test_tcp-test_tcp.obj -MD -MP -MF "$(DEPDIR)/test_tcp-test_tcp.Tpo" -c -o test_tcp-test_tcp.obj `if test -f 'test_tcp.c'; then $(CYGPATH_W) 'test_tcp.c'; else $(CYGPATH_W) '$(srcdir)/test_tcp.c'; fi`; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/test_tcp-test_tcp.Tpo" "$(DEPDIR)/test_tcp-test_tcp.Po"; else rm -f "$(DEPDIR)/test_tcp-test_tcp.Tpo"; exit 1; fi
@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='test_tcp.c' object='test_tcp-test_tcp.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_tcp_CFLAGS) $(CFLAGS) -c -o test_tcp-test_tcp.obj `if test -f 'test_tcp.c'; then $(CYGPATH_W) 'test_tcp.c'; else $(CYGPATH_W) '$(srcdir)/test_tcp.c'; fi`
test_utils-test_utils.o: test_utils.c
@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(test_utils_CFLAGS) $(CFLAGS) -MT test_utils-test_utils.o -MD -MP -MF "$(DEPDIR)/test_utils-test_utils.Tpo" -c -o test_utils-test_utils.o `test -f 'test_utils.c' || echo '$(srcdir)/'`test_utils.c; \
@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/test_utils-test_utils.Tpo" "$(DEPDIR)/test_utils-test_utils.Po"; else rm -f "$(DEPDIR)/test_utils-test_utils.Tpo"; exit 1; fi

210
lib/tests/test_cmd.c Normal file
View file

@ -0,0 +1,210 @@
/******************************************************************************
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: test_cmd.c 1732 2007-06-03 15:58:22Z psychotrahe $
******************************************************************************/
#include "common.h"
#include "utils_cmd.h"
#include "utils_base.h"
#include "tap.h"
#define COMMAND_LINE 1024
#define UNSET 65530
char *
get_command (char *const *line)
{
char *cmd;
int i = 0;
asprintf (&cmd, " %s", line[i++]);
while (line[i] != NULL) {
asprintf (&cmd, "%s %s", cmd, line[i]);
i++;
}
return cmd;
}
int
main (int argc, char **argv)
{
char **command_line = malloc (sizeof (char *) * COMMAND_LINE);
char *command = NULL;
char *perl;
output chld_out, chld_err;
int c;
int result = UNSET;
plan_tests(47);
diag ("Running plain echo command, set one");
/* ensure everything is empty before we begin */
memset (&chld_out, 0, sizeof (output));
memset (&chld_err, 0, sizeof (output));
ok (chld_out.lines == 0, "(initialised) Checking stdout is reset");
ok (chld_err.lines == 0, "(initialised) Checking stderr is reset");
ok (result == UNSET, "(initialised) Checking exit code is reset");
command_line[0] = strdup ("/bin/echo");
command_line[1] = strdup ("this");
command_line[2] = strdup ("is");
command_line[3] = strdup ("test");
command_line[4] = strdup ("one");
command = get_command (command_line);
result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
ok (chld_out.lines == 1,
"(array) Check for expected number of stdout lines");
ok (chld_err.lines == 0,
"(array) Check for expected number of stderr lines");
ok (strcmp (chld_out.line[0], "this is test one") == 0,
"(array) Check for expected stdout output");
ok (result == 0, "(array) Checking exit code");
/* ensure everything is empty again */
memset (&chld_out, 0, sizeof (output));
memset (&chld_err, 0, sizeof (output));
result = UNSET;
ok (chld_out.lines == 0, "(initialised) Checking stdout is reset");
ok (chld_err.lines == 0, "(initialised) Checking stderr is reset");
ok (result == UNSET, "(initialised) Checking exit code is reset");
result = cmd_run (command, &chld_out, &chld_err, 0);
ok (chld_out.lines == 1,
"(string) Check for expected number of stdout lines");
ok (chld_err.lines == 0,
"(string) Check for expected number of stderr lines");
ok (strcmp (chld_out.line[0], "this is test one") == 0,
"(string) Check for expected stdout output");
ok (result == 0, "(string) Checking exit code");
diag ("Running plain echo command, set two");
/* ensure everything is empty again */
memset (&chld_out, 0, sizeof (output));
memset (&chld_err, 0, sizeof (output));
result = UNSET;
ok (chld_out.lines == 0, "(initialised) Checking stdout is reset");
ok (chld_err.lines == 0, "(initialised) Checking stderr is reset");
ok (result == UNSET, "(initialised) Checking exit code is reset");
command_line[0] = strdup ("/bin/echo");
command_line[1] = strdup ("this is test two");
command_line[2] = NULL;
command_line[3] = NULL;
command_line[4] = NULL;
result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
ok (chld_out.lines == 1,
"(array) Check for expected number of stdout lines");
ok (chld_err.lines == 0,
"(array) Check for expected number of stderr lines");
ok (strcmp (chld_out.line[0], "this is test two") == 0,
"(array) Check for expected stdout output");
ok (result == 0, "(array) Checking exit code");
/* ensure everything is empty again */
memset (&chld_out, 0, sizeof (output));
memset (&chld_err, 0, sizeof (output));
result = UNSET;
ok (chld_out.lines == 0, "(initialised) Checking stdout is reset");
ok (chld_err.lines == 0, "(initialised) Checking stderr is reset");
ok (result == UNSET, "(initialised) Checking exit code is reset");
result = cmd_run (command, &chld_out, &chld_err, 0);
ok (chld_out.lines == 1,
"(string) Check for expected number of stdout lines");
ok (chld_err.lines == 0,
"(string) Check for expected number of stderr lines");
ok (strcmp (chld_out.line[0], "this is test one") == 0,
"(string) Check for expected stdout output");
ok (result == 0, "(string) Checking exit code");
/* ensure everything is empty again */
memset (&chld_out, 0, sizeof (output));
memset (&chld_err, 0, sizeof (output));
result = UNSET;
ok (chld_out.lines == 0, "(initialised) Checking stdout is reset");
ok (chld_err.lines == 0, "(initialised) Checking stderr is reset");
ok (result == UNSET, "(initialised) Checking exit code is reset");
/* Pass linefeeds via parameters through - those should be evaluated by echo to give multi line output */
command_line[0] = strdup("/bin/echo");
command_line[1] = strdup("this is a test via echo\nline two\nit's line 3");
command_line[2] = strdup("and (note space between '3' and 'and') $$ will not get evaluated");
result = cmd_run_array (command_line, &chld_out, &chld_err, 0);
ok (chld_out.lines == 3,
"(array) Check for expected number of stdout lines");
ok (chld_err.lines == 0,
"(array) Check for expected number of stderr lines");
ok (strcmp (chld_out.line[0], "this is a test via echo") == 0,
"(array) Check line 1 for expected stdout output");
ok (strcmp (chld_out.line[1], "line two") == 0,
"(array) Check line 2 for expected stdout output");
ok (strcmp (chld_out.line[2], "it's line 3 and (note space between '3' and 'and') $$ will not get evaluated") == 0,
"(array) Check line 3 for expected stdout output");
ok (result == 0, "(array) Checking exit code");
/* ensure everything is empty again */
memset (&chld_out, 0, sizeof (output));
memset (&chld_err, 0, sizeof (output));
result = UNSET;
ok (chld_out.lines == 0, "(initialised) Checking stdout is reset");
ok (chld_err.lines == 0, "(initialised) Checking stderr is reset");
ok (result == UNSET, "(initialised) Checking exit code is reset");
command = (char *)malloc(COMMAND_LINE);
strcpy(command, "/bin/echo3456 non-existant command");
result = cmd_run (command, &chld_out, &chld_err, 0);
ok (chld_out.lines == 0,
"Non existant command, so no output");
ok (chld_err.lines == 0,
"No stderr either");
ok (result == 3, "Get return code 3 (?) for non-existant command");
/* ensure everything is empty again */
memset (&chld_out, 0, sizeof (output));
memset (&chld_err, 0, sizeof (output));
result = UNSET;
command = (char *)malloc(COMMAND_LINE);
strcpy(command, "/bin/grep pattern non-existant-file");
result = cmd_run (command, &chld_out, &chld_err, 0);
ok (chld_out.lines == 0,
"Grep returns no stdout when file is missing...");
ok (chld_err.lines == 1,
"...but does give an error line");
ok (strstr(chld_err.line[0],"non-existant-file") != NULL, "And missing filename is in error message");
ok (result == 2, "Get return code 2 from grep");
return exit_status ();
}

6
lib/tests/test_cmd.t Normal file
View file

@ -0,0 +1,6 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_cmd") {
plan skip_all => "./test_cmd not compiled - please install tap library to test";
}
exec "./test_cmd";

View file

@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: test_disk.c,v 1.3 2007/03/30 09:00:05 psychotrahe Exp $
$Id: test_disk.c 1786 2007-09-22 17:40:35Z psychotrahe $
******************************************************************************/
@ -36,14 +36,15 @@ main (int argc, char **argv)
struct name_list *dummy_mountlist = NULL;
struct name_list *temp_name;
struct parameter_list *paths = NULL;
struct parameter_list *p;
struct parameter_list *p, *prev, *last;
struct mount_entry *dummy_mount_list;
struct mount_entry *me;
struct mount_entry **mtail = &dummy_mount_list;
int cflags = REG_NOSUB | REG_EXTENDED;
int found = 0, count = 0;
plan_tests(29);
plan_tests(33);
ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list");
np_add_name(&exclude_filesystem, "/var/log");
@ -160,6 +161,46 @@ main (int argc, char **argv)
}
}
/* test deleting first element in paths */
paths = np_del_parameter(paths, NULL);
for (p = paths; p; p = p->name_next) {
if (! strcmp(p->name, "/home/groups"))
found = 1;
}
ok(found == 0, "first element successfully deleted");
found = 0;
p=paths;
while (p) {
if (! strcmp(p->name, "/tmp"))
p = np_del_parameter(p, prev);
else {
prev = p;
p = p->name_next;
}
}
for (p = paths; p; p = p->name_next) {
if (! strcmp(p->name, "/tmp"))
found = 1;
if (p->name_next)
prev = p;
else
last = p;
}
ok(found == 0, "/tmp element successfully deleted");
p = np_del_parameter(last, prev);
for (p = paths; p; p = p->name_next) {
if (! strcmp(p->name, "/home"))
found = 1;
last = p;
count++;
}
ok(found == 0, "last (/home) element successfully deleted");
ok(count == 2, "two elements remaining");
return exit_status();
}

58
lib/tests/test_tcp.c Normal file
View file

@ -0,0 +1,58 @@
/******************************************************************************
This program 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 2 of the License, or
(at your option) any later version.
This program 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 this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: test_tcp.c 1732 2007-06-03 15:58:22Z psychotrahe $
******************************************************************************/
#include "common.h"
#include "utils_tcp.h"
#include "tap.h"
int
main (int argc, char **argv)
{
char** server_expect;
int server_expect_count = 3;
plan_tests(8);
server_expect = malloc(sizeof(char*) * server_expect_count);
server_expect[0] = strdup("AA");
server_expect[1] = strdup("bb");
server_expect[2] = strdup("CC");
ok(np_expect_match("AA bb CC XX", server_expect, server_expect_count, FALSE, TRUE, FALSE) == TRUE,
"Test matching any string at the beginning (first expect string)");
ok(np_expect_match("bb AA CC XX", server_expect, server_expect_count, FALSE, TRUE, FALSE) == TRUE,
"Test matching any string at the beginning (second expect string)");
ok(np_expect_match("XX bb AA CC XX", server_expect, server_expect_count, FALSE, TRUE, FALSE) == FALSE,
"Test with strings not matching at the beginning");
ok(np_expect_match("XX CC XX", server_expect, server_expect_count, FALSE, TRUE, FALSE) == FALSE,
"Test matching any string");
ok(np_expect_match("XX", server_expect, server_expect_count, FALSE, FALSE, FALSE) == FALSE,
"Test not matching any string");
ok(np_expect_match("XX AA bb CC XX", server_expect, server_expect_count, TRUE, FALSE, FALSE) == TRUE,
"Test matching all strings");
ok(np_expect_match("XX bb CC XX", server_expect, server_expect_count, TRUE, FALSE, FALSE) == FALSE,
"Test not matching all strings");
ok(np_expect_match("XX XX", server_expect, server_expect_count, TRUE, FALSE, FALSE) == FALSE,
"Test not matching any string (testing all)");
return exit_status();
}

6
lib/tests/test_tcp.t Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/perl
use Test::More;
if (! -e "./test_tcp") {
plan skip_all => "./test_tcp not compiled - please install tap library to test";
}
exec "./test_tcp";

View file

@ -14,7 +14,7 @@
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: test_utils.c,v 1.2 2006/07/13 23:58:00 tonvoon Exp $
$Id: test_utils.c 1452 2006-07-13 23:58:00Z tonvoon $
******************************************************************************/