package com.foxx.androidcast.network.diag;

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

import org.junit.Test;

public class CastDiagPingTest {

    @Test
    public void roundTrip_probe() throws Exception {
        CastDiagPing.Packet in = new CastDiagPing.Packet();
        in.timestampMs = 1_700_000_000_123L;
        in.seq = 42;
        in.direction = CastDiagPing.DIR_MIRROR_SMART;
        in.payload = new byte[0];
        byte[] wire = CastDiagPing.encode(in);
        CastDiagPing.Packet out = CastDiagPing.decode(wire);
        assertTrue(out.isValidMagic());
        assertEquals(in.timestampMs, out.timestampMs);
        assertEquals(in.seq, out.seq);
        assertEquals(in.direction, out.direction);
        assertEquals(0, out.payload.length);
    }

    @Test
    public void roundTrip_replyWithPong() throws Exception {
        CastDiagPing.Packet in = new CastDiagPing.Packet();
        in.flags = CastDiagPing.FLAG_PONG;
        in.direction = CastDiagPing.DIR_REPLY_WITH;
        in.timestampMs = 1_700_000_000_500L;
        in.seq = 7;
        in.replyForSeq = 6;
        in.replyForTimestampMs = 1_700_000_000_400L;
        byte[] wire = CastDiagPing.encode(in);
        CastDiagPing.Packet out = CastDiagPing.decode(wire);
        assertTrue(out.isPong());
        assertEquals(CastDiagPing.DIR_REPLY_WITH, out.direction);
        assertEquals(in.replyForSeq, out.replyForSeq);
        assertEquals(in.replyForTimestampMs, out.replyForTimestampMs);
    }
}
