package com.foxx.androidcast;

/*********************************************************************
 * CastResolutionTest.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 CastResolutionTest
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (3 commits, 26 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	6839d31665eec94c6c24a1a54c86dfaaef483d19196fe6b6a754eb7156c09b26
**********************************************************************/
import android.util.DisplayMetrics;

import com.foxx.androidcast.sender.calibration.CalibrationSourceDimensions;

import org.junit.Test;

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

public class CastResolutionTest {

    @Test
    public void calibrationSourceMatchesReferenceAssetSize() {
        CastResolution.Size size = CalibrationSourceDimensions.fromIntrinsic(500, 400, 0);
        assertEquals(500, size.width);
        assertEquals(400, size.height);
        assertTrue(size.width > size.height);
    }

    @Test
    public void forPresetUiMapsLegacyResolutions() {
        assertEquals(CastSettings.Resolution.HD_720P,
                CastSettings.forPresetUi(CastSettings.Resolution.FIXED_720P));
        assertEquals(CastSettings.Resolution.FULL,
                CastSettings.forPresetUi(CastSettings.Resolution.FIXED_1080P));
        assertEquals(CastSettings.Resolution.ADAPTIVE,
                CastSettings.forPresetUi(CastSettings.Resolution.HALF));
        assertEquals(CastSettings.Resolution.SD_480P,
                CastSettings.forPresetUi(CastSettings.Resolution.SD_480P));
    }

    @Test
    public void sd480pCapsLongEdge() {
        CastSettings settings = new CastSettings();
        settings.setResolution(CastSettings.Resolution.SD_480P);
        DisplayMetrics metrics = new DisplayMetrics();
        metrics.widthPixels = 2000;
        metrics.heightPixels = 1200;
        metrics.densityDpi = 320;
        CastTuningEngine.CaptureLimits limits = CastTuningEngine.resolveCaptureLimits(settings, null);
        assertEquals(480, limits.maxHeight);
        CastResolution.Size size = CastResolution.compute(metrics, settings, null);
        assertEquals(480, Math.max(size.width, size.height));
    }
}
