[gnome-calculator/60-split-out-a-backend-library] unit-tests: added initial gcalc tests



commit bf0633fa2c582fc708eee6d48286d3a1f92cdc6c
Author: Daniel Espinosa <esodan gmail com>
Date:   Mon Dec 10 17:44:33 2018 -0600

    unit-tests: added initial gcalc tests

 gcalc/gcalc-gsolver.vala         |  7 ++++++-
 gcalc/gcalc-solver.vala          |  4 ++++
 tests/gcalc-main-interfaces.vala | 38 ++++++++++++++++++++++++++++++++++++++
 tests/meson.build                | 11 +++++++++++
 4 files changed, 59 insertions(+), 1 deletion(-)
---
diff --git a/gcalc/gcalc-gsolver.vala b/gcalc/gcalc-gsolver.vala
index 78902148..95ff3856 100644
--- a/gcalc/gcalc-gsolver.vala
+++ b/gcalc/gcalc-gsolver.vala
@@ -22,7 +22,12 @@ public class GCalc.GSolver : Object, Solver {
   private Equation equation;
   public Result solve (string str) throws GLib.Error {
     equation = new Equation (str);
-    var num = equation.parse ();
+    ErrorCode err = ErrorCode.NONE;
+    uint rpb = 0;
+    var num = equation.parse (out rpb, out err);
+    if (num == null) {
+      throw new SolverError.EXPRESSION_ERROR ("Invalid equation. Parser error: %s", err.to_string ());
+    }
     var exp = new GExpression.number_object (num) as Expression;
     return new GResult (exp) as Result;
   }
diff --git a/gcalc/gcalc-solver.vala b/gcalc/gcalc-solver.vala
index 498a589a..68e4986d 100644
--- a/gcalc/gcalc-solver.vala
+++ b/gcalc/gcalc-solver.vala
@@ -21,3 +21,7 @@
 public interface GCalc.Solver : Object {
   public abstract Result solve (string str) throws GLib.Error;
 }
+
+public errordomain GCalc.SolverError {
+  EXPRESSION_ERROR
+}
diff --git a/tests/gcalc-main-interfaces.vala b/tests/gcalc-main-interfaces.vala
new file mode 100644
index 00000000..e342d87d
--- /dev/null
+++ b/tests/gcalc-main-interfaces.vala
@@ -0,0 +1,38 @@
+/* -*- Mode: Vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
+/*
+ * libvda Unit Tests
+ * Copyright (C) Daniel Espinosa Ortiz 2018 <esodan gmail com>
+ *
+ * libgda 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 3 of the License, or
+ * (at your option) any later version.
+ *
+ * libgda 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 program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+using GCalc;
+
+class Tests {
+  static int main (string[] args)
+  {
+    GLib.Intl.setlocale (GLib.LocaleCategory.ALL, "");
+    Test.init (ref args);
+    Test.add_func ("/gcalc/solver/initial",
+    ()=>{
+      try {
+        var solv = new GCalc.GSolver () as Solver;
+        //var res = solv.solve ("4+4");
+        //message (res.to_string ());
+      } catch (GLib.Error error) {
+        warning ("Error: %s", error.message);
+      }
+    });
+    return Test.run ();
+  }
+}
diff --git a/tests/meson.build b/tests/meson.build
index 3ff4af7c..b4f58cdc 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -44,3 +44,14 @@ test_serializer = executable('test-serializer', test_serializer_sources,
   include_directories: gnome_calculator_tests_includes,
 )
 test('Serializer test', test_serializer)
+
+
+test_main_interfaces_sources = [
+  'gcalc-main-interfaces.vala',
+]
+test_interfaces = executable('gcalc-interfaces', test_main_interfaces_sources,
+  dependencies: gnome_calculator_tests_deps,
+  link_with: [lib, lib_mpfrg],
+  include_directories: gnome_calculator_tests_includes,
+)
+test('gcalc-interfaces', test_interfaces)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]