merge the formfield patch from ooo-build
[ooovba.git] / testtools / source / cliversioning / runtests.cs
blob1ee56f18b973d8fddff906c4f3a5c942a5338279
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: runtests.cs,v $
10 * $Revision: 1.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 using System;
32 using System.Reflection;
33 using System.IO;
35 // __________ implementation ____________________________________
37 /** Create and modify a spreadsheet document.
39 namespace cliversion
41 public class RunTests
44 public static int Main(String[] args)
46 // System.Diagnostics.Debugger.Launch();
47 //get the path to the directory
48 string sLocation = Assembly.GetExecutingAssembly().Location;
49 sLocation = sLocation.Substring(0, sLocation.LastIndexOf('\\'));
50 // Create a reference to the current directory.
51 DirectoryInfo di = new DirectoryInfo(sLocation);
52 // Create an array representing the files in the current directory.
53 FileInfo[] fi = di.GetFiles();
55 //For every found dll try to figure out if it contains a
56 //cliversion.Version class
57 foreach (FileInfo fiTemp in fi)
59 if (fiTemp.Extension != ".dll"
60 || ! fiTemp.Name.StartsWith("version"))
61 continue;
63 Assembly ass = null;
64 Object objVersion = null;
65 try
67 string sName = fiTemp.Name.Substring(0, fiTemp.Name.LastIndexOf(".dll"));
68 ass = Assembly.Load(sName);
70 catch (BadImageFormatException)
72 continue;
74 catch (Exception e)
76 Console.WriteLine("#Unexpected Exception");
77 Console.WriteLine(e.Message);
78 return -1;
81 //Assembly is loaded, instantiate cliversion.Version
82 try
84 //This runs the test
85 objVersion = ass.CreateInstance("cliversion.Version");
86 if (objVersion == null)
87 continue;
88 Console.WriteLine("#Tested successfully " + fiTemp.Name);
89 //Starting the office the second time may fail without this pause
90 System.Threading.Thread.Sleep(2000);
92 catch (Exception e)
94 TargetInvocationException te = e as TargetInvocationException;
95 if (te != null)
97 FileNotFoundException fe = e.InnerException as FileNotFoundException;
98 if (fe != null)
100 Console.WriteLine(fiTemp.Name + " did not find " + fe.FileName +
101 ". Maybe the " + fe.FileName + " is not installed or does not match the referenced version." +
102 "Original message: " + fe.Message + "\n\n FusionLog: \n" + fe.FusionLog );
103 return -1;
105 FileLoadException fl = e.InnerException as FileLoadException;
106 if (fl != null)
108 Console.WriteLine(fiTemp.Name + " could not load " + fl.FileName +
109 ". Maybe the version of " + fl.FileName + " does not match the referenced version. " +
110 "Original message: " + fl.Message + "\n\n FusionLog: \n" + fl.FusionLog );
111 return -1;
114 if (e.InnerException != null)
116 Console.WriteLine(e.InnerException);
119 Console.WriteLine("#Unexpected Exception");
120 Console.WriteLine(e.Message);
121 return -1;
124 //For some unknown reason this program hangs sometimes when started from java. This is
125 //a workaround that makes the problem disappear.
126 System.Threading.Thread.Sleep(1000);
127 return 0;