Skip to content
Snippets Groups Projects
Commit ee42372c authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Comparators registration moved to separate file

parent 8d0b6031
No related branches found
No related tags found
No related merge requests found
#include "Comparators.h"
#include "ComboProperty.h"
#include "ExternalProperty.h"
#include <QMetaType>
bool Comparators::m_is_registered = false;
void Comparators::registerComparators()
{
QMetaType::registerComparators<ComboProperty>();
QMetaType::registerComparators<ExternalProperty>();
m_is_registered = true;
}
bool Comparators::registered()
{
return m_is_registered;
}
#ifndef COMPARATORS_H
#define COMPARATORS_H
//! Helper class to register custom variants comparators and to report
//! unit tests if comparators should be tested.
class Comparators
{
public:
static void registerComparators();
static bool registered();
private:
static bool m_is_registered;
};
#endif // COMPARATORS_H
#include "google_test.h"
#include "ComboProperty.h"
#include "Comparators.h"
#include "test_utils.h"
class TestComboProperty : public ::testing::Test
......@@ -35,6 +36,9 @@ TEST_F(TestComboProperty, test_ComboEquality)
EXPECT_TRUE(c1 == c2);
}
//! Check equality of ComboPeroperty's variants.
//! If comparators are not registered, the behavior is undefined.
TEST_F(TestComboProperty, test_VariantEquality)
{
QVariant v1(1.0);
......@@ -45,16 +49,22 @@ TEST_F(TestComboProperty, test_VariantEquality)
ComboProperty c1 = ComboProperty() << "a1" << "a2";
ComboProperty c2 = ComboProperty() << "a1" << "a2";
EXPECT_TRUE(c1.variant() == c2.variant());
c2 << "a3";
EXPECT_TRUE(c1.variant() != c2.variant());
c2.setValue("a2");
EXPECT_TRUE(c1.variant() != c2.variant());
if (Comparators::registered()) {
EXPECT_TRUE(c1.variant() == c2.variant());
c2 << "a3";
c2.setValue("a2");
EXPECT_TRUE(c1.variant() != c2.variant());
EXPECT_FALSE(c1.variant() == c2.variant());
c1 << "a3";
c1.setValue("a2");
EXPECT_TRUE(c1.variant() == c2.variant());
c1 << "a3";
c1.setValue("a2");
EXPECT_TRUE(c1.variant() == c2.variant());
EXPECT_FALSE(c1.variant() != c2.variant());
}
}
TEST_F(TestComboProperty, test_setValue)
......
#include "google_test.h"
#include "ExternalProperty.h"
#include "Comparators.h"
#include "test_utils.h"
class TestExternalProperty : public ::testing::Test
......@@ -55,18 +56,24 @@ TEST_F(TestExternalProperty, test_equalityOperators)
}
//! Testing equality operators for QVariants based on ExternalProperty.
//! Comparators should be enabled in main.cpp
//! If comparators are not registered, the behavior is undefined
TEST_F(TestExternalProperty, test_variantEquality)
{
ExternalProperty prop1;
ExternalProperty prop2;
EXPECT_TRUE(prop1.variant() == prop2.variant());
prop1.setIdentifier("aaa");
EXPECT_TRUE(prop1.variant() != prop2.variant());
prop2.setIdentifier("aaa");
EXPECT_TRUE(prop1.variant() == prop2.variant());
if (Comparators::registered()) {
EXPECT_TRUE(prop1.variant() == prop2.variant());
prop1.setIdentifier("aaa");
EXPECT_TRUE(prop1.variant() != prop2.variant());
EXPECT_FALSE(prop1.variant() == prop2.variant());
prop2.setIdentifier("aaa");
EXPECT_TRUE(prop1.variant() == prop2.variant());
}
}
TEST_F(TestExternalProperty, test_toXML)
......
#include "google_test.h"
#include <QString>
#include <QCoreApplication>
#include "ComboProperty.h"
#include "Comparators.h"
#include "TestComboProperty.h"
#include "TestComponentProxyModel.h"
......@@ -46,8 +46,7 @@ int main(int argc, char** argv) {
QCoreApplication app(argc, argv);
Q_UNUSED(app);
QMetaType::registerComparators<ComboProperty>();
QMetaType::registerComparators<ExternalProperty>();
Comparators::registerComparators();
qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>("LayoutChangeHint");
::testing::InitGoogleTest(&argc, argv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment