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.

BorderPropsTestCase.java 3.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.traits;
  19. import java.awt.Color;
  20. import org.junit.Test;
  21. import static org.junit.Assert.assertEquals;
  22. import org.apache.xmlgraphics.java2d.color.ColorWithAlternatives;
  23. import org.apache.xmlgraphics.java2d.color.DeviceCMYKColorSpace;
  24. import org.apache.fop.fo.Constants;
  25. import org.apache.fop.util.ColorUtil;
  26. /**
  27. * Tests the BorderProps class.
  28. */
  29. public class BorderPropsTestCase {
  30. /**
  31. * Test serialization and deserialization to/from String.
  32. * @throws Exception if an error occurs
  33. */
  34. @Test
  35. public void testSerialization() throws Exception {
  36. Color col = new Color(1.0f, 1.0f, 0.5f, 1.0f);
  37. //Normalize: Avoid false alarms due to color conversion (rounding)
  38. col = ColorUtil.parseColorString(null, ColorUtil.colorToString(col));
  39. BorderProps sut = BorderProps.makeRectangular(Constants.EN_DOUBLE, 1250, col,
  40. BorderProps.Mode.COLLAPSE_OUTER);
  41. testSerialization(sut);
  42. float[] cmyk = new float[] {1.0f, 1.0f, 0.5f, 1.0f};
  43. col = DeviceCMYKColorSpace.createCMYKColor(cmyk);
  44. //Convert to sRGB with CMYK alternative as constructed by the cmyk() function
  45. float[] rgb = col.getRGBColorComponents(null);
  46. col = new ColorWithAlternatives(rgb[0], rgb[1], rgb[2], new Color[] {col});
  47. sut = BorderProps.makeRectangular(Constants.EN_INSET, 9999, col, BorderProps.Mode.SEPARATE);
  48. testSerialization(sut);
  49. }
  50. /**
  51. * Test serialization and deserialization to/from String.
  52. * @throws Exception if an error occurs
  53. */
  54. @Test
  55. public void testSerializationWithCornerRadii() throws Exception {
  56. Color col = new Color(1.0f, 1.0f, 0.5f, 1.0f);
  57. //Normalize: Avoid false alarms due to color conversion (rounding)
  58. col = ColorUtil.parseColorString(null, ColorUtil.colorToString(col));
  59. for (BorderProps.Mode mode : BorderProps.Mode.values()) {
  60. BorderProps sut = BorderProps.makeRectangular(Constants.EN_SOLID, 10, col, mode);
  61. testSerialization(sut);
  62. sut = new BorderProps(Constants.EN_SOLID, 10, 4, 3, col, mode);
  63. testSerialization(sut);
  64. }
  65. }
  66. private void testSerialization(BorderProps borderProp) {
  67. assertEquals(borderProp, BorderProps.valueOf(null, borderProp.toString()));
  68. }
  69. }