Skip to content

Commit 2eadf0d

Browse files
committed
Improve test for ctkComboBox
1 parent 422a1bb commit 2eadf0d

File tree

1 file changed

+68
-2
lines changed

1 file changed

+68
-2
lines changed

Libs/Widgets/Testing/Cpp/ctkComboBoxTest1.cpp

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
// Qt includes
2222
#include <QApplication>
23+
#include <QTimer>
2324

2425
// CTK includes
2526
#include "ctkComboBox.h"
@@ -33,8 +34,73 @@ int ctkComboBoxTest1(int argc, char * argv [] )
3334
{
3435
QApplication app(argc, argv);
3536

36-
ctkComboBox ctkObject;
37+
ctkComboBox comboBox(0);
38+
if (!comboBox.defaultText().isEmpty())
39+
{
40+
std::cerr << "non empty default defaultText" << std::endl;
41+
return EXIT_FAILURE;
42+
}
43+
comboBox.setDefaultText("Select...");
44+
if (comboBox.defaultText() != "Select...")
45+
{
46+
std::cerr << "ctkComboBox::setDefaultText() failed"
47+
<< comboBox.defaultText().toStdString() << std::endl;
48+
return EXIT_FAILURE;
49+
}
50+
if (comboBox.currentText() == "Select...")
51+
{
52+
std::cerr << "ctkComboBox::setDefaultText() failed" << std::endl;
53+
return EXIT_FAILURE;
54+
}
55+
QIcon icon = comboBox.style()->standardIcon(QStyle::SP_MessageBoxQuestion);
56+
comboBox.setDefaultIcon(icon);
57+
if (comboBox.defaultIcon().pixmap(20).toImage() !=
58+
icon.pixmap(20).toImage())
59+
{
60+
std::cerr << "ctkComboBox::setDefaultIcon() failed" << std::endl;
61+
return EXIT_FAILURE;
62+
}
63+
if (comboBox.isDefaultForced())
64+
{
65+
std::cerr << "default of ctkComboBox::isDefaultForced() failed" << std::endl;
66+
return EXIT_FAILURE;
67+
}
68+
comboBox.forceDefault(true);
69+
if (!comboBox.isDefaultForced())
70+
{
71+
std::cerr << "ctkComboBox::setDefaultForced() failed" << std::endl;
72+
return EXIT_FAILURE;
73+
}
74+
if (comboBox.elideMode() != Qt::ElideNone)
75+
{
76+
std::cerr << "Wrong default elide mode" << std::endl;
77+
return EXIT_FAILURE;
78+
}
79+
comboBox.setElideMode(Qt::ElideRight);
80+
if (comboBox.elideMode() != Qt::ElideRight)
81+
{
82+
std::cerr << "ctkComboBox::setElideMode() failed" << std::endl;
83+
return EXIT_FAILURE;
84+
}
85+
comboBox.addItem("Item Item Item Item Item Item Item Item 1");
86+
comboBox.addItem("Item Item Item Item Item Item Item Item 2");
87+
comboBox.addItem("Item Item Item Item Item Item Item Item 3");
88+
// adding items shouldn't change anything to the combobox current text
89+
if (comboBox.currentIndex() != 0 ||
90+
comboBox.currentText() != "Item Item Item Item Item Item Item Item 1")
91+
{
92+
std::cerr << "ctkComboBox::addItem failed:"
93+
<< comboBox.currentIndex() << " "
94+
<< comboBox.currentText().toStdString() << std::endl;
95+
return EXIT_FAILURE;
96+
}
97+
comboBox.show();
3798

38-
return EXIT_SUCCESS;
99+
if (argc < 2 || QString(argv[1]) != "-I" )
100+
{
101+
QTimer::singleShot(200, &app, SLOT(quit()));
102+
}
103+
104+
return app.exec();
39105
}
40106

0 commit comments

Comments
 (0)