package com.foxx.androidcast.network;

/*********************************************************************
 * CastProtoHeaderTest.java
 * Created at: Sat 16 May 2026 18:50:36 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class CastProtoHeaderTest
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 41 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	c02de3b69fdda1b46fe3e877de117e4b0eb656c3388749e483a7b5318f3f87b7
**********************************************************************/
import org.junit.Test;

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

public class CastProtoHeaderTest {

    @Test
    public void encodeDecodeRoundTrip() throws Exception {
        CastProtoHeader original = CastProtoHeader.forCast(0x12345678, 0xABCDEF01, 0x0F, 0xF0);
        byte[] wire = original.encode();
        CastProtoHeader decoded = CastProtoHeader.decode(wire, 0, wire.length);
        assertEquals(original.sessionId, decoded.sessionId);
        assertEquals(original.placeholderId, decoded.placeholderId);
        assertEquals(original.videoCodecs, decoded.videoCodecs);
        assertEquals(original.audioCodecs, decoded.audioCodecs);
        assertTrue(decoded.verifyChecksum());
    }

    @Test
    public void frameUnframePreservesPayload() throws Exception {
        CastProtoHeader hdr = CastProtoHeader.forCast(99, 1, 2, 3);
        byte[] payload = new byte[] {1, 2, 3, 4};
        byte[] wire = CastPacketFramer.frame(hdr, (byte) 7, payload);
        CastProtoHeader fromWire = CastPacketFramer.readHeader(wire);
        assertEquals(99, fromWire.sessionId);
        CastProtocol.Message msg = CastPacketFramer.unframe(wire);
        assertEquals(7, msg.type);
        assertArrayEquals(payload, msg.payload);
    }
}
