1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 package ifc.view;
29 
30 import com.sun.star.form.XForm;
31 import com.sun.star.form.runtime.XFormController;
32 import lib.MultiMethodTest;
33 
34 import com.sun.star.view.XFormLayerAccess;
35 import lib.Status;
36 import lib.StatusException;
37 
38 
39 /**
40  * Testing <code>com.sun.star.view.XFormLayerAccess</code>
41  * interface methods :
42  * <ul>
43  *  <li><code> getFromController()</code></li>
44  *  <li><code> isFormDesignMode()</code></li>
45  *  <li><code> setFormDesignMode()</code></li>
46  * </ul> <p>
47  *
48  * Test is <b> NOT </b> multithread compilant. <p>
49  * @see com.sun.star.view.XFormLayerAccess
50  */
51 public class _XFormLayerAccess extends MultiMethodTest {
52 
53     // oObj filled by MultiMethodTest
54 
55     public XFormLayerAccess oObj = null;
56 
57     private XForm xForm = null;
58 
59     /**
60      * checks if the object relation <CODE>XFormLayerAccess.XForm</CODE>
61      * is available
62      */
63     public void before() {
64         xForm = (XForm) tEnv.getObjRelation("XFormLayerAccess.XForm");
65         if (xForm == null) {
66             throw new StatusException(Status.failed("Object raltion 'XFormLayerAccess.XForm' is null"));
67         }
68     }
69 
70     /**
71      * Test disables the FormDesignMode and calls the mthod. <p>
72      * Has <b> OK </b> status if the method returns
73      * a not empty object of kind of com.sun.star.form.XFormController<P>
74      * The following method tests are to be completed successfully before :
75      * <ul>
76      *  <li> <code> setFormDesignMode() </code></li>
77      * </ul>
78      * @see com.sun.star.view.XFormLayerAccess
79      */
80     public void _getFromController(){
81         requiredMethod("setFormDesignMode()") ;
82 
83         log.println("try to get current DesignMode...");
84         boolean currentMode = oObj.isFormDesignMode();
85         log.println("DesignMode is " + currentMode);
86 
87         log.println("enable DesignMode");
88         oObj.setFormDesignMode(false);
89 
90         log.println("test for getFromController() ");
91         XFormController xFormCont = oObj.getFormController(xForm);
92 
93         if (xFormCont == null)
94             log.println("ERROR: Could not get FromContoller");
95 
96         log.println("set back DesignMode to previouse state");
97         oObj.setFormDesignMode(currentMode);
98 
99         tRes.tested("getFromController()", xFormCont != null );
100     }
101 
102     /**
103      * This test calls the test for <code>setFormDesignMode()</CODE>.
104      * Has <b> OK </b> status if the test for  setFormDesignMode() returns
105      * <code>true</code> since the tests use <CODE>isFormDesignMode()</CODE><P>
106      * The following method tests are to be completed successfully before :
107      * <ul>
108      *  <li> <code> setFormDesignMode() </code></li>
109      * </ul>
110      */
111     public void _isFormDesignMode(){
112         requiredMethod("setFormDesignMode()") ;
113 
114         log.println("test for isFormDesignMode() is ok since test for 'setFormDesingMode()' use it");
115         tRes.tested("isFormDesignMode()", true);
116     }
117 
118     /**
119      * This test gets the current FormDesignMode, change it to the opposite and checks if the expected value of
120      * method isFormDesignmode() was given. Then the FormDesignmode was set back to the original value.<P>
121      * Has <B> OK </B> if expected values are returned.
122      *
123      */
124 
125     public void _setFormDesignMode(){
126         log.println("test for setFormDesignMode() and isFormDesignMode() ");
127 
128         log.println("try to get current DesignMode...");
129         boolean currentMode = oObj.isFormDesignMode();
130         log.println("DesignMode is " + currentMode);
131 
132         log.println("try to change to " + !currentMode + "...");
133         oObj.setFormDesignMode(!currentMode);
134         log.println("try to get new DesignMode...");
135         boolean newMode = oObj.isFormDesignMode();
136         log.println("DesignMode is " + newMode);
137 
138         boolean bOK = (newMode != currentMode);
139 
140         if ( !bOK)
141             log.println("ERROR: both modes are equal");
142 
143         log.println("set back DesignMode to " + currentMode);
144         oObj.setFormDesignMode(currentMode);
145 
146         log.println("try to get DesignMode...");
147         boolean oldMode = oObj.isFormDesignMode();
148 
149         bOK &= (bOK &(currentMode == oldMode));
150 
151         if (currentMode != oldMode)
152             log.println("ERROR: could not change back");
153 
154         tRes.tested("setFormDesignMode()", bOK );
155     }
156 
157 }  // finish class _XFormLayerAccess
158 
159