merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / tests / java / complex / unoapi / CheckModuleAPI.java
blob85d4c6b3544563bc5716b8f0c1e4d7fd8f8ceed9
1 /*
2 * ************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * Copyright 2008 by Sun Microsystems, Inc.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * $RCSfile: CheckModuleAPI.java,v $
11 * $Revision: 1.6 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 * **********************************************************************
32 /** complex tests to check the UNO-API
33 **/
34 package complex.unoapi;
36 // imports
37 import base.java_complex;
38 import complexlib.ComplexTestCase;
39 import helper.OfficeProvider;
40 import helper.ParameterNotFoundException;
41 import helper.ProcessHandler;
42 import com.sun.star.lang.XMultiServiceFactory;
43 import helper.BuildEnvTools;
44 import helper.ComplexDescGetter;
45 import helper.CwsDataExchangeImpl;
46 import java.io.File;
47 // import java.io.FileFilter;
48 import java.util.ArrayList;
49 import java.util.HashMap;
50 import java.util.Iterator;
51 import java.util.Set;
52 import share.DescEntry;
53 import util.PropertyName;
54 import util.utils;
56 /**
57 * This Complex Test will test the UNO-API by calling dmake in <B>$MODULE</B>/qa/unoapi<p>
58 * This test depends on some requirments:
59 * The <B>TestJob</B> is <b>-o complex.unoapi.CheckModuleAPI::module(<CODE>MODULE</CODE>)</b><p> where <CODE>MODULE</CODE>
60 * could be the following:<p>
61 * <ul>
62 * <li><b>all</b> iterates over <CODE>SRC_ROOT</CODE> and call <CODE>dmake</CODE> in all qa/unoapi folder</li><p>
63 * <li><b>$module</b> call dmake in $module/qa/unoapi folder</li><p>
64 * <li><b>$module1,$module2,...</b> call dmake in $module1/qa/unoapi folder then in $module2/qa/unoapi folder and so on</li><p>
65 * </ul><p>
67 * Also you have to fill the following parameter:
68 * <ul>
69 * <li><b>SHELL</b>: fill this parameter with a shell</li>
70 * </ul>
73 public class CheckModuleAPI extends ComplexTestCase
76 private static String mSRC_ROOT = null;
77 private static boolean mIsInitialized = false;
78 private final static boolean mContinue = true;
79 private static boolean mDebug = false;
80 private static BuildEnvTools bet = null;
82 /**
83 * Initialize the test environment.
84 * This method checks for all neccesarry parameter and exit if not all parameter are set.
86 * Further this method starts an office instance and gets the office some more time to start. This is because
87 * some freshly installed offices don not have such a user tree. The office will create it on its first start,
88 * but this will take some time.
89 * Note: This funktionality is only reasonable with parameter <CODE>-noOffice true</CODE>
91 public void before()
94 if (!mIsInitialized)
96 mIsInitialized = true;
98 try
101 bet = new BuildEnvTools(param, log);
104 catch (ParameterNotFoundException ex)
106 this.failed(ex.toString(), false);
109 mSRC_ROOT = bet.getSrcRoot();
111 mDebug = param.getBool(PropertyName.DEBUG_IS_ACTIVE);
117 * let API tests run.
118 * @param module
120 public void checkModule(String module)
122 log.println(utils.getDateTime() + ": start testing module '" + module + "'");
124 log.println(utils.getDateTime() + "start new Office instance...");
126 // TODO: is Office started with this program?
127 final OfficeProvider officeProvider = new OfficeProvider();
129 log.println(utils.getDateTime() + "Receiving the ServiceManager of the Office ");
130 final XMultiServiceFactory msf = (XMultiServiceFactory) officeProvider.getManager(param);
131 assure("couldnot get ServiceFarcotry", msf != null, mContinue);
132 param.put("ServiceFactory", msf);
134 final String sep = System.getProperty("file.separator");
135 final String sUnoapi = getModulePath(module);
136 final File fUnoapi = new File(sUnoapi);
137 final String sMakeFile = sUnoapi + sep + "makefile.mk";
138 final File fMakeFile = new File(sMakeFile);
139 assure("ERROR: could not find makefile: '" + sMakeFile + "'", fMakeFile.exists(), mContinue);
141 final String[] commands = getDmakeCommands(sUnoapi);
143 final ProcessHandler procHdl = bet.runCommandsInEnvironmentShell(commands, fUnoapi, 0);
144 log.println("exit code of dmake: " + procHdl.getExitCode());
145 String test = procHdl.getOutputText();
146 test += procHdl.getErrorText();
147 // if (mDebug) {
148 // log.println("---> Output of dmake:");
149 // log.println(procHdl.getOutputText());
150 // log.println("<--- Output of dmake:");
151 // log.println("---> Error output of dmake:");
152 // log.println(procHdl.getErrorText());
153 // log.println("<--- Error output of dmake:");
154 // }
155 assure("module '" + module + "' failed", verifyOutput(test), mContinue);
156 log.println(utils.getDateTime() + " module '" + module + "': kill existing office...");
158 // TODO: how to check if the office is not started with this process.
159 boolean bNoOffice = param.getBool("NoOffice");
160 if (!bNoOffice)
164 officeProvider.closeExistingOffice(param, true);
166 catch (java.lang.UnsatisfiedLinkError exception)
168 log.println("Office seems not to be running");
172 private String getQaUnoApiPath(String srcRoot, String _sModul)
174 File aFile = new File(srcRoot);
175 if (!aFile.exists())
177 System.out.println("ERROR: srcRoot '" + srcRoot + "' does not exist.");
178 return null;
180 String sModulePath = srcRoot;
181 sModulePath += File.separator;
182 sModulePath += _sModul;
184 File aModulePath = new File(sModulePath);
185 if (! aModulePath.exists())
187 aModulePath = new File(sModulePath + ".lnk");
188 if (! aModulePath.exists())
190 aModulePath = new File(sModulePath + ".link");
191 if (! aModulePath.exists())
193 // module does not exist.
194 return null;
198 sModulePath = aModulePath.getAbsolutePath();
199 sModulePath += File.separator;
200 sModulePath += "qa";
201 sModulePath += File.separator;
202 sModulePath += "unoapi";
203 File aModulePathQaUnoApi = new File(sModulePath);
204 if (aModulePathQaUnoApi.exists())
206 return aModulePathQaUnoApi.getAbsolutePath();
208 return null;
210 private boolean doesQaUnoApiFolderExist(String srcRoot, String _sModul)
212 if (getQaUnoApiPath(srcRoot, _sModul) != null)
214 return true;
216 return false;
219 private boolean doesQaUnoApiFolderExist(File srcRoot)
221 final FolderFilter qaFilter = new FolderFilter("qa");
222 final File[] qaTree = srcRoot.listFiles(qaFilter);
223 if (qaTree != null)
225 for (int j = 0; j < qaTree.length; j++)
227 final File qaFolder = qaTree[j];
228 final FolderFilter apiFilter = new FolderFilter("unoapi");
229 final File[] apiTree = qaFolder.listFiles(apiFilter);
230 if (apiTree != null && apiTree.length > 0)
232 return true;
236 return false;
240 private String[] getAllModuleCommand()
242 String[] checkModules;
244 final String[] names = getModulesFromSourceRoot();
245 checkModules = getCheckModuleCommand(names);
247 return checkModules;
250 private String[] getCheckModuleCommand(String[] names)
252 String[] checkModules;
253 checkModules = new String[names.length];
255 for (int i = 0; i < names.length; i++)
257 // if a module is not added to a cws it contains a dot in its name (forms.lnk)
258 if (names[i].indexOf(".") != -1)
260 checkModules[i] = "checkModule(" + names[i].substring(0, names[i].indexOf(".")) + ")";
262 else
264 checkModules[i] = "checkModule(" + names[i] + ")";
267 return checkModules;
270 private String[] getDmakeCommands(String sUnoapi)
273 String[] cmdLines = null;
274 final String platform = (String) param.get(PropertyName.OPERATING_SYSTEM);
275 log.println("prepare command for platform " + platform);
277 if (platform.equals(PropertyName.WNTMSCI))
279 if (param.getBool(PropertyName.CYGWIN))
281 // cygwin stuff
282 cmdLines = new String[]
284 "cd `cygpath '" + sUnoapi.replaceAll("\\\\", "\\\\\\\\") + "'`",
285 "dmake"
288 else
290 // old 4NT
291 cmdLines = new String[]
293 "cdd " + sUnoapi,
294 "dmake"
298 else
300 // unix
301 cmdLines = new String[]
303 "cd " + sUnoapi,
304 "dmake"
307 return cmdLines;
310 private String[] getCwsModuleCommand()
312 String[] checkModules;
313 final String version = (String) param.get(PropertyName.VERSION);
314 String[] names = null;
315 if (version.startsWith("cws_"))
319 // cws version: all added modules must be tested
320 final String cws = version.substring(4, version.length());
321 final CwsDataExchangeImpl cde = new CwsDataExchangeImpl(cws, param, log);
322 final ArrayList addedModules = cde.getModules();
324 final ArrayList moduleNames = new ArrayList();
325 Iterator iterator = addedModules.iterator();
326 while (iterator.hasNext())
328 String sModuleName = (String) iterator.next();
329 // String sFilename = mSRC_ROOT; // + File.separator + sModuleName;
330 // final File sourceRoot = new File(sFilename);
331 if (doesQaUnoApiFolderExist(mSRC_ROOT, sModuleName))
333 moduleNames.add(sModuleName);
336 names = (String[]) moduleNames.toArray(new String[0]);
338 catch (ParameterNotFoundException ex)
340 this.failed(ex.toString(), false);
345 else
347 // major version: all modules must be tested
348 names = getModulesFromSourceRoot();
350 checkModules = getCheckModuleCommand(names);
352 return checkModules;
355 private String[] getDefinedModuleCommand(String module)
357 String[] checkModules = null;
358 // list of modules to test: (sw,sc,sd)
359 if (module.indexOf(",") != -1)
361 final String[] names = module.split(",");
362 checkModules = new String[names.length];
363 for (int i = 0; i < names.length; i++)
365 final String moduleName = names[i].trim();
367 // File sourceRoot = new File(mSRC_ROOT + File.separator + moduleName);
368 // if (!sourceRoot.exists())
369 // {
370 // sourceRoot = new File(mSRC_ROOT + File.separator + moduleName + ".lnk");
371 // }
373 if (doesQaUnoApiFolderExist(mSRC_ROOT, moduleName))
375 checkModules[i] = "checkModule(" + moduleName + ")";
379 else
381 // File sourceRoot = new File(mSRC_ROOT + File.separator + module);
382 // if (!sourceRoot.exists())
383 // {
384 // sourceRoot = new File(mSRC_ROOT + File.separator + module + ".lnk");
385 // }
386 if (doesQaUnoApiFolderExist(mSRC_ROOT, module))
388 checkModules = new String[]
390 "checkModule(" + module + ")"
394 return checkModules;
397 private String getModulePath(String module)
400 // String sUnoapi = null;
401 // final String sep = System.getProperty("file.separator");
402 // final File srcRoot = new File(mSRC_ROOT);
404 // final FolderFilter qaFilter = new FolderFilter(module);
405 // final File[] moduleTree = srcRoot.listFiles(qaFilter);
406 // if (moduleTree != null)
407 // {
408 // if (mDebug)
409 // {
410 // log.println("moduleTree length:" + moduleTree.length);
411 // log.println("moduleTree: " + moduleTree[0].getAbsolutePath());
412 // }
413 // if (moduleTree != null)
414 // {
415 // sUnoapi = moduleTree[0].getAbsolutePath() + sep + "qa" + sep + "unoapi";
416 // }
417 // }
418 String sUnoapi = getQaUnoApiPath(mSRC_ROOT, module);
419 return sUnoapi;
423 Some modules contains more the one project. This methods translates given project paramater to the
424 * correspind module name.
426 * fwk -> framework
427 * fwl -> framework
428 * sch -> chart2
429 * sysmgr1 -> configmgr
430 * cfgmgr2 -> configmgr
431 * lnn -> lingu
432 * lng -> linguistic
433 * sfx -> sfx2
434 * sm -> starmath
436 private String getTranslatedNames(String module)
439 final HashMap aModuleHashMap = new HashMap();
441 aModuleHashMap.put("fwk", "framework");
442 aModuleHashMap.put("fwl", "framework");
443 aModuleHashMap.put("sch", "chart2");
444 aModuleHashMap.put("sysmgr1", "configmgr");
445 aModuleHashMap.put("cfgmag2", "configmgr");
446 aModuleHashMap.put("lnn", "lingu");
447 aModuleHashMap.put("lng", "linguistic");
448 aModuleHashMap.put("sfx", "sfx2");
449 aModuleHashMap.put("sm", "starmath");
451 // it could the that the parameter looks like "fwk,fwl". This results in double "famework,framework".
452 // The following loop correct this to only one "framework"
454 final Set keys = aModuleHashMap.keySet();
455 final Iterator iterator = keys.iterator();
456 while (iterator.hasNext())
459 final String key = (String) iterator.next();
460 final String value = (String) aModuleHashMap.get(key);
462 module = module.replaceAll(key, value);
464 final int count = module.split(value).length;
465 if (count > 2)
467 for (int i = 2; i < count; i++)
469 module.replaceFirst("," + value, "");
474 return module;
477 private boolean verifyOutput(String output)
480 log.println("verify output...");
481 boolean ok = false;
482 final String[] outs = output.split("\n");
484 for (int i = 0; i < outs.length; i++)
486 final String line = outs[i];
487 if (line.matches("[0-9]+? of [0-9]+? tests failed"))
489 log.println("mached line: " + line);
490 if (line.matches("0 of [0-9]+? tests failed"))
492 ok = true;
493 log.println("Module passed OK");
495 else
497 log.println("Module passed FAILED");
502 if (!ok)
504 log.println("ERROR: could not find '0 of [0-9]+? tests failed' in output");
507 return ok;
510 private String[] getModulesFromSourceRoot()
512 log.println("**** run module tests over all modules ****");
514 log.println("search for qa/unoapi foldres in all modules based in ");
515 log.println("'" + mSRC_ROOT + "'");
517 final ArrayList moduleNames = new ArrayList();
518 final File sourceRoot = new File(mSRC_ROOT);
519 final File[] sourceTree = sourceRoot.listFiles();
521 // assure("Could not find any files in SOURCE_ROOT=" + mSRC_ROOT, sourceTree != null, false);
523 for (int i = 0; i < sourceTree.length; i++)
525 final File moduleName = sourceTree[i];
526 String sModuleName = moduleName.getName(); // (String)moduleNames.get(i);
527 if (doesQaUnoApiFolderExist(mSRC_ROOT, sModuleName))
529 // addIfQaUnoApiFolderExist(moduleName, moduleNames);
530 moduleNames.add(sModuleName);
534 final String[] names = (String[]) moduleNames.toArray(new String[0]);
535 return names;
539 * This function generates a list of modules to test and call <CODE>checkModule</CODE> for every module.
540 * <p>
542 * @param module names to test. This could be
543 * <ul>
544 * <li>a comma separated list of modules like 'sw,sc,sd'</li>
545 * <li>'all' to test all modules </li>
546 * <li>'auto' to check only modules which are added to the ChildWorkSpace</li>
547 * </ul>
549 public void module(String module)
552 String[] checkModules;
553 final ComplexDescGetter desc = new ComplexDescGetter();
554 DescEntry entry = null;
555 module = module.trim();
558 all: check all modules which contains a qa/unoapi folder
559 auto: check all modules which contains a qa/unoapi folder except the module is not added
561 if (module.equals("all"))
563 checkModules = getAllModuleCommand();
565 else if (module.equals("auto"))
567 checkModules = getCwsModuleCommand();
569 else
571 module = getTranslatedNames(module);
572 checkModules = getDefinedModuleCommand(module);
575 if (checkModules != null && checkModules.length > 0)
578 entry = desc.createTestDesc("complex.unoapi.CheckModuleAPI", "complex.unoapi.CheckModuleAPI", checkModules,
579 log);
581 final java_complex complex = new java_complex();
583 log.println("********** start test *************");
584 final boolean result = complex.executeTest(param, new DescEntry[] { entry });
585 log.println("********** end test *************");
587 assure("CheckModuleAPI.module(" + module + ") PASSED.FAILED", result);
590 else
592 log.println("No modules containing qa/unoapi folder found => OK");
593 state = true;
596 setUnoApiCwsStatus(state);
600 private void setUnoApiCwsStatus(boolean status)
603 if (!param.getBool(PropertyName.NO_CWS_ATTACH))
606 final String version = (String) param.get(PropertyName.VERSION);
607 if (version.startsWith("cws_"))
612 // cws version: all added modules must be tested
613 final String cws = version.substring(4, version.length());
614 final CwsDataExchangeImpl cde = new CwsDataExchangeImpl(cws, param, log);
615 cde.setUnoApiCwsStatus(status);
617 catch (ParameterNotFoundException ex)
619 log.println("ERROR: could not wirte status to EIS database: " + ex.toString());
625 public String[] getTestMethodNames()
627 return new String[]
629 "module(all)"
633 // class _FolderFilter implements FileFilter
634 // {
636 // private String mFolderName;
638 // public FolderFilter(String folderName)
639 // {
640 // mFolderName = folderName;
641 // }
643 // public boolean accept_(File pathname)
644 // {
646 // boolean found = false;
647 // if (pathname.isDirectory())
648 // {
649 // if (pathname.getName().equals(mFolderName))
650 // {
651 // found = true;
652 // }
653 // else if (pathname.getName().equals(mFolderName + ".lnk"))
654 // {
655 // found = true;
656 // }
657 // }
658 // return found;
659 // }
660 // }