xref: /trunk/main/stoc/test/testsmgr.cxx (revision 647a425c)
1*647a425cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*647a425cSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*647a425cSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*647a425cSAndrew Rist  * distributed with this work for additional information
6*647a425cSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*647a425cSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*647a425cSAndrew Rist  * "License"); you may not use this file except in compliance
9*647a425cSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*647a425cSAndrew Rist  *
11*647a425cSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647a425cSAndrew Rist  *
13*647a425cSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*647a425cSAndrew Rist  * software distributed under the License is distributed on an
15*647a425cSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647a425cSAndrew Rist  * KIND, either express or implied.  See the License for the
17*647a425cSAndrew Rist  * specific language governing permissions and limitations
18*647a425cSAndrew Rist  * under the License.
19*647a425cSAndrew Rist  *
20*647a425cSAndrew Rist  *************************************************************/
21*647a425cSAndrew Rist 
22*647a425cSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_stoc.hxx"
26cdf0e10cSrcweir #include <stdio.h>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <sal/main.h>
29cdf0e10cSrcweir #include <osl/process.h>
30cdf0e10cSrcweir #include <registry/registry.hxx>
31cdf0e10cSrcweir #include <uno/mapping.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <com/sun/star/registry/XSimpleRegistry.hpp>
34cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
35cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir extern "C" void SAL_CALL test_ServiceManager();
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #ifndef FALSE
40cdf0e10cSrcweir #define FALSE 0
41cdf0e10cSrcweir #endif
42cdf0e10cSrcweir 
43cdf0e10cSrcweir #ifndef TRUE
44cdf0e10cSrcweir #define TRUE 1
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
48cdf0e10cSrcweir #define TEST_ENSHURE(c, m)   OSL_ENSURE(c, m)
49cdf0e10cSrcweir #else
50cdf0e10cSrcweir #define TEST_ENSHURE(c, m)   OSL_VERIFY(c)
51cdf0e10cSrcweir #endif
52cdf0e10cSrcweir 
53cdf0e10cSrcweir 
54cdf0e10cSrcweir using namespace ::rtl;
55cdf0e10cSrcweir OString userRegEnv("STAR_USER_REGISTRY=");
56cdf0e10cSrcweir 
getExePath()57cdf0e10cSrcweir OUString getExePath()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir 	OUString 		exe;
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	OSL_VERIFY( osl_getExecutableFile( &exe.pData) == osl_Process_E_None);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir #if defined(WIN32) || defined(__OS2__) || defined(WNT)
64cdf0e10cSrcweir 	exe = exe.copy(0, exe.getLength() - 16);
65cdf0e10cSrcweir #else
66cdf0e10cSrcweir 	exe = exe.copy(0, exe.getLength() - 12);
67cdf0e10cSrcweir #endif
68cdf0e10cSrcweir 	return exe;
69cdf0e10cSrcweir }
70cdf0e10cSrcweir 
setStarUserRegistry()71cdf0e10cSrcweir void setStarUserRegistry()
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	Registry *myRegistry = new Registry();
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	RegistryKey rootKey, rKey, rKey2;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 	OUString userReg = getExePath();
78cdf0e10cSrcweir 	userReg += OUString::createFromAscii("user.rdb");
79cdf0e10cSrcweir 	if(myRegistry->open(userReg, REG_READWRITE))
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 		TEST_ENSHURE(!myRegistry->create(userReg), "setStarUserRegistry error 1");
82cdf0e10cSrcweir 	}
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	TEST_ENSHURE(!myRegistry->close(), "setStarUserRegistry error 9");
85cdf0e10cSrcweir 	delete myRegistry;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	userRegEnv += OUStringToOString(userReg, RTL_TEXTENCODING_ASCII_US);
88cdf0e10cSrcweir 	putenv((char *)userRegEnv.getStr());
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 
SAL_IMPLEMENT_MAIN()92cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	printf( "ServiceManagerTest : \r");
95cdf0e10cSrcweir 	setStarUserRegistry();
96cdf0e10cSrcweir 	fflush( stdout );
97cdf0e10cSrcweir 	test_ServiceManager();
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	printf( "ServiceManagerTest : OK\n" );
100cdf0e10cSrcweir     return 0;
101cdf0e10cSrcweir }
102