xref: /AOO42X/main/qadevOOo/tests/java/complex/unoapi/CheckModuleAPI.java (revision 850627aea5051aeeadcec55420dcd716dc66f0c8)
1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23a3415cdeSmseidel 
24cdf0e10cSrcweir /** complex tests to check the UNO-API
25cdf0e10cSrcweir  **/
26cdf0e10cSrcweir package complex.unoapi;
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // imports
29cdf0e10cSrcweir import base.java_complex;
30cdf0e10cSrcweir import complexlib.ComplexTestCase;
31cdf0e10cSrcweir import helper.OfficeProvider;
32cdf0e10cSrcweir import helper.ParameterNotFoundException;
33cdf0e10cSrcweir import helper.ProcessHandler;
34cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory;
35cdf0e10cSrcweir import helper.BuildEnvTools;
36cdf0e10cSrcweir import helper.ComplexDescGetter;
37cdf0e10cSrcweir import helper.CwsDataExchangeImpl;
38cdf0e10cSrcweir import java.io.File;
39cdf0e10cSrcweir // import java.io.FileFilter;
40cdf0e10cSrcweir import java.util.ArrayList;
41cdf0e10cSrcweir import java.util.HashMap;
42cdf0e10cSrcweir import java.util.Iterator;
43cdf0e10cSrcweir import java.util.Set;
44cdf0e10cSrcweir import share.DescEntry;
45cdf0e10cSrcweir import util.PropertyName;
46cdf0e10cSrcweir import util.utils;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir /**
49cdf0e10cSrcweir  * This Complex Test will test the UNO-API by calling dmake in <B>$MODULE</B>/qa/unoapi<p>
50a3415cdeSmseidel  * This test depends on some requirements:
51cdf0e10cSrcweir  * The <B>TestJob</B> is <b>-o complex.unoapi.CheckModuleAPI::module(<CODE>MODULE</CODE>)</b><p> where <CODE>MODULE</CODE>
52cdf0e10cSrcweir  * could be the following:<p>
53cdf0e10cSrcweir  * <ul>
54cdf0e10cSrcweir  *  <li><b>all</b>  iterates over <CODE>SRC_ROOT</CODE> and call <CODE>dmake</CODE> in all qa/unoapi folder</li><p>
55cdf0e10cSrcweir  *  <li><b>$module</b>  call dmake in $module/qa/unoapi folder</li><p>
56cdf0e10cSrcweir  *  <li><b>$module1,$module2,...</b>    call dmake in $module1/qa/unoapi folder then in $module2/qa/unoapi folder and so on</li><p>
57cdf0e10cSrcweir  * </ul><p>
58cdf0e10cSrcweir  *
59cdf0e10cSrcweir  * Also you have to fill the following parameter:
60cdf0e10cSrcweir  * <ul>
61cdf0e10cSrcweir  *  <li><b>SHELL</b>:      fill this parameter with a shell</li>
62cdf0e10cSrcweir  * </ul>
63cdf0e10cSrcweir  *
64cdf0e10cSrcweir  */
65cdf0e10cSrcweir public class CheckModuleAPI extends ComplexTestCase
66cdf0e10cSrcweir {
67cdf0e10cSrcweir 
68cdf0e10cSrcweir     private static String mSRC_ROOT = null;
69cdf0e10cSrcweir     private static boolean mIsInitialized = false;
70cdf0e10cSrcweir     private final static boolean mContinue = true;
71cdf0e10cSrcweir     private static boolean mDebug = false;
72cdf0e10cSrcweir     private static BuildEnvTools bet = null;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     /**
75cdf0e10cSrcweir      * Initialize the test environment.
76a3415cdeSmseidel      * This method checks for all necessary parameter and exit if not all parameter are set.
77cdf0e10cSrcweir      *
78cdf0e10cSrcweir      * Further this method starts an office instance and gets the office some more time to start. This is because
79*850627aeSJohn Bampton      * some freshly installed offices do not have such a user tree. The office will create it on its first start,
80cdf0e10cSrcweir      * but this will take some time.
81a3415cdeSmseidel      * Note: This functionality is only reasonable with parameter <CODE>-noOffice true</CODE>
82cdf0e10cSrcweir      */
before()83cdf0e10cSrcweir     public void before()
84cdf0e10cSrcweir     {
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         if (!mIsInitialized)
87cdf0e10cSrcweir         {
88cdf0e10cSrcweir             mIsInitialized = true;
89cdf0e10cSrcweir 
90cdf0e10cSrcweir             try
91cdf0e10cSrcweir             {
92cdf0e10cSrcweir 
93cdf0e10cSrcweir                 bet = new BuildEnvTools(param, log);
94cdf0e10cSrcweir 
95cdf0e10cSrcweir             }
96cdf0e10cSrcweir             catch (ParameterNotFoundException ex)
97cdf0e10cSrcweir             {
98cdf0e10cSrcweir                 this.failed(ex.toString(), false);
99cdf0e10cSrcweir             }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir             mSRC_ROOT = bet.getSrcRoot();
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             mDebug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir         }
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     /**
109cdf0e10cSrcweir      * let API tests run.
110cdf0e10cSrcweir      * @param module
111cdf0e10cSrcweir      */
checkModule(String module)112cdf0e10cSrcweir     public void checkModule(String module)
113cdf0e10cSrcweir     {
114cdf0e10cSrcweir         log.println(utils.getDateTime() + ": start testing module '" + module + "'");
115cdf0e10cSrcweir 
116cdf0e10cSrcweir         log.println(utils.getDateTime() + "start new Office instance...");
117cdf0e10cSrcweir 
118cdf0e10cSrcweir         // TODO: is Office started with this program?
119cdf0e10cSrcweir         final OfficeProvider officeProvider = new OfficeProvider();
120cdf0e10cSrcweir 
121cdf0e10cSrcweir         log.println(utils.getDateTime() + "Receiving the ServiceManager of the Office ");
122cdf0e10cSrcweir         final XMultiServiceFactory msf = (XMultiServiceFactory) officeProvider.getManager(param);
123*850627aeSJohn Bampton         assure("could not get ServiceFactory", msf != null, mContinue);
124cdf0e10cSrcweir         param.put("ServiceFactory", msf);
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         final String sep = System.getProperty("file.separator");
127cdf0e10cSrcweir         final String sUnoapi = getModulePath(module);
128cdf0e10cSrcweir         final File fUnoapi = new File(sUnoapi);
129cdf0e10cSrcweir         final String sMakeFile = sUnoapi + sep + "makefile.mk";
130cdf0e10cSrcweir         final File fMakeFile = new File(sMakeFile);
131cdf0e10cSrcweir         assure("ERROR: could not find makefile: '" + sMakeFile + "'", fMakeFile.exists(), mContinue);
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         final String[] commands = getDmakeCommands(sUnoapi);
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         final ProcessHandler procHdl = bet.runCommandsInEnvironmentShell(commands, fUnoapi, 0);
136cdf0e10cSrcweir         log.println("exit code of dmake: " + procHdl.getExitCode());
137cdf0e10cSrcweir         String test = procHdl.getOutputText();
138cdf0e10cSrcweir         test += procHdl.getErrorText();
139cdf0e10cSrcweir //        if (mDebug) {
140cdf0e10cSrcweir //            log.println("---> Output of dmake:");
141cdf0e10cSrcweir //            log.println(procHdl.getOutputText());
142cdf0e10cSrcweir //            log.println("<--- Output of dmake:");
143cdf0e10cSrcweir //            log.println("---> Error output of dmake:");
144cdf0e10cSrcweir //            log.println(procHdl.getErrorText());
145cdf0e10cSrcweir //            log.println("<--- Error output of dmake:");
146cdf0e10cSrcweir //        }
147cdf0e10cSrcweir         assure("module '" + module + "' failed", verifyOutput(test), mContinue);
148cdf0e10cSrcweir         log.println(utils.getDateTime() + " module '" + module + "': kill existing office...");
149cdf0e10cSrcweir 
150cdf0e10cSrcweir         // TODO: how to check if the office is not started with this process.
151cdf0e10cSrcweir         boolean bNoOffice = param.getBool("NoOffice");
152cdf0e10cSrcweir         if (!bNoOffice)
153cdf0e10cSrcweir         {
154cdf0e10cSrcweir             try
155cdf0e10cSrcweir             {
156cdf0e10cSrcweir                 officeProvider.closeExistingOffice(param, true);
157cdf0e10cSrcweir             }
158cdf0e10cSrcweir             catch (java.lang.UnsatisfiedLinkError exception)
159cdf0e10cSrcweir             {
160cdf0e10cSrcweir                 log.println("Office seems not to be running");
161cdf0e10cSrcweir             }
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir     }
getQaUnoApiPath(String srcRoot, String _sModul)164cdf0e10cSrcweir     private String getQaUnoApiPath(String srcRoot, String _sModul)
165cdf0e10cSrcweir     {
166cdf0e10cSrcweir         File aFile = new File(srcRoot);
167cdf0e10cSrcweir         if (!aFile.exists())
168cdf0e10cSrcweir         {
169cdf0e10cSrcweir             System.out.println("ERROR: srcRoot '" + srcRoot + "' does not exist.");
170cdf0e10cSrcweir             return null;
171cdf0e10cSrcweir         }
172cdf0e10cSrcweir         String sModulePath = srcRoot;
173cdf0e10cSrcweir         sModulePath += File.separator;
174cdf0e10cSrcweir         sModulePath += _sModul;
175cdf0e10cSrcweir 
176cdf0e10cSrcweir         File aModulePath = new File(sModulePath);
177cdf0e10cSrcweir         if (! aModulePath.exists())
178cdf0e10cSrcweir         {
179cdf0e10cSrcweir             aModulePath = new File(sModulePath + ".lnk");
180cdf0e10cSrcweir             if (! aModulePath.exists())
181cdf0e10cSrcweir             {
182cdf0e10cSrcweir                 aModulePath = new File(sModulePath + ".link");
183cdf0e10cSrcweir                 if (! aModulePath.exists())
184cdf0e10cSrcweir                 {
185cdf0e10cSrcweir                     // module does not exist.
186cdf0e10cSrcweir                     return null;
187cdf0e10cSrcweir                 }
188cdf0e10cSrcweir             }
189cdf0e10cSrcweir         }
190cdf0e10cSrcweir         sModulePath = aModulePath.getAbsolutePath();
191cdf0e10cSrcweir         sModulePath += File.separator;
192cdf0e10cSrcweir         sModulePath += "qa";
193cdf0e10cSrcweir         sModulePath += File.separator;
194cdf0e10cSrcweir         sModulePath += "unoapi";
195cdf0e10cSrcweir         File aModulePathQaUnoApi = new File(sModulePath);
196cdf0e10cSrcweir         if (aModulePathQaUnoApi.exists())
197cdf0e10cSrcweir         {
198cdf0e10cSrcweir             return aModulePathQaUnoApi.getAbsolutePath();
199cdf0e10cSrcweir         }
200cdf0e10cSrcweir         return null;
201cdf0e10cSrcweir     }
doesQaUnoApiFolderExist(String srcRoot, String _sModul)202cdf0e10cSrcweir     private boolean doesQaUnoApiFolderExist(String srcRoot, String _sModul)
203cdf0e10cSrcweir     {
204cdf0e10cSrcweir         if (getQaUnoApiPath(srcRoot, _sModul) != null)
205cdf0e10cSrcweir         {
206cdf0e10cSrcweir             return true;
207cdf0e10cSrcweir         }
208cdf0e10cSrcweir         return false;
209cdf0e10cSrcweir     }
210cdf0e10cSrcweir /*
211cdf0e10cSrcweir  private boolean doesQaUnoApiFolderExist(File srcRoot)
212cdf0e10cSrcweir     {
213cdf0e10cSrcweir         final FolderFilter qaFilter = new FolderFilter("qa");
214cdf0e10cSrcweir         final File[] qaTree = srcRoot.listFiles(qaFilter);
215cdf0e10cSrcweir         if (qaTree != null)
216cdf0e10cSrcweir         {
217cdf0e10cSrcweir             for (int j = 0; j < qaTree.length; j++)
218cdf0e10cSrcweir             {
219cdf0e10cSrcweir                 final File qaFolder = qaTree[j];
220cdf0e10cSrcweir                 final FolderFilter apiFilter = new FolderFilter("unoapi");
221cdf0e10cSrcweir                 final File[] apiTree = qaFolder.listFiles(apiFilter);
222cdf0e10cSrcweir                 if (apiTree != null && apiTree.length > 0)
223cdf0e10cSrcweir                 {
224cdf0e10cSrcweir                     return true;
225cdf0e10cSrcweir                 }
226cdf0e10cSrcweir             }
227cdf0e10cSrcweir         }
228cdf0e10cSrcweir         return false;
229cdf0e10cSrcweir     }
230cdf0e10cSrcweir */
231cdf0e10cSrcweir 
getAllModuleCommand()232cdf0e10cSrcweir     private String[] getAllModuleCommand()
233cdf0e10cSrcweir     {
234cdf0e10cSrcweir         String[] checkModules;
235cdf0e10cSrcweir 
236cdf0e10cSrcweir         final String[] names = getModulesFromSourceRoot();
237cdf0e10cSrcweir         checkModules = getCheckModuleCommand(names);
238cdf0e10cSrcweir 
239cdf0e10cSrcweir         return checkModules;
240cdf0e10cSrcweir     }
241cdf0e10cSrcweir 
getCheckModuleCommand(String[] names)242cdf0e10cSrcweir     private String[] getCheckModuleCommand(String[] names)
243cdf0e10cSrcweir     {
244cdf0e10cSrcweir         String[] checkModules;
245cdf0e10cSrcweir         checkModules = new String[names.length];
246cdf0e10cSrcweir 
247cdf0e10cSrcweir         for (int i = 0; i < names.length; i++)
248cdf0e10cSrcweir         {
249cdf0e10cSrcweir             // if a module is not added to a cws it contains a dot in its name (forms.lnk)
250cdf0e10cSrcweir             if (names[i].indexOf(".") != -1)
251cdf0e10cSrcweir             {
252cdf0e10cSrcweir                 checkModules[i] = "checkModule(" + names[i].substring(0, names[i].indexOf(".")) + ")";
253cdf0e10cSrcweir             }
254cdf0e10cSrcweir             else
255cdf0e10cSrcweir             {
256cdf0e10cSrcweir                 checkModules[i] = "checkModule(" + names[i] + ")";
257cdf0e10cSrcweir             }
258cdf0e10cSrcweir         }
259cdf0e10cSrcweir         return checkModules;
260cdf0e10cSrcweir     }
261cdf0e10cSrcweir 
getDmakeCommands(String sUnoapi)262cdf0e10cSrcweir     private String[] getDmakeCommands(String sUnoapi)
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir 
265cdf0e10cSrcweir         String[] cmdLines = null;
266cdf0e10cSrcweir         final String platform = (String) param.get(PropertyName.OPERATING_SYSTEM);
267cdf0e10cSrcweir         log.println("prepare command for platform " + platform);
268cdf0e10cSrcweir 
269cdf0e10cSrcweir         if (platform.equals(PropertyName.WNTMSCI))
270cdf0e10cSrcweir         {
271cdf0e10cSrcweir             if (param.getBool(PropertyName.CYGWIN))
272cdf0e10cSrcweir             {
273cdf0e10cSrcweir                 // cygwin stuff
274cdf0e10cSrcweir                 cmdLines = new String[]
275cdf0e10cSrcweir                         {
276cdf0e10cSrcweir                             "cd `cygpath '" + sUnoapi.replaceAll("\\\\", "\\\\\\\\") + "'`",
277cdf0e10cSrcweir                             "dmake"
278cdf0e10cSrcweir                         };
279cdf0e10cSrcweir             }
280cdf0e10cSrcweir             else
281cdf0e10cSrcweir             {
282cdf0e10cSrcweir                 // old 4NT
283cdf0e10cSrcweir                 cmdLines = new String[]
284cdf0e10cSrcweir                         {
285cdf0e10cSrcweir                             "cdd " + sUnoapi,
286cdf0e10cSrcweir                             "dmake"
287cdf0e10cSrcweir                         };
288cdf0e10cSrcweir             }
289cdf0e10cSrcweir         }
290cdf0e10cSrcweir         else
291cdf0e10cSrcweir         {
292cdf0e10cSrcweir             // unix
293cdf0e10cSrcweir             cmdLines = new String[]
294cdf0e10cSrcweir                     {
295cdf0e10cSrcweir                         "cd " + sUnoapi,
296cdf0e10cSrcweir                         "dmake"
297cdf0e10cSrcweir                     };
298cdf0e10cSrcweir         }
299cdf0e10cSrcweir         return cmdLines;
300cdf0e10cSrcweir     }
301cdf0e10cSrcweir 
getCwsModuleCommand()302cdf0e10cSrcweir     private String[] getCwsModuleCommand()
303cdf0e10cSrcweir     {
304cdf0e10cSrcweir         String[] checkModules;
305cdf0e10cSrcweir         final String version = (String) param.get(PropertyName.VERSION);
306cdf0e10cSrcweir         String[] names = null;
307cdf0e10cSrcweir         if (version.startsWith("cws_"))
308cdf0e10cSrcweir         {
309cdf0e10cSrcweir             try
310cdf0e10cSrcweir             {
311cdf0e10cSrcweir                 // cws version: all added modules must be tested
312cdf0e10cSrcweir                 final String cws = version.substring(4, version.length());
313cdf0e10cSrcweir                 final CwsDataExchangeImpl cde = new CwsDataExchangeImpl(cws, param, log);
314cdf0e10cSrcweir                 final ArrayList addedModules = cde.getModules();
315cdf0e10cSrcweir 
316cdf0e10cSrcweir                 final ArrayList moduleNames = new ArrayList();
317cdf0e10cSrcweir                 Iterator iterator = addedModules.iterator();
318cdf0e10cSrcweir                 while (iterator.hasNext())
319cdf0e10cSrcweir                 {
320cdf0e10cSrcweir                     String sModuleName = (String) iterator.next();
321cdf0e10cSrcweir                     // String sFilename = mSRC_ROOT; //  + File.separator + sModuleName;
322cdf0e10cSrcweir                     // final File sourceRoot = new File(sFilename);
323cdf0e10cSrcweir                     if (doesQaUnoApiFolderExist(mSRC_ROOT, sModuleName))
324cdf0e10cSrcweir                     {
325cdf0e10cSrcweir                         moduleNames.add(sModuleName);
326cdf0e10cSrcweir                     }
327cdf0e10cSrcweir                 }
328cdf0e10cSrcweir                 names = (String[]) moduleNames.toArray(new String[0]);
329cdf0e10cSrcweir             }
330cdf0e10cSrcweir             catch (ParameterNotFoundException ex)
331cdf0e10cSrcweir             {
332cdf0e10cSrcweir                 this.failed(ex.toString(), false);
333cdf0e10cSrcweir             }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 
336cdf0e10cSrcweir         }
337cdf0e10cSrcweir         else
338cdf0e10cSrcweir         {
339cdf0e10cSrcweir             // major version: all modules must be tested
340cdf0e10cSrcweir             names = getModulesFromSourceRoot();
341cdf0e10cSrcweir         }
342cdf0e10cSrcweir         checkModules = getCheckModuleCommand(names);
343cdf0e10cSrcweir 
344cdf0e10cSrcweir         return checkModules;
345cdf0e10cSrcweir     }
346cdf0e10cSrcweir 
getDefinedModuleCommand(String module)347cdf0e10cSrcweir     private String[] getDefinedModuleCommand(String module)
348cdf0e10cSrcweir     {
349cdf0e10cSrcweir         String[] checkModules = null;
350cdf0e10cSrcweir         // list of modules to test: (sw,sc,sd)
351cdf0e10cSrcweir         if (module.indexOf(",") != -1)
352cdf0e10cSrcweir         {
353cdf0e10cSrcweir             final String[] names = module.split(",");
354cdf0e10cSrcweir             checkModules = new String[names.length];
355cdf0e10cSrcweir             for (int i = 0; i < names.length; i++)
356cdf0e10cSrcweir             {
357cdf0e10cSrcweir                 final String moduleName = names[i].trim();
358cdf0e10cSrcweir 
359cdf0e10cSrcweir //                File sourceRoot = new File(mSRC_ROOT + File.separator + moduleName);
360cdf0e10cSrcweir //                if (!sourceRoot.exists())
361cdf0e10cSrcweir //                {
362cdf0e10cSrcweir //                    sourceRoot = new File(mSRC_ROOT + File.separator + moduleName + ".lnk");
363cdf0e10cSrcweir //                }
364cdf0e10cSrcweir 
365cdf0e10cSrcweir                 if (doesQaUnoApiFolderExist(mSRC_ROOT, moduleName))
366cdf0e10cSrcweir                 {
367cdf0e10cSrcweir                     checkModules[i] = "checkModule(" + moduleName + ")";
368cdf0e10cSrcweir                 }
369cdf0e10cSrcweir             }
370cdf0e10cSrcweir         }
371cdf0e10cSrcweir         else
372cdf0e10cSrcweir         {
373cdf0e10cSrcweir //            File sourceRoot = new File(mSRC_ROOT + File.separator + module);
374cdf0e10cSrcweir //            if (!sourceRoot.exists())
375cdf0e10cSrcweir //            {
376cdf0e10cSrcweir //                sourceRoot = new File(mSRC_ROOT + File.separator + module + ".lnk");
377cdf0e10cSrcweir //            }
378cdf0e10cSrcweir             if (doesQaUnoApiFolderExist(mSRC_ROOT, module))
379cdf0e10cSrcweir             {
380cdf0e10cSrcweir                 checkModules = new String[]
381cdf0e10cSrcweir                         {
382cdf0e10cSrcweir                             "checkModule(" + module + ")"
383cdf0e10cSrcweir                         };
384cdf0e10cSrcweir             }
385cdf0e10cSrcweir         }
386cdf0e10cSrcweir         return checkModules;
387cdf0e10cSrcweir     }
388cdf0e10cSrcweir 
getModulePath(String module)389cdf0e10cSrcweir     private String getModulePath(String module)
390cdf0e10cSrcweir     {
391cdf0e10cSrcweir 
392cdf0e10cSrcweir         // String sUnoapi = null;
393cdf0e10cSrcweir         // final String sep = System.getProperty("file.separator");
394cdf0e10cSrcweir         // final File srcRoot = new File(mSRC_ROOT);
395cdf0e10cSrcweir 
396cdf0e10cSrcweir         // final FolderFilter qaFilter = new FolderFilter(module);
397cdf0e10cSrcweir         // final File[] moduleTree = srcRoot.listFiles(qaFilter);
398cdf0e10cSrcweir //        if (moduleTree != null)
399cdf0e10cSrcweir //        {
400cdf0e10cSrcweir //            if (mDebug)
401cdf0e10cSrcweir //            {
402cdf0e10cSrcweir //                log.println("moduleTree length:" + moduleTree.length);
403cdf0e10cSrcweir //                log.println("moduleTree: " + moduleTree[0].getAbsolutePath());
404cdf0e10cSrcweir //            }
405cdf0e10cSrcweir //            if (moduleTree != null)
406cdf0e10cSrcweir //            {
407cdf0e10cSrcweir //                sUnoapi = moduleTree[0].getAbsolutePath() + sep + "qa" + sep + "unoapi";
408cdf0e10cSrcweir //            }
409cdf0e10cSrcweir //        }
410cdf0e10cSrcweir         String sUnoapi = getQaUnoApiPath(mSRC_ROOT, module);
411cdf0e10cSrcweir         return sUnoapi;
412cdf0e10cSrcweir     }
413cdf0e10cSrcweir 
414cdf0e10cSrcweir     /**
415a3415cdeSmseidel     Some modules contain more than one project. This method translates given project parameter to the
416a3415cdeSmseidel      *  corresponding module name.
417cdf0e10cSrcweir      *
418cdf0e10cSrcweir      * fwk -> framework
419cdf0e10cSrcweir      * fwl -> framework
420cdf0e10cSrcweir      * sch -> chart2
421cdf0e10cSrcweir      * lnn -> lingu
422cdf0e10cSrcweir      * lng -> linguistic
423cdf0e10cSrcweir      * sfx -> sfx2
424cdf0e10cSrcweir      * sm -> starmath
425cdf0e10cSrcweir      */
getTranslatedNames(String module)426cdf0e10cSrcweir     private String getTranslatedNames(String module)
427cdf0e10cSrcweir     {
428cdf0e10cSrcweir 
429cdf0e10cSrcweir         final HashMap aModuleHashMap = new HashMap();
430cdf0e10cSrcweir 
431cdf0e10cSrcweir         aModuleHashMap.put("fwk", "framework");
432cdf0e10cSrcweir         aModuleHashMap.put("fwl", "framework");
433cdf0e10cSrcweir         aModuleHashMap.put("sch", "chart2");
434cdf0e10cSrcweir         aModuleHashMap.put("lnn", "lingu");
435cdf0e10cSrcweir         aModuleHashMap.put("lng", "linguistic");
436cdf0e10cSrcweir         aModuleHashMap.put("sfx", "sfx2");
437cdf0e10cSrcweir         aModuleHashMap.put("sm", "starmath");
438cdf0e10cSrcweir 
439a3415cdeSmseidel         // it could the that the parameter looks like "fwk,fwl". This results in double "framework,framework".
440cdf0e10cSrcweir         // The following loop correct this to only one "framework"
441cdf0e10cSrcweir 
442cdf0e10cSrcweir         final Set keys = aModuleHashMap.keySet();
443cdf0e10cSrcweir         final Iterator iterator = keys.iterator();
444cdf0e10cSrcweir         while (iterator.hasNext())
445cdf0e10cSrcweir         {
446cdf0e10cSrcweir 
447cdf0e10cSrcweir             final String key = (String) iterator.next();
448cdf0e10cSrcweir             final String value = (String) aModuleHashMap.get(key);
449cdf0e10cSrcweir 
450cdf0e10cSrcweir             module = module.replaceAll(key, value);
451cdf0e10cSrcweir 
452cdf0e10cSrcweir             final int count = module.split(value).length;
453cdf0e10cSrcweir             if (count > 2)
454cdf0e10cSrcweir             {
455cdf0e10cSrcweir                 for (int i = 2; i < count; i++)
456cdf0e10cSrcweir                 {
457cdf0e10cSrcweir                     module.replaceFirst("," + value, "");
458cdf0e10cSrcweir                 }
459cdf0e10cSrcweir 
460cdf0e10cSrcweir             }
461cdf0e10cSrcweir         }
462cdf0e10cSrcweir         return module;
463cdf0e10cSrcweir     }
464cdf0e10cSrcweir 
verifyOutput(String output)465cdf0e10cSrcweir     private boolean verifyOutput(String output)
466cdf0e10cSrcweir     {
467cdf0e10cSrcweir 
468cdf0e10cSrcweir         log.println("verify output...");
469cdf0e10cSrcweir         boolean ok = false;
470cdf0e10cSrcweir         final String[] outs = output.split("\n");
471cdf0e10cSrcweir 
472cdf0e10cSrcweir         for (int i = 0; i < outs.length; i++)
473cdf0e10cSrcweir         {
474cdf0e10cSrcweir             final String line = outs[i];
475cdf0e10cSrcweir             if (line.matches("[0-9]+? of [0-9]+? tests failed"))
476cdf0e10cSrcweir             {
477*850627aeSJohn Bampton                 log.println("matched line: " + line);
478cdf0e10cSrcweir                 if (line.matches("0 of [0-9]+? tests failed"))
479cdf0e10cSrcweir                 {
480cdf0e10cSrcweir                     ok = true;
481cdf0e10cSrcweir                     log.println("Module passed OK");
482cdf0e10cSrcweir                 }
483cdf0e10cSrcweir                 else
484cdf0e10cSrcweir                 {
485cdf0e10cSrcweir                     log.println("Module passed FAILED");
486cdf0e10cSrcweir                 }
487cdf0e10cSrcweir             }
488cdf0e10cSrcweir         }
489cdf0e10cSrcweir 
490cdf0e10cSrcweir         if (!ok)
491cdf0e10cSrcweir         {
492cdf0e10cSrcweir             log.println("ERROR: could not find '0 of [0-9]+? tests failed' in output");
493cdf0e10cSrcweir         }
494cdf0e10cSrcweir 
495cdf0e10cSrcweir         return ok;
496cdf0e10cSrcweir     }
497cdf0e10cSrcweir 
getModulesFromSourceRoot()498cdf0e10cSrcweir     private String[] getModulesFromSourceRoot()
499cdf0e10cSrcweir     {
500cdf0e10cSrcweir         log.println("**** run module tests over all modules ****");
501cdf0e10cSrcweir 
502*850627aeSJohn Bampton         log.println("search for qa/unoapi folders in all modules based in ");
503cdf0e10cSrcweir         log.println("'" + mSRC_ROOT + "'");
504cdf0e10cSrcweir 
505cdf0e10cSrcweir         final ArrayList moduleNames = new ArrayList();
506cdf0e10cSrcweir         final File sourceRoot = new File(mSRC_ROOT);
507cdf0e10cSrcweir         final File[] sourceTree = sourceRoot.listFiles();
508cdf0e10cSrcweir 
509cdf0e10cSrcweir //        assure("Could not find any files in SOURCE_ROOT=" + mSRC_ROOT, sourceTree != null, false);
510cdf0e10cSrcweir 
511cdf0e10cSrcweir         for (int i = 0; i < sourceTree.length; i++)
512cdf0e10cSrcweir         {
513cdf0e10cSrcweir             final File moduleName = sourceTree[i];
514cdf0e10cSrcweir             String sModuleName = moduleName.getName(); // (String)moduleNames.get(i);
515cdf0e10cSrcweir             if (doesQaUnoApiFolderExist(mSRC_ROOT, sModuleName))
516cdf0e10cSrcweir             {
517cdf0e10cSrcweir                 // addIfQaUnoApiFolderExist(moduleName, moduleNames);
518cdf0e10cSrcweir                 moduleNames.add(sModuleName);
519cdf0e10cSrcweir             }
520cdf0e10cSrcweir         }
521cdf0e10cSrcweir 
522cdf0e10cSrcweir         final String[] names = (String[]) moduleNames.toArray(new String[0]);
523cdf0e10cSrcweir         return names;
524cdf0e10cSrcweir     }
525cdf0e10cSrcweir 
526cdf0e10cSrcweir     /**
527cdf0e10cSrcweir      * This function generates a list of modules to test and call <CODE>checkModule</CODE> for every module.
528cdf0e10cSrcweir      * <p>
529cdf0e10cSrcweir      *
530cdf0e10cSrcweir      * @param module names to test. This could be
531cdf0e10cSrcweir      * <ul>
532cdf0e10cSrcweir      * <li>a comma separated list of modules like 'sw,sc,sd'</li>
533cdf0e10cSrcweir      * <li>'all' to test all modules </li>
534cdf0e10cSrcweir      * <li>'auto' to check only modules which are added to the ChildWorkSpace</li>
535cdf0e10cSrcweir      * </ul>
536cdf0e10cSrcweir      */
module(String module)537cdf0e10cSrcweir     public void module(String module)
538cdf0e10cSrcweir     {
539cdf0e10cSrcweir 
540cdf0e10cSrcweir         String[] checkModules;
541cdf0e10cSrcweir         final ComplexDescGetter desc = new ComplexDescGetter();
542cdf0e10cSrcweir         DescEntry entry = null;
543cdf0e10cSrcweir         module = module.trim();
544cdf0e10cSrcweir 
545cdf0e10cSrcweir         /*
546cdf0e10cSrcweir         all: check all modules which contains a qa/unoapi folder
547cdf0e10cSrcweir         auto: check all modules which contains a qa/unoapi folder except the module is not added
548cdf0e10cSrcweir          */
549cdf0e10cSrcweir         if (module.equals("all"))
550cdf0e10cSrcweir         {
551cdf0e10cSrcweir             checkModules = getAllModuleCommand();
552cdf0e10cSrcweir         }
553cdf0e10cSrcweir         else if (module.equals("auto"))
554cdf0e10cSrcweir         {
555cdf0e10cSrcweir             checkModules = getCwsModuleCommand();
556cdf0e10cSrcweir         }
557cdf0e10cSrcweir         else
558cdf0e10cSrcweir         {
559cdf0e10cSrcweir             module = getTranslatedNames(module);
560cdf0e10cSrcweir             checkModules = getDefinedModuleCommand(module);
561cdf0e10cSrcweir         }
562cdf0e10cSrcweir 
563cdf0e10cSrcweir         if (checkModules != null && checkModules.length > 0)
564cdf0e10cSrcweir         {
565cdf0e10cSrcweir 
566cdf0e10cSrcweir             entry = desc.createTestDesc("complex.unoapi.CheckModuleAPI", "complex.unoapi.CheckModuleAPI", checkModules,
567cdf0e10cSrcweir                     log);
568cdf0e10cSrcweir 
569cdf0e10cSrcweir             final java_complex complex = new java_complex();
570cdf0e10cSrcweir 
571cdf0e10cSrcweir             log.println("********** start test *************");
572cdf0e10cSrcweir             final boolean result = complex.executeTest(param, new DescEntry[] { entry });
573cdf0e10cSrcweir             log.println("********** end test *************");
574cdf0e10cSrcweir 
575cdf0e10cSrcweir             assure("CheckModuleAPI.module(" + module + ") PASSED.FAILED", result);
576cdf0e10cSrcweir 
577cdf0e10cSrcweir         }
578cdf0e10cSrcweir         else
579cdf0e10cSrcweir         {
580cdf0e10cSrcweir             log.println("No modules containing qa/unoapi folder found => OK");
581cdf0e10cSrcweir             state = true;
582cdf0e10cSrcweir         }
583cdf0e10cSrcweir 
584cdf0e10cSrcweir         setUnoApiCwsStatus(state);
585cdf0e10cSrcweir 
586cdf0e10cSrcweir     }
587cdf0e10cSrcweir 
setUnoApiCwsStatus(boolean status)588cdf0e10cSrcweir     private void setUnoApiCwsStatus(boolean status)
589cdf0e10cSrcweir     {
590cdf0e10cSrcweir 
591cdf0e10cSrcweir         if (!param.getBool(PropertyName.NO_CWS_ATTACH))
592cdf0e10cSrcweir         {
593cdf0e10cSrcweir 
594cdf0e10cSrcweir             final String version = (String) param.get(PropertyName.VERSION);
595cdf0e10cSrcweir             if (version.startsWith("cws_"))
596cdf0e10cSrcweir             {
597cdf0e10cSrcweir                 try
598cdf0e10cSrcweir                 {
599cdf0e10cSrcweir 
600cdf0e10cSrcweir                     // cws version: all added modules must be tested
601cdf0e10cSrcweir                     final String cws = version.substring(4, version.length());
602cdf0e10cSrcweir                     final CwsDataExchangeImpl cde = new CwsDataExchangeImpl(cws, param, log);
603cdf0e10cSrcweir                     cde.setUnoApiCwsStatus(status);
604cdf0e10cSrcweir                 }
605cdf0e10cSrcweir                 catch (ParameterNotFoundException ex)
606cdf0e10cSrcweir                 {
607*850627aeSJohn Bampton                     log.println("ERROR: could not write status to EIS database: " + ex.toString());
608cdf0e10cSrcweir                 }
609cdf0e10cSrcweir             }
610cdf0e10cSrcweir         }
611cdf0e10cSrcweir     }
612cdf0e10cSrcweir 
getTestMethodNames()613cdf0e10cSrcweir     public String[] getTestMethodNames()
614cdf0e10cSrcweir     {
615cdf0e10cSrcweir         return new String[]
616cdf0e10cSrcweir                 {
617cdf0e10cSrcweir                     "module(all)"
618cdf0e10cSrcweir                 };
619cdf0e10cSrcweir     }
620cdf0e10cSrcweir 
621cdf0e10cSrcweir //    class _FolderFilter implements FileFilter
622cdf0e10cSrcweir //    {
623cdf0e10cSrcweir //
624cdf0e10cSrcweir //        private String mFolderName;
625cdf0e10cSrcweir //
626cdf0e10cSrcweir //        public FolderFilter(String folderName)
627cdf0e10cSrcweir //        {
628cdf0e10cSrcweir //            mFolderName = folderName;
629cdf0e10cSrcweir //        }
630cdf0e10cSrcweir //
631cdf0e10cSrcweir //        public boolean accept_(File pathname)
632cdf0e10cSrcweir //        {
633cdf0e10cSrcweir //
634cdf0e10cSrcweir //            boolean found = false;
635cdf0e10cSrcweir //            if (pathname.isDirectory())
636cdf0e10cSrcweir //            {
637cdf0e10cSrcweir //                if (pathname.getName().equals(mFolderName))
638cdf0e10cSrcweir //                {
639cdf0e10cSrcweir //                    found = true;
640cdf0e10cSrcweir //                }
641cdf0e10cSrcweir //                else if (pathname.getName().equals(mFolderName + ".lnk"))
642cdf0e10cSrcweir //                {
643cdf0e10cSrcweir //                    found = true;
644cdf0e10cSrcweir //                }
645cdf0e10cSrcweir //            }
646cdf0e10cSrcweir //            return found;
647cdf0e10cSrcweir //        }
648cdf0e10cSrcweir //    }
649cdf0e10cSrcweir }
650