| 1 | package cz.vutbr.feec.packets.rtcp; |
| 2 | |
| 3 | import org.junit.Assert; |
| 4 | import org.junit.Test; |
| 5 | |
| 6 | import cz.vutbr.feec.packets.PacketGenerateException; |
| 7 | import cz.vutbr.feec.packets.PacketParseException; |
| 8 | |
| 9 | public class AppPacketTest { |
| 10 | |
| 11 | byte[] buffer = new byte[100]; |
| 12 | |
| 13 | @Test |
| 14 | public void testAppPacket() throws PacketParseException, |
| 15 | PacketGenerateException { |
| 16 | AppPacket appliPacket = new AppPacket(); |
| 17 | appliPacket.setVersion(2); |
| 18 | appliPacket.setPadding(1); |
| 19 | appliPacket.setSubtype(8); |
| 20 | appliPacket.setPayloadtype(204); |
| 21 | appliPacket.setLength(200); |
| 22 | appliPacket.setSSRC_CSRC(11223344); |
| 23 | appliPacket.setNameASCII(55555); |
| 24 | |
| 25 | String text = "Ahoj"; |
| 26 | byte appData[] = text.getBytes(); |
| 27 | int lengthData = text.length(); |
| 28 | appliPacket.setAppData(appData, lengthData); |
| 29 | |
| 30 | int length = appliPacket.generate(buffer, 0); |
| 31 | |
| 32 | AppPacket appliPacketParse = new AppPacket(); |
| 33 | |
| 34 | int length2 = appliPacketParse.parse(buffer, 0, length); |
| 35 | |
| 36 | Assert.assertTrue("Musi byt zarovnano na 4 byty", length % 4 == 0); |
| 37 | Assert.assertTrue(length == length2); |
| 38 | Assert.assertTrue(appliPacket.getVersion() == appliPacketParse.getVersion()); |
| 39 | Assert.assertTrue(appliPacket.getPadding() == appliPacketParse.getPadding()); |
| 40 | Assert.assertTrue(appliPacket.getSubtype() == appliPacketParse.getSubtype()); |
| 41 | Assert.assertTrue(appliPacket.getPayloadtype() == appliPacketParse.getPayloadtype()); |
| 42 | Assert.assertTrue(appliPacket.getLength() == appliPacketParse.getLength()); |
| 43 | Assert.assertTrue(appliPacket.getSSRC_CSRC() == appliPacketParse.getSSRC_CSRC()); |
| 44 | Assert.assertTrue(appliPacket.getNameASCII() == appliPacketParse.getNameASCII()); |
| 45 | //Assert.assertTrue(appliPacket.getAppData() == appliPacketParse.getAppData()); |
| 46 | |
| 47 | } |
| 48 | } |