diff options
author | Mikayla Ray <mikayla@livioconnect.com> | 2015-05-05 15:29:30 -0400 |
---|---|---|
committer | Mikayla Ray <mikayla@livioconnect.com> | 2015-05-05 15:29:30 -0400 |
commit | 872219326ad6d845e2198621806ac27e870faece (patch) | |
tree | 9a53d2fc620f8e40e58cf479a70a8fef3d8cf612 | |
parent | 572645264f24a8adce2816611f63f521856c5481 (diff) | |
download | sdl_android-872219326ad6d845e2198621806ac27e870faece.tar.gz |
Added unit tests to AbstractPacketizer class.
-rw-r--r-- | sdl_android_tests/src/com/smartdevicelink/test/proxy/InternalProxyMessageTests.java | 2 | ||||
-rw-r--r-- | sdl_android_tests/src/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java | 112 |
2 files changed, 113 insertions, 1 deletions
diff --git a/sdl_android_tests/src/com/smartdevicelink/test/proxy/InternalProxyMessageTests.java b/sdl_android_tests/src/com/smartdevicelink/test/proxy/InternalProxyMessageTests.java index 123b0eb61..1e14245a1 100644 --- a/sdl_android_tests/src/com/smartdevicelink/test/proxy/InternalProxyMessageTests.java +++ b/sdl_android_tests/src/com/smartdevicelink/test/proxy/InternalProxyMessageTests.java @@ -25,6 +25,6 @@ public class InternalProxyMessageTests extends TestCase { test = "OnProxyClosed"; assertEquals("OnProxyClosed did not match expected value.", test, - InternalProxyMessage.OnProxyError); + InternalProxyMessage.OnProxyClosed); } }
\ No newline at end of file diff --git a/sdl_android_tests/src/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java b/sdl_android_tests/src/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java new file mode 100644 index 000000000..cc5e885c9 --- /dev/null +++ b/sdl_android_tests/src/com/smartdevicelink/test/streaming/AbstractPacketizerTests.java @@ -0,0 +1,112 @@ +package com.smartdevicelink.test.streaming; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.net.URLConnection; + +import junit.framework.TestCase; + +import com.smartdevicelink.protocol.ProtocolMessage; +import com.smartdevicelink.protocol.enums.SessionType; +import com.smartdevicelink.proxy.RPCRequest; +import com.smartdevicelink.streaming.AbstractPacketizer; +import com.smartdevicelink.streaming.IStreamListener; + +public class AbstractPacketizerTests extends TestCase { + + private final String MSG = "Value did not match expected value."; + + public void testConstructors () { + + byte testSessionId = (byte) 0x0A; + byte testWV = (byte) 0x0B; + SessionType testSessionType = SessionType.RPC; + RPCRequest testRequest = new RPCRequest(MSG); + InputStream testInputStream = null; + IStreamListener testListener = new MockStreamListener(); + MockPacketizer testAP = null; + + // Test -- AbstractPacketizer (IStreamListener streamListener, InputStream is, SessionType sType, byte rpcSessionID) throws IOException + try { + + URL url = new URL("ftp://mirror.csclub.uwaterloo.ca/index.html"); + URLConnection urlConnection = url.openConnection(); + testInputStream = new BufferedInputStream(urlConnection.getInputStream()); + + testAP = new MockPacketizer(testListener, testInputStream, testSessionType, testSessionId); + assertNotNull(MSG, testAP); + assertEquals(MSG, testListener, testAP.getListener()); + assertEquals(MSG, testInputStream, testAP.getInputStream()); + assertEquals(MSG, testSessionType, testAP.getSessionType()); + assertEquals(MSG, testSessionId, testAP.getSessionId()); + + testAP = new MockPacketizer(null, null, null, testSessionId); + assertNotNull(MSG, testAP); + assertNull(MSG, testAP.getListener()); + assertNull(MSG, testAP.getInputStream()); + assertNull(MSG, testAP.getSessionType()); + + } catch (IOException e) { + fail("IOException was thrown."); + } catch (Exception e) { + fail("Exception was thrown."); + } + + // Test -- AbstractPacketizer (IStreamListener streamListener, InputStream is, RPCRequest request, SessionType sType, byte rpcSessionID, byte wiproVersion) throws IOException + try { + + URL url = new URL("ftp://mirror.csclub.uwaterloo.ca/index.html"); + URLConnection urlConnection = url.openConnection(); + testInputStream = new BufferedInputStream(urlConnection.getInputStream()); + + testAP = new MockPacketizer(testListener, testInputStream, testRequest, testSessionType, testSessionId, testWV); + assertNotNull(MSG, testAP); + assertEquals(MSG, testListener, testAP.getListener()); + assertEquals(MSG, testInputStream, testAP.getInputStream()); + assertEquals(MSG, testSessionType, testAP.getSessionType()); + assertEquals(MSG, testSessionId, testAP.getSessionId()); + assertEquals(MSG, testWV, testAP.getWiproVersion()); + assertEquals(MSG, testRequest.getFunctionName(), testAP.getRPCRequest().getFunctionName()); + + testAP = new MockPacketizer(null, null, null, null, testSessionId, testWV); + assertNotNull(MSG, testAP); + assertNull(MSG, testAP.getListener()); + assertNull(MSG, testAP.getInputStream()); + assertNull(MSG, testAP.getSessionType()); + assertNull(MSG, testAP.getRPCRequest()); + + } catch (IOException e) { + fail("IOException was thrown."); + } catch (Exception e) { + fail("Exception was thrown."); + } + } + +} + +class MockStreamListener implements IStreamListener { + public MockStreamListener () { } + @Override public void sendStreamPacket(ProtocolMessage pm) { } +} + +class MockPacketizer extends AbstractPacketizer { + public MockPacketizer (IStreamListener l, InputStream i, SessionType s, byte sid) throws IOException { + super (l, i, s, sid); + } + + public MockPacketizer (IStreamListener l, InputStream i, RPCRequest r, SessionType s, byte sid, byte w) throws IOException { + super (l, i, r, s, sid, w); + } + + @Override public void start() throws IOException { } + @Override public void stop() { } + + public IStreamListener getListener () { return _streamListener; } + public InputStream getInputStream () { return is; } + public SessionType getSessionType () { return _session; } + public byte getSessionId () { return _rpcSessionID; } + public RPCRequest getRPCRequest () { return _request; } + public byte getWiproVersion () { return _wiproVersion; } +}
\ No newline at end of file |