1*87d2adbcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*87d2adbcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*87d2adbcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*87d2adbcSAndrew Rist * distributed with this work for additional information
6*87d2adbcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*87d2adbcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*87d2adbcSAndrew Rist * "License"); you may not use this file except in compliance
9*87d2adbcSAndrew Rist * with the License. You may obtain a copy of the License at
10*87d2adbcSAndrew Rist *
11*87d2adbcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*87d2adbcSAndrew Rist *
13*87d2adbcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*87d2adbcSAndrew Rist * software distributed under the License is distributed on an
15*87d2adbcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*87d2adbcSAndrew Rist * KIND, either express or implied. See the License for the
17*87d2adbcSAndrew Rist * specific language governing permissions and limitations
18*87d2adbcSAndrew Rist * under the License.
19*87d2adbcSAndrew Rist *
20*87d2adbcSAndrew Rist *************************************************************/
21*87d2adbcSAndrew Rist
22*87d2adbcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir
25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
26cdf0e10cSrcweir #include "precompiled_sal.hxx"
27cdf0e10cSrcweir #include <stdio.h>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <rtl/process.h>
30cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
31cdf0e10cSrcweir #include <rtl/string.hxx>
32cdf0e10cSrcweir #include <rtl/byteseq.hxx>
33cdf0e10cSrcweir
34cdf0e10cSrcweir #include <osl/process.h>
35cdf0e10cSrcweir
36cdf0e10cSrcweir using namespace ::rtl;
37cdf0e10cSrcweir
38cdf0e10cSrcweir
main(int argc,char * argv[])39cdf0e10cSrcweir int main( int argc, char *argv[] )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir osl_setCommandArgs (argc, argv);
42cdf0e10cSrcweir
43cdf0e10cSrcweir sal_Int32 nCount = rtl_getAppCommandArgCount();
44cdf0e10cSrcweir
45cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
46cdf0e10cSrcweir fprintf( stdout, "rtl-commandargs (%d) real args:%i ", nCount, argc);
47cdf0e10cSrcweir for( sal_Int32 i = 0 ; i < nCount ; i ++ )
48cdf0e10cSrcweir {
49cdf0e10cSrcweir OUString data;
50cdf0e10cSrcweir rtl_getAppCommandArg( i , &(data.pData) );
51cdf0e10cSrcweir OString o = OUStringToOString( data, RTL_TEXTENCODING_ASCII_US );
52cdf0e10cSrcweir fprintf( stdout, " %s", o.getStr() );
53cdf0e10cSrcweir }
54cdf0e10cSrcweir fprintf( stdout, "\n" );
55cdf0e10cSrcweir #endif
56cdf0e10cSrcweir
57cdf0e10cSrcweir if( nCount == 0 )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir printf( "usage : testbootstrap <checkedValueOfMyBootstrapValue>\n" );
60cdf0e10cSrcweir exit( 1 );
61cdf0e10cSrcweir }
62cdf0e10cSrcweir
63cdf0e10cSrcweir
64cdf0e10cSrcweir OUString iniName;
65cdf0e10cSrcweir Bootstrap::get(OUString(RTL_CONSTASCII_USTRINGPARAM("iniName")), iniName, OUString());
66cdf0e10cSrcweir
67cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
68cdf0e10cSrcweir if(iniName.getLength())
69cdf0e10cSrcweir {
70cdf0e10cSrcweir OString tmp_iniName = OUStringToOString(iniName, RTL_TEXTENCODING_ASCII_US);
71cdf0e10cSrcweir fprintf(stderr, "using ini: %s\n", tmp_iniName.getStr());
72cdf0e10cSrcweir }
73cdf0e10cSrcweir #endif
74cdf0e10cSrcweir
75cdf0e10cSrcweir Bootstrap bootstrap(iniName);
76cdf0e10cSrcweir
77cdf0e10cSrcweir
78cdf0e10cSrcweir OUString name( RTL_CONSTASCII_USTRINGPARAM( "MYBOOTSTRAPTESTVALUE" ));
79cdf0e10cSrcweir OUString myDefault( RTL_CONSTASCII_USTRINGPARAM("$Default"));
80cdf0e10cSrcweir
81cdf0e10cSrcweir OUString value;
82cdf0e10cSrcweir sal_Bool useDefault;
83cdf0e10cSrcweir
84cdf0e10cSrcweir OUString aDummy;
85cdf0e10cSrcweir useDefault = bootstrap.getFrom(OUString(RTL_CONSTASCII_USTRINGPARAM("USEDEFAULT")), aDummy);
86cdf0e10cSrcweir
87cdf0e10cSrcweir sal_Bool result = sal_False;
88cdf0e10cSrcweir sal_Bool found = sal_True;
89cdf0e10cSrcweir
90cdf0e10cSrcweir if(useDefault)
91cdf0e10cSrcweir bootstrap.getFrom(name, value, myDefault);
92cdf0e10cSrcweir
93cdf0e10cSrcweir else
94cdf0e10cSrcweir found = bootstrap.getFrom(name, value);
95cdf0e10cSrcweir
96cdf0e10cSrcweir if(found)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir OUString para(OUString::createFromAscii( argv[1] ));
99cdf0e10cSrcweir
100cdf0e10cSrcweir result = para == value;
101cdf0e10cSrcweir
102cdf0e10cSrcweir if(!result)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir OString para_tmp = OUStringToOString(para, RTL_TEXTENCODING_ASCII_US);
105cdf0e10cSrcweir OString value_tmp = OUStringToOString(value, RTL_TEXTENCODING_ASCII_US);
106cdf0e10cSrcweir
107cdf0e10cSrcweir fprintf(stderr, "para(%s) != value(%s)\n", para_tmp.getStr(), value_tmp.getStr());
108cdf0e10cSrcweir }
109cdf0e10cSrcweir }
110cdf0e10cSrcweir else
111cdf0e10cSrcweir fprintf(stderr, "bootstrap parameter couldn't be found\n");
112cdf0e10cSrcweir
113cdf0e10cSrcweir // test the default case
114cdf0e10cSrcweir name = OUString( RTL_CONSTASCII_USTRINGPARAM( "no_one_has_set_this_name" ) );
115cdf0e10cSrcweir OSL_ASSERT( ! bootstrap.getFrom( name, value ) );
116cdf0e10cSrcweir result = result && !bootstrap.getFrom( name, value );
117cdf0e10cSrcweir
118cdf0e10cSrcweir myDefault = OUString( RTL_CONSTASCII_USTRINGPARAM( "1" ) );
119cdf0e10cSrcweir OUString myDefault2 = OUString( RTL_CONSTASCII_USTRINGPARAM( "2" ) );
120cdf0e10cSrcweir
121cdf0e10cSrcweir bootstrap.getFrom( name, value, myDefault );
122cdf0e10cSrcweir OSL_ASSERT( value == myDefault );
123cdf0e10cSrcweir result = result && (value == myDefault);
124cdf0e10cSrcweir
125cdf0e10cSrcweir bootstrap.getFrom( name, value, myDefault2 );
126cdf0e10cSrcweir OSL_ASSERT( value == myDefault2 );
127cdf0e10cSrcweir result = result && (value == myDefault2);
128cdf0e10cSrcweir
129cdf0e10cSrcweir return result;
130cdf0e10cSrcweir }
131