Branch libreoffice-5-0-4
[LibreOffice.git] / cppuhelper / test / bootstrap / TestEnv.cxx
blob0a08b54bd559600dc0817241df533a6c581bac64
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <cppu/EnvDcp.hxx>
23 #include <cppu/helper/purpenv/Environment.hxx>
24 #include <cppu/helper/purpenv/Mapping.hxx>
28 #define LOG_LIFECYCLE_TestEnv
29 #ifdef LOG_LIFECYCLE_TestEnv
30 # include <iostream>
31 # define LOG_LIFECYCLE_TestEnv_emit(x) x
33 #else
34 # define LOG_LIFECYCLE_TestEnv_emit(x)
36 #endif
39 class TestEnv : public cppu::Enterable
41 int m_inCount;
43 virtual ~TestEnv();
45 public:
46 explicit TestEnv();
48 protected:
49 virtual void v_enter();
50 virtual void v_leave();
52 virtual void v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam);
53 virtual void v_callOut_v (uno_EnvCallee * pCallee, va_list * pParam);
55 virtual bool v_isValid (rtl::OUString * pReason);
58 TestEnv::TestEnv()
59 : m_inCount(0)
61 LOG_LIFECYCLE_TestEnv_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestEnv::TestEnv(...)", this));
64 TestEnv::~TestEnv()
66 LOG_LIFECYCLE_TestEnv_emit(fprintf(stderr, "LIFE: %s -> %p\n", "TestEnv::~TestEnv()", this));
70 void TestEnv::v_callInto_v(uno_EnvCallee * pCallee, va_list * pParam)
72 ++ m_inCount;
73 pCallee(pParam);
74 -- m_inCount;
77 void TestEnv::v_callOut_v(uno_EnvCallee * pCallee, va_list * pParam)
79 -- m_inCount;
80 pCallee(pParam);
81 ++ m_inCount;
84 void TestEnv::v_enter()
86 ++ m_inCount;
89 void TestEnv::v_leave()
91 -- m_inCount;
94 bool TestEnv::v_isValid(rtl::OUString * pReason)
96 bool result = m_inCount & 1;
98 if (result)
99 *pReason = rtl::OUString("OK");
101 else
102 *pReason = rtl::OUString("not entered/invoked");
104 return result;
107 extern "C" void SAL_CALL uno_initEnvironment(uno_Environment * pEnv) SAL_THROW_EXTERN_C()
109 cppu::helper::purpenv::Environment_initWithEnterable(pEnv, new TestEnv());
112 extern "C" void uno_ext_getMapping(uno_Mapping ** ppMapping,
113 uno_Environment * pFrom,
114 uno_Environment * pTo )
116 cppu::helper::purpenv::createMapping(ppMapping, pFrom, pTo);
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */