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.

PDFObjectTestCase.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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.pdf;
  19. import static org.junit.Assert.assertEquals;
  20. import java.util.Calendar;
  21. import java.util.Date;
  22. import java.util.Locale;
  23. import java.util.TimeZone;
  24. import org.junit.Test;
  25. /**
  26. * Tests the PDFObject class.
  27. */
  28. public class PDFObjectTestCase {
  29. /**
  30. * Tests date/time formatting in PDFObject.
  31. * @throws Exception if an error occurs
  32. */
  33. @Test
  34. public void testDateFormatting() throws Exception {
  35. Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"), Locale.ENGLISH);
  36. cal.set(2008, Calendar.FEBRUARY, 07, 15, 11, 07);
  37. cal.set(Calendar.MILLISECOND, 0);
  38. Date dt = cal.getTime();
  39. MyPDFObject obj = new MyPDFObject();
  40. String s = obj.formatDateTime(dt, TimeZone.getTimeZone("GMT"));
  41. assertEquals("D:20080207151107Z", s);
  42. s = obj.formatDateTime(dt, TimeZone.getTimeZone("GMT+02:00"));
  43. assertEquals("D:20080207171107+02'00'", s);
  44. s = obj.formatDateTime(dt, TimeZone.getTimeZone("GMT+02:30"));
  45. assertEquals("D:20080207174107+02'30'", s);
  46. s = obj.formatDateTime(dt, TimeZone.getTimeZone("GMT-08:00"));
  47. assertEquals("D:20080207071107-08'00'", s);
  48. }
  49. private class MyPDFObject extends PDFObject {
  50. }
  51. /**
  52. * Tests PDF object references.
  53. * @throws Exception if an error occurs
  54. */
  55. @Test
  56. public void testReference() throws Exception {
  57. PDFDictionary dict = new PDFDictionary();
  58. dict.setObjectNumber(7);
  59. PDFReference ref = dict.makeReference();
  60. assertEquals(ref.getObjectNumber(), 7);
  61. assertEquals(ref.getGeneration(), 0);
  62. assertEquals(ref.toString(), "7 0 R");
  63. ref = new PDFReference("8 0 R");
  64. assertEquals(ref.getObjectNumber(), 8);
  65. assertEquals(ref.getGeneration(), 0);
  66. assertEquals(ref.toString(), "8 0 R");
  67. }
  68. }