68 lines
2.2 KiB
C++
68 lines
2.2 KiB
C++
|
|
#include <gtest/gtest.h>
|
||
|
|
|
||
|
|
#include <QComboBox>
|
||
|
|
|
||
|
|
#include "ConnectionConfig.h"
|
||
|
|
#include "PrintTo_Qt.h"
|
||
|
|
#include "SslModeModel.h"
|
||
|
|
|
||
|
|
TEST(SslModeModelTest, SelectedModesKeepTheirTextAndCanonicalValue)
|
||
|
|
{
|
||
|
|
SslModeModel model;
|
||
|
|
QComboBox combo;
|
||
|
|
combo.setModel(&model);
|
||
|
|
|
||
|
|
ASSERT_FALSE(combo.isEditable());
|
||
|
|
const QStringList modes = {"disable", "allow", "prefer", "require", "verify-ca", "verify-full"};
|
||
|
|
ASSERT_EQ(combo.count(), modes.size() + 1);
|
||
|
|
|
||
|
|
for (const auto &mode : modes) {
|
||
|
|
SCOPED_TRACE(mode.toStdString());
|
||
|
|
auto index = combo.findData(mode);
|
||
|
|
ASSERT_GT(index, 0);
|
||
|
|
combo.setCurrentIndex(index);
|
||
|
|
EXPECT_EQ(combo.currentText(), mode);
|
||
|
|
EXPECT_EQ(combo.currentData().toString(), mode);
|
||
|
|
|
||
|
|
ConnectionConfig config;
|
||
|
|
config.setParameter("sslmode", combo.currentData().toString());
|
||
|
|
EXPECT_EQ(config.getParameter("sslmode"), mode);
|
||
|
|
EXPECT_TRUE(config.connectionString().contains("sslmode=" + mode));
|
||
|
|
|
||
|
|
QComboBox reopened;
|
||
|
|
reopened.setModel(&model);
|
||
|
|
reopened.setCurrentIndex(reopened.findData(config.getParameter("sslmode")));
|
||
|
|
EXPECT_EQ(reopened.currentText(), mode);
|
||
|
|
EXPECT_EQ(reopened.currentData().toString(), mode);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(SslModeModelTest, DefaultClearsAnExplicitMode)
|
||
|
|
{
|
||
|
|
SslModeModel model;
|
||
|
|
QComboBox combo;
|
||
|
|
combo.setModel(&model);
|
||
|
|
|
||
|
|
EXPECT_EQ(combo.currentText(), QStringLiteral("Default"));
|
||
|
|
EXPECT_EQ(combo.currentData().toString(), QString());
|
||
|
|
EXPECT_EQ(combo.findData(QString()), 0);
|
||
|
|
|
||
|
|
ConnectionConfig config;
|
||
|
|
config.setParameter("sslmode", "require");
|
||
|
|
combo.setCurrentIndex(combo.findData(QStringLiteral("require")));
|
||
|
|
combo.setCurrentIndex(combo.findData(QString()));
|
||
|
|
config.setParameter("sslmode", combo.currentData().toString());
|
||
|
|
|
||
|
|
EXPECT_TRUE(config.getParameter("sslmode").isEmpty());
|
||
|
|
EXPECT_EQ(config.getParameters().count("sslmode"), 0);
|
||
|
|
EXPECT_FALSE(config.connectionString().contains("sslmode="));
|
||
|
|
}
|
||
|
|
|
||
|
|
TEST(SslModeModelTest, InvalidIndexesAndChildRowsAreEmpty)
|
||
|
|
{
|
||
|
|
SslModeModel model;
|
||
|
|
EXPECT_FALSE(model.data(QModelIndex()).isValid());
|
||
|
|
EXPECT_FALSE(model.data(model.index(model.rowCount(), 0)).isValid());
|
||
|
|
EXPECT_EQ(model.rowCount(model.index(0, 0)), 0);
|
||
|
|
}
|