xref: /trunk/main/stoc/test/testsmgr.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_stoc.hxx"
30 #include <stdio.h>
31 
32 #include <sal/main.h>
33 #include <osl/process.h>
34 #include <registry/registry.hxx>
35 #include <uno/mapping.hxx>
36 
37 #include <com/sun/star/registry/XSimpleRegistry.hpp>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
40 
41 extern "C" void SAL_CALL test_ServiceManager();
42 
43 #ifndef FALSE
44 #define FALSE 0
45 #endif
46 
47 #ifndef TRUE
48 #define TRUE 1
49 #endif
50 
51 #if OSL_DEBUG_LEVEL > 0
52 #define TEST_ENSHURE(c, m)   OSL_ENSURE(c, m)
53 #else
54 #define TEST_ENSHURE(c, m)   OSL_VERIFY(c)
55 #endif
56 
57 
58 using namespace ::rtl;
59 OString userRegEnv("STAR_USER_REGISTRY=");
60 
61 OUString getExePath()
62 {
63 	OUString 		exe;
64 
65 	OSL_VERIFY( osl_getExecutableFile( &exe.pData) == osl_Process_E_None);
66 
67 #if defined(WIN32) || defined(__OS2__) || defined(WNT)
68 	exe = exe.copy(0, exe.getLength() - 16);
69 #else
70 	exe = exe.copy(0, exe.getLength() - 12);
71 #endif
72 	return exe;
73 }
74 
75 void setStarUserRegistry()
76 {
77 	Registry *myRegistry = new Registry();
78 
79 	RegistryKey rootKey, rKey, rKey2;
80 
81 	OUString userReg = getExePath();
82 	userReg += OUString::createFromAscii("user.rdb");
83 	if(myRegistry->open(userReg, REG_READWRITE))
84 	{
85 		TEST_ENSHURE(!myRegistry->create(userReg), "setStarUserRegistry error 1");
86 	}
87 
88 	TEST_ENSHURE(!myRegistry->close(), "setStarUserRegistry error 9");
89 	delete myRegistry;
90 
91 	userRegEnv += OUStringToOString(userReg, RTL_TEXTENCODING_ASCII_US);
92 	putenv((char *)userRegEnv.getStr());
93 }
94 
95 
96 SAL_IMPLEMENT_MAIN()
97 {
98 	printf( "ServiceManagerTest : \r");
99 	setStarUserRegistry();
100 	fflush( stdout );
101 	test_ServiceManager();
102 
103 	printf( "ServiceManagerTest : OK\n" );
104     return 0;
105 }
106