Skip to content

Commit

Permalink
Add new baseline use case provided by forum user and fix test with form
Browse files Browse the repository at this point in the history
The input "some text" was hard-coded into the form.
Also, take the chance to use the parameterized values directly in the form's contents to avoid having to answer questions and to make the calculate expression simpler, since we can assume that the values will be always there.
  • Loading branch information
ggalmazor committed Mar 11, 2020
1 parent 56c9c97 commit 05b91c3
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/test/java/org/javarosa/xpath/expr/DigestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public static Iterable<Object[]> data() {
{"SHA-1", SHA1, "some text", BASE64, "N6pjx3OY2VRHMmLhoAV8HmMu2nc="},
{"SHA-256", SHA256, "some text", BASE64, "uU9vElx546X/qoJvWEwQ1SraZp5nYgUbgmtVd20FrtI="},
{"SHA-384", SHA384, "some text", BASE64, "zJTsPphzwLmnJIZEKVj2cQZ833e5QnQW0DFEDMYgQeLuE0RJhEfsDO2fcENGG9Hz"},
{"SHA-512", SHA512, "some text", BASE64, "4nMrrtyj6sFAeChjfeHbynAsP8ns4Wz1Nt241hOc2F3+dGS4I1spgm9gjM9KxkPimxnGN4WKPYcQpZER30LdtQ=="}
{"SHA-512", SHA512, "some text", BASE64, "4nMrrtyj6sFAeChjfeHbynAsP8ns4Wz1Nt241hOc2F3+dGS4I1spgm9gjM9KxkPimxnGN4WKPYcQpZER30LdtQ=="},

{"MD5 HEX of empty string (baseline from forum feedback)", MD5, "", HEX, "d41d8cd98f00b204e9800998ecf8427e"}
});
}

Expand All @@ -89,15 +91,15 @@ public void digestFunction_acceptsDynamicParameters() throws IOException {
title("Digest form"),
model(
mainInstance(t("data id=\"digest\"",
t("my-text"),
t("my-algorithm"),
t("my-encoding"),
t("my-text", input),
t("my-algorithm", algorithm.toString()),
t("my-encoding", encoding.toString()),
t("my-digest")
)),
bind("/data/my-text").type("string"),
bind("/data/my-algorithm").type("string"),
bind("/data/my-encoding").type("string"),
bind("/data/my-digest").type("string").calculate("if(/data/my-algorithm != '' and /data/my-encoding != '', digest(/data/my-text, /data/my-algorithm, /data/my-encoding), '')")
bind("/data/my-digest").type("string").calculate("digest(/data/my-text, /data/my-algorithm, /data/my-encoding)")
)
),
body(
Expand All @@ -107,9 +109,6 @@ public void digestFunction_acceptsDynamicParameters() throws IOException {
))
);

scenario.answer("/data/my-text", "some text");
scenario.answer("/data/my-algorithm", algorithm.toString());
scenario.answer("/data/my-encoding", encoding.toString());
assertThat(scenario.answerOf("/data/my-digest"), is(stringAnswer(expectedOutput)));
}
}

0 comments on commit 05b91c3

Please sign in to comment.