use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.
the class QuestionDefTest method testConstructors.
@Test
public void testConstructors() {
QuestionDef q;
q = new QuestionDef();
if (q.getID() != -1) {
fail("QuestionDef not initialized properly (default constructor)");
}
q = new QuestionDef(17, Constants.CONTROL_RANGE);
if (q.getID() != 17) {
fail("QuestionDef not initialized properly");
}
testSerialize(q, "b");
}
use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.
the class QuestionDefTest method testReferences.
@Test
public void testReferences() {
QuestionDef q = fpi.getFirstQuestionDef();
FormEntryPrompt fep = fpi.getFormEntryModel().getQuestionPrompt();
Localizer l = fpi.getFormDef().getLocalizer();
l.setDefaultLocale(l.getAvailableLocales()[0]);
l.setLocale(l.getAvailableLocales()[0]);
String audioURI = fep.getAudioText();
String ref;
ReferenceManager.instance().addReferenceFactory(new ResourceReferenceFactory());
ReferenceManager.instance().addRootTranslator(new RootTranslator("jr://audio/", "jr://resource/"));
try {
Reference r = ReferenceManager.instance().DeriveReference(audioURI);
ref = r.getURI();
if (!ref.equals("jr://resource/hah.mp3")) {
fail("Root translation failed.");
}
} catch (InvalidReferenceException ire) {
fail("There was an Invalid Reference Exception:" + ire.getMessage());
ire.printStackTrace();
}
ReferenceManager.instance().addRootTranslator(new RootTranslator("jr://images/", "jr://resource/"));
q = fpi.getNextQuestion();
fep = fpi.getFormEntryModel().getQuestionPrompt();
String imURI = fep.getImageText();
try {
Reference r = ReferenceManager.instance().DeriveReference(imURI);
ref = r.getURI();
if (!ref.equals("jr://resource/four.gif")) {
fail("Root translation failed.");
}
} catch (InvalidReferenceException ire) {
fail("There was an Invalid Reference Exception:" + ire.getMessage());
ire.printStackTrace();
}
}
use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.
the class QuestionDefTest method testChild.
@Test
public void testChild() {
QuestionDef q = new QuestionDef();
if (q.getChildren() != null) {
fail("Question has children");
}
try {
q.setChildren(new ArrayList<IFormElement>());
fail("Set a question's children without exception");
} catch (IllegalStateException ise) {
// expected
}
try {
q.addChild(new QuestionDef());
fail("Added a child to a question without exception");
} catch (IllegalStateException ise) {
// expected
}
}
use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.
the class TextFormTests method testNonLocalizedText.
public void testNonLocalizedText() {
FormEntryController fec = fpi.getFormEntryController();
fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
boolean testFlag = false;
Localizer l = fpi.getFormDef().getLocalizer();
l.setDefaultLocale(l.getAvailableLocales()[0]);
l.setLocale(l.getAvailableLocales()[0]);
do {
if (fpi.getCurrentQuestion() == null)
continue;
QuestionDef q = fpi.getCurrentQuestion();
fep = fpi.getFormEntryModel().getQuestionPrompt();
String t = fep.getQuestionText();
if (t == null)
continue;
if (t.equals("Non-Localized label inner text!"))
testFlag = true;
} while (fec.stepToNextEvent() != FormEntryController.EVENT_END_OF_FORM);
if (!testFlag)
fail("Failed to fallback to labelInnerText in testNonLocalizedText()");
}
use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.
the class TextFormTests method testSelectChoicesNoLocalizer.
public void testSelectChoicesNoLocalizer() {
QuestionDef q = fpi.getFirstQuestionDef();
if (q.getNumChoices() != 0) {
fail("Select choices not empty on init");
}
// fpi.getNextQuestion();
String onetext = "choice";
String twotext = "stacey's";
SelectChoice one = new SelectChoice(null, onetext, "val", false);
q.addSelectChoice(one);
SelectChoice two = new SelectChoice(null, twotext, "mom", false);
q.addSelectChoice(two);
if (!fep.getSelectChoices().toString().equals("[choice => val, stacey's => mom]")) {
fail("Could not add individual select choice" + fep.getSelectChoices().toString());
}
Object a = onetext;
Object b = fep.getSelectChoiceText(one);
assertEquals("Invalid select choice text returned", a, b);
assertEquals("Invalid select choice text returned", twotext, fep.getSelectChoiceText(two));
assertNull("Form Entry Caption incorrectly contains Image Text", fep.getSpecialFormSelectChoiceText(one, FormEntryCaption.TEXT_FORM_IMAGE));
assertNull("Form Entry Caption incorrectly contains Audio Text", fep.getSpecialFormSelectChoiceText(one, FormEntryCaption.TEXT_FORM_AUDIO));
q.removeSelectChoice(q.getChoice(0));
q.removeSelectChoice(q.getChoice(0));
}
Aggregations