1 /*
2  * This file is part of the LibreOffice project.
3  *
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/.
7  *
8  * This file incorporates work covered by the following license notice:
9  *
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 .
17  */
18 
19 package mod._forms;
20 
21 import com.sun.star.beans.PropertyValue;
22 import com.sun.star.drawing.XControlShape;
23 import com.sun.star.text.XTextDocument;
24 import com.sun.star.uno.UnoRuntime;
25 import com.sun.star.uno.XInterface;
26 import com.sun.star.util.XCloseable;
27 import java.io.PrintWriter;
28 import lib.TestCase;
29 import lib.TestEnvironment;
30 import lib.TestParameters;
31 import util.FormTools;
32 import util.WriterTools;
33 
34 public class OSpinButtonModel extends TestCase {
35 
36     XTextDocument xTextDoc;
37 
38     /**
39      * Creates a Writer document.
40      */
41     @Override
initialize( TestParameters tParam, PrintWriter log )42     protected void initialize( TestParameters tParam, PrintWriter log ) throws Exception {
43 
44         log.println( "creating a textdocument" );
45         xTextDoc = WriterTools.createTextDoc(tParam.getMSF());
46     }
47 
48     /**
49      * Disposes the Writer document.
50      */
51     @Override
cleanup(TestParameters tParam, PrintWriter log)52     protected void cleanup(TestParameters tParam, PrintWriter log) {
53         log.println("    disposing xTextDoc ");
54 
55         try {
56             XCloseable closer = UnoRuntime.queryInterface(
57                 XCloseable.class, xTextDoc);
58             closer.close(true);
59         } catch (com.sun.star.util.CloseVetoException e) {
60             log.println("couldn't close document");
61         } catch (com.sun.star.lang.DisposedException e) {
62             log.println("couldn't close document");
63         }
64     }
65 
66 
67     /**
68      * Creating a TestEnvironment for the interfaces to be tested.
69      * Adds spin button into text and retrieves it's control model.
70      */
71     @Override
createTestEnvironment(TestParameters Param, PrintWriter log)72     protected TestEnvironment createTestEnvironment(TestParameters Param, PrintWriter log)
73         throws com.sun.star.uno.Exception
74     {
75         XInterface oObj = null;
76 
77         XControlShape aShape = FormTools.createControlShape(
78             xTextDoc,3000,4500,15000,10000,"SpinButton");
79 
80         WriterTools.getDrawPage(xTextDoc).add(aShape);
81         oObj = aShape.getControl();
82         log.println( "creating a new environment for OButtonModel object" );
83         TestEnvironment tEnv = new TestEnvironment( oObj );
84         tEnv.addObjRelation("OBJNAME", "com.sun.star.form.component.SpinButton");
85         PropertyValue prop = new PropertyValue();
86         prop.Name = "HelpText";
87         prop.Value = "new Help Text since XPropertyAccess";
88         tEnv.addObjRelation("XPropertyAccess.propertyToChange", prop);
89         tEnv.addObjRelation("XPropertyContainer.propertyNotRemovable", "HelpText");
90 
91         System.out.println("Implementation name: "+util.utils.getImplName(oObj));
92         return tEnv;
93     } // finish method getTestEnvironment
94 
95 }
96