gflow-node-test.vala 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* GFlowTest
  2. *
  3. * Copyright (C) 2015 Daniel Espinosa <esodan@gmail.com>
  4. *
  5. * librescl is free software: you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * librescl is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. * See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. using GFlow;
  19. public class GFlowTest.NodeTest {
  20. public static void add_tests () {
  21. Test.add_func ("/gflow/node/sink",
  22. () => {
  23. try {
  24. Value initial = Value(typeof(int));
  25. initial.set_int (1);
  26. var s = new GFlow.SimpleSink (initial);
  27. var n = new GFlow.SimpleNode ();
  28. assert (n.has_sink(s) == false);
  29. n.add_sink(s);
  30. assert (n.has_sink(s) == true);
  31. n.remove_sink(s);
  32. assert (n.has_sink(s) == false);
  33. } catch (GFlow.NodeError e) {
  34. assert (false);
  35. }
  36. });
  37. Test.add_func ("/gflow/node/source",
  38. () => {
  39. try {
  40. Value initial = Value(typeof(int));
  41. initial.set_int (1);
  42. var s = new GFlow.SimpleSource (initial);
  43. var n = new GFlow.SimpleNode ();
  44. assert (n.has_source(s) == false);
  45. n.add_source(s);
  46. assert (n.has_source(s) == true);
  47. n.remove_source(s);
  48. assert (n.has_source(s) == false);
  49. } catch (GFlow.NodeError e) {
  50. assert (false);
  51. }
  52. });
  53. Test.add_func ("/gflow/node/dock",
  54. () => {
  55. try {
  56. Value si_initial = Value(typeof(int));
  57. si_initial.set_int (1);
  58. var si = new GFlow.SimpleSink (si_initial);
  59. Value so_initial = Value(typeof(int));
  60. so_initial.set_int (1);
  61. var so = new GFlow.SimpleSource (so_initial);
  62. var n = new GFlow.SimpleNode ();
  63. assert (n.has_dock(si) == false);
  64. assert (n.has_dock(so) == false);
  65. n.add_source(so);
  66. n.add_sink(si);
  67. assert (n.has_dock(si) == true);
  68. assert (n.has_dock(so) == true);
  69. n.remove_source(so);
  70. n.remove_sink(si);
  71. assert (n.has_dock(si) == false);
  72. assert (n.has_dock(so) == false);
  73. } catch (GFlow.NodeError e) {
  74. assert (false);
  75. }
  76. });
  77. Test.add_func ("/gflow/node/get_dock",
  78. () => {
  79. try {
  80. Value si_initial = Value(typeof(int));
  81. si_initial.set_int (1);
  82. var si = new GFlow.SimpleSink (si_initial);
  83. si.name = "foo";
  84. Value so_initial = Value(typeof(int));
  85. so_initial.set_int (1);
  86. var so = new GFlow.SimpleSource (so_initial);
  87. so.name = "bar";
  88. var n = new GFlow.SimpleNode();
  89. assert(n.get_dock("foo") == null);
  90. assert(n.get_dock("bar") == null);
  91. n.add_sink(si);
  92. n.add_source(so);
  93. assert(n.get_dock("foo") == si);
  94. assert(n.get_dock("bar") == so);
  95. n.remove_source(so);
  96. n.remove_sink(si);
  97. assert(n.get_dock("foo") == null);
  98. assert(n.get_dock("bar") == null);
  99. } catch (GFlow.NodeError e) {
  100. assert (false);
  101. }
  102. });
  103. }
  104. }