gflow-node-test.vala 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. var s = new GFlow.SimpleSink.with_type (typeof(int));
  25. var n = new GFlow.SimpleNode();
  26. assert (n.has_sink(s) == false);
  27. n.add_sink(s);
  28. assert (n.has_sink(s) == true);
  29. n.remove_sink(s);
  30. assert (n.has_sink(s) == false);
  31. } catch (GFlow.NodeError e) {
  32. assert (false);
  33. }
  34. });
  35. Test.add_func ("/gflow/node/source",
  36. () => {
  37. try {
  38. var s = new GFlow.SimpleSource.with_type (typeof(int));
  39. var n = new GFlow.SimpleNode();
  40. try {
  41. s.set_value(1);
  42. } catch {
  43. assert_not_reached();
  44. }
  45. assert (n.has_source(s) == false);
  46. n.add_source(s);
  47. assert (n.has_source(s) == true);
  48. n.remove_source(s);
  49. assert (n.has_source(s) == false);
  50. } catch (GFlow.NodeError e) {
  51. assert (false);
  52. }
  53. });
  54. Test.add_func ("/gflow/node/dock",
  55. () => {
  56. try {
  57. var si = new GFlow.SimpleSink (typeof(int));
  58. var so = new GFlow.SimpleSource (typeof(int));
  59. try {
  60. so.set_value(1);
  61. } catch {
  62. assert_not_reached();
  63. }
  64. var n = new GFlow.SimpleNode ();
  65. assert (n.has_dock(si) == false);
  66. assert (n.has_dock(so) == false);
  67. n.add_source(so);
  68. n.add_sink(si);
  69. assert (n.has_dock(si) == true);
  70. assert (n.has_dock(so) == true);
  71. n.remove_source(so);
  72. n.remove_sink(si);
  73. assert (n.has_dock(si) == false);
  74. assert (n.has_dock(so) == false);
  75. } catch (GFlow.NodeError e) {
  76. assert (false);
  77. }
  78. });
  79. Test.add_func ("/gflow/node/get_dock",
  80. () => {
  81. try {
  82. var si = new GFlow.SimpleSink (typeof(int));
  83. var so = new GFlow.SimpleSource (typeof(int));
  84. si.name = "foo";
  85. so.name = "bar";
  86. try {
  87. so.set_value(1);
  88. } catch {
  89. assert_not_reached();
  90. }
  91. var n = new GFlow.SimpleNode();
  92. assert(n.get_dock("foo") == null);
  93. assert(n.get_dock("bar") == null);
  94. n.add_sink(si);
  95. n.add_source(so);
  96. assert(n.get_dock("foo") == si);
  97. assert(n.get_dock("bar") == so);
  98. n.remove_source(so);
  99. n.remove_sink(si);
  100. assert(n.get_dock("foo") == null);
  101. assert(n.get_dock("bar") == null);
  102. } catch (GFlow.NodeError e) {
  103. assert (false);
  104. }
  105. });
  106. }
  107. }