1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 29 // MARKER(update_precomp.py): autogen include statement, do not remove 30 #include "precompiled_sal.hxx" 31 #include <stdio.h> 32 33 #include <rtl/process.h> 34 #include <rtl/bootstrap.hxx> 35 #include <rtl/string.hxx> 36 #include <rtl/byteseq.hxx> 37 38 #include <osl/process.h> 39 40 using namespace ::rtl; 41 42 43 int main( int argc, char *argv[] ) 44 { 45 osl_setCommandArgs (argc, argv); 46 47 sal_Int32 nCount = rtl_getAppCommandArgCount(); 48 49 #if OSL_DEBUG_LEVEL > 1 50 fprintf( stdout, "rtl-commandargs (%d) real args:%i ", nCount, argc); 51 for( sal_Int32 i = 0 ; i < nCount ; i ++ ) 52 { 53 OUString data; 54 rtl_getAppCommandArg( i , &(data.pData) ); 55 OString o = OUStringToOString( data, RTL_TEXTENCODING_ASCII_US ); 56 fprintf( stdout, " %s", o.getStr() ); 57 } 58 fprintf( stdout, "\n" ); 59 #endif 60 61 if( nCount == 0 ) 62 { 63 printf( "usage : testbootstrap <checkedValueOfMyBootstrapValue>\n" ); 64 exit( 1 ); 65 } 66 67 68 OUString iniName; 69 Bootstrap::get(OUString(RTL_CONSTASCII_USTRINGPARAM("iniName")), iniName, OUString()); 70 71 #if OSL_DEBUG_LEVEL > 1 72 if(iniName.getLength()) 73 { 74 OString tmp_iniName = OUStringToOString(iniName, RTL_TEXTENCODING_ASCII_US); 75 fprintf(stderr, "using ini: %s\n", tmp_iniName.getStr()); 76 } 77 #endif 78 79 Bootstrap bootstrap(iniName); 80 81 82 OUString name( RTL_CONSTASCII_USTRINGPARAM( "MYBOOTSTRAPTESTVALUE" )); 83 OUString myDefault( RTL_CONSTASCII_USTRINGPARAM("$Default")); 84 85 OUString value; 86 sal_Bool useDefault; 87 88 OUString aDummy; 89 useDefault = bootstrap.getFrom(OUString(RTL_CONSTASCII_USTRINGPARAM("USEDEFAULT")), aDummy); 90 91 sal_Bool result = sal_False; 92 sal_Bool found = sal_True; 93 94 if(useDefault) 95 bootstrap.getFrom(name, value, myDefault); 96 97 else 98 found = bootstrap.getFrom(name, value); 99 100 if(found) 101 { 102 OUString para(OUString::createFromAscii( argv[1] )); 103 104 result = para == value; 105 106 if(!result) 107 { 108 OString para_tmp = OUStringToOString(para, RTL_TEXTENCODING_ASCII_US); 109 OString value_tmp = OUStringToOString(value, RTL_TEXTENCODING_ASCII_US); 110 111 fprintf(stderr, "para(%s) != value(%s)\n", para_tmp.getStr(), value_tmp.getStr()); 112 } 113 } 114 else 115 fprintf(stderr, "bootstrap parameter couldn't be found\n"); 116 117 // test the default case 118 name = OUString( RTL_CONSTASCII_USTRINGPARAM( "no_one_has_set_this_name" ) ); 119 OSL_ASSERT( ! bootstrap.getFrom( name, value ) ); 120 result = result && !bootstrap.getFrom( name, value ); 121 122 myDefault = OUString( RTL_CONSTASCII_USTRINGPARAM( "1" ) ); 123 OUString myDefault2 = OUString( RTL_CONSTASCII_USTRINGPARAM( "2" ) ); 124 125 bootstrap.getFrom( name, value, myDefault ); 126 OSL_ASSERT( value == myDefault ); 127 result = result && (value == myDefault); 128 129 bootstrap.getFrom( name, value, myDefault2 ); 130 OSL_ASSERT( value == myDefault2 ); 131 result = result && (value == myDefault2); 132 133 return result; 134 } 135