1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "jvmaccess/javainfo.hxx"
22 #include "osl/file.hxx"
23 #include "osl/thread.h"
24 #include "rtl/ustring.hxx"
32 using jvmaccess::JavaInfo
;
35 #define JAVA_VERSION "1.4.1_01"
37 bool test_constructor1();
38 bool test_constructor2();
39 bool test_createAllInfo();
40 bool test_compareVersions();
41 bool test_createAllInfo();
42 bool test_createBestInfo();
44 bool test_getJarFilePath();
46 void printInfo(const JavaInfo
& info
);
48 int main( int argc
, char * argv
[], char * envp
[])
53 arRet
[i
++]= test_createAllInfo();
54 arRet
[i
++]= test_constructor1();
55 arRet
[i
++]= test_constructor2();
57 arRet
[i
++]= test_compareVersions();
58 arRet
[i
++]= test_createBestInfo();
59 arRet
[i
++]= test_isEqual();
60 arRet
[i
++]= test_getJarFilePath();
62 for(int j
= 0; j
< i
; j
++)
66 printf("Errors occurred\n");
70 bool test_constructor1()
72 printf("\ntest JavaInfo::JavaInfo(const OUString& usJavaHome\n" \
73 "!Check output for correctness\n\n");
75 JavaInfo
info("file:///d:/java/j2sdk1.4.1_01");
76 // JavaInfo info("file:///local/jl/java/j2sdk1.4.0");
77 // JavaInfo info("file:///usr/local2/jl/java/j2sdk1.4.0");
80 }catch( JavaInfo::InitException
& )
88 bool test_constructor2()
90 printf("\ntest JavaInfo::JavaInfo(const OUString& usVersion, int requirements)\n" \
91 "!Check output for correctness\n\n");
95 JavaInfo
a("file:///d:/java/j2sdk1.4.1_01");
96 // -----------------------------------------------------
97 // JavaInfo a("file:///usr/local2/jl/java/j2sdk1.4.0");
99 // JavaInfo a("file:///local/jl/java/j2sdk1.4.0");
101 JavaInfo info
= JavaInfo(OUString(), 0);
108 // make sure it supports accessibility
109 JavaInfo info
= JavaInfo(OUString(), JavaInfo::Accessibility
);
110 arRet
[i
++]= info
.supportsAccessibility();
117 JavaInfo
info(OUString(JAVA_VERSION
), JavaInfo::EqualVersion
);
118 arRet
[i
++]= info
.compareVersions(a
) == 0;
124 JavaInfo
info(OUString(JAVA_VERSION
), 0);
125 arRet
[i
++]= info
.compareVersions(a
) == 0;
132 JavaInfo
info(OUString(JAVA_VERSION
), JavaInfo::EqualVersion
| JavaInfo::GreaterVersion
);
133 arRet
[i
++]= info
.compareVersions(a
) >= 0;
139 JavaInfo
info(OUString(JAVA_VERSION
), JavaInfo::EqualVersion
| JavaInfo::SmallerVersion
);
140 arRet
[i
++]= info
.compareVersions(a
) <= 0;
146 JavaInfo
info(OUString(JAVA_VERSION
), JavaInfo::SmallerVersion
);
147 arRet
[i
++]= info
.compareVersions(a
) < 0;
153 JavaInfo
info(OUString(JAVA_VERSION
), JavaInfo::GreaterVersion
);
154 arRet
[i
++]= info
.compareVersions(a
) > 0;
161 JavaInfo
info(OUString(JAVA_VERSION
), JavaInfo::EqualVersion
| JavaInfo::SmallerVersion
162 | JavaInfo::Accessibility
);
163 arRet
[i
++]= info
.compareVersions(a
) <= 0 && info
.supportsAccessibility();
169 JavaInfo
info(OUString(JAVA_VERSION
), JavaInfo::GreaterVersion
| JavaInfo::Accessibility
);
170 arRet
[i
++]= info
.compareVersions(a
) > 0 && info
.supportsAccessibility();
178 for(int j
= 0; j
< i
; j
++)
188 bool test_createAllInfo()
190 printf("\ntest JavaInfo::createAllInfo\n" \
191 "! Compare output with values in registry, PATH, JAVA_HOME, LD_LIBRARY_PATH !\n\n");
192 vector
<JavaInfo
> vec
;
193 JavaInfo::createAllInfo(&vec
);
194 for(vector
<JavaInfo
>::size_type i
= 0; i
< vec
.size(); i
++)
199 bool test_compareVersions()
202 printf("\ntest JavaInfo::compareVersions \n" \
203 "! Check output for correctness\n\n");
206 JavaInfo
a("file:///C:/Program%20Files/JavaSoft/JRE/1.3.1");
207 JavaInfo
b("file:///C:/Program%20Files/JavaSoft/JRE/1.3.1_04");
208 JavaInfo
c("file:///C:/Program%20Files/Java/j2re1.4.0_03");
209 JavaInfo
d("file:///C:/Program%20Files/Java/j2re1.4.2_04");
210 // JavaInfo e("file:///d:/java/j2sdk1.4.0_01");
211 // JavaInfo f("file:///d:/java/j2sdk1.4.0_02");
212 // JavaInfo g("file:///d:/java/j2sdk1.4.1");
213 // JavaInfo h("file:///d:/java/j2sdk1.4.1_01");
215 // JavaInfo a("file:///usr/local2/jl/java/j2re1_3_1_02");
216 // JavaInfo b("file:///usr/local2/jl/java/j2sdk1.4.0");
217 // JavaInfo c("file:///usr/local2/jl/java/j2sdk1.4.1");
218 // JavaInfo d("file:///usr/local2/jl/java/j2re1.4.1_01");
220 // JavaInfo a("file:///local/jl/java/jre1.3.1");
221 // JavaInfo b("file:///local/jl/java/jdk1.3.1_04");
222 // JavaInfo c("file:///local/jl/java/j2sdk1.4.0");
223 // JavaInfo d("file:///local/jl/java/j2sdk1.4.1");
224 // JavaInfo e("file:///local/jl/java/j2re1.4.1_01");
225 // fprintf(stderr,"###ok1");
227 if( (a
.compareVersions(a
) == 0
228 && a
.compareVersions(b
) < 0
229 && a
.compareVersions(c
) < 0
230 // && a.compareVersions(d) < 0
231 // && a.compareVersions(e) < 0
232 // && a.compareVersions(h) < 0
235 (a
.compareVersions(a
)== 0))
240 (b
.compareVersions(a
) > 0
241 && b
.compareVersions(b
) == 0
242 && b
.compareVersions(c
) < 0
243 && b
.compareVersions(d
) < 0
244 // && b.compareVersions(e) < 0
245 // && b.compareVersions(h) < 0))
250 ( d
.compareVersions(a
) > 0
251 && d
.compareVersions(b
) > 0
252 && d
.compareVersions(c
) > 0
253 && d
.compareVersions(d
) == 0
254 // && d.compareVersions(e) < 0
255 // && d.compareVersions(f) < 0
256 // && d.compareVersions(g) < 0
257 // && d.compareVersions(h) < 0))
262 // && e.compareVersions(a) > 0
263 // && e.compareVersions(b) > 0
264 // && e.compareVersions(c) > 0
265 // && e.compareVersions(d) > 0
266 // && e.compareVersions(e) == 0
271 // (f.compareVersions(a) > 0
272 // && f.compareVersions(c) > 0
273 // && f.compareVersions(d) > 0
274 // && f.compareVersions(g) < 0
275 // && f.compareVersions(h) < 0))
286 bool test_createBestInfo()
288 printf("\ntest JavaInfo::createBestInfo\n" \
289 "! Check output for correctness\n\n");
290 JavaInfo info
= JavaInfo::createBestInfo(false);
297 printf("\ntest JavaInfo::isEqual\n");
298 JavaInfo
a(JAVA_VERSION
); // accessible
299 JavaInfo
b(JAVA_VERSION
);
301 JavaInfo
c("file:///c:/local/r/j2sdk1.4.0");// not Accessible
302 JavaInfo
d("file:///d:/java/copy_j2sdk1.4.0");
304 // JavaInfo a("file:///usr/local2/jl/java/j2re1_3_1_02");
305 // JavaInfo b("file:///usr/local2/jl/java/j2re1_3_1_02");
307 // JavaInfo c("file:///usr/local2/jl/java/j2sdk1.4.1");
308 // JavaInfo d("file:///usr/local2/jl/java/copyj2sdk1.4.1");
310 // JavaInfo a("file:///local/jl/java/jre1.3.1");
311 // JavaInfo b("file:///local/jl/java/jre1.3.1");
312 // JavaInfo c("file:///local/jl/java/j2sdk1.4.1");
313 // JavaInfo d("file:///local/jl/java/copyj2sdk1.4.1");
317 arRet
[i
++]= a
.isEqual(b
);
318 arRet
[i
++]= ! a
.isEqual(c
); //must fail
319 arRet
[i
++]= a
.isEqual(d
);
322 for(int j
= 0; j
< i
; j
++)
331 bool test_getJarFilePath()
333 printf("\ntest JavaInfo::getJarFilePath\n");
334 JavaInfo
info(OUString("1.3.1"), JavaInfo::GreaterVersion
| JavaInfo::EqualVersion
);
335 OUString s
= info
.getJarFilePath("javaplugin.jar");
337 printf("check if this URL is correct:\n");
338 OString oPath
= OUStringToOString(s
, osl_getThreadTextEncoding());
339 printf("%s\n", oPath
.getStr());
343 void printInfo(const JavaInfo
& info
)
345 OUString usVersion
= info
.getVersion();
346 OString sVersion
= OUStringToOString( usVersion
, osl_getThreadTextEncoding());
347 OUString usHome
= info
.getInstallationLocation();
348 OString sHome
= OUStringToOString( usHome
, osl_getThreadTextEncoding());
349 OUString usType
= info
.getType();
350 OString sType
= OUStringToOString(usType
, osl_getThreadTextEncoding());
351 OUString usLib
= info
.getRuntimeLibLocation();
352 OString sLib
= OUStringToOString(usLib
, osl_getThreadTextEncoding());
353 OUString usLibLocation
= info
.getLibLocations();
354 OString sLibLocation
= OUStringToOString(usLibLocation
, osl_getThreadTextEncoding());
355 sal_Bool baccess
= info
.supportsAccessibility();
357 printf("%s %s\n",sType
.getStr(), sVersion
.getStr());
358 printf("\t%s \n",sHome
.getStr());
359 printf("\t%s \n",sLib
.getStr());
360 printf("\tLibDir: %s \n", sLibLocation
.getStr());
361 printf("\t%s\n", baccess
? "accessible" : "not accessible");
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */