From 99959f8ececf19c143f672a9600068a551bf480d Mon Sep 17 00:00:00 2001 From: Rico Tzschichholz Date: Mon, 26 Sep 2016 20:01:31 +0200 Subject: Rename Module to TestModule --- valadate/Makefile.am | 2 +- valadate/module.vala | 58 ---------------------------------------------- valadate/testexplorer.vala | 14 +++++------ valadate/testmodule.vala | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 66 insertions(+), 66 deletions(-) delete mode 100644 valadate/module.vala create mode 100644 valadate/testmodule.vala diff --git a/valadate/Makefile.am b/valadate/Makefile.am index 1d6dbf7d2..6c71cf831 100644 --- a/valadate/Makefile.am +++ b/valadate/Makefile.am @@ -21,12 +21,12 @@ lib_LTLIBRARIES = \ $(NULL) libvaladate_la_VALASOURCES = \ - module.vala \ test.vala \ testcase.vala \ testconfig.vala \ testexplorer.vala \ testiterator.vala \ + testmodule.vala \ testresult.vala \ testrunner.vala \ testsuite.vala \ diff --git a/valadate/module.vala b/valadate/module.vala deleted file mode 100644 index 1cf32c80a..000000000 --- a/valadate/module.vala +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Valadate - Unit testing library for GObject-based libraries. - * Copyright (C) 2016 Chris Daley - * - * 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 - * - * Authors: - * Chris Daley - */ - -public errordomain Valadate.ModuleError { - NOT_FOUND, - LOAD, - METHOD -} - -/** - * Represents a loadable module containing {@link Valadate.Test}s - */ -public class Valadate.Module : Object { - - private string lib_path; - private GLib.Module module; - - public Module (string libpath) { - lib_path = libpath; - } - - public void load_module () throws ModuleError { - if (!File.new_for_path (lib_path).query_exists ()) - throw new ModuleError.NOT_FOUND ("Module: %s does not exist", lib_path); - - module = GLib.Module.open (lib_path, ModuleFlags.BIND_LOCAL); - if (module == null) - throw new ModuleError.LOAD (GLib.Module.error ()); - module.make_resident (); - } - - internal void* get_method (string method_name) throws ModuleError { - void* function; - if (module.symbol (method_name, out function)) - if (function != null) - return function; - throw new ModuleError.METHOD (GLib.Module.error ()); - } -} diff --git a/valadate/testexplorer.vala b/valadate/testexplorer.vala index 97a72f262..7c12b9ce3 100644 --- a/valadate/testexplorer.vala +++ b/valadate/testexplorer.vala @@ -27,7 +27,7 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor { private TestSuite current; private Vala.CodeContext context; - private Module module; + private TestModule module; private string binary; private string? running; @@ -50,10 +50,10 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor { throw new ConfigError.TESTPLAN ("Test Plan %s Not Found!", testplanfile); try { - module = new Module (binary); + module = new TestModule (binary); module.load_module (); load_test_plan (testplanfile); - } catch (ModuleError e) { + } catch (TestModuleError e) { throw new ConfigError.MODULE (e.message); } } @@ -83,7 +83,7 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor { class.is_abstract != true) current.add_test (visit_testsuite (class)); - } catch (ModuleError e) { + } catch (TestModuleError e) { error (e.message); } class.accept_children (this); @@ -96,12 +96,12 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor { return false; } - private unowned Constructor get_constructor (Vala.Class class) throws ModuleError { + private unowned Constructor get_constructor (Vala.Class class) throws TestModuleError { var attr = new Vala.CCodeAttribute (class.default_construction_method); return (Constructor)module.get_method (attr.name); } - public TestCase visit_testcase (Vala.Class testclass) throws ModuleError { + public TestCase visit_testcase (Vala.Class testclass) throws TestModuleError { unowned Constructor meth = get_constructor(testclass); var current_test = meth () as TestCase; current_test.name = testclass.name; @@ -129,7 +129,7 @@ internal class Valadate.TestExplorer : Vala.CodeVisitor { return current_test; } - public TestSuite visit_testsuite (Vala.Class testclass) throws ModuleError { + public TestSuite visit_testsuite (Vala.Class testclass) throws TestModuleError { unowned Constructor meth = get_constructor (testclass); var current_test = meth () as TestSuite; current_test.name = testclass.name; diff --git a/valadate/testmodule.vala b/valadate/testmodule.vala new file mode 100644 index 000000000..eda6ac59e --- /dev/null +++ b/valadate/testmodule.vala @@ -0,0 +1,58 @@ +/* + * Valadate - Unit testing library for GObject-based libraries. + * Copyright (C) 2016 Chris Daley + * + * 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 + * + * Authors: + * Chris Daley + */ + +public errordomain Valadate.TestModuleError { + NOT_FOUND, + LOAD, + METHOD +} + +/** + * Represents a loadable module containing {@link Valadate.Test}s + */ +public class Valadate.TestModule : Object { + + private string lib_path; + private GLib.Module module; + + public TestModule (string libpath) { + lib_path = libpath; + } + + public void load_module () throws TestModuleError { + if (!File.new_for_path (lib_path).query_exists ()) + throw new TestModuleError.NOT_FOUND ("Module: %s does not exist", lib_path); + + module = GLib.Module.open (lib_path, ModuleFlags.BIND_LOCAL); + if (module == null) + throw new TestModuleError.LOAD (GLib.Module.error ()); + module.make_resident (); + } + + internal void* get_method (string method_name) throws TestModuleError { + void* function; + if (module.symbol (method_name, out function)) + if (function != null) + return function; + throw new TestModuleError.METHOD (GLib.Module.error ()); + } +} -- cgit v1.2.1