1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "jvmaccess/javainfo.hxx"
31 #include "osl/file.hxx"
32 #include "osl/thread.h"
33 #include "rtl/ustring.hxx"
41 using jvmaccess::JavaInfo
;
43 using ::rtl::OUString
;
44 using ::rtl::OUStringToOString
;
47 #define OUSTR( x ) ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( x ))
49 #define JAVA_VERSION "1.4.1_01"
51 bool test_constructor1();
52 bool test_constructor2();
53 bool test_createAllInfo();
54 bool test_compareVersions();
55 bool test_createAllInfo();
56 bool test_createBestInfo();
58 bool test_getJarFilePath();
60 void printInfo(const JavaInfo
& info
);
62 int main( int argc
, char * argv
[], char * envp
[])
67 arRet
[i
++]= test_createAllInfo();
68 arRet
[i
++]= test_constructor1();
69 arRet
[i
++]= test_constructor2();
71 arRet
[i
++]= test_compareVersions();
72 arRet
[i
++]= test_createBestInfo();
73 arRet
[i
++]= test_isEqual();
74 arRet
[i
++]= test_getJarFilePath();
76 for(int j
= 0; j
< i
; j
++)
80 printf("Errors occurred\n");
84 bool test_constructor1()
86 printf("\ntest JavaInfo::JavaInfo(const OUString& usJavaHome\n" \
87 "!Check output for correctness\n\n");
89 JavaInfo
info(OUSTR("file:///d:/java/j2sdk1.4.1_01"));
90 // JavaInfo info(OUSTR("file:///local/jl/java/j2sdk1.4.0"));
91 // JavaInfo info(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.0"));
94 }catch( JavaInfo::InitException
& )
102 bool test_constructor2()
104 printf("\ntest JavaInfo::JavaInfo(const OUString& usVersion, int requirements)\n" \
105 "!Check output for correctness\n\n");
109 JavaInfo
a(OUSTR("file:///d:/java/j2sdk1.4.1_01"));
110 // -----------------------------------------------------
111 // JavaInfo a(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.0"));
112 //------------------------------------------------------------
113 // JavaInfo a(OUSTR("file:///local/jl/java/j2sdk1.4.0"));
115 JavaInfo info
= JavaInfo(OUString(), 0);
122 // make sure it supports accessibility
123 JavaInfo info
= JavaInfo(OUString(), JavaInfo::Accessibility
);
124 arRet
[i
++]= info
.supportsAccessibility();
131 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::EqualVersion
);
132 arRet
[i
++]= info
.compareVersions(a
) == 0;
138 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), 0);
139 arRet
[i
++]= info
.compareVersions(a
) == 0;
146 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::EqualVersion
| JavaInfo::GreaterVersion
);
147 arRet
[i
++]= info
.compareVersions(a
) >= 0;
153 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::EqualVersion
| JavaInfo::SmallerVersion
);
154 arRet
[i
++]= info
.compareVersions(a
) <= 0;
160 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::SmallerVersion
);
161 arRet
[i
++]= info
.compareVersions(a
) < 0;
167 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::GreaterVersion
);
168 arRet
[i
++]= info
.compareVersions(a
) > 0;
175 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::EqualVersion
| JavaInfo::SmallerVersion
176 | JavaInfo::Accessibility
);
177 arRet
[i
++]= info
.compareVersions(a
) <= 0 && info
.supportsAccessibility();
183 JavaInfo
info(OUString(OUSTR(JAVA_VERSION
)), JavaInfo::GreaterVersion
| JavaInfo::Accessibility
);
184 arRet
[i
++]= info
.compareVersions(a
) > 0 && info
.supportsAccessibility();
192 for(int j
= 0; j
< i
; j
++)
202 bool test_createAllInfo()
204 printf("\ntest JavaInfo::createAllInfo\n" \
205 "! Compare output with values in registry, PATH, JAVA_HOME, LD_LIBRARY_PATH !\n\n");
206 vector
<JavaInfo
> vec
;
207 JavaInfo::createAllInfo(&vec
);
208 for(vector
<JavaInfo
>::size_type i
= 0; i
< vec
.size(); i
++)
213 bool test_compareVersions()
216 printf("\ntest JavaInfo::compareVersions \n" \
217 "! Check output for correctness\n\n");
220 JavaInfo
a(OUSTR("file:///C:/Program%20Files/JavaSoft/JRE/1.3.1"));
221 JavaInfo
b(OUSTR("file:///C:/Program%20Files/JavaSoft/JRE/1.3.1_04"));
222 JavaInfo
c(OUSTR("file:///C:/Program%20Files/Java/j2re1.4.0_03"));
223 JavaInfo
d(OUSTR("file:///C:/Program%20Files/Java/j2re1.4.2_04"));
224 // JavaInfo e(OUSTR("file:///d:/java/j2sdk1.4.0_01"));
225 // JavaInfo f(OUSTR("file:///d:/java/j2sdk1.4.0_02"));
226 // JavaInfo g(OUSTR("file:///d:/java/j2sdk1.4.1"));
227 // JavaInfo h(OUSTR("file:///d:/java/j2sdk1.4.1_01"));
229 // JavaInfo a(OUSTR("file:///usr/local2/jl/java/j2re1_3_1_02"));
230 // JavaInfo b(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.0"));
231 // JavaInfo c(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.1"));
232 // JavaInfo d(OUSTR("file:///usr/local2/jl/java/j2re1.4.1_01"));
234 // JavaInfo a(OUSTR("file:///local/jl/java/jre1.3.1"));
235 // JavaInfo b(OUSTR("file:///local/jl/java/jdk1.3.1_04"));
236 // JavaInfo c(OUSTR("file:///local/jl/java/j2sdk1.4.0"));
237 // JavaInfo d(OUSTR("file:///local/jl/java/j2sdk1.4.1"));
238 // JavaInfo e(OUSTR("file:///local/jl/java/j2re1.4.1_01"));
239 // fprintf(stderr,"###ok1");
241 if( (a
.compareVersions(a
) == 0
242 && a
.compareVersions(b
) < 0
243 && a
.compareVersions(c
) < 0
244 // && a.compareVersions(d) < 0
245 // && a.compareVersions(e) < 0
246 // && a.compareVersions(h) < 0
249 (a
.compareVersions(a
)== 0))
254 (b
.compareVersions(a
) > 0
255 && b
.compareVersions(b
) == 0
256 && b
.compareVersions(c
) < 0
257 && b
.compareVersions(d
) < 0
258 // && b.compareVersions(e) < 0
259 // && b.compareVersions(h) < 0))
264 ( d
.compareVersions(a
) > 0
265 && d
.compareVersions(b
) > 0
266 && d
.compareVersions(c
) > 0
267 && d
.compareVersions(d
) == 0
268 // && d.compareVersions(e) < 0
269 // && d.compareVersions(f) < 0
270 // && d.compareVersions(g) < 0
271 // && d.compareVersions(h) < 0))
276 // && e.compareVersions(a) > 0
277 // && e.compareVersions(b) > 0
278 // && e.compareVersions(c) > 0
279 // && e.compareVersions(d) > 0
280 // && e.compareVersions(e) == 0
285 // (f.compareVersions(a) > 0
286 // && f.compareVersions(c) > 0
287 // && f.compareVersions(d) > 0
288 // && f.compareVersions(g) < 0
289 // && f.compareVersions(h) < 0))
300 bool test_createBestInfo()
302 printf("\ntest JavaInfo::createBestInfo\n" \
303 "! Check output for correctness\n\n");
304 JavaInfo info
= JavaInfo::createBestInfo(false);
311 printf("\ntest JavaInfo::isEqual\n");
312 JavaInfo
a(OUSTR(JAVA_VERSION
)); // accessible
313 JavaInfo
b(OUSTR(JAVA_VERSION
));
315 JavaInfo
c(OUSTR("file:///c:/local/r/j2sdk1.4.0"));// not Accessible
316 JavaInfo
d(OUSTR("file:///d:/java/copy_j2sdk1.4.0"));
317 //-------------------------------------------------------------------
318 // JavaInfo a(OUSTR("file:///usr/local2/jl/java/j2re1_3_1_02"));
319 // JavaInfo b(OUSTR("file:///usr/local2/jl/java/j2re1_3_1_02"));
321 // JavaInfo c(OUSTR("file:///usr/local2/jl/java/j2sdk1.4.1"));
322 // JavaInfo d(OUSTR("file:///usr/local2/jl/java/copyj2sdk1.4.1"));
324 // JavaInfo a(OUSTR("file:///local/jl/java/jre1.3.1"));
325 // JavaInfo b(OUSTR("file:///local/jl/java/jre1.3.1"));
326 // JavaInfo c(OUSTR("file:///local/jl/java/j2sdk1.4.1"));
327 // JavaInfo d(OUSTR("file:///local/jl/java/copyj2sdk1.4.1"));
331 arRet
[i
++]= a
.isEqual(b
);
332 arRet
[i
++]= ! a
.isEqual(c
); //must fail
333 arRet
[i
++]= a
.isEqual(d
);
336 for(int j
= 0; j
< i
; j
++)
345 bool test_getJarFilePath()
347 printf("\ntest JavaInfo::getJarFilePath\n");
348 JavaInfo
info(OUString(OUSTR("1.3.1")), JavaInfo::GreaterVersion
| JavaInfo::EqualVersion
);
349 OUString s
= info
.getJarFilePath(OUSTR("javaplugin.jar"));
351 printf("check if this URL is correct:\n");
352 OString oPath
= OUStringToOString(s
, osl_getThreadTextEncoding());
353 printf("%s\n", oPath
.getStr());
357 void printInfo(const JavaInfo
& info
)
359 OUString usVersion
= info
.getVersion();
360 OString sVersion
= OUStringToOString( usVersion
, osl_getThreadTextEncoding());
361 OUString usHome
= info
.getInstallationLocation();
362 OString sHome
= OUStringToOString( usHome
, osl_getThreadTextEncoding());
363 OUString usType
= info
.getType();
364 OString sType
= OUStringToOString(usType
, osl_getThreadTextEncoding());
365 OUString usLib
= info
.getRuntimeLibLocation();
366 OString sLib
= OUStringToOString(usLib
, osl_getThreadTextEncoding());
367 OUString usLibLocation
= info
.getLibLocations();
368 OString sLibLocation
= OUStringToOString(usLibLocation
, osl_getThreadTextEncoding());
369 sal_Bool baccess
= info
.supportsAccessibility();
371 printf("%s %s\n",sType
.getStr(), sVersion
.getStr());
372 printf("\t%s \n",sHome
.getStr());
373 printf("\t%s \n",sLib
.getStr());
374 printf("\tLibDir: %s \n", sLibLocation
.getStr());
375 printf("\t%s\n", baccess
? "accessible" : "not accessible");
378 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */