Search in sources :

Example 26 with QuestionDef

use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.

the class TextFormTests method testPromptsNoLocalizer.

public void testPromptsNoLocalizer() {
    QuestionDef q = new QuestionDef();
    q.setLabelInnerText("labelInnerText");
    if (!"labelInnerText".equals(q.getLabelInnerText())) {
        fail("LabelInnerText getter/setter broken");
    }
    q.setHelpText("help text");
    if (!"help text".equals(q.getHelpText())) {
        fail("Help text getter/setter broken");
    }
}
Also used : QuestionDef(org.javarosa.core.model.QuestionDef)

Example 27 with QuestionDef

use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.

the class TextFormTests method testConstructors.

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");
    }
    if (q.getControlType() != Constants.CONTROL_RANGE) {
        fail("QuestionDef not initialized properly");
    }
}
Also used : QuestionDef(org.javarosa.core.model.QuestionDef)

Example 28 with QuestionDef

use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.

the class TextFormTests method testPromptsWithLocalizer.

public void testPromptsWithLocalizer() {
    Localizer l = new Localizer();
    TableLocaleSource table = new TableLocaleSource();
    l.addAvailableLocale("locale");
    l.setDefaultLocale("locale");
    table.setLocaleMapping("prompt;long", "loc: long text");
    table.setLocaleMapping("prompt;short", "loc: short text");
    table.setLocaleMapping("help", "loc: help text");
    l.registerLocaleResource("locale", table);
    l.setLocale("locale");
    QuestionDef q = new QuestionDef();
    q.setHelpTextID("help");
    FormEntryPrompt fep = new DummyFormEntryPrompt(l, "prompt", q);
    if (!"loc: long text".equals(fep.getLongText())) {
        fail("Long text did not localize properly");
    }
    if (!"loc: short text".equals(fep.getShortText())) {
        fail("Short text did not localize properly");
    }
}
Also used : FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DummyFormEntryPrompt(org.javarosa.core.model.test.DummyFormEntryPrompt) DummyFormEntryPrompt(org.javarosa.core.model.test.DummyFormEntryPrompt) TableLocaleSource(org.javarosa.core.services.locale.TableLocaleSource) Localizer(org.javarosa.core.services.locale.Localizer) QuestionDef(org.javarosa.core.model.QuestionDef)

Example 29 with QuestionDef

use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.

the class SelectMultiDataTests method setUp.

/* (non-Javadoc)
     * @see j2meunit.framework.TestCase#setUp()
     */
public void setUp() throws Exception {
    super.setUp();
    question = new QuestionDef();
    for (int i = 0; i < 4; i++) {
        question.addSelectChoice(new SelectChoice("", "Selection" + i, "Selection " + i, false));
    }
    one = new Selection("Selection 1");
    one.attachChoice(question);
    two = new Selection("Selection 2");
    two.attachChoice(question);
    three = new Selection("Selection 3");
    three.attachChoice(question);
    firstTwo = new ArrayList<Selection>();
    firstTwo.add(one);
    firstTwo.add(two);
    lastTwo = new ArrayList<Selection>();
    lastTwo.add(two);
    lastTwo.add(three);
    invalid = new ArrayList<Object>();
    invalid.add(three);
    invalid.add(new Integer(12));
    invalid.add(one);
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) Selection(org.javarosa.core.model.data.helper.Selection) QuestionDef(org.javarosa.core.model.QuestionDef)

Example 30 with QuestionDef

use of org.javarosa.core.model.QuestionDef in project javarosa by opendatakit.

the class FormParseInit method printStuff.

/*
     * Makes an 'extremely basic' print out of the xform model.
     */
public String printStuff() {
    String stuff = "";
    // go to the beginning of the form
    fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
    do {
        FormEntryCaption fep = femodel.getCaptionPrompt();
        boolean choiceFlag = false;
        if (fep.getFormElement() instanceof QuestionDef) {
            stuff += "\t[Type:QuestionDef, ";
            List<SelectChoice> s = ((QuestionDef) fep.getFormElement()).getChoices();
            stuff += "ContainsChoices: " + ((s != null && s.size() > 0) ? "true " : "false") + ", ";
            if (s != null && s.size() > 0)
                choiceFlag = true;
        } else if (fep.getFormElement() instanceof FormDef) {
            stuff += "\t[Type:FormDef, ";
        } else if (fep.getFormElement() instanceof GroupDef) {
            stuff += "\t[Type:GroupDef, ";
        } else {
            stuff += "\t[Type:Unknown]\n";
            continue;
        }
        stuff += "ID:" + fep.getFormElement().getID() + ", TextID:" + fep.getFormElement().getTextID() + ",InnerText:" + fep.getFormElement().getLabelInnerText();
        if (choiceFlag) {
            stuff += "] \n\t\t---Choices:" + ((QuestionDef) fep.getFormElement()).getChoices().toString() + "\n";
        } else {
            stuff += "]\n";
        }
    } while (fec.stepToNextEvent() != fec.EVENT_END_OF_FORM);
    return stuff;
}
Also used : SelectChoice(org.javarosa.core.model.SelectChoice) FormDef(org.javarosa.core.model.FormDef) FormEntryCaption(org.javarosa.form.api.FormEntryCaption) QuestionDef(org.javarosa.core.model.QuestionDef) GroupDef(org.javarosa.core.model.GroupDef)

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