Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / jvmaccess / workbench / javainfo / javainfotest.cxx
blobbb7c9875825d077db787670de47219afdd26419a
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"
35 #include <stdio.h>
36 #include <vector>
38 using namespace std;
39 using namespace osl;
41 using jvmaccess::JavaInfo;
43 using ::rtl::OUString;
44 using ::rtl::OUStringToOString;
45 using ::rtl::OString;
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();
57 bool test_isEqual();
58 bool test_getJarFilePath();
60 void printInfo(const JavaInfo& info);
62 int main( int argc, char * argv[], char * envp[])
64 const int arSize= 20;
65 bool arRet[arSize];
66 int i =0;
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();
75 bool error= true;
76 for(int j= 0; j < i; j++)
77 error &= arRet[j];
79 if( error == false)
80 printf("Errors occurred\n");
81 return 0;
84 bool test_constructor1()
86 printf("\ntest JavaInfo::JavaInfo(const OUString& usJavaHome\n" \
87 "!Check output for correctness\n\n");
88 try{
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"));
93 printInfo(info);
94 }catch( JavaInfo::InitException& )
96 return false;
99 return true;
102 bool test_constructor2()
104 printf("\ntest JavaInfo::JavaInfo(const OUString& usVersion, int requirements)\n" \
105 "!Check output for correctness\n\n");
106 bool arRet[20];
107 int i= 0;
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"));
114 try{
115 JavaInfo info= JavaInfo(OUString(), 0);
116 arRet[i++]= true;
118 catch( ...) {
119 arRet[i++]= false;
121 try{
122 // make sure it supports accessibility
123 JavaInfo info= JavaInfo(OUString(), JavaInfo::Accessibility);
124 arRet[i++]= info.supportsAccessibility();
126 catch( ...) {
127 arRet[i++]= false;
130 try{
131 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::EqualVersion);
132 arRet[i++]= info.compareVersions(a) == 0;
134 catch( ...) {
135 arRet[i++]= false;
137 try{
138 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), 0);
139 arRet[i++]= info.compareVersions(a) == 0;
141 catch( ...) {
142 arRet[i++]= false;
145 try{
146 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::EqualVersion | JavaInfo::GreaterVersion);
147 arRet[i++]= info.compareVersions(a) >= 0;
149 catch( ...) {
150 arRet[i++]= false;
152 try{
153 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::EqualVersion | JavaInfo::SmallerVersion);
154 arRet[i++]= info.compareVersions(a) <= 0;
156 catch( ...) {
157 arRet[i++]= false;
159 try{
160 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::SmallerVersion);
161 arRet[i++]= info.compareVersions(a) < 0;
163 catch( ...) {
164 arRet[i++]= false;
166 try{
167 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::GreaterVersion);
168 arRet[i++]= info.compareVersions(a) > 0;
170 catch( ...) {
171 arRet[i++]= false;
174 try{
175 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::EqualVersion | JavaInfo::SmallerVersion
176 | JavaInfo::Accessibility);
177 arRet[i++]= info.compareVersions(a) <= 0 && info.supportsAccessibility();
179 catch( ...) {
180 arRet[i++]= false;
182 try{
183 JavaInfo info(OUString(OUSTR(JAVA_VERSION)), JavaInfo::GreaterVersion | JavaInfo::Accessibility);
184 arRet[i++]= info.compareVersions(a) > 0 && info.supportsAccessibility();
186 catch( ...) {
187 arRet[i++]= false;
191 bool err= true;
192 for(int j= 0; j < i; j++)
193 err &= arRet[j];
194 if( err)
195 printf("ok\n");
196 else
197 printf("failed\n");
198 return err;
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++)
209 printInfo(vec[i]);
210 return true;
213 bool test_compareVersions()
215 bool ret= false;
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))
251 ret= true;
253 if(ret &&
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))
261 ret= true;
263 if(ret &&
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))
273 ret= true;
275 // if(ret
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
281 // )
284 // if(ret &&
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))
290 // ret= true;
292 if( ! ret)
293 printf("failed\n");
294 else
295 printf("ok\n");
297 return ret;
300 bool test_createBestInfo()
302 printf("\ntest JavaInfo::createBestInfo\n" \
303 "! Check output for correctness\n\n");
304 JavaInfo info= JavaInfo::createBestInfo(false);
305 printInfo(info);
306 return true;
309 bool test_isEqual()
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"));
329 bool arRet[20];
330 int i= 0;
331 arRet[i++]= a.isEqual(b);
332 arRet[i++]= ! a.isEqual(c); //must fail
333 arRet[i++]= a.isEqual(d);
335 bool err= true;
336 for(int j= 0; j < i; j++)
337 err &= arRet[j];
338 if( arRet == false)
339 printf("failed\n");
340 else
341 printf("ok\n");
342 return err;
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());
354 return true;
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: */