xref: /trunk/main/cppuhelper/test/bootstrap/TestEnv.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
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_cppuhelper.hxx"
30 
31 #include "cppu/EnvDcp.hxx"
32 
33 #include "cppu/helper/purpenv/Environment.hxx"
34 #include "cppu/helper/purpenv/Mapping.hxx"
35 
36 
37 
38 #define LOG_LIFECYCLE_TestEnv
39 #ifdef LOG_LIFECYCLE_TestEnv
40 #  include <iostream>
41 #  define LOG_LIFECYCLE_TestEnv_emit(x) x
42 
43 #else
44 #  define LOG_LIFECYCLE_TestEnv_emit(x)
45 
46 #endif
47 
48 
49 class SAL_DLLPRIVATE TestEnv : public cppu::Enterable
50 {
51     int m_inCount;
52 
53     virtual  ~TestEnv();
54 
55 public:
56     explicit  TestEnv();
57 
58 protected:
59     virtual void v_enter(void);
60     virtual void v_leave(void);
61 
62     virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam);
63     virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam);
64 
65     virtual int  v_isValid   (rtl::OUString * pReason);
66 };
67 
68 TestEnv::TestEnv()
69     : m_inCount(0)
70 {
71     LOG_LIFECYCLE_TestEnv_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestEnv::TestEnv(...)", this));
72 }
73 
74 TestEnv::~TestEnv(void)
75 {
76     LOG_LIFECYCLE_TestEnv_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestEnv::~TestEnv(void)", this));
77 }
78 
79 
80 void TestEnv::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
81 {
82     ++ m_inCount;
83     pCallee(pParam);
84     -- m_inCount;
85 }
86 
87 void TestEnv::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
88 {
89     -- m_inCount;
90     pCallee(pParam);
91     ++ m_inCount;
92 }
93 
94 void TestEnv::v_enter(void)
95 {
96     ++ m_inCount;
97 }
98 
99 void TestEnv::v_leave(void)
100 {
101     -- m_inCount;
102 }
103 
104 int  TestEnv::v_isValid(rtl::OUString * pReason)
105 {
106     int result = m_inCount & 1;
107 
108     if (result)
109         *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OK"));
110 
111     else
112         *pReason = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("not entered/invoked"));
113 
114     return result;
115 }
116 
117 extern "C" void SAL_CALL uno_initEnvironment(uno_Environment * pEnv) SAL_THROW_EXTERN_C()
118 {
119     cppu::helper::purpenv::Environment_initWithEnterable(pEnv, new TestEnv());
120 }
121 
122 extern "C" void uno_ext_getMapping(uno_Mapping     ** ppMapping,
123                                    uno_Environment  * pFrom,
124                                    uno_Environment  * pTo )
125 {
126     cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo);
127 }
128 
129