|
| 1 | +/*************************************************************************** |
| 2 | + testqgshstoreutils.cpp |
| 3 | + -------------------------------------- |
| 4 | + Date : October 2018 |
| 5 | + Copyright : (C) 2018 Etienne Trimaille |
| 6 | + Email : etienne dot trimaille at gmail dot com |
| 7 | + *************************************************************************** |
| 8 | + * * |
| 9 | + * This program is free software; you can redistribute it and/or modify * |
| 10 | + * it under the terms of the GNU General Public License as published by * |
| 11 | + * the Free Software Foundation; either version 2 of the License, or * |
| 12 | + * (at your option) any later version. * |
| 13 | + * * |
| 14 | + ***************************************************************************/ |
| 15 | + |
| 16 | +#include <QString> |
| 17 | +#include "qgstest.h" |
| 18 | +#include "qgshstoreutils.h" |
| 19 | + |
| 20 | +class TestQgsHstoreUtils : public QObject |
| 21 | +{ |
| 22 | + Q_OBJECT |
| 23 | + private slots: |
| 24 | + |
| 25 | + void testHstore(); |
| 26 | +}; |
| 27 | + |
| 28 | + |
| 29 | +void TestQgsHstoreUtils::testHstore() |
| 30 | +{ |
| 31 | + QVariantMap map; |
| 32 | + map[QStringLiteral( "1" )] = "one"; |
| 33 | + map[QStringLiteral( "2" )] = "two"; |
| 34 | + map[QStringLiteral( "3" )] = "three"; |
| 35 | + |
| 36 | + QCOMPARE( QgsHstoreUtils::parse( QStringLiteral( "1=>one,2=>two,3=>three" ) ), map ); |
| 37 | + QCOMPARE( QgsHstoreUtils::build( map ), QStringLiteral( "\"1\"=>\"one\",\"2\"=>\"two\",\"3\"=>\"three\"" ) ); |
| 38 | + |
| 39 | + map.clear(); |
| 40 | + map[QStringLiteral( "1" )] = "one"; |
| 41 | + // if a key is missing its closing quote, the map construction process will stop and a partial map is returned |
| 42 | + QCOMPARE( QgsHstoreUtils::parse( QStringLiteral( "\"1\"=>\"one\",\"2=>\"two\"" ) ), QVariantMap( map ) ); |
| 43 | +} |
| 44 | + |
| 45 | +QGSTEST_MAIN( TestQgsHstoreUtils ) |
| 46 | +#include "testqgshstoreutils.moc" |
0 commit comments