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