Skip to content

Commit

Permalink
Fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Dec 20, 2016
1 parent c4a0c47 commit 930ce54
Show file tree
Hide file tree
Showing 17 changed files with 293 additions and 205 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ class QgsValueRelationSearchWidgetWrapper : QgsSearchWidgetWrapper
QWidget* createWidget( QWidget* parent );
void initWidget( QWidget* editor );

protected slots:
void onValueChanged();

void setExpression( QString exp );

};
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
35 changes: 19 additions & 16 deletions src/core/fieldkit/qgsvaluerelationfieldkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/core/qgsconfigurationmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsfieldkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
7 changes: 7 additions & 0 deletions src/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# for installing headers

SET(QGIS_TEST_HDRS
qgstest.h
)

INSTALL(FILES ${QGIS_TEST_HDRS} DESTINATION ${QGIS_INCLUDE_DIR})
35 changes: 35 additions & 0 deletions src/test/qgstest.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion tests/src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}
Expand Down
4 changes: 3 additions & 1 deletion tests/src/app/testqgsattributetable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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"
1 change: 1 addition & 0 deletions tests/src/gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
9 changes: 4 additions & 5 deletions tests/src/gui/testqgsdualview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <qgsmapcanvas.h>
#include <qgsfeature.h>

#include "qgstest.h"

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

QgsEditorWidgetRegistry::initEditors();

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

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




1 change: 1 addition & 0 deletions tests/src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions tests/src/python/test_qgsconfigurationmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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):
"""
Expand All @@ -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__':
Expand Down
Loading

0 comments on commit 930ce54

Please sign in to comment.