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