package cz.vutbr.feec.packets.ttp;

import oldPackets.LMSLandMarkGroup;
import oldPackets.LMSPacket;

import org.junit.Assert;
import org.junit.Test;

import cz.vutbr.feec.packets.PacketGenerateException;
import cz.vutbr.feec.packets.PacketParseException;

import cz.vutbr.feec.packets.ttp.GeneralTTPHeader;

public class LMStest {
	private byte buffer[] = new byte[500];
	@Test
	public void LMSPacket() throws PacketParseException,
			PacketGenerateException {
	LMSPacket packetLMS = new LMSPacket();
	
	
	packetLMS.setVersion(1);
// packetLMS.setPadding(1);
	packetLMS.setPacketType(1);
	packetLMS.setFeedbackTreeId(1);
	packetLMS.setLength(1);

/*
 * packetLMS.setLMSseqNumber(1);
 * 
 * packetLMS.setSessionSize(1); packetLMS.setIncreaseFactor(1);
 * packetLMS.setSessionSize(1); packetLMS.setReservedEnd(1);
 */
	LMSLandMarkGroup item1 = new LMSLandMarkGroup();
	LMSLandMarkGroup item2 = new LMSLandMarkGroup();
	LMSLandMarkGroup item3 = new LMSLandMarkGroup();
	LMSLandMarkGroup item4 = new LMSLandMarkGroup();
	item1.setLandmarkIPaddr(55555555L);
	item2.setLandmarkIPaddr(44444444L);
	item3.setLandmarkIPaddr(33333333L);
	item4.setLandmarkIPaddr(22222222L);
	packetLMS.addGroupBlock(item1);
	packetLMS.addGroupBlock(item2);
	packetLMS.addGroupBlock(item3);
	packetLMS.addGroupBlock(item4);
	
	int length = packetLMS.generate(buffer, 0);

	LMSPacket packetLMS2 = new LMSPacket();
	int length2 = packetLMS2.parse(buffer, 0, length);
	
	Assert.assertTrue("Musi byt zarovnano na 4 byty", length % 4 == 0);
	Assert.assertTrue(length == length2);
	Assert.assertTrue(packetLMS.equals(packetLMS2));
	}
}
