xref: /trunk/main/svl/qa/complex/ConfigItems/helper/ConfigItemTest.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
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 #include "HistoryOptTest.hxx"
25 // #include "AccessibilityOptTest.hxx"
26 // #include "PrintOptTest.hxx"
27 #include "UserOptTest.hxx"
28 
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/task/XJob.hpp>
32 #include <com/sun/star/beans/NamedValue.hpp>
33 
34 #include <sal/config.h>
35 #include <rtl/ustring.hxx>
36 #include <cppuhelper/implbase2.hxx>
37 #include <cppuhelper/implementationentry.hxx>
38 
39 //=============================================================================
40 namespace css = ::com::sun::star;
41 
42 namespace svl{
43 
44 //=============================================================================
45 static const ::rtl::OUString PROP_TEST                  = ::rtl::OUString::createFromAscii("Test");
46 static const ::rtl::OUString TEST_PICKLIST              = ::rtl::OUString::createFromAscii("checkPicklist");
47 static const ::rtl::OUString TEST_URLHISTORY            = ::rtl::OUString::createFromAscii("checkURLHistory");
48 static const ::rtl::OUString TEST_HELPBOOKMARKS         = ::rtl::OUString::createFromAscii("checkHelpBookmarks");
49 // static const ::rtl::OUString TEST_ACCESSIBILITYOPTIONS  = ::rtl::OUString::createFromAscii("checkAccessibilityOptions");
50 // static const ::rtl::OUString TEST_PRINTOPTIONS          = ::rtl::OUString::createFromAscii("checkPrintOptions");
51 static const ::rtl::OUString TEST_USEROPTIONS           = ::rtl::OUString::createFromAscii("checkUserOptions");
52 
53 //=============================================================================
54 class ConfigItemTest : public ::cppu::WeakImplHelper2< css::task::XJob         ,
55                                                         css::lang::XServiceInfo >
56 {
57     //-------------------------------------------------------------------------
58     // interface
59     public:
60         explicit ConfigItemTest(const css::uno::Reference< css::uno::XComponentContext >& xContext);
61 
62         // css::task::XJob
63         virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments);
64 
65         // css::lang::XServiceInfo
66         virtual ::rtl::OUString SAL_CALL getImplementationName();
67 
68         virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString& sServiceName);
69 
70         virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames();
71 
72     //-------------------------------------------------------------------------
73     // internal
74     private:
75         ConfigItemTest(ConfigItemTest &); // not defined
76         virtual ~ConfigItemTest() {}
77         void operator=(ConfigItemTest &); // not defined
78 
79     //-------------------------------------------------------------------------
80     // helper for registration !
81     public:
82         static ::rtl::OUString SAL_CALL st_getImplementationName();
83         static css::uno::Sequence< ::rtl::OUString > SAL_CALL st_getSupportedServiceNames();
84         static css::uno::Reference< css::uno::XInterface > SAL_CALL st_create(const css::uno::Reference< css::uno::XComponentContext >& XContext);
85 
86     //-------------------------------------------------------------------------
87     // member
88     private:
89         css::uno::Reference< css::uno::XComponentContext >  m_xContext;
90 };
91 
92 //=============================================================================
93 ConfigItemTest::ConfigItemTest(const css::uno::Reference< css::uno::XComponentContext >& xContext)
94     : m_xContext(xContext)
95 {}
96 
97 //=============================================================================
98 // css::task::XJob
99 css::uno::Any SAL_CALL ConfigItemTest::execute(const css::uno::Sequence< css::beans::NamedValue >& lArguments)
100 {
101     ::rtl::OUString sTest;
102     ::sal_Int32     i    = 0;
103     ::sal_Int32     c    = lArguments.getLength();
104     for (i=0; i<c; ++i)
105     {
106         const css::beans::NamedValue& rArg = lArguments[0];
107         if (rArg.Name.equals(PROP_TEST))
108             rArg.Value >>= sTest;
109     }
110 
111     if (sTest.equals(TEST_PICKLIST))
112     {
113         HistoryOptTest aOptTest;
114         aOptTest.checkPicklist();
115     }
116     else if (sTest.equals(TEST_URLHISTORY))
117     {
118         HistoryOptTest aOptTest;
119         aOptTest.checkURLHistory();
120     }
121     else if (sTest.equals(TEST_HELPBOOKMARKS))
122     {
123         HistoryOptTest aOptTest;
124         aOptTest.checkHelpBookmarks();
125     }
126 //  else if (sTest.equals(TEST_ACCESSIBILITYOPTIONS))
127 //  {
128 //      AccessibilityOptTest aOptTest;
129 //      aOptTest.impl_checkAccessibilityOptions();
130 //  }
131 //  else if (sTest.equals(TEST_PRINTOPTIONS))
132 //  {
133 //         PrintOptTest aOptTest;
134 //         aOptTest.impl_checkPrint();
135 //  }
136     else if (sTest.equals(TEST_USEROPTIONS))
137     {
138         UserOptTest aOptTest;
139         aOptTest.impl_checkUserData();
140     }
141 
142     return css::uno::Any();
143 }
144 
145 //=============================================================================
146 // com::sun::star::uno::XServiceInfo
147 ::rtl::OUString SAL_CALL ConfigItemTest::getImplementationName()
148 {
149     return ConfigItemTest::st_getImplementationName();
150 }
151 
152 //=============================================================================
153 // com::sun::star::uno::XServiceInfo
154 ::sal_Bool SAL_CALL ConfigItemTest::supportsService(const ::rtl::OUString& sServiceName)
155 {
156     css::uno::Sequence< ::rtl::OUString > lServiceNames = ConfigItemTest::st_getSupportedServiceNames();
157     for (::sal_Int32 i = 0; i < lServiceNames.getLength(); ++i)
158     {
159         if (lServiceNames[i].equals(sServiceName))
160             return sal_True;
161     }
162     return sal_False;
163 }
164 
165 //=============================================================================
166 // com::sun::star::uno::XServiceInfo
167 css::uno::Sequence< ::rtl::OUString > SAL_CALL ConfigItemTest::getSupportedServiceNames()
168 {
169     return ConfigItemTest::st_getSupportedServiceNames();
170 }
171 
172 //=============================================================================
173 ::rtl::OUString SAL_CALL ConfigItemTest::st_getImplementationName()
174 {
175     return ::rtl::OUString::createFromAscii("com.sun.star.comp.svl.ConfigItemTest");
176 }
177 
178 //=============================================================================
179 css::uno::Sequence< ::rtl::OUString > SAL_CALL ConfigItemTest::st_getSupportedServiceNames()
180 {
181     css::uno::Sequence< ::rtl::OUString > lServices(1);
182     lServices[0] = ::rtl::OUString::createFromAscii("com.sun.star.test.ConfigItems");
183     return lServices;
184 }
185 
186 //=============================================================================
187 css::uno::Reference< css::uno::XInterface > SAL_CALL ConfigItemTest::st_create(const css::uno::Reference< css::uno::XComponentContext >& xContext)
188 {
189     ConfigItemTest*                            pObject = new ConfigItemTest(xContext);
190     css::uno::Reference< css::uno::XInterface > xObject (static_cast< ::cppu::OWeakObject* >(pObject));
191     return xObject;
192 }
193 
194 } // namespace svl
195 
196 //=============================================================================
197 static ::cppu::ImplementationEntry const lRegEntries[] =
198 {
199     {
200         &::svl::ConfigItemTest::st_create,
201         &::svl::ConfigItemTest::st_getImplementationName,
202         &::svl::ConfigItemTest::st_getSupportedServiceNames,
203         &::cppu::createSingleComponentFactory, 0, 0
204     },
205 
206     { 0, 0, 0, 0, 0, 0 }
207 };
208 
209 //=============================================================================
210 extern "C" void SAL_CALL component_getImplementationEnvironment(const char**            pEnvTypeName,
211                                                                       uno_Environment**             )
212 {
213     *pEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
214 }
215 
216 //=============================================================================
217 extern "C" void * SAL_CALL component_getFactory(const char* sImplName      ,
218                                                       void* pServiceManager,
219                                                       void* pRegistryKey   )
220 {
221     return ::cppu::component_getFactoryHelper(sImplName, pServiceManager, pRegistryKey, lRegEntries);
222 }
223 
224 //=============================================================================
225 extern "C" sal_Bool SAL_CALL component_writeInfo(void* pServiceManager,
226                                                  void* pRegistryKey   )
227 {
228     return ::cppu::component_writeInfoHelper(pServiceManager, pRegistryKey, lRegEntries);
229 }
230