Add tests module. Fix warnings and bugs.

Note to module writers: include gnc-module-api.h to make sure
your signatures are correct.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@5168 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas
2001-08-17 22:49:17 +00:00
parent 0980fa2934
commit f959452ec4
18 changed files with 406 additions and 41 deletions

View File

@@ -681,6 +681,7 @@ AC_OUTPUT(
src/scm/gnumeric/Makefile
src/scm/printing/Makefile
src/test/Makefile
src/test-core/Makefile
dnl # non-makefiles
dnl # Please read doc/build-system before adding *anything* here

View File

@@ -2,6 +2,7 @@
SUBDIRS = \
doc \
gnc-module \
test-core \
engine \
backend \
app-utils \

View File

@@ -12,6 +12,7 @@
#include <libguile/modules.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
/* version of the gnc module system interface we require */
int gnc_module_system_interface = 0;
@@ -54,9 +55,7 @@ gnc_module_init(int refcount) {
return TRUE;
}
void
gnc_module_finish(int refcount) {
int
gnc_module_end(int refcount) {
return TRUE;
}

View File

@@ -1,6 +0,0 @@
Makefile
Makefile.in
.deps
.libs
*.lo
*.la

View File

@@ -1,8 +1,12 @@
#include "config.h"
#include <kvp_frame.h>
#include <g-wrap-runtime-guile.h>
#include <libguile.h>
#include <engine-helpers.h>
#include "kvp-scm.h"
int
gnc_kvp_value_ptr_p(SCM arg)
{

View File

@@ -27,6 +27,6 @@
char * gnc_module_path (void);
char * gnc_module_description (void);
int gnc_module_init (int refcount);
int gnc_module_end(int refcount);
int gnc_module_end (int refcount);
#endif

View File

@@ -8,7 +8,9 @@
#include <stdio.h>
#include <guile/gh.h>
#include <glib.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
/* version of the gnc module system interface we require */
int gnc_module_system_interface = 0;
@@ -51,8 +53,7 @@ gnc_module_on_load(void) {
gh_eval_str("(use-modules (gnucash qif-io core))");
}
void
gnc_module_finish(void) {
int
gnc_module_end(void) {
return TRUE;
}

View File

@@ -1,6 +1,6 @@
pkglib_LTLIBRARIES = libgncmod-register-gnome.la
libgncmod_register_gnome_la_LDFLAGS = -module ${GNOMEUI_LIBS}
libgncmod_register_gnome_la_LDFLAGS = -module ${GNOME_LIBDIR} ${GNOMEUI_LIBS}
libgncmod_register_gnome_la_SOURCES = \
gncmod-register-gnome.c \

View File

@@ -8,7 +8,9 @@
#include <stdio.h>
#include <guile/gh.h>
#include <glib.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
/* version of the gnc module system interface we require */
int gnc_module_system_interface = 0;
@@ -44,9 +46,7 @@ gnc_module_init(int refcount) {
return TRUE;
}
void
gnc_module_finish(int refcount) {
int
gnc_module_end(int refcount) {
return TRUE;
}

View File

@@ -8,7 +8,9 @@
#include <stdio.h>
#include <guile/gh.h>
#include <glib.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
/* version of the gnc module system interface we require */
int gnc_module_system_interface = 0;
@@ -58,9 +60,7 @@ gnc_module_init(int refcount) {
return TRUE;
}
void
gnc_module_finish(int refcount) {
int
gnc_module_end(int refcount) {
return TRUE;
}

View File

@@ -8,7 +8,9 @@
#include <stdio.h>
#include <guile/gh.h>
#include <glib.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
/* version of the gnc module system interface we require */
int gnc_module_system_interface = 0;
@@ -43,9 +45,8 @@ gnc_module_init(int refcount) {
return TRUE;
}
void
gnc_module_finish(int refcount) {
int
gnc_module_end(int refcount) {
return TRUE;
}

View File

@@ -8,7 +8,9 @@
#include <stdio.h>
#include <guile/gh.h>
#include <glib.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
/* version of the gnc module system interface we require */
int gnc_module_system_interface = 0;
@@ -44,9 +46,7 @@ gnc_module_init(int refcount) {
return TRUE;
}
void
gnc_module_finish(int refcount) {
int
gnc_module_end(int refcount) {
return TRUE;
}

View File

@@ -8,7 +8,9 @@
#include <stdio.h>
#include <guile/gh.h>
#include <glib.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
/* version of the gnc module system interface we require */
int gnc_module_system_interface = 0;
@@ -44,9 +46,7 @@ gnc_module_init(int refcount) {
return TRUE;
}
void
gnc_module_finish(int refcount) {
int
gnc_module_end(int refcount) {
return TRUE;
}

2
src/test-core/.cvsignore Normal file
View File

@@ -0,0 +1,2 @@
Makefile
Makefile.in

11
src/test-core/Makefile.am Normal file
View File

@@ -0,0 +1,11 @@
noinst_LTLIBRARIES=libgncmod-test.la
libgncmod_test_la_SOURCES = gncmod-test.c test-stuff.c
libgncmod_test_la_LDFLAGS = -module
libgncmod_test_la_LIBADD = \
-L${top_srcdir}/src/gnc-module -L${top_srcdir}/src/gnc-module/.libs -lgncmodule \
${GLIB_LIBS} ${GUILE_LIBS}
noinst_HEADERS=test-stuff.h
INCLUDES=-I${top_srcdir}/src/gnc-module ${GLIB_CFLAGS}

View File

@@ -0,0 +1,40 @@
/*********************************************************************
* gncmod-test.c
* module definition/initialization for the report infrastructure
*
* Copyright (c) 2001 Linux Developers Group, Inc.
*********************************************************************/
#include <stdio.h>
#include <glib.h>
#include "gnc-module.h"
#include "gnc-module-api.h"
/* version of the gnc module system interface we require */
int gnc_module_system_interface = 0;
/* module versioning uses libtool semantics. */
int gnc_module_current = 0;
int gnc_module_revision = 0;
int gnc_module_age = 0;
char *
gnc_module_path(void) {
return g_strdup("gnucash/test");
}
char *
gnc_module_description(void) {
return g_strdup("Basic GnuCash test infrastructure.");
}
int
gnc_module_init(int refcount) {
return TRUE;
}
int
gnc_module_end(int refcount) {
return TRUE;
}

190
src/test-core/test-stuff.c Normal file
View File

@@ -0,0 +1,190 @@
/*
* Created 20010320 by bstanley to hold only those
* testing functions which are independent of the rest of
* the GNUCash system.
*
* This allows me to compile simple test programs standalone...
*
*/
#include "config.h"
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <glib.h>
#include "test-stuff.h"
void vsuccess_args(
const char *test_title,
const char *file,
int line,
const char *format,
va_list ap);
void vfailure_args(
const char *test_title,
const char *file,
int line,
const char *format,
va_list ap);
static guint successes;
static guint failures;
static gboolean success_should_print = FALSE;
void
success_call(
const char *test_title,
const char* file,
int line )
{
success_args( test_title, file, line, "" );
}
void
success_args(
const char *test_title,
const char *file,
int line,
const char *format,
... )
{
va_list ap;
va_start(ap,format);
vsuccess_args( test_title, file, line, format, ap );
va_end(ap);
}
void
vsuccess_args(
const char *test_title,
const char *file,
int line,
const char *format,
va_list ap)
{
if( success_should_print ) {
printf("SUCCESS: %s, %s:%d ", test_title, file, line );
vprintf(format, ap);
printf("\n");
fflush(stdout);
}
++successes;
}
void
failure_call(
const char *test_title,
const char *file,
int line)
{
failure_args( test_title, file, line, "" );
}
void
failure_args(
const char *test_title,
const char *file,
int line,
const char *format,
... )
{
va_list ap;
va_start(ap,format);
vfailure_args( test_title, file, line, format, ap );
va_end(ap);
}
void
vfailure_args(
const char *test_title,
const char* file,
int line,
const char *format,
va_list ap)
{
printf("FAILURE %s %s:%d ", test_title, file, line );
vprintf(format, ap);
printf("\n");
fflush(stdout);
++failures;
}
int
get_rv(void)
{
if( failures ) {
return 1;
}
return 0;
}
void
do_test_call(
gboolean result,
const char* test_title,
const char* filename,
int line )
{
if( result ) {
success_args( test_title, filename, line, "" );
} else {
failure_args( test_title, filename, line, "" );
}
}
void
do_test_args(
gboolean result,
const char* test_title,
const char* filename,
int line,
const char* format,
... )
{
va_list ap;
va_start(ap, format);
if( result ) {
vsuccess_args( test_title, filename, line, format, ap );
} else {
vfailure_args( test_title, filename, line, format, ap );
}
va_end(ap);
}
void
print_test_results(void)
{
guint total = successes+failures;
if( total == 1 ) {
printf( "Executed 1 test." );
} else {
printf("Executed %d tests.", successes+failures );
}
if( failures ) {
if( failures == 1 ) {
printf(" There was 1 failure." );
} else {
printf(" There were %d failures.", failures );
}
} else {
printf(" All tests passed.");
}
printf("\n");
fflush(stdout);
}
void
set_success_print( gboolean in_should_print )
{
success_should_print = in_should_print;
}

121
src/test-core/test-stuff.h Normal file
View File

@@ -0,0 +1,121 @@
/* Modified by bstanley 20010320
* Added do_test macro, do_test_call and do_test_call_args,
* print_test_results, set_success_print.
*
* Modified by bstanley 20010323
* removed testing functionality which depends on the rest of gnucash -
* sepearated into gnc-test-stuff.h
*
*/
/* Outline of a test program using the new testing functions:
#include "test-stuff.h"
int main( int argc, char* argv[] )
{
int a, b;
g_log_set_always_fatal( G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING );
a = b = 1;
do_test( a == b, 'integer equality" );
do_test( a != b, 'integer inequality? (should fail)" );
do_test_args( a == b, "fancy info", __FILE__, __LINE__, "a = %d, b = %b", a, b );
print_test_results();
return get_rv();
}
*/
/* If you want to see test passes, use
set_success_print(TRUE);
before you execute the tests.
Otherwise, only failures are printed out.
*/
#ifndef TEST_STUFF_H
#define TEST_STUFF_H
#include "config.h"
#include <glib.h>
#include <stdlib.h>
/**
* Use this to indicate the result of a test.
* The result is TRUE for success, FALSE for failure.
* title describes the test
* Tests are automatically identified by their source file and line.
*/
#define do_test( result, title ) do_test_call( result, title, __FILE__, __LINE__ );
#define success( title ) success_call( title, __FILE__, __LINE__ );
#define failure( title ) failure_call( title, __FILE__, __LINE__ );
/** This one doesn't work because macros can't take a variable number of arguments.
* well, apparently gcc can, but it's non-standard.
* Apparently C99 can, too, but it's not exactly standard either.
#define do_test_args( result, title, format ) do_test_call( result, title, __FILE__, __LINE__, format, ... );
*/
/* Privately used to indicate a test result. You may use these if you
* wish, but it's easier to use the do_test macro above.
*/
void do_test_call(
gboolean result,
const char* test_title,
const char* filename,
int line );
void do_test_args(
gboolean result,
const char* test_title,
const char* filename,
int line,
const char* format, ... );
/**
* Prints out the number of tests passed and failed.
*/
void print_test_results(void);
/**
* Use this to set whether successful tests
* should print a message.
* Default is false.
* Successful test messages are useful while initally constructing the
* test suite, but when it's completed, no news is good news.
* A successful test run will be indicated by the message
* from print_test_results().
*/
void set_success_print( gboolean in_should_print );
/* Value to return from main. Set to 1 if there were any fails, 0 otherwise. */
int get_rv(void);
/** Testing primitives.
* Sometimes you just have to put the results of
* a test into different forks of the code.
*/
void success_call(
const char *test_title,
const char *file,
int line );
void success_args(
const char *test_title,
const char *file,
int line,
const char *format,
... );
void failure_call(
const char *test_title,
const char *file,
int line);
void failure_args(
const char *test_title,
const char *file,
int line,
const char *format,
... );
#endif /* TEST_STUFF_H */