gtkflow-test-app-class.vala 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
  2. /* GtkFlowTest
  3. *
  4. * Copyright (C) 2015 Daniel Espinosa <esodan@gmail.com>
  5. *
  6. * librescl is free software: you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * librescl is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. * See the GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. using GFlow;
  20. using GtkFlow;
  21. using Gtk;
  22. public abstract class GtkFlowTest.TestApp : GLib.Object
  23. {
  24. public delegate bool Test ();
  25. public Gtk.Window window { get; set; }
  26. public Gtk.Box action_area { get; set; default = new Gtk.Box (Gtk.Orientation.VERTICAL, 10); }
  27. public Gtk.Label result { get; set; }
  28. public Gtk.Button brun;
  29. public GLib.List<void*> tests = new GLib.List<void*> ();
  30. public bool @continue { get; set; default = true; }
  31. public string test_prefix { get; set; default = "/gtkflow"; }
  32. public bool status { get; set; default = true; }
  33. public TestApp ()
  34. {
  35. window = new Gtk.Window (Gtk.WindowType.TOPLEVEL);
  36. result = new Gtk.Label ("Running Tests: " + test_prefix);
  37. result.label = "RUNNING";
  38. action_area.pack_end (result);
  39. brun = new Gtk.Button ();
  40. brun.label = "Run";
  41. action_area.pack_end (brun);
  42. window.add (action_area);
  43. window.title = "GtkFlow Unit Tests";
  44. window.destroy.connect (()=>{
  45. Gtk.main_quit ();
  46. });
  47. brun.clicked.connect (()=>{
  48. if (execute () != 0)
  49. status = false;
  50. else
  51. status = true;
  52. });
  53. }
  54. public void run ()
  55. {
  56. window.show_all ();
  57. Timeout.add(1000,()=>{brun.clicked(); return false;});
  58. Gtk.main ();
  59. }
  60. public abstract int execute ();
  61. public bool end_test ()
  62. {
  63. if (status == true)
  64. result.label = "PASS";
  65. else
  66. GLib.message ("Test Result: "+result.label);
  67. return false;
  68. }
  69. }