Branch libreoffice-5-0-4
[LibreOffice.git] / jvmaccess / workbench / javainfo / javainfotest.cxx
blob115019da1d74bd596480d120d648d687678ba0bf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
26 #include <stdio.h>
27 #include <vector>
29 using namespace std;
30 using namespace osl;
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();
43 bool test_isEqual();
44 bool test_getJarFilePath();
46 void printInfo(const JavaInfo& info);
48 int main( int argc, char * argv[], char * envp[])
50 const int arSize= 20;
51 bool arRet[arSize];
52 int i =0;
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();
61 bool error= true;
62 for(int j= 0; j < i; j++)
63 error &= arRet[j];
65 if( error == false)
66 printf("Errors occurred\n");
67 return 0;
70 bool test_constructor1()
72 printf("\ntest JavaInfo::JavaInfo(const OUString& usJavaHome\n" \
73 "!Check output for correctness\n\n");
74 try{
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");
79 printInfo(info);
80 }catch( JavaInfo::InitException& )
82 return false;
85 return true;
88 bool test_constructor2()
90 printf("\ntest JavaInfo::JavaInfo(const OUString& usVersion, int requirements)\n" \
91 "!Check output for correctness\n\n");
92 bool arRet[20];
93 int i= 0;
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");
100 try{
101 JavaInfo info= JavaInfo(OUString(), 0);
102 arRet[i++]= true;
104 catch( ...) {
105 arRet[i++]= false;
107 try{
108 // make sure it supports accessibility
109 JavaInfo info= JavaInfo(OUString(), JavaInfo::Accessibility);
110 arRet[i++]= info.supportsAccessibility();
112 catch( ...) {
113 arRet[i++]= false;
116 try{
117 JavaInfo info(OUString(JAVA_VERSION), JavaInfo::EqualVersion);
118 arRet[i++]= info.compareVersions(a) == 0;
120 catch( ...) {
121 arRet[i++]= false;
123 try{
124 JavaInfo info(OUString(JAVA_VERSION), 0);
125 arRet[i++]= info.compareVersions(a) == 0;
127 catch( ...) {
128 arRet[i++]= false;
131 try{
132 JavaInfo info(OUString(JAVA_VERSION), JavaInfo::EqualVersion | JavaInfo::GreaterVersion);
133 arRet[i++]= info.compareVersions(a) >= 0;
135 catch( ...) {
136 arRet[i++]= false;
138 try{
139 JavaInfo info(OUString(JAVA_VERSION), JavaInfo::EqualVersion | JavaInfo::SmallerVersion);
140 arRet[i++]= info.compareVersions(a) <= 0;
142 catch( ...) {
143 arRet[i++]= false;
145 try{
146 JavaInfo info(OUString(JAVA_VERSION), JavaInfo::SmallerVersion);
147 arRet[i++]= info.compareVersions(a) < 0;
149 catch( ...) {
150 arRet[i++]= false;
152 try{
153 JavaInfo info(OUString(JAVA_VERSION), JavaInfo::GreaterVersion);
154 arRet[i++]= info.compareVersions(a) > 0;
156 catch( ...) {
157 arRet[i++]= false;
160 try{
161 JavaInfo info(OUString(JAVA_VERSION), JavaInfo::EqualVersion | JavaInfo::SmallerVersion
162 | JavaInfo::Accessibility);
163 arRet[i++]= info.compareVersions(a) <= 0 && info.supportsAccessibility();
165 catch( ...) {
166 arRet[i++]= false;
168 try{
169 JavaInfo info(OUString(JAVA_VERSION), JavaInfo::GreaterVersion | JavaInfo::Accessibility);
170 arRet[i++]= info.compareVersions(a) > 0 && info.supportsAccessibility();
172 catch( ...) {
173 arRet[i++]= false;
177 bool err= true;
178 for(int j= 0; j < i; j++)
179 err &= arRet[j];
180 if( err)
181 printf("ok\n");
182 else
183 printf("failed\n");
184 return err;
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++)
195 printInfo(vec[i]);
196 return true;
199 bool test_compareVersions()
201 bool ret= false;
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))
237 ret= true;
239 if(ret &&
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))
247 ret= true;
249 if(ret &&
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))
259 ret= true;
261 // if(ret
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
267 // )
270 // if(ret &&
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))
276 // ret= true;
278 if( ! ret)
279 printf("failed\n");
280 else
281 printf("ok\n");
283 return ret;
286 bool test_createBestInfo()
288 printf("\ntest JavaInfo::createBestInfo\n" \
289 "! Check output for correctness\n\n");
290 JavaInfo info= JavaInfo::createBestInfo(false);
291 printInfo(info);
292 return true;
295 bool test_isEqual()
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");
315 bool arRet[20];
316 int i= 0;
317 arRet[i++]= a.isEqual(b);
318 arRet[i++]= ! a.isEqual(c); //must fail
319 arRet[i++]= a.isEqual(d);
321 bool err= true;
322 for(int j= 0; j < i; j++)
323 err &= arRet[j];
324 if( arRet == false)
325 printf("failed\n");
326 else
327 printf("ok\n");
328 return err;
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());
340 return true;
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: */