Browse Source

Merge branch 'JNI-147 - "Utils: add a method to check two URIs for equality"' into Release_2.1

JNI-132
heck 4 years ago
parent
commit
b4d7c663eb
  1. 12
      src/java/foundation/pEp/jniadapter/Utils.java
  2. 34
      test/java/foundation/pEp/jniadapter/test/jni147/Makefile
  3. 53
      test/java/foundation/pEp/jniadapter/test/jni147/TestAlice.java

12
src/java/foundation/pEp/jniadapter/Utils.java

@ -4,6 +4,8 @@ import java.io.UnsupportedEncodingException;
import java.text.Normalizer; import java.text.Normalizer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Vector; import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Utils { public class Utils {
private Utils() { } private Utils() { }
@ -112,4 +114,14 @@ public class Utils {
return result; return result;
} }
public static boolean URIEqual(String left, String right) {
Pattern pattern = Pattern.compile("^.*?://");
Matcher leftMatcher = pattern.matcher(left.trim());
String leftRelevant = leftMatcher.replaceAll("");
Matcher rightMatcher = pattern.matcher(right.trim());
String rightRelevant = rightMatcher.replaceAll("");
return rightRelevant.equals(leftRelevant);
}
} }

34
test/java/foundation/pEp/jniadapter/test/jni147/Makefile

@ -0,0 +1,34 @@
include ../../../../../../../Makefile.conf
include ../Makefile.conf
TEST_UNIT_NAME=jni147
JAVA_CLASSES+= \
TestAlice.class
.PHONY: pitytest compile alice test clean
all: alice compile
pitytest:
$(MAKE) -C $(PITYTEST_DIR)
alice: compile clean-pep-home-alice
cd $(JAVA_CWD);pwd;HOME=$(JAVA_PEP_HOME_DIR_ALICE) $(JAVA) $(JAVA_PKG_BASENAME).$(TEST_UNIT_NAME).TestAlice
compile: $(JAVA_CLASSES) pitytest
%.class: %.java
cd $(JAVA_CWD);javac -cp $(CLASSPATH) $(JAVA_PKG_BASEPATH)/$(TEST_UNIT_NAME)/$<
clean:
rm -f $(JAVA_CLASSES)
rm -f *.class
rm -f *.log
rm -Rf .gnupg
rm -Rf .lldb
clean-pep-home: clean-pep-home-alice
clean-pep-home-alice:
rm -rf $(PEP_HOME_DIR_ALICE)/.pEp

53
test/java/foundation/pEp/jniadapter/test/jni147/TestAlice.java

@ -0,0 +1,53 @@
package foundation.pEp.jniadapter.test.jni147;
import foundation.pEp.jniadapter.test.utils.CTXBase;
import foundation.pEp.pitytest.TestSuite;
import foundation.pEp.pitytest.TestUnit;
import foundation.pEp.pitytest.utils.TestUtils;
import static foundation.pEp.jniadapter.Utils.*;
/*
JNI-147 - Utils: add a method to check two URIs for equlity
Definition:
On both URI's:
* remove leading and trailing withespace
* remove substring before and with "://"
compare the resulting strings byte by byte for case sensitive equality.
e.g.
"file://testname" == "testname"
*/
class TestAlice {
public static void main(String[] args) throws Exception {
TestSuite.getDefault().setVerbose(true);
TestSuite.getDefault().setTestColor(TestUtils.TermColor.GREEN);
CTXBase jni147Ctx = new CTXBase();
new TestUnit<CTXBase>("URIEquals tests", new CTXBase(), ctx -> {
// SAME
assert URIEqual("", "") == true : "1";
assert URIEqual("file://", "") == true : "2";
assert URIEqual("", "file://") == true : "3";
assert URIEqual("alice@peptest.com", "alice@peptest.com") == true : "4";
assert URIEqual("mailto://alice@peptest.com", "alice@peptest.com") == true : "5";
assert URIEqual("alice@peptest.com", "mailto://alice@peptest.com") == true : "6";
assert URIEqual("mailto://alice@peptest.com", "mailto://alice@peptest.com") == true : "7";
assert URIEqual("", " ") == true : "8";
assert URIEqual("file://", " ") == true : "9";
assert URIEqual(" ", "file://") == true : "10";
// NOT SAME
assert URIEqual("alice@peptest.com", "bob@peptest.com") == false : "11";
assert URIEqual("mailto://alice@peptest.com", "bob@peptest.com") == false : "12";
assert URIEqual("alice@peptest.com", "mailto://bob@peptest.com") == false : "13";
});
TestSuite.getDefault().run();
}
}
Loading…
Cancel
Save