sync master with lastest vba changes
[ooovba.git] / jvmaccess / workbench / javainfo / javainfotest.cxx
blob4d09889520bfc77b92d40d9817e8f2ac0826cd69
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: javainfotest.cxx,v $
10 * $Revision: 1.5 $
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 #include "jvmaccess/javainfo.hxx"
33 #include "osl/file.hxx"
34 #include "osl/thread.h"
35 #include "rtl/ustring.hxx"
37 #include <stdio.h>
38 #include <vector>
40 using namespace rtl;
41 using namespace std;
42 using namespace osl;
44 using jvmaccess::JavaInfo;
46 #define OUSTR( x ) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( x ))
48 #define JAVA_VERSION "1.4.1_01"
50 bool test_constructor1();
51 bool test_constructor2();
52 bool test_createAllInfo();
53 bool test_compareVersions();
54 bool test_createAllInfo();
55 bool test_createBestInfo();
56 bool test_isEqual();
57 bool test_getJarFilePath();
59 void printInfo(const JavaInfo& info);
61 int main( int argc, char * argv[], char * envp[])
63 const int arSize= 20;
64 bool arRet[arSize];
65 int i =0;
66 arRet[i++]= test_createAllInfo();
67 arRet[i++]= test_constructor1();
68 arRet[i++]= test_constructor2();
70 arRet[i++]= test_compareVersions();
71 arRet[i++]= test_createBestInfo();
72 arRet[i++]= test_isEqual();
73 arRet[i++]= test_getJarFilePath();
74 bool error= true;
75 for(int j= 0; j < i; j++)
76 error &= arRet[j];
78 if( error == false)
79 printf("Errors occurred\n");
80 return 0;
83 bool test_constructor1()
85 printf("\ntest JavaInfo::JavaInfo(const OUString& usJavaHome\n" \
86 "!Check output for correctness\n\n");
87 try{
88 JavaInfo info(OUSTR("file:///d:/java/j2sdk1.4.1_01"));
89 // JavaInfo info(OUSTR("file:///local/jl/java/j2sdk1.4.0"));
90 // JavaInfo info(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.0"));
92 printInfo(info);
93 }catch( JavaInfo::InitException& )
95 return false;
98 return true;
101 bool test_constructor2()
103 printf("\ntest JavaInfo::JavaInfo(const OUString& usVersion, int requirements)\n" \
104 "!Check output for correctness\n\n");
105 bool arRet[20];
106 int i= 0;
108 JavaInfo a(OUSTR("file:///d:/java/j2sdk1.4.1_01"));
109 // -----------------------------------------------------
110 // JavaInfo a(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.0"));
111 //------------------------------------------------------------
112 // JavaInfo a(OUSTR("file:///local/jl/java/j2sdk1.4.0"));
113 try{
114 JavaInfo info= JavaInfo(OUString(), 0);
115 arRet[i++]= true;
117 catch( ...) {
118 arRet[i++]= false;
120 try{
121 // make sure it supports accessibility
122 JavaInfo info= JavaInfo(OUString(), JavaInfo::Accessibility);
123 arRet[i++]= info.supportsAccessibility();
125 catch( ...) {
126 arRet[i++]= false;
129 try{
130 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::EqualVersion);
131 arRet[i++]= info.compareVersions(a) == 0;
133 catch( ...) {
134 arRet[i++]= false;
136 try{
137 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), 0);
138 arRet[i++]= info.compareVersions(a) == 0;
140 catch( ...) {
141 arRet[i++]= false;
144 try{
145 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::EqualVersion | JavaInfo::GreaterVersion);
146 arRet[i++]= info.compareVersions(a) >= 0;
148 catch( ...) {
149 arRet[i++]= false;
151 try{
152 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::EqualVersion | JavaInfo::SmallerVersion);
153 arRet[i++]= info.compareVersions(a) <= 0;
155 catch( ...) {
156 arRet[i++]= false;
158 try{
159 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::SmallerVersion);
160 arRet[i++]= info.compareVersions(a) < 0;
162 catch( ...) {
163 arRet[i++]= false;
165 try{
166 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::GreaterVersion);
167 arRet[i++]= info.compareVersions(a) > 0;
169 catch( ...) {
170 arRet[i++]= false;
173 try{
174 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::EqualVersion | JavaInfo::SmallerVersion
175 | JavaInfo::Accessibility);
176 arRet[i++]= info.compareVersions(a) <= 0 && info.supportsAccessibility();
178 catch( ...) {
179 arRet[i++]= false;
181 try{
182 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::GreaterVersion | JavaInfo::Accessibility);
183 arRet[i++]= info.compareVersions(a) > 0 && info.supportsAccessibility();
185 catch( ...) {
186 arRet[i++]= false;
190 bool err= true;
191 for(int j= 0; j < i; j++)
192 err &= arRet[j];
193 if( err)
194 printf("ok\n");
195 else
196 printf("failed\n");
197 return err;
201 bool test_createAllInfo()
203 printf("\ntest JavaInfo::createAllInfo\n" \
204 "! Compare output with values in registry, PATH, JAVA_HOME, LD_LIBRARY_PATH !\n\n");
205 vector<JavaInfo> vec;
206 JavaInfo::createAllInfo(&vec);
207 for(vector<JavaInfo>::size_type i= 0; i < vec.size(); i++)
208 printInfo(vec[i]);
209 return true;
212 bool test_compareVersions()
214 bool ret= false;
215 printf("\ntest JavaInfo::compareVersions \n" \
216 "! Check output for correctness\n\n");
219 JavaInfo a(OUSTR("file:///C:/Program%20Files/JavaSoft/JRE/1.3.1"));
220 JavaInfo b(OUSTR("file:///C:/Program%20Files/JavaSoft/JRE/1.3.1_04"));
221 JavaInfo c(OUSTR("file:///C:/Program%20Files/Java/j2re1.4.0_03"));
222 JavaInfo d(OUSTR("file:///C:/Program%20Files/Java/j2re1.4.2_04"));
223 // JavaInfo e(OUSTR("file:///d:/java/j2sdk1.4.0_01"));
224 // JavaInfo f(OUSTR("file:///d:/java/j2sdk1.4.0_02"));
225 // JavaInfo g(OUSTR("file:///d:/java/j2sdk1.4.1"));
226 // JavaInfo h(OUSTR("file:///d:/java/j2sdk1.4.1_01"));
228 // JavaInfo a(OUSTR("file:///usr/local2/jl/java/j2re1_3_1_02"));
229 // JavaInfo b(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.0"));
230 // JavaInfo c(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.1"));
231 // JavaInfo d(OUSTR("file:///usr/local2/jl/java/j2re1.4.1_01"));
233 // JavaInfo a(OUSTR("file:///local/jl/java/jre1.3.1"));
234 // JavaInfo b(OUSTR("file:///local/jl/java/jdk1.3.1_04"));
235 // JavaInfo c(OUSTR("file:///local/jl/java/j2sdk1.4.0"));
236 // JavaInfo d(OUSTR("file:///local/jl/java/j2sdk1.4.1"));
237 // JavaInfo e(OUSTR("file:///local/jl/java/j2re1.4.1_01"));
238 // fprintf(stderr,"###ok1");
240 if( (a.compareVersions(a) == 0
241 && a.compareVersions(b) < 0
242 && a.compareVersions(c) < 0
243 // && a.compareVersions(d) < 0
244 // && a.compareVersions(e) < 0
245 // && a.compareVersions(h) < 0
248 (a.compareVersions(a)== 0))
250 ret= true;
252 if(ret &&
253 (b.compareVersions(a) > 0
254 && b.compareVersions(b) == 0
255 && b.compareVersions(c) < 0
256 && b.compareVersions(d) < 0
257 // && b.compareVersions(e) < 0
258 // && b.compareVersions(h) < 0))
260 ret= true;
262 if(ret &&
263 ( d.compareVersions(a) > 0
264 && d.compareVersions(b) > 0
265 && d.compareVersions(c) > 0
266 && d.compareVersions(d) == 0
267 // && d.compareVersions(e) < 0
268 // && d.compareVersions(f) < 0
269 // && d.compareVersions(g) < 0
270 // && d.compareVersions(h) < 0))
272 ret= true;
274 // if(ret
275 // && e.compareVersions(a) > 0
276 // && e.compareVersions(b) > 0
277 // && e.compareVersions(c) > 0
278 // && e.compareVersions(d) > 0
279 // && e.compareVersions(e) == 0
280 // )
283 // if(ret &&
284 // (f.compareVersions(a) > 0
285 // && f.compareVersions(c) > 0
286 // && f.compareVersions(d) > 0
287 // && f.compareVersions(g) < 0
288 // && f.compareVersions(h) < 0))
289 // ret= true;
291 if( ! ret)
292 printf("failed\n");
293 else
294 printf("ok\n");
296 return ret;
299 bool test_createBestInfo()
301 printf("\ntest JavaInfo::createBestInfo\n" \
302 "! Check output for correctness\n\n");
303 JavaInfo info= JavaInfo::createBestInfo(false);
304 printInfo(info);
305 return true;
308 bool test_isEqual()
310 printf("\ntest JavaInfo::isEqual\n");
311 JavaInfo a(OUSTR(JAVA_VERSION)); // accessible
312 JavaInfo b(OUSTR(JAVA_VERSION));
314 JavaInfo c(OUSTR("file:///c:/local/r/j2sdk1.4.0"));// not Accessible
315 JavaInfo d(OUSTR("file:///d:/java/copy_j2sdk1.4.0"));
316 //-------------------------------------------------------------------
317 // JavaInfo a(OUSTR("file:///usr/local2/jl/java/j2re1_3_1_02"));
318 // JavaInfo b(OUSTR("file:///usr/local2/jl/java/j2re1_3_1_02"));
320 // JavaInfo c(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.1"));
321 // JavaInfo d(OUSTR("file:///usr/local2/jl/java/copyj2sdk1.4.1"));
323 // JavaInfo a(OUSTR("file:///local/jl/java/jre1.3.1"));
324 // JavaInfo b(OUSTR("file:///local/jl/java/jre1.3.1"));
325 // JavaInfo c(OUSTR("file:///local/jl/java/j2sdk1.4.1"));
326 // JavaInfo d(OUSTR("file:///local/jl/java/copyj2sdk1.4.1"));
328 bool arRet[20];
329 int i= 0;
330 arRet[i++]= a.isEqual(b);
331 arRet[i++]= ! a.isEqual(c); //must fail
332 arRet[i++]= a.isEqual(d);
334 bool err= true;
335 for(int j= 0; j < i; j++)
336 err &= arRet[j];
337 if( arRet == false)
338 printf("failed\n");
339 else
340 printf("ok\n");
341 return err;
344 bool test_getJarFilePath()
346 printf("\ntest JavaInfo::getJarFilePath\n");
347 JavaInfo info(OUString(OUSTR("1.3.1")), JavaInfo::GreaterVersion | JavaInfo::EqualVersion );
348 OUString s= info.getJarFilePath(OUSTR("javaplugin.jar"));
350 printf("check if this URL is correct:\n");
351 OString oPath= OUStringToOString(s, osl_getThreadTextEncoding());
352 printf("%s\n", oPath.getStr());
353 return true;
356 void printInfo(const JavaInfo& info)
358 OUString usVersion= info.getVersion();
359 OString sVersion= OUStringToOString( usVersion, osl_getThreadTextEncoding());
360 OUString usHome= info.getInstallationLocation();
361 OString sHome= OUStringToOString( usHome, osl_getThreadTextEncoding());
362 OUString usType= info.getType();
363 OString sType= OUStringToOString(usType, osl_getThreadTextEncoding());
364 OUString usLib= info.getRuntimeLibLocation();
365 OString sLib= OUStringToOString(usLib, osl_getThreadTextEncoding());
366 OUString usLibLocation= info.getLibLocations();
367 OString sLibLocation= OUStringToOString(usLibLocation, osl_getThreadTextEncoding());
368 sal_Bool baccess= info.supportsAccessibility();
370 printf("%s %s\n",sType.getStr(), sVersion.getStr());
371 printf("\t%s \n",sHome.getStr());
372 printf("\t%s \n",sLib.getStr());
373 printf("\tLibDir: %s \n", sLibLocation.getStr());
374 printf("\t%s\n", baccess ? "accessible" : "not accessible");