Search in sources :

Example 6 with FormEntryController

use of org.javarosa.form.api.FormEntryController in project javarosa by opendatakit.

the class FormDef method validate.

public ValidateOutcome validate(boolean markCompleted) {
    FormEntryModel formEntryModelToBeValidated = new FormEntryModel(this);
    FormEntryController formEntryControllerToBeValidated = new FormEntryController(formEntryModelToBeValidated);
    return dagImpl.validate(formEntryControllerToBeValidated, markCompleted);
}
Also used : FormEntryController(org.javarosa.form.api.FormEntryController) FormEntryModel(org.javarosa.form.api.FormEntryModel)

Example 7 with FormEntryController

use of org.javarosa.form.api.FormEntryController in project javarosa by opendatakit.

the class FormDefTest method testAnswerConstraint.

public void testAnswerConstraint() {
    IntegerData ans = new IntegerData(13);
    FormEntryController fec = fpi.getFormEntryController();
    fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
    do {
        QuestionDef q = fpi.getCurrentQuestion();
        if (q == null || q.getTextID() == null || q.getTextID().length() == 0)
            continue;
        if (q.getTextID().equals("constraint-test")) {
            int response = fec.answerQuestion(ans, true);
            if (response == FormEntryController.ANSWER_CONSTRAINT_VIOLATED) {
                fail("Answer Constraint test failed.");
            } else if (response == FormEntryController.ANSWER_OK) {
                break;
            } else {
                fail("Bad response from fec.answerQuestion()");
            }
        }
    } while (fec.stepToNextEvent() != FormEntryController.EVENT_END_OF_FORM);
}
Also used : FormEntryController(org.javarosa.form.api.FormEntryController) IntegerData(org.javarosa.core.model.data.IntegerData) QuestionDef(org.javarosa.core.model.QuestionDef)

Example 8 with FormEntryController

use of org.javarosa.form.api.FormEntryController in project javarosa by opendatakit.

the class TextFormTests method testTextForms.

/**
 * Test that the long and short text forms work as expected
 * (fallback to default for example).
 * Test being able to retrieve other exotic forms
 */
public void testTextForms() {
    FormEntryController fec = fpi.getFormEntryController();
    fec.jumpToIndex(FormIndex.createBeginningOfFormIndex());
    boolean foundFlag = false;
    Localizer l = fpi.getFormDef().getLocalizer();
    l.setDefaultLocale(l.getAvailableLocales()[0]);
    l.setLocale(l.getAvailableLocales()[0]);
    int state = -99;
    while (state != FormEntryController.EVENT_QUESTION) {
        state = fec.stepToNextEvent();
    }
    fep = fec.getModel().getQuestionPrompt();
    if (!fep.getLongText().equals("Patient ID"))
        fail("getLongText() not returning correct value");
    if (!fep.getShortText().equals("ID"))
        fail("getShortText() not returning correct value");
    if (!fep.getAudioText().equals("jr://audio/hah.mp3"))
        fail("getAudioText() not returning correct value");
    state = -99;
    while (state != FormEntryController.EVENT_QUESTION) {
        state = fec.stepToNextEvent();
    }
    fep = fec.getModel().getQuestionPrompt();
    if (!fep.getShortText().equals("Name"))
        fail("getShortText() not returning correct value");
    if (!fep.getLongText().equals("Full Name"))
        fail("getLongText() not falling back to default text form correctly");
    String v = fep.getSpecialFormQuestionText("long");
    if (fep.getSpecialFormQuestionText("long") != null)
        fail("getSpecialFormQuestionText() returning incorrect value");
}
Also used : FormEntryController(org.javarosa.form.api.FormEntryController) Localizer(org.javarosa.core.services.locale.Localizer)

Example 9 with FormEntryController

use of org.javarosa.form.api.FormEntryController in project javarosa by opendatakit.

the class FormIndexSerializationTest method testOnFormController.

@Test
public void testOnFormController() throws IOException, ClassNotFoundException {
    FormParseInit formParseInit = new FormParseInit();
    formParseInit.setFormToParse(Paths.get(PathConst.getTestResourcePath().getAbsolutePath(), "formindex-serialization.xml").toString());
    FormEntryController formEntryController = formParseInit.getFormEntryController();
    FormIndex formIndex = formEntryController.getModel().getFormIndex();
    assertFormIndex(formIndex, deserializeFormIndex(serializeObject(formIndex)));
    do {
        formIndex = formEntryController.getModel().incrementIndex(formIndex);
        assertFormIndex(formIndex, deserializeFormIndex(serializeObject(formIndex)));
    } while (!formIndex.isEndOfFormIndex());
}
Also used : FormEntryController(org.javarosa.form.api.FormEntryController) FormIndex(org.javarosa.core.model.FormIndex) FormParseInit(org.javarosa.core.test.FormParseInit) Test(org.junit.Test)

Aggregations

FormEntryController (org.javarosa.form.api.FormEntryController)9 FormEntryModel (org.javarosa.form.api.FormEntryModel)4 FormDef (org.javarosa.core.model.FormDef)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 FormIndex (org.javarosa.core.model.FormIndex)2 QuestionDef (org.javarosa.core.model.QuestionDef)2 Localizer (org.javarosa.core.services.locale.Localizer)2 FormParseInit (org.javarosa.core.test.FormParseInit)2 Test (org.junit.Test)2 IntegerData (org.javarosa.core.model.data.IntegerData)1 TreeElement (org.javarosa.core.model.instance.TreeElement)1 RootTranslator (org.javarosa.core.reference.RootTranslator)1 XPathTypeMismatchException (org.javarosa.xpath.XPathTypeMismatchException)1 ExternalDataHandler (org.odk.collect.android.external.ExternalDataHandler)1 ExternalDataManagerImpl (org.odk.collect.android.external.ExternalDataManagerImpl)1 ExternalDataHandlerPull (org.odk.collect.android.external.handler.ExternalDataHandlerPull)1 FileReferenceFactory (org.odk.collect.android.logic.FileReferenceFactory)1