ctkAddRemoveComboBoxTest1.cpp 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QSignalSpy>
  16. // CTK includes
  17. #include "ctkAddRemoveComboBox.h"
  18. #include "ctkTestApplication.h"
  19. // STD includes
  20. #include <cstdlib>
  21. #include <iostream>
  22. //-----------------------------------------------------------------------------
  23. QCTK_DECLARE_TEST(ctkAddRemoveComboBoxTest1)
  24. {
  25. ctkAddRemoveComboBox ctkObject;
  26. int currentCount = ctkObject.count();
  27. if (currentCount != 0)
  28. {
  29. ctkObject.printAdditionalInfo();
  30. std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
  31. QCTK_EXIT_TEST(EXIT_FAILURE);
  32. }
  33. // Add items
  34. ctkObject.addItem("Item1");
  35. ctkObject.addItem("Item2");
  36. ctkObject.addItem("Item3");
  37. currentCount = ctkObject.count();
  38. if (currentCount != 3)
  39. {
  40. ctkObject.printAdditionalInfo();
  41. std::cerr << __LINE__ << " - Error in count() - Expected: 3, current:" << currentCount << std::endl;
  42. QCTK_EXIT_TEST(EXIT_FAILURE);
  43. }
  44. if (ctkObject.itemText(0) != "Item1" ||
  45. ctkObject.itemText(1) != "Item2" ||
  46. ctkObject.itemText(2) != "Item3")
  47. {
  48. ctkObject.printAdditionalInfo();
  49. std::cerr << __LINE__ << " - Error in itemText()" << std::endl
  50. << " Expected items [Item1, Item2, Item3]" << std::endl
  51. << " Current items [" << qPrintable(ctkObject.itemText(0)) << ", "
  52. << qPrintable(ctkObject.itemText(1)) << ", "
  53. << qPrintable(ctkObject.itemText(2)) << "]" << std::endl;
  54. QCTK_EXIT_TEST(EXIT_FAILURE);
  55. }
  56. ctkObject.removeItem(1);
  57. currentCount = ctkObject.count();
  58. if (currentCount != 2)
  59. {
  60. ctkObject.printAdditionalInfo();
  61. std::cerr << __LINE__ << " - Error in count() - Expected: 2, current:" << currentCount << std::endl;
  62. QCTK_EXIT_TEST(EXIT_FAILURE);
  63. }
  64. if (ctkObject.itemText(0) != "Item1" ||
  65. ctkObject.itemText(1) != "Item3")
  66. {
  67. ctkObject.printAdditionalInfo();
  68. std::cerr << __LINE__ << " - Error in itemText()" << std::endl
  69. << " Expected items [Item1, Item3]" << std::endl
  70. << " Current items [" << qPrintable(ctkObject.itemText(0)) << ", "
  71. << qPrintable(ctkObject.itemText(1)) << "]" << std::endl;
  72. QCTK_EXIT_TEST(EXIT_FAILURE);
  73. }
  74. ctkObject.addItem("Item4");
  75. currentCount = ctkObject.count();
  76. if (currentCount != 3)
  77. {
  78. ctkObject.printAdditionalInfo();
  79. std::cerr << __LINE__ << " - Error in count() - Expected: 3, current:" << currentCount << std::endl;
  80. QCTK_EXIT_TEST(EXIT_FAILURE);
  81. }
  82. if (ctkObject.itemText(0) != "Item1" ||
  83. ctkObject.itemText(1) != "Item3" ||
  84. ctkObject.itemText(2) != "Item4")
  85. {
  86. ctkObject.printAdditionalInfo();
  87. std::cerr << __LINE__ << " - Error in itemText()" << std::endl
  88. << " Expected items [Item1, Item3, Item4]" << std::endl
  89. << " Current items [" << qPrintable(ctkObject.itemText(0)) << ", "
  90. << qPrintable(ctkObject.itemText(1)) << ", "
  91. << qPrintable(ctkObject.itemText(2)) << "]" << std::endl;
  92. QCTK_EXIT_TEST(EXIT_FAILURE);
  93. }
  94. ctkObject.clear();
  95. currentCount = ctkObject.count();
  96. if (currentCount != 0)
  97. {
  98. ctkObject.printAdditionalInfo();
  99. std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
  100. QCTK_EXIT_TEST(EXIT_FAILURE);
  101. }
  102. ctkObject.addItem("Item5");
  103. currentCount = ctkObject.count();
  104. if (currentCount != 1)
  105. {
  106. ctkObject.printAdditionalInfo();
  107. std::cerr << __LINE__ << " - Error in count() - Expected: 1, current:" << currentCount << std::endl;
  108. QCTK_EXIT_TEST(EXIT_FAILURE);
  109. }
  110. if (ctkObject.itemText(0) != "Item5")
  111. {
  112. ctkObject.printAdditionalInfo();
  113. std::cerr << __LINE__ << " - Error in itemText()" << std::endl
  114. << " Expected items [Item5]" << std::endl
  115. << " Current items [" << qPrintable(ctkObject.itemText(0)) << "]" << std::endl;
  116. QCTK_EXIT_TEST(EXIT_FAILURE);
  117. }
  118. ctkObject.clear();
  119. currentCount = ctkObject.count();
  120. if (currentCount != 0)
  121. {
  122. ctkObject.printAdditionalInfo();
  123. std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
  124. QCTK_EXIT_TEST(EXIT_FAILURE);
  125. }
  126. QCTK_EXIT_TEST(EXIT_SUCCESS);
  127. }
  128. QCTK_RUN_TEST(ctkAddRemoveComboBoxTest1);