123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- /*=========================================================================
- Library: CTK
- Copyright (c) Kitware Inc.
- All rights reserved.
- Distributed under a BSD License. See LICENSE.txt file.
- This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
- the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- See the above copyright notice for more information.
- =========================================================================*/
- // Qt includes
- #include <QSignalSpy>
- // CTK includes
- #include "ctkAddRemoveComboBox.h"
- #include "ctkTestApplication.h"
- // STD includes
- #include <cstdlib>
- #include <iostream>
- //-----------------------------------------------------------------------------
- QCTK_DECLARE_TEST(ctkAddRemoveComboBoxTest1)
- {
- ctkAddRemoveComboBox ctkObject;
-
- int currentCount = ctkObject.count();
- if (currentCount != 0)
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- // Add items
- ctkObject.addItem("Item1");
- ctkObject.addItem("Item2");
- ctkObject.addItem("Item3");
- currentCount = ctkObject.count();
- if (currentCount != 3)
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in count() - Expected: 3, current:" << currentCount << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- if (ctkObject.itemText(0) != "Item1" ||
- ctkObject.itemText(1) != "Item2" ||
- ctkObject.itemText(2) != "Item3")
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in itemText()" << std::endl
- << " Expected items [Item1, Item2, Item3]" << std::endl
- << " Current items [" << qPrintable(ctkObject.itemText(0)) << ", "
- << qPrintable(ctkObject.itemText(1)) << ", "
- << qPrintable(ctkObject.itemText(2)) << "]" << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- ctkObject.removeItem(1);
- currentCount = ctkObject.count();
- if (currentCount != 2)
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in count() - Expected: 2, current:" << currentCount << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- if (ctkObject.itemText(0) != "Item1" ||
- ctkObject.itemText(1) != "Item3")
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in itemText()" << std::endl
- << " Expected items [Item1, Item3]" << std::endl
- << " Current items [" << qPrintable(ctkObject.itemText(0)) << ", "
- << qPrintable(ctkObject.itemText(1)) << "]" << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- ctkObject.addItem("Item4");
- currentCount = ctkObject.count();
- if (currentCount != 3)
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in count() - Expected: 3, current:" << currentCount << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- if (ctkObject.itemText(0) != "Item1" ||
- ctkObject.itemText(1) != "Item3" ||
- ctkObject.itemText(2) != "Item4")
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in itemText()" << std::endl
- << " Expected items [Item1, Item3, Item4]" << std::endl
- << " Current items [" << qPrintable(ctkObject.itemText(0)) << ", "
- << qPrintable(ctkObject.itemText(1)) << ", "
- << qPrintable(ctkObject.itemText(2)) << "]" << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- ctkObject.clear();
- currentCount = ctkObject.count();
- if (currentCount != 0)
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- ctkObject.addItem("Item5");
- currentCount = ctkObject.count();
- if (currentCount != 1)
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in count() - Expected: 1, current:" << currentCount << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- if (ctkObject.itemText(0) != "Item5")
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in itemText()" << std::endl
- << " Expected items [Item5]" << std::endl
- << " Current items [" << qPrintable(ctkObject.itemText(0)) << "]" << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
- ctkObject.clear();
- currentCount = ctkObject.count();
- if (currentCount != 0)
- {
- ctkObject.printAdditionalInfo();
- std::cerr << __LINE__ << " - Error in count() - Expected: 0, current:" << currentCount << std::endl;
- QCTK_EXIT_TEST(EXIT_FAILURE);
- }
-
- QCTK_EXIT_TEST(EXIT_SUCCESS);
- }
- QCTK_RUN_TEST(ctkAddRemoveComboBoxTest1);
|