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.MultiMethodTest; 27 import util.utils; 28 29 import com.sun.star.beans.PropertyValue; 30 import com.sun.star.document.XTypeDetection; 31 32 /** 33 * Testing <code>com.sun.star.document.XTypeDetection</code> 34 * interface methods : 35 * <ul> 36 * <li><code> queryTypeByURL()</code></li> 37 * <li><code> queryTypeByDescriptor()</code></li> 38 * </ul> <p> 39 * 40 * The following predefined files needed to complete the test: 41 * <ul> 42 * <li> <code>XTypeDetection.sxw</code> : <b>Calc</b> 43 * document which extension is <b>sxw</b>. </li> 44 * <ul> <p> 45 * 46 * @see com.sun.star.document.XTypeDetection 47 */ 48 public class _XTypeDetection extends MultiMethodTest { 49 public XTypeDetection oObj = null; 50 51 private String docURL = null; 52 private String bookmarkURL = null; 53 54 /** 55 * Get the document URL. 56 */ before()57 public void before() { 58 docURL = utils.getFullTestURL("XTypeDetection.sxw"); 59 bookmarkURL = (String) tEnv.getObjRelation("XTypeDetection.bookmarkDoc"); 60 } 61 62 /** 63 * Tries to detect type by writer document URL. <p> 64 * 65 * Has <b> OK </b> status if type returned contains 66 * 'writer' as substring. 67 */ _queryTypeByURL()68 public void _queryTypeByURL() { 69 70 boolean result = true ; 71 String type = oObj.queryTypeByURL(docURL) ; 72 result &= type.indexOf("writer") > -1; 73 74 tRes.tested("queryTypeByURL()", result) ; 75 } 76 77 /** 78 * Tries to detect type of the document using <i>flat</i> 79 * and <i>deep</i> detection. For flat detection a writer type 80 * must be returned (file has writer extension), but deep 81 * detection must return calc type (document has calc contents)<p> 82 * 83 * Has <b> OK </b> status if for the first case type contains 84 * 'writer' string and for the second 'calc' string. 85 */ _queryTypeByDescriptor()86 public void _queryTypeByDescriptor() { 87 boolean result = true ; 88 boolean ok = true; 89 log.println("test document with wrong extension"); 90 log.println("the document '" + docURL + "' is not what it seems to be ;-)"); 91 PropertyValue[][] mediaDescr = new PropertyValue[1][1]; 92 mediaDescr[0][0] = new PropertyValue(); 93 mediaDescr[0][0].Name = "URL"; 94 mediaDescr[0][0].Value = docURL; 95 96 String type = oObj.queryTypeByDescriptor(mediaDescr, false); 97 ok = type.indexOf("writer") > -1; 98 result &= ok; 99 log.println("flat detection should detect a writer and has detected '"+ type +"': " + ok); 100 101 type = oObj.queryTypeByDescriptor(mediaDescr, true); 102 ok = type.indexOf("calc") > -1; 103 result &= ok; 104 log.println("deep detection should detect a calc and has detected '"+ type +"': " + ok); 105 106 log.println("test dokument with bookmark: " + bookmarkURL); 107 mediaDescr = new PropertyValue[1][1]; 108 mediaDescr[0][0] = new PropertyValue(); 109 mediaDescr[0][0].Name = "URL"; 110 mediaDescr[0][0].Value = bookmarkURL; 111 type = oObj.queryTypeByDescriptor(mediaDescr, true); 112 ok = type.indexOf("writer") > -1; 113 result &= ok; 114 log.println("deep detection should detect a writer and has detected '"+ type +"': " + ok); 115 116 tRes.tested("queryTypeByDescriptor()", result) ; 117 } 118 } 119 120