Branch libreoffice-5-0-4
[LibreOffice.git] / testtools / source / cliversioning / runtests.cs
blob40cccefc667d495321e8449a05e82492ed46a91d
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 using System;
20 using System.Reflection;
21 using System.IO;
23 // __________ implementation ____________________________________
25 /** Create and modify a spreadsheet document.
27 namespace cliversion
29 public class RunTests
32 public static int Main(String[] args)
34 // System.Diagnostics.Debugger.Launch();
35 //get the path to the directory
36 string sLocation = Assembly.GetExecutingAssembly().Location;
37 sLocation = sLocation.Substring(0, sLocation.LastIndexOf('\\'));
38 // Create a reference to the current directory.
39 DirectoryInfo di = new DirectoryInfo(sLocation);
40 // Create an array representing the files in the current directory.
41 FileInfo[] fi = di.GetFiles();
43 //For every found dll try to figure out if it contains a
44 //cliversion.Version class
45 foreach (FileInfo fiTemp in fi)
47 if (fiTemp.Extension != ".dll"
48 || ! fiTemp.Name.StartsWith("version"))
49 continue;
51 Assembly ass = null;
52 Object objVersion = null;
53 try
55 string sName = fiTemp.Name.Substring(0, fiTemp.Name.LastIndexOf(".dll"));
56 ass = Assembly.Load(sName);
58 catch (BadImageFormatException)
60 continue;
62 catch (Exception e)
64 Console.WriteLine("#Unexpected Exception");
65 Console.WriteLine(e.Message);
66 return -1;
69 //Assembly is loaded, instantiate cliversion.Version
70 try
72 //This runs the test
73 objVersion = ass.CreateInstance("cliversion.Version");
74 if (objVersion == null)
75 continue;
76 Console.WriteLine("#Tested successfully " + fiTemp.Name);
77 //Starting the office the second time may fail without this pause
78 System.Threading.Thread.Sleep(2000);
80 catch (Exception e)
82 TargetInvocationException te = e as TargetInvocationException;
83 if (te != null)
85 FileNotFoundException fe = e.InnerException as FileNotFoundException;
86 if (fe != null)
88 Console.WriteLine(fiTemp.Name + " did not find " + fe.FileName +
89 ". Maybe the " + fe.FileName + " is not installed or does not match the referenced version." +
90 "Original message: " + fe.Message + "\n\n FusionLog: \n" + fe.FusionLog );
91 return -1;
93 FileLoadException fl = e.InnerException as FileLoadException;
94 if (fl != null)
96 Console.WriteLine(fiTemp.Name + " could not load " + fl.FileName +
97 ". Maybe the version of " + fl.FileName + " does not match the referenced version. " +
98 "Original message: " + fl.Message + "\n\n FusionLog: \n" + fl.FusionLog );
99 return -1;
102 if (e.InnerException != null)
104 Console.WriteLine(e.InnerException);
107 Console.WriteLine("#Unexpected Exception");
108 Console.WriteLine(e.Message);
109 return -1;
112 //For some unknown reason this program hangs sometimes when started from java. This is
113 //a workaround that makes the problem disappear.
114 System.Threading.Thread.Sleep(1000);
115 return 0;