2005-01-19 23:07:31 +00:00
|
|
|
/**
|
|
|
|
|
|
|
|
@file projecttst.h
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2005-01-19 20:51:24 +00:00
|
|
|
#include <cppunit/TestFixture.h>
|
|
|
|
#include <cppunit/extensions/HelperMacros.h>
|
|
|
|
|
|
|
|
#include <qgsproject.h>
|
|
|
|
|
|
|
|
#include <qstring.h>
|
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
|
|
|
|
|
2005-01-19 23:07:31 +00:00
|
|
|
/**
|
|
|
|
tests for QgsProject
|
|
|
|
|
|
|
|
@todo XXX add tests for:
|
|
|
|
|
|
|
|
entryList()
|
|
|
|
removeEntry()
|
|
|
|
clearProperties()
|
|
|
|
read()
|
|
|
|
write()
|
|
|
|
|
|
|
|
Although the last two may be difficult to test for since qgis won't be running.
|
|
|
|
|
|
|
|
*/
|
2005-01-19 20:51:24 +00:00
|
|
|
class ProjectTest : public CppUnit::TestFixture
|
|
|
|
{
|
|
|
|
CPPUNIT_TEST_SUITE( ProjectTest );
|
|
|
|
|
|
|
|
CPPUNIT_TEST( testFileName );
|
|
|
|
CPPUNIT_TEST( testTitle );
|
2005-01-19 21:00:11 +00:00
|
|
|
CPPUNIT_TEST( testMapUnits );
|
|
|
|
CPPUNIT_TEST( testDirtyFlag );
|
2005-01-19 21:22:30 +00:00
|
|
|
CPPUNIT_TEST( readNullEntries );
|
2005-01-19 21:54:23 +00:00
|
|
|
CPPUNIT_TEST( testWriteEntries );
|
2005-01-19 23:07:31 +00:00
|
|
|
CPPUNIT_TEST( testRemoveEntry );
|
2005-01-19 23:09:32 +00:00
|
|
|
CPPUNIT_TEST( testClearProperties );
|
2005-01-19 20:51:24 +00:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
|
|
|
Setup the common test members, etc
|
|
|
|
*/
|
|
|
|
void setUp()
|
|
|
|
{
|
2005-01-19 21:22:30 +00:00
|
|
|
mFile = "test.project";
|
|
|
|
mTitle = "test title";
|
|
|
|
mScope = "project_test";
|
|
|
|
|
|
|
|
mNumValueKey = "/values/num";
|
|
|
|
|
|
|
|
mDoubleValueKey = "/values/double";
|
|
|
|
|
|
|
|
mBoolValueKey = "/values/bool";
|
|
|
|
|
|
|
|
mStringValueKey = "/values/string";
|
|
|
|
|
|
|
|
mStringListValueKey = "/values/stringlist";
|
|
|
|
|
|
|
|
|
|
|
|
mNumValueConst = 42;
|
|
|
|
|
|
|
|
mDoubleValueConst = 12345.6789;
|
|
|
|
|
|
|
|
mBoolValueConst = true;
|
|
|
|
|
|
|
|
mStringValueConst = "Test String";
|
|
|
|
|
|
|
|
mStringListValueConst += "first";
|
|
|
|
mStringListValueConst += "second";
|
|
|
|
mStringListValueConst += "third";
|
|
|
|
} // setUp
|
|
|
|
|
2005-01-19 20:51:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
void testFileName()
|
|
|
|
{
|
2005-01-19 21:22:30 +00:00
|
|
|
QgsProject::instance()->dirty( false );
|
|
|
|
QgsProject::instance()->filename( mFile );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( mFile == QgsProject::instance()->filename() );
|
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
|
|
|
} // testFileName
|
2005-01-19 20:51:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void testTitle()
|
|
|
|
{
|
2005-01-19 21:22:30 +00:00
|
|
|
QgsProject::instance()->dirty( false );
|
|
|
|
QgsProject::instance()->title( mTitle );
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( mTitle == QgsProject::instance()->title() );
|
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
|
|
|
} // testTitle
|
2005-01-19 20:51:24 +00:00
|
|
|
|
2005-01-19 21:00:11 +00:00
|
|
|
|
|
|
|
void testMapUnits()
|
|
|
|
{
|
2005-01-19 21:22:30 +00:00
|
|
|
QgsProject::instance()->dirty( false );
|
2005-01-19 21:00:11 +00:00
|
|
|
QgsProject::instance()->mapUnits( QgsScaleCalculator::METERS );
|
|
|
|
CPPUNIT_ASSERT( QgsScaleCalculator::METERS == QgsProject::instance()->mapUnits() );
|
2005-01-19 21:22:30 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
2005-01-19 21:00:11 +00:00
|
|
|
|
2005-01-19 21:22:30 +00:00
|
|
|
QgsProject::instance()->dirty( false );
|
2005-01-19 21:00:11 +00:00
|
|
|
QgsProject::instance()->mapUnits( QgsScaleCalculator::FEET );
|
|
|
|
CPPUNIT_ASSERT( QgsScaleCalculator::FEET == QgsProject::instance()->mapUnits() );
|
2005-01-19 21:22:30 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
2005-01-19 21:00:11 +00:00
|
|
|
|
2005-01-19 21:22:30 +00:00
|
|
|
QgsProject::instance()->dirty( false );
|
2005-01-19 21:00:11 +00:00
|
|
|
QgsProject::instance()->mapUnits( QgsScaleCalculator::DEGREES );
|
|
|
|
CPPUNIT_ASSERT( QgsScaleCalculator::DEGREES == QgsProject::instance()->mapUnits() );
|
2005-01-19 21:22:30 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
|
|
|
} // testMapUnits
|
|
|
|
|
|
|
|
|
2005-01-19 21:00:11 +00:00
|
|
|
|
|
|
|
void testDirtyFlag()
|
|
|
|
{
|
|
|
|
QgsProject::instance()->dirty( true );
|
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
|
|
|
|
|
|
|
QgsProject::instance()->dirty( false );
|
|
|
|
CPPUNIT_ASSERT( ! QgsProject::instance()->dirty() );
|
2005-01-19 21:22:30 +00:00
|
|
|
} // testDirtyFlag
|
|
|
|
|
2005-01-19 20:51:24 +00:00
|
|
|
|
2005-01-19 21:22:30 +00:00
|
|
|
/**
|
|
|
|
Reading entries that are known not to exist should fail and use default
|
|
|
|
values.
|
|
|
|
*/
|
|
|
|
void readNullEntries()
|
|
|
|
{
|
|
|
|
bool status;
|
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
bool b = QgsProject::instance()->readBoolEntry( mScope, mBoolValueKey, false, &status );
|
2005-01-19 21:22:30 +00:00
|
|
|
CPPUNIT_ASSERT( false == b && ! status );
|
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
int i = QgsProject::instance()->readNumEntry( mScope, mNumValueKey, 13, &status );
|
|
|
|
CPPUNIT_ASSERT( 13 == i && ! status );
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
double d = QgsProject::instance()->readDoubleEntry( mScope, mDoubleValueKey, 99.0, &status );
|
|
|
|
CPPUNIT_ASSERT( 99.0 == d && ! status );
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
QString s = QgsProject::instance()->readEntry( mScope, mStringValueKey, "FOO", &status );
|
|
|
|
CPPUNIT_ASSERT( "FOO" == s && ! status );
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
QStringList sl = QgsProject::instance()->readListEntry( mScope, mStringListValueKey, &status );
|
|
|
|
CPPUNIT_ASSERT( sl.empty() && ! status );
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
} // readNullEntries
|
2005-01-19 21:22:30 +00:00
|
|
|
|
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
/** check that writing entries works */
|
|
|
|
void testWriteEntries()
|
|
|
|
{
|
2005-01-19 22:03:37 +00:00
|
|
|
QgsProject::instance()->dirty( false );
|
2005-01-19 21:54:23 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->writeEntry( mScope, mBoolValueKey, mBoolValueConst ) );
|
2005-01-19 22:03:37 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
|
|
|
|
|
|
|
QgsProject::instance()->dirty( false );
|
2005-01-19 21:54:23 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->writeEntry( mScope, mNumValueKey, mNumValueConst ) );
|
2005-01-19 22:03:37 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
|
|
|
|
|
|
|
QgsProject::instance()->dirty( false );
|
2005-01-19 21:54:23 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->writeEntry( mScope, mDoubleValueKey, mDoubleValueConst ) );
|
2005-01-19 22:03:37 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
|
|
|
|
|
|
|
QgsProject::instance()->dirty( false );
|
2005-01-19 21:54:23 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->writeEntry( mScope, mStringValueKey, mStringValueConst ) );
|
2005-01-19 22:03:37 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
|
|
|
|
|
|
|
QgsProject::instance()->dirty( false );
|
2005-01-19 21:54:23 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->writeEntry( mScope, mStringListValueKey, mStringListValueConst ) );
|
2005-01-19 22:03:37 +00:00
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->dirty() );
|
|
|
|
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
bool status;
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
bool b = QgsProject::instance()->readBoolEntry( mScope, mBoolValueKey, false, &status );
|
|
|
|
CPPUNIT_ASSERT( mBoolValueConst == b && status );
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
int i = QgsProject::instance()->readNumEntry( mScope, mNumValueKey, 13, &status );
|
|
|
|
CPPUNIT_ASSERT( mNumValueConst == i && status );
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
double d = QgsProject::instance()->readDoubleEntry( mScope, mDoubleValueKey, 99.0, &status );
|
|
|
|
CPPUNIT_ASSERT( mDoubleValueConst == d && status );
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
QString s = QgsProject::instance()->readEntry( mScope, mStringValueKey, "FOO", &status );
|
|
|
|
CPPUNIT_ASSERT( mStringValueConst == s && status );
|
2005-01-19 21:22:30 +00:00
|
|
|
|
2005-01-19 21:54:23 +00:00
|
|
|
QStringList sl = QgsProject::instance()->readListEntry( mScope, mStringListValueKey, &status );
|
|
|
|
CPPUNIT_ASSERT( mStringListValueConst == sl && status );
|
|
|
|
|
|
|
|
} // testWriteEntries
|
2005-01-19 21:22:30 +00:00
|
|
|
|
|
|
|
|
2005-01-19 23:07:31 +00:00
|
|
|
|
|
|
|
void testRemoveEntry()
|
|
|
|
{
|
|
|
|
// presume that testWriteEntries() already invoked so that properties are set
|
|
|
|
|
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->removeEntry( mScope, mBoolValueKey ) );
|
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->removeEntry( mScope, mNumValueKey ) );
|
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->removeEntry( mScope, mDoubleValueKey ) );
|
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->removeEntry( mScope, mStringValueKey ) );
|
|
|
|
CPPUNIT_ASSERT( QgsProject::instance()->removeEntry( mScope, mStringListValueKey ) );
|
|
|
|
|
|
|
|
// since we've removed everything, re-run this test to verify that
|
|
|
|
readNullEntries();
|
|
|
|
|
|
|
|
} // testRemoveEntry
|
|
|
|
|
2005-01-19 23:09:32 +00:00
|
|
|
|
|
|
|
void testClearProperties()
|
|
|
|
{ // rebuild the properties deleted in testRemoveEntry()
|
|
|
|
testWriteEntries();
|
|
|
|
|
|
|
|
// remove all in one fell swoop
|
|
|
|
QgsProject::instance()->clearProperties();
|
|
|
|
|
|
|
|
// since we've removed everything, re-run this test to verify that
|
|
|
|
readNullEntries();
|
|
|
|
} // testClearProperties
|
|
|
|
|
|
|
|
|
2005-01-19 20:51:24 +00:00
|
|
|
private:
|
|
|
|
|
|
|
|
/// file name for project file
|
2005-01-19 21:22:30 +00:00
|
|
|
QString mFile;
|
2005-01-19 20:51:24 +00:00
|
|
|
|
|
|
|
/// test project title
|
2005-01-19 21:22:30 +00:00
|
|
|
QString mTitle;
|
|
|
|
|
|
|
|
/// test project scope
|
|
|
|
QString mScope;
|
|
|
|
|
|
|
|
/// num value key
|
|
|
|
QString mNumValueKey;
|
|
|
|
|
|
|
|
/// double value key
|
|
|
|
QString mDoubleValueKey;
|
|
|
|
|
|
|
|
/// bool value key
|
|
|
|
QString mBoolValueKey;
|
|
|
|
|
|
|
|
/// string value key
|
|
|
|
QString mStringValueKey;
|
|
|
|
|
|
|
|
/// string list value key
|
|
|
|
QString mStringListValueKey;
|
|
|
|
|
|
|
|
/// num value const
|
|
|
|
int mNumValueConst;
|
|
|
|
|
|
|
|
/// double value const
|
|
|
|
double mDoubleValueConst;
|
|
|
|
|
|
|
|
/// bool value const
|
|
|
|
bool mBoolValueConst;
|
|
|
|
|
|
|
|
/// string value const
|
|
|
|
QString mStringValueConst;
|
|
|
|
|
|
|
|
/// string list value const
|
|
|
|
QStringList mStringListValueConst;
|
|
|
|
|
2005-01-19 20:51:24 +00:00
|
|
|
}; // class ProjectTest
|
|
|
|
|