/*
 * Copyright 2014 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.pdfbox.pdmodel.graphics.color;

import java.io.IOException;
import junit.framework.TestCase;
import org.apache.pdfbox.cos.COSArray;
import org.apache.pdfbox.cos.COSDictionary;
import org.apache.pdfbox.pdmodel.common.PDRange;

/**
 *
 * @author Tilman Hausherr
 */
public class PDLabTest extends TestCase
{

    /**
     * This test checks that getting default values do not alter the object.
     */
    public void testLAB() throws IOException
    {
        PDLab pdLab = new PDLab();
        COSArray cosArray = (COSArray) pdLab.getCOSObject();
        COSDictionary dict = (COSDictionary) cosArray.getObject(1);
        
        // test with default values
        assertEquals("Lab", pdLab.getName());
        assertEquals(3, pdLab.getNumberOfComponents());
        assertEquals(0f, pdLab.getBlackPoint().getX());
        assertEquals(0f, pdLab.getBlackPoint().getY());
        assertEquals(0f, pdLab.getBlackPoint().getZ());
        assertEquals(1f, pdLab.getWhitePoint().getX());
        assertEquals(1f, pdLab.getWhitePoint().getY());
        assertEquals(1f, pdLab.getWhitePoint().getZ());
        assertEquals(-100f, pdLab.getARange().getMin());
        assertEquals(100f, pdLab.getARange().getMax());
        assertEquals(-100f, pdLab.getBRange().getMin());
        assertEquals(100f, pdLab.getBRange().getMax());
        assertEquals("read operations should not change the size of /Lab objects", 0, dict.size());
        dict.toString(); // rev 1571125 did a stack overflow here

        // test setting specific values
        PDRange pdRange = new PDRange();
        pdRange.setMin(-1);
        pdRange.setMax(2);
        pdLab.setARange(pdRange);
        pdRange = new PDRange();
        pdRange.setMin(3);
        pdRange.setMax(4);
        pdLab.setBRange(pdRange);
        assertEquals(-1f, pdLab.getARange().getMin());
        assertEquals(2f, pdLab.getARange().getMax());
        assertEquals(3f, pdLab.getBRange().getMin());
        assertEquals(4f, pdLab.getBRange().getMax());
        PDTristimulus pdTristimulus = new PDTristimulus();
        pdTristimulus.setX(5);
        pdTristimulus.setY(6);
        pdTristimulus.setZ(7);
        pdLab.setWhitePoint(pdTristimulus);
        pdTristimulus = new PDTristimulus();
        pdTristimulus.setX(8);
        pdTristimulus.setY(9);
        pdTristimulus.setZ(10);
        pdLab.setBlackPoint(pdTristimulus);
        assertEquals(5f, pdLab.getWhitePoint().getX());
        assertEquals(6f, pdLab.getWhitePoint().getY());
        assertEquals(7f, pdLab.getWhitePoint().getZ());
        assertEquals(8f, pdLab.getBlackPoint().getX());
        assertEquals(9f, pdLab.getBlackPoint().getY());
        assertEquals(10f, pdLab.getBlackPoint().getZ());
    }

}
