You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TraitColorTestCase.java 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2006 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. /* $Id$ */
  17. package org.apache.fop.traits;
  18. import org.apache.fop.area.Trait;
  19. import junit.framework.TestCase;
  20. /**
  21. * Tests the Trait.Color class.
  22. */
  23. public class TraitColorTestCase extends TestCase {
  24. /**
  25. * Test serialization to String.
  26. * @throws Exception if an error occurs
  27. */
  28. public void testSerialization() throws Exception {
  29. Trait.Color col = new Trait.Color(1.0f, 1.0f, 0.5f, 1.0f);
  30. String s = col.toString();
  31. assertEquals("#ffff7f", s);
  32. col = new Trait.Color(1.0f, 0.0f, 0.0f, 0.8f);
  33. s = col.toString();
  34. assertEquals("#ff0000cc", s);
  35. }
  36. /**
  37. * Test deserialization from String.
  38. * @throws Exception if an error occurs
  39. */
  40. public void testDeserialization() throws Exception {
  41. float tolerance = 0.5f / 255; //due to color value conversion
  42. Trait.Color col = Trait.Color.valueOf("#ffff7f");
  43. assertEquals(1.0f, col.getRed(), 0.0f);
  44. assertEquals(1.0f, col.getGreen(), 0.0f);
  45. assertEquals(0.5f, col.getBlue(), tolerance);
  46. assertEquals(1.0f, col.getAlpha(), 0.0f);
  47. col = Trait.Color.valueOf("#ff0000cc");
  48. assertEquals(1.0f, col.getRed(), 0.0f);
  49. assertEquals(0.0f, col.getGreen(), 0.0f);
  50. assertEquals(0.0f, col.getBlue(), 0.0f);
  51. assertEquals(0.8f, col.getAlpha(), tolerance);
  52. }
  53. /**
  54. * Test equals().
  55. * @throws Exception if an error occurs
  56. */
  57. public void testEquals() throws Exception {
  58. Trait.Color col1 = Trait.Color.valueOf("#ff0000cc");
  59. Trait.Color col2 = Trait.Color.valueOf("#ff0000cc");
  60. assertTrue(col1 != col2);
  61. assertEquals(col1, col2);
  62. }
  63. }