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.text; 24 25 import lib.MultiMethodTest; 26 27 import com.sun.star.container.XNameAccess; 28 import com.sun.star.text.XTextSectionsSupplier; 29 30 31 public class _XTextSectionsSupplier extends MultiMethodTest { 32 public XTextSectionsSupplier oObj; 33 _getTextSections()34 public void _getTextSections() { 35 XNameAccess sections = oObj.getTextSections(); 36 boolean res = checkSections(sections); 37 tRes.tested("getTextSections()", res); 38 } 39 checkSections(XNameAccess sections)40 protected boolean checkSections(XNameAccess sections) { 41 String[] sNames = sections.getElementNames(); 42 boolean res = true; 43 44 for (int k = 0; k < sNames.length; k++) { 45 try { 46 res &= sections.hasByName(sNames[k]); 47 res &= (sections.getByName(sNames[k]) != null); 48 log.println("Works for ... " + sNames[k]); 49 } catch (com.sun.star.container.NoSuchElementException e) { 50 log.println("positive test failed " + e.getMessage()); 51 res = false; 52 } catch (com.sun.star.lang.WrappedTargetException e) { 53 log.println("positive test failed " + e.getMessage()); 54 res = false; 55 } 56 } 57 58 try { 59 sections.getByName("unknown"); 60 log.println("negative test failed ... no Exception thrown"); 61 res = false; 62 } catch (com.sun.star.container.NoSuchElementException e) { 63 log.println("expected Exception for wrong argument ... OK"); 64 } catch (com.sun.star.lang.WrappedTargetException e) { 65 log.println("negative test failed ... wrong Exception thrown"); 66 res = false; 67 } 68 69 return res; 70 } 71 }