xref: /trunk/main/stoc/test/testsmgr.cxx (revision 647a425c)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_stoc.hxx"
26 #include <stdio.h>
27 
28 #include <sal/main.h>
29 #include <osl/process.h>
30 #include <registry/registry.hxx>
31 #include <uno/mapping.hxx>
32 
33 #include <com/sun/star/registry/XSimpleRegistry.hpp>
34 #include <com/sun/star/lang/XServiceInfo.hpp>
35 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
36 
37 extern "C" void SAL_CALL test_ServiceManager();
38 
39 #ifndef FALSE
40 #define FALSE 0
41 #endif
42 
43 #ifndef TRUE
44 #define TRUE 1
45 #endif
46 
47 #if OSL_DEBUG_LEVEL > 0
48 #define TEST_ENSHURE(c, m)   OSL_ENSURE(c, m)
49 #else
50 #define TEST_ENSHURE(c, m)   OSL_VERIFY(c)
51 #endif
52 
53 
54 using namespace ::rtl;
55 OString userRegEnv("STAR_USER_REGISTRY=");
56 
getExePath()57 OUString getExePath()
58 {
59 	OUString 		exe;
60 
61 	OSL_VERIFY( osl_getExecutableFile( &exe.pData) == osl_Process_E_None);
62 
63 #if defined(WIN32) || defined(__OS2__) || defined(WNT)
64 	exe = exe.copy(0, exe.getLength() - 16);
65 #else
66 	exe = exe.copy(0, exe.getLength() - 12);
67 #endif
68 	return exe;
69 }
70 
setStarUserRegistry()71 void setStarUserRegistry()
72 {
73 	Registry *myRegistry = new Registry();
74 
75 	RegistryKey rootKey, rKey, rKey2;
76 
77 	OUString userReg = getExePath();
78 	userReg += OUString::createFromAscii("user.rdb");
79 	if(myRegistry->open(userReg, REG_READWRITE))
80 	{
81 		TEST_ENSHURE(!myRegistry->create(userReg), "setStarUserRegistry error 1");
82 	}
83 
84 	TEST_ENSHURE(!myRegistry->close(), "setStarUserRegistry error 9");
85 	delete myRegistry;
86 
87 	userRegEnv += OUStringToOString(userReg, RTL_TEXTENCODING_ASCII_US);
88 	putenv((char *)userRegEnv.getStr());
89 }
90 
91 
SAL_IMPLEMENT_MAIN()92 SAL_IMPLEMENT_MAIN()
93 {
94 	printf( "ServiceManagerTest : \r");
95 	setStarUserRegistry();
96 	fflush( stdout );
97 	test_ServiceManager();
98 
99 	printf( "ServiceManagerTest : OK\n" );
100     return 0;
101 }
102