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