mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-15 14:05:05 -05:00
Merge pull request #389 from jca02266/tests-on-jvm
Added tests running on JVM.
This commit is contained in:
commit
bfb5a5bb78
8
tests-on-jvm/.classpath
Normal file
8
tests-on-jvm/.classpath
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="src" path="src"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry combineaccessrules="false" kind="src" path="/k9mail"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||||
|
<classpathentry kind="output" path="bin/classes"/>
|
||||||
|
</classpath>
|
17
tests-on-jvm/.project
Normal file
17
tests-on-jvm/.project
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>tests-on-jvm</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
10
tests-on-jvm/src/android/util/Log.java
Normal file
10
tests-on-jvm/src/android/util/Log.java
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
package android.util;
|
||||||
|
|
||||||
|
public class Log {
|
||||||
|
public static int v(String tag, String message) { return 0; }
|
||||||
|
public static int d(String tag, String message) { return 0; }
|
||||||
|
public static int i(String tag, String message) { return 0; }
|
||||||
|
public static int w(String tag, String message) { return 0; }
|
||||||
|
public static int e(String tag, String message) { return 0; }
|
||||||
|
public static int e(String tag, String message, Throwable th) { return 0; }
|
||||||
|
}
|
111
tests-on-jvm/src/com/fsck/k9/mail/internet/DecoderUtilTest.java
Normal file
111
tests-on-jvm/src/com/fsck/k9/mail/internet/DecoderUtilTest.java
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
package com.fsck.k9.mail.internet;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class DecoderUtilTest extends TestCase {
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDecodeEncodedWords() {
|
||||||
|
String body, expect;
|
||||||
|
MimeMessage message;
|
||||||
|
|
||||||
|
body = "abc";
|
||||||
|
expect = "abc";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=?us-ascii?q?abc?=";
|
||||||
|
expect = "abc";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=?";
|
||||||
|
expect = "=?";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=??";
|
||||||
|
expect = "=??";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=???";
|
||||||
|
expect = "=???";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=????";
|
||||||
|
expect = "=????";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=????=";
|
||||||
|
expect = "=????=";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=??q??=";
|
||||||
|
expect = "=??q??=";;
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=??q?a?=";
|
||||||
|
expect = "a";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=??=";
|
||||||
|
expect = "=??=";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=?x?=";
|
||||||
|
expect = "=?x?=";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=?x??=";
|
||||||
|
expect = "=?x??=";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=?x?q?=";
|
||||||
|
expect = "=?x?q?=";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=?x?q??=";
|
||||||
|
expect = "=?x?q??=";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=?x?q?X?=";
|
||||||
|
expect = "X";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
// invalid base64 string
|
||||||
|
body = "=?us-ascii?b?abc?=";
|
||||||
|
expect = "";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
// broken encoded header
|
||||||
|
body = "=?us-ascii?q?abc?= =?";
|
||||||
|
expect = "abc =?";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
|
||||||
|
body = "=?x?= =?";
|
||||||
|
expect = "=?x?= =?";
|
||||||
|
message = null;
|
||||||
|
assertEquals(expect, DecoderUtil.decodeEncodedWords(body, message));
|
||||||
|
}
|
||||||
|
}
|
147
tests-on-jvm/src/com/fsck/k9/mail/internet/MimeUtilityTest.java
Normal file
147
tests-on-jvm/src/com/fsck/k9/mail/internet/MimeUtilityTest.java
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
package com.fsck.k9.mail.internet;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import com.fsck.k9.K9;
|
||||||
|
import com.fsck.k9.mail.MessagingException;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
public class MimeUtilityTest extends TestCase {
|
||||||
|
|
||||||
|
protected void setUp() throws Exception {
|
||||||
|
super.setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void tearDown() throws Exception {
|
||||||
|
super.tearDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetHeaderParameter() {
|
||||||
|
String result;
|
||||||
|
|
||||||
|
/* Test edge cases */
|
||||||
|
result = MimeUtility.getHeaderParameter(";", null);
|
||||||
|
assertEquals(null, result);
|
||||||
|
|
||||||
|
result = MimeUtility.getHeaderParameter("name", "name");
|
||||||
|
assertEquals(null, result);
|
||||||
|
|
||||||
|
result = MimeUtility.getHeaderParameter("name=", "name");
|
||||||
|
assertEquals("", result);
|
||||||
|
|
||||||
|
result = MimeUtility.getHeaderParameter("name=\"", "name");
|
||||||
|
assertEquals("\"", result);
|
||||||
|
|
||||||
|
/* Test expected cases */
|
||||||
|
result = MimeUtility.getHeaderParameter("name=value", "name");
|
||||||
|
assertEquals("value", result);
|
||||||
|
|
||||||
|
result = MimeUtility.getHeaderParameter("name = value", "name");
|
||||||
|
assertEquals("value", result);
|
||||||
|
|
||||||
|
result = MimeUtility.getHeaderParameter("name=\"value\"", "name");
|
||||||
|
assertEquals("value", result);
|
||||||
|
|
||||||
|
result = MimeUtility.getHeaderParameter("name = \"value\"" , "name");
|
||||||
|
assertEquals("value", result);
|
||||||
|
|
||||||
|
result = MimeUtility.getHeaderParameter("name=\"\"", "name");
|
||||||
|
assertEquals("", result);
|
||||||
|
|
||||||
|
result = MimeUtility.getHeaderParameter("text/html ; charset=\"windows-1251\"", null);
|
||||||
|
assertEquals("text/html", result);
|
||||||
|
|
||||||
|
result = MimeUtility.getHeaderParameter("text/HTML ; charset=\"windows-1251\"", null);
|
||||||
|
assertEquals("text/HTML", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFixupCharset() throws MessagingException {
|
||||||
|
String charsetOnMail;
|
||||||
|
String expect;
|
||||||
|
|
||||||
|
charsetOnMail = "CP932";
|
||||||
|
expect = "shift_jis";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, new MimeMessage()));
|
||||||
|
|
||||||
|
// charsetOnMail = "koi8-u";
|
||||||
|
// expect = "koi8-r";
|
||||||
|
// assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, new MimeMessage()));
|
||||||
|
|
||||||
|
MimeMessage message;
|
||||||
|
|
||||||
|
message= new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@docomo.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-docomo-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@dwmail.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-docomo-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@pdx.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-docomo-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@willcom.com");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-docomo-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@emnet.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-docomo-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@emobile.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-docomo-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@softbank.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-softbank-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@vodafone.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-softbank-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@disney.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-softbank-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@vertuclub.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-softbank-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@ezweb.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-kddi-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
message = new MimeMessage();
|
||||||
|
message.setHeader("From", "aaa@ido.ne.jp");
|
||||||
|
charsetOnMail = "shift_jis";
|
||||||
|
expect = "x-kddi-shift_jis-2007";
|
||||||
|
assertEquals(expect, MimeUtility.fixupCharset(charsetOnMail, message));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user