summaryrefslogtreecommitdiff
path: root/main/src/test/java/de/blinkt/openvpn
diff options
context:
space:
mode:
authorArne Schwabe <arne@rfc2549.org>2016-04-12 00:23:31 +0200
committerArne Schwabe <arne@rfc2549.org>2016-04-12 00:27:02 +0200
commitf4bba2b57f4d0e616010a2c25d92d5656bede036 (patch)
treef682206cac27250c97d4158e39fff764964b87b6 /main/src/test/java/de/blinkt/openvpn
parent2138a6ad52b7b48088eb8b46b46b86c2994530f7 (diff)
Rework log item caching, might work better or at least give a better understanding what goes wrong (closes #455)
Diffstat (limited to 'main/src/test/java/de/blinkt/openvpn')
-rw-r--r--main/src/test/java/de/blinkt/openvpn/core/TestLogFileHandler.java81
1 files changed, 81 insertions, 0 deletions
diff --git a/main/src/test/java/de/blinkt/openvpn/core/TestLogFileHandler.java b/main/src/test/java/de/blinkt/openvpn/core/TestLogFileHandler.java
new file mode 100644
index 00000000..f86dbcdc
--- /dev/null
+++ b/main/src/test/java/de/blinkt/openvpn/core/TestLogFileHandler.java
@@ -0,0 +1,81 @@
+package de.blinkt.openvpn.core;
+
+import android.annotation.SuppressLint;
+import android.os.Looper;
+import android.os.Message;
+import android.util.Log;
+
+import junit.framework.Assert;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.StringBufferInputStream;
+import java.util.Arrays;
+
+public class TestLogFileHandler {
+
+ byte[] testUnescaped = new byte[] {0x00, 0x55, -27, 0x00, 0x56, 0x10, -128, 0x55, 0x54};
+ byte[] expectedEscaped = new byte[] {0x55, 0x00, 0x00, 0x00, 0x09, 0x00, 0x56, 0x00, -27, 0x00, 0x56, 0x01, 0x10, -128, 0x56, 0x00, 0x54};
+ private TestingLogFileHandler lfh;
+
+
+ @Before
+ public void setup()
+ {
+ lfh = new TestingLogFileHandler();
+ }
+
+ @Test
+ public void testWriteByteArray() throws IOException {
+
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+ lfh.setLogFile(byteArrayOutputStream);
+
+ lfh.writeEscapedBytes(testUnescaped);
+
+ byte[] result = byteArrayOutputStream.toByteArray();
+ Assert.assertTrue(Arrays.equals(expectedEscaped, result));
+ }
+
+ @Test
+ public void readByteArray() throws IOException {
+
+ ByteArrayInputStream in = new ByteArrayInputStream(expectedEscaped);
+
+ lfh.readCacheContents(in);
+
+ Assert.assertTrue(Arrays.equals(testUnescaped, lfh.mRestoredByteArray));
+
+ }
+
+ @SuppressLint("HandlerLeak")
+ static class TestingLogFileHandler extends LogFileHandler {
+
+ public byte[] mRestoredByteArray;
+
+ public TestingLogFileHandler() {
+ super(null);
+ }
+
+ public void setLogFile(OutputStream out) {
+ mLogFile = out;
+ }
+
+ @Override
+ public void readCacheContents(InputStream in) throws IOException {
+ super.readCacheContents(in);
+ }
+
+ @Override
+ protected void restoreLogItem(byte[] buf, int len) {
+ mRestoredByteArray = Arrays.copyOf(buf, len);
+ }
+ }
+} \ No newline at end of file