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