aRts audio server
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
3.9KB

  1. /*
  2. Copyright (C) 2000 Stefan Westerfeld stefan@space.twc.de
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  14. Permission is also granted to link this program with the Qt
  15. library, treating Qt like a library that normally accompanies the
  16. operating system kernel, whether or not that is in fact the case.
  17. */
  18. #include "value.h"
  19. #include "connect.h"
  20. #include "test.h"
  21. #include <iostream.h>
  22. #include <stdio.h>
  23. using namespace std;
  24. using namespace Arts;
  25. struct TestChangeNotify : public TestCase
  26. {
  27. TESTCASE(TestChangeNotify);
  28. Arts::Dispatcher dispatcher;
  29. float zero, three, four;
  30. void setUp()
  31. {
  32. zero = 0.0;
  33. three = 3.0;
  34. four = 4.0;
  35. }
  36. void process()
  37. {
  38. dispatcher.ioManager()->processOneEvent(false);
  39. }
  40. TEST(floatValue)
  41. {
  42. FloatValue f;
  43. testEquals(zero, f.value());
  44. f.value(three);
  45. testEquals(three, f.value());
  46. }
  47. TEST(stringValue)
  48. {
  49. StringValue s;
  50. testEquals("",s.value());
  51. s.value("hello");
  52. testEquals("hello", s.value());
  53. }
  54. TEST(floatNotify)
  55. {
  56. FloatValue f1, f2;
  57. connect(f1,"value_changed",f2,"value");
  58. f1.value(three);
  59. process();
  60. testEquals(three, f2.value());
  61. }
  62. TEST(floatMultiNotify)
  63. {
  64. FloatValue f1, f2, f3;
  65. connect(f1,"value_changed",f2,"value");
  66. connect(f1,"value_changed",f3,"value");
  67. f1.value(three);
  68. process();
  69. testEquals(three, f2.value());
  70. testEquals(three, f3.value());
  71. }
  72. TEST(floatCrossNotify)
  73. {
  74. FloatValue f1, f2;
  75. connect(f1,"value_changed",f2,"value");
  76. connect(f2,"value_changed",f1,"value");
  77. f1.value(three);
  78. process();
  79. testEquals(three, f1.value());
  80. testEquals(three, f2.value());
  81. f2.value(four);
  82. process();
  83. testEquals(four, f1.value());
  84. testEquals(four, f2.value());
  85. }
  86. TEST(stringNotify)
  87. {
  88. StringValue s1, s2;
  89. connect(s1,"value_changed",s2,"value");
  90. s1.value("hello");
  91. process();
  92. testEquals("hello", s2.value());
  93. }
  94. TEST(stringMultiNotify)
  95. {
  96. StringValue s1, s2, s3;
  97. connect(s1,"value_changed",s2,"value");
  98. connect(s1,"value_changed",s3,"value");
  99. s1.value("hello");
  100. process();
  101. testEquals("hello", s2.value());
  102. testEquals("hello", s3.value());
  103. }
  104. TEST(stringCrossNotify)
  105. {
  106. StringValue s1, s2;
  107. connect(s1,"value_changed",s2,"value");
  108. connect(s2,"value_changed",s1,"value");
  109. s1.value("world");
  110. process();
  111. testEquals("world", s1.value());
  112. testEquals("world", s2.value());
  113. s2.value("test");
  114. process();
  115. testEquals("test", s1.value());
  116. testEquals("test", s2.value());
  117. }
  118. TEST(floatSenderToValue1)
  119. {
  120. FloatSender sender;
  121. FloatValue f;
  122. connect(sender,"outstream",f,"value");
  123. vector<float> data;
  124. data.push_back(three);
  125. sender.send(data);
  126. process();
  127. testEquals(three,f.value());
  128. }
  129. TEST(floatSenderToValue2)
  130. {
  131. FloatSender sender;
  132. FloatValue f;
  133. connect(sender,"outstream",f,"value");
  134. vector<float> data;
  135. data.push_back(three);
  136. data.push_back(four);
  137. sender.send(data);
  138. process();
  139. testEquals(four,f.value());
  140. }
  141. TEST(myEnumNotify)
  142. {
  143. MyEnumValue e1, e2;
  144. connect(e1,"value_changed",e2,"value");
  145. testEquals(meIdle, e1.value());
  146. testEquals(meIdle, e2.value());
  147. e1.value(meHelloWorld);
  148. process();
  149. testEquals(meHelloWorld, e1.value());
  150. testEquals(meHelloWorld, e2.value());
  151. }
  152. };
  153. TESTMAIN(TestChangeNotify);