gflow-source-test.vala 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* -*- Mode: vala; indent-tabs-mode: nil; c-basic-offset: 2; tab-width: 2 -*- */
  2. /* GFlowTest
  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. public class GFlowTest.Source : GFlow.SimpleSource
  21. {
  22. public Source () {
  23. base.with_type (typeof(bool));
  24. }
  25. }
  26. public class GFlowTest.SourceTest
  27. {
  28. public static void add_tests ()
  29. {
  30. Test.add_func ("/gflow/source",
  31. () => {
  32. var src = new GFlow.SimpleSource.with_type (typeof(int));
  33. try {
  34. src.set_value(0);
  35. } catch {
  36. assert_not_reached();
  37. }
  38. assert (!src.is_linked ());
  39. });
  40. Test.add_func ("/gflow/source/link",
  41. () => {
  42. var src = new GFlow.SimpleSource.with_type (typeof(int));
  43. try{
  44. src.set_value(0);
  45. } catch {
  46. assert_not_reached();
  47. }
  48. var s = new GFlow.SimpleSink.with_type (typeof(bool));
  49. var s1 = new GFlow.SimpleSink.with_type (typeof(int));
  50. var s2 = new GFlow.SimpleSink.with_type (typeof(int));
  51. assert (!src.is_linked ());
  52. bool fail = true;
  53. try { src.link (s); } catch { fail = false; }
  54. if (fail) assert_not_reached ();
  55. try {
  56. assert (!s1.is_linked ());
  57. fail = true;
  58. s1.linked.connect (()=>{
  59. fail = false;
  60. });
  61. src.link (s1);
  62. if (fail) assert_not_reached ();
  63. fail = true;
  64. s2.linked.connect (()=>{
  65. fail = false;
  66. });
  67. src.link (s2);
  68. if (fail) assert_not_reached ();
  69. try {
  70. src.set_value(20);
  71. } catch {
  72. assert_not_reached();
  73. }
  74. // assert (((int) s1.val.nth_data(0)) == 20);
  75. // assert (((int) s2.val.nth_data(0)) == 20);
  76. } catch { assert_not_reached (); }
  77. });
  78. Test.add_func ("/gflow/source/derived",
  79. () => {
  80. var src = new GFlowTest.Source ();
  81. assert (!src.is_linked ());
  82. });
  83. }
  84. }