You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by tw...@apache.org on 2007/01/19 14:08:20 UTC
svn commit: r497800 [9/10] - in /incubator/uima/uimaj/trunk/uimaj-core/src:
main/java/org/apache/uima/cas/ main/java/org/apache/uima/cas/impl/
main/java/org/apache/uima/jcas/cas/ main/java/org/apache/uima/jcas/impl/
main/resources/org/apache/uima/ main...
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTest.java?view=diff&rev=497800&r1=497799&r2=497800
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/CASTest.java Fri Jan 19 05:08:19 2007
@@ -35,125 +35,125 @@
*/
public class CASTest extends TestCase {
- private CAS cas;
+ private CAS cas;
- private TypeSystem ts;
+ private TypeSystem ts;
- /**
+ /**
* Constructor for CASTest.
*
* @param arg0
*/
- public CASTest(String arg0) {
- super(arg0);
- }
-
- public void setUp() {
- try {
- this.cas = CASInitializer.initCas(new CASTestSetup());
- this.ts = this.cas.getTypeSystem();
- } catch (Exception e) {
- assertTrue(false);
- }
- }
-
- public void tearDown() {
- this.cas = null;
- this.ts = null;
- }
-
- public void testGetTypeSystem() {
- assertTrue(this.cas.getTypeSystem() != null);
- }
-
- public void testCreateFS() {
- // Can create FS of type "Top"
- assertTrue(this.cas.createFS(this.ts.getType(CAS.TYPE_NAME_TOP)) != null);
- boolean caughtExc = false;
- // Can't create int FS.
- try {
- this.cas.createFS(this.ts.getType(CAS.TYPE_NAME_INTEGER));
- } catch (CASRuntimeException e) {
- caughtExc = true;
- assertTrue(e.getError() == CASRuntimeException.NON_CREATABLE_TYPE);
- }
- assertTrue(caughtExc);
- caughtExc = false;
- // Can't create array with CAS.createFS().
- try {
- this.cas.createFS(this.ts.getType(CAS.TYPE_NAME_FS_ARRAY));
- } catch (CASRuntimeException e) {
- caughtExc = true;
- assertTrue(e.getError() == CASRuntimeException.NON_CREATABLE_TYPE);
- }
- assertTrue(caughtExc);
- caughtExc = false;
-
- // Check that we can create structures that are larger than the internal
- // heap page size.
- final int arraySize = 1000000;
- // Make sure that the structure we're trying to create is actually larger
- // than the page size we're testing with.
- assertTrue(arraySize > Heap.DEFAULT_PAGE_SIZE);
- IntArrayFS array = null;
- try {
- array = this.cas.createIntArrayFS(arraySize);
- } catch (CASRuntimeException e) {
- assertTrue(false);
- }
- try {
- array.set(arraySize - 1, 1);
- } catch (ArrayIndexOutOfBoundsException e) {
- assertTrue(false);
- }
-
- // Can't create array subtype with CAS.createFS().
- // try {
- // this.cas.createFS(this.ts.getType(CASTestSetup.INT_ARRAY_SUB));
- // } catch (CASRuntimeException e) {
- // caughtExc = true;
- // assertTrue(e.getError() == CASRuntimeException.NON_CREATABLE_TYPE);
- // }
- // assertTrue(caughtExc);
- }
-
- public void testCreateCAS() {
- TypeSystemMgr tsm = CASFactory.createTypeSystem();
- tsm.commit();
- }
-
- public void testCreateArrayFS() {
- // Has its own test class.
- }
-
- public void testCreateIntArrayFS() {
- // Has its own test class.
- }
-
- public void testCreateStringArrayFS() {
- // Has its own test class.
- }
-
- // public void testCreateFilteredIterator() {
- // }
- //
- // public void testCommitFS() {
- // }
- //
- // public void testGetConstraintFactory() {
- // }
- //
- // public void testCreateFeaturePath() {
- // }
- //
- // public void testGetIndexRepository() {
- // }
- //
- // public void testFs2listIterator() {
- // }
- //
- public static void main(String[] args) {
- junit.textui.TestRunner.run(CASTest.class);
- }
+ public CASTest(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() {
+ try {
+ this.cas = CASInitializer.initCas(new CASTestSetup());
+ this.ts = this.cas.getTypeSystem();
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ }
+
+ public void tearDown() {
+ this.cas = null;
+ this.ts = null;
+ }
+
+ public void testGetTypeSystem() {
+ assertTrue(this.cas.getTypeSystem() != null);
+ }
+
+ public void testCreateFS() {
+ // Can create FS of type "Top"
+ assertTrue(this.cas.createFS(this.ts.getType(CAS.TYPE_NAME_TOP)) != null);
+ boolean caughtExc = false;
+ // Can't create int FS.
+ try {
+ this.cas.createFS(this.ts.getType(CAS.TYPE_NAME_INTEGER));
+ } catch (CASRuntimeException e) {
+ caughtExc = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.NON_CREATABLE_TYPE));
+ }
+ assertTrue(caughtExc);
+ caughtExc = false;
+ // Can't create array with CAS.createFS().
+ try {
+ this.cas.createFS(this.ts.getType(CAS.TYPE_NAME_FS_ARRAY));
+ } catch (CASRuntimeException e) {
+ caughtExc = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.NON_CREATABLE_TYPE));
+ }
+ assertTrue(caughtExc);
+ caughtExc = false;
+
+ // Check that we can create structures that are larger than the internal
+ // heap page size.
+ final int arraySize = 1000000;
+ // Make sure that the structure we're trying to create is actually larger
+ // than the page size we're testing with.
+ assertTrue(arraySize > Heap.DEFAULT_PAGE_SIZE);
+ IntArrayFS array = null;
+ try {
+ array = this.cas.createIntArrayFS(arraySize);
+ } catch (CASRuntimeException e) {
+ assertTrue(false);
+ }
+ try {
+ array.set(arraySize - 1, 1);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ assertTrue(false);
+ }
+
+ // Can't create array subtype with CAS.createFS().
+ // try {
+ // this.cas.createFS(this.ts.getType(CASTestSetup.INT_ARRAY_SUB));
+ // } catch (CASRuntimeException e) {
+ // caughtExc = true;
+ // assertTrue(e.getError() == CASRuntimeException.NON_CREATABLE_TYPE);
+ // }
+ // assertTrue(caughtExc);
+ }
+
+ public void testCreateCAS() {
+ TypeSystemMgr tsm = CASFactory.createTypeSystem();
+ tsm.commit();
+ }
+
+ public void testCreateArrayFS() {
+ // Has its own test class.
+ }
+
+ public void testCreateIntArrayFS() {
+ // Has its own test class.
+ }
+
+ public void testCreateStringArrayFS() {
+ // Has its own test class.
+ }
+
+ // public void testCreateFilteredIterator() {
+ // }
+ //
+ // public void testCommitFS() {
+ // }
+ //
+ // public void testGetConstraintFactory() {
+ // }
+ //
+ // public void testCreateFeaturePath() {
+ // }
+ //
+ // public void testGetIndexRepository() {
+ // }
+ //
+ // public void testFs2listIterator() {
+ // }
+ //
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(CASTest.class);
+ }
}
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/FeatureStructureTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/FeatureStructureTest.java?view=diff&rev=497800&r1=497799&r2=497800
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/FeatureStructureTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/FeatureStructureTest.java Fri Jan 19 05:08:19 2007
@@ -38,363 +38,363 @@
*/
public class FeatureStructureTest extends TestCase {
- private CAS cas;
+ private CAS cas;
- private TypeSystem ts;
+ private TypeSystem ts;
- private Type topType;
+ private Type topType;
- private Type stringType;
+ private Type stringType;
- private Type tokenType;
+ private Type tokenType;
- private Type intType;
+ private Type intType;
- private Type tokenTypeType;
+ private Type tokenTypeType;
- private Type wordType;
-
- private Type arrayFsWithSubtypeType;
-
- private Feature arrayFsWithSubtypeTypeFeat;
+ private Type wordType;
- private Type group1Type;
+ private Type arrayFsWithSubtypeType;
- private Type group2Type;
+ private Feature arrayFsWithSubtypeTypeFeat;
- private Type langPairType;
+ private Type group1Type;
- private Type neListType;
+ private Type group2Type;
- private Feature lang1;
+ private Type langPairType;
- private Feature lang2;
+ private Type neListType;
- private Feature descr;
+ private Feature lang1;
- private Feature tokenTypeFeat;
+ private Feature lang2;
- private Feature lemmaFeat;
+ private Feature descr;
- private Feature sentLenFeat;
+ private Feature tokenTypeFeat;
- private Feature tokenFloatFeat;
+ private Feature lemmaFeat;
- private Feature startFeature;
+ private Feature sentLenFeat;
- private Feature tlFeature;
+ private Feature tokenFloatFeat;
- private Feature hdFeature;
+ private Feature startFeature;
- /**
+ private Feature tlFeature;
+
+ private Feature hdFeature;
+
+ /**
* Constructor for FeatureStructureTest.
*
* @param arg0
*/
- public FeatureStructureTest(String arg0) {
- super(arg0);
- }
-
- public void setUp() {
- try {
- this.cas = CASInitializer.initCas(new CASTestSetup());
- assertTrue(this.cas != null);
- this.ts = this.cas.getTypeSystem();
- assertTrue(this.ts != null);
- } catch (Exception e) {
- e.printStackTrace();
- assertTrue(false);
- }
- this.topType = this.ts.getType(CAS.TYPE_NAME_TOP);
- assertTrue(this.topType != null);
- this.stringType = this.ts.getType(CAS.TYPE_NAME_STRING);
- assertTrue(this.stringType != null);
- this.tokenType = this.ts.getType(CASTestSetup.TOKEN_TYPE);
- assertTrue(this.stringType != null);
- this.intType = this.ts.getType(CAS.TYPE_NAME_INTEGER);
- assertTrue(this.intType != null);
- this.tokenTypeType = this.ts.getType(CASTestSetup.TOKEN_TYPE_TYPE);
- assertTrue(this.tokenTypeType != null);
- this.wordType = this.ts.getType(CASTestSetup.WORD_TYPE);
- assertTrue(this.wordType != null);
- this.arrayFsWithSubtypeType = this.ts.getType(CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE);
- assertTrue(this.arrayFsWithSubtypeType != null);
- this.arrayFsWithSubtypeTypeFeat = this.ts.getFeatureByFullName(CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE_FEAT_Q);
- this.group1Type = this.ts.getType(CASTestSetup.GROUP_1);
- assertTrue(this.group1Type != null);
- this.group2Type = this.ts.getType(CASTestSetup.GROUP_2);
- assertTrue(this.group2Type != null);
- this.tokenTypeFeat = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_TYPE_FEAT_Q);
- assertTrue(this.tokenTypeFeat != null);
- this.lemmaFeat = this.ts.getFeatureByFullName(CASTestSetup.LEMMA_FEAT_Q);
- assertTrue(this.lemmaFeat != null);
- this.sentLenFeat = this.ts.getFeatureByFullName(CASTestSetup.SENT_LEN_FEAT_Q);
- assertTrue(this.sentLenFeat != null);
- this.tokenFloatFeat = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_FLOAT_FEAT_Q);
- assertTrue(this.tokenFloatFeat != null);
- this.startFeature = this.ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_BEGIN);
- assertTrue(this.startFeature != null);
- this.langPairType = this.ts.getType(CASTestSetup.LANG_PAIR);
- assertTrue(this.langPairType != null);
- this.lang1 = this.langPairType.getFeatureByBaseName(CASTestSetup.LANG1);
- assertTrue(this.lang1 != null);
- this.lang2 = this.langPairType.getFeatureByBaseName(CASTestSetup.LANG2);
- assertTrue(this.lang2 != null);
- this.descr = this.langPairType.getFeatureByBaseName(CASTestSetup.DESCR_FEAT);
- assertTrue(this.descr != null);
- this.neListType = this.ts.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
- assertTrue(this.neListType != null);
- this.tlFeature = this.neListType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);
- assertTrue(this.tlFeature != null);
- this.hdFeature = this.neListType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
- assertTrue(this.hdFeature != null);
- }
-
- public void tearDown() {
- this.cas = null;
-
- this.ts = null;
- this.topType = null;
- this.stringType = null;
- this.tokenType = null;
-
- this.intType = null;
- this.tokenTypeType = null;
- this.wordType = null;
- this.group1Type = null;
- this.group2Type = null;
-
- this.tokenTypeFeat = null;
- this.lemmaFeat = null;
- this.sentLenFeat = null;
- this.tokenFloatFeat = null;
- this.startFeature = null;
- this.langPairType = null;
- this.lang1 = null;
- this.lang2 = null;
- this.descr = null;
- }
-
- public void testGetType() {
- Type tokenType1 = this.ts.getType(CASTestSetup.TOKEN_TYPE);
- Type wordType1 = this.ts.getType(CASTestSetup.WORD_TYPE);
- FeatureStructure word = this.cas.createFS(wordType1);
- FeatureStructure token = this.cas.createFS(tokenType1);
- assertTrue(word.getType().equals(wordType1));
- assertTrue(token.getType().equals(tokenType1));
- }
-
- public void testSetArrayValuedFeature() {
- FeatureStructure testFS = this.cas.createFS(this.arrayFsWithSubtypeType);
- assertTrue(testFS.getFeatureValue(this.arrayFsWithSubtypeTypeFeat) == null);
- ArrayFS arrayFS = this.cas.createArrayFS(1);
- testFS.setFeatureValue(this.arrayFsWithSubtypeTypeFeat, arrayFS);
- assertTrue(true);
- boolean caughtExc = false;
- try {
- testFS.setFeatureValue(this.arrayFsWithSubtypeTypeFeat, testFS);
- } catch (CASRuntimeException e) {
- caughtExc = true;
- assertTrue(e.getError() == CASRuntimeException.INAPPROP_RANGE);
- }
- assertTrue(caughtExc);
- }
-
- public void testSetFeatureValue() {
- FeatureStructure token = this.cas.createFS(this.tokenType);
- assertTrue(token.getFeatureValue(this.tokenTypeFeat) == null);
- assertTrue(token.getStringValue(this.lemmaFeat) == null);
- boolean caughtExc = false;
- try {
- token.getFeatureValue(this.sentLenFeat);
- } catch (CASRuntimeException e) {
- caughtExc = true;
- assertTrue(e.getError() == CASRuntimeException.INAPPROP_FEAT);
- }
- assertTrue(caughtExc);
- FeatureStructure word = this.cas.createFS(this.wordType);
- token.setFeatureValue(this.tokenTypeFeat, word);
- caughtExc = false;
- try {
- token.setFeatureValue(this.lemmaFeat, word);
- } catch (CASRuntimeException e) {
- caughtExc = true;
- assertTrue(e.getError() == CASRuntimeException.INAPPROP_RANGE);
- }
- assertTrue(caughtExc);
-
- try {
- token.setFeatureValue(this.tokenTypeFeat, null);
- } catch (CASRuntimeException e) {
- assertTrue(false);
- }
-
- caughtExc = false;
- try {
- token.setFeatureValue(this.startFeature, null);
- } catch (CASRuntimeException e) {
- assertTrue(e.getError() == CASRuntimeException.PRIMITIVE_VAL_FEAT);
- caughtExc = true;
- }
- assertTrue(caughtExc);
-
- assertTrue(token.getStringValue(this.lemmaFeat) == null);
- String testString = "test";
- token.setStringValue(this.lemmaFeat, testString);
- assertTrue(token.getStringValue(this.lemmaFeat).equals(testString));
- testString = "";
- token.setStringValue(this.lemmaFeat, testString);
- assertTrue(token.getStringValue(this.lemmaFeat).equals(testString));
- }
-
- public void testSetFloatValue() {
- AnnotationFS token = (AnnotationFS) this.cas.createFS(this.tokenType);
- assertTrue(token.getFloatValue(this.tokenFloatFeat) == 0.0f);
- float f = -3.2f;
- token.setFloatValue(this.tokenFloatFeat, f);
- assertTrue(token.getFloatValue(this.tokenFloatFeat) == f);
- f = 51234.132f;
- token.setFloatValue(this.tokenFloatFeat, f);
- assertTrue(token.getFloatValue(this.tokenFloatFeat) == f);
- boolean caughtExc = false;
- try {
- token.setFloatValue(this.tokenTypeFeat, 0.0f);
- } catch (CASRuntimeException e) {
- caughtExc = true;
- assertTrue(e.getError() == CASRuntimeException.INAPPROP_RANGE);
- }
- assertTrue(caughtExc);
- assertTrue(token.getFloatValue(this.tokenFloatFeat) == f);
- caughtExc = false;
- try {
- token.setFloatValue(this.sentLenFeat, 0.0f);
- } catch (CASRuntimeException e) {
- caughtExc = true;
- assertTrue(e.getError() == CASRuntimeException.INAPPROP_FEAT);
- }
- assertTrue(caughtExc);
- assertTrue(token.getFloatValue(this.tokenFloatFeat) == f);
- }
-
- public void testSetIntValue() {
- AnnotationFS token = (AnnotationFS) this.cas.createFS(this.tokenType);
- assertTrue(token.getIntValue(this.startFeature) == 0);
- int i = 3;
- token.setIntValue(this.startFeature, i);
- assertTrue(token.getIntValue(this.startFeature) == i);
- i = -123456;
- token.setIntValue(this.startFeature, i);
- assertTrue(token.getIntValue(this.startFeature) == i);
- boolean caughtExc = false;
- try {
- token.setIntValue(this.tokenTypeFeat, 0);
- } catch (CASRuntimeException e) {
- caughtExc = true;
- assertTrue(e.getError() == CASRuntimeException.INAPPROP_RANGE);
- }
- assertTrue(caughtExc);
- assertTrue(token.getIntValue(this.startFeature) == i);
- caughtExc = false;
- try {
- token.setIntValue(this.sentLenFeat, 0);
- } catch (CASRuntimeException e) {
- caughtExc = true;
- assertTrue(e.getError() == CASRuntimeException.INAPPROP_FEAT);
- }
- assertTrue(caughtExc);
- assertTrue(token.getIntValue(this.startFeature) == i);
- }
-
-
- public void testStrings() {
- FeatureStructure lp = this.cas.createFS(this.langPairType);
- assertTrue(lp != null);
- // Check that all strings are initially null.
- try {
- assertTrue(lp.getStringValue(this.lang1) == null);
- } catch (Exception e) {
- assertTrue(false);
- }
- try {
- assertTrue(lp.getStringValue(this.lang2) == null);
- } catch (Exception e) {
- assertTrue(false);
- }
- try {
- assertTrue(lp.getStringValue(this.descr) == null);
- } catch (Exception e) {
- assertTrue(false);
- }
- // FeatureStructure topFS = cas.createFS(topType);
- String val = "Some string.";
- try {
- lp.setStringValue(this.descr, val);
- assertTrue(val.equals(lp.getStringValue(this.descr)));
- } catch (CASRuntimeException e) {
- assertTrue(false);
- }
- try {
- lp.setStringValue(this.descr, null);
- assertTrue(lp.getStringValue(this.descr) == null);
- } catch (CASRuntimeException e) {
- assertTrue(false);
- }
- try {
- lp.setStringValue(this.lang1, CASTestSetup.GROUP_1_LANGUAGES[0]);
- lp.setStringValue(this.lang2, CASTestSetup.GROUP_2_LANGUAGES[2]);
- } catch (Exception e) {
- assertTrue(false);
- }
- boolean exc = false;
- try {
- lp.setStringValue(this.lang1, CASTestSetup.GROUP_2_LANGUAGES[0]);
- } catch (CASRuntimeException e) {
- assertTrue(e.getError() == CASRuntimeException.ILLEGAL_STRING_VALUE);
- exc = true;
- }
- assertTrue(exc);
- exc = false;
- try {
- lp.setStringValue(this.lang2, val);
- } catch (CASRuntimeException e) {
- assertTrue(e.getError() == CASRuntimeException.ILLEGAL_STRING_VALUE);
- exc = true;
- }
- assertTrue(exc);
-
- // Regression: toString() used to fail because string subtypes were
- // incorrectly classified as ref types.
- lp.toString();
-
- LowLevelCAS llc = this.cas.getLowLevelCAS();
- LowLevelTypeSystem llts = llc.ll_getTypeSystem();
- final int tokenTypeCode = llts.ll_getCodeForType(this.tokenType);
- final int addr = llc.ll_createFS(tokenTypeCode);
- final int lemmaFeatCode = llts.ll_getCodeForFeature(this.lemmaFeat);
- llc.ll_setStringValue(addr, lemmaFeatCode, "test", true);
- assertTrue(llc.ll_getCharBufferValueSize(addr, lemmaFeatCode) == 4);
-
- }
-
- public void testEquals() {
- // ???
- }
-
- public void testToString() {
- FeatureStructure listFS = this.cas.createFS(this.neListType);
- listFS.setFeatureValue(this.tlFeature, listFS);
- // System.out.println(listFS.toString());
-
- FeatureStructure value = this.cas.createFS(this.tokenType);
- FeatureStructure newList = this.cas.createFS(this.neListType);
- newList.setFeatureValue(this.tlFeature, listFS);
- newList.setFeatureValue(this.hdFeature, value);
- listFS.setFeatureValue(this.hdFeature, value);
- // System.out.println("\n" + newList.toString());
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(FeatureStructureTest.class);
- }
+ public FeatureStructureTest(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() {
+ try {
+ this.cas = CASInitializer.initCas(new CASTestSetup());
+ assertTrue(this.cas != null);
+ this.ts = this.cas.getTypeSystem();
+ assertTrue(this.ts != null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue(false);
+ }
+ this.topType = this.ts.getType(CAS.TYPE_NAME_TOP);
+ assertTrue(this.topType != null);
+ this.stringType = this.ts.getType(CAS.TYPE_NAME_STRING);
+ assertTrue(this.stringType != null);
+ this.tokenType = this.ts.getType(CASTestSetup.TOKEN_TYPE);
+ assertTrue(this.stringType != null);
+ this.intType = this.ts.getType(CAS.TYPE_NAME_INTEGER);
+ assertTrue(this.intType != null);
+ this.tokenTypeType = this.ts.getType(CASTestSetup.TOKEN_TYPE_TYPE);
+ assertTrue(this.tokenTypeType != null);
+ this.wordType = this.ts.getType(CASTestSetup.WORD_TYPE);
+ assertTrue(this.wordType != null);
+ this.arrayFsWithSubtypeType = this.ts.getType(CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE);
+ assertTrue(this.arrayFsWithSubtypeType != null);
+ this.arrayFsWithSubtypeTypeFeat = this.ts
+ .getFeatureByFullName(CASTestSetup.ARRAYFSWITHSUBTYPE_TYPE_FEAT_Q);
+ this.group1Type = this.ts.getType(CASTestSetup.GROUP_1);
+ assertTrue(this.group1Type != null);
+ this.group2Type = this.ts.getType(CASTestSetup.GROUP_2);
+ assertTrue(this.group2Type != null);
+ this.tokenTypeFeat = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_TYPE_FEAT_Q);
+ assertTrue(this.tokenTypeFeat != null);
+ this.lemmaFeat = this.ts.getFeatureByFullName(CASTestSetup.LEMMA_FEAT_Q);
+ assertTrue(this.lemmaFeat != null);
+ this.sentLenFeat = this.ts.getFeatureByFullName(CASTestSetup.SENT_LEN_FEAT_Q);
+ assertTrue(this.sentLenFeat != null);
+ this.tokenFloatFeat = this.ts.getFeatureByFullName(CASTestSetup.TOKEN_FLOAT_FEAT_Q);
+ assertTrue(this.tokenFloatFeat != null);
+ this.startFeature = this.ts.getFeatureByFullName(CAS.FEATURE_FULL_NAME_BEGIN);
+ assertTrue(this.startFeature != null);
+ this.langPairType = this.ts.getType(CASTestSetup.LANG_PAIR);
+ assertTrue(this.langPairType != null);
+ this.lang1 = this.langPairType.getFeatureByBaseName(CASTestSetup.LANG1);
+ assertTrue(this.lang1 != null);
+ this.lang2 = this.langPairType.getFeatureByBaseName(CASTestSetup.LANG2);
+ assertTrue(this.lang2 != null);
+ this.descr = this.langPairType.getFeatureByBaseName(CASTestSetup.DESCR_FEAT);
+ assertTrue(this.descr != null);
+ this.neListType = this.ts.getType(CAS.TYPE_NAME_NON_EMPTY_FS_LIST);
+ assertTrue(this.neListType != null);
+ this.tlFeature = this.neListType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_TAIL);
+ assertTrue(this.tlFeature != null);
+ this.hdFeature = this.neListType.getFeatureByBaseName(CAS.FEATURE_BASE_NAME_HEAD);
+ assertTrue(this.hdFeature != null);
+ }
+
+ public void tearDown() {
+ this.cas = null;
+
+ this.ts = null;
+ this.topType = null;
+ this.stringType = null;
+ this.tokenType = null;
+
+ this.intType = null;
+ this.tokenTypeType = null;
+ this.wordType = null;
+ this.group1Type = null;
+ this.group2Type = null;
+
+ this.tokenTypeFeat = null;
+ this.lemmaFeat = null;
+ this.sentLenFeat = null;
+ this.tokenFloatFeat = null;
+ this.startFeature = null;
+ this.langPairType = null;
+ this.lang1 = null;
+ this.lang2 = null;
+ this.descr = null;
+ }
+
+ public void testGetType() {
+ Type tokenType1 = this.ts.getType(CASTestSetup.TOKEN_TYPE);
+ Type wordType1 = this.ts.getType(CASTestSetup.WORD_TYPE);
+ FeatureStructure word = this.cas.createFS(wordType1);
+ FeatureStructure token = this.cas.createFS(tokenType1);
+ assertTrue(word.getType().equals(wordType1));
+ assertTrue(token.getType().equals(tokenType1));
+ }
+
+ public void testSetArrayValuedFeature() {
+ FeatureStructure testFS = this.cas.createFS(this.arrayFsWithSubtypeType);
+ assertTrue(testFS.getFeatureValue(this.arrayFsWithSubtypeTypeFeat) == null);
+ ArrayFS arrayFS = this.cas.createArrayFS(1);
+ testFS.setFeatureValue(this.arrayFsWithSubtypeTypeFeat, arrayFS);
+ assertTrue(true);
+ boolean caughtExc = false;
+ try {
+ testFS.setFeatureValue(this.arrayFsWithSubtypeTypeFeat, testFS);
+ } catch (CASRuntimeException e) {
+ caughtExc = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.INAPPROP_RANGE));
+ }
+ assertTrue(caughtExc);
+ }
+
+ public void testSetFeatureValue() {
+ FeatureStructure token = this.cas.createFS(this.tokenType);
+ assertTrue(token.getFeatureValue(this.tokenTypeFeat) == null);
+ assertTrue(token.getStringValue(this.lemmaFeat) == null);
+ boolean caughtExc = false;
+ try {
+ token.getFeatureValue(this.sentLenFeat);
+ } catch (CASRuntimeException e) {
+ caughtExc = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.INAPPROP_FEAT));
+ }
+ assertTrue(caughtExc);
+ FeatureStructure word = this.cas.createFS(this.wordType);
+ token.setFeatureValue(this.tokenTypeFeat, word);
+ caughtExc = false;
+ try {
+ token.setFeatureValue(this.lemmaFeat, word);
+ } catch (CASRuntimeException e) {
+ caughtExc = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.INAPPROP_RANGE));
+ }
+ assertTrue(caughtExc);
+
+ try {
+ token.setFeatureValue(this.tokenTypeFeat, null);
+ } catch (CASRuntimeException e) {
+ assertTrue(false);
+ }
+
+ caughtExc = false;
+ try {
+ token.setFeatureValue(this.startFeature, null);
+ } catch (CASRuntimeException e) {
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.PRIMITIVE_VAL_FEAT));
+ caughtExc = true;
+ }
+ assertTrue(caughtExc);
+
+ assertTrue(token.getStringValue(this.lemmaFeat) == null);
+ String testString = "test";
+ token.setStringValue(this.lemmaFeat, testString);
+ assertTrue(token.getStringValue(this.lemmaFeat).equals(testString));
+ testString = "";
+ token.setStringValue(this.lemmaFeat, testString);
+ assertTrue(token.getStringValue(this.lemmaFeat).equals(testString));
+ }
+
+ public void testSetFloatValue() {
+ AnnotationFS token = (AnnotationFS) this.cas.createFS(this.tokenType);
+ assertTrue(token.getFloatValue(this.tokenFloatFeat) == 0.0f);
+ float f = -3.2f;
+ token.setFloatValue(this.tokenFloatFeat, f);
+ assertTrue(token.getFloatValue(this.tokenFloatFeat) == f);
+ f = 51234.132f;
+ token.setFloatValue(this.tokenFloatFeat, f);
+ assertTrue(token.getFloatValue(this.tokenFloatFeat) == f);
+ boolean caughtExc = false;
+ try {
+ token.setFloatValue(this.tokenTypeFeat, 0.0f);
+ } catch (CASRuntimeException e) {
+ caughtExc = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.INAPPROP_RANGE));
+ }
+ assertTrue(caughtExc);
+ assertTrue(token.getFloatValue(this.tokenFloatFeat) == f);
+ caughtExc = false;
+ try {
+ token.setFloatValue(this.sentLenFeat, 0.0f);
+ } catch (CASRuntimeException e) {
+ caughtExc = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.INAPPROP_FEAT));
+ }
+ assertTrue(caughtExc);
+ assertTrue(token.getFloatValue(this.tokenFloatFeat) == f);
+ }
+
+ public void testSetIntValue() {
+ AnnotationFS token = (AnnotationFS) this.cas.createFS(this.tokenType);
+ assertTrue(token.getIntValue(this.startFeature) == 0);
+ int i = 3;
+ token.setIntValue(this.startFeature, i);
+ assertTrue(token.getIntValue(this.startFeature) == i);
+ i = -123456;
+ token.setIntValue(this.startFeature, i);
+ assertTrue(token.getIntValue(this.startFeature) == i);
+ boolean caughtExc = false;
+ try {
+ token.setIntValue(this.tokenTypeFeat, 0);
+ } catch (CASRuntimeException e) {
+ caughtExc = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.INAPPROP_RANGE));
+ }
+ assertTrue(caughtExc);
+ assertTrue(token.getIntValue(this.startFeature) == i);
+ caughtExc = false;
+ try {
+ token.setIntValue(this.sentLenFeat, 0);
+ } catch (CASRuntimeException e) {
+ caughtExc = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.INAPPROP_FEAT));
+ }
+ assertTrue(caughtExc);
+ assertTrue(token.getIntValue(this.startFeature) == i);
+ }
+
+ public void testStrings() {
+ FeatureStructure lp = this.cas.createFS(this.langPairType);
+ assertTrue(lp != null);
+ // Check that all strings are initially null.
+ try {
+ assertTrue(lp.getStringValue(this.lang1) == null);
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ try {
+ assertTrue(lp.getStringValue(this.lang2) == null);
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ try {
+ assertTrue(lp.getStringValue(this.descr) == null);
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ // FeatureStructure topFS = cas.createFS(topType);
+ String val = "Some string.";
+ try {
+ lp.setStringValue(this.descr, val);
+ assertTrue(val.equals(lp.getStringValue(this.descr)));
+ } catch (CASRuntimeException e) {
+ assertTrue(false);
+ }
+ try {
+ lp.setStringValue(this.descr, null);
+ assertTrue(lp.getStringValue(this.descr) == null);
+ } catch (CASRuntimeException e) {
+ assertTrue(false);
+ }
+ try {
+ lp.setStringValue(this.lang1, CASTestSetup.GROUP_1_LANGUAGES[0]);
+ lp.setStringValue(this.lang2, CASTestSetup.GROUP_2_LANGUAGES[2]);
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ boolean exc = false;
+ try {
+ lp.setStringValue(this.lang1, CASTestSetup.GROUP_2_LANGUAGES[0]);
+ } catch (CASRuntimeException e) {
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.ILLEGAL_STRING_VALUE));
+ exc = true;
+ }
+ assertTrue(exc);
+ exc = false;
+ try {
+ lp.setStringValue(this.lang2, val);
+ } catch (CASRuntimeException e) {
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.ILLEGAL_STRING_VALUE));
+ exc = true;
+ }
+ assertTrue(exc);
+
+ // Regression: toString() used to fail because string subtypes were
+ // incorrectly classified as ref types.
+ lp.toString();
+
+ LowLevelCAS llc = this.cas.getLowLevelCAS();
+ LowLevelTypeSystem llts = llc.ll_getTypeSystem();
+ final int tokenTypeCode = llts.ll_getCodeForType(this.tokenType);
+ final int addr = llc.ll_createFS(tokenTypeCode);
+ final int lemmaFeatCode = llts.ll_getCodeForFeature(this.lemmaFeat);
+ llc.ll_setStringValue(addr, lemmaFeatCode, "test", true);
+ assertTrue(llc.ll_getCharBufferValueSize(addr, lemmaFeatCode) == 4);
+
+ }
+
+ public void testEquals() {
+ // ???
+ }
+
+ public void testToString() {
+ FeatureStructure listFS = this.cas.createFS(this.neListType);
+ listFS.setFeatureValue(this.tlFeature, listFS);
+ // System.out.println(listFS.toString());
+
+ FeatureStructure value = this.cas.createFS(this.tokenType);
+ FeatureStructure newList = this.cas.createFS(this.neListType);
+ newList.setFeatureValue(this.tlFeature, listFS);
+ newList.setFeatureValue(this.hdFeature, value);
+ listFS.setFeatureValue(this.hdFeature, value);
+ // System.out.println("\n" + newList.toString());
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(FeatureStructureTest.class);
+ }
}
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/FloatArrayFSTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/FloatArrayFSTest.java?view=diff&rev=497800&r1=497799&r2=497800
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/FloatArrayFSTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/FloatArrayFSTest.java Fri Jan 19 05:08:19 2007
@@ -24,131 +24,126 @@
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASRuntimeException;
import org.apache.uima.cas.FloatArrayFS;
-import org.apache.uima.cas.TypeSystem;
public class FloatArrayFSTest extends TestCase {
- private CAS cas;
+ private CAS cas;
- private TypeSystem ts;
-
- /**
+ /**
* Constructor for ArrayFSTest.
*
* @param arg0
*/
- public FloatArrayFSTest(String arg0) {
- super(arg0);
- }
-
- public void setUp() {
- try {
- this.cas = CASInitializer.initCas(new CASTestSetup());
- this.ts = this.cas.getTypeSystem();
- } catch (Exception e) {
- assertTrue(false);
- }
- }
-
- public void tearDown() {
- this.cas = null;
- this.ts = null;
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(FloatArrayFSTest.class);
- }
-
- public void testSet() {
- FloatArrayFS array = cas.createFloatArrayFS(0);
- assertTrue(array != null);
- assertTrue(array.size() == 0);
- boolean exceptionCaught = false;
- try {
- array.get(0);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- array = cas.createFloatArrayFS(3);
- try {
- array.set(0, 1.0f);
- array.set(1, 2.0f);
- array.set(2, 3.0f);
- } catch (ArrayIndexOutOfBoundsException e) {
- assertTrue(false);
- }
- exceptionCaught = false;
- try {
- array.set(-1, 1.0f);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- exceptionCaught = false;
- try {
- array.set(4, 1.0f);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- assertTrue(array.get(0) == 1f);
- assertTrue(array.get(1) == 2f);
- assertTrue(array.get(2) == 3f);
- exceptionCaught = false;
- try {
- array.get(-1);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- exceptionCaught = false;
- try {
- array.get(4);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- // Check that we can't create arrays smaller than 0.
- exceptionCaught = false;
- try {
- array = cas.createFloatArrayFS(-1);
- } catch (CASRuntimeException e) {
- exceptionCaught = true;
- assertTrue(e.getError() == CASRuntimeException.ILLEGAL_ARRAY_SIZE);
- }
- assertTrue(exceptionCaught);
- }
-
- public void testToArray() {
- // From CAS array to Java array.
- FloatArrayFS array = cas.createFloatArrayFS(3);
- float[] fsArray = array.toArray();
- for (int i = 0; i < 3; i++) {
- assertTrue(fsArray[i] == 0f);
- }
- array.set(0, 1f);
- array.set(1, 2f);
- array.set(2, 3f);
- fsArray = array.toArray();
- assertTrue(fsArray.length == 3);
- assertTrue(fsArray[0] == 1f);
- assertTrue(fsArray[1] == 2f);
- assertTrue(fsArray[2] == 3f);
-
- // From Java array to CAS array.
- array = cas.createFloatArrayFS(3);
- assertTrue(array.get(0) == 0f);
- assertTrue(array.get(1) == 0f);
- assertTrue(array.get(2) == 0f);
- for (int i = 0; i < 3; i++) {
- array.set(i, fsArray[i]);
- }
- assertTrue(array.get(0) == 1f);
- assertTrue(array.get(1) == 2f);
- assertTrue(array.get(2) == 3f);
- array.set(0, 0f);
- assertTrue(array.get(0) == 0f);
- }
+ public FloatArrayFSTest(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() {
+ try {
+ this.cas = CASInitializer.initCas(new CASTestSetup());
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ }
+
+ public void tearDown() {
+ this.cas = null;
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(FloatArrayFSTest.class);
+ }
+
+ public void testSet() {
+ FloatArrayFS array = this.cas.createFloatArrayFS(0);
+ assertTrue(array != null);
+ assertTrue(array.size() == 0);
+ boolean exceptionCaught = false;
+ try {
+ array.get(0);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ array = this.cas.createFloatArrayFS(3);
+ try {
+ array.set(0, 1.0f);
+ array.set(1, 2.0f);
+ array.set(2, 3.0f);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ assertTrue(false);
+ }
+ exceptionCaught = false;
+ try {
+ array.set(-1, 1.0f);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ exceptionCaught = false;
+ try {
+ array.set(4, 1.0f);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ assertTrue(array.get(0) == 1f);
+ assertTrue(array.get(1) == 2f);
+ assertTrue(array.get(2) == 3f);
+ exceptionCaught = false;
+ try {
+ array.get(-1);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ exceptionCaught = false;
+ try {
+ array.get(4);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ // Check that we can't create arrays smaller than 0.
+ exceptionCaught = false;
+ try {
+ array = this.cas.createFloatArrayFS(-1);
+ } catch (CASRuntimeException e) {
+ exceptionCaught = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.ILLEGAL_ARRAY_SIZE));
+ }
+ assertTrue(exceptionCaught);
+ }
+
+ public void testToArray() {
+ // From CAS array to Java array.
+ FloatArrayFS array = this.cas.createFloatArrayFS(3);
+ float[] fsArray = array.toArray();
+ for (int i = 0; i < 3; i++) {
+ assertTrue(fsArray[i] == 0f);
+ }
+ array.set(0, 1f);
+ array.set(1, 2f);
+ array.set(2, 3f);
+ fsArray = array.toArray();
+ assertTrue(fsArray.length == 3);
+ assertTrue(fsArray[0] == 1f);
+ assertTrue(fsArray[1] == 2f);
+ assertTrue(fsArray[2] == 3f);
+
+ // From Java array to CAS array.
+ array = this.cas.createFloatArrayFS(3);
+ assertTrue(array.get(0) == 0f);
+ assertTrue(array.get(1) == 0f);
+ assertTrue(array.get(2) == 0f);
+ for (int i = 0; i < 3; i++) {
+ array.set(i, fsArray[i]);
+ }
+ assertTrue(array.get(0) == 1f);
+ assertTrue(array.get(1) == 2f);
+ assertTrue(array.get(2) == 3f);
+ array.set(0, 0f);
+ assertTrue(array.get(0) == 0f);
+ }
}
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IntArrayFSTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IntArrayFSTest.java?view=diff&rev=497800&r1=497799&r2=497800
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IntArrayFSTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/IntArrayFSTest.java Fri Jan 19 05:08:19 2007
@@ -24,14 +24,11 @@
import org.apache.uima.cas.CAS;
import org.apache.uima.cas.CASRuntimeException;
import org.apache.uima.cas.IntArrayFS;
-import org.apache.uima.cas.TypeSystem;
public class IntArrayFSTest extends TestCase {
private CAS cas;
- private TypeSystem ts;
-
/**
* Constructor for ArrayFSTest.
*
@@ -44,7 +41,6 @@
public void setUp() {
try {
this.cas = CASInitializer.initCas(new CASTestSetup());
- this.ts = this.cas.getTypeSystem();
} catch (Exception e) {
assertTrue(false);
}
@@ -52,7 +48,6 @@
public void tearDown() {
this.cas = null;
- this.ts = null;
}
public static void main(String[] args) {
@@ -60,7 +55,7 @@
}
public void testSet() {
- IntArrayFS array = cas.createIntArrayFS(0);
+ IntArrayFS array = this.cas.createIntArrayFS(0);
assertTrue(array != null);
assertTrue(array.size() == 0);
boolean exceptionCaught = false;
@@ -70,7 +65,7 @@
exceptionCaught = true;
}
assertTrue(exceptionCaught);
- array = cas.createIntArrayFS(3);
+ array = this.cas.createIntArrayFS(3);
try {
array.set(0, 1);
array.set(1, 2);
@@ -112,17 +107,17 @@
// Check that we can't create arrays smaller than 0.
exceptionCaught = false;
try {
- array = cas.createIntArrayFS(-1);
+ array = this.cas.createIntArrayFS(-1);
} catch (CASRuntimeException e) {
exceptionCaught = true;
- assertTrue(e.getError() == CASRuntimeException.ILLEGAL_ARRAY_SIZE);
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.ILLEGAL_ARRAY_SIZE));
}
assertTrue(exceptionCaught);
}
public void testToArray() {
// From CAS array to Java array.
- IntArrayFS array = cas.createIntArrayFS(3);
+ IntArrayFS array = this.cas.createIntArrayFS(3);
int[] fsArray = array.toArray();
for (int i = 0; i < 3; i++) {
assertTrue(fsArray[i] == 0);
@@ -137,7 +132,7 @@
assertTrue(fsArray[2] == 3);
// From Java array to CAS array.
- array = cas.createIntArrayFS(3);
+ array = this.cas.createIntArrayFS(3);
assertTrue(array.get(0) == 0);
assertTrue(array.get(1) == 0);
assertTrue(array.get(2) == 0);
Modified: incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java?view=diff&rev=497800&r1=497799&r2=497800
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-core/src/test/java/org/apache/uima/cas/test/StringArrayTest.java Fri Jan 19 05:08:19 2007
@@ -34,144 +34,144 @@
*/
public class StringArrayTest extends TestCase {
- private CAS cas;
+ private CAS cas;
- private TypeSystem ts;
+ private TypeSystem ts;
- /**
+ /**
* Constructor for ArrayFSTest.
*
* @param arg0
*/
- public StringArrayTest(String arg0) {
- super(arg0);
- }
-
- public void setUp() {
- try {
- this.cas = CASInitializer.initCas(new CASTestSetup());
- this.ts = this.cas.getTypeSystem();
- } catch (Exception e) {
- assertTrue(false);
- }
- }
-
- public void tearDown() {
- this.cas = null;
- this.ts = null;
- }
-
- public static void main(String[] args) {
- junit.textui.TestRunner.run(StringArrayTest.class);
- }
-
- public void testSet() {
- StringArrayFS array = cas.createStringArrayFS(0);
- assertTrue(array != null);
- assertTrue(array.size() == 0);
- boolean exceptionCaught = false;
- try {
- array.get(0);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- array = cas.createStringArrayFS(3);
- try {
- array.set(0, "1");
- array.set(1, "2");
- array.set(2, "3");
- } catch (ArrayIndexOutOfBoundsException e) {
- assertTrue(false);
- }
- exceptionCaught = false;
- try {
- array.set(-1, "1");
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- exceptionCaught = false;
- try {
- array.set(4, "1");
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- assertTrue(array.get(0).equals("1"));
- assertTrue(array.get(1).equals("2"));
- assertTrue(array.get(2).equals("3"));
- exceptionCaught = false;
- try {
- array.get(-1);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- exceptionCaught = false;
- try {
- array.get(4);
- } catch (ArrayIndexOutOfBoundsException e) {
- exceptionCaught = true;
- }
- assertTrue(exceptionCaught);
- // Check that we can't create arrays smaller than 0.
- exceptionCaught = false;
- try {
- array = cas.createStringArrayFS(-1);
- } catch (CASRuntimeException e) {
- exceptionCaught = true;
- assertTrue(e.getError() == CASRuntimeException.ILLEGAL_ARRAY_SIZE);
- }
- assertTrue(exceptionCaught);
- }
-
- public void testToArray() {
- // From CAS array to Java array.
- StringArrayFS array = cas.createStringArrayFS(3);
- String[] fsArray = array.toArray();
- for (int i = 0; i < 3; i++) {
- assertTrue(fsArray[i] == null);
- }
- array.set(0, "1");
- array.set(1, "2");
- array.set(2, "3");
- fsArray = array.toArray();
- assertTrue(fsArray.length == 3);
- assertTrue(fsArray[0].equals("1"));
- assertTrue(fsArray[1].equals("2"));
- assertTrue(fsArray[2].equals("3"));
-
- // From Java array to CAS array.
- array = cas.createStringArrayFS(3);
- assertTrue(array.get(0) == null);
- assertTrue(array.get(1) == null);
- assertTrue(array.get(2) == null);
- for (int i = 0; i < 3; i++) {
- array.set(i, fsArray[i]);
- }
- assertTrue(array.get(0).equals("1"));
- assertTrue(array.get(1).equals("2"));
- assertTrue(array.get(2).equals("3"));
- array.set(0, null);
- assertTrue(array.get(0) == null);
- }
-
- public void testStringArrayValue() {
- String lemmaListName = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR
- + CASTestSetup.LEMMA_LIST_FEAT;
- final Feature lemmaList = this.ts.getFeatureByFullName(lemmaListName);
- assertTrue(lemmaList != null);
- String[] javaArray = { "1", "2", "3" };
- StringArrayFS casArray = this.cas.createStringArrayFS(3);
- casArray.copyFromArray(javaArray, 0, 0, 3);
- FeatureStructure token = cas.createFS(this.ts.getType(CASTestSetup.TOKEN_TYPE));
- assertTrue(token.getFeatureValue(lemmaList) == null);
- token.setFeatureValue(lemmaList, casArray);
- assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == "1");
- String hello = "Hello.";
- casArray.set(0, hello);
- assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == hello);
- }
+ public StringArrayTest(String arg0) {
+ super(arg0);
+ }
+
+ public void setUp() {
+ try {
+ this.cas = CASInitializer.initCas(new CASTestSetup());
+ this.ts = this.cas.getTypeSystem();
+ } catch (Exception e) {
+ assertTrue(false);
+ }
+ }
+
+ public void tearDown() {
+ this.cas = null;
+ this.ts = null;
+ }
+
+ public static void main(String[] args) {
+ junit.textui.TestRunner.run(StringArrayTest.class);
+ }
+
+ public void testSet() {
+ StringArrayFS array = this.cas.createStringArrayFS(0);
+ assertTrue(array != null);
+ assertTrue(array.size() == 0);
+ boolean exceptionCaught = false;
+ try {
+ array.get(0);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ array = this.cas.createStringArrayFS(3);
+ try {
+ array.set(0, "1");
+ array.set(1, "2");
+ array.set(2, "3");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ assertTrue(false);
+ }
+ exceptionCaught = false;
+ try {
+ array.set(-1, "1");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ exceptionCaught = false;
+ try {
+ array.set(4, "1");
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ assertTrue(array.get(0).equals("1"));
+ assertTrue(array.get(1).equals("2"));
+ assertTrue(array.get(2).equals("3"));
+ exceptionCaught = false;
+ try {
+ array.get(-1);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ exceptionCaught = false;
+ try {
+ array.get(4);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ exceptionCaught = true;
+ }
+ assertTrue(exceptionCaught);
+ // Check that we can't create arrays smaller than 0.
+ exceptionCaught = false;
+ try {
+ array = this.cas.createStringArrayFS(-1);
+ } catch (CASRuntimeException e) {
+ exceptionCaught = true;
+ assertTrue(e.getMessageKey().equals(CASRuntimeException.ILLEGAL_ARRAY_SIZE));
+ }
+ assertTrue(exceptionCaught);
+ }
+
+ public void testToArray() {
+ // From CAS array to Java array.
+ StringArrayFS array = this.cas.createStringArrayFS(3);
+ String[] fsArray = array.toArray();
+ for (int i = 0; i < 3; i++) {
+ assertTrue(fsArray[i] == null);
+ }
+ array.set(0, "1");
+ array.set(1, "2");
+ array.set(2, "3");
+ fsArray = array.toArray();
+ assertTrue(fsArray.length == 3);
+ assertTrue(fsArray[0].equals("1"));
+ assertTrue(fsArray[1].equals("2"));
+ assertTrue(fsArray[2].equals("3"));
+
+ // From Java array to CAS array.
+ array = this.cas.createStringArrayFS(3);
+ assertTrue(array.get(0) == null);
+ assertTrue(array.get(1) == null);
+ assertTrue(array.get(2) == null);
+ for (int i = 0; i < 3; i++) {
+ array.set(i, fsArray[i]);
+ }
+ assertTrue(array.get(0).equals("1"));
+ assertTrue(array.get(1).equals("2"));
+ assertTrue(array.get(2).equals("3"));
+ array.set(0, null);
+ assertTrue(array.get(0) == null);
+ }
+
+ public void testStringArrayValue() {
+ String lemmaListName = CASTestSetup.TOKEN_TYPE + TypeSystem.FEATURE_SEPARATOR
+ + CASTestSetup.LEMMA_LIST_FEAT;
+ final Feature lemmaList = this.ts.getFeatureByFullName(lemmaListName);
+ assertTrue(lemmaList != null);
+ String[] javaArray = { "1", "2", "3" };
+ StringArrayFS casArray = this.cas.createStringArrayFS(3);
+ casArray.copyFromArray(javaArray, 0, 0, 3);
+ FeatureStructure token = this.cas.createFS(this.ts.getType(CASTestSetup.TOKEN_TYPE));
+ assertTrue(token.getFeatureValue(lemmaList) == null);
+ token.setFeatureValue(lemmaList, casArray);
+ assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == "1");
+ String hello = "Hello.";
+ casArray.set(0, hello);
+ assertTrue(((StringArrayFS) token.getFeatureValue(lemmaList)).get(0) == hello);
+ }
}