Commit 5b0e5e7e authored by Jürg Billeter's avatar Jürg Billeter Committed by Jürg Billeter
Browse files

add unit tests

2008-02-26  Juerg Billeter  <j@bitron.ch>

	* Makefile.am, Makefile.decl, configure.ac, gee/Makefile.am,
	  tests/Makefile.am, tests/testarraylist.vala,
	  tests/testhashmap.vala, tests/testhashset.vala: add unit tests

svn path=/trunk/; revision=22
parent 028f3ac4
2008-02-26 Jürg Billeter <j@bitron.ch>
* Makefile.am, Makefile.decl, configure.ac, gee/Makefile.am,
tests/Makefile.am, tests/testarraylist.vala,
tests/testhashmap.vala, tests/testhashset.vala: add unit tests
2008-02-26 Jürg Billeter <j@bitron.ch>
* gee/hashset.vala: fix iterator, patch by Ali Sabil
......
include $(top_srcdir)/Makefile.decl
NULL =
SUBDIRS = \
gee \
tests \
$(NULL)
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = gee-1.0.pc
EXTRA_DIST = \
EXTRA_DIST += \
MAINTAINERS \
gee-1.0.pc.in \
$(NULL)
......
# GLIB - Library of useful C routines
GTESTER = gtester
GTESTER_REPORT = gtester-report
# initialize variables for unconditional += appending
EXTRA_DIST =
TEST_PROGS =
### testing rules
# test: run all tests in cwd and subdirs
test: ${TEST_PROGS}
@test -z "${TEST_PROGS}" || ${GTESTER} --verbose ${TEST_PROGS}
@ for subdir in $(SUBDIRS) . ; do \
test "$$subdir" = "." -o "$$subdir" = "po" || \
( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
done
# test-report: run tests in subdirs and generate report
# perf-report: run tests in subdirs with -m perf and generate report
# full-report: like test-report: with -m perf and -m slow
test-report perf-report full-report: ${TEST_PROGS}
@test -z "${TEST_PROGS}" || { \
case $@ in \
test-report) test_options="-k";; \
perf-report) test_options="-k -m=perf";; \
full-report) test_options="-k -m=perf -m=slow";; \
esac ; \
if test -z "$$GTESTER_LOGDIR" ; then \
${GTESTER} --verbose $$test_options -o test-report.xml ${TEST_PROGS} ; \
elif test -n "${TEST_PROGS}" ; then \
${GTESTER} --verbose $$test_options -o `mktemp "$$GTESTER_LOGDIR/log-XXXXXX"` ${TEST_PROGS} ; \
fi ; \
}
@ ignore_logdir=true ; \
if test -z "$$GTESTER_LOGDIR" ; then \
GTESTER_LOGDIR=`mktemp -d "\`pwd\`/.testlogs-XXXXXX"`; export GTESTER_LOGDIR ; \
ignore_logdir=false ; \
fi ; \
for subdir in $(SUBDIRS) . ; do \
test "$$subdir" = "." -o "$$subdir" = "po" || \
( cd $$subdir && $(MAKE) $(AM_MAKEFLAGS) $@ ) || exit $? ; \
done ; \
$$ignore_logdir || { \
echo '<?xml version="1.0"?>' > $@.xml ; \
echo '<report-collection>' >> $@.xml ; \
for lf in `ls -L "$$GTESTER_LOGDIR"/.` ; do \
sed '1,1s/^<?xml\b[^>?]*?>//' <"$$GTESTER_LOGDIR"/"$$lf" >> $@.xml ; \
done ; \
echo >> $@.xml ; \
echo '</report-collection>' >> $@.xml ; \
rm -rf "$$GTESTER_LOGDIR"/ ; \
${GTESTER_REPORT} --version 2>/dev/null 1>&2 ; test "$$?" != 0 || ${GTESTER_REPORT} $@.xml >$@.html ; \
}
.PHONY: test test-report perf-report full-report
# run make test as part of make check
check-local: test
......@@ -24,6 +24,7 @@ AC_SUBST(GLIB_LIBS)
AC_CONFIG_FILES([Makefile
gee-1.0.pc
gee/Makefile])
gee/Makefile
tests/Makefile])
AC_OUTPUT
include $(top_srcdir)/Makefile.decl
NULL =
AM_CPPFLAGS = \
......@@ -53,4 +55,4 @@ dist_vapi_DATA = \
gee-1.0.vapi \
$(NULL)
EXTRA_DIST = $(libgee_la_VALASOURCES) gee-1.0.vapi gee.vala.stamp
EXTRA_DIST += $(libgee_la_VALASOURCES) gee-1.0.vapi gee.vala.stamp
include $(top_srcdir)/Makefile.decl
NULL =
AM_CPPFLAGS = \
-I$(top_srcdir) \
$(GLIB_CFLAGS) \
$(NULL)
noinst_PROGRAMS = $(TEST_PROGS)
progs_ldadd = $(GLIB_LIBS) ../gee/libgee.la
TEST_PROGS += testarraylist
testarraylist_VALASOURCES = testarraylist.vala
testarraylist_SOURCES = testarraylist.c testarraylist.h
$(testarraylist_SOURCES): $(testarraylist_VALASOURCES)
$(VALAC) --basedir $(top_srcdir) --vapidir $(top_srcdir)/gee --pkg gee-1.0 $^
touch $@
testarraylist_LDADD = $(progs_ldadd)
TEST_PROGS += testhashmap
testhashmap_VALASOURCES = testhashmap.vala
testhashmap_SOURCES = testhashmap.c testhashmap.h
$(testhashmap_SOURCES): $(testhashmap_VALASOURCES)
$(VALAC) --basedir $(top_srcdir) --vapidir $(top_srcdir)/gee --pkg gee-1.0 $^
touch $@
testhashmap_LDADD = $(progs_ldadd)
TEST_PROGS += testhashset
testhashset_VALASOURCES = testhashset.vala
testhashset_SOURCES = testhashset.c testhashset.h
$(testhashset_SOURCES): $(testhashset_VALASOURCES)
$(VALAC) --basedir $(top_srcdir) --vapidir $(top_srcdir)/gee --pkg gee-1.0 $^
touch $@
testhashset_LDADD = $(progs_ldadd)
EXTRA_DIST += $(testhashset_VALASOURCES)
/* testarraylist.vala
*
* Copyright (C) 2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Jürg Billeter <j@bitron.ch>
*/
using GLib;
using Gee;
void test_arraylist_int_add () {
var arraylist = new ArrayList<int> ();
arraylist.add (42);
assert (arraylist.contains (42));
assert (arraylist.size == 1);
}
void test_arraylist_int_iterator () {
var arraylist = new ArrayList<int> ();
arraylist.add (42);
var it = arraylist.iterator ();
assert (it.next ());
assert (it.get () == 42);
assert (!it.next ());
}
void test_arraylist_int_remove () {
var arraylist = new ArrayList<int> ();
arraylist.add (42);
arraylist.remove (42);
assert (!arraylist.contains (42));
assert (arraylist.size == 0);
}
void test_arraylist_string_add () {
var arraylist = new ArrayList<string> (str_equal);
arraylist.add ("hello");
assert (arraylist.contains ("hello"));
assert (arraylist.size == 1);
}
void test_arraylist_string_iterator () {
var arraylist = new ArrayList<string> (str_equal);
arraylist.add ("hello");
var it = arraylist.iterator ();
assert (it.next ());
assert (it.get () == "hello");
assert (!it.next ());
}
void test_arraylist_string_remove () {
var arraylist = new ArrayList<string> (str_equal);
arraylist.add ("hello");
arraylist.remove ("hello");
assert (!arraylist.contains ("hello"));
assert (arraylist.size == 0);
}
void main (string[] args) {
Test.init (ref args);
Test.add_func ("/arraylist/int/add", test_arraylist_int_add);
Test.add_func ("/arraylist/int/iterator", test_arraylist_int_iterator);
Test.add_func ("/arraylist/int/remove", test_arraylist_int_remove);
Test.add_func ("/arraylist/string/add", test_arraylist_string_add);
Test.add_func ("/arraylist/string/iterator", test_arraylist_string_iterator);
Test.add_func ("/arraylist/string/remove", test_arraylist_string_remove);
Test.run ();
}
/* testhashmap.vala
*
* Copyright (C) 2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Jürg Billeter <j@bitron.ch>
*/
using GLib;
using Gee;
void test_hashmap_int_int_remove () {
var hashmap = new HashMap<int,int> ();
hashmap.set (42, 23);
hashmap.remove (42);
assert (!hashmap.contains (42));
assert (hashmap.size == 0);
}
void test_hashmap_int_int_set () {
var hashmap = new HashMap<int,int> ();
hashmap.set (42, 23);
assert (hashmap.contains (42));
assert (hashmap.get (42) == 23);
assert (hashmap.size == 1);
}
void test_hashmap_string_string_remove () {
var hashmap = new HashMap<string,string> (str_hash, str_equal, str_equal);
hashmap.set ("hello", "world");
hashmap.remove ("hello");
assert (!hashmap.contains ("hello"));
assert (hashmap.size == 0);
}
void test_hashmap_string_string_set () {
var hashmap = new HashMap<string,string> (str_hash, str_equal, str_equal);
hashmap.set ("hello", "world");
assert (hashmap.contains ("hello"));
assert (hashmap.get ("hello") == "world");
assert (hashmap.size == 1);
}
void main (string[] args) {
Test.init (ref args);
Test.add_func ("/hashmap/int-int/remove", test_hashmap_int_int_remove);
Test.add_func ("/hashmap/int-int/set", test_hashmap_int_int_set);
Test.add_func ("/hashmap/string-string/remove", test_hashmap_string_string_remove);
Test.add_func ("/hashmap/string-string/set", test_hashmap_string_string_set);
Test.run ();
}
/* testhashset.vala
*
* Copyright (C) 2008 Jürg Billeter
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library 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
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Author:
* Jürg Billeter <j@bitron.ch>
*/
using GLib;
using Gee;
void test_hashset_int_add () {
var hashset = new HashSet<int> ();
hashset.add (42);
assert (hashset.contains (42));
assert (hashset.size == 1);
}
void test_hashset_int_iterator () {
var hashset = new HashSet<int> ();
hashset.add (42);
var it = hashset.iterator ();
assert (it.next ());
assert (it.get () == 42);
assert (!it.next ());
}
void test_hashset_int_remove () {
var hashset = new HashSet<int> ();
hashset.add (42);
hashset.remove (42);
assert (!hashset.contains (42));
assert (hashset.size == 0);
}
void test_hashset_string_add () {
var hashset = new HashSet<string> (str_hash, str_equal);
hashset.add ("hello");
assert (hashset.contains ("hello"));
assert (hashset.size == 1);
}
void test_hashset_string_iterator () {
var hashset = new HashSet<string> (str_hash, str_equal);
hashset.add ("hello");
var it = hashset.iterator ();
assert (it.next ());
assert (it.get () == "hello");
assert (!it.next ());
}
void test_hashset_string_remove () {
var hashset = new HashSet<string> (str_hash, str_equal);
hashset.add ("hello");
hashset.remove ("hello");
assert (!hashset.contains ("hello"));
assert (hashset.size == 0);
}
void main (string[] args) {
Test.init (ref args);
Test.add_func ("/hashset/int/add", test_hashset_int_add);
Test.add_func ("/hashset/int/iterator", test_hashset_int_iterator);
Test.add_func ("/hashset/int/remove", test_hashset_int_remove);
Test.add_func ("/hashset/string/add", test_hashset_string_add);
Test.add_func ("/hashset/string/iterator", test_hashset_string_iterator);
Test.add_func ("/hashset/string/remove", test_hashset_string_remove);
Test.run ();
}
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