1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.document;
29 
30 import lib.MultiPropertyTest;
31 
32 import com.sun.star.util.DateTime;
33 
34 /**
35 * Testing <code>com.sun.star.document.DocumentInfo</code>
36 * service properties : <p>
37 * <ul>
38 *   <li> <code> Author          </code> </li>
39 *   <li> <code> AutoloadEnabled </code> </li>
40 *   <li> <code> AutoloadSecs    </code> </li>
41 *   <li> <code> AutoloadURL     </code> </li>
42 *   <li> <code> BlindCopiesTo   </code> </li>
43 *   <li> <code> CopyTo          </code> </li>
44 *   <li> <code> CreationDate    </code> </li>
45 *   <li> <code> DefaultTarget   </code> </li>
46 *   <li> <code> Description     </code> </li>
47 *   <li> <code> InReplyTo       </code> </li>
48 *   <li> <code> IsEncrypted     </code> </li>
49 *   <li> <code> Keywords        </code> </li>
50 *   <li> <code> MIMEType        </code> </li>
51 *   <li> <code> ModifiedBy      </code> </li>
52 *   <li> <code> ModifyDate      </code> </li>
53 *   <li> <code> Newsgroups      </code> </li>
54 *   <li> <code> Original        </code> </li>
55 *   <li> <code> PrintDate       </code> </li>
56 *   <li> <code> PrintedBy       </code> </li>
57 *   <li> <code> Priority        </code> </li>
58 *   <li> <code> Recipient       </code> </li>
59 *   <li> <code> References      </code> </li>
60 *   <li> <code> ReplyTo         </code> </li>
61 *   <li> <code> Template        </code> </li>
62 *   <li> <code> TemplateDate    </code> </li>
63 *   <li> <code> Theme           </code> </li>
64 *   <li> <code> Title           </code> </li>
65 * </ul>
66 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
67 * @see com.sun.star.document.DocumentInfo
68 */
69 public class _DocumentInfo extends MultiPropertyTest {
70 
71     /**
72      * Overrides compare method. Can compare <code>DateTime</code>
73      * structures.
74      */
75     protected boolean compare(Object ob1, Object ob2) {
76         if (ob1 instanceof DateTime && ob2 instanceof DateTime) {
77             DateTime dt1 = (DateTime)ob1;
78             DateTime dt2 = (DateTime)ob2;
79 
80             return dt1.Year == dt2.Year
81                 && dt1.Month == dt2.Month
82                 && dt1.Day == dt2.Day
83                 && dt1.Hours == dt2.Hours
84                 && dt1.Minutes == dt2.Minutes
85                 && dt1.Seconds == dt2.Seconds
86                 && dt1.HundredthSeconds == dt2.HundredthSeconds;
87         } else {
88             return super.compare(ob1, ob2);
89         }
90     }
91 
92     /**
93      * Prints DateTime.
94      */
95     protected String toString(Object obj) {
96         if (obj instanceof DateTime) {
97             DateTime dt = (DateTime)obj;
98 
99             return dt.Year + ":" + dt.Month + ":" + dt.Day
100                     + ":" + dt.Hours + ":" + dt.Minutes
101                     + ":" + dt.Seconds + ":" + dt.HundredthSeconds;
102         } else {
103             return super.toString(obj);
104         }
105     }
106 
107     /**
108      * Tester for properties with <code>DateTime</code> type which
109      * creates new structure if old property value was null.
110      */
111     class DatePropertyTester extends PropertyTester {
112         protected Object getNewValue(String propName,
113                 Object oldValue) {
114             if (oldValue == null || util.utils.isVoid(oldValue)) {
115                 DateTime dt = new DateTime();
116 
117                 dt.Year = 2000;
118                 dt.Month = 10;
119                 dt.Day = 18;
120                 dt.Hours = 19;
121                 dt.Minutes = 41;
122 
123                 return dt;
124             } else {
125                 return super.getNewValue(propName, oldValue);
126             }
127         }
128     }
129 
130     /**
131      * Can be void.
132      */
133     public void _PrintDate() {
134         testProperty("PrintDate", new DatePropertyTester());
135     }
136 
137     /**
138      * Can be void.
139      */
140     public void _TemplateDate() {
141         testProperty("TemplateDate", new DatePropertyTester());
142     }
143 
144     /**
145      * Can be void.
146      */
147     public void _ModifyDate() {
148         testProperty("ModifyDate", new DatePropertyTester());
149     }
150 }
151 
152