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 package ifc.util; 24 25 import com.sun.star.util.XProtectable; 26 import lib.MultiMethodTest; 27 28 /** 29 * Check the XProtectable interface. 30 */ 31 public class _XProtectable extends MultiMethodTest { 32 public XProtectable oObj = null; 33 String sPassWord = "TopSecret"; 34 35 /** 36 * Check, if the sheet is protected. 37 * Has OK status, if this is the case. 38 */ _isProtected()39 public void _isProtected() { 40 requiredMethod("protect()"); 41 boolean result = oObj.isProtected(); 42 tRes.tested("isProtected()", result); 43 } 44 45 /** 46 * Protect the sheet 47 */ _protect()48 public void _protect() { 49 oObj.protect(sPassWord); 50 tRes.tested("protect()", true); 51 } 52 53 /** 54 * Unprotect with wrong password, see if it's still protected. 55 * Unprotect with correct password, see if it's unprotected. 56 */ _unprotect()57 public void _unprotect() { 58 requiredMethod("isProtected()"); 59 boolean result = true; 60 try { 61 oObj.unprotect("WrongPassword"); 62 // result = false; 63 } 64 catch(com.sun.star.lang.IllegalArgumentException e) { 65 log.println("Correct Exception thrown."); 66 } 67 // just check if it's still protected 68 result &= oObj.isProtected(); 69 try { 70 oObj.unprotect(sPassWord); 71 } 72 catch(com.sun.star.lang.IllegalArgumentException e) { 73 log.println("Wrong Exception thrown: password is correct."); 74 result = false; 75 } 76 result &= !oObj.isProtected(); 77 tRes.tested("unprotect()", result); 78 } 79 80 } 81