Bump for 3.6-28
[LibreOffice.git] / sal / test / testbootstrap.cxx
blobbcb19999063276993177b88407e25f1b797ff19b
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 ************************************************************************/
30 #include <stdio.h>
32 #include <rtl/process.h>
33 #include <rtl/bootstrap.hxx>
34 #include <rtl/string.hxx>
35 #include <rtl/byteseq.hxx>
37 #include <osl/process.h>
39 using namespace ::rtl;
42 int main( int argc, char *argv[] )
44 osl_setCommandArgs (argc, argv);
46 sal_Int32 nCount = rtl_getAppCommandArgCount();
48 #if OSL_DEBUG_LEVEL > 1
49 fprintf( stdout, "rtl-commandargs (%d) real args:%i ", nCount, argc);
50 for( sal_Int32 i = 0 ; i < nCount ; i ++ )
52 OUString data;
53 rtl_getAppCommandArg( i , &(data.pData) );
54 OString o = OUStringToOString( data, RTL_TEXTENCODING_ASCII_US );
55 fprintf( stdout, " %s", o.getStr() );
57 fprintf( stdout, "\n" );
58 #endif
60 if( nCount == 0 )
62 printf( "usage : testbootstrap <checkedValueOfMyBootstrapValue>\n" );
63 exit( 1 );
67 OUString iniName;
68 Bootstrap::get(OUString(RTL_CONSTASCII_USTRINGPARAM("iniName")), iniName, OUString());
70 #if OSL_DEBUG_LEVEL > 1
71 if(iniName.getLength())
73 OString tmp_iniName = OUStringToOString(iniName, RTL_TEXTENCODING_ASCII_US);
74 fprintf(stderr, "using ini: %s\n", tmp_iniName.getStr());
76 #endif
78 Bootstrap bootstrap(iniName);
81 OUString name( RTL_CONSTASCII_USTRINGPARAM( "MYBOOTSTRAPTESTVALUE" ));
82 OUString myDefault( RTL_CONSTASCII_USTRINGPARAM("$Default"));
84 OUString value;
85 sal_Bool useDefault;
87 OUString aDummy;
88 useDefault = bootstrap.getFrom(OUString(RTL_CONSTASCII_USTRINGPARAM("USEDEFAULT")), aDummy);
90 sal_Bool result = sal_False;
91 sal_Bool found = sal_True;
93 if(useDefault)
94 bootstrap.getFrom(name, value, myDefault);
96 else
97 found = bootstrap.getFrom(name, value);
99 if(found)
101 OUString para(OUString::createFromAscii( argv[1] ));
103 result = para == value;
105 if(!result)
107 OString para_tmp = OUStringToOString(para, RTL_TEXTENCODING_ASCII_US);
108 OString value_tmp = OUStringToOString(value, RTL_TEXTENCODING_ASCII_US);
110 fprintf(stderr, "para(%s) != value(%s)\n", para_tmp.getStr(), value_tmp.getStr());
113 else
114 fprintf(stderr, "bootstrap parameter couldn't be found\n");
116 // test the default case
117 name = OUString( RTL_CONSTASCII_USTRINGPARAM( "no_one_has_set_this_name" ) );
118 OSL_ASSERT( ! bootstrap.getFrom( name, value ) );
119 result = result && !bootstrap.getFrom( name, value );
121 myDefault = OUString( RTL_CONSTASCII_USTRINGPARAM( "1" ) );
122 OUString myDefault2 = OUString( RTL_CONSTASCII_USTRINGPARAM( "2" ) );
124 bootstrap.getFrom( name, value, myDefault );
125 OSL_ASSERT( value == myDefault );
126 result = result && (value == myDefault);
128 bootstrap.getFrom( name, value, myDefault2 );
129 OSL_ASSERT( value == myDefault2 );
130 result = result && (value == myDefault2);
132 return result;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */