Permalink
Browse files

Toolbar unit test + fixes

  • Loading branch information...
feragon committed Jul 4, 2016
1 parent 7b491e3 commit 43dc089e6f4205fef56aa460ea968f7820fd76f0
View
@@ -14,7 +14,7 @@ Toolbar::~Toolbar() {
delete ui;
}
void Toolbar::addTab(const char* name, QWidget* page) {
void Toolbar::addTab(const char* name, ToolbarTab* page) {
ui->tabWidget->addTab(page, tr(name));
}
View
@@ -12,7 +12,7 @@ class Toolbar : public QDockWidget {
Toolbar(QWidget *parent = 0);
~Toolbar();
void addTab(const char* name, QWidget* page);
void addTab(const char* name, ToolbarTab* page);
void removeTab(QWidget* page);
ToolbarTab* tabByName(const char* name);
@@ -69,7 +69,7 @@ QPushButton *ToolbarTab::buttonByText(QGroupBox* groupBox, const char* buttonTex
auto nbButtons = groupBox->layout()->count();
for (int i = 0; i < nbButtons; i++) {
auto button = dynamic_cast<QPushButton*>(groupBox->layout()->itemAt(i));
auto button = dynamic_cast<QPushButton*>(groupBox->layout()->itemAt(i)->widget());
if(button && button->text() == buttonText) {
return button;
@@ -85,4 +85,10 @@ void ToolbarTab::removeGroup(QGroupBox *group) {
}
delete group;
}
void ToolbarTab::removeButton(QPushButton *button) {
if(button != nullptr) {
delete button;
}
}
@@ -26,6 +26,7 @@ class ToolbarTab : public QWidget {
QPushButton* buttonByText(QGroupBox* groupBox, const char* buttonText);
void removeGroup(QGroupBox* group);
void removeButton(QPushButton* button);
private:
Ui::ToolbarTab* ui;
View
@@ -47,6 +47,10 @@ if(WITH_QTUI)
${hdrs}
ui/testcommandline.h
ui/clicommandtest.h)
set(src
${src}
ui/testtoolbar.cpp)
include_directories("${CMAKE_SOURCE_DIR}/lcUI")
endif(WITH_QTUI)
@@ -0,0 +1,57 @@
#include <gtest/gtest.h>
#include <QApplication>
#include <widgets/toolbar.h>
#include <widgets/toolbartab.h>
static int argc = 0;
static char** argv = NULL;
TEST(ToolbarTest, TabOperations) {
QApplication app(argc, argv);
Toolbar toolbar;
toolbar.addTab("Test", new ToolbarTab());
auto tab = toolbar.tabByName("Test");
EXPECT_NE(nullptr, tab);
toolbar.removeTab(tab);
tab = toolbar.tabByName("Test");
EXPECT_EQ(nullptr, tab);
}
TEST(ToolbarTest, GroupOperations) {
QApplication app(argc, argv);
ToolbarTab toolbarTab;
toolbarTab.addGroup("Test");
auto group = toolbarTab.groupByName("Test");
EXPECT_NE(nullptr, group);
toolbarTab.removeGroup(group);
group = toolbarTab.groupByName("Test");
EXPECT_EQ(nullptr, group);
}
TEST(ToolbarTest, ButtonOperations) {
QApplication app(argc, argv);
ToolbarTab toolbarTab;
toolbarTab.addGroup("Test");
auto group = toolbarTab.groupByName("Test");
toolbarTab.addButtonStr(group, "TestButton");
auto button = toolbarTab.buttonByText(group, "TestButton");
EXPECT_NE(nullptr, button);
toolbarTab.removeButton(button);
button = toolbarTab.buttonByText(group, "TestButton");
EXPECT_EQ(nullptr, button);
}

0 comments on commit 43dc089

Please sign in to comment.