1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 19 package ifc.container; 20 21 import lib.MultiMethodTest; 22 23 import com.sun.star.container.NoSuchElementException; 24 import com.sun.star.container.XNameAccess; 25 26 /** 27 * Testing <code>com.sun.star.container.XNameAccess</code> interface methods. <p> 28 * Test is <b> NOT </b> multithread compliant. <p> 29 */ 30 public class _XNameAccess extends MultiMethodTest { 31 public XNameAccess oObj = null; 32 public String[] Names = null; 33 34 /** 35 * Test calls the method and checks return value and that 36 * no exceptions were thrown. <p> 37 * Has <b> OK </b> status if the method successfully returns 38 * not null value and no exceptions were thrown. <p> 39 */ _getElementNames()40 public void _getElementNames() { 41 boolean result = true; 42 log.println("getting elements names"); 43 Names = oObj.getElementNames(); 44 45 result = (Names != null); 46 tRes.tested("getElementNames()", result); 47 } // end getElementNames() 48 49 /** 50 * First test calls the method with existing element name, 51 * then with non existing. <p> 52 * Has <b> OK </b> status if in the first case the method returns 53 * true and in the second - false. <p> 54 * The following method tests are to be completed successfully before : 55 * <ul> 56 * <li> <code> getElementNames </code> : to retrieve at least one 57 * element name. </li> 58 * </ul> 59 */ _hasByName()60 public void _hasByName() { 61 requiredMethod("getElementNames()"); 62 log.println("testing hasByName() ..."); 63 64 boolean result = true; 65 boolean loc_result = true; 66 67 String name = null; 68 69 if (Names.length != 0) { 70 name = Names[0]; 71 log.println("testing hasByName() with valid name '" + name + "'"); 72 loc_result = oObj.hasByName(name); 73 log.println("hasByName with valid names: " + loc_result); 74 result &= loc_result; 75 } 76 77 name = "non_existent_name__1234"; 78 log.println("testing hasByName() with invalid name"); 79 try { 80 loc_result = !oObj.hasByName(name); 81 } catch ( Exception nsee) { 82 log.println("Expected exception was thrown"); 83 } 84 log.println("hasByName with invalid names: " + loc_result); 85 result &= loc_result; 86 87 tRes.tested("hasByName()", result); 88 } // end hasByName() 89 90 91 /** 92 * First test calls the method with existing element name, 93 * then with non existing. <p> 94 * Has <b> OK </b> status if in the first case the method returns 95 * not null value and no exceptions were thrown, 96 * and in the second case <code>NoSuchElementException</code> was 97 * thrown. <p> 98 * The following method tests are to be completed successfully before : 99 * <ul> 100 * <li> <code> getElementNames </code> : to retrieve at least one 101 * element name. </li> 102 * </ul> 103 */ _getByName()104 public void _getByName() { 105 log.println("require getElementNames() ..."); 106 requiredMethod("getElementNames()"); 107 log.println("require getElementNames() ...OK"); 108 log.println("testing getByName() ..."); 109 110 boolean result = true; 111 boolean loc_result = true; 112 113 String name = null; 114 115 if (Names.length != 0) { 116 name = Names[0]; 117 log.println("testing with valid name '" + name + "'"); 118 try { 119 loc_result = (null != oObj.getByName(name)); 120 } catch (Exception e) { 121 log.println("Exception! - FAILED"); 122 log.println(e.toString()); 123 loc_result = false; 124 } 125 log.println("getByName with valid name: " + loc_result); 126 result &= loc_result; 127 } 128 129 log.println("testing with non-existent name"); 130 name = "non_existent_name__1234"; 131 try { 132 loc_result = (null != oObj.getByName(name)); 133 loc_result = false; 134 log.println("getByName: Exception expected - FAILED"); 135 } catch (NoSuchElementException e) { 136 log.println("getByName: Expected exception - OK"); 137 loc_result = true; 138 } catch (com.sun.star.lang.WrappedTargetException e) { 139 log.println("getByName: Wrong exception - " + e + " - FAILED"); 140 loc_result = false; 141 } 142 143 result &= loc_result; 144 tRes.tested("getByName()", result); 145 } // end getByName() 146 } /// finished class _XNameAccess 147 148 149 150