}
}
public void testJCasAccessing() throws Exception {
try {
Root r1 = new Root(jcas);
r1.setArrayFloat(new FloatArray(jcas, 2));
r1.setArrayFloat(0, (float) 3.0);
r1.setArrayFloat(1, (float) 2.5);
assertTrue(3.0 == r1.getArrayFloat(0));
assertTrue(2.5 == r1.getArrayFloat(1));
Root r2 = new Root(jcas);
r2.setArrayRef(new FSArray(jcas, 3));
EndOfSentence eos1 = new EndOfSentence(jcas);
EndOfSentence eos2 = new EndOfSentence(jcas);
r2.setArrayRef(0, eos1);
r2.setArrayRef(1, eos2);
assertTrue(r2.getArrayRef(0).equals(eos1));
assertTrue(r2.getArrayRef(1).equals(eos2));
r2.setArrayInt(new IntegerArray(jcas, 1));
r2.setArrayInt(0, 17);
assertTrue(r2.getArrayInt(0) == 17);
IntegerArray ia = r2.getArrayInt();
assertTrue(ia.get(0) == 17);
r2.setArrayString(new StringArray(jcas, 2));
r2.setArrayString(0, "zero");
r2.setArrayString(1, "one");
assertTrue(r2.getArrayString(0).equals("zero"));
assertTrue(r2.getArrayString(1).equals("one"));
// error paths
// array out of bounds
try {
r2.getArrayString(2);
} catch (LowLevelException e) {
if (e.getError() != LowLevelException.ARRAY_INDEX_OUT_OF_RANGE)
assertTrue(false);
}
try {
r2.setArrayString(-1, "should fail");
} catch (LowLevelException e) {
if (e.getError() != LowLevelException.ARRAY_INDEX_OUT_OF_RANGE)
assertTrue(false);
}
// null values
r2.setArrayString(0, null);
r2.setArrayRef(0, null);
r2.setArrayRef(null);
r2.setArrayString(null);
r2.setPlainRef(null);
r2.setPlainString(null);
assertTrue(null == r2.getPlainString());
assertTrue(null == r2.getPlainRef());
try {
r2.getArrayRef(0);
} catch (LowLevelException e) {
if (e.getError() != LowLevelException.NULL_ARRAY_ACCESS)
assertTrue(false);
}
assertTrue(null == r2.getArrayString());
assertTrue(null == r2.getArrayRef());
r2.addToIndexes();
r1.addToIndexes();
JFSIndexRepository jfsi = jcas.getJFSIndexRepository();
FSIndex fsi1 = jfsi.getIndex("all", Root.type);
FSIterator fsit1 = fsi1.iterator();