1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: javainfotest.cxx,v $
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"
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();
57 bool test_getJarFilePath();
59 void printInfo(const JavaInfo
& info
);
61 int main( int argc
, char * argv
[], char * envp
[])
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();
75 for(int j
= 0; j
< i
; j
++)
79 printf("Errors occurred\n");
83 bool test_constructor1()
85 printf("\ntest JavaInfo::JavaInfo(const OUString& usJavaHome\n" \
86 "!Check output for correctness\n\n");
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"));
93 }catch( JavaInfo::InitException
& )
101 bool test_constructor2()
103 printf("\ntest JavaInfo::JavaInfo(const OUString& usVersion, int requirements)\n" \
104 "!Check output for correctness\n\n");
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"));
114 JavaInfo info
= JavaInfo(OUString(), 0);
121 // make sure it supports accessibility
122 JavaInfo info
= JavaInfo(OUString(), JavaInfo::Accessibility
);
123 arRet
[i
++]= info
.supportsAccessibility();
130 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::EqualVersion
);
131 arRet
[i
++]= info
.compareVersions(a
) == 0;
137 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), 0);
138 arRet
[i
++]= info
.compareVersions(a
) == 0;
145 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::EqualVersion
| JavaInfo::GreaterVersion
);
146 arRet
[i
++]= info
.compareVersions(a
) >= 0;
152 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::EqualVersion
| JavaInfo::SmallerVersion
);
153 arRet
[i
++]= info
.compareVersions(a
) <= 0;
159 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::SmallerVersion
);
160 arRet
[i
++]= info
.compareVersions(a
) < 0;
166 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::GreaterVersion
);
167 arRet
[i
++]= info
.compareVersions(a
) > 0;
174 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::EqualVersion
| JavaInfo::SmallerVersion
175 | JavaInfo::Accessibility
);
176 arRet
[i
++]= info
.compareVersions(a
) <= 0 && info
.supportsAccessibility();
182 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::GreaterVersion
| JavaInfo::Accessibility
);
183 arRet
[i
++]= info
.compareVersions(a
) > 0 && info
.supportsAccessibility();
191 for(int j
= 0; j
< i
; j
++)
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
++)
212 bool test_compareVersions()
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))
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))
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))
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
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))
299 bool test_createBestInfo()
301 printf("\ntest JavaInfo::createBestInfo\n" \
302 "! Check output for correctness\n\n");
303 JavaInfo info
= JavaInfo::createBestInfo(false);
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"));
330 arRet
[i
++]= a
.isEqual(b
);
331 arRet
[i
++]= ! a
.isEqual(c
); //must fail
332 arRet
[i
++]= a
.isEqual(d
);
335 for(int j
= 0; j
< i
; j
++)
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());
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");