package ru.r2cloud.jradio.blocks;

import static org.junit.Assert.assertEquals;

import org.junit.After;
import org.junit.Test;

import ru.r2cloud.jradio.ArrayByteInput;

public class HdlcTransmitterTest {

	private HdlcReceiver receiver;
	private HdlcTransmitter transmitter;

	@Test
	public void testSendReceive() throws Exception {
		byte[] data = new byte[] { (byte) 0xF1, (byte) 0xA7, (byte) 0x7C, 0x56 };
		transmitter = new HdlcTransmitter();
		byte[] encoded = transmitter.encode(data);
		receiver = new HdlcReceiver(new ArrayByteInput(encoded), 10);
		byte[] actual = receiver.readBytes();
		assertEquals(data.length, actual.length);
		for (int i = 0; i < data.length; i++) {
			assertEquals(data[i], actual[i]);
		}
	}

	@After
	public void stop() throws Exception {
		if (receiver != null) {
			receiver.close();
		}
	}

}

@@ -162,16 +162,52 @@
 teInput;
+%0Aimport ru.r2cloud.jradio.ByteInput;
 %0A%0Apublic
@@ -757,16 +757,606 @@
 ;%0A%09%09%7D%0A%09%7D
+%0A%09%0A%09@Test%0A%09public void testSendReceiveScrambled() throws Exception %7B%0A%09%09byte%5B%5D data = new byte%5B%5D %7B (byte) 0xF1, (byte) 0xA7, (byte) 0x7C, 0x56 %7D;%0A%09%09transmitter = new HdlcTransmitter();%0A%09%09byte%5B%5D encoded = transmitter.encode(data);%0A%09%09ByteInput scrambled = new NrziEncode(new Scrambler(new ArrayByteInput(encoded), 0x21, 0x00, 16));%0A%09%09receiver = new HdlcReceiver(new Descrambler(new NrziDecode(scrambled), 0x21, 0, 16), 10);%0A%09%09byte%5B%5D actual = receiver.readBytes();%0A%09%09assertEquals(data.length, actual.length);%0A%09%09for (int i = 0; i %3C data.length; i++) %7B%0A%09%09%09assertEquals(data%5Bi%5D, actual%5Bi%5D);%0A%09%09%7D%0A%09%7D
 %0A%0A%09@Afte

add test for scrambled data