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 mod._scripting;
29 
30 import com.sun.star.uno.XInterface;
31 import java.io.PrintWriter;
32 import lib.StatusException;
33 import lib.TestCase;
34 import lib.TestEnvironment;
35 import lib.TestParameters;
36 import util.utils;
37 import java.net.URLEncoder;
38 import com.sun.star.lang.XMultiServiceFactory;
39 import com.sun.star.ucb.XSimpleFileAccess;
40 import com.sun.star.uno.UnoRuntime;
41 
42 import drafts.com.sun.star.script.framework.storage.XScriptInfoAccess;
43 import drafts.com.sun.star.script.framework.storage.XScriptInfo;
44 
45 public class ScriptInfo extends TestCase {
46 
47     String docPath = null;
48     public void initialize( TestParameters tParam, PrintWriter log ) {
49         // Get path to test documents
50         String rootDocPath = ( String )tParam.get( "DOCPTH" );
51         System.out.println( "DOCPTH is " + rootDocPath );
52         rootDocPath = util.utils.getFullTestURL( "ExampleSpreadSheetLatest.sxc" );
53         if ( rootDocPath != null && rootDocPath.length() > 1 ){
54             // convert all "\\" to "/", necessary for UCB
55             if ( rootDocPath.indexOf( "\\" ) > 0 ){
56                 rootDocPath = rootDocPath.replace( '\\','/' );
57 	    }
58             System.out.println("After processing the path is " + rootDocPath);
59 	    // encode the ulr (for UCB)
60             String encodedPath = URLEncoder.encode( rootDocPath );
61             System.out.println("The encoded path is " + encodedPath );
62             docPath = "vnd.sun.star.pkg://" + encodedPath;
63             System.out.println( "docPath path is " + docPath );
64         }
65 
66     }
67 
68     public synchronized TestEnvironment createTestEnvironment(
69         TestParameters tParam, PrintWriter log ) throws StatusException {
70 
71 	log.println("creating test environment");
72         if ( docPath == null ){
73             log.println("Testdata not set up, docPath is null");
74             throw new StatusException(
75                 "Can't create object environment, no test document available",
76                 new Exception() ) ;
77         }
78 
79         XInterface oObj = null;
80         XSimpleFileAccess access = null;
81         try {
82             XMultiServiceFactory xMSF = tParam.getMSF();
83             Object xInterface =
84                 xMSF.createInstance( "com.sun.star.ucb.SimpleFileAccess" );
85             access = ( XSimpleFileAccess )
86                 UnoRuntime.queryInterface( XSimpleFileAccess.class, xInterface );
87             Object storageObj = ( XInterface )xMSF.createInstanceWithArguments(
88                 "drafts.com.sun.star.script.framework.storage.ScriptStorage",
89                 new Object[]{ access, new Integer(99), docPath } );
90             XScriptInfoAccess infoAccess = ( XScriptInfoAccess )UnoRuntime.queryInterface(XScriptInfoAccess.class, storageObj);
91             XScriptInfo[] infos = infoAccess.getImplementations("script://MemoryUtils.MemUsage?location=document");
92            oObj = infos[0];
93         } catch (com.sun.star.uno.Exception e) {
94             throw new StatusException("Can't create object environment", e) ;
95         }
96 
97         TestEnvironment tEnv = new TestEnvironment(oObj) ;
98         TestDataLoader.setupData(tEnv, "ScriptInfo");
99 
100         return tEnv ;
101     }
102 
103     public synchronized void disposeTestEnvironment( TestEnvironment tEnv,
104             TestParameters tParam) {
105     }
106 }
107 
108 
109