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 [5/6] - /incubator/uima/uimacpp/trunk/src/test/src/
Added: incubator/uima/uimacpp/trunk/src/test/src/test_iterators.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_iterators.cpp?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_iterators.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_iterators.cpp Sat Feb 3 09:19:12 2007
@@ -0,0 +1,776 @@
+/** \file test_compositeindex.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 iterators")
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+
+#include "uima/pragmas.hpp" //must be first include to surpress warnings
+#include "uima/api.hpp"
+#include "uima/internal_casimpl.hpp"
+///#include "uima/lowlevel_indexiterator.hpp"
+///#include "uima/internal_fspromoter.hpp"
+#include "uima/tt_types.hpp"
+#include <sys/stat.h>
+/* ----------------------------------------------------------------------- */
+/* 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
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+using namespace uima;
+
+
+bool checkIndex(AnnotationFS const & anFS, ANIndex const & ix) {
+ ANIterator it = ix.iterator();
+ for (it.moveToFirst(); it.isValid(); it.moveToNext() ) {
+ if (it.get() == anFS) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/*-----------------------------------------------------------------------------*/
+uima::lowlevel::IndexIterator * createIterator(uima::lowlevel::IndexABase const & crAnnIndex,
+ set<uima::lowlevel::TyFSType> const & crTypes) {
+ if (crTypes.size() == 0) {
+ return crAnnIndex.createIterator();
+ } else {
+ return crAnnIndex.createTypeSetIterator(crTypes);
+ }
+}
+
+void createNewIterator(uima::lowlevel::IndexIterator*& rpIt,
+ uima::lowlevel::IndexABase const & crAnnIndex,
+ set<uima::lowlevel::TyFSType> const & crTypes,
+ bool bUseOnlyOneIterator ) {
+ uima::lowlevel::IndexIterator * pOldIt = rpIt;
+ if (rpIt == NULL ) {
+ rpIt = createIterator(crAnnIndex, crTypes);
+ return;
+ }
+ if (! bUseOnlyOneIterator) {
+ delete rpIt;
+ rpIt = createIterator(crAnnIndex, crTypes);
+ } else {
+ assert( rpIt == pOldIt );
+ }
+}
+
+
+void checkIterator(uima::lowlevel::IndexABase const & crIndex,
+ set<uima::lowlevel::TyFSType> const & crTypes,
+ bool bUseOnlyOneIterator,
+ uima::internal::CASImpl * tcas,
+ util::ConsoleUI * pConsole) {
+ ////uima::internal::TCASImpl * tcas = iv_pTCASImpl;
+
+ bool bIsIteratorOverTypeSet = ( crTypes.size() != 0 );
+
+ int iSize = 0;
+ if (!bIsIteratorOverTypeSet) {
+ iSize = crIndex.getSize();
+ }
+ pConsole->format("Index size", iSize);
+
+// uima::lowlevel::TyFS * arFSs = new uima::lowlevel::TyFS[iSize];
+ vector<uima::lowlevel::TyFS> arFSs;
+ int j;
+
+ uima::lowlevel::IndexIterator * pIt = NULL;
+ createNewIterator(pIt, crIndex, crTypes, bUseOnlyOneIterator);
+
+ // fill array with one single forward movement
+ pConsole->format("Filling array", "");
+ for (pIt->moveToFirst(); pIt->isValid(); pIt->moveToNext() ) {
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ arFSs.push_back( pIt->get() );
+ if (bIsIteratorOverTypeSet) {
+ ++iSize;
+ }
+ }
+ ASSERT_OR_THROWEXCEPTION( ! pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( arFSs.size() == iSize );
+ pConsole->format("Array full", true);
+
+ /////////////////////////////////////////////////
+ // check array with forward movement
+ createNewIterator(pIt, crIndex, crTypes, bUseOnlyOneIterator);
+ pConsole->format("Checking forward iterator", "");
+ pIt->moveToFirst();
+ for (j=0; j<iSize; ++j) {
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == pIt->get() );
+ pIt->moveToNext();
+ }
+ ASSERT_OR_THROWEXCEPTION( ! pIt->isValid() );
+ pConsole->format("Forward iterator", true);
+
+ /////////////////////////////////////////////////
+ // check array with reverse movement
+ createNewIterator(pIt, crIndex, crTypes, bUseOnlyOneIterator);
+ pConsole->format("Checking reverse iterator", "");
+ pIt->moveToLast();
+ for (j=iSize-1; j>=0; --j) {
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == pIt->get() );
+ pIt->moveToPrevious();
+ }
+ ASSERT_OR_THROWEXCEPTION( ! pIt->isValid() );
+ pConsole->format("Reverse iterator", true);
+
+ ///////////////////////////////////////////////
+ // check array with one single forth and back movement
+ createNewIterator(pIt, crIndex, crTypes, bUseOnlyOneIterator);
+ pConsole->format("Checking one forth and back movement", "");
+ pIt->moveToFirst();
+ for (j=0; j<iSize-1; ++j) {
+// iv_pclConsole->format(" checking fs", j);
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == pIt->get() );
+ pIt->moveToNext();
+ }
+ pConsole->format(" forth movement", true);
+
+ for (j=iSize-1; j>=0; --j) {
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == pIt->get() );
+ pIt->moveToPrevious();
+ }
+ ASSERT_OR_THROWEXCEPTION( ! pIt->isValid() );
+ pConsole->format(" back movement", true);
+
+ /////////////////////////////////////////////////
+ // check array with many back and forth movements
+ createNewIterator(pIt, crIndex, crTypes, bUseOnlyOneIterator);
+ pConsole->format("Checking many forth and back movements", "");
+ pIt->moveToFirst();
+ for (j=0; j<iSize; ++j) {
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == pIt->get() );
+
+ if (j>1) {
+ int k;
+ for (k=j; k>=2; --k) {
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k] );
+ pIt->moveToPrevious();
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k-1] );
+ uima::lowlevel::TyFS prevFS = pIt->get();
+ pIt->moveToPrevious();
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k-2] );
+ pIt->moveToNext();
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k-1] );
+ ASSERT_OR_THROWEXCEPTION( prevFS == pIt->get() );
+ }
+ ASSERT_OR_THROWEXCEPTION(k==1);
+ for (k=1; k<j; ++k) {
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k] );
+ pIt->moveToNext();
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k+1] );
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ }
+ ASSERT_OR_THROWEXCEPTION(k==j);
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == pIt->get() );
+ }
+
+ if (j<iSize-1) {
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == pIt->get() );
+ int k;
+ for (k=j; k<iSize-2; ++k) {
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k] );
+ pIt->moveToNext();
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k+1] );
+ uima::lowlevel::TyFS prevFS = pIt->get();
+ pIt->moveToNext();
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k+2] );
+ pIt->moveToPrevious();
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ ASSERT_OR_THROWEXCEPTION( pIt->get() == arFSs[k+1] );
+ ASSERT_OR_THROWEXCEPTION( prevFS == pIt->get() );
+ }
+ ASSERT_OR_THROWEXCEPTION( k == iSize-2 );
+ for (k=iSize-2; k>j; --k) {
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ pIt->moveToPrevious();
+ ASSERT_OR_THROWEXCEPTION( pIt->isValid() );
+ }
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == pIt->get() );
+ }
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == pIt->get() );
+
+ pIt->moveToNext();
+ }
+ pConsole->format(" Many forth and back movements", true);
+
+
+ /////////////////////////////////////////////////
+ // check peek() methods
+ pConsole->format("Checking peek() functions", "");
+
+ uima::lowlevel::IndexIterator * it2 = pIt->clone();
+ uima::FSIterator fsit = uima::internal::FSPromoter::promoteIterator(it2, *tcas );
+ j=0;
+ for (fsit.moveToFirst(); fsit.isValid(); fsit.moveToNext()) {
+ // test peekPrevious
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == uima::internal::FSPromoter::demoteFS(fsit.get()) );
+ uima::FeatureStructure fsPrev = fsit.peekPrevious();
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == uima::internal::FSPromoter::demoteFS(fsit.get()) );
+ if (j == 0) {
+ ASSERT_OR_THROWEXCEPTION(!fsPrev.isValid());
+ } else {
+ ASSERT_OR_THROWEXCEPTION(fsPrev.isValid());
+ ASSERT_OR_THROWEXCEPTION( uima::internal::FSPromoter::demoteFS( fsPrev ) == arFSs[j-1] );
+ }
+
+ // test peekNext
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == uima::internal::FSPromoter::demoteFS(fsit.get()) );
+ uima::FeatureStructure fsNext = fsit.peekNext();
+ ASSERT_OR_THROWEXCEPTION( arFSs[j] == uima::internal::FSPromoter::demoteFS(fsit.get()) );
+ if (j == (arFSs.size()-1)) {
+ ASSERT_OR_THROWEXCEPTION(!fsNext.isValid());
+ } else {
+ ASSERT_OR_THROWEXCEPTION(fsNext.isValid());
+ ASSERT_OR_THROWEXCEPTION( uima::internal::FSPromoter::demoteFS( fsNext ) == arFSs[j+1] );
+ }
+
+ ++j;
+ }
+ ASSERT_OR_THROWEXCEPTION( j == arFSs.size() );
+ pConsole->format(" peek() functions", true);
+
+ /////////////////////////////////////////////////////////
+ // cleanup
+ delete pIt;
+// delete[] arFSs;
+// arFSs = NULL;
+
+}
+
+
+void checkIterators(bool bUseOnlyOneIterator, util::ConsoleUI * pConsole,
+ uima::internal::CASImpl * tcas) {
+ ///uima::internal::TCASImpl * tcas = iv_pTCASImpl;
+ uima::lowlevel::IndexRepository const & crIndexRep = tcas->getIndexRepository();
+
+ uima::lowlevel::TypeSystem const & crTypeSystem = tcas->getHeap().getTypeSystem();
+
+ vector<icu::UnicodeString> allIndexes = crIndexRep.getAllIndexIDs();
+
+ size_t n;
+ for (n=0; n<allIndexes.size(); ++n) {
+
+ icu::UnicodeString const & ixid = allIndexes[n];
+
+ uima::lowlevel::TyFSType tyType = crIndexRep.getIndexDefinition().getTypeForIndex(ixid);
+ pConsole->format("Processing index with ID", UnicodeStringRef(ixid).asUTF8().c_str() );
+ pConsole->format(" on type", UnicodeStringRef(crTypeSystem.getTypeName(tyType)).asUTF8().c_str() );
+
+ vector<uima::lowlevel::TyFSType> subsumedTypes;
+ crTypeSystem.getSubsumedTypes(tyType, subsumedTypes);
+
+ size_t i;
+ for (i=0; i<subsumedTypes.size(); ++i) {
+
+ uima::lowlevel::TyFSType tySubType = subsumedTypes[i];
+ ASSERT_OR_THROWEXCEPTION( tcas->getHeap().getTypeSystem().isValidType( tySubType ) );
+
+ pConsole->format("Processing type", UnicodeStringRef(crTypeSystem.getTypeName(tySubType)).asUTF8().c_str() );
+ pConsole->format("Use new iterator for every test", ! bUseOnlyOneIterator);
+
+ ASSERT_OR_THROWEXCEPTION( crTypeSystem.subsumes( tyType, tySubType ) );
+ ASSERT_OR_THROWEXCEPTION( crTypeSystem.subsumes( crIndexRep.getIndexDefinition().getTypeForIndex(ixid), tySubType ) );
+
+ uima::lowlevel::IndexABase const & crIndex = crIndexRep.getLowlevelIndex(ixid, tySubType);
+
+ set<uima::lowlevel::TyFSType> indexTypes;
+
+ // check normal iterators
+ ASSERT_OR_THROWEXCEPTION( indexTypes.size() == 0 );
+ checkIterator(crIndex, indexTypes, bUseOnlyOneIterator, tcas, pConsole);
+
+ // check type set iterators
+ vector<uima::lowlevel::TyFSType> subTypes;
+ crTypeSystem.getSubsumedTypes(tySubType, subTypes);
+ if ( subTypes.size() > 1) {
+ pConsole->format("Processing iterator over type sets", "");
+
+ size_t j = 0;
+ for (j=0; j<subTypes.size(); ++j) {
+ if (subTypes[j] != tyType) {
+ indexTypes.insert(subTypes[j]);
+
+ }
+ }
+
+ // make vector shorter to make test faster
+ const int MAXTYPESETSIZE = 15;
+ if (indexTypes.size() > MAXTYPESETSIZE) {
+ for (j = indexTypes.size() - MAXTYPESETSIZE; j>0; --j) {
+ set<uima::lowlevel::TyFSType>::iterator itLast = indexTypes.end();
+ --itLast;
+ indexTypes.erase( itLast );
+ }
+ }
+
+ while (indexTypes.size() > 0 ) {
+ set<uima::lowlevel::TyFSType>::const_iterator cit;
+ for (cit = indexTypes.begin(); cit != indexTypes.end(); ++cit) {
+ pConsole->format(" choosing type", UnicodeStringRef(crTypeSystem.getTypeName(*cit)).asUTF8().c_str() );
+ }
+
+ checkIterator(crIndex, indexTypes, bUseOnlyOneIterator, tcas, pConsole);
+ indexTypes.erase( indexTypes.begin() );
+ }
+ }
+ }
+ }
+}
+
+//do we need this (bi)
+void defect_011303_subiterator(uima::ANIterator & forConstituent, uima::AnnotationFS const & sent, util::ConsoleUI * pConsole) {
+ int subfsnum = 0;
+ for ( forConstituent.moveToFirst(); forConstituent.isValid() ; forConstituent.moveToNext() ) {
+ subfsnum++;
+ uima::AnnotationFS annot = forConstituent.get();
+ ASSERT_OR_THROWEXCEPTION( annot.getBeginPosition() >= sent.getBeginPosition() );
+ ASSERT_OR_THROWEXCEPTION( annot.getEndPosition() <= sent.getEndPosition() );
+ ASSERT_OR_THROWEXCEPTION( annot != sent );
+ }
+ pConsole->format("number of sub FSs", subfsnum);
+
+}
+//do we need this test (bi)
+void defect_011303_subiterator(uima::AnnotationFS const & sent, Type const & tAnnotation, EnIteratorAmbiguity ambiguity, util::ConsoleUI * pConsole) {
+
+ // the next three variants should do the same, but the assignment operators/copy constructors
+ // may be called differently. Different compilers may create different code
+ // in particular for variants 1 and 2.
+
+ // variant 1
+ uima::ANIterator forConstituent1( sent.subIterator( tAnnotation, ambiguity ) );
+ defect_011303_subiterator(forConstituent1, sent, pConsole);
+
+ // variant 2
+ uima::ANIterator forConstituent2 = sent.subIterator( tAnnotation, ambiguity );
+ defect_011303_subiterator(forConstituent2, sent, pConsole);
+
+ // variant 3
+ uima::ANIterator forConstituent3_tmp = sent.subIterator( tAnnotation, ambiguity );
+ uima::ANIterator forConstituent3 = forConstituent3_tmp;
+ defect_011303_subiterator(forConstituent3, sent, pConsole);
+
+}
+
+// defect in Mary's mail from 01/13/2003
+// do we need this test (bi)
+void defect_011303(uima::CAS const & tcas, util::ConsoleUI * pConsole) {
+ pConsole->format("Checking Mary's defect 01/13/2003", "");
+ uima::Type tSent = tcas.getTypeSystem().getType(uima::TT::TYPE_NAME_SENTENCE_ANNOTATION);
+ uima::Type tAnnotation = tcas.getTypeSystem().getType(uima::CAS::TYPE_NAME_ANNOTATION);
+
+ uima::ANIterator forSent =
+ tcas.getAnnotationIndex( tSent ).iterator();
+ int sentnum = 1;
+ for ( forSent.moveToFirst() ; forSent.isValid() ; forSent.moveToNext() ) {
+ pConsole->format("Sentence", sentnum);
+ sentnum++;
+ uima::AnnotationFS sent = forSent.get();
+
+ defect_011303_subiterator(sent, tAnnotation, enAmbiguous,pConsole);
+ defect_011303_subiterator(sent, tAnnotation, enUnambiguous,pConsole);
+
+ }
+ pConsole->format("Done Checking Mary's defect 01/13/2003", "");
+}
+
+void testTypeSetIterator(uima::CAS & tcas, util::ConsoleUI * pConsole) {
+ pConsole->format("Checking Type set iterators", "");
+
+ uima::Type tAnnotation = tcas.getTypeSystem().getType(uima::CAS::TYPE_NAME_ANNOTATION);
+ uima::Type tSent = tcas.getTypeSystem().getType(uima::TT::TYPE_NAME_SENTENCE_ANNOTATION);
+ uima::Type tPar = tcas.getTypeSystem().getType(uima::TT::TYPE_NAME_PARAGRAPH_ANNOTATION);
+
+ set<Type> s;
+ s.insert(tSent);
+ s.insert(tPar);
+
+ uima::FSIterator it = tcas.getAnnotationIndex( tAnnotation ).typeSetIterator(s);
+ for ( it.moveToFirst() ; it.isValid() ; it.moveToNext() ) {
+ uima::FeatureStructure fs = it.get();
+ uima::Type t = fs.getType();
+ ASSERT_OR_THROWEXCEPTION( (t == tSent) || (t == tPar) );
+ }
+ pConsole->format("Type set iterators check successful?", true);
+
+}
+
+void checkTypePriority(uima::AnnotationFS const & crFS1, uima::AnnotationFS const & crFS2) {
+ if ( ! crFS1.isValid() ) {
+ return;
+ }
+
+ if ( (crFS1.getBeginPosition() == crFS2.getBeginPosition())
+ && (crFS1.getEndPosition() == crFS2.getEndPosition() ) ) {
+ uima::lowlevel::TyFSType t1 = uima::internal::FSPromoter::demoteType( crFS1.getType() );
+ uima::lowlevel::TyFSType t2 = uima::internal::FSPromoter::demoteType( crFS2.getType() );
+
+ // current implementation of type priority simply assumes this
+ ASSERT_OR_THROWEXCEPTION( t1 <= t2 );
+ }
+
+}
+
+void checkSubIterators(char const * mainIteratorTypeName, char const * subIteratorTypeName, EnIteratorAmbiguity ambiguity, uima::CAS const & crTCAS, util::ConsoleUI * pConsole) {
+
+ pConsole->format("Main iterator type", mainIteratorTypeName);
+ pConsole->format("Sub iterator type", subIteratorTypeName);
+ pConsole->format("Ambiguous", (ambiguity == enAmbiguous));
+
+ uima::Type mainIteratorType = crTCAS.getTypeSystem().getType(mainIteratorTypeName);
+ uima::Type subIteratorType = crTCAS.getTypeSystem().getType(subIteratorTypeName);
+ ASSERT_OR_THROWEXCEPTION( mainIteratorType.isValid() );
+ ASSERT_OR_THROWEXCEPTION( subIteratorType.isValid() );
+ uima::ANIndex ix = crTCAS.getAnnotationIndex(mainIteratorType);
+ uima::ANIterator it = ix.iterator();
+ for (it.moveToFirst(); it.isValid(); it.moveToNext()) {
+
+ uima::AnnotationFS mainFS = it.get();
+
+ // don't use tokens as main type
+ if (mainFS.getType() != crTCAS.getTypeSystem().getType(uima::TT::TYPE_NAME_TOKEN_ANNOTATION)) {
+
+ pConsole->format("Found main annotation from", (unsigned long)mainFS.getBeginPosition());
+ pConsole->format(" to", (unsigned long)mainFS.getEndPosition());
+ UIMA_TPRINT("Found sentence '" << sentFS.getCoveredText() << "' from " << sentFS.getBeginPosition() << " to " << sentFS.getEndPosition() );
+ uima::ANIterator subIt = mainFS.subIterator(subIteratorType, ambiguity);
+
+ uima::AnnotationFS subFS;
+ pConsole->format("Traversing sub iterator from left to right", "");
+ for (subIt.moveToFirst(); subIt.isValid(); subIt.moveToNext() ) {
+ checkTypePriority( subFS, subIt.get() );
+ subFS = subIt.get();
+ UIMA_TPRINT("Found token '" << tokFS.getCoveredText() << "' from " << tokFS.getBeginPosition() << " to " << tokFS.getEndPosition());
+
+ ASSERT_OR_THROWEXCEPTION( subFS.getBeginPosition() >= mainFS.getBeginPosition() );
+ ASSERT_OR_THROWEXCEPTION( subFS.getBeginPosition() < mainFS.getEndPosition() );
+
+ ASSERT_OR_THROWEXCEPTION( subFS != mainFS );
+ }
+ pConsole->format("Success?", true);
+
+ pConsole->format("Traversing sub iterator from right to left", "");
+ for (subIt.moveToLast(); subIt.isValid(); subIt.moveToPrevious() ) {
+ subFS = subIt.get();
+ UIMA_TPRINT("Found token '" << tokFS.getCoveredText() << "' from " << tokFS.getBeginPosition() << " to " << tokFS.getEndPosition() );
+ ASSERT_OR_THROWEXCEPTION( subFS.getBeginPosition() >= mainFS.getBeginPosition() );
+ ASSERT_OR_THROWEXCEPTION( subFS.getBeginPosition() < mainFS.getEndPosition() );
+ }
+ pConsole->format("Success?", true);
+
+
+ pConsole->format("Moving sub iterator to last and beyond", "");
+ subIt.moveToLast(); // That's a UIMA subiterator
+
+ if ( subIt.isValid() ) {
+ uima::AnnotationFS remember = subIt.get();
+
+ subIt.moveToNext();
+
+ if ( subIt.isValid() ) {
+ ostream& os = pConsole->getOutputStream();
+ os << "Remembered: "; // This trace actually gets executed
+ os << remember.getType().getName() << " between " << remember.getBeginPosition() << " and " << remember.getEndPosition() << endl;
+ remember.getCoveredText().toSingleByteStream( os );
+ os << endl;
+ os << "Supposed to be invalid: ";
+ uima::AnnotationFS current = subIt.get();
+ os << current.getType().getName() << " between " << current.getBeginPosition() << " and " << current.getEndPosition() << endl;
+ current.getCoveredText().toSingleByteStream(os);
+ os << endl;
+ }
+
+ ASSERT_OR_THROWEXCEPTION( !subIt.isValid()); // And this assertion fails
+ }
+ pConsole->format("checkSubIterators Success?", true);
+ }
+ }
+}
+
+/* ----------------------------------------------------------------------- */
+/* TESTS */
+/* ----------------------------------------------------------------------- */
+/**
+ *
+ * test subiterators
+ */
+void testSubIterators(util::ConsoleUI * pConsole) {
+ pConsole->info("Testing SubIterators");
+
+ ErrorInfo errInfo;
+ UnicodeString filename("toktest.xml");
+ UnicodeString fn = ResourceManager::resolveFilename(filename, filename);
+
+ /* create engine */
+ 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 );
+
+ UnicodeString dataFile("tdoc_001_en_850.asc");
+ UnicodeString datafn = ResourceManager::resolveFilename(dataFile, dataFile);
+ std::string dataFilename = UnicodeStringRef(datafn).asUTF8();
+ /* read in file contents and set TCAS Document text */
+ 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 );
+
+ defect_011303(*tcas, pConsole);
+ testTypeSetIterator(*tcas, pConsole);
+
+ checkSubIterators(uima::TT::TYPE_NAME_SENTENCE_ANNOTATION, uima::TT::TYPE_NAME_TOKEN_ANNOTATION, enAmbiguous, *tcas, pConsole );
+ checkSubIterators(uima::CAS::TYPE_NAME_ANNOTATION, uima::TT::TYPE_NAME_TOKEN_ANNOTATION, enAmbiguous, *tcas, pConsole );
+ checkSubIterators(uima::TT::TYPE_NAME_LEXICAL_ANNOTATION, uima::TT::TYPE_NAME_LEXICAL_ANNOTATION, enAmbiguous, *tcas, pConsole );
+
+ checkSubIterators(uima::TT::TYPE_NAME_SENTENCE_ANNOTATION, uima::TT::TYPE_NAME_TOKEN_ANNOTATION, enUnambiguous, *tcas, pConsole );
+ checkSubIterators(uima::CAS::TYPE_NAME_ANNOTATION, uima::TT::TYPE_NAME_TOKEN_ANNOTATION, enUnambiguous, *tcas, pConsole );
+ checkSubIterators(uima::TT::TYPE_NAME_LEXICAL_ANNOTATION, uima::TT::TYPE_NAME_LEXICAL_ANNOTATION, enUnambiguous, *tcas, pConsole );
+ pConsole->info("Sub Iterators test finished.");
+}
+/**
+ * test iterators
+ *
+ */
+void testIterators(util::ConsoleUI * pConsole) {
+
+ pConsole->info("Testing Iterators");
+
+ ErrorInfo errInfo;
+ UnicodeString filename("toktest.xml");
+ UnicodeString fn = ResourceManager::resolveFilename(filename, filename);
+
+ /* create engine */
+ 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 );
+
+ UnicodeString dataFile("toktest.xml");
+ UnicodeString datafn = ResourceManager::resolveFilename(dataFile, dataFile);
+ std::string dataFilename = UnicodeStringRef(datafn).asUTF8();
+ /* read in file contents and set TCAS Document text */
+ 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 );
+
+ /* checkIterators twice - true/false */
+ checkIterators(true, pConsole, &(uima::internal::CASImpl::promoteCAS(*tcas)));
+ checkIterators(false, pConsole, &(uima::internal::CASImpl::promoteCAS(*tcas)));
+ pConsole->info("Iterators test finished");
+}
+
+/**
+ *
+ * Test composite index
+ *
+ */
+void testCaching(util::ConsoleUI * pConsole) {
+
+ pConsole->info("Testing Caching");
+
+ 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 );
+
+ /* set TCAS Document text */
+ CAS * tcas = pEngine->newCAS();
+ ASSERT_OR_THROWEXCEPTION( EXISTS(tcas) );
+ UnicodeString ustrInputText("This is test doc for testing iteration.");
+ 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 );
+
+ // iterator over a composite index
+ FSIndexRepository & ixRep = tcas->getIndexRepository();
+ Type annType = tcas->getTypeSystem().getType(CAS::TYPE_NAME_ANNOTATION);
+ ANIndex ix = tcas->getAnnotationIndex(annType);
+
+ vector<Type> subTypes;
+ annType.getSubTypes(subTypes);
+ size_t i;
+ // now create some annotations and check they are in the index
+ for (i=0; i<subTypes.size(); ++i) {
+ AnnotationFS an1 = tcas->createAnnotation(subTypes[i], i, i+10);
+ AnnotationFS an2 = tcas->createAnnotation(subTypes[i], i+1, i+11);
+
+ ixRep.addFS(an1);
+ ixRep.addFS(an2);
+
+ ASSERT_OR_THROWEXCEPTION( checkIndex(an1, ix) );
+ ASSERT_OR_THROWEXCEPTION( checkIndex(an2, ix) );
+ }
+ pConsole->info("Caching test finished");
+ return;
+}
+
+
+/* ----------------------------------------------------------------------- */
+/* 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);
+}
+
+/* ----------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/* 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);
+ testCaching(pConsole);
+ testIterators(pConsole);
+ testSubIterators(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);
+}
+
Propchange: incubator/uima/uimacpp/trunk/src/test/src/test_iterators.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/test/src/test_iterators.vcproj
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_iterators.vcproj?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_iterators.vcproj (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_iterators.vcproj Sat Feb 3 09:19:12 2007
@@ -0,0 +1,144 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="test_iterators"
+ ProjectGUID="{02C73C58-59FF-494D-95C6-11CF049217BD}"
+ 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_iterators.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_iterators.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_iterators.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_iterators.vcproj
------------------------------------------------------------------------------
svn:eol-style = CRLF
Added: incubator/uima/uimacpp/trunk/src/test/src/test_language.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_language.cpp?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_language.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_language.cpp Sat Feb 3 09:19:12 2007
@@ -0,0 +1,308 @@
+/** @name uimatest_language.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 <stdlib.h>
+#include <string.h>
+#include <iostream>
+#include <iomanip>
+using namespace std;
+
+#include "uima/assertmsg.h"
+#include "uima/consoleui.hpp"
+
+#include "uima/ftools.hpp"
+#include "uima/err_ids.h"
+#include "uima/strtools.hpp"
+#include "uima/strconvert.hpp"
+#include "uima/language.hpp"
+
+using namespace uima;
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+#define MAIN_TITLE _TEXT("Language Class Unit Tester")
+
+const TCHAR * gs_szUsage = _TEXT("\t[--verbose]"
+ );
+
+static const TCHAR * gs_szHelp = _TEXT("\t"
+ "Perform some test with the Language class.\n\t"
+ "\n\t"
+ "[--verbose] verbose display mode\n\t"
+ );
+
+static bool gs_bVerbose = false;
+
+#define ASSERT(x) if (!(x)) { cerr << "FAILED ASSERTION '" << UIMA_STRINGIFY(x) \
+ << "' in " << __FILE__ << " at line " << __LINE__ << endl; exit(1); }
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+
+void mainDisplay(util::ConsoleUI & rclConsole, Language & rclLang)
+/* ----------------------------------------------------------------------- */
+{
+ char s1[50];
+ string str2;
+ int id = rclLang.asNumber();
+ sprintf(s1,"0x%08x %d",id,id);
+ if (rclLang.hasLanguage())
+ str2 = rclLang.getLanguageCode();
+ else
+ str2 = "**";
+ if ( rclLang.hasTerritory() )
+ str2 += " - " + (string)rclLang.getTerritoryCode();
+
+ rclConsole.format(s1, str2.c_str());
+}
+
+// Display an array of Unicode characters
+void ucharDisplay(util::ConsoleUI & rclConsole, char* tag, const UChar* ucbuff, int len) {
+ char cbuf[1024];
+ char* s = cbuf;
+ *s++ = '\"';
+ for ( int i = 0; i < len; ++i ) {
+ if (ucbuff[i] < 128)
+ s += sprintf(s,"%c",ucbuff[i]);
+ else
+ s += sprintf(s,"\\u%04x",ucbuff[i]);
+ }
+ *s++ = '\"';
+ *s = '\0';
+ rclConsole.format(tag, cbuf);
+}
+
+
+TyErrorId
+mainTest(
+ util::ConsoleUI & rclConsole,
+ bool bVerbose
+) {
+ TyErrorId enErrorId = UIMA_ERR_NONE;
+
+ rclConsole.formatHeader(_TEXT("Performing language tests:"));
+
+ Language clTestLang1("en-US");
+ Language clTestLang2("En_us");
+ Language clTestLang3("en-GB");
+ Language clTestLang4("en");
+ Language clTestLang5("fr");
+ Language clTestLang6;
+
+ Language clInvalid1("foo");
+ Language clInvalid2("fu-bar");
+ Language clInvalid3("f0-ba");
+ Language clInvalid4("en us");
+ Language clInvalid5("és-ca");
+
+ ASSERT( !clInvalid1.isValid());
+ ASSERT( !clInvalid2.isValid());
+ ASSERT( !clInvalid3.isValid());
+ ASSERT( !clInvalid4.isValid());
+ ASSERT( !clInvalid5.isValid());
+ ASSERT( clTestLang1.isValid());
+ ASSERT( clTestLang3.hasTerritory());
+ ASSERT(!clTestLang4.hasTerritory());
+
+ mainDisplay ( rclConsole, clTestLang1 );
+ mainDisplay ( rclConsole, clTestLang2 );
+ mainDisplay ( rclConsole, clTestLang3 );
+ mainDisplay ( rclConsole, clTestLang4 );
+ mainDisplay ( rclConsole, clTestLang5 );
+ mainDisplay ( rclConsole, clTestLang6 );
+
+ rclConsole.format("construct tests", "OK");
+
+ // Test the prefix-match concept, e.g. "en" matches "en-US"
+ ASSERT(!clTestLang1.matches(clTestLang3));
+ ASSERT( clTestLang1.matches(clTestLang2));
+ ASSERT( clTestLang1.matches(clTestLang4));
+ ASSERT(!clTestLang1.matches(clTestLang5));
+ ASSERT( clTestLang1.matches(clTestLang6));
+
+ rclConsole.format("match tests", "OK");
+
+ // Test the comparison operators
+ ASSERT(clTestLang1 == clTestLang2);
+ ASSERT(clTestLang1 != clTestLang3);
+ ASSERT(clTestLang4 < clTestLang3);
+ ASSERT(clTestLang3 < clTestLang1);
+
+ rclConsole.format("comparison tests", "OK");
+
+ // Test the construction from the numeric form
+ Language clTestLang7(clTestLang1.asNumber());
+ ASSERT(clTestLang7 == clTestLang1);
+
+ // Test the construction of one from just the language part of another
+ Language clTestLang8(clTestLang1.getLanguageCode());
+ ASSERT(clTestLang1.matches(clTestLang8));
+ ASSERT(clTestLang8 == clTestLang4);
+
+ // Same test but construct from the numeric form of the language
+ Language clTestLang9(clTestLang1.getLanguage());
+ ASSERT(clTestLang1.matches(clTestLang9));
+ ASSERT(clTestLang9 == clTestLang4);
+
+ rclConsole.format("numeric construct tests", "OK");
+
+ //------------------------------------------------------
+ // Test some UnicodeStringRef copy functions
+ //------------------------------------------------------
+
+ int len;
+ UChar ucbuf[100];
+ UErrorCode err;
+ std::string ss;
+
+ char* cstr = "abcdefghijklmnopqrstuvyzyz 0123456789";
+ UnicodeString us1(cstr);
+ UnicodeStringRef usr(us1);
+
+ // into std::string with default conversion
+ usr.extract(ss);
+ if (bVerbose) rclConsole.format("extract to std::string",ss.c_str());
+ ASSERT (strlen(cstr) == ss.length());
+
+ // substring into UnicodeString
+ UnicodeString us2("initialValue");
+ UnicodeString us3("z 0");
+ usr.extractBetween(25,28,us2); // Should be "z 0"
+ if (bVerbose) ucharDisplay(rclConsole, "extractBetween into UChar buffer", us2.getBuffer(), us2.length());
+ ASSERT ( us2 == us3 );
+
+ // substring into UChar buffer
+ err = U_ZERO_ERROR;
+ len = us1.extract(ucbuf,100,err); // Pre-fill buffer
+
+ usr.extract(27,3,ucbuf,5); // extract part of USR into the buffer
+ UnicodeString us4("abcde012ijklm");
+ if (bVerbose) ucharDisplay(rclConsole, "extract into UChar buffer", ucbuf, 13);
+ ASSERT ( us4.compare(ucbuf,13) == 0 );
+
+ // extract into too-small UChar buffer
+ err = U_ZERO_ERROR;
+ len = usr.extract(ucbuf,36,err); // too small
+ ASSERT(err == U_BUFFER_OVERFLOW_ERROR);
+ err = U_ZERO_ERROR;
+ len = usr.extract(ucbuf,37,err); // no room for final 0
+ ASSERT(err == U_STRING_NOT_TERMINATED_WARNING);
+ err = U_ZERO_ERROR;
+ len = usr.extract(ucbuf,38,err); // just right
+ ASSERT(err == U_ZERO_ERROR);
+ if (bVerbose) ucharDisplay(rclConsole, "extract into UChar buffer", ucbuf, len);
+ ASSERT ( us1.compare(ucbuf,len) == 0 );
+
+
+ //------------------------------------------------------
+ // Test some UnicodeStringRef conversion functions
+ //------------------------------------------------------
+
+ // Create a UnicodeString with 8 Arabic characters followed by a blank.
+ // Also get the utf-8 form as a reference
+ UChar uc[] = {0x062c, 0x0648, 0x0631, 0x062c, 0x062a, 0x0627, 0x0648, 0x0646, 0x0020};
+ int nchars = sizeof(uc)/sizeof(UChar);
+ UnicodeString US1(uc, nchars);
+ char u8[100];
+ US1.extract(0, US1.length(), u8, 100, "utf-8");
+
+ // Create two UnicodeStringRef and compare them
+ UnicodeStringRef USR1(US1);
+ UnicodeStringRef USR2(uc, nchars);
+ if (bVerbose) ucharDisplay(rclConsole, "Construct from UnicodeString", USR1.getBuffer(), USR1.length());
+ if (bVerbose) ucharDisplay(rclConsole, "Construct from UChar array", USR2.getBuffer(), USR2.length());
+ ASSERT ( USR1.compare(US1) == 0 );
+
+ // Extract into a buffer using the utf-8 converter
+ char cbuf[100];
+ *cbuf = 0;
+ len = USR1.extract(0, USR1.length(), cbuf, 100, "utf-8");
+ if (bVerbose) rclConsole.format("extract into buffer with utf-8 converter", cbuf);
+ ASSERT ( strcmp(u8,cbuf) == 0 );
+
+ // Extract into a string using the utf-8 converter
+ USR1.extract(ss, "utf-8");
+ if (bVerbose) rclConsole.format("extract into string with utf-8 converter", ss.c_str());
+ ASSERT ( strlen(u8) == ss.length() );
+ ASSERT ( strncmp(u8,ss.data(),strlen(u8)) == 0 );
+
+ // Test the "re-try when overflows" logic in unistrref.cpp
+ // Create a string that converts to >255 chars
+ UnicodeString US2(uc, nchars);
+ for ( int i=0; i < 15; ++i )
+ US2.append(uc, nchars);
+
+ // Extract the 12th repeat
+ UnicodeStringRef USR3(US2);
+ USR3.extract(11*nchars, nchars, ss, "utf-8");
+ if (bVerbose) rclConsole.format("extract part into string with utf-8 converter", ss.c_str());
+ ASSERT ( strlen(u8) == ss.length() );
+
+ // Extract all to string with converter
+ USR3.extract(ss, "utf-8");
+ ASSERT ( 16*strlen(u8) == ss.length() );
+
+ // Explicit extract to utf-8 (no ICU converter)
+ std::string ss2;
+ USR3.extractUTF8(ss2);
+ ASSERT ( ss2 == ss );
+
+ // Convert to utf-8 (no ICU converter)
+ std::string ss3 = USR3.asUTF8();
+ ASSERT ( ss3 == ss );
+
+ rclConsole.format("UnicodeStringRef tests", "OK");
+
+ return enErrorId;
+}
+
+int main(int argc, char * argv[]) /*
+---------------------------------- */
+{
+ util::ConsoleUI clConsole(argc, argv, MAIN_TITLE, "");
+ TyErrorId enErrorId;
+
+ clConsole.handleUsageHelp(gs_szUsage, gs_szHelp);
+ gs_bVerbose = clConsole.hasArgSwitch(_TEXT("verbose"));
+
+ enErrorId = mainTest(clConsole, gs_bVerbose);
+
+ if (enErrorId == UIMA_ERR_NONE) {
+ clConsole.info(_TEXT("The program terminated successfully."));
+ } else {
+ clConsole.info(_TEXT("The program terminated with an error."));
+ }
+ return(int) enErrorId;
+} //lint !e529 rclResMgr not subsequently referenced
+
+/* <EOF> */
+
Propchange: incubator/uima/uimacpp/trunk/src/test/src/test_language.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/test/src/test_language.vcproj
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_language.vcproj?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_language.vcproj (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_language.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_language"
+ ProjectGUID="{562C331B-2F3C-4F39-8A7C-ECD9611D1E25}"
+ 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_language.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_language.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_language.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_language.vcproj
------------------------------------------------------------------------------
svn:eol-style = CRLF
Added: incubator/uima/uimacpp/trunk/src/test/src/test_primitivetypes.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_primitivetypes.cpp?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_primitivetypes.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_primitivetypes.cpp Sat Feb 3 09:19:12 2007
@@ -0,0 +1,452 @@
+/** \file sofatest.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 "uima/macros.h"
+#include "uima/xmlwriter.hpp"
+#include "uima/xcasdeserializer.hpp"
+#include "uima/internal_casserializer.hpp"
+#include "uima/internal_casdeserializer.hpp"
+
+#include <fstream>
+
+#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
+
+using namespace uima;
+icu::UnicodeString str1("string1");
+icu::UnicodeString str2("string2");
+icu::UnicodeString str3("string3");
+icu::UnicodeString str4("string4");
+icu::UnicodeString str5("string5");
+
+UnicodeStringRef strings[] = {
+ str1, str3, str2, str5, str4
+ };
+
+int ints[] = {
+ 1,2,3,4,5
+ };
+float floats[] = {
+ (float)1.1, (float)2.2, (float)3.3, (float)4.4, (float)5.5
+ };
+char chars[] = {
+ 'a','b','c','c','d'
+ };
+int shorts[] = {
+ 10,20,30,40,50
+ };
+int longs[] = {
+ 10000,20000,30000,40000,50000
+ };
+double doubles[] = {
+ 21E10,
+ 31E10,
+ 41E10,
+ 51E10,
+ 61E10
+
+ };
+
+bool val = false;
+UnicodeString ustr("this beer is good");
+int begin = 1;
+int end = 5;
+char * viewName = "EnglishDocument";
+#define BOOLEAN_ARRAY_SIZE 20
+
+void createExampleFS(CAS & cas) {
+
+ Type testType = cas.getTypeSystem().getType("test.primitives.Example");
+ Feature intF = testType.getFeatureByBaseName("intFeature");
+ Feature floatF = testType.getFeatureByBaseName("floatFeature");
+ Feature stringF = testType.getFeatureByBaseName("stringFeature");
+ Feature booleanF = testType.getFeatureByBaseName("boolFeature");
+ Feature byteF = testType.getFeatureByBaseName("byteFeature");
+ Feature shortF = testType.getFeatureByBaseName("shortFeature");
+ Feature longF = testType.getFeatureByBaseName("longFeature");
+ Feature doubleF = testType.getFeatureByBaseName("doubleFeature");
+
+ Feature intArrayF = testType.getFeatureByBaseName("intArrayFeature");
+ Feature floatArrayF = testType.getFeatureByBaseName("floatArrayFeature");
+ Feature stringArrayF = testType.getFeatureByBaseName("stringArrayFeature");
+ Feature booleanArrayF = testType.getFeatureByBaseName("boolArrayFeature");
+ Feature byteArrayF = testType.getFeatureByBaseName("byteArrayFeature");
+ Feature shortArrayF = testType.getFeatureByBaseName("shortArrayFeature");
+ Feature longArrayF = testType.getFeatureByBaseName("longArrayFeature");
+ Feature doubleArrayF = testType.getFeatureByBaseName("doubleArrayFeature");
+
+ //get index repository
+ FSIndexRepository & indexRep = cas.getIndexRepository();
+
+ // Create a view
+ CAS * englishView = cas.createView(viewName);
+ // Set the document text
+ englishView->setDocumentText(ustr);
+
+ // create an FS of exampleType and index it
+ AnnotationFS fs = englishView->createAnnotation(testType, begin, end);
+ englishView->getIndexRepository().addFS(fs);
+
+ // create Array FSs
+
+ StringArrayFS stringArrayFS = cas.createStringArrayFS(NUMBEROF(strings));
+
+ for (size_t i=0; i< NUMBEROF(strings); ++i) {
+ stringArrayFS.set(i, strings[i]);
+ }
+
+ IntArrayFS intArrayFS = cas.createIntArrayFS(NUMBEROF(ints));
+ for (size_t i=0; i< NUMBEROF(ints); ++i) {
+ intArrayFS.set(i, ints[i]);
+ }
+
+ FloatArrayFS floatArrayFS = cas.createFloatArrayFS(NUMBEROF(floats));
+ for (size_t i=0; i< NUMBEROF(floats); ++i) {
+ floatArrayFS.set(i, floats[i]);
+ }
+
+ ByteArrayFS byteArrayFS = cas.createByteArrayFS(NUMBEROF(chars));
+ for (size_t i=0; i< NUMBEROF(chars); ++i) {
+ byteArrayFS.set(i, chars[i]);
+ }
+
+ BooleanArrayFS boolArrayFS = cas.createBooleanArrayFS(BOOLEAN_ARRAY_SIZE);
+ for (int i=0; i<20; i++) {
+ boolArrayFS.set(i,val=!val);
+ }
+
+ ShortArrayFS shortArrayFS = cas.createShortArrayFS(NUMBEROF(shorts));
+ for (size_t i=0; i< NUMBEROF(shorts); ++i) {
+ shortArrayFS.set(i, shorts[i]);
+ }
+
+ LongArrayFS longArrayFS = cas.createLongArrayFS(NUMBEROF(longs));
+ for (size_t i=0; i< NUMBEROF(longs); ++i) {
+ longArrayFS.set(i, longs[i]);
+ }
+
+ DoubleArrayFS doubleArrayFS = cas.createDoubleArrayFS(NUMBEROF(doubles));
+ for (size_t i=0; i< NUMBEROF(doubles); ++i) {
+ doubleArrayFS.set(i, doubles[i]);
+ }
+
+ // set features of fs
+ fs.setStringValue(stringF, strings[0]);
+ fs.setFloatValue(floatF, floats[0]);
+ fs.setBooleanValue(booleanF, val);
+ fs.setByteValue(byteF, chars[0]);
+ fs.setShortValue(shortF, shorts[0]);
+ fs.setLongValue(longF, longs[0]);
+ fs.setDoubleValue(doubleF, doubles[0]);
+
+ fs.setFeatureValue(intArrayF, intArrayFS);
+ fs.setFeatureValue(floatArrayF, floatArrayFS);
+ fs.setFeatureValue(stringArrayF, stringArrayFS);
+ fs.setFeatureValue(byteArrayF, byteArrayFS);
+ fs.setFeatureValue(booleanArrayF, boolArrayFS);
+ fs.setFeatureValue(shortArrayF, shortArrayFS);
+ fs.setFeatureValue(longArrayF, longArrayFS);
+ fs.setFeatureValue(doubleArrayF, doubleArrayFS);
+
+}
+
+void validateFS(CAS & cas) {
+
+
+ Type testType = cas.getTypeSystem().getType("test.primitives.Example");
+ Feature intF = testType.getFeatureByBaseName("intFeature");
+ Feature floatF = testType.getFeatureByBaseName("floatFeature");
+ Feature stringF = testType.getFeatureByBaseName("stringFeature");
+ Feature booleanF = testType.getFeatureByBaseName("boolFeature");
+ Feature byteF = testType.getFeatureByBaseName("byteFeature");
+ Feature shortF = testType.getFeatureByBaseName("shortFeature");
+ Feature longF = testType.getFeatureByBaseName("longFeature");
+ Feature doubleF = testType.getFeatureByBaseName("doubleFeature");
+
+ Feature intArrayF = testType.getFeatureByBaseName("intArrayFeature");
+ Feature floatArrayF = testType.getFeatureByBaseName("floatArrayFeature");
+ Feature stringArrayF = testType.getFeatureByBaseName("stringArrayFeature");
+ Feature booleanArrayF = testType.getFeatureByBaseName("boolArrayFeature");
+ Feature byteArrayF = testType.getFeatureByBaseName("byteArrayFeature");
+ Feature shortArrayF = testType.getFeatureByBaseName("shortArrayFeature");
+ Feature longArrayF = testType.getFeatureByBaseName("longArrayFeature");
+ Feature doubleArrayF = testType.getFeatureByBaseName("doubleArrayFeature");
+ //get index repository
+ FSIndexRepository & indexRep = cas.getIndexRepository();
+
+ // get a view
+ CAS * englishView = cas.getView(viewName);
+ ASSERT_OR_THROWEXCEPTION(EXISTS(englishView));
+ ASSERT_OR_THROWEXCEPTION(0==englishView->getDocumentText().compare(ustr));
+
+ ANIndex index = englishView->getAnnotationIndex(testType);
+ ANIterator iter = index.iterator();
+ AnnotationFS fs = iter.get();
+ ASSERT_OR_THROWEXCEPTION(fs.isValid());
+
+ // check array values
+ StringArrayFS stringArrayFS = fs.getStringArrayFSValue(stringArrayF);
+ ASSERT_OR_THROWEXCEPTION(NUMBEROF(strings)==stringArrayFS.size());
+ for (size_t i=0; i< NUMBEROF(strings); ++i) {
+ ASSERT_OR_THROWEXCEPTION(0==stringArrayFS.get(i).compare(strings[i]));
+ }
+
+ IntArrayFS intArrayFS = fs.getIntArrayFSValue(intArrayF);
+ ASSERT_OR_THROWEXCEPTION(NUMBEROF(ints)==intArrayFS.size());
+ for (size_t i=0; i< NUMBEROF(ints); ++i) {
+ ASSERT_OR_THROWEXCEPTION(intArrayFS.get(i)==ints[i]);
+ }
+
+ FloatArrayFS floatArrayFS = fs.getFloatArrayFSValue(floatArrayF);
+ ASSERT_OR_THROWEXCEPTION(NUMBEROF(floats)==floatArrayFS.size());
+ for (size_t i=0; i< NUMBEROF(floats); ++i) {
+ ASSERT_OR_THROWEXCEPTION(floatArrayFS.get(i)==floats[i]);
+ }
+
+ ByteArrayFS byteArrayFS = fs.getByteArrayFSValue(byteArrayF);
+ ASSERT_OR_THROWEXCEPTION(NUMBEROF(chars)==byteArrayFS.size());
+ for (size_t i=0; i< NUMBEROF(chars); ++i) {
+ ASSERT_OR_THROWEXCEPTION(byteArrayFS.get(i)==chars[i]);
+ }
+
+ BooleanArrayFS boolArrayFS = fs.getBooleanArrayFSValue(booleanArrayF);
+ ASSERT_OR_THROWEXCEPTION(BOOLEAN_ARRAY_SIZE==boolArrayFS.size());
+ for (size_t i=0; i< BOOLEAN_ARRAY_SIZE; ++i) {
+ val = !val;
+ ASSERT_OR_THROWEXCEPTION(boolArrayFS.get(i)==val);
+ }
+
+ ShortArrayFS shortArrayFS = fs.getShortArrayFSValue(shortArrayF);
+ ASSERT_OR_THROWEXCEPTION(NUMBEROF(shorts)==shortArrayFS.size());
+ for (size_t i=0; i< NUMBEROF(shorts); ++i) {
+ ASSERT_OR_THROWEXCEPTION(shortArrayFS.get(i)==shorts[i]);
+ }
+
+ LongArrayFS longArrayFS = fs.getLongArrayFSValue(longArrayF);
+ ASSERT_OR_THROWEXCEPTION(NUMBEROF(longs)==longArrayFS.size());
+ for (size_t i=0; i< NUMBEROF(longs); ++i) {
+ ASSERT_OR_THROWEXCEPTION(longArrayFS.get(i)==longs[i]);
+ }
+
+ DoubleArrayFS doubleArrayFS = fs.getDoubleArrayFSValue(doubleArrayF);
+ ASSERT_OR_THROWEXCEPTION(NUMBEROF(doubles)==doubleArrayFS.size());
+ for (size_t i=0; i< NUMBEROF(doubles); ++i) {
+ ASSERT_OR_THROWEXCEPTION(doubleArrayFS.get(i) == doubles[i]);
+ }
+
+
+ // check scalar values
+ ASSERT_OR_THROWEXCEPTION(0==fs.getStringValue(stringF).compare(strings[0]));
+ ASSERT_OR_THROWEXCEPTION(fs.getBeginPosition()==begin);
+ ASSERT_OR_THROWEXCEPTION(fs.getEndPosition()==end);
+ ASSERT_OR_THROWEXCEPTION(fs.getFloatValue(floatF)==floats[0]);
+ ASSERT_OR_THROWEXCEPTION(fs.getBooleanValue(booleanF)==val);
+ ASSERT_OR_THROWEXCEPTION(fs.getByteValue(byteF)==chars[0]);
+ ASSERT_OR_THROWEXCEPTION(fs.getShortValue(shortF)==shorts[0]);
+ ASSERT_OR_THROWEXCEPTION(fs.getLongValue(longF)==longs[0]);
+ ASSERT_OR_THROWEXCEPTION(fs.getDoubleValue(doubleF)==doubles[0]);
+}
+
+
+
+
+
+
+
+/* ----------------------------------------------------------------------- */
+/* Main routine */
+/* ----------------------------------------------------------------------- */
+
+int main(int argc, char * argv[]) /*
+---------------------------------- */
+{
+ LOG("UIMATEST_PRIMITIVETYPES started");
+ int iRetVal = 0;
+
+ try {
+ char const * config =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<typeSystemDescription xmlns=\"http://uima.apache.org/resourceSpecifier\">"
+ " <types>"
+ " <typeDescription>"
+ " <name>test.primitives.Example</name>"
+ " <description></description>"
+ " <supertypeName>uima.tcas.Annotation</supertypeName>"
+ " <features>"
+ " <featureDescription>"
+ " <name>floatFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.Float</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>stringFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.String</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>boolFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.Boolean</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>byteFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.Byte</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>shortFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.Short</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>longFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.Long</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>doubleFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.Double</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>intArrayFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.IntegerArray</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>floatArrayFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.FloatArray</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>stringArrayFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.StringArray</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>boolArrayFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.BooleanArray</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>byteArrayFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.ByteArray</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>shortArrayFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.ShortArray</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>longArrayFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.LongArray</rangeTypeName>"
+ " </featureDescription>"
+ " <featureDescription>"
+ " <name>doubleArrayFeature</name>"
+ " <description></description>"
+ " <rangeTypeName>uima.cas.DoubleArray</rangeTypeName>"
+ " </featureDescription>"
+ " </features>"
+ " </typeDescription>"
+ " </types>"
+ "</typeSystemDescription>";
+
+ ResourceManager::createInstance("test");
+
+ ErrorInfo errorInfo;
+ ofstream outputStream;
+
+ static TypeSystem *ts = Framework::createTypeSystemFromXMLBuffer(config, errorInfo );
+ CAS* cas = Framework::createCAS(*ts, errorInfo);
+ ASSERT_OR_THROWEXCEPTION( EXISTS(cas) );
+
+ /* add a FS */
+ LOG("UIMATEST_PRIMITIVETYPES create a FS");
+ createExampleFS(*cas);
+ validateFS(*cas);
+
+ /* test xcas serialization */
+ CAS* trgCas = Framework::createCAS(*ts, errorInfo);
+ LOG("UIMATEST_PRIMITIVETYPES test XCAS serialization");
+ outputStream.open("testprimitivetypes.xcas");
+ ASSERT_OR_THROWEXCEPTION(outputStream);
+ //LOG("serialize XCAS");
+ XCASWriter writer(*cas, false);
+ writer.write(outputStream);
+ outputStream.close();
+ //LOG("deserialize XCAS");
+ XCASDeserializer::deserialize("testprimitivetypes.xcas", *trgCas);
+ validateFS(*trgCas);
+
+ /* test blob serialization */
+ LOG("UIMATEST_PRIMITIVETYPES test blob serialization");
+ trgCas->reset();
+ internal::CASSerializer serializer(false);
+ internal::CASDeserializer deserializer;
+ //LOG("serialize BLOB");
+ size_t blobsz = serializer.getBlobSize(*cas);
+ char* blob = new char[blobsz];
+ size_t blobsz2 = serializer.getBlob(*cas, blob, blobsz);
+ ASSERT_OR_THROWEXCEPTION(blobsz == blobsz2);
+ //LOG("deserialize BLOB");
+ deserializer.deserializeBlob(blob, *trgCas);
+ delete[] blob;
+ validateFS(*trgCas);
+
+ /* test binary serialization */
+ LOG("UIMATEST_PRIMITIVETYPES test binary serialization");
+ trgCas->reset();
+ internal::SerializedCAS serializedCas;
+ //LOG("serialize data");
+ serializer.serializeData(*cas, serializedCas);
+ //LOG("deserialize data");
+ deserializer.deserializeData(serializedCas, *trgCas);
+ validateFS(*trgCas);
+
+
+ delete cas;
+ delete trgCas;
+ LOG("UIMATEST_PRIMITIVETYPES finished");
+ } catch (Exception & exc) {
+ cerr << exc.asString() << endl;
+ iRetVal = 1;
+ }
+#ifdef NDEBUG
+ catch (...) {
+ cerr << "Unexpected exception " << endl;
+ iRetVal = 1;
+ }
+#endif
+ return iRetVal;
+}
+
+/* <EOF> */
Propchange: incubator/uima/uimacpp/trunk/src/test/src/test_primitivetypes.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/test/src/test_primitivetypes.vcproj
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/test/src/test_primitivetypes.vcproj?view=auto&rev=503265
==============================================================================
--- incubator/uima/uimacpp/trunk/src/test/src/test_primitivetypes.vcproj (added)
+++ incubator/uima/uimacpp/trunk/src/test/src/test_primitivetypes.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_primitivetypes"
+ ProjectGUID="{2A4A561A-F304-4280-9238-DD2C1C82F8AE}"
+ 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 uima.lib"
+ OutputFile="$(OutDir)/test_primitivetypes.exe"
+ LinkIncremental="2"
+ 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 uima.lib"
+ OutputFile="$(OutDir)/test_primitivetypes.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_primitivetypes.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_primitivetypes.vcproj
------------------------------------------------------------------------------
svn:eol-style = CRLF