Skip to content

Use InputStreamReader for serial UTF8 decoder #10389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Added test for invalid UTF-8 sequences
  • Loading branch information
cmaglie committed Jun 19, 2020
commit 782a35bf9e4d64b612a21443c7671c53087dfafc
11 changes: 11 additions & 0 deletions app/test/processing/app/SerialTest.java
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@

package processing.app;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;

import org.junit.Test;
@@ -47,6 +48,16 @@ protected void message(char[] chars, int length) {
String output = "";
}

@Test
public void testSerialUTF8DecoderWithInvalidChars() throws Exception {
NullSerial s = new NullSerial();
byte[] testdata = new byte[] { '>', (byte) 0xC3, (byte) 0x28, '<' };
byte[] expected = new byte[] { '>', (byte) 0xEF, (byte) 0xBF, (byte) 0xBD, (byte) 0x28, '<' };
s.processSerialEvent(testdata);
byte[] res = s.output.getBytes("UTF-8");
assertArrayEquals(expected, res);
}

@Test
public void testSerialUTF8Decoder() throws Exception {
NullSerial s = new NullSerial();