1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package ifc.document;
25 
26 import lib.MultiPropertyTest;
27 
28 import com.sun.star.util.DateTime;
29 
30 /**
31 * Testing <code>com.sun.star.document.DocumentInfo</code>
32 * service properties : <p>
33 * <ul>
34 *   <li> <code> Author          </code> </li>
35 *   <li> <code> AutoloadEnabled </code> </li>
36 *   <li> <code> AutoloadSecs    </code> </li>
37 *   <li> <code> AutoloadURL     </code> </li>
38 *   <li> <code> BlindCopiesTo   </code> </li>
39 *   <li> <code> CopyTo          </code> </li>
40 *   <li> <code> CreationDate    </code> </li>
41 *   <li> <code> DefaultTarget   </code> </li>
42 *   <li> <code> Description     </code> </li>
43 *   <li> <code> InReplyTo       </code> </li>
44 *   <li> <code> IsEncrypted     </code> </li>
45 *   <li> <code> Keywords        </code> </li>
46 *   <li> <code> MIMEType        </code> </li>
47 *   <li> <code> ModifiedBy      </code> </li>
48 *   <li> <code> ModifyDate      </code> </li>
49 *   <li> <code> Newsgroups      </code> </li>
50 *   <li> <code> Original        </code> </li>
51 *   <li> <code> PrintDate       </code> </li>
52 *   <li> <code> PrintedBy       </code> </li>
53 *   <li> <code> Priority        </code> </li>
54 *   <li> <code> Recipient       </code> </li>
55 *   <li> <code> References      </code> </li>
56 *   <li> <code> ReplyTo         </code> </li>
57 *   <li> <code> Template        </code> </li>
58 *   <li> <code> TemplateDate    </code> </li>
59 *   <li> <code> Theme           </code> </li>
60 *   <li> <code> Title           </code> </li>
61 * </ul>
62 * Properties testing is automated by <code>lib.MultiPropertyTest</code>.
63 * @see com.sun.star.document.DocumentInfo
64 */
65 public class _DocumentInfo extends MultiPropertyTest {
66 
67     /**
68      * Overrides compare method. Can compare <code>DateTime</code>
69      * structures.
70      */
compare(Object ob1, Object ob2)71     protected boolean compare(Object ob1, Object ob2) {
72         if (ob1 instanceof DateTime && ob2 instanceof DateTime) {
73             DateTime dt1 = (DateTime)ob1;
74             DateTime dt2 = (DateTime)ob2;
75 
76             return dt1.Year == dt2.Year
77                 && dt1.Month == dt2.Month
78                 && dt1.Day == dt2.Day
79                 && dt1.Hours == dt2.Hours
80                 && dt1.Minutes == dt2.Minutes
81                 && dt1.Seconds == dt2.Seconds
82                 && dt1.HundredthSeconds == dt2.HundredthSeconds;
83         } else {
84             return super.compare(ob1, ob2);
85         }
86     }
87 
88     /**
89      * Prints DateTime.
90      */
toString(Object obj)91     protected String toString(Object obj) {
92         if (obj instanceof DateTime) {
93             DateTime dt = (DateTime)obj;
94 
95             return dt.Year + ":" + dt.Month + ":" + dt.Day
96                     + ":" + dt.Hours + ":" + dt.Minutes
97                     + ":" + dt.Seconds + ":" + dt.HundredthSeconds;
98         } else {
99             return super.toString(obj);
100         }
101     }
102 
103     /**
104      * Tester for properties with <code>DateTime</code> type which
105      * creates new structure if old property value was null.
106      */
107     class DatePropertyTester extends PropertyTester {
getNewValue(String propName, Object oldValue)108         protected Object getNewValue(String propName,
109                 Object oldValue) {
110             if (oldValue == null || util.utils.isVoid(oldValue)) {
111                 DateTime dt = new DateTime();
112 
113                 dt.Year = 2000;
114                 dt.Month = 10;
115                 dt.Day = 18;
116                 dt.Hours = 19;
117                 dt.Minutes = 41;
118 
119                 return dt;
120             } else {
121                 return super.getNewValue(propName, oldValue);
122             }
123         }
124     }
125 
126     /**
127      * Can be void.
128      */
_PrintDate()129     public void _PrintDate() {
130         testProperty("PrintDate", new DatePropertyTester());
131     }
132 
133     /**
134      * Can be void.
135      */
_TemplateDate()136     public void _TemplateDate() {
137         testProperty("TemplateDate", new DatePropertyTester());
138     }
139 
140     /**
141      * Can be void.
142      */
_ModifyDate()143     public void _ModifyDate() {
144         testProperty("ModifyDate", new DatePropertyTester());
145     }
146 }
147 
148