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