Changeset - c718c481771c
[Not reviewed]
default
0 4 4
Nathan Brink (binki) - 15 years ago 2010-09-24 11:53:29
ohnobinki@ohnopublishing.net
Fix up testsuite to actually run tests and to use one executable instead of three.
8 files changed with 237 insertions and 55 deletions:
0 comments (0 inline, 0 general)
Makefile.am
Show inline comments
 
@@ -86,14 +86,13 @@ EXTRA_DIST = etc/distrendaemon.conf.in \
 

	
 

	
 
# tests
 
TESTS=test/check_execio test/check_asprintf test/check_csv
 
check_PROGRAMS=$(TESTS)
 
TESTS = test/check
 
check_PROGRAMS = $(TESTS)
 

	
 
#check_execio_LIBS = $(CHECK_LIBS)
 
#check_asprintf_LIBS = $(CHECK_LIBS)
 
test_check_csv_LDADD = $(CHECK_LIBS) libdistrencommon.la
 
test_check_execio_LDADD = $(CHECK_LIBS) libdistrencommon.la
 
test_check_asprintf_LDADD = $(CHECK_LIBS) libdistrencommon.la
 
test_check_csv_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS)
 
test_check_execio_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS)
 
test_check_asprintf_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS)
 
test_check_LDADD = $(CHECK_LIBS) libdistrencommon.la
 
test_check_CFLAGS = $(AM_CFLAGS) $(CHECK_CFLAGS)
 
test_check_SOURCES = \
 
	test/check.c \
 
	test/check_asprintf.c test/check_asprintf.h \
 
	test/check_csv.c test/check_csv.h \
 
	test/check_execio.c test/check_execio.h
test/check.c
Show inline comments
 
new file 100644
 
/*
 
 * Copyright 2010 Nathan Phillip Brink
 
 *
 
 * This file is a part of DistRen.
 
 *
 
 * DistRen is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * DistRen 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 Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
#include <check.h>
 
#include <stdio.h>
 
#include <stdlib.h>
 

	
 
#include "check_asprintf.h"
 
#include "check_csv.h"
 
#include "check_execio.h"
 

	
 
/**
 
 * \brief
 
 *   Use libcheck to run our full testsuite.
 
 */
 
int main(int argc, char *argv[])
 
{
 
  int number_failed;
 
  size_t test_num;
 

	
 
  Suite *s;
 
  SRunner *sr;
 

	
 
  Suite *(*suites[])() =
 
    {
 
      &asprintf_suite,
 
      &csv_suite,
 
      &execio_suite,
 
      NULL
 
    };
 

	
 
  number_failed = 0;
 

	
 
  for (test_num = 0; suites[test_num]; test_num ++)
 
    {
 
      s = (*suites[test_num])();
 
      sr = srunner_create(s);
 

	
 
      srunner_run_all(sr, CK_NORMAL);
 
      number_failed += srunner_ntests_failed(sr);
 
      srunner_free(sr);
 
    }
 

	
 
  if (number_failed)
 
    {
 
      fprintf(stderr, "total tests failed: %d\n", number_failed);
 
      return EXIT_FAILURE;
 
    }
 
  return EXIT_SUCCESS;
 
}
test/check_asprintf.c
Show inline comments
 
@@ -17,6 +17,8 @@
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include "check_asprintf.h"
 

	
 
#include "common/asprintf.h"
 

	
 
#include <check.h>
 
@@ -35,9 +37,16 @@ START_TEST (check_asprintf)
 
}
 
END_TEST
 

	
 
int main(int argc, char *argv[])
 
Suite *asprintf_suite()
 
{
 
  return 0;
 
  /* see http://check.sourceforge.net/doc/check.html/check_6.html#SEC6 */
 
  Suite *s;
 
  TCase *tc;
 

	
 
  s = suite_create("asprintf");
 

	
 
  tc = tcase_create("core");
 
  tcase_add_test(tc, check_asprintf);
 
  suite_add_tcase(s, tc);
 

	
 
  return s;
 
}
 

	
test/check_asprintf.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright 2010 Nathan Phillip Brink
 
 *
 
 * This file is a part of DistRen.
 
 *
 
 * DistRen is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * DistRen 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 Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
#ifndef _DISTREN_CHECK_ASPRINTF_H
 
#define _DISTREN_CHECK_ASPRINTF_H
 

	
 
#include <check.h>
 

	
 
/**
 
 * \brief
 
 *   Return a suite with a set of tests for the common/asprintf
 
 *   functionality
 
 */
 
Suite *asprintf_suite();
 

	
 
#endif /* _DISTREN_CHECK_ASPRINTF_H */
test/check_csv.c
Show inline comments
 
@@ -17,6 +17,8 @@
 
 * along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
#include "check_csv.h"
 

	
 
#include "common/csv.h"
 

	
 
#include <check.h>
 
@@ -110,7 +112,7 @@ d,f,ss,e\n", vals.num_cols);
 
}
 
END_TEST
 

	
 
static Suite *csv_suite()
 
Suite *csv_suite()
 
{
 
  Suite *s;
 
  TCase *tc;
 
@@ -123,21 +125,3 @@ static Suite *csv_suite()
 

	
 
  return s;
 
}
 

	
 
int main(int argc, char *argv[])
 
{
 
  int number_failed;
 
  Suite *s;
 
  SRunner *sr;
 

	
 
  s = csv_suite();
 
  sr = srunner_create(s);
 

	
 
  srunner_run_all(sr, CK_NORMAL);
 
  number_failed = srunner_ntests_failed(sr);
 
  srunner_free(sr);
 

	
 
  if (number_failed)
 
    return EXIT_FAILURE;
 
  return EXIT_SUCCESS;
 
}
test/check_csv.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright 2010 Nathan Phillip Brink
 
 *
 
 * This file is a part of DistRen.
 
 *
 
 * DistRen is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * DistRen 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 Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
#ifndef _DISTREN_CHECK_CSV_H
 
#define _DISTREN_CHECK_CSV_H
 

	
 
#include <check.h>
 

	
 
/**
 
 * \brief
 
 *   Return a suite with a set of tests for the common/csv
 
 *   functionality.
 
 */
 
Suite *csv_suite();
 

	
 
#endif /* _DISTREN_CHECK_CSV_H */
test/check_execio.c
Show inline comments
 
/*
 
  Copyright 2010 Nathan Phillip Brink, Ethan Zonca
 

	
 
  This file is a part of DistRen.
 
 * Copyright 2010 Nathan Phillip Brink, Ethan Zonca
 
 *
 
 * This file is a part of DistRen.
 
 *
 
 * DistRen is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * DistRen 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 Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
  DistRen is free software: you can redistribute it and/or modify
 
  it under the terms of the GNU Affero General Public License as published by
 
  the Free Software Foundation, either version 3 of the License, or
 
  (at your option) any later version.
 

	
 
  DistRen 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 Affero General Public License for more details.
 

	
 
  You should have received a copy of the GNU Affero General Public License
 
  along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
*/
 
#include "check_execio.h"
 

	
 
#include "common/execio.h"
 

	
 
#include <check.h>
 
#include <string.h>
 

	
 
START_TEST (check_execio)
 
{
 
@@ -32,21 +35,46 @@ START_TEST (check_execio)
 

	
 
  char inbuf[20];
 
  size_t bytesread;
 
  
 
  size_t pos;
 

	
 
  pos = 1;
 

	
 
  fail_unless(execio_open(&eio, echoargv[0], echoargv) == 0,
 
	      "execio_open failed");
 
  
 
  fail_unless(execio_read(eio, inbuf, sizeof(inbuf) - 1, &bytesread) == 0,
 
	      "error using execio_read\n");
 
  
 
  pos += bytesread;
 

	
 
  while (bytesread && pos < (sizeof(inbuf) - 1))
 
    {
 
      execio_read(eio, &inbuf[pos], sizeof(inbuf) - 1 - pos, &bytesread);
 
      pos += bytesread;
 
    }
 

	
 
  fail_if (pos > 10,
 
	   "I read more than 10 bytes from the command ``echo test'' when I expected only 5 or 6 bytes");
 

	
 
  inbuf[sizeof(inbuf) - 1] = '\0';
 
  fail_if (strncmp(inbuf, "test", 4),
 
	   "Expecting ``test''; got ``%s''",
 
	   inbuf);
 

	
 
  fail_unless(execio_close(eio) == 0,
 
	      "error using execio_close\n");
 
}
 
END_TEST
 

	
 
int main(int argc, char *argv[])
 
Suite *execio_suite()
 
{
 
  return 0;
 
  /* see http://check.sourceforge.net/doc/check.html/check_6.html#SEC6 */
 
  Suite *s;
 
  TCase *tc;
 

	
 
  s = suite_create("execio");
 

	
 
  tc = tcase_create("core");
 
  tcase_add_test(tc, check_execio);
 
  suite_add_tcase(s, tc);
 

	
 
  return s;
 
}
 

	
test/check_execio.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright 2010 Nathan Phillip Brink
 
 *
 
 * This file is a part of DistRen.
 
 *
 
 * DistRen is free software: you can redistribute it and/or modify
 
 * it under the terms of the GNU Affero General Public License as published by
 
 * the Free Software Foundation, either version 3 of the License, or
 
 * (at your option) any later version.
 
 *
 
 * DistRen 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 Affero General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU Affero General Public License
 
 * along with DistRen.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
#ifndef _DISTREN_CHECK_EXECIO_H
 
#define _DISTREN_CHECK_EXECIO_H
 

	
 
#include <check.h>
 

	
 
/**
 
 * \brief
 
 *   Return a suite with a set of tests for the common/csv
 
 *   functionality.
 
 */
 
Suite *execio_suite();
 

	
 
#endif /* _DISTREN_CHECK_EXECIO_H */
0 comments (0 inline, 0 general)