Avoid potential negative array index access to cached text.
[LibreOffice.git] / qadevOOo / tests / java / mod / _fwk / PopupMenuControllerFactory.java
blob60dee1adf3018211442e65bc1c273c7ef66b474e
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
19 package mod._fwk;
21 import com.sun.star.beans.XPropertySet;
22 import com.sun.star.lang.XMultiServiceFactory;
23 import com.sun.star.uno.UnoRuntime;
24 import com.sun.star.uno.XInterface;
25 import java.io.PrintWriter;
26 import com.sun.star.text.XTextDocument;
27 import com.sun.star.uno.XComponentContext;
28 import com.sun.star.util.XCloseable;
29 import com.sun.star.frame.XUIControllerRegistration;
30 import lib.TestCase;
31 import lib.TestEnvironment;
32 import lib.TestParameters;
33 import util.WriterTools;
35 /**
37 public class PopupMenuControllerFactory extends TestCase {
38 XTextDocument xTextDoc;
40 /**
41 * Cleanup: close the created document
42 * @param tParam The test parameters.
43 * @param log The log writer.
45 @Override
46 protected void cleanup(TestParameters tParam, PrintWriter log) {
47 log.println(" disposing xTextDoc ");
49 try {
50 XCloseable closer = UnoRuntime.queryInterface(
51 XCloseable.class, xTextDoc);
52 closer.close(true);
53 } catch (com.sun.star.util.CloseVetoException e) {
54 log.println("couldn't close document");
55 } catch (com.sun.star.lang.DisposedException e) {
56 log.println("couldn't close document");
61 /**
62 * Create test environment:
63 * @param tParam The test parameters.
64 * @param log The log writer.
65 * @return The test environment.
67 @Override
68 protected TestEnvironment createTestEnvironment(TestParameters tParam, PrintWriter log) throws Exception {
69 TestEnvironment tEnv = null;
70 XMultiServiceFactory xMSF = tParam.getMSF();
71 XInterface xInst = null;
73 log.println("Creating instance...");
75 xTextDoc = WriterTools.createTextDoc(xMSF);
76 util.dbg.printInterfaces(xTextDoc);
78 xInst = (XInterface)xMSF.createInstance(
79 "com.sun.star.comp.framework.PopupMenuControllerFactory");
81 log.println("TestObject: " + util.utils.getImplName(xInst));
82 tEnv = new TestEnvironment(xInst);
83 XPropertySet xProp = UnoRuntime.queryInterface(XPropertySet.class, xMSF);
84 Object o = xProp.getPropertyValue("DefaultContext");
85 XComponentContext xContext = UnoRuntime.queryInterface(XComponentContext.class, o);
86 tEnv.addObjRelation("DC", xContext);
88 // register one controller, so it can be instantiated
89 XUIControllerRegistration xReg = UnoRuntime.queryInterface(XUIControllerRegistration.class, xInst);
91 xReg.registerController(".uno:MyCommandUrl", "", "com.sun.star.comp.framework.FooterMenuController");
92 tEnv.addObjRelation("XUIControllerRegistration.RegisteredController", ".uno:MyCommandUrl");
93 tEnv.addObjRelation("XMultiComponentFactory.ServiceNames", new String[]{".uno:MyCommandUrl"});
95 return tEnv;