/** * Inserts the element stored and removed before. * * <p>Has <b> OK </b> status if <code>has()</code> method returns <code>true</code>. The following * method tests are to be completed successfully before : * * <ul> * <li><code> remove() </code> : element from set is stored and removed * </ul> */ public void _insert() { boolean res = true; try { XMultiServiceFactory xMSF = (XMultiServiceFactory) tParam.getMSF(); element = xMSF.createInstance("com.sun.star.reflection.TypeDescriptionProvider"); oObj.insert(element); if (!oObj.has(element)) { res = false; log.println("After adding element method has()" + " returned false"); hasResult = false; } } catch (com.sun.star.container.ElementExistException e) { e.printStackTrace(log); res = false; } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); res = false; } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); res = false; } tRes.tested("insert()", res); }
/** * Creating a Testenvironment for the interfaces to be tested. Creates an instance of the service * <code>com.sun.star.text.AutoTextContainer</code>, then selects the 'mytexts' group from the * given container using <code>XNameAccess</code> interface, and inserts some text entry to this * group. Then entry passed as test component. * * <p>Object relations created : * * <ul> * <li><code>'XTEXTINFO'</code> for {@link ifc.text._XText} : creates tables 6x4 * <li><code>'TEXTDOC'</code> for {@link ifc.text._XAutoTextEntry} : text document * </ul> */ protected synchronized TestEnvironment createTestEnvironment( TestParameters Param, PrintWriter log) { XAutoTextEntry oEntry = null; XAutoTextContainer oContainer; XInterface oObj = null; log.println("creating a test environment"); try { XMultiServiceFactory myMSF = (XMultiServiceFactory) Param.getMSF(); Object oInst = myMSF.createInstance("com.sun.star.text.AutoTextContainer"); oContainer = UnoRuntime.queryInterface(XAutoTextContainer.class, oInst); } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); throw new StatusException("Couldn't create AutoTextContainer", e); } XNameAccess oContNames = UnoRuntime.queryInterface(XNameAccess.class, oContainer); String contNames[] = oContNames.getElementNames(); for (int i = 0; i < contNames.length; i++) { log.println("ContainerNames[ " + i + "]: " + contNames[i]); } try { oObj = (XInterface) AnyConverter.toObject(new Type(XInterface.class), oContNames.getByName("mytexts")); } catch (com.sun.star.uno.Exception e) { e.printStackTrace(log); throw new StatusException("Couldn't get AutoTextGroup", e); } oGroup = UnoRuntime.queryInterface(XAutoTextGroup.class, oObj); String[] oENames = oGroup.getElementNames(); for (int i = 0; i < oENames.length; i++) { log.println("AutoTextEntryNames[" + i + "]: " + oENames[i]); } XText oText = xTextDoc.getText(); oText.insertString(oText.getStart(), "New AutoText", true); XTextRange oTextRange = oText; try { if (oGroup.hasByName("NewEntryName")) { oGroup.removeByName("NewEntryName"); log.println("Element 'NewEntryName' exists, removing..."); } log.println("Adding new element 'NewEntryName' to group..."); oGroup.insertNewByName("NewEntryName", "NewEntryTitle", oTextRange); oEntry = (XAutoTextEntry) AnyConverter.toObject( new Type(XAutoTextEntry.class), oGroup.getByName("NewEntryName")); } catch (com.sun.star.container.ElementExistException e) { e.printStackTrace(log); } catch (com.sun.star.container.NoSuchElementException e) { e.printStackTrace(log); } catch (com.sun.star.lang.WrappedTargetException e) { e.printStackTrace(log); } catch (com.sun.star.lang.IllegalArgumentException e) { e.printStackTrace(log); } oObj = oEntry; log.println("Trying to use XText as TextRange in the method applyTo"); oEntry.applyTo(oTextRange); oTextRange = oText.createTextCursor(); log.println("Trying to use XTextCursor as TextRange in the method applyTo"); oEntry.applyTo(oTextRange); log.println("creating a new environment for AutoTextEntry object"); TestEnvironment tEnv = new TestEnvironment(oObj); // adding relation for XText DefaultDsc tDsc = new DefaultDsc("com.sun.star.text.XTextContent", "com.sun.star.text.TextField.DateTime"); log.println(" adding InstCreator object"); tEnv.addObjRelation("XTEXTINFO", new InstCreator(xTextDoc, tDsc)); log.println("adding TextDocument as mod relation to environment"); tEnv.addObjRelation("TEXTDOC", xTextDoc); return tEnv; } // finish method getTestEnvironment