Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / testtools / source / cliversioning / runtests.cs
blobfdf1761f4ace1d6ce2d58ac411bbeb7776f40081
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 using System;
29 using System.Reflection;
30 using System.IO;
32 // __________ implementation ____________________________________
34 /** Create and modify a spreadsheet document.
36 namespace cliversion
38 public class RunTests
41 public static int Main(String[] args)
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();
52 //For every found dll try to figure out if it contains a
53 //cliversion.Version class
54 foreach (FileInfo fiTemp in fi)
56 if (fiTemp.Extension != ".dll"
57 || ! fiTemp.Name.StartsWith("version"))
58 continue;
60 Assembly ass = null;
61 Object objVersion = null;
62 try
64 string sName = fiTemp.Name.Substring(0, fiTemp.Name.LastIndexOf(".dll"));
65 ass = Assembly.Load(sName);
67 catch (BadImageFormatException)
69 continue;
71 catch (Exception e)
73 Console.WriteLine("#Unexpected Exception");
74 Console.WriteLine(e.Message);
75 return -1;
78 //Assembly is loaded, instantiate cliversion.Version
79 try
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);
89 catch (Exception e)
91 TargetInvocationException te = e as TargetInvocationException;
92 if (te != null)
94 FileNotFoundException fe = e.InnerException as FileNotFoundException;
95 if (fe != null)
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;
102 FileLoadException fl = e.InnerException as FileLoadException;
103 if (fl != null)
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;
111 if (e.InnerException != null)
113 Console.WriteLine(e.InnerException);
116 Console.WriteLine("#Unexpected Exception");
117 Console.WriteLine(e.Message);
118 return -1;
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;