ctkAddRemoveComboBoxTest1.cpp 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. // Qt includes
  11. #include <QSignalSpy>
  12. // CTK includes
  13. #include "ctkAddRemoveComboBox.h"
  14. #include "ctkTestApplication.h"
  15. // STD includes
  16. #include <cstdlib>
  17. #include <iostream>
  18. //-----------------------------------------------------------------------------
  19. QCTK_DECLARE_TEST(ctkAddRemoveComboBoxTest1)
  20. {
  21. ctkAddRemoveComboBox ctkObject;
  22. int currentCount = ctkObject.count();
  23. if (currentCount != 0)
  24. {
  25. ctkObject.printAdditionalInfo();
  26. std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
  27. QCTK_EXIT_TEST(EXIT_FAILURE);
  28. }
  29. // Add items
  30. ctkObject.addItem("Item1");
  31. ctkObject.addItem("Item2");
  32. ctkObject.addItem("Item3");
  33. currentCount = ctkObject.count();
  34. if (currentCount != 3)
  35. {
  36. ctkObject.printAdditionalInfo();
  37. std::cerr << __LINE__ << " - Error in count() - Expected: 3, current:" << currentCount << std::endl;
  38. QCTK_EXIT_TEST(EXIT_FAILURE);
  39. }
  40. if (ctkObject.itemText(0) != "Item1" ||
  41. ctkObject.itemText(1) != "Item2" ||
  42. ctkObject.itemText(2) != "Item3")
  43. {
  44. ctkObject.printAdditionalInfo();
  45. std::cerr << __LINE__ << " - Error in itemText()" << std::endl
  46. << " Expected items [Item1, Item2, Item3]" << std::endl
  47. << " Current items [" << qPrintable(ctkObject.itemText(0)) << ", "
  48. << qPrintable(ctkObject.itemText(1)) << ", "
  49. << qPrintable(ctkObject.itemText(2)) << "]" << std::endl;
  50. QCTK_EXIT_TEST(EXIT_FAILURE);
  51. }
  52. ctkObject.removeItem(1);
  53. currentCount = ctkObject.count();
  54. if (currentCount != 2)
  55. {
  56. ctkObject.printAdditionalInfo();
  57. std::cerr << __LINE__ << " - Error in count() - Expected: 2, current:" << currentCount << std::endl;
  58. QCTK_EXIT_TEST(EXIT_FAILURE);
  59. }
  60. if (ctkObject.itemText(0) != "Item1" ||
  61. ctkObject.itemText(1) != "Item3")
  62. {
  63. ctkObject.printAdditionalInfo();
  64. std::cerr << __LINE__ << " - Error in itemText()" << std::endl
  65. << " Expected items [Item1, Item3]" << std::endl
  66. << " Current items [" << qPrintable(ctkObject.itemText(0)) << ", "
  67. << qPrintable(ctkObject.itemText(1)) << "]" << std::endl;
  68. QCTK_EXIT_TEST(EXIT_FAILURE);
  69. }
  70. ctkObject.addItem("Item4");
  71. currentCount = ctkObject.count();
  72. if (currentCount != 3)
  73. {
  74. ctkObject.printAdditionalInfo();
  75. std::cerr << __LINE__ << " - Error in count() - Expected: 3, current:" << currentCount << std::endl;
  76. QCTK_EXIT_TEST(EXIT_FAILURE);
  77. }
  78. if (ctkObject.itemText(0) != "Item1" ||
  79. ctkObject.itemText(1) != "Item3" ||
  80. ctkObject.itemText(2) != "Item4")
  81. {
  82. ctkObject.printAdditionalInfo();
  83. std::cerr << __LINE__ << " - Error in itemText()" << std::endl
  84. << " Expected items [Item1, Item3, Item4]" << std::endl
  85. << " Current items [" << qPrintable(ctkObject.itemText(0)) << ", "
  86. << qPrintable(ctkObject.itemText(1)) << ", "
  87. << qPrintable(ctkObject.itemText(2)) << "]" << std::endl;
  88. QCTK_EXIT_TEST(EXIT_FAILURE);
  89. }
  90. ctkObject.clear();
  91. currentCount = ctkObject.count();
  92. if (currentCount != 0)
  93. {
  94. ctkObject.printAdditionalInfo();
  95. std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
  96. QCTK_EXIT_TEST(EXIT_FAILURE);
  97. }
  98. ctkObject.addItem("Item5");
  99. currentCount = ctkObject.count();
  100. if (currentCount != 1)
  101. {
  102. ctkObject.printAdditionalInfo();
  103. std::cerr << __LINE__ << " - Error in count() - Expected: 1, current:" << currentCount << std::endl;
  104. QCTK_EXIT_TEST(EXIT_FAILURE);
  105. }
  106. if (ctkObject.itemText(0) != "Item5")
  107. {
  108. ctkObject.printAdditionalInfo();
  109. std::cerr << __LINE__ << " - Error in itemText()" << std::endl
  110. << " Expected items [Item5]" << std::endl
  111. << " Current items [" << qPrintable(ctkObject.itemText(0)) << "]" << std::endl;
  112. QCTK_EXIT_TEST(EXIT_FAILURE);
  113. }
  114. ctkObject.clear();
  115. currentCount = ctkObject.count();
  116. if (currentCount != 0)
  117. {
  118. ctkObject.printAdditionalInfo();
  119. std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
  120. QCTK_EXIT_TEST(EXIT_FAILURE);
  121. }
  122. QCTK_EXIT_TEST(EXIT_SUCCESS);
  123. }
  124. QCTK_RUN_TEST(ctkAddRemoveComboBoxTest1);