You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2007/02/03 18:19:14 UTC
svn commit: r503265 [4/6] - /incubator/uima/uimacpp/trunk/src/test/src/
Propchange: incubator/uima/uimacpp/trunk/src/test/src/test_cas.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/test/src/test_cas.vcproj
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_cas.vcproj?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_cas.vcproj (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_cas.vcproj Sat Feb 3 09:19:12 2007
@@ -0,0 +1,146 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="test_cas"
+ ProjectGUID="{87F00969-FF24-4446-A128-2F3EA5D00DE1}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(InputDir)\.."
+ IntermediateDirectory="..\Debug\$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=".;"$(APR_HOME)\include";"$(ICU_HOME)\include";"$(XERCES_HOME)\include";"$(JAVA_HOME)\include";"$(JAVA_HOME)\include\win32";"$(UIMACPP_HOME)\include";"$(UIMACPP_HOME)\include\apr""
+ PreprocessorDefinitions="UIMA_SUPPRESS_TIMING;WIN32;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="xerces-c_2.lib icuuc.lib libapr$(APR_VER).lib uimaD.lib"
+ OutputFile="$(OutDir)/test_cas.exe"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""$(APR_HOME)\Debug";"$(XERCES_HOME)\lib";"$(ICU_HOME)\lib";"$(UIMACPP_HOME)\lib""
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(InputDir)\.."
+ IntermediateDirectory="..\Release\$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="3"
+ AdditionalIncludeDirectories=".;"$(APR_HOME)\include";"$(ICU_HOME)\include";"$(XERCES_HOME)\include";"$(JAVA_HOME)\include";"$(JAVA_HOME)\include\win32";"$(UIMACPP_HOME)\include";"$(UIMACPP_HOME)\include\apr""
+ PreprocessorDefinitions="UIMA_SUPPRESS_TIMING;TRACEOFF;NDEBUG;WIN32;_CONSOLE"
+ BasicRuntimeChecks="0"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="xerces-c_2.lib icuuc.lib libapr$(APR_VER).lib uima.lib"
+ OutputFile="$(OutDir)/test_cas.exe"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""$(APR_HOME)\Release";"$(XERCES_HOME)\lib";"$(ICU_HOME)\lib";"$(UIMACPP_HOME)\lib""
+ GenerateDebugInformation="FALSE"
+ ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ <File
+ RelativePath="test_cas.cpp">
+ </File>
+ <File
+ RelativePath=".\tt_types.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Propchange: incubator/uima/uimacpp/trunk/src/test/src/test_cas.vcproj
------------------------------------------------------------------------------
svn:eol-style = CRLF
Added: incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.cpp?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.cpp Sat Feb 3 09:19:12 2007
@@ -0,0 +1,391 @@
+/** \file test_casserializer.cpp .
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-------------------------------------------------------------------------- */
+
+
+// define this first to get your application name added to command line
+// used inside "cmdline_driver_args.h"
+#define MAIN_TITLE _TEXT("UIMA Test CAS Serializer")
+
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+
+#include "uima/pragmas.hpp" //must be first include to surpress warnings
+#include "uima/api.hpp"
+#include "uima/internal_casimpl.hpp"
+#include "uima/casdefinition.hpp"
+#include "uima/internal_casserializer.hpp"
+#include "uima/internal_casdeserializer.hpp"
+#include <sys/stat.h>
+
+using namespace uima;
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+#ifndef NDEBUG
+#define ASSERT_OR_THROWEXCEPTION(x) assert(x)
+#else
+#define ASSERT_OR_THROWEXCEPTION(x) if (!(x)) { cerr << __FILE__ << ": Error in line " << __LINE__ << endl; exit(1); }
+#endif
+#define LOG(x) cout << __FILE__ << __LINE__ << ": " << x << endl
+/* ----------------------------------------------------------------------- */
+/* UTILS */
+/* ----------------------------------------------------------------------- */
+void displayException(util::ConsoleUI & console, Exception & crclException)
+/* ----------------------------------------------------------------------- */
+{
+ console.formatHeader(_TEXT("Exception"));
+ console.format(_TEXT("Exception error id"), crclException.getErrorInfo().getErrorId());
+ console.format(_TEXT("Exception name"), crclException.getName());
+ console.format(_TEXT("Exception what"), crclException.what());
+ console.format(_TEXT("Exception message"), crclException.getErrorInfo().getMessage().asString().c_str());
+ console.formatBool(_TEXT("Exception recoverable"), crclException.getErrorInfo().isRecoverable());
+ const TCHAR * cpszSavePrefix = ErrorInfo::getGlobalErrorInfoIndent();
+ ErrorInfo::setGlobalErrorInfoIndent(" ");
+ console.getOutputStream() << crclException.getErrorInfo() << endl;
+ ErrorInfo::setGlobalErrorInfoIndent(cpszSavePrefix);
+}
+
+
+template<class T>
+bool equalVectors(vector<T> const & crV1, vector<T> const & crV2, util::ConsoleUI * pConsole) {
+ bool bResult = true;
+ if ( crV1.size() != crV2.size() ) {
+ pConsole->getOutputStream() << "size 1: " << crV1.size() << ", size 2: " << crV2.size() << endl;
+ return false;
+ }
+
+ size_t i;
+ for (i=0; i<crV1.size(); ++i) {
+ bool bIsEqual = (crV1[i] == crV2[i]);
+
+ if (!bIsEqual) {
+ bResult = false;
+ }
+ }
+
+ if (!bResult) {
+ size_t j;
+ for (j=0; j<crV1.size(); ++j) {
+ if (crV1[j] != crV2[j]) {
+ pConsole->getOutputStream() << j << ": " << crV1[j] << " " << crV2[j] << endl;
+ }
+ }
+ }
+ return bResult;
+}
+
+/* ----------------------------------------------------------------------- */
+/* Tests */
+/* ----------------------------------------------------------------------- */
+
+void testSerializeDefinitions(util::ConsoleUI * pConsole) {
+ uima::internal::CASDefinition * iv_newCASDefinition;
+ uima::internal::SerializedCAS iv_serializedCAS;
+ uima::Timer iv_serializeTimerDefinitions;
+
+ /* create engine */
+ ErrorInfo errInfo;
+ UnicodeString filename("toktest.xml");
+ UnicodeString fn = ResourceManager::resolveFilename(filename, filename);
+
+ uima::TextAnalysisEngine * pEngine = TextAnalysisEngine::createTextAnalysisEngine
+ (UnicodeStringRef(fn).asUTF8().c_str(), errInfo);
+ if (pEngine == NULL ) {
+ LOG("Error: " << errInfo.asString());
+ ASSERT_OR_THROWEXCEPTION(false);
+ }
+ ASSERT_OR_THROWEXCEPTION(EXISTS(pEngine));
+ ASSERT_OR_THROWEXCEPTION( errInfo.getErrorId() == UIMA_ERR_NONE );
+
+ iv_newCASDefinition = uima::internal::CASDefinition::createCASDefinition(pEngine->getAnnotatorContext());
+
+ pConsole->info("Serializing Type System and Index definitions CAS");
+ uima::internal::CASSerializer serializer(true);
+ iv_serializedCAS.reset();
+
+ // serialize type system and index definition
+
+ uima::internal::CASDeserializer deserializer;
+
+ iv_serializeTimerDefinitions.reset();
+ iv_serializeTimerDefinitions.start();
+ serializer.serializeDefinitions(*iv_newCASDefinition, iv_serializedCAS);
+ iv_serializeTimerDefinitions.stop();
+#ifndef UIMA_SUPPRESS_TIMING
+ pConsole->format(" Serialization of Definitions", uima::Timer::timeString( iv_serializeTimerDefinitions.getAccumulatedTime() ).c_str() );
+#endif
+
+ iv_serializeTimerDefinitions.reset();
+ iv_serializeTimerDefinitions.start();
+ deserializer.deserializeDefinitions(iv_serializedCAS , *iv_newCASDefinition );
+ iv_serializeTimerDefinitions.stop();
+#ifndef UIMA_SUPPRESS_TIMING
+ pConsole->format(" Deserialization of Definitions", uima::Timer::timeString( iv_serializeTimerDefinitions.getAccumulatedTime() ).c_str() );
+#endif
+
+
+ // serializing again
+ uima::internal::SerializedCAS serializedCAS2;
+
+ serializer.serializeDefinitions(*iv_newCASDefinition, serializedCAS2);
+
+ // checking
+ pConsole->format("Checking", "type symbol table");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getTypeSymbolTable(), serializedCAS2.getTypeSymbolTable(), pConsole ));
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "type inheritance table");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getTypeInheritanceTable(), serializedCAS2.getTypeInheritanceTable(), pConsole));
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "feature symbol table");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getFeatureSymbolTable(), serializedCAS2.getFeatureSymbolTable(), pConsole));
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "feature offset table");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getFeatureOffsetTable(), serializedCAS2.getFeatureOffsetTable(), pConsole));
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "feature def table");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getFeatureDefinitionTable(), serializedCAS2.getFeatureDefinitionTable(), pConsole));
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "type priorities");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getTypePriorityTable(), serializedCAS2.getTypePriorityTable(), pConsole));
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "index IDs");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getIndexIDTable(), serializedCAS2.getIndexIDTable(), pConsole ));
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "index kinds");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getIndexKindTable(), serializedCAS2.getIndexKindTable(), pConsole) );
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "comparator start");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getComparatorStartTable(), serializedCAS2.getComparatorStartTable(), pConsole) );
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "comparator def");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getComparatorDefinitionTable(), serializedCAS2.getComparatorDefinitionTable(), pConsole) );
+ pConsole->format(" success", true);
+
+ delete iv_newCASDefinition;
+ delete pEngine;
+
+}
+
+void testSerializeData(util::ConsoleUI * pConsole ) {
+ pConsole->info("Serializing Document Data CAS");
+ uima::Timer iv_serializeTimerData;
+
+ ErrorInfo errInfo;
+ UnicodeString filename("toktest.xml");
+ UnicodeString fn = ResourceManager::resolveFilename(filename, filename);
+
+ uima::TextAnalysisEngine * pEngine =
+ TextAnalysisEngine::createTextAnalysisEngine(UnicodeStringRef(fn).asUTF8().c_str(), errInfo);
+ if (pEngine == NULL ) {
+ LOG("Error: " << errInfo.asString());
+ ASSERT_OR_THROWEXCEPTION(false);
+ }
+ ASSERT_OR_THROWEXCEPTION(EXISTS(pEngine));
+ ASSERT_OR_THROWEXCEPTION( errInfo.getErrorId() == UIMA_ERR_NONE );
+
+ /* read in a file */
+ UnicodeString dataFile("tdoc_001_en_850.asc");
+ UnicodeString datafn = ResourceManager::resolveFilename(dataFile, dataFile);
+ std::string dataFilename = UnicodeStringRef(datafn).asUTF8();
+ /* open file for read */
+ FILE * pFile = fopen( dataFilename.c_str(),"rb");
+ ASSERT_OR_THROWEXCEPTION(pFile != NULL );
+
+ /* allocate buffer for file contents */
+ struct stat stat_result;
+ stat(dataFilename.c_str(), &stat_result);
+ int filesize = stat_result.st_size;
+ char * pBuffer = new char[filesize+1];
+ ASSERT_OR_THROWEXCEPTION(pBuffer != NULL );
+
+ /* read the file */
+ size_t numread = fread(pBuffer,1,filesize,pFile);
+ fclose(pFile);
+
+ /* convert to unicode and set tcas document text*/
+ UnicodeString ustrInputText(pBuffer, (int32_t)numread, "utf-8");
+ delete pBuffer;
+
+ /* set TCAS Document text */
+ CAS * tcas = pEngine->newCAS();
+ ASSERT_OR_THROWEXCEPTION( EXISTS(tcas) );
+
+ tcas->setDocumentText(ustrInputText.getBuffer(), ustrInputText.length(), true);
+ tcas->getDocumentAnnotation().setLanguage("en");
+
+ /* call process */
+ TyErrorId err = pEngine->process(*tcas);
+ ASSERT_OR_THROWEXCEPTION( err == UIMA_ERR_NONE );
+
+ uima::internal::CASImpl & cas = uima::internal::CASImpl::promoteCAS( *tcas);
+ uima::internal::CASSerializer serializer(true);
+
+ uima::internal::SerializedCAS iv_serializedCAS;
+ iv_serializedCAS.reset();
+
+ iv_serializeTimerData.reset();
+ iv_serializeTimerData.start();
+ serializer.serializeData(cas, iv_serializedCAS);
+ iv_serializeTimerData.stop();
+#ifndef UIMA_SUPPRESS_TIMING
+ pConsole->format(" Serialization per-document data", uima::Timer::timeString( iv_serializeTimerData.getAccumulatedTime() ).c_str() );
+#endif
+
+ iv_serializeTimerData.reset();
+ iv_serializeTimerData.start();
+ size_t blobsz = serializer.getBlobSize(cas);
+ char* blob = new char[blobsz];
+ blobsz = serializer.getBlob(cas, blob, blobsz);
+ iv_serializeTimerData.stop();
+#ifndef UIMA_SUPPRESS_TIMING
+ pConsole->format(" Blob serialization per-document data", uima::Timer::timeString( iv_serializeTimerData.getAccumulatedTime() ).c_str() );
+#endif
+
+ pConsole->formatHeader("CAS Serialization Results:");
+ pConsole->format(" FS Heap size", (unsigned long)iv_serializedCAS.getFSHeapArray().size() );
+ pConsole->format(" String Heap size", (unsigned long)iv_serializedCAS.getStringSymbolTable().size() );
+ pConsole->format(" Number of Indexed FSs", (unsigned long)iv_serializedCAS.getIndexedFSs().size() );
+ pConsole->format(" Blob size:", (unsigned long)blobsz);
+
+
+// iv_serializedCAS.print(cout);
+
+ pConsole->info("Deserializing CAS");
+
+//ee uima::internal::TCASImpl * newTCAS = uima::internal::TCASImpl::createTCASImpl( *iv_newCASDefinition, getEngine().getAnnotatorContext() );
+ uima::internal::CASImpl * newTCAS = &uima::internal::CASImpl::promoteCAS( *(pEngine->newCAS()) );
+
+ uima::internal::CASDeserializer deserializer;
+
+ /*
+ iv_serializeTimerFSAndStringHeap.reset();
+ iv_serializeTimerFSAndStringHeap.start();
+ deserializer.deserializeFSHeapAndStringTable(iv_serializedCAS, *iv_newTCAS);
+ iv_serializeTimerFSAndStringHeap.stop();
+ getConsole().format(" Deserialization of FS/String Heap", uima::Timer::timeString( iv_serializeTimerFSAndStringHeap.getAccumulatedTime() ).c_str() );
+ */
+
+ iv_serializeTimerData.reset();
+ iv_serializeTimerData.start();
+ deserializer.deserializeData(iv_serializedCAS, *newTCAS);
+ iv_serializeTimerData.stop();
+#ifndef UIMA_SUPPRESS_TIMING
+ getConsole().format(" Deserialization document data", uima::Timer::timeString( iv_serializeTimerData.getAccumulatedTime() ).c_str() );
+#endif
+
+ // deserialize the blob on top for a quick test
+ iv_serializeTimerData.reset();
+ iv_serializeTimerData.start();
+ deserializer.deserializeBlob(blob, *newTCAS);
+ iv_serializeTimerData.stop();
+#ifndef UIMA_SUPPRESS_TIMING
+ pConsole->format(" Deserialization blob", uima::Timer::timeString( iv_serializeTimerData.getAccumulatedTime() ).c_str() );
+#endif
+
+// deserializer.deserializeDocument(iv_serializedCAS, *iv_newTCAS);
+
+// iv_newTCAS->getFSSystem().getLowlevelFSHeap().print(cout);
+// cout << "DocID: " << newTCAS.getDocumentAnnotation().getID() << endl;
+
+// cout << "========SERIALIZE AGAIN======" << endl;
+ pConsole->info("Serializing CAS again");
+ uima::internal::SerializedCAS serializedCAS2;
+ uima::internal::CASSerializer serializer2(true);
+
+ /*
+ serializer2.serializeDocument(*iv_newTCAS, serializedCAS2);
+ serializer2.serializeFSHeapAndStringHeap(*iv_newTCAS, serializedCAS2);
+ serializer2.serializeIndexedFSs(*iv_newTCAS, serializedCAS2);
+ */
+
+ serializer2.serializeData(*newTCAS, serializedCAS2);
+
+// serCas2.print(cout);
+
+ pConsole->info("Checking results");
+ pConsole->format("Checking", "fs heap");
+ ASSERT_OR_THROWEXCEPTION(equalVectors( iv_serializedCAS.getFSHeapArray(), serializedCAS2.getFSHeapArray(), pConsole ) );
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "string symbol table");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getStringSymbolTable(), serializedCAS2.getStringSymbolTable(), pConsole ) );
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "document");
+ ASSERT_OR_THROWEXCEPTION( iv_serializedCAS.getDocument() == serializedCAS2.getDocument() );
+ pConsole->format(" success", true);
+
+ pConsole->format("Checking", "indexed FSs");
+ ASSERT_OR_THROWEXCEPTION( equalVectors( iv_serializedCAS.getIndexedFSs(), serializedCAS2.getIndexedFSs(), pConsole ));
+ pConsole->format(" success", true);
+
+ pConsole->info("Done");
+ delete tcas;
+ delete newTCAS;
+ delete pEngine;
+
+}
+
+/* ----------------------------------------------------------------------- */
+/* Main routine */
+/* ----------------------------------------------------------------------- */
+
+int main(int argc, char * argv[]) /*
+---------------------------------- */
+{
+ /* create console */
+ util::ConsoleUI * pConsole = new util::ConsoleUI(argc, argv, MAIN_TITLE, "\n");
+ assert(EXISTS(pConsole));
+
+ /* create a UIMA resource */
+ try {
+ ResourceManager::createInstance(MAIN_TITLE);
+ testSerializeDefinitions(pConsole);
+ testSerializeData(pConsole);
+ ResourceManager::deleteInstance();
+ } catch (Exception & rclException) {
+ displayException(*pConsole, rclException);
+ pConsole->error("Unexpected UIMA exception");
+ return 1;
+ } catch (exception & rclException) {
+ pConsole->error(rclException.what());
+ return 1;
+ }
+
+ return(0);
+
+}
+
+/* <EOF> */
+
+
Propchange: incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.vcproj
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.vcproj?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.vcproj (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.vcproj Sat Feb 3 09:19:12 2007
@@ -0,0 +1,141 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="test_casserializer"
+ ProjectGUID="{C1CC67C7-6514-4C9A-88B6-02678AA4DD5B}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(InputDir)\.."
+ IntermediateDirectory="..\Debug\$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=".;"$(APR_HOME)\include";"$(ICU_HOME)\include";"$(XERCES_HOME)\include";"$(JAVA_HOME)\include";"$(JAVA_HOME)\include\win32";"$(UIMACPP_HOME)\include";"$(UIMACPP_HOME)\include\apr""
+ PreprocessorDefinitions="UIMA_SUPPRESS_TIMING;WIN32;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="xerces-c_2.lib icuuc.lib libapr$(APR_VER).lib uimaD.lib"
+ OutputFile="$(OutDir)/test_casserializer.exe"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""$(APR_HOME)\Debug";"$(XERCES_HOME)\lib";"$(ICU_HOME)\lib";"$(UIMACPP_HOME)\lib""
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(InputDir)\.."
+ IntermediateDirectory="..\Release\$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="3"
+ AdditionalIncludeDirectories=".;"$(APR_HOME)\include";"$(ICU_HOME)\include";"$(XERCES_HOME)\include";"$(JAVA_HOME)\include";"$(JAVA_HOME)\include\win32";"$(UIMACPP_HOME)\include";"$(UIMACPP_HOME)\include\apr""
+ PreprocessorDefinitions="UIMA_SUPPRESS_TIMING;TRACEOFF;NDEBUG;WIN32;_CONSOLE"
+ BasicRuntimeChecks="0"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="xerces-c_2.lib icuuc.lib libapr$(APR_VER).lib uima.lib"
+ OutputFile="$(OutDir)/test_casserializer.exe"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""$(APR_HOME)\Release";"$(XERCES_HOME)\lib";"$(ICU_HOME)\lib";"$(UIMACPP_HOME)\lib""
+ GenerateDebugInformation="FALSE"
+ ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ <File
+ RelativePath="test_casserializer.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Propchange: incubator/uima/uimacpp/trunk/src/test/src/test_casserializer.vcproj
------------------------------------------------------------------------------
svn:eol-style = CRLF
Added: incubator/uima/uimacpp/trunk/src/test/src/test_engine.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_engine.cpp?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_engine.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_engine.cpp Sat Feb 3 09:19:12 2007
@@ -0,0 +1,524 @@
+/** @name uimatest_engine.cpp
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+
+-------------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+
+#include "uima/api.hpp"
+
+#include <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
+#include "uima/consoleui.hpp"
+#include "uima/assertmsg.h"
+
+#include "uima/conui.hpp"
+#include "uima/doc_buffer.hpp"
+#include "uima/ftools.hpp"
+
+#include "uima/internal_aggregate_engine.hpp"
+#include "xercesc/util/XMLException.hpp"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+#define MAIN_TITLE _TEXT("Commandline Tester with extended tests")
+
+#define MAIN_DEFAULT_CCSID 1208 /* v must match v */
+#define MAIN_DEFAULT_CCSID_STR "cp1208" /* ^ must match ^ */
+
+#define MAIN_DEFAULT_LANG _TEXT("En_US")
+
+const TCHAR * gs_szUsage = _TEXT("\t"
+ "[--verbose]\n\t"
+ "--config <ConfigFilename>\n\t"
+ "[--ccsid <CCSID>]\n\t"
+ "[--lang <langId>]\n\t"
+ "[--ni <NumberOfIterations>]\n\t"
+ "[--iteratortest]\n\t"
+ "[--initrc <rc>]\n\t"
+ "[--processdocrc <rc>]\n\t"
+ "[--docisterm]\n\t"
+ "[--inpterm <term>] | <InputFilename> <...>\n"
+ );
+
+static const TCHAR * gs_szHelp = _TEXT("\t"
+ "Load the specified annotator(s) and feed them the specifed input text file(s).\n\t"
+ "\n\t"
+ "[--verbose] verbose display mode\n\t"
+ "-config <ConfigFilename> The file name of the config file to use.\n\t"
+ "[--ccsid <CCSID>] The CCSID for the text files to be processed\n\t"
+ " (default is: " MAIN_DEFAULT_CCSID_STR ")\n\t"
+ "[--lang <langId>] The Language ID for the text files to be processed\n\t"
+ " (default is: En_US)\n\t"
+ "[--ni <NumberOfIt>] Number of iterations for process\n\t"
+ "[--initrc <rc>] uima::Engine.init() must fail with specified RC\n\t"
+ "[--iteratortest] Run an iterator/output test after processing the doc(s)\n\t"
+ "[--processdocrc <rc>] uima::Engine.processDocument() must fail with specified RC\n\t"
+ "[--docisterm] Annotate the whole document as a term\n\t"
+ "[--inpterm <term>] Use the specified term instead of text files\n\t"
+ "<InputFilename> <...> The file name(s) of the text files to be processed\n"
+ );
+
+static bool gs_bVerbose = false;
+static bool gs_bDocIsTerm = false;
+static bool gs_bDoIterTest = false;
+static long gs_lExpectedInitRc = UIMA_ERR_NONE;
+static long gs_lExpectedProcessDocumentRc = UIMA_ERR_NONE;
+
+using namespace uima;
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+
+#define failIfNotTrue( expr ) /*lint -save -e611 -e923 -e731 -e909 -e506 */ \
+ ( ( expr ) ? ( void )0 : failImpl( #expr, __FILE__, (unsigned int) __LINE__ ) ) /*lint -restore */
+
+void failImpl( const char * cpszExpr, const char * cpszFile, unsigned int uiLine) {
+ /* compose error message */
+ cerr << "\n"
+ "*** TEST CONDITION FAILED ***\n";
+ /* compose error message */
+ cerr << "*** TEST: " << cpszExpr << "\n"
+ "*** LINE: " << uiLine << "\n"
+ "*** MODULE: " << cpszFile << "\n"
+ << endl;
+
+ UIMA_EXC_THROW_NEW(ConsoleAbortExc,
+ UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION,
+ UIMA_MSG_ID_EXC_UNEXPECTED_ERROR,
+ ErrorMessage(UIMA_MSG_ID_EXCON_UNKNOWN_CONTEXT),
+ ErrorInfo::unrecoverable);
+}
+
+void testCallingSequence1(uima::util::ConsoleUI & rclConsole, const TCHAR * cpszConfigFilename)
+/* ----------------------------------------------------------------------- */
+{
+ ErrorInfo errInfo;
+ uima::TextAnalysisEngine * pEngine = TextAnalysisEngine::createTextAnalysisEngine(cpszConfigFilename, errInfo);
+
+ failIfNotTrue( errInfo.getErrorId() == UIMA_ERR_NONE );
+ failIfNotTrue( pEngine != NULL );
+ CAS * cas = pEngine->newCAS();
+ failIfNotTrue( cas != NULL );
+
+ uima::UnicodeStringRef us(icu::UnicodeString("a") );
+// UnicodeStringRef uRef(us);
+ rclConsole.formatHeader(_TEXT("testing Engine CallingSequence1"));
+
+ cas->setDocumentText(us.getBuffer(), us.length());
+ cas->getDocumentAnnotation().setLanguage("en");
+ failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_NONE);
+ failIfNotTrue(cas->reset() == UIMA_ERR_NONE);
+ failIfNotTrue(pEngine->destroy() == UIMA_ERR_NONE);
+
+ cas->setDocumentText(us.getBuffer(), us.length());
+ cas->getDocumentAnnotation().setLanguage("en");
+ failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+
+ TyErrorId deInitRC = pEngine->destroy();
+ rclConsole.format("RC of deInit()", deInitRC);
+ failIfNotTrue( deInitRC == UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ rclConsole.formatBool(_TEXT("testing Engine CallingSequence1 OK"), true); //lint !e944: argument for operator '!' always evaluates to False
+ delete cas;
+ delete pEngine;
+} //lint !e715: cpszConfigFilename (line 99) not referenced
+
+void testCallingSequence2(uima::util::ConsoleUI & rclConsole, const TCHAR * cpszConfigFilename)
+/* ----------------------------------------------------------------------- */
+{
+ rclConsole.formatHeader(_TEXT("testing Engine CallingSequence2"));
+ {
+
+ uima::TextAnalysisEngine * pEngine = NULL;
+ ErrorInfo errInfo;
+
+ pEngine = TextAnalysisEngine::createTextAnalysisEngine(cpszConfigFilename, errInfo);
+ failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_NONE);
+ failIfNotTrue(pEngine != NULL );
+ delete pEngine;
+ }
+ rclConsole.formatBool(_TEXT("testing Engine CallingSequence2 OK"), true); //lint !e944: argument for operator '!' always evaluates to False
+}
+
+#include "unicode/utypes.h"
+
+void testCallingSequence3(uima::util::ConsoleUI & rclConsole, const TCHAR * cpszConfigFilename)
+/* ----------------------------------------------------------------------- */
+{
+ uima::TextAnalysisEngine * pEngine = NULL;
+ uima::Language clLanguage(MAIN_DEFAULT_LANG);
+ const char * clCCSID = MAIN_DEFAULT_CCSID_STR;
+ TyErrorId utErrorId;
+
+ icu::UnicodeString us("a");
+ UnicodeStringRef uref( us);
+
+ rclConsole.formatHeader(_TEXT("testing Engine CallingSequence3"));
+
+ ErrorInfo errInfo;
+ pEngine = TextAnalysisEngine::createTextAnalysisEngine(cpszConfigFilename, errInfo);
+ failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_NONE);
+ failIfNotTrue(pEngine != NULL );
+ CAS * cas = pEngine->newCAS();
+ failIfNotTrue( cas != NULL );
+
+ /* test for NULL ptrs */
+
+ UnicodeStringRef uref2(NULL);
+ cas->setDocumentText(uref2.getBuffer(), uref2.length());
+ cas->getDocumentAnnotation().setLanguage("en");
+ failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_NONE);
+ failIfNotTrue(cas->reset() == UIMA_ERR_NONE);
+
+
+ /* test for subsequent processes */
+ cas->setDocumentText(uref2.getBuffer(), uref2.length());
+ cas->getDocumentAnnotation().setLanguage("en");
+
+ failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_NONE);
+
+ failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_NONE);
+
+
+ utErrorId = pEngine->destroy();
+ failIfNotTrue(utErrorId == UIMA_ERR_NONE);
+ delete cas;
+ delete pEngine;
+ rclConsole.formatBool(_TEXT("testing Engine CallingSequence3 OK"), true); //lint !e944: argument for operator '!' always evaluates to False
+}
+
+void testMissingResMgr(uima::util::ConsoleUI & rclConsole)
+/* ----------------------------------------------------------------------- */
+{
+ rclConsole.info("testMissingResMgr start.");
+ uima::TextAnalysisEngine * pEngine;
+
+ failIfNotTrue( ! ResourceManager::hasInstance() );
+ ErrorInfo errInfo;
+ pEngine = TextAnalysisEngine::createTextAnalysisEngine(_TEXT("DUMMY"), errInfo );
+ failIfNotTrue( ! ResourceManager::hasInstance() );
+ failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_ENGINE_RESMGR_NOT_INITIALIZED);
+ failIfNotTrue(pEngine == NULL);
+ rclConsole.info("testMissingResMgr finished." );
+}
+
+void testProcessDocu(uima::util::ConsoleUI & rclConsole,
+ uima::TextAnalysisEngine & rclEngine,
+ const char * crclCCSID,
+ const uima::Language & crclLanguage)
+/* ----------------------------------------------------------------------- */
+{
+ TyErrorId utErrorId;
+ string clstrInputFileContent;
+ size_t uiNumOfInputDocs = 0;
+
+ uima::DocBuffer docBuffer;
+ CAS * cas = rclEngine.newCAS();
+ failIfNotTrue(cas != NULL );
+
+ /* iterate through all doc specs on command line */
+ for (rclConsole.setToFirst(); rclConsole.isValid(); rclConsole.setToNext()) {
+ ////uima::util::Filename clInputFilename(rclConsole.getAsCString());
+ //replaced with a hard wired data file
+ UnicodeString filename("tdoc_001_enus_850.asc");
+ UnicodeString fn = ResourceManager::resolveFilename(filename, filename);
+ uima::util::Filename clInputFilename(UnicodeStringRef(fn).asUTF8().c_str());
+
+ size_t uiSize;
+
+ if (!clInputFilename.isExistent()) {
+ rclConsole.fatal(1, _TEXT("Input file not found"), clInputFilename.getAsCString());
+ }
+ if (crclCCSID == NULL) /**** (!crclCCSID.isValid()) ***/
+ {
+ rclConsole.fatal(1, _TEXT("Invalid CCSID specified - cannot load document"), crclCCSID /**crclCCSID.getName() **/);
+ }
+ rclConsole.format(_TEXT("Adding Document"), clInputFilename.getAsCString());
+ uiSize = ftool_ReadFileToString(clInputFilename, clstrInputFileContent);
+
+ docBuffer.addDocPart(clstrInputFileContent.data(),uiSize,crclCCSID);
+ // For real file based documents we only add a term annotation for the
+ // whole "document" if the appropriate switch is set
+ if (gs_bDocIsTerm) {
+ assert(false);
+ }
+
+ icu::UnicodeString ustrInputFileContent(clstrInputFileContent.data(), uiSize, crclCCSID);
+ /* since we already added a complete doc, we may not add anything else */
+/// failIfNotTrue(rclEngine.addDocPart(ustrInputFileContent) == UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+/// failIfNotTrue(rclEngine.addDoc(ustrInputFileContent) == UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+
+ cas->setDocumentText(docBuffer.getDocBuffer(), docBuffer.getLength() );
+ cas->getDocumentAnnotation().setLanguage(crclLanguage);
+
+ utErrorId = rclEngine.process(*cas);
+ uimaToolHandleErrorId(rclConsole, utErrorId, rclEngine.getAnnotatorContext().getLogger().getLastErrorAsCStr(), _TEXT("uima::Engine::processDocument"), gs_lExpectedProcessDocumentRc);
+
+ if (utErrorId == UIMA_ERR_NONE && gs_bDoIterTest) {
+ failIfNotTrue(false);
+ // iteratorTest(rclConsole, rclEngine);
+ }
+
+ utErrorId = cas->reset();
+ uimaToolHandleErrorId(rclConsole, utErrorId, rclEngine.getAnnotatorContext().getLogger().getLastErrorAsCStr(), _TEXT("uima::Engine::resetDocument"));
+ ++uiNumOfInputDocs;
+ }
+ if (uiNumOfInputDocs == 0) {
+ rclConsole.warning(_TEXT("No input file(s) specified"));
+ }
+ delete cas;
+}
+
+void testProcessTerm(uima::util::ConsoleUI & rclConsole,
+ uima::TextAnalysisEngine & rclEngine,
+ ///const uima::CCSID & crclCCSID,
+ const char * crclCCSID,
+ const uima::Language & crclLanguage,
+ const TCHAR * cpszInpTerm)
+/* ----------------------------------------------------------------------- */
+{
+ TyErrorId utErrorId;
+
+ failIfNotTrue(EXISTS(cpszInpTerm));
+ rclConsole.format(_TEXT("Input term"), cpszInpTerm);
+
+ DocBuffer docBuffer;
+ docBuffer.addDocPart(cpszInpTerm, strlen(cpszInpTerm), crclCCSID);
+
+ //? assert(false);
+ CAS * cas = rclEngine.newCAS();
+ failIfNotTrue(cas != NULL );
+
+ // For terms we always add a term annotation for the whole "document"
+ /* since we already added a complete doc, we may not add anything else */
+ cas->setDocumentText(docBuffer.getDocBuffer(), docBuffer.getLength() );
+ cas->getDocumentAnnotation().setLanguage(crclLanguage);
+
+ utErrorId = rclEngine.process(*cas);
+ uimaToolHandleErrorId(rclConsole, utErrorId, rclEngine.getAnnotatorContext().getLogger().getLastErrorAsCStr(), _TEXT("uima::Engine::processDocument"), gs_lExpectedProcessDocumentRc);
+
+ if (utErrorId == UIMA_ERR_NONE && gs_bDoIterTest) {
+ failIfNotTrue(false);
+ // iteratorTest(rclConsole, rclEngine);
+ }
+
+ utErrorId = cas->reset();
+ uimaToolHandleErrorId(rclConsole, utErrorId, rclEngine.getAnnotatorContext().getLogger().getLastErrorAsCStr(), _TEXT("uima::Engine::resetDocument"));
+ delete cas;
+}
+
+
+
+
+bool testLoadData(uima::util::ConsoleUI & rclConsole,
+ const char * cpszCCSID,
+ const TCHAR * cpszConfigFilename,
+ const TCHAR * cpszLanguage,
+ size_t uiNumOfIterations)
+/* ----------------------------------------------------------------------- */
+{
+ uima::TextAnalysisEngine * pEngine = NULL;
+ ///uima::CCSID clCCSID(lCCSID);
+ uima::Language clLanguage(cpszLanguage);
+ ErrorInfo errInfo;
+
+ rclConsole.formatHeader(_TEXT("testing UIMA Engine loading a document"));
+ /* init engine */
+ pEngine = TextAnalysisEngine::createTextAnalysisEngine(cpszConfigFilename, errInfo);
+ uimaToolHandleErrorId(rclConsole, errInfo.getErrorId(), errInfo.asString().c_str(), _TEXT("uima::Engine::init()"), gs_lExpectedInitRc);
+ if (gs_lExpectedInitRc != UIMA_ERR_NONE) {
+ return(false);
+ }
+ failIfNotTrue( pEngine != NULL );
+
+
+ for (size_t ui = 0; ui < uiNumOfIterations; ui++) {
+ const TCHAR * cpszInpTerm = 0;
+
+ /* read in file */
+ if (uiNumOfIterations > 1) {
+ rclConsole.newline();
+ rclConsole.format(_TEXT("Iteration"), (unsigned long)ui);
+ }
+ if (rclConsole.hasArgString(_TEXT("inpterm"), cpszInpTerm)) {
+ testProcessTerm(rclConsole, *pEngine, cpszCCSID, clLanguage, cpszInpTerm);
+ } else {
+ testProcessDocu(rclConsole, *pEngine, cpszCCSID, clLanguage);
+ }
+ }
+ TyErrorId utErrorId = pEngine->destroy();
+ uimaToolHandleErrorId(rclConsole, utErrorId, pEngine->getAnnotatorContext().getLogger().getLastErrorAsCStr(), _TEXT("uima::Engine::deInit"));
+ delete pEngine;
+ return(true);
+}
+
+
+void testDescriptorNotFound(uima::util::ConsoleUI & rclConsole)
+/* ----------------------------------------------------------------------- */
+{
+ rclConsole.info("testDescriptorNotFound start.");
+ uima::TextAnalysisEngine * pEngine;
+
+ ErrorInfo errInfo;
+ pEngine = TextAnalysisEngine::createTextAnalysisEngine(_TEXT("DUMMY"), errInfo );
+ failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_RESOURCE_CORRUPTED);
+ failIfNotTrue(pEngine == NULL);
+ rclConsole.info("testDescriptorNotFound finished." );
+}
+
+
+void testCasMultiplier(uima::util::ConsoleUI & rclConsole)
+/* ----------------------------------------------------------------------- */
+{
+ rclConsole.info("testCasMultiplier start.");
+ uima::TextAnalysisEngine * pEngine;
+
+ ErrorInfo errInfo;
+
+ UnicodeString filename("SimpleTextSegmenter.xml");
+ UnicodeString fn = ResourceManager::resolveFilename(filename, filename);
+ pEngine = TextAnalysisEngine::createTextAnalysisEngine(UnicodeStringRef(fn).asUTF8().c_str(), errInfo );
+ failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_NONE);
+ failIfNotTrue(pEngine != NULL);
+
+ CAS * cas = pEngine->newCAS();
+ cas->setDocumentText(UnicodeString("This is the first sentence. This is the second sentence. This is the third sentence."));
+
+ CASIterator iter = pEngine->processAndOutputNewCASes(*cas);
+ int num=0;
+ while (iter.hasNext()) {
+ num++;
+ CAS & seg = iter.next();
+ failIfNotTrue(seg.getDocumentText().length() > 0);
+ pEngine->getAnnotatorContext().releaseCAS(seg);
+ }
+ failIfNotTrue(num==3);
+
+ rclConsole.info("testCasMultiplier finished." );
+}
+
+
+
+
+
+void mainTest(uima::util::ConsoleUI & rclConsole,
+ const char * cpszCCSID,
+ const TCHAR * cpszConfigFilename,
+ const TCHAR * cpszLanguage,
+ size_t uiNumOfIterations)
+/* ----------------------------------------------------------------------- */
+{
+ testDescriptorNotFound(rclConsole);
+ if (testLoadData(rclConsole, cpszCCSID, cpszConfigFilename, cpszLanguage, uiNumOfIterations)) {
+ testCallingSequence1(rclConsole, cpszConfigFilename);
+ testCallingSequence2(rclConsole, cpszConfigFilename);
+ testCallingSequence3(rclConsole, cpszConfigFilename);
+ }
+ testCasMultiplier(rclConsole);
+}
+
+int main(int argc, char * argv[]) /*
+---------------------------------- */
+{
+ uima::util::ConsoleUI clConsole(argc, argv, MAIN_TITLE, "");
+
+ const char * cpszCCSID = MAIN_DEFAULT_CCSID_STR;
+ long lNumberOfIterations = 1;
+ const TCHAR * cpszLanguage = MAIN_DEFAULT_LANG;
+ const TCHAR * cpszConfigFilename = NULL;
+ int iRetVal = 0;
+
+ clConsole.handleUsageHelp(gs_szUsage, gs_szHelp);
+
+ /* check cmd line args */
+ gs_bVerbose = clConsole.hasArgSwitch(_TEXT("verbose"));
+ gs_bDocIsTerm = clConsole.hasArgSwitch(_TEXT("docisterm"));
+ gs_bDoIterTest = clConsole.hasArgSwitch(_TEXT("iteratortest"));
+ /*** run with toktest.xml only
+ if (!clConsole.hasArgString(_TEXT("config"), cpszConfigFilename)) {
+ cerr << "ERROR: required option \"config\" is missing.\n";
+ clConsole.displayUsage();
+ } ***/
+
+ ///(void) clConsole.hasArgNumval(_TEXT("ccsid"), lCCSID);
+ (void) clConsole.hasArgString(_TEXT("ccsid"), cpszCCSID);
+ (void) clConsole.hasArgString(_TEXT("lang"), cpszLanguage);
+ (void) clConsole.hasArgNumval(_TEXT("ni"), lNumberOfIterations);
+ (void) clConsole.hasArgNumval(_TEXT("initrc"), gs_lExpectedInitRc);
+ (void) clConsole.hasArgNumval(_TEXT("processdocrc"), gs_lExpectedProcessDocumentRc);
+
+ /* before we init the res mgr, we test for the correct error */
+ testMissingResMgr(clConsole);
+
+ try {
+ /* create a UIMA resource */
+ (void) uima::ResourceManager::createInstance(MAIN_TITLE);
+
+ ///mainTest(clConsole, lCCSID, cpszConfigFilename, cpszLanguage, (size_t) lNumberOfIterations);
+ UnicodeString filename("toktest.xml");
+ UnicodeString fn = ResourceManager::resolveFilename(filename, filename);
+ UnicodeStringRef fnRef(fn);
+ string fnStr = fnRef.asUTF8();
+ mainTest(clConsole, cpszCCSID, fnStr.c_str(),
+ cpszLanguage, (size_t) lNumberOfIterations);
+ fnRef.release(fnStr); // release storage returned by asUTF8()
+ clConsole.info(_TEXT("The program terminated successfully."));
+ iRetVal = 0;
+ } catch (ConsoleAbortExc & ) { // only thrown by uimaToolHandleErrorId to signal abortion
+ clConsole.error(_TEXT("Aborting UIMA execution"));
+ iRetVal = 1;
+ } catch (Exception & rclException) {
+ clConsole.getOutputStream() << rclException;
+ clConsole.error(_TEXT("Unexpected UIMA exception"));
+ iRetVal = 1;
+ } catch (XMLException & rException) {
+ clConsole.getOutputStream() << "XML Error: "
+ << icu::UnicodeString( (UChar const *) rException.getMessage() ) << endl;
+ iRetVal = 5041; // hack that our testcase basic_engine_bad_params works
+ } catch (exception & rclException) {
+ clConsole.error(rclException.what());
+ iRetVal = 1;
+ } catch (...) {
+ clConsole.error(_TEXT("Unexpected exception"));
+ iRetVal = 1;
+ }
+ return(iRetVal);
+}
+
+/* <EOF> */
+
Propchange: incubator/uima/uimacpp/trunk/src/test/src/test_engine.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/test/src/test_engine.vcproj
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_engine.vcproj?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_engine.vcproj (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_engine.vcproj Sat Feb 3 09:19:12 2007
@@ -0,0 +1,148 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="test_engine"
+ ProjectGUID="{EC9D70CD-3EAB-45F7-B779-5D82370BFF5B}"
+ RootNamespace="test_engine"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(InputDir).."
+ IntermediateDirectory="..\Debug\$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=".;"$(APR_HOME)\include";"$(ICU_HOME)\include";"$(XERCES_HOME)\include";"$(JAVA_HOME)\include";"$(JAVA_HOME)\include\win32";"$(UIMACPP_HOME)\include";"$(UIMACPP_HOME)\include\apr""
+ PreprocessorDefinitions="UIMA_SUPPRESS_TIMING;WIN32;_CONSOLE;_DEBUG"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="xerces-c_2.lib icuuc.lib libapr$(APR_VER).lib uimaD.lib"
+ OutputFile="$(OutDir)/test_engine.exe"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""$(APR_HOME)\Debug";"$(XERCES_HOME)\lib";"$(ICU_HOME)\lib";"$(UIMACPP_HOME)\lib""
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(InputDir)\.."
+ IntermediateDirectory="..\Release\$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="3"
+ AdditionalIncludeDirectories=".;"$(APR_HOME)\include";"$(ICU_HOME)\include";"$(XERCES_HOME)\include";"$(JAVA_HOME)\include";"$(JAVA_HOME)\include\win32";"$(UIMACPP_HOME)\include";"$(UIMACPP_HOME)\include\apr""
+ PreprocessorDefinitions="UIMA_SUPPRESS_TIMING;TRACEOFF;NDEBUG;WIN32;_CONSOLE"
+ BasicRuntimeChecks="0"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="xerces-c_2.lib icuuc.lib libapr$(APR_VER).lib uima.lib"
+ OutputFile="$(OutDir)/test_engine.exe"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""$(APR_HOME)\Release";"$(XERCES_HOME)\lib";"$(ICU_HOME)\lib";"$(UIMACPP_HOME)\lib""
+ GenerateDebugInformation="FALSE"
+ ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ <File
+ RelativePath="conui.cpp">
+ </File>
+ <File
+ RelativePath="doc_buffer.cpp">
+ </File>
+ <File
+ RelativePath="test_engine.cpp">
+ </File>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ </Filter>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
Propchange: incubator/uima/uimacpp/trunk/src/test/src/test_engine.vcproj
------------------------------------------------------------------------------
svn:eol-style = CRLF
Added: incubator/uima/uimacpp/trunk/src/test/src/test_engine.vcproj-new
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_engine.vcproj-new?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_engine.vcproj-new (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_engine.vcproj-new Sat Feb 3 09:19:12 2007
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="test_engine"
+ ProjectGUID="{EC9D70CD-3EAB-45F7-B779-5D82370BFF5B}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="..\..\Debug\bin"
+ IntermediateDirectory="..\..\Debug\$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ AdditionalIncludeDirectories=".;..\cas;..\framework;"$(APR_HOME)\include";"$(ICU_HOME)\include";"$(XERCES_HOME)\include";"$(JAVA_HOME)\include";"$(JAVA_HOME)\include\win32";"$(UIMACPP_HOME)\include";"$(UIMACPP_HOME)\include\apr""
+ PreprocessorDefinitions="UIMA_SUPPRESS_TIMING;WIN32;_CONSOLE"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="xerces-c_2.lib icuuc.lib libapr$(APR_VER).lib uima.lib"
+ OutputFile="$(OutDir)/test_engine.exe"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""$(OutDir)\..\lib";"$(APR_HOME)\Debug";"$(XERCES_HOME)\lib";"$(ICU_HOME)\lib";"$(UIMACPP_HOME)\lib""
+ GenerateDebugInformation="TRUE"
+ ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+ SubSystem="1"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="..\..\Release\bin"
+ IntermediateDirectory="..\..\Release\$(ProjectName)"
+ ConfigurationType="1"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="3"
+ AdditionalIncludeDirectories=".;..\cas;..\framework;"$(APR_HOME)\include";"$(ICU_HOME)\include";"$(XERCES_HOME)\include";"$(JAVA_HOME)\include";"$(JAVA_HOME)\include\win32";"$(UIMACPP_HOME)\include";"$(UIMACPP_HOME)\include\apr""
+ PreprocessorDefinitions="UIMA_SUPPRESS_TIMING;TRACEOFF;NDEBUG;WIN32;_CONSOLE"
+ BasicRuntimeChecks="0"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="xerces-c_2.lib icuuc.lib libapr$(APR_VER).lib uima.lib"
+ OutputFile="$(OutDir)/test_engine.exe"
+ LinkIncremental="1"
+ AdditionalLibraryDirectories=""$(OutDir)\..\lib";"$(APR_HOME)\Release";"$(XERCES_HOME)\lib";"$(ICU_HOME)\lib";"$(UIMACPP_HOME)\lib""
+ GenerateDebugInformation="FALSE"
+ ProgramDatabaseFile="$(OutDir)/$(TargetName).pdb"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCWebDeploymentTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ <File
+ RelativePath="conui.cpp">
+ </File>
+ <File
+ RelativePath="doc_buffer.cpp">
+ </File>
+ <File
+ RelativePath="test_engine.cpp">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>