xmltester.cpp

来自「一个很好的vc底层代码」· C++ 代码 · 共 663 行 · 第 1/2 页

CPP
663
字号
/********************************************************************** * $Id: XMLTester.cpp,v 1.48.2.4 2005/06/21 12:22:29 strk Exp $ * * GEOS - Geometry Engine Open Source * http://geos.refractions.net * * Copyright (C) 2001-2002 Vivid Solutions Inc. * Copyright (C) 2005 Refractions Research Inc. * * This is free software; you can redistribute and/or modify it under * the terms of the GNU Lesser General Public Licence as published * by the Free Software Foundation.  * See the COPYING file for more information. * **********************************************************************///#define _CRTDBG_MAP_ALLOC//#include <stdlib.h>#ifdef _MSC_VER#include <crtdbg.h>#endif#include <string>#include <iostream>#include <fstream>#include <geos/util.h>#include <geos/geomgraph.h>#include <geos/io.h>#include <geos/opRelate.h>#include <geos/opPolygonize.h>#include <geos/profiler.h>#include "../io/markup/MarkupSTL.h"#include <geos/unload.h>#include "XMLTester.h"//#include "util.h"//#include "geomgraph.h"//#include "io.h"//#include "opRelate.h"//#include "MarkupSTL.h"#ifdef _MSC_VER#include <windows.h>#include "Stackwalker.h"#endifusing namespace std;using namespace geos;//using geos::Polygon; // for mingw providing a Polygon global functionXMLTester::XMLTester(const char *source){	r=NULL;	w=NULL;	pm=NULL;	factory=NULL;	failed=succeeded=caseCount=testCount=0;	xml.Load(source);	out=TEST_DESCR+GEOM_A_IN+GEOM_A_OUT+GEOM_B_IN+GEOM_B_OUT+TEST_OP+TEST_RESULT;}voidXMLTester::run(){	xml.ResetPos();	xml.FindElem("run");	xml.FindChildElem("precisionModel");	parsePrecisionModel();	while (xml.FindChildElem("case")) {		try {			parseCase();		} catch (GEOSException *exc) {			cerr<<exc->toString()<<endl;		}	}	cout << "Failed: ";	cout << failed << endl;	cout << "Succeeded: ";	cout << succeeded << endl;}voidXMLTester::parsePrecisionModel(){	string precisionModel;	/* This does not seem to work... */	//precisionModel=xml.GetChildAttrib("type");	string scaleStr=xml.GetChildAttrib("scale");	if ( scaleStr == "" ) {		pm=new PrecisionModel();		cout << "Precision Model: FLOATING" << endl;	} else {		char* stopstring;		//string scaleStr=xml.GetChildAttrib("scale");		string offsetXStr=xml.GetChildAttrib("offsetx");		string offsetYStr=xml.GetChildAttrib("offsety");		double scale=strtod(scaleStr.c_str(),&stopstring);		double offsetX=strtod(offsetXStr.c_str(),&stopstring);		double offsetY=strtod(offsetYStr.c_str(),&stopstring);		pm=new PrecisionModel(scale,offsetX,offsetY);		cout << "Precision Model: FIXED (scale: "<<scale<<", offsetX: "<<offsetX<<", offsetY: "<<offsetY<<")" << endl;	}	factory = new GeometryFactory(pm);	r=new WKTReader(factory);	w=new WKTWriter();}voidXMLTester::parseCase(){	string geomAin;	string geomBin;	string geomAout;	string geomBout;	string desc;	gA=NULL;	gB=NULL;	xml.IntoElem();	caseCount++;	xml.FindChildElem("desc");	desc=xml.GetChildData();	if (out & TEST_DESCR) {		cout << "Case #" << caseCount << endl;		cout << "\t" << desc << endl;	}	xml.FindChildElem("a");	geomAin=xml.GetChildData();	gA=r->read(geomAin);	geomAout=w->write(gA);	if (out &(GEOM_A_IN | GEOM_A_OUT)) {		cout << "\tGeometry A" << endl;		if (out & GEOM_A_IN)			cout << "\t\tIn:" << geomAin << endl;		if (out & GEOM_A_OUT)			cout << "\t\tOut:" << geomAout << endl;	}	if ( xml.FindChildElem("b") )	{		geomBin=xml.GetChildData();		gB=r->read(geomBin);		geomBout=w->write(gB);		if (out &(GEOM_B_IN | GEOM_B_OUT)) {			cout << "\tGeometry B" << endl;			if (out & GEOM_B_IN)				cout << "\t\tIn:" << geomBin << endl;			if (out & GEOM_B_OUT)				cout << "\t\tOut:" << geomBout << endl;		}	}	testCount=0;	while(xml.FindChildElem("test")) {		parseTest();	}			xml.OutOfElem();	delete gA;	delete gB;}voidXMLTester::parseTest(){	string opName;	string opSig;	string opArg1;	string opArg2;	string opArg3;	string opRes;	testCount++;	if (out & TEST_DESCR) {		cout << "\tTest #" << testCount << endl;	}	xml.IntoElem();	xml.FindChildElem("op");	opName=xml.GetChildAttrib("name");	opArg1=xml.GetChildAttrib("arg1");	opArg2=xml.GetChildAttrib("arg2");	opArg3=xml.GetChildAttrib("arg3");	opSig=xml.GetChildAttrib("arg3");	opRes=xml.GetChildData();	// trim blanks	string::size_type pos = opRes.find_first_not_of(" \t\n\r");	if (pos!=string::npos) opRes=opRes.substr(pos);	pos = opRes.find_last_not_of(" \t\n\r");	if (pos!=string::npos) opRes=opRes.substr(0, pos+1);	if (out & TEST_OP) {		Profile *profile = new Profile("op");		if (opName=="relate") {			cout << "\t\tOperation '" << opName << "[" << opSig <<"]' should be " << opRes << endl;			IntersectionMatrix *im=gA->relate(gB);			if (out & TEST_RESULT)				cout << "\t\tResult: matrix='" << im->toString() << "' result=" << (im->matches(opSig)?"true":"false") <<endl;			if (!im->matches(opSig)) {				failed++;			} else {				succeeded++;			}			delete im;		} else if (opName=="isValid") {			Geometry *gT=gA;			string gTname="A";			if ( opArg1 == "B" && gB ) {				gT=gB;				gTname="B";			} 			cout << "\t\tOperation '" << opName << "(" << gTname << ")' should be " << opRes << endl;			string result;			if (gT->isValid()) {				result="true";			} else {				result="false";			}			if (out & TEST_RESULT) {				if (result==opRes) {					cout << "\t\tResult: isValid='" << result << "' result=true"  <<endl;					succeeded++;				} else {					cout << "\t\tResult: isValid='" << result << "' result=false"  <<endl;					failed++;				}			}		} else if (opName=="intersection") {			Geometry *gRes=NULL;			Geometry *gRealRes=NULL;			gRes=r->read(opRes);			gRes->normalize();			cout << "\t\tOperation '" << opName << "[" << opSig <<"]' should be " << gRes->toString() << endl;			try {				gRealRes=gA->intersection(gB);				gRealRes->normalize();			} catch ( ... ) {				delete gRealRes;				delete gRes;				throw;			}			if (out & TEST_RESULT) {				if (gRes->compareTo(gRealRes)==0) {					cout << "\t\tResult: intersection='" << gRealRes->toString() << "' result=true"  <<endl;					succeeded++;				} else {					cout << "\t\tResult: intersection='" << gRealRes->toString() << "' result=false"  <<endl;					failed++;				}			}			delete gRes;			delete gRealRes;		} else if (opName=="union") {			Geometry *gRes=r->read(opRes);			gRes->normalize();			cout << "\t\tOperation '" << opName << "[" << opSig <<"]' should be " << gRes->toString() << endl;			Geometry *gRealRes=gA->Union(gB);			gRealRes->normalize();			if (out & TEST_RESULT) {				if (gRes->compareTo(gRealRes)==0) {					cout << "\t\tResult: union='" << gRealRes->toString() << "' result=true"  <<endl;					succeeded++;				} else {					cout << "\t\tResult: union='" << gRealRes->toString() << "' result=false"  <<endl;					failed++;				}			}			delete gRes;			delete gRealRes;		} else if (opName=="difference") {			Geometry *gRes=r->read(opRes);			gRes->normalize();			cout << "\t\tOperation '" << opName << "[" << opSig <<"]' should be " << gRes->toString() << endl;			Geometry *gRealRes=gA->difference(gB);			gRealRes->normalize();			if (out & TEST_RESULT) {				if (gRes->compareTo(gRealRes)==0) {					cout << "\t\tResult: difference='" << gRealRes->toString() << "' result=true"  <<endl;					succeeded++;				} else {					cout << "\t\tResult: difference='" << gRealRes->toString() << "' result=false"  <<endl;					failed++;				}			}			delete gRes;			delete gRealRes;		} else if (opName=="symdifference") {			Geometry *gRes=r->read(opRes);			gRes->normalize();			cout << "\t\tOperation '" << opName << "[" << opSig <<"]' should be " << gRes->toString() << endl;			Geometry *gRealRes=gA->symDifference(gB);			gRealRes->normalize();			if (out & TEST_RESULT) {				if (gRes->compareTo(gRealRes)==0) {					cout << "\t\tResult: symdifference='" << gRealRes->toString() << "' result=true"  <<endl;					succeeded++;				} else {					cout << "\t\tResult: symdifference='" << gRealRes->toString() << "' result=false"  <<endl;					failed++;				}			}			delete gRes;			delete gRealRes;		} else if (opName=="intersects") {			cout << "\t\tOperation '" << opName << " should be " << opRes << endl;			string result;			if (gA->intersects(gB)) {				result="true";			} else {				result="false";			}			if (out & TEST_RESULT) {				if (result==opRes) {					cout << "\t\tResult: intersects='" << result << "' result=true"  <<endl;					succeeded++;				} else {					cout << "\t\tResult: intersects='" << result << "' result=false"  <<endl;					failed++;				}			}		} else if (opName=="getboundary") {			Geometry *gT=gA;			string gTname="A";			if ( opArg1 == "B" && gB ) {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?