Skip to content
Permalink
Browse files

Fix failing tests

  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent c4a0c47 commit 930ce545a8e970ef705d3b862ac8fe7d7769b33b
@@ -28,4 +28,9 @@ class QgsValueRelationSearchWidgetWrapper : QgsSearchWidgetWrapper
QWidget* createWidget( QWidget* parent );
void initWidget( QWidget* editor );

protected slots:
void onValueChanged();

void setExpression( QString exp );

};
@@ -5,6 +5,7 @@ ADD_SUBDIRECTORY(gui)
ADD_SUBDIRECTORY(auth)
ADD_SUBDIRECTORY(providers)
ADD_SUBDIRECTORY(crssync)
ADD_SUBDIRECTORY(test)

IF (WITH_DESKTOP)
ADD_SUBDIRECTORY(app)
@@ -47,47 +47,50 @@ QString QgsValueRelationFieldKit::representValue( QgsVectorLayer* layer, int fie
Q_UNUSED( layer )
Q_UNUSED( fieldIndex )

QHash<QString, QString> vrCache;
QgsValueRelationFieldKit::ValueRelationCache vrCache;

if ( cache.isValid() )
{
vrCache = cache.value<QHash<QString, QString>>();
vrCache = cache.value<QgsValueRelationFieldKit::ValueRelationCache>();
}
else
{
vrCache = createCache( layer, fieldIndex, config ).value<QHash<QString, QString>>();
vrCache = QgsValueRelationFieldKit::createCache( config );
}

if ( config.value( QStringLiteral( "AllowMulti" ) ).toBool() )
if ( config.value( "AllowMulti" ).toBool() )
{
QStringList keyList = value.toString().remove( QChar( '{' ) ).remove( QChar( '}' ) ).split( ',' );
QStringList valueList;

Q_FOREACH ( const QString& key, keyList )
Q_FOREACH ( const QgsValueRelationFieldKit::ValueRelationItem& item, vrCache )
{
auto val = vrCache.constFind( key );
if ( val != vrCache.constEnd() )
valueList << val.value();
else
valueList << QStringLiteral( "(%1)" ).arg( key );
if ( keyList.contains( item.key.toString() ) )
{
valueList << item.value;
}
}

return valueList.join( QStringLiteral( ", " ) ).prepend( '{' ).append( '}' );
return valueList.join( ", " ).prepend( '{' ).append( '}' );
}
else
{
if ( value.isNull() )
{
QSettings settings;
return settings.value( QStringLiteral( "qgis/nullValue" ), "NULL" ).toString();
return settings.value( "qgis/nullValue", "NULL" ).toString();
}

auto val = vrCache.constFind( value.toString() );
if ( val != vrCache.constEnd() )
return val.value();
Q_FOREACH ( const QgsValueRelationFieldKit::ValueRelationItem& item, vrCache )
{
if ( item.key == value )
{
return item.value;
}
}
}

return QStringLiteral( "(%1)" ).arg( value.toString() );
return QString( "(%1)" ).arg( value.toString() );
}

QVariant QgsValueRelationFieldKit::sortValue( QgsVectorLayer* layer, int fieldIndex, const QVariantMap& config, const QVariant& cache, const QVariant& value ) const
@@ -116,12 +116,13 @@ QVariant QgsConfigurationMap::fromXmlHelper( const QDomElement& element ) const
else if ( type == QLatin1String( "Map" ) )
{
QVariantMap map;
QDomNodeList options = element.elementsByTagName( QStringLiteral( "Option" ) );
QDomNodeList options = element.childNodes();

for ( int i = 0; i < options.count(); ++i )
{
QDomElement elem = options.at( i ).toElement();
map.insert( elem.attribute( QStringLiteral( "name" ) ), fromXmlHelper( elem ) );
if ( elem.tagName() == QLatin1String( "Option" ) )
map.insert( elem.attribute( QStringLiteral( "name" ) ), fromXmlHelper( elem ) );
}
return map;
}
@@ -33,7 +33,7 @@ class QgsVectorLayer;
*
* This is an abstract base class and will always need to be subclassed.
*
* @Note added in QGIS 3.0
* @note added in QGIS 3.0
*/
class CORE_EXPORT QgsFieldKit
{
@@ -52,7 +52,7 @@ class GUI_EXPORT QgsValueRelationSearchWidgetWrapper : public QgsSearchWidgetWra
QWidget* createWidget( QWidget* parent ) override;
void initWidget( QWidget* editor ) override;

private slots:
protected slots:
//! Called when current value of search widget changes
void onValueChanged();

@@ -0,0 +1,7 @@
# for installing headers

SET(QGIS_TEST_HDRS
qgstest.h
)

INSTALL(FILES ${QGIS_TEST_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
@@ -0,0 +1,35 @@
/***************************************************************************
qgstest - %{Cpp:License:ClassName}
---------------------
begin : 5.12.2016
copyright : (C) 2016 by Matthias Kuhn
email : matthias@opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifndef QGSTEST_H
#define QGSTEST_H

#define QGSTEST_MAIN(TestObject) \
QT_BEGIN_NAMESPACE \
QTEST_ADD_GPU_BLACKLIST_SUPPORT_DEFS \
QT_END_NAMESPACE \
int main(int argc, char *argv[]) \
{ \
QgsApplication app(argc, argv, false); \
app.setAttribute(Qt::AA_Use96Dpi, true); \
QTEST_DISABLE_KEYPAD_NAVIGATION \
QTEST_ADD_GPU_BLACKLIST_SUPPORT \
TestObject tc; \
QTEST_SET_MAIN_SOURCE_PATH \
return QTest::qExec(&tc, argc, argv); \
}


#endif // QGSTEST_H
@@ -10,6 +10,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/raster
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/symbology-ng
${CMAKE_CURRENT_BINARY_DIR}/../../../src/ui
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/ui
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/gui
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/gui/editorwidgets
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/gui/editorwidgets/core
@@ -19,7 +20,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/python
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/app
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/app/pluginmanager
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/ui
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/test
)
INCLUDE_DIRECTORIES(SYSTEM
${QT_INCLUDE_DIR}
@@ -25,6 +25,8 @@
#include "qgsmapcanvas.h"
#include "qgsunittypes.h"

#include "qgstest.h"

/** \ingroup UnitTests
* This is a unit test for the attribute table dialog
*/
@@ -167,5 +169,5 @@ void TestQgsAttributeTable::testFieldCalculationArea()
QVERIFY( qgsDoubleNear( f.attribute( "col1" ).toDouble(), expected, 0.001 ) );
}

QTEST_MAIN( TestQgsAttributeTable )
QGSTEST_MAIN( TestQgsAttributeTable )
#include "testqgsattributetable.moc"
@@ -19,6 +19,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/geometry
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/raster
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/core/symbology-ng
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/test
)
INCLUDE_DIRECTORIES(SYSTEM
${QT_INCLUDE_DIR}
@@ -27,6 +27,8 @@
#include <qgsmapcanvas.h>
#include <qgsfeature.h>

#include "qgstest.h"

class TestQgsDualView : public QObject
{
Q_OBJECT
@@ -67,6 +69,7 @@ void TestQgsDualView::initTestCase()
QgsApplication::init();
QgsApplication::initQgis();
QgsApplication::showSettings();

QgsEditorWidgetRegistry::initEditors();

// Setup a map canvas with a vector layer loaded...
@@ -267,9 +270,5 @@ void TestQgsDualView::testAttributeFormSharedValueScanning()
QVERIFY( mixedValueFields.isEmpty() );
}

QTEST_MAIN( TestQgsDualView )
QGSTEST_MAIN( TestQgsDualView )
#include "testqgsdualview.moc"




@@ -45,6 +45,7 @@ ADD_PYTHON_TEST(PyQgsEditWidgets test_qgseditwidgets.py)
ADD_PYTHON_TEST(PyQgsExpression test_qgsexpression.py)
ADD_PYTHON_TEST(PyQgsExpressionLineEdit test_qgsexpressionlineedit.py)
ADD_PYTHON_TEST(PyQgsFeature test_qgsfeature.py)
ADD_PYTHON_TEST(PyQgsFieldKitsTest test_qgsfieldkits.py)
ADD_PYTHON_TEST(PyQgsProject test_qgsproject.py)
ADD_PYTHON_TEST(PyQgsFeatureIterator test_qgsfeatureiterator.py)
ADD_PYTHON_TEST(PyQgsField test_qgsfield.py)
@@ -52,7 +52,7 @@ def test_integer(self):
prop2 = QgsConfigurationMap()

prop2.fromXml(element)
self.assertEquals(prop2.get(), my_properties)
self.assertEquals(my_properties, prop2.get())

def test_string(self):
"""
@@ -69,7 +69,7 @@ def test_string(self):
prop2 = QgsConfigurationMap()

prop2.fromXml(element)
self.assertEquals(prop2.get(), my_properties)
self.assertEquals(my_properties, prop2.get())

def test_double(self):
"""
@@ -86,7 +86,7 @@ def test_double(self):
prop2 = QgsConfigurationMap()

prop2.fromXml(element)
self.assertEquals(prop2.get(), my_properties)
self.assertEquals(my_properties, prop2.get())

def test_boolean(self):
"""
@@ -105,7 +105,7 @@ def test_boolean(self):
prop2 = QgsConfigurationMap()

prop2.fromXml(element)
self.assertEquals(prop2.get(), my_properties)
self.assertEquals(my_properties, prop2.get())

def test_complex(self):
"""
@@ -124,7 +124,7 @@ def test_complex(self):
prop2 = QgsConfigurationMap()

prop2.fromXml(element)
self.assertEquals(prop2.get(), my_properties)
self.assertEquals(my_properties, prop2.get())


if __name__ == '__main__':

0 comments on commit 930ce54

Please sign in to comment.
You can’t perform that action at this time.