[fdo-commits] r2583 - in trunk/Utilities: Common/Inc Common/Src
TestCommon TestCommon/Inc TestCommon/Src
svn_fdo at osgeo.org
svn_fdo at osgeo.org
Thu Feb 22 09:28:04 EST 2007
Author: pierredalcourt
Date: 2007-02-22 09:28:04 -0500 (Thu, 22 Feb 2007)
New Revision: 2583
Added:
trunk/Utilities/TestCommon/Inc/TestCommonFileUtil.h
trunk/Utilities/TestCommon/Inc/TestCommonGeomUtil.h
trunk/Utilities/TestCommon/Inc/TestCommonSchemaUtil.h
trunk/Utilities/TestCommon/Src/TestCommonFileUtil.cpp
trunk/Utilities/TestCommon/Src/TestCommonGeomUtil.cpp
trunk/Utilities/TestCommon/Src/TestCommonSchemaUtil.cpp
Modified:
trunk/Utilities/Common/Inc/FdoCommonDataReader.h
trunk/Utilities/Common/Inc/FdoCommonQueryAggregator.h
trunk/Utilities/Common/Src/FdoCommonDataReader.cpp
trunk/Utilities/Common/Src/FdoCommonFilterExecutor.cpp
trunk/Utilities/Common/Src/FdoCommonQueryAggregator.cpp
trunk/Utilities/TestCommon/Inc/TestCommonMiscUtil.h
trunk/Utilities/TestCommon/Inc/stdafx.h
trunk/Utilities/TestCommon/Makefile.am
trunk/Utilities/TestCommon/Src/TestCommonMiscUtil.cpp
trunk/Utilities/TestCommon/TestCommon.vcproj
Log:
TRAC Ticket #17 "SHP/SDF: fix various Select/SelectAggregates defects"
Modified: trunk/Utilities/Common/Inc/FdoCommonDataReader.h
===================================================================
--- trunk/Utilities/Common/Inc/FdoCommonDataReader.h 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/Common/Inc/FdoCommonDataReader.h 2007-02-22 14:28:04 UTC (rev 2583)
@@ -360,8 +360,8 @@
virtual FdoCommonBinaryReader* GetBinaryReader();
FdoCommonPropertyIndex* GetPropertyIndex();
- FdoArray<FdoFunction*>* GetAggregateFunctions(FdoIdentifierCollection* selectedIds, FdoCommonExpressionType &exprType);
- FdoArray<FdoFunction*>* GetAggregateFunctions(FdoExpression* expr, FdoCommonExpressionType &exprType);
+ static FdoArray<FdoFunction*>* GetAggregateFunctions(FdoIdentifierCollection* selectedIds, FdoCommonExpressionType &exprType);
+ static FdoArray<FdoFunction*>* GetAggregateFunctions(FdoExpression* expr, FdoCommonExpressionType &exprType);
FdoClassDefinition* GetAggregateClassDef(FdoClassDefinition* originalClassDef, FdoIdentifierCollection* selectedIds);
void RunAggregateQuery(FdoISelect* selectCmd, FdoClassDefinition* originalClassDef, FdoIdentifierCollection* selectedIds, FdoClassDefinition* aggrClassDef, FdoArray<FdoFunction*>* aggrFunctions);
Modified: trunk/Utilities/Common/Inc/FdoCommonQueryAggregator.h
===================================================================
--- trunk/Utilities/Common/Inc/FdoCommonQueryAggregator.h 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/Common/Inc/FdoCommonQueryAggregator.h 2007-02-22 14:28:04 UTC (rev 2583)
@@ -23,11 +23,13 @@
struct AggregateStats
{
- double doubleVal;
- double doubleValAccumulator;
- FdoInt64 int64Val;
+ double doubleVal;
+ double doubleValAccumulator;
+ FdoInt64 int64Val;
+ FdoStringP stringVal;
+ FdoDateTime dateTimeVal;
FdoPtr<FdoIGeometry> geomVal;
- bool isNull;
+ bool isNull;
};
Modified: trunk/Utilities/Common/Src/FdoCommonDataReader.cpp
===================================================================
--- trunk/Utilities/Common/Src/FdoCommonDataReader.cpp 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/Common/Src/FdoCommonDataReader.cpp 2007-02-22 14:28:04 UTC (rev 2583)
@@ -411,10 +411,15 @@
FdoArray<FdoFunction*>* FdoCommonDataReader::GetAggregateFunctions(FdoIdentifierCollection* selectedIds, FdoCommonExpressionType &exprType)
{
- VALIDATE_ARGUMENT(selectedIds);
-
FdoArray<FdoFunction*>* aggrIdents = NULL;
+ // If no identifiers have been explicitly selected, this implies a per-row expression type with no aggregate functions:
+ if (selectedIds == NULL)
+ {
+ exprType = FdoCommonExpressionType_PerRow;
+ return NULL;
+ }
+
bool bContainsAggregateExpressions = false;
bool bContainsPerRowExpressions = false;
for (FdoInt32 i=0; i<selectedIds->GetCount(); i++)
Modified: trunk/Utilities/Common/Src/FdoCommonFilterExecutor.cpp
===================================================================
--- trunk/Utilities/Common/Src/FdoCommonFilterExecutor.cpp 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/Common/Src/FdoCommonFilterExecutor.cpp 2007-02-22 14:28:04 UTC (rev 2583)
@@ -3788,12 +3788,9 @@
}
}
- // If no matching signature was found, revert to 'default' return property/data type:
- if (!bFound)
- {
- retPropType = funcDef->GetReturnPropertyType();
- retDataType = funcDef->GetReturnType();
- }
+ // If no matching signature was found, throw an exception:
+ if (!bFound)
+ throw FdoException::Create(FdoException::NLSGetMessage(FDO_183_INVALID_FUNCTION_ARG, "One or more arguments for function '%1$ls' did not match the expected argument types.", function->GetName()));
}
}
Modified: trunk/Utilities/Common/Src/FdoCommonQueryAggregator.cpp
===================================================================
--- trunk/Utilities/Common/Src/FdoCommonQueryAggregator.cpp 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/Common/Src/FdoCommonQueryAggregator.cpp 2007-02-22 14:28:04 UTC (rev 2583)
@@ -219,6 +219,20 @@
dv = FdoDoubleValue::Create(aggrStats.doubleVal);
break;
+ case FdoDataType_String:
+ if (aggrStats.isNull)
+ dv = FdoStringValue::Create(); // defaults to NULL
+ else
+ dv = FdoStringValue::Create(aggrStats.stringVal);
+ break;
+
+ case FdoDataType_DateTime:
+ if (aggrStats.isNull)
+ dv = FdoDateTimeValue::Create(); // defaults to NULL
+ else
+ dv = FdoDateTimeValue::Create(aggrStats.dateTimeVal);
+ break;
+
default:
throw FdoException::Create(FdoException::NLSGetMessage(FDO_NLSID(FDO_57_UNEXPECTEDERROR)));
}
@@ -260,34 +274,63 @@
// If it is a number, get the result (cast to double); in the case of COUNT(),
// this could be any type (e.g. geometry) so don't complain if not numeric:
double d = 0.0;
+ FdoString* strResult = NULL;
+ FdoDateTime dateTimeResult;
bool bValueIsNull = false;
+ FdoDataType resultDataType;
if (GetResultPropertyType() == FdoPropertyType_DataProperty)
{
- FdoDataType dataType = GetResultDataType();
- if (dataType == FdoDataType_Double)
+ resultDataType = GetResultDataType();
+ if (resultDataType == FdoDataType_Double)
d = GetDoubleResult(bValueIsNull);
- else if (dataType == FdoDataType_Single)
+ else if (resultDataType == FdoDataType_Single)
d = (double)GetSingleResult(bValueIsNull);
- else if (dataType == FdoDataType_Decimal)
+ else if (resultDataType == FdoDataType_Decimal)
d = (double)GetDecimalResult(bValueIsNull);
- else if (dataType == FdoDataType_Byte)
+ else if (resultDataType == FdoDataType_Byte)
d = (double)GetByteResult(bValueIsNull);
- else if (dataType == FdoDataType_Int16)
+ else if (resultDataType == FdoDataType_Int16)
d = (double)GetInt16Result(bValueIsNull);
- else if (dataType == FdoDataType_Int32)
+ else if (resultDataType == FdoDataType_Int32)
d = (double)GetInt32Result(bValueIsNull);
- else if (dataType == FdoDataType_Int64)
+ else if (resultDataType == FdoDataType_Int64)
d = (double)GetInt64Result(bValueIsNull);
+ else if (resultDataType == FdoDataType_String)
+ strResult = GetStringResult(bValueIsNull);
+ else if (resultDataType == FdoDataType_DateTime)
+ dateTimeResult = GetDateTimeResult(bValueIsNull);
}
// Handle the aggregate function logic:
AggregateStats &aggrStats = m_aggrStats.at(m_aggrStatsIndex);
if (0==wcscmp(expr.GetName(), FDO_FUNCTION_MIN))
{
- if (!bValueIsNull && (aggrStats.isNull || (d < aggrStats.doubleVal)))
+ if (!bValueIsNull)
{
- aggrStats.doubleVal = d;
- aggrStats.isNull = false;
+ if (resultDataType==FdoDataType_String)
+ {
+ if (aggrStats.isNull || (0>wcscmp(strResult, aggrStats.stringVal)))
+ {
+ aggrStats.stringVal = strResult;
+ aggrStats.isNull = false;
+ }
+ }
+ else if (resultDataType==FdoDataType_DateTime)
+ {
+ if (aggrStats.isNull || (0>FdoCommonMiscUtil::CompareDateTimes(dateTimeResult, aggrStats.dateTimeVal)))
+ {
+ aggrStats.dateTimeVal = dateTimeResult;
+ aggrStats.isNull = false;
+ }
+ }
+ else // datatype is decimal, double, single, int16, int32, etc
+ {
+ if (aggrStats.isNull || (d < aggrStats.doubleVal))
+ {
+ aggrStats.doubleVal = d;
+ aggrStats.isNull = false;
+ }
+ }
}
}
else if (0==wcscmp(expr.GetName(), FDO_FUNCTION_AVG))
@@ -310,10 +353,32 @@
}
else if (0==wcscmp(expr.GetName(), FDO_FUNCTION_MAX))
{
- if (!bValueIsNull && (aggrStats.isNull || (d > aggrStats.doubleVal)))
+ if (!bValueIsNull)
{
- aggrStats.doubleVal = d;
- aggrStats.isNull = false;
+ if (resultDataType==FdoDataType_String)
+ {
+ if (aggrStats.isNull || (0<wcscmp(strResult, aggrStats.stringVal)))
+ {
+ aggrStats.stringVal = strResult;
+ aggrStats.isNull = false;
+ }
+ }
+ else if (resultDataType==FdoDataType_DateTime)
+ {
+ if (aggrStats.isNull || (0<FdoCommonMiscUtil::CompareDateTimes(dateTimeResult, aggrStats.dateTimeVal)))
+ {
+ aggrStats.dateTimeVal = dateTimeResult;
+ aggrStats.isNull = false;
+ }
+ }
+ else // datatype is decimal, double, single, int16, int32, etc
+ {
+ if (aggrStats.isNull || (d > aggrStats.doubleVal))
+ {
+ aggrStats.doubleVal = d;
+ aggrStats.isNull = false;
+ }
+ }
}
}
else if (0==wcscmp(expr.GetName(), FDO_FUNCTION_SUM))
Added: trunk/Utilities/TestCommon/Inc/TestCommonFileUtil.h
===================================================================
--- trunk/Utilities/TestCommon/Inc/TestCommonFileUtil.h (rev 0)
+++ trunk/Utilities/TestCommon/Inc/TestCommonFileUtil.h 2007-02-22 14:28:04 UTC (rev 2583)
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2004-2006 Autodesk, Inc.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of version 2.1 of the GNU Lesser
+* General Public License as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * Revision Control Modification History
+ *
+ * $Id: $
+ * $Author: $
+ * $DateTime: $
+ * $Change: $
+ *
+ */
+
+#ifndef TESTCOMMONFILEUTIL___H
+#define TESTCOMMONFILEUTIL___H 1
+
+#ifdef _WIN32
+#pragma once
+#endif
+
+
+//
+// File-based test utilities common to many providers
+class TestCommonFileUtil
+{
+public:
+ // Compare the contents of 2 files, and return -1 if they don't match, 0 otherwise
+ static FdoInt32 CompareFiles( const char* file1Name, const char* file2Name );
+
+ // Compare the contents of 2 files, and throw a CPPUNIT exception if they do not match
+ static void CompareFilesAndThrow( const char* masterFileName, const char* outFileName );
+
+ // Compare the contents of 2 files, with a start byte offset and the number of bytes to compare (-1 to compare all bytes)
+ static void CompareFiles (const wchar_t* file1Name, const wchar_t* file2Name, unsigned long startByteOffset = 0L, unsigned long bytesToCompare = (unsigned long) -1L);
+};
+
+#endif // TESTCOMMONFILEUTIL___H
+
Property changes on: trunk/Utilities/TestCommon/Inc/TestCommonFileUtil.h
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/Utilities/TestCommon/Inc/TestCommonGeomUtil.h
===================================================================
--- trunk/Utilities/TestCommon/Inc/TestCommonGeomUtil.h (rev 0)
+++ trunk/Utilities/TestCommon/Inc/TestCommonGeomUtil.h 2007-02-22 14:28:04 UTC (rev 2583)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2004-2006 Autodesk, Inc.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of version 2.1 of the GNU Lesser
+* General Public License as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * Revision Control Modification History
+ *
+ * $Id: $
+ * $Author: $
+ * $DateTime: $
+ * $Change: $
+ *
+ */
+
+#ifndef TESTCOMMONGEOMUTIL___H
+#define TESTCOMMONGEOMUTIL___H 1
+
+#ifdef _WIN32
+#pragma once
+#endif
+
+
+//
+// Geometry-based test utilities common to many providers
+class TestCommonGeomUtil
+{
+public:
+ // Compare two geometries for equivalence:
+ static bool GeometriesEquivalent (FdoIGeometry *geom1, FdoIGeometry *geom2);
+ static bool LinearRingsEquivalent (FdoILinearRing* lr1, FdoILinearRing* lr2);
+ static bool PointsEquivalent (FdoIDirectPosition* pos1, FdoIDirectPosition* pos2);
+
+ // Print out info about the given geometry (type, length, area, etc):
+ static void PrintGeometryAnalysis( const wchar_t *class_name, int index, FdoByteArray * geom_fgf, double length, double area, bool verbose);
+};
+
+#endif // TESTCOMMONGEOMUTIL___H
Property changes on: trunk/Utilities/TestCommon/Inc/TestCommonGeomUtil.h
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/Utilities/TestCommon/Inc/TestCommonMiscUtil.h
===================================================================
--- trunk/Utilities/TestCommon/Inc/TestCommonMiscUtil.h 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/TestCommon/Inc/TestCommonMiscUtil.h 2007-02-22 14:28:04 UTC (rev 2583)
@@ -33,15 +33,13 @@
//
// Misc commonly-used utility functions:
void TestCommonFail (FdoException* ge);
+void TestCommonFail (char* error);
-
//
-// Common select-related tests
+// Utilities common to many unit tests
class TestCommonMiscUtil
{
public:
- void duplicateComputedIdTest (FdoIConnection* conn, FdoString* className, FdoString* propName);
-
// Retrieve the named property value from a property value collection.
// Create and add the property value to the collection if it is not already there.
static FdoPropertyValue* AddNewProperty( FdoPropertyValueCollection* propertyValues, FdoString* name );
@@ -94,6 +92,13 @@
static void SetupLeakReport();
#endif
+ // Get time on system clock (in seconds) -- used for computing elapsed time.
+ static double GetTime_S(void);
+
+ // check that 2 doubles are roughly equal:
+ static bool FuzzyEqual (const double d1, const double d2);
+
+
protected:
static FdoPtr<FdoDataValue> ArgsToDataValue( va_list& arguments );
Added: trunk/Utilities/TestCommon/Inc/TestCommonSchemaUtil.h
===================================================================
--- trunk/Utilities/TestCommon/Inc/TestCommonSchemaUtil.h (rev 0)
+++ trunk/Utilities/TestCommon/Inc/TestCommonSchemaUtil.h 2007-02-22 14:28:04 UTC (rev 2583)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2004-2006 Autodesk, Inc.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of version 2.1 of the GNU Lesser
+* General Public License as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ * Revision Control Modification History
+ *
+ * $Id: $
+ * $Author: $
+ * $DateTime: $
+ * $Change: $
+ *
+ */
+
+#ifndef TESTCOMMONSCHEMAUTIL___H
+#define TESTCOMMONSCHEMAUTIL___H 1
+
+#ifdef _WIN32
+#pragma once
+#endif
+
+
+//
+// Schema-based test utilities common to many providers
+class TestCommonSchemaUtil
+{
+public:
+ // Delete a class (if bDeleteRowsOnly==false) or delete the rows of a class (if bDeleteRowsOnly==true):
+ static void CleanUpClass(FdoIConnection *connection, const wchar_t* schema_name, const wchar_t* class_name, bool bDeleteRowsOnly=false);
+};
+
+#endif // TESTCOMMONSCHEMAUTIL___H
+
Property changes on: trunk/Utilities/TestCommon/Inc/TestCommonSchemaUtil.h
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/Utilities/TestCommon/Inc/stdafx.h
===================================================================
--- trunk/Utilities/TestCommon/Inc/stdafx.h 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/TestCommon/Inc/stdafx.h 2007-02-22 14:28:04 UTC (rev 2583)
@@ -72,7 +72,15 @@
using namespace std;
#endif
+#ifdef _WIN32
+#include <io.h>
+#include <stddef.h>
+#else
+#include <sys/time.h>
+#endif
+#include <math.h>
+
#include <FdoStd.h>
#include <Fdo/Expression/DataValueCollection.h>
#include <Fdo.h>
Modified: trunk/Utilities/TestCommon/Makefile.am
===================================================================
--- trunk/Utilities/TestCommon/Makefile.am 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/TestCommon/Makefile.am 2007-02-22 14:28:04 UTC (rev 2583)
@@ -27,12 +27,18 @@
Src/TestCommonConstraints.cpp \
Src/TestCommonFeatureCommands.cpp \
Src/TestCommonMiscUtil.cpp \
+ Src/TestCommonFileUtil.cpp \
+ Src/TestCommonGeomUtil.cpp \
+ Src/TestCommonSchemaUtil.cpp \
Src/stdafx.cpp
noinst_HEADERS = $(libTestCommon_la_SOURCES) \
Inc/TestCommonConstraints.h \
Inc/TestCommonFeatureCommands.h \
Inc/TestCommonMiscUtil.h \
+ Inc/TestCommonFileUtil.h \
+ Inc/TestCommonGeomUtil.h \
+ Inc/TestCommonSchemaUtil.h \
Inc/TestCommon.h \
Inc/stdafx.h
Added: trunk/Utilities/TestCommon/Src/TestCommonFileUtil.cpp
===================================================================
--- trunk/Utilities/TestCommon/Src/TestCommonFileUtil.cpp (rev 0)
+++ trunk/Utilities/TestCommon/Src/TestCommonFileUtil.cpp 2007-02-22 14:28:04 UTC (rev 2583)
@@ -0,0 +1,136 @@
+/*
+ *
+* Copyright (C) 2004-2006 Autodesk, Inc.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of version 2.1 of the GNU Lesser
+* General Public License as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*
+ * Revision Control Modification History
+ *
+ * $Id: $
+ * $Author: $
+ * $DateTime: $
+ * $Change: $
+ *
+ */
+
+#include "stdafx.h"
+#include "TestCommonFileUtil.h"
+#include "FdoCommonFile.h"
+
+
+void TestCommonFileUtil::CompareFilesAndThrow( const char* masterFileName, const char* outFileName )
+{
+ if ( CompareFiles( masterFileName, outFileName ) != 0 ) {
+ char buffer[5000];
+ sprintf( buffer, "Output file %s differs from expected output file %s", outFileName, masterFileName );
+ CPPUNIT_FAIL (buffer);
+ }
+}
+
+FdoInt32 TestCommonFileUtil::CompareFiles( const char* file1Name, const char* file2Name )
+{
+ char buffer[500];
+ char buffer1[5000];
+ char buffer2[5000];
+
+ FdoInt32 retcode = -1;
+
+ FILE* fp1 = fopen( file1Name, "r" );
+ FILE* fp2 = fopen( file2Name, "r" );
+
+ if ( fp1 == NULL ) {
+ sprintf( buffer, "TestCommonFileUtil::CompareFiles: failed to open file %s", file1Name );
+ CPPUNIT_FAIL (buffer);
+ }
+
+ if ( fp2 == NULL ) {
+ fclose(fp1);
+ sprintf( buffer, "TestCommonFileUtil::CompareFiles: failed to open file %s", file2Name );
+ CPPUNIT_FAIL (buffer);
+ }
+
+ while ( fgets( buffer1, sizeof(buffer1-1), fp1 ) != NULL ) {
+ if ( !fgets( buffer2, sizeof(buffer2-1), fp2 ) )
+ // different: file2 has fewer lines.
+ goto the_exit;
+
+ if ( strcmp( buffer1, buffer2 ) )
+ // different: a line is different
+ goto the_exit;
+ }
+
+ if ( fgets( buffer2, sizeof(buffer2-1), fp2 ) )
+ // different: file2 has more lines.
+ goto the_exit;
+
+ retcode = 0;
+
+the_exit:
+ fclose(fp1);
+ fclose(fp2);
+
+ return( retcode );
+}
+
+
+void TestCommonFileUtil::CompareFiles (const wchar_t* file1Name, const wchar_t* file2Name, unsigned long startByteOffset, unsigned long bytesToCompare)
+{
+ FdoCommonFile file1;
+ FdoCommonFile file2;
+ FdoCommonFile::ErrorCode code;
+ unsigned char buffer1;
+ unsigned char buffer2;
+ unsigned long count;
+
+ if (file1.OpenFile (file1Name, FdoCommonFile::IDF_OPEN_READ, code))
+ if (file2.OpenFile (file2Name, FdoCommonFile::IDF_OPEN_READ, code))
+ {
+ file1.SetFilePointer (startByteOffset);
+ file2.SetFilePointer (startByteOffset);
+ if (-1L == bytesToCompare)
+ {
+ file2.GetFileSize (bytesToCompare);
+ file1.GetFileSize (count);
+ if (count > bytesToCompare)
+ bytesToCompare = count;
+ }
+ count = 0;
+ while (file1.ReadFile (&buffer1, 1L))
+ if (file2.ReadFile (&buffer2, 1L))
+ {
+ // The 29th byte is LDID. The original file might not have it set but (i.e. is 0) but the
+ // copy file does (takes the locale into account).
+ bool isLDID = ((count + startByteOffset) == 29);
+ if ((buffer1 != buffer2) && (buffer1 != 0 && isLDID))
+ {
+ char message[1024];
+ sprintf (message, "compare error at offset 0x%x, expected 0x%x, got 0x%x", count + startByteOffset, buffer2, buffer1);
+ CPPUNIT_FAIL (message);
+ }
+ count++;
+ if (count > bytesToCompare)
+ return;
+ }
+ else
+ CPPUNIT_FAIL ("reference has fewer bytes");
+ // check the file2 file has been sucked dry too
+ CPPUNIT_ASSERT_MESSAGE ("reference has more bytes", !file2.ReadFile (&buffer2, 1L));
+
+ }
+ else
+ CPPUNIT_FAIL ("can't open reference file");
+ else
+ CPPUNIT_FAIL ("can't open target file");
+}
+
Property changes on: trunk/Utilities/TestCommon/Src/TestCommonFileUtil.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Added: trunk/Utilities/TestCommon/Src/TestCommonGeomUtil.cpp
===================================================================
--- trunk/Utilities/TestCommon/Src/TestCommonGeomUtil.cpp (rev 0)
+++ trunk/Utilities/TestCommon/Src/TestCommonGeomUtil.cpp 2007-02-22 14:28:04 UTC (rev 2583)
@@ -0,0 +1,326 @@
+/*
+ *
+* Copyright (C) 2004-2006 Autodesk, Inc.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of version 2.1 of the GNU Lesser
+* General Public License as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*
+ * Revision Control Modification History
+ *
+ * $Id: $
+ * $Author: $
+ * $DateTime: $
+ * $Change: $
+ *
+ */
+
+#include "stdafx.h"
+#include <FdoSpatial.h>
+#include "TestCommonGeomUtil.h"
+#include "TestCommonMiscUtil.h"
+
+
+bool TestCommonGeomUtil::GeometriesEquivalent(FdoIGeometry *geom1, FdoIGeometry *geom2)
+{
+ bool bRet = true;
+ FdoGeometryType type1 = geom1->GetDerivedType();
+ FdoGeometryType type2 = geom2->GetDerivedType();
+ FdoDimensionality dim1 = (FdoDimensionality)geom1->GetDimensionality();
+ FdoDimensionality dim2 = (FdoDimensionality)geom1->GetDimensionality();
+
+ // Make sure types are the same:
+ if (type1 != type2)
+ return false;
+
+ // Make sure dimensionalities are the same:
+ if (dim1 != dim2)
+ return false;
+
+ // Make sure contents are the same:
+ FdoPtr<FdoIDirectPosition> pos1;
+ FdoPtr<FdoIDirectPosition> pos2;
+ bool bHasZ = (dim1 & FdoDimensionality_Z) > 0;
+ bool bHasM = (dim1 & FdoDimensionality_M) > 0;
+ switch (type1)
+ {
+ case FdoGeometryType_Point:
+ {
+ FdoIPoint* p1 = (FdoIPoint*)geom1;
+ FdoIPoint* p2 = (FdoIPoint*)geom2;
+ pos1 = p1->GetPosition();
+ pos2 = p2->GetPosition();
+ if (!PointsEquivalent(pos1, pos2))
+ return false;
+ }
+ break;
+
+ case FdoGeometryType_LineString:
+ {
+ FdoILineString* l1 = (FdoILineString*)geom1;
+ FdoILineString* l2 = (FdoILineString*)geom2;
+ FdoInt32 iCount1 = l1->GetCount();
+ FdoInt32 iCount2 = l2->GetCount();
+ if (iCount1 != iCount2)
+ return false;
+ for (FdoInt32 i=0; i<iCount1; i++)
+ {
+ pos1 = l1->GetItem(i);
+ pos2 = l2->GetItem(i);
+ if (!PointsEquivalent(pos1, pos2))
+ return false;
+ }
+ }
+ break;
+
+ case FdoGeometryType_Polygon:
+ {
+ FdoIPolygon* p1 = (FdoIPolygon*)geom1;
+ FdoIPolygon* p2 = (FdoIPolygon*)geom2;
+ FdoPtr<FdoILinearRing> ring1 = p1->GetExteriorRing();
+ FdoPtr<FdoILinearRing> ring2 = p2->GetExteriorRing();
+ if (!LinearRingsEquivalent(ring1, ring2))
+ return false;
+ FdoInt32 iIntRingCount1 = p1->GetInteriorRingCount();
+ FdoInt32 iIntRingCount2 = p2->GetInteriorRingCount();
+ if (iIntRingCount1 != iIntRingCount2)
+ return false;
+ for (FdoInt32 i=0; i<iIntRingCount1; i++)
+ {
+ ring1 = p1->GetInteriorRing(i);
+ ring2 = p2->GetInteriorRing(i);
+ if (!LinearRingsEquivalent(ring1, ring2))
+ return false;
+ }
+ }
+ break;
+
+ case FdoGeometryType_MultiPoint:
+ {
+ FdoIMultiPoint* multi1 = (FdoIMultiPoint*)geom1;
+ FdoIMultiPoint* multi2 = (FdoIMultiPoint*)geom2;
+ FdoInt32 count1 = multi1->GetCount();
+ FdoInt32 count2 = multi2->GetCount();
+ if (count1 != count2)
+ return false;
+ for (FdoInt32 i=0; i<count1; i++)
+ {
+ FdoPtr<FdoIGeometry> item1 = multi1->GetItem(i);
+ FdoPtr<FdoIGeometry> item2 = multi2->GetItem(i);
+ if (!GeometriesEquivalent(item1,item2))
+ return false;
+ }
+ }
+ break;
+
+ case FdoGeometryType_MultiLineString:
+ {
+ FdoIMultiLineString* multi1 = (FdoIMultiLineString*)geom1;
+ FdoIMultiLineString* multi2 = (FdoIMultiLineString*)geom2;
+ FdoInt32 count1 = multi1->GetCount();
+ FdoInt32 count2 = multi2->GetCount();
+ if (count1 != count2)
+ return false;
+ for (FdoInt32 i=0; i<count1; i++)
+ {
+ FdoPtr<FdoIGeometry> item1 = multi1->GetItem(i);
+ FdoPtr<FdoIGeometry> item2 = multi2->GetItem(i);
+ if (!GeometriesEquivalent(item1,item2))
+ return false;
+ }
+ }
+ break;
+
+ case FdoGeometryType_MultiPolygon:
+ {
+ FdoIMultiPolygon* multi1 = (FdoIMultiPolygon*)geom1;
+ FdoIMultiPolygon* multi2 = (FdoIMultiPolygon*)geom2;
+ FdoInt32 count1 = multi1->GetCount();
+ FdoInt32 count2 = multi2->GetCount();
+ if (count1 != count2)
+ return false;
+ for (FdoInt32 i=0; i<count1; i++)
+ {
+ FdoPtr<FdoIGeometry> item1 = multi1->GetItem(i);
+ FdoPtr<FdoIGeometry> item2 = multi2->GetItem(i);
+ if (!GeometriesEquivalent(item1,item2))
+ return false;
+ }
+ }
+ break;
+
+ case FdoGeometryType_MultiGeometry:
+ case FdoGeometryType_CurveString:
+ case FdoGeometryType_CurvePolygon:
+ case FdoGeometryType_MultiCurveString:
+ case FdoGeometryType_MultiCurvePolygon:
+ default:
+ throw FdoException::Create(L"Don't know how to compare these 2 geometries");
+ break;
+ }
+
+ return bRet;
+}
+
+
+bool TestCommonGeomUtil::PointsEquivalent(FdoIDirectPosition* pos1, FdoIDirectPosition* pos2)
+{
+ if (pos1->GetDimensionality() != pos2->GetDimensionality())
+ return false;
+
+ bool bHasZ = (pos1->GetDimensionality() & FdoDimensionality_Z) > 0;
+ bool bHasM = (pos1->GetDimensionality() & FdoDimensionality_M) > 0;
+
+ if (!TestCommonMiscUtil::FuzzyEqual(pos1->GetX(), pos2->GetX()))
+ return false;
+ if (!TestCommonMiscUtil::FuzzyEqual(pos1->GetY(), pos2->GetY()))
+ return false;
+ if (bHasZ && !TestCommonMiscUtil::FuzzyEqual(pos1->GetZ(),pos2->GetZ()))
+ return false;
+ if (bHasM && !TestCommonMiscUtil::FuzzyEqual(pos1->GetM(),pos2->GetM()))
+ return false;
+
+ return true;
+}
+
+
+bool TestCommonGeomUtil::LinearRingsEquivalent(FdoILinearRing* lr1, FdoILinearRing* lr2)
+{
+ FdoInt32 count1 = lr1->GetCount();
+ FdoInt32 count2 = lr2->GetCount();
+ if (count1 != count2)
+ return false;
+
+ // Compare all the points in the 2 linear rings:
+ for (FdoInt32 i=0; i<count1; i++)
+ {
+ FdoPtr<FdoIDirectPosition> pos1 = lr1->GetItem(i);
+ FdoPtr<FdoIDirectPosition> pos2 = lr2->GetItem(i);
+ if (!PointsEquivalent(pos1,pos2))
+ return false;
+ }
+
+ return true;
+}
+
+
+
+void TestCommonGeomUtil::PrintGeometryAnalysis( const wchar_t *class_name, int index, FdoByteArray * geom_fgf, double length0, double area0, bool verbose)
+{
+ FdoPtr<FdoFgfGeometryFactory> gf = FdoFgfGeometryFactory::GetInstance ();
+ FdoIGeometry *geom = gf->CreateGeometryFromFgf( geom_fgf );
+
+ switch (geom->GetDerivedType())
+ {
+ case FdoGeometryType_LineString:
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_LineString!\n", class_name, index);
+ break;
+
+ case FdoGeometryType_Point:
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_Point!\n", class_name, index);
+ break;
+
+ case FdoGeometryType_Polygon:
+ {
+ FdoIPolygon *poly = (FdoIPolygon *)geom;
+ FdoILinearRing *extRing = poly->GetExteriorRing();
+ double area = FdoSpatialUtility::ComputeLinearRingArea( extRing );
+ double length = FdoSpatialUtility::ComputeLinearRingLength( extRing );
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_Polygon length=%lf (%lf) area=%lf (%lf)\n", class_name, index, length, length0, area, area0);
+
+ for ( int j = 0; j < poly->GetInteriorRingCount(); j++ )
+ {
+ FdoILinearRing *intRing = poly->GetInteriorRing(j);
+ area = FdoSpatialUtility::ComputeLinearRingArea( intRing );
+ if (verbose)
+ printf(" %d. intPolygon area=%lf\n", j, area);
+ FDO_SAFE_RELEASE(intRing);
+ }
+
+ FDO_SAFE_RELEASE(extRing);
+ }
+ break;
+
+ case FdoGeometryType_MultiPoint:
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_MultiPoint!\n", class_name, index);
+ break;
+
+ case FdoGeometryType_MultiGeometry:
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_MultiGeometry!\n", class_name, index);
+ break;
+
+ case FdoGeometryType_MultiLineString:
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_MultiLineString!\n", class_name, index);
+ break;
+
+ case FdoGeometryType_MultiPolygon:
+ {
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_MultiPolygon (%lf)\n", class_name, index, area0);
+
+ FdoIMultiPolygon *mpoly = (FdoIMultiPolygon *)geom;
+ for (int i = 0; i < mpoly->GetCount(); i++ )
+ {
+ FdoIPolygon *poly = mpoly->GetItem(i);
+ FdoILinearRing *extRing = poly->GetExteriorRing();
+ double area = FdoSpatialUtility::ComputeLinearRingArea( extRing );
+ double length = FdoSpatialUtility::ComputeLinearRingLength( extRing );
+ if (verbose)
+ printf(" %d. extPolygon length=%lf (%lf) area=%lf (%lf) \n", i, length, length0, area, area0);
+
+ for ( int j = 0; j < poly->GetInteriorRingCount(); j++ )
+ {
+ FdoILinearRing *intRing = poly->GetInteriorRing(j);
+ area = FdoSpatialUtility::ComputeLinearRingArea( intRing );
+ if (verbose)
+ printf(" %d. intPolygon area=%lf\n", j, area);
+ FDO_SAFE_RELEASE(intRing);
+ }
+ FDO_SAFE_RELEASE(poly);
+ FDO_SAFE_RELEASE(extRing);
+ }
+ }
+ break;
+
+ case FdoGeometryType_CurveString:
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_CurveString!\n", class_name, index);
+ break;
+
+ case FdoGeometryType_MultiCurveString:
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_MultiCurveString!\n", class_name, index);
+ break;
+
+ case FdoGeometryType_CurvePolygon:
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_CurvePolygon!\n", class_name, index);
+ break;
+
+ case FdoGeometryType_MultiCurvePolygon:
+ if (verbose)
+ printf("%ls-%d. FdoGeometryType_MultiCurvePolygon!\n", class_name, index);
+ break;
+
+ default:
+ ;
+ }
+
+ FDO_SAFE_RELEASE(geom);
+}
+
Property changes on: trunk/Utilities/TestCommon/Src/TestCommonGeomUtil.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/Utilities/TestCommon/Src/TestCommonMiscUtil.cpp
===================================================================
--- trunk/Utilities/TestCommon/Src/TestCommonMiscUtil.cpp 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/TestCommon/Src/TestCommonMiscUtil.cpp 2007-02-22 14:28:04 UTC (rev 2583)
@@ -50,6 +50,15 @@
CPPUNIT_FAIL (multibyte);
}
+
+void TestCommonFail (char* error)
+{
+ char message[4096];
+ sprintf (message, "\nFAILURE: %s\n", error);
+ CPPUNIT_FAIL (message);
+}
+
+
FdoPropertyValue* TestCommonMiscUtil::AddNewProperty( FdoPropertyValueCollection* propertyValues, FdoString* name )
{
FdoPropertyValue* propertyValue = propertyValues->FindItem( name );
@@ -256,3 +265,43 @@
return(0);
}
#endif
+
+
+
+// Get time on system clock (in seconds) -- used for computing elapsed time.
+double TestCommonMiscUtil::GetTime_S(void)
+{
+#ifdef _WIN32
+
+ double our_time;
+
+ our_time = GetTickCount() / 1000.0;
+ return our_time;
+
+#else
+
+ struct timeval this_time;
+ static struct timezone time_zone = { 0, 0 };
+ double sec, micro, time;
+
+
+ if (gettimeofday(&this_time, &time_zone) == -1)
+ return (double) 0.0;
+
+ micro = (double) ((double) this_time.tv_usec / (double) 1000000.0);
+ sec = (double) this_time.tv_sec;
+ time = micro + sec;
+ return time;
+
+#endif
+}
+
+
+bool TestCommonMiscUtil::FuzzyEqual (const double d1, const double d2)
+{
+ if ((d1==0.0) || (d2==0.0))
+ return 1e-5 > fabs(d1 - d2);
+ else
+ return 1e-5 > fabs(1.0 - (d2 / d1));
+}
+
Added: trunk/Utilities/TestCommon/Src/TestCommonSchemaUtil.cpp
===================================================================
--- trunk/Utilities/TestCommon/Src/TestCommonSchemaUtil.cpp (rev 0)
+++ trunk/Utilities/TestCommon/Src/TestCommonSchemaUtil.cpp 2007-02-22 14:28:04 UTC (rev 2583)
@@ -0,0 +1,88 @@
+/*
+ *
+* Copyright (C) 2004-2006 Autodesk, Inc.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of version 2.1 of the GNU Lesser
+* General Public License as published by the Free Software Foundation.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+*
+ * Revision Control Modification History
+ *
+ * $Id: $
+ * $Author: $
+ * $DateTime: $
+ * $Change: $
+ *
+ */
+
+#include "stdafx.h"
+#include "TestCommonSchemaUtil.h"
+#include "TestCommonMiscUtil.h"
+
+
+// Delete a class (if bDeleteRowsOnly==false) or delete the rows of a class (if bDeleteRowsOnly==true):
+void TestCommonSchemaUtil::CleanUpClass(FdoIConnection *connection, const wchar_t* schema_name, const wchar_t* class_name, bool bDeleteRowsOnly)
+{
+ try
+ {
+ FdoPtr<FdoIdentifier> identifier = FdoIdentifier::Create (class_name);
+ FdoPtr<FdoIDescribeSchema> descSchema = (FdoIDescribeSchema*)connection->CreateCommand(FdoCommandType_DescribeSchema);
+ // NOTE: in case the schema_name no longer exists, we dont specify it up front because it will cause an exception:
+ //if (NULL!=schema_name)
+ // descSchema->SetSchemaName(schema_name);
+ FdoPtr<FdoFeatureSchemaCollection> schemas = descSchema->Execute();
+
+ bool bFound = false;
+ for (FdoInt32 iSchemaIndex = 0; iSchemaIndex<schemas->GetCount(); iSchemaIndex++)
+ {
+ FdoPtr<FdoFeatureSchema> schema = schemas->GetItem(iSchemaIndex);
+ if ((NULL==schema_name) || (0==wcscmp(schema->GetName(), schema_name)))
+ {
+ FdoPtr<FdoClassCollection> classes = schema->GetClasses();
+ for (FdoInt32 iClassIndex = 0; iClassIndex<classes->GetCount(); iClassIndex++)
+ {
+ FdoPtr<FdoClassDefinition> classDef = classes->GetItem(iClassIndex);
+ if (0==FdoCommonOSUtil::wcsicmp(classDef->GetName(), identifier->GetName ()))
+ {
+ bFound = true;
+ // delete the rows of this class, but not the class itself:
+ FdoPtr<FdoIDelete> deleteCmd = (FdoIDelete*)connection->CreateCommand (FdoCommandType_Delete);
+ deleteCmd->SetFeatureClassName(classDef->GetName());
+ deleteCmd->Execute();
+
+ if (!bDeleteRowsOnly)
+ {
+ // delete the entire class:
+ classDef->Delete();
+ FdoPtr<FdoIApplySchema> applySchema = (FdoIApplySchema*)connection->CreateCommand(FdoCommandType_ApplySchema);
+ applySchema->SetFeatureSchema(schema);
+ applySchema->Execute();
+ }
+
+ break;
+ }
+ }
+ }
+
+ if (bFound)
+ break;
+ }
+
+ // recurse with default schema, if class not found:
+ if (!bFound && (NULL!=schema_name) && (wcslen(schema_name)>0))
+ CleanUpClass(connection, NULL, class_name);
+ }
+ catch (FdoException* ge)
+ {
+ TestCommonFail (ge);
+ }
+}
Property changes on: trunk/Utilities/TestCommon/Src/TestCommonSchemaUtil.cpp
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: trunk/Utilities/TestCommon/TestCommon.vcproj
===================================================================
--- trunk/Utilities/TestCommon/TestCommon.vcproj 2007-02-22 14:26:12 UTC (rev 2582)
+++ trunk/Utilities/TestCommon/TestCommon.vcproj 2007-02-22 14:28:04 UTC (rev 2583)
@@ -195,9 +195,21 @@
>
</File>
<File
+ RelativePath=".\Src\TestCommonFileUtil.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\Src\TestCommonGeomUtil.cpp"
+ >
+ </File>
+ <File
RelativePath=".\Src\TestCommonMiscUtil.cpp"
>
</File>
+ <File
+ RelativePath=".\Src\TestCommonSchemaUtil.cpp"
+ >
+ </File>
</Filter>
<Filter
Name="Header Files"
@@ -216,9 +228,21 @@
>
</File>
<File
+ RelativePath=".\Inc\TestCommonFileUtil.h"
+ >
+ </File>
+ <File
+ RelativePath=".\Inc\TestCommonGeomUtil.h"
+ >
+ </File>
+ <File
RelativePath=".\Inc\TestCommonMiscUtil.h"
>
</File>
+ <File
+ RelativePath=".\Inc\TestCommonSchemaUtil.h"
+ >
+ </File>
</Filter>
<Filter
Name="Resource Files"
More information about the fdo-commits
mailing list