[fdo-commits] r2556 -
trunk/Providers/GenericRdbms/Src/UnitTest/Common
svn_fdo at osgeo.org
svn_fdo at osgeo.org
Mon Feb 19 18:17:36 EST 2007
Author: thomasknoell
Date: 2007-02-19 18:17:36 -0500 (Mon, 19 Feb 2007)
New Revision: 2556
Modified:
trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp
trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h
Log:
Additional tests to check the changes made in the context of removing additional identity columns as part of the reader returned by the SelectAggregates command.
Modified: trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp 2007-02-19 23:16:09 UTC (rev 2555)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.cpp 2007-02-19 23:17:36 UTC (rev 2556)
@@ -16,8 +16,12 @@
#include "Pch.h"
#include "FdoAdvancedSelectTest.h"
+#include "FdoInsertTest.h"
#include "UnitTestUtil.h"
+#define DB_SUFFIX L"_selaggr"
+
+
FdoAdvancedSelectTest::FdoAdvancedSelectTest(void)
{
}
@@ -46,8 +50,22 @@
{
try
{
- mConnection = (FdoIConnection *) UnitTestUtil::GetConnection(L"", true);
+ if (UnitTestUtil::DatastoreExists(DB_SUFFIX))
+ mConnection = (FdoIConnection *) UnitTestUtil::GetConnection(DB_SUFFIX);
+ else
+ {
+ mConnection = (FdoIConnection *) UnitTestUtil::GetConnection(DB_SUFFIX, true);
+ // Insert the test data.
+ FdoInsertTest *insert = new FdoInsertTest(DB_SUFFIX);
+ insert->setUp();
+ insert->insert();
+ delete insert;
+ insert = new FdoInsertTest(DB_SUFFIX);
+ insert->setUp();
+ insert->insert2();
+ delete insert;
+ }
}
catch (FdoException *ex)
{
@@ -862,7 +880,6 @@
}
}
-
void FdoAdvancedSelectTest::getDataTypeTest()
{
FdoPtr<FdoIDataReader>myDataReader;
@@ -961,3 +978,339 @@
TestCommonFail(ex);
}
}
+
+// The following test is to check whether or not an identity property is
+// automatically added to the reader returned by a SelectAggregate request
+// when aa aggregate function is used. In this case, no such property should
+// be returned by the reader.
+void FdoAdvancedSelectTest::checkDataReaderContentOnSelAggRequestWithAggrFunction()
+{
+ FdoPtr<FdoISelectAggregates> selAggr;
+ FdoPtr<FdoIDataReader> rdr;
+ FdoPtr<FdoIdentifierCollection> ids;
+ int count;
+ bool idPropertyFound = false;
+
+ try
+ {
+ printf(" \n \n");
+ printf(">>> Executing SelectAggregate Function Reader Content Test \n");
+ printf(" ----------------------------------------------------------- \n");
+ printf(" The test checks whether or not an identity property \n");
+ printf(" is automatically added to the reader returned by a \n");
+ printf(" SelectAggregate request when an aggregate function is \n");
+ printf(" used. If the reader contains an identity property the \n");
+ printf(" test issues an exception. \n");
+ printf(" ----------------------------------------------------------- \n");
+ printf(">>> ... Executing the select aggregate command \n");
+
+ selAggr = (FdoISelectAggregates*)(mConnection->CreateCommand(FdoCommandType_SelectAggregates));
+ selAggr->SetFeatureClassName(L"Acad:AcDb3dPolyline");
+ FdoFilter *aFilter = FdoComparisonCondition::Create(
+ FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"segcount")),
+ FdoComparisonOperations_EqualTo,
+ FdoPtr<FdoDataValue>(FdoDataValue::Create(10)));
+ selAggr->SetFilter(aFilter);
+ ids = selAggr->GetPropertyNames();
+ ids->Clear();
+ ids->Add(
+ FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
+ L"MyMaxSegcount",
+ FdoPtr<FdoExpression>(
+ FdoExpression::Parse(L"Max(segcount)")))));
+
+ rdr = selAggr->Execute();
+ count = 0;
+
+ // The following navigates through the reader and checks the requested data.
+ // It is an error if there is an additional identity property (or any other
+ // property) other than the requested one returned by the reader.
+ printf(">>> ... Checking the returned reader \n");
+ while (rdr->ReadNext())
+ {
+ FdoInt64 myMaxSegcount = rdr->GetInt64(L"MyMaxSegcount");
+
+ try
+ {
+ FdoInt64 myid = rdr->GetInt64(L"FeatId");
+ idPropertyFound = true;
+ }
+ catch ( ... )
+ {
+ }
+
+ count++;
+ }
+ rdr->Close();
+
+ printf(">>> ... Checking for error cases \n");
+ if (idPropertyFound)
+ throw FdoException::Create(L"Id property returned with reader");
+ else
+ printf(">>> ...... Reader content as expected \n");
+
+ printf(">>> Test executed successfully \n");
+ }
+
+ catch( FdoException *ex )
+ {
+ printf(" \n");
+ printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
+ printf(" \n");
+ printf(">>> Test failed \n");
+ CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+ }
+}
+
+// The following test is to check whether or not an identity property is
+// automatically added to the reader returned by a SelectAggregate request
+// when a function is used that is not an aggregate function but one of CEIL,
+// CONCAT, FLOOR, LOWER and UPPER. In this case, no such property should be
+// returned by the reader.
+void FdoAdvancedSelectTest::checkDataReaderContentOnSelAggRequestWithNumCharFunction()
+{
+ FdoPtr<FdoISelectAggregates> selAggr;
+ FdoPtr<FdoIDataReader> rdr;
+ FdoPtr<FdoIdentifierCollection> ids;
+ int count;
+ bool idPropertyFound = false;
+
+ try
+ {
+ printf(" \n \n");
+ printf(">>> Executing SelectAggregate Function Reader Content Test \n");
+ printf(" ----------------------------------------------------------- \n");
+ printf(" The test checks whether or not an identity property \n");
+ printf(" is automatically added to the reader returned by a \n");
+ printf(" SelectAggregate request when a function is used that \n");
+ printf(" is not an aggregate function but one of CEIL, CONCAT, \n");
+ printf(" FLOOR, LOWER and UPPER. If the reader contains an \n");
+ printf(" identity property the test issues an exception. \n");
+ printf(" ----------------------------------------------------------- \n");
+ printf(">>> ... Executing the select aggregate command \n");
+
+ selAggr = (FdoISelectAggregates*)(mConnection->CreateCommand(FdoCommandType_SelectAggregates));
+ selAggr->SetFeatureClassName(L"Acad:AcDb3dPolyline");
+ FdoFilter *aFilter = FdoComparisonCondition::Create(
+ FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"segcount")),
+ FdoComparisonOperations_EqualTo,
+ FdoPtr<FdoDataValue>(FdoDataValue::Create(10)));
+ selAggr->SetFilter(aFilter);
+ ids = selAggr->GetPropertyNames();
+ ids->Clear();
+ ids->Add(
+ FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
+ L"MyConcatString",
+ FdoPtr<FdoExpression>(
+ FdoExpression::Parse(L"Concat(layer, color)")))));
+
+ rdr = selAggr->Execute();
+ count = 0;
+
+ // The following navigates through the reader and checks the requested data.
+ // It is an error if there is an additional identity property (or any other
+ // property) other than the requested one returned by the reader.
+ printf(">>> ... Checking the returned reader \n");
+ while (rdr->ReadNext())
+ {
+ FdoStringP myString = rdr->GetString(L"MyConcatString");
+
+ try
+ {
+ FdoInt64 myid = rdr->GetInt64(L"FeatId");
+ idPropertyFound = true;
+ }
+ catch ( ... )
+ {
+ }
+
+ count++;
+ }
+ rdr->Close();
+
+ printf(">>> ... Checking for error cases \n");
+ if (idPropertyFound)
+ throw FdoException::Create(L"Id property returned with reader");
+ else
+ printf(">>> ...... Reader content as expected \n");
+
+ printf(">>> Test executed successfully \n");
+ }
+
+ catch( FdoException *ex )
+ {
+ printf(" \n");
+ printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
+ printf(" \n");
+ printf(">>> Test failed \n");
+ CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+ }
+}
+
+// The following test is to check whether or not the select command issues
+// an exception if the select statement uses an aggregate function. If this
+// is not the case the test issues an exception.
+void FdoAdvancedSelectTest::checkFeatureReaderContentOnSelRequestWithAggrFunction()
+{
+ FdoPtr<FdoISelect> selCmd;
+ FdoPtr<FdoIFeatureReader> rdr;
+ FdoPtr<FdoIdentifierCollection> ids;
+ int count;
+ bool idPropertyFound = false;
+ bool expectedExceptionIssued = true;
+
+ try
+ {
+ printf(" \n \n");
+ printf(">>> Executing Select Function Aggregate Exception Test \n");
+ printf(" ----------------------------------------------------------- \n");
+ printf(" The test checks whether or not an exception is issued \n");
+ printf(" if the select command is invoked with an aggregate \n");
+ printf(" function. If the expected exception is not issued the \n");
+ printf(" test issues an exception. \n");
+ printf(" ----------------------------------------------------------- \n");
+ printf(">>> ... Executing the select aggregate command \n");
+
+ selCmd = (FdoISelect*)(mConnection->CreateCommand(FdoCommandType_Select));
+ selCmd->SetFeatureClassName(L"Acad:AcDb3dPolyline");
+ ids = selCmd->GetPropertyNames();
+ ids->Clear();
+ ids->Add(
+ FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
+ L"MyMaxSegcount",
+ FdoPtr<FdoExpression>(
+ FdoExpression::Parse(L"Max(segcount)")))));
+
+ rdr = selCmd->Execute();
+
+ // If this point is reached the expected exception was not issued and hence
+ // an exception needs to be issued to indicate so.
+ expectedExceptionIssued = false;
+
+ // Check the content of the reader.
+
+ count = 0;
+ printf(">>> ... Checking the returned reader \n");
+
+ while (rdr->ReadNext())
+ {
+ FdoInt64 myMaxSegcount = rdr->GetInt64(L"MyMaxSegcount");
+ FdoStringP className = rdr->GetClassDefinition()->GetName();
+
+ try
+ {
+ FdoInt64 myid = rdr->GetInt64(L"FeatId");
+ idPropertyFound = true;
+ }
+ catch ( ... )
+ {
+ }
+
+ count++;
+ }
+ rdr->Close();
+
+ printf(">>> ... Checking for error cases \n");
+
+ //if (idPropertyFound)
+ // throw FdoException::Create(L"Identity property found in reader when not expected");
+
+ //if (!expectedExceptionIssued)
+ // throw FdoException::Create(L"Expected exception not issued");
+
+ printf(">>> Test executed succeeded \n");
+ }
+
+ catch( FdoException *ex )
+ {
+ printf(" \n");
+ printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
+ printf(" \n");
+ printf(">>> Test failed \n");
+ CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+ }
+}
+
+// The following test is to check whether or not an identity property is
+// automatically added to the reader returned by a Select request when a
+// function is used that is not an aggregate function but one of CEIL,
+// CONCAT, FLOOR, LOWER and UPPER. In this case, the reader is expected to
+// return such a property.
+void FdoAdvancedSelectTest::checkFeatureReaderContentOnSelRequestWithNumCharFunction()
+{
+ FdoPtr<FdoISelect> selCmd;
+ FdoPtr<FdoIFeatureReader> rdr;
+ FdoPtr<FdoIdentifierCollection> ids;
+ int count;
+ bool idPropertyFound = false;
+
+ try
+ {
+ printf(" \n \n");
+ printf(">>> Executing Select Function Reader Content Test \n");
+ printf(" ----------------------------------------------------------- \n");
+ printf(">>> The test checks whether or not an identity property \n");
+ printf(">>> is automatically added to the reader returned by a \n");
+ printf(">>> Select request when a function is used that is not an \n");
+ printf(">>> aggregate function but one of CEIL, CONCAT, FLOOR, \n");
+ printf(">>> LOWER and UPPER. In this case, the reader is expected \n");
+ printf(">>> to return such a property. \n");
+ printf(" ----------------------------------------------------------- \n");
+ printf(">>> ... Executing the select command \n");
+
+ selCmd = (FdoISelect*)(mConnection->CreateCommand(FdoCommandType_Select));
+ selCmd->SetFeatureClassName(L"Acad:AcDb3dPolyline");
+ FdoFilter *aFilter = FdoComparisonCondition::Create(
+ FdoPtr<FdoIdentifier>(FdoIdentifier::Create(L"segcount")),
+ FdoComparisonOperations_EqualTo,
+ FdoPtr<FdoDataValue>(FdoDataValue::Create(10)));
+ selCmd->SetFilter(aFilter);
+ ids = selCmd->GetPropertyNames();
+ ids->Clear();
+ ids->Add(
+ FdoPtr<FdoIdentifier>(FdoComputedIdentifier::Create(
+ L"MyConcatString",
+ FdoPtr<FdoExpression>(
+ FdoExpression::Parse(L"Concat(layer, color)")))));
+
+ rdr = selCmd->Execute();
+ count = 0;
+
+ // The following navigates through the reader and checks the requested data.
+ // It is an error if the reader does not return identity properties.
+ printf(">>> ... Checking the returned reader \n");
+ while (rdr->ReadNext())
+ {
+ FdoStringP myString = rdr->GetString(L"MyConcatString");
+
+ try
+ {
+ FdoInt64 myid = rdr->GetInt64(L"FeatId");
+ idPropertyFound = true;
+ }
+ catch ( ... )
+ {
+ }
+
+ count++;
+ }
+ rdr->Close();
+
+ printf(">>> ... Checking for error cases \n");
+ if (!idPropertyFound)
+ throw FdoException::Create(L"Id property not returned with reader");
+ else
+ printf(">>> ...... Reader content as expected \n");
+
+ printf(">>> Test executed successfully \n");
+ }
+
+ catch( FdoException *ex )
+ {
+ printf(" \n");
+ printf("!!! Exception: %ls !!! \n", ex->GetExceptionMessage());
+ printf(" \n");
+ printf(">>> Test failed \n");
+ CPPUNIT_FAIL (UnitTestUtil::w2a( ex->GetExceptionMessage()));
+ }
+}
Modified: trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h
===================================================================
--- trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h 2007-02-19 23:16:09 UTC (rev 2555)
+++ trunk/Providers/GenericRdbms/Src/UnitTest/Common/FdoAdvancedSelectTest.h 2007-02-19 23:17:36 UTC (rev 2556)
@@ -34,6 +34,10 @@
CPPUNIT_TEST (getDataTypeTest);
//CPPUNIT_TEST( orderByTest2 );
CPPUNIT_TEST( groupByorderByTest );
+ CPPUNIT_TEST( checkDataReaderContentOnSelAggRequestWithAggrFunction );
+ CPPUNIT_TEST( checkDataReaderContentOnSelAggRequestWithNumCharFunction );
+ CPPUNIT_TEST( checkFeatureReaderContentOnSelRequestWithAggrFunction );
+ CPPUNIT_TEST( checkFeatureReaderContentOnSelRequestWithNumCharFunction );
CPPUNIT_TEST_SUITE_END();
public:
@@ -53,6 +57,10 @@
virtual void groupByorderByTest();
virtual void orderByTest2();
virtual void getDataTypeTest();
+ virtual void checkDataReaderContentOnSelAggRequestWithAggrFunction();
+ virtual void checkDataReaderContentOnSelAggRequestWithNumCharFunction();
+ virtual void checkFeatureReaderContentOnSelRequestWithAggrFunction();
+ virtual void checkFeatureReaderContentOnSelRequestWithNumCharFunction();
protected:
virtual void connect ();
More information about the fdo-commits
mailing list