
package com.google.blockly.model;

import android.test.AndroidTestCase;

/**
 * Tests for {@link FieldColor}.
 */
public class FieldColorTest extends AndroidTestCase {
    public void testFieldColour() {
        FieldColor field = new FieldColor("fname", 0xaa00aa);
        assertEquals(Field.TYPE_COLOR, field.getType());
        assertEquals("fname", field.getName());
        assertEquals(0xaa00aa, field.getColor());

        field = new FieldColor("fname");
        assertEquals("fname", field.getName());
        assertEquals(FieldColor.DEFAULT_COLOR, field.getColor());

        field.setColor(0xb0bb1e);
        assertEquals(0xb0bb1e, field.getColor());

        // xml parsing
        assertTrue(field.setFromString("#ffcc66"));
        assertEquals(0xffcc66, field.getColor());
        assertTrue(field.setFromString("#00cc66"));
        assertEquals(0x00cc66, field.getColor());
        assertTrue(field.setFromString("#1000cc66"));
        assertEquals(0x00cc66, field.getColor());
        assertFalse(field.setFromString("This is not a color"));
        // Color does not change
        assertEquals(0x00cc66, field.getColor());
        assertFalse(field.setFromString("#fc6"));
        // Color does not change
        assertEquals(0x00cc66, field.getColor());

        assertNotSame(field, field.clone());
    }
}
