summaryrefslogtreecommitdiff
path: root/framework/qa
diff options
context:
space:
mode:
authorAkash Jain <akash96j@gmail.com>2016-04-05 11:58:01 +0530
committerStephan Bergmann <sbergman@redhat.com>2016-04-05 13:33:47 +0000
commit3e253963b93330dcd9e38c39de6601dbd43f13e4 (patch)
tree283520dcd24812363e14ddf63c8087e5755cc621 /framework/qa
parent739cbf2e0952532f96cb74689fa5a3bc8be8eb11 (diff)
Add unit tests for XTitle interface
Added several unit tests for the XTitle interface. Tests are for bugs tdf#96044,tdf#98837,tdf#96896 Change-Id: I9b3990dff02d5d5738024b60e94555199b625a2e Reviewed-on: https://gerrit.libreoffice.org/23834 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'framework/qa')
-rw-r--r--framework/qa/complex/XTitle/CheckXTitle.java284
1 files changed, 284 insertions, 0 deletions
diff --git a/framework/qa/complex/XTitle/CheckXTitle.java b/framework/qa/complex/XTitle/CheckXTitle.java
new file mode 100644
index 000000000000..486971ad8a3b
--- /dev/null
+++ b/framework/qa/complex/XTitle/CheckXTitle.java
@@ -0,0 +1,284 @@
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+package complex.XTitle;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import helper.URLHelper;
+
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.openoffice.test.OfficeConnection;
+import org.openoffice.test.OfficeFileUrl;
+
+import com.sun.star.beans.PropertyValue;
+import com.sun.star.frame.FrameSearchFlag;
+import com.sun.star.frame.XComponentLoader;
+import com.sun.star.frame.XFrame;
+import com.sun.star.frame.XFrame2;
+import com.sun.star.frame.XModel;
+import com.sun.star.frame.XTitle;
+import com.sun.star.frame.XController;
+import com.sun.star.frame.XStorable;
+import com.sun.star.lang.XComponent;
+import com.sun.star.lang.XMultiServiceFactory;
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.util.XCloseable;
+import com.sun.star.util.XURLTransformer;
+import com.sun.star.util.URL;
+import com.sun.star.frame.XDispatchProvider;
+import com.sun.star.frame.XDispatch;
+
+/** @short Check the interface XTitle
+
+ @descr These tests check in various cases the correctness of
+ the title in the ui window.
+*/
+
+public class CheckXTitle
+{
+
+ // some const
+ private static final String DOCUMENT_TITLE = "documentTitle";
+ private static final String UNO_URL_FOR_PRINT_PREVIEW = ".uno:PrintPreview";
+ private static final String UNO_URL_FOR_CLOSING_PRINT_PREVIEW = ".uno:ClosePreview";
+ private static final String UNO_URL_FOR_CLOSING_DOC = ".uno:CloseWin";
+ private static final String UNO_URL_FOR_READ_ONLY = ".uno:OpenReadOnly";
+
+ // members
+
+ /** provides XComponentLoader interface */
+ private XFrame m_xFrame = null;
+
+ /** will be set to xDesktop OR xFrame. */
+ private XComponentLoader m_xLoader = null;
+
+ /** provides uno service manager */
+ private XMultiServiceFactory m_xMSF = null;
+
+ /** used for parsing uno query URLs */
+ private XURLTransformer m_xParser = null;
+
+ // test environment
+ /** @short Create the environment for following tests.
+
+ @descr Use either a component loader from desktop or
+ from frame
+ */
+ @Before public void before() throws Exception
+ {
+ // get uno service manager from global test environment
+ /* points to the global uno service manager. */
+ m_xMSF = getMSF();
+
+ // create desktop instance
+ /* provides XComponentLoader interface. */
+ XFrame xDesktop = UnoRuntime.queryInterface(XFrame.class, m_xMSF.createInstance("com.sun.star.frame.Desktop"));
+
+ // create frame instance
+ m_xFrame = xDesktop.findFrame("testFrame_titleChecker",
+ FrameSearchFlag.TASKS | FrameSearchFlag.CREATE);
+ assertNotNull("Couldn't create test frame.", m_xFrame);
+
+ // define default loader
+ m_xLoader = UnoRuntime.queryInterface(XComponentLoader.class, xDesktop);
+ assertNotNull("Desktop service doesn't support needed component loader interface.", m_xLoader);
+
+ // get URL parser
+ m_xParser = UnoRuntime.queryInterface(XURLTransformer.class, m_xMSF.createInstance("com.sun.star.util.URLTransformer"));
+ assertNotNull("Could not obtain URL parser instance", m_xParser);
+
+ }
+
+ /** @short close the environment.
+ */
+ @After public void after() throws Exception
+ {
+ XCloseable xClose = UnoRuntime.queryInterface(XCloseable.class, m_xFrame);
+ xClose.close(false);
+
+ m_xFrame = null;
+ m_xLoader = null;
+ m_xParser = null;
+ m_xMSF = null;
+ }
+
+ // prepare an uno URL query and dispatch it
+ private void prepareQueryAndDispatch(XDispatchProvider xDisProv, String unoURL)
+ {
+ XDispatch xDispatcher = null;
+ URL[] aParseURL = new URL[1];
+ aParseURL[0] = new URL();
+ aParseURL[0].Complete = unoURL;
+ m_xParser.parseStrict(aParseURL);
+
+ xDispatcher = xDisProv.queryDispatch(aParseURL[0], "", 0);
+ assertNotNull("Can not obtain dispatcher for query: " + unoURL, xDispatcher);
+ xDispatcher.dispatch(aParseURL[0], null);
+ }
+
+ /** @short checks the numbers displayed in the title
+
+ @descr cycles through default view and print preview
+ and asserts that the title doesn't change.
+ */
+ @Test public void checkTitleNumbers() throws Exception
+ {
+ PropertyValue[] lArgs = new PropertyValue[1];
+
+ lArgs[0] = new PropertyValue();
+ lArgs[0].Name = "Hidden";
+ lArgs[0].Value = Boolean.FALSE;
+
+ // load doc
+ XComponent xDoc=null;
+ xDoc = m_xLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, lArgs);
+ assertNotNull("Could not load temporary document", xDoc);
+
+ XModel xModel = UnoRuntime.queryInterface( XModel.class, xDoc );
+ XController xController = UnoRuntime.queryInterface( XController.class, xModel.getCurrentController() );
+ XTitle xTitle = UnoRuntime.queryInterface( XTitle.class, xModel.getCurrentController().getFrame() );
+ XDispatchProvider xDisProv = null;
+
+ // get window title with ui in default mode
+ String defaultTitle = xTitle.getTitle();
+
+ xDisProv = UnoRuntime.queryInterface( XDispatchProvider.class, xModel.getCurrentController() );
+ prepareQueryAndDispatch( xDisProv, UNO_URL_FOR_PRINT_PREVIEW );
+ // get window title with ui in print preview mode
+ String printPreviewTitle = xTitle.getTitle();
+ assertEquals("Title mismatch between default view window title and print preview window title",
+ defaultTitle, printPreviewTitle);
+
+ xDisProv = UnoRuntime.queryInterface( XDispatchProvider.class, xModel.getCurrentController() );
+ prepareQueryAndDispatch( xDisProv, UNO_URL_FOR_CLOSING_PRINT_PREVIEW );
+ //get window title with ui back in default mode
+ String printPreviewClosedTitle = xTitle.getTitle();
+ assertEquals("Title mismatch between default view window title and title after switching from print preview to default view window" ,defaultTitle, printPreviewClosedTitle);
+
+ xDisProv = UnoRuntime.queryInterface( XDispatchProvider.class, xModel.getCurrentController() );
+ prepareQueryAndDispatch( xDisProv, UNO_URL_FOR_CLOSING_DOC );
+
+ xDoc = null;
+ xDisProv = null;
+ }
+
+ /** @short sets frame title and checks for infinite recusion
+
+ @descr sets frame title. then cycles through default and
+ print preview. then closes the window and checks
+ for infinite recursion.
+ */
+ @Test public void setTitleAndCheck() throws Exception
+ {
+ PropertyValue[] lArgs = new PropertyValue[1];
+
+ lArgs[0] = new PropertyValue();
+ lArgs[0].Name = "Hidden";
+ lArgs[0].Value = Boolean.FALSE;
+
+ // load doc
+ XComponent xDoc = null;
+ xDoc = m_xLoader.loadComponentFromURL("private:factory/swriter", "_blank", 0, lArgs);
+ assertNotNull("Could not create office document", xDoc);
+ XModel xModel = UnoRuntime.queryInterface( XModel.class, xDoc );
+ XFrame2 xFrame = UnoRuntime.queryInterface( XFrame2.class, xModel.getCurrentController().getFrame() );
+ XDispatchProvider xDisProv = null;
+ // set doc title
+ xFrame.setTitle(DOCUMENT_TITLE);
+
+ // switch to print preview mode
+ xDisProv = UnoRuntime.queryInterface( XDispatchProvider.class, xModel.getCurrentController() );
+ prepareQueryAndDispatch( xDisProv, UNO_URL_FOR_PRINT_PREVIEW );
+
+ // switch back to default mode
+ xDisProv = UnoRuntime.queryInterface( XDispatchProvider.class, xModel.getCurrentController() );
+ prepareQueryAndDispatch( xDisProv, UNO_URL_FOR_CLOSING_PRINT_PREVIEW );
+
+ // close document
+ xDisProv = UnoRuntime.queryInterface( XDispatchProvider.class, xModel.getCurrentController() );
+ // todo: execute this on a new thread using executorservice and terminate it after some time
+ try{
+ prepareQueryAndDispatch( xDisProv, UNO_URL_FOR_CLOSING_DOC );
+ } catch( Exception e ) {
+ // cr: there is no exception being thrown when there should be one
+ fail(e.toString());
+ }
+
+ xDoc = null;
+ xDisProv = null;
+ }
+
+ /** @short checks loading of new document with readonly set to true
+
+ @descr loads a new document with readonly mode set to true.
+ this should fail because new doc can not be opened in
+ read only mode
+ */
+ // cr: this test should ideally be in CheckXModuleManager
+ // but that test is disabled in JunitTest_framework_complex.mk
+ @Test public void checkLoadingWithReadOnly()
+ {
+ PropertyValue[] lArgs = new PropertyValue[2];
+
+ lArgs[0] = new PropertyValue();
+ lArgs[0].Name = "Hidden";
+ lArgs[0].Value = Boolean.FALSE;
+ lArgs[1] = new PropertyValue();
+ lArgs[1].Name = "ReadOnly";
+ lArgs[1].Value = Boolean.TRUE;
+
+ // load doc
+ XComponent xDoc = null;
+ try{
+ xDoc = m_xLoader.loadComponentFromURL("private:factory/swriter", "_default", 0, lArgs);
+ } catch (Exception e) {
+ //exception is expected. do nothing
+ }
+
+ assertNull("Loading new document with read only mode true should have failed", xDoc);
+ }
+
+ private XMultiServiceFactory getMSF()
+ {
+ return UnoRuntime.queryInterface(XMultiServiceFactory.class, connection.getComponentContext().getServiceManager());
+ }
+
+ // setup and close connections
+ @BeforeClass
+ public static void setUpConnection() throws Exception
+ {
+ System.out.println("setUpConnection()");
+ connection.setUp();
+ }
+
+ @AfterClass
+ public static void tearDownConnection()
+ throws InterruptedException, com.sun.star.uno.Exception
+ {
+ System.out.println("tearDownConnection()");
+ connection.tearDown();
+ }
+ private static final OfficeConnection connection = new OfficeConnection();
+}