Some more enhancements to the test infrastructure
authorJulien Peeters <contact@julienpeeters.fr>
Sat, 5 Sep 2009 14:25:54 +0000 (16:25 +0200)
committerDidier 'Ptitjes <ptitjes@free.fr>
Sun, 6 Sep 2009 14:24:14 +0000 (16:24 +0200)
TestCase is a more appropriate name, and so are set_up and tear_down.

tests/Makefile.am
tests/testarraylist.vala
tests/testcase.vala [moved from tests/testfixture.vala with 54% similarity]
tests/testcollection.vala

index e7a82e0..f0c3c52 100644 (file)
@@ -12,8 +12,8 @@ noinst_PROGRAMS = $(TEST_PROGS)
 progs_ldadd = $(GLIB_LIBS) ../gee/libgee.la
 
 TEST_PROGS += testarraylist
-testarraylist_VALASOURCES = testarraylist.vala testcollection.vala testfixture.vala
-testarraylist_SOURCES = testarraylist.c testcollection.c testfixture.c
+testarraylist_VALASOURCES = testarraylist.vala testcollection.vala testcase.vala
+testarraylist_SOURCES = testarraylist.c testcollection.c testcase.c
 $(testarraylist_SOURCES): $(testarraylist_VALASOURCES)
        $(VALAC) -C --basedir $(top_srcdir) --vapidir $(top_srcdir)/gee --pkg gee-1.0 $^
        touch $@
index 0c79dba..1e90a0d 100644 (file)
@@ -20,7 +20,6 @@
  *     Jürg Billeter <j@bitron.ch>
  */
 
-using GLib;
 using Gee;
 
 public class ArrayListTests : CollectionTests {
@@ -54,13 +53,13 @@ public class ArrayListTests : CollectionTests {
                add_test("iterator", test_arraylist_iterator);
        }
 
-       public override void setup () {
+       public override void set_up () {
                int_collection = new ArrayList<int> ();
                string_collection = new ArrayList<string> (str_equal);
                object_collection = new ArrayList<Object> ();
        }
 
-       public override void teardown () {
+       public override void tear_down () {
                int_collection = null;
                string_collection = null;
                object_collection = null;
similarity index 54%
rename from tests/testfixture.vala
rename to tests/testcase.vala
index 861a3b6..1d77a6d 100644 (file)
  *     Julien Peeters <contact@julienpeeters.fr>
  */
 
-using GLib;
+public abstract class Gee.TestCase : GLib.Object {
 
-public abstract class TestFixture: Object {
-
-       private TestSuite suite;
-       private TestAdaptor[] adaptors = new TestAdaptor[0];
+       private GLib.TestSuite suite;
+       private Adaptor[] adaptors = new Adaptor[0];
 
        public delegate void TestMethod ();
 
-       public TestFixture (string name) {
-               this.suite = new TestSuite (name);
+       public TestCase (string name) {
+               this.suite = new GLib.TestSuite (name);
        }
 
        public void add_test (string name, TestMethod test) {
-               var adaptor = new TestAdaptor (name, test, this);
+               var adaptor = new Adaptor (name, test, this);
                this.adaptors += adaptor;
 
-               this.suite.add (new TestCase (adaptor.name,
-                                             0,
-                                             adaptor.setup,
-                                             adaptor.run,
-                                             adaptor.teardown ));
+               this.suite.add (new GLib.TestCase (adaptor.name,
+                                                  0,
+                                                  adaptor.set_up,
+                                                  adaptor.run,
+                                                  adaptor.tear_down ));
        }
 
-       public virtual void setup () {}
-       public virtual void teardown () {}
+       public virtual void set_up () {
+       }
 
-       public TestSuite get_suite () {
-               return this.suite;
+       public virtual void tear_down () {
        }
 
-       public void add_to_suite (TestSuite suite) {
-               suite.add_suite (this.suite);
+       public GLib.TestSuite get_suite () {
+               return this.suite;
        }
 
-       private class TestAdaptor {
+       private class Adaptor {
 
-               public string name { set; get; }
+               public string name { get; private set; }
                private TestMethod test;
-               private TestFixture fixture;
+               private TestCase test_case;
 
-               public TestAdaptor (string name, TestMethod test, TestFixture fixture) {
+               public Adaptor (string name,
+                               TestMethod test,
+                               TestCase test_case) {
                        this.name = name;
                        this.test = test;
-                       this.fixture = fixture;
+                       this.test_case = test_case;
                }
 
-               public void setup (void* fixture) {
-                       this.fixture.setup ();
+               public void set_up (void* fixture) {
+                       this.test_case.set_up ();
                }
 
                public void run (void* fixture) {
                        this.test ();
                }
 
-               public void teardown (void* fixture) {
-                       this.fixture.teardown ();
+               public void tear_down (void* fixture) {
+                       this.test_case.tear_down ();
                }
        }
 }
index 4c31cd8..406448a 100644 (file)
  *     Didier 'Ptitjes' Villevalois <ptitjes@free.fr>
  */
 
-using GLib;
 using Gee;
 
-public abstract class CollectionTests : TestFixture {
+public abstract class CollectionTests : Gee.TestCase {
 
        public CollectionTests (string name) {
                base(name);