Search in sources :

Example 6 with QuestionDef

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");
}
Also used : QuestionDef(org.javarosa.core.model.QuestionDef) Test(org.junit.Test)

Example 7 with QuestionDef

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();
    }
}
Also used : ResourceReferenceFactory(org.javarosa.core.reference.ResourceReferenceFactory) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) Reference(org.javarosa.core.reference.Reference) IDataReference(org.javarosa.core.model.IDataReference) QuestionDef(org.javarosa.core.model.QuestionDef) Localizer(org.javarosa.core.services.locale.Localizer) RootTranslator(org.javarosa.core.reference.RootTranslator) InvalidReferenceException(org.javarosa.core.reference.InvalidReferenceException) Test(org.junit.Test)

Example 8 with QuestionDef

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
    }
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) QuestionDef(org.javarosa.core.model.QuestionDef) Test(org.junit.Test)

Example 9 with QuestionDef

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()");
}
Also used : FormEntryController(org.javarosa.form.api.FormEntryController) Localizer(org.javarosa.core.services.locale.Localizer) QuestionDef(org.javarosa.core.model.QuestionDef)

Example 10 with QuestionDef

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));
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) QuestionDef(org.javarosa.core.model.QuestionDef)

Aggregations

QuestionDef (org.javarosa.core.model.QuestionDef)30 IFormElement (org.javarosa.core.model.IFormElement)8 SelectChoice (org.javarosa.core.model.SelectChoice)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 GroupDef (org.javarosa.core.model.GroupDef)5 IDataReference (org.javarosa.core.model.IDataReference)4 Selection (org.javarosa.core.model.data.helper.Selection)4 TreeElement (org.javarosa.core.model.instance.TreeElement)4 FormEntryPrompt (org.javarosa.form.api.FormEntryPrompt)4 TreeReference (org.javarosa.core.model.instance.TreeReference)3 Localizer (org.javarosa.core.services.locale.Localizer)3 List (java.util.List)2 FormDef (org.javarosa.core.model.FormDef)2 ItemsetBinding (org.javarosa.core.model.ItemsetBinding)2 Constraint (org.javarosa.core.model.condition.Constraint)2 EvaluationContext (org.javarosa.core.model.condition.EvaluationContext)2 SelectMultiData (org.javarosa.core.model.data.SelectMultiData)2 SelectOneData (org.javarosa.core.model.data.SelectOneData)2 AbstractTreeElement (org.javarosa.core.model.instance.AbstractTreeElement)2