bump product version to 6.4.0.3
[LibreOffice.git] / stoc / test / registry_tdprovider / testregistrytdprovider.cxx
blob359c4b789f3b69f10225c4288462e902168a93a6
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 <com/sun/star/beans/XPropertySet.hpp>
22 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
23 #include <com/sun/star/lang/XMain.hpp>
24 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
25 #include <com/sun/star/reflection/XCompoundTypeDescription.hpp>
26 #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
27 #include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp>
28 #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
29 #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
30 #include <com/sun/star/reflection/XPublished.hpp>
31 #include <com/sun/star/reflection/XServiceTypeDescription2.hpp>
32 #include <com/sun/star/reflection/XSingletonTypeDescription2.hpp>
33 #include <com/sun/star/reflection/XStructTypeDescription.hpp>
34 #include <com/sun/star/reflection/XTypeDescription.hpp>
35 #include <com/sun/star/registry/InvalidRegistryException.hpp>
36 #include <com/sun/star/registry/XRegistryKey.hpp>
37 #include <com/sun/star/uno/Any.hxx>
38 #include <com/sun/star/uno/Exception.hpp>
39 #include <com/sun/star/uno/Reference.hxx>
40 #include <com/sun/star/uno/RuntimeException.hpp>
41 #include <com/sun/star/uno/Sequence.hxx>
42 #include <com/sun/star/uno/TypeClass.hpp>
43 #include <com/sun/star/uno/XComponentContext.hpp>
44 #include <com/sun/star/uno/XInterface.hpp>
45 #include <cppuhelper/factory.hxx>
46 #include <cppuhelper/implbase.hxx>
47 #include <cppuhelper/weak.hxx>
48 #include <rtl/textenc.h>
49 #include <rtl/ustring.h>
50 #include <rtl/ustring.hxx>
51 #include <sal/types.h>
52 #include <uno/environment.h>
54 #include /*MSVC trouble: <cstdlib>*/ <stdlib.h>
55 #include <iostream>
56 #include <ostream>
58 namespace {
60 class Service: public cppu::WeakImplHelper< css::lang::XMain > {
61 public:
62 virtual sal_Int32 SAL_CALL
63 run(css::uno::Sequence< OUString > const & arguments)
64 throw (css::uno::RuntimeException);
66 static OUString getImplementationName();
68 static css::uno::Sequence< OUString > getSupportedServiceNames();
70 static css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance(
71 css::uno::Reference< css::uno::XComponentContext > const & context)
72 throw (css::uno::Exception);
74 private:
75 explicit Service(
76 css::uno::Reference< css::uno::XComponentContext > const & context):
77 m_context(context)
80 css::uno::Reference< css::uno::XComponentContext > m_context;
85 namespace {
87 std::ostream & operator <<(std::ostream & out, OUString const & value) {
88 return out << OUStringToOString(value, RTL_TEXTENCODING_UTF8).getStr();
91 void assertTrue(bool argument) {
92 if (!argument) {
93 std::cerr
94 << "assertTrue(" << argument << ") failed" << std::endl;
95 /*MSVC trouble: std::*/abort();
99 void assertFalse(bool argument) {
100 if (argument) {
101 std::cerr
102 << "assertFalse(" << argument << ") failed" << std::endl;
103 /*MSVC trouble: std::*/abort();
107 template< typename T > void assertEqual(T const & value, T const & argument) {
108 if (argument != value) {
109 std::cerr
110 << "assertEqual(" << value << ", " << argument << ") failed"
111 << std::endl;
112 /*MSVC trouble: std::*/abort();
118 sal_Int32 Service::run(css::uno::Sequence< OUString > const &)
119 throw (css::uno::RuntimeException)
121 css::uno::Reference< css::lang::XMultiComponentFactory > factory(
122 m_context->getServiceManager());
123 assertTrue(factory.is());
124 css::uno::Sequence< css::uno::Any > args(1);
125 args[0] = css::uno::Reference< css::beans::XPropertySet >(
126 factory, css::uno::UNO_QUERY_THROW)->getPropertyValue(
127 OUString("Registry"));
128 css::uno::Reference< css::container::XHierarchicalNameAccess > provider(
129 factory->createInstanceWithArgumentsAndContext(
130 "com.sun.star.comp.stoc.RegistryTypeDescriptionProvider",
131 args, m_context),
132 css::uno::UNO_QUERY_THROW);
134 // The following assumes that interface members are sorted by increasing
135 // values of XInterfaceMemberTypeDescription.getPosition, the exceptions
136 // of interface attributes and interface methods, the constructors of
137 // services, and the exceptions of service constructors are sorted as given
138 // in the UNOIDL source code:
140 assertEqual< bool >(
141 false,
142 provider->hasByHierarchicalName(
143 OUString( "[][]boolean")));
144 assertEqual< bool >(
145 false,
146 provider->hasByHierarchicalName(
147 OUString( "test.registrytdprovider.Struct3<boolean,boolean>")));
148 assertEqual< bool >(
149 false,
150 provider->hasByHierarchicalName(
151 OUString( "com.sun.star.uno.XComponentContext::getValueByName")));
153 css::uno::Reference< css::reflection::XCompoundTypeDescription > exception;
154 exception.set(
155 provider->getByHierarchicalName(
156 OUString( "com.sun.star.uno.Exception")),
157 css::uno::UNO_QUERY_THROW);
158 assertEqual(css::uno::TypeClass_EXCEPTION, exception->getTypeClass());
159 assertEqual( OUString( "com.sun.star.uno.Exception"),
160 exception->getName());
161 assertFalse(exception->getBaseType().is());
162 exception.set(
163 provider->getByHierarchicalName(
164 OUString( "com.sun.star.uno.RuntimeException")),
165 css::uno::UNO_QUERY_THROW);
166 assertEqual(css::uno::TypeClass_EXCEPTION, exception->getTypeClass());
167 assertEqual( OUString( "com.sun.star.uno.RuntimeException"),
168 exception->getName());
169 assertEqual( OUString( "com.sun.star.uno.Exception"),
170 exception->getBaseType()->getName());
172 css::uno::Reference< css::reflection::XStructTypeDescription > structure;
174 structure.set(
175 provider->getByHierarchicalName(
176 OUString( "test.registrytdprovider.Struct2")),
177 css::uno::UNO_QUERY_THROW);
178 assertEqual(css::uno::TypeClass_STRUCT, structure->getTypeClass());
179 assertEqual( OUString( "test.registrytdprovider.Struct2"),
180 structure->getName());
181 assertFalse(structure->getBaseType().is());
182 assertEqual< sal_Int32 >(1, structure->getMemberTypes().getLength());
183 assertEqual(
184 OUString( "test.registrytdprovider.Struct1"),
185 structure->getMemberTypes()[0]->getName());
186 assertEqual< sal_Int32 >(1, structure->getMemberNames().getLength());
187 assertEqual(
188 OUString("s1"),
189 structure->getMemberNames()[0]);
190 assertEqual< sal_Int32 >(0, structure->getTypeParameters().getLength());
191 assertEqual< sal_Int32 >(0, structure->getTypeArguments().getLength());
193 structure.set(
194 provider->getByHierarchicalName(
195 OUString( "test.registrytdprovider.Struct3")),
196 css::uno::UNO_QUERY_THROW);
197 assertEqual(css::uno::TypeClass_STRUCT, structure->getTypeClass());
198 assertEqual(
199 OUString( "test.registrytdprovider.Struct3"),
200 structure->getName());
201 assertFalse(structure->getBaseType().is());
202 assertEqual< sal_Int32 >(1, structure->getMemberTypes().getLength());
203 assertEqual(
204 css::uno::TypeClass_UNKNOWN,
205 structure->getMemberTypes()[0]->getTypeClass());
206 assertEqual(
207 OUString("U"),
208 structure->getMemberTypes()[0]->getName());
209 assertEqual< sal_Int32 >(1, structure->getMemberNames().getLength());
210 assertEqual(
211 OUString("s2"),
212 structure->getMemberNames()[0]);
213 assertEqual< sal_Int32 >(2, structure->getTypeParameters().getLength());
214 assertEqual(
215 OUString("T"),
216 structure->getTypeParameters()[0]);
217 assertEqual(
218 OUString("U"),
219 structure->getTypeParameters()[1]);
220 assertEqual< sal_Int32 >(0, structure->getTypeArguments().getLength());
222 structure.set(
223 provider->getByHierarchicalName(
224 OUString( "test.registrytdprovider.Struct4")),
225 css::uno::UNO_QUERY_THROW);
226 assertEqual(css::uno::TypeClass_STRUCT, structure->getTypeClass());
227 assertEqual(
228 OUString( "test.registrytdprovider.Struct4"),
229 structure->getName());
230 assertEqual(
231 OUString( "test.registrytdprovider.Struct2"),
232 structure->getBaseType()->getName());
233 assertEqual< sal_Int32 >(1, structure->getMemberTypes().getLength());
234 assertEqual(
235 OUString( "test.registrytdprovider.Struct3<"
236 "test.registrytdprovider.Struct2,"
237 "test.registrytdprovider.Struct3<boolean,any>>"),
238 structure->getMemberTypes()[0]->getName());
239 assertEqual< sal_Int32 >(1, structure->getMemberNames().getLength());
240 assertEqual(
241 OUString("s2"),
242 structure->getMemberNames()[0]);
243 assertEqual< sal_Int32 >(0, structure->getTypeParameters().getLength());
244 assertEqual< sal_Int32 >(0, structure->getTypeArguments().getLength());
246 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >
247 interface;
249 interface.set(
250 provider->getByHierarchicalName(
251 OUString( "test.registrytdprovider.XTest1")),
252 css::uno::UNO_QUERY_THROW);
253 assertEqual(css::uno::TypeClass_INTERFACE, interface->getTypeClass());
254 assertEqual(
255 OUString( "test.registrytdprovider.XTest1"),
256 interface->getName());
257 css::uno::Sequence<
258 css::uno::Reference< css::reflection::XTypeDescription > > bases(
259 interface->getBaseTypes());
260 assertEqual< sal_Int32 >(1, bases.getLength());
261 assertEqual(
262 OUString( "com.sun.star.uno.XInterface"),
263 bases[0]->getName());
264 css::uno::Sequence<
265 css::uno::Reference< css::reflection::XTypeDescription > >
266 optionalBases(interface->getOptionalBaseTypes());
267 assertEqual< sal_Int32 >(1, optionalBases.getLength());
268 assertEqual(
269 OUString(
270 "test.registrytdprovider.XBase"),
271 optionalBases[0]->getName());
272 css::uno::Sequence<
273 css::uno::Reference<
274 css::reflection::XInterfaceMemberTypeDescription > > members(
275 interface->getMembers());
276 assertEqual< sal_Int32 >(5, members.getLength());
278 css::uno::Reference< css::reflection::XInterfaceAttributeTypeDescription2 >
279 attribute;
280 css::uno::Sequence<
281 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
282 getExceptions;
283 css::uno::Sequence<
284 css::uno::Reference< css::reflection::XCompoundTypeDescription > >
285 setExceptions;
286 css::uno::Reference< css::reflection::XInterfaceMethodTypeDescription >
287 method;
289 attribute.set( members[0], css::uno::UNO_QUERY_THROW);
290 assertEqual(
291 css::uno::TypeClass_INTERFACE_ATTRIBUTE, attribute->getTypeClass());
292 assertEqual(
293 OUString( "test.registrytdprovider.XTest1::a1"),
294 attribute->getName());
295 assertEqual(
296 OUString("a1"),
297 attribute->getMemberName());
298 assertEqual< sal_Int32 >(3, attribute->getPosition());
299 assertEqual< bool >(false, attribute->isReadOnly());
300 assertEqual(
301 OUString("short"),
302 attribute->getType()->getName());
303 assertEqual< bool >(true, attribute->isBound());
304 getExceptions = attribute->getGetExceptions();
305 assertEqual< sal_Int32 >(0, getExceptions.getLength());
306 setExceptions = attribute->getSetExceptions();
307 assertEqual< sal_Int32 >(0, setExceptions.getLength());
309 attribute.set( members[1], css::uno::UNO_QUERY_THROW);
310 assertEqual(
311 css::uno::TypeClass_INTERFACE_ATTRIBUTE, attribute->getTypeClass());
312 assertEqual(
313 OUString( "test.registrytdprovider.XTest1::a2"),
314 attribute->getName());
315 assertEqual(
316 OUString("a2"),
317 attribute->getMemberName());
318 assertEqual< sal_Int32 >(4, attribute->getPosition());
319 assertEqual< bool >(false, attribute->isReadOnly());
320 assertEqual(
321 OUString("long"),
322 attribute->getType()->getName());
323 assertEqual< bool >(false, attribute->isBound());
324 getExceptions = attribute->getGetExceptions();
325 assertEqual< sal_Int32 >(2, getExceptions.getLength());
326 assertEqual(
327 OUString( "com.sun.star.lang.WrappedTargetException"),
328 getExceptions[0]->getName());
329 assertEqual(
330 OUString( "com.sun.star.uno.RuntimeException"),
331 getExceptions[1]->getName());
332 setExceptions = attribute->getSetExceptions();
333 assertEqual< sal_Int32 >(2, setExceptions.getLength());
334 assertEqual(
335 OUString( "com.sun.star.uno.Exception"),
336 setExceptions[0]->getName());
337 assertEqual(
338 OUString( "com.sun.star.lang.WrappedTargetException"),
339 setExceptions[1]->getName());
341 attribute.set( members[2], css::uno::UNO_QUERY_THROW);
342 assertEqual(
343 css::uno::TypeClass_INTERFACE_ATTRIBUTE, attribute->getTypeClass());
344 assertEqual(
345 OUString(
346 "test.registrytdprovider.XTest1::a3"),
347 attribute->getName());
348 assertEqual(
349 OUString("a3"),
350 attribute->getMemberName());
351 assertEqual< sal_Int32 >(5, attribute->getPosition());
352 assertEqual< bool >(true, attribute->isReadOnly());
353 assertEqual(
354 OUString("hyper"),
355 attribute->getType()->getName());
356 assertEqual< bool >(true, attribute->isBound());
357 getExceptions = attribute->getGetExceptions();
358 assertEqual< sal_Int32 >(1, getExceptions.getLength());
359 assertEqual(
360 OUString( "com.sun.star.lang.WrappedTargetException"),
361 getExceptions[0]->getName());
362 setExceptions = attribute->getSetExceptions();
363 assertEqual< sal_Int32 >(0, setExceptions.getLength());
365 method.set( members[3], css::uno::UNO_QUERY_THROW);
366 assertEqual(css::uno::TypeClass_INTERFACE_METHOD, method->getTypeClass());
367 assertEqual(
368 OUString( "test.registrytdprovider.XTest1::f1"),
369 method->getName());
370 assertEqual(
371 OUString("f1"),
372 method->getMemberName());
373 assertEqual< sal_Int32 >(6, method->getPosition());
374 assertEqual< bool >(false, method->isOneway());
375 assertEqual< sal_Int32 >(1, method->getParameters().getLength());
376 assertEqual(
377 OUString("p"),
378 method->getParameters()[0]->getName());
379 assertEqual(
380 OUString("any"),
381 method->getParameters()[0]->getType()->getName());
382 assertEqual< bool >(false, method->getParameters()[0]->isIn());
383 assertEqual< bool >(true, method->getParameters()[0]->isOut());
384 assertEqual< sal_Int32 >(0, method->getParameters()[0]->getPosition());
385 assertEqual< sal_Int32 >(1, method->getExceptions().getLength());
386 assertEqual(
387 OUString( "com.sun.star.uno.RuntimeException"),
388 method->getExceptions()[0]->getName());
390 method.set( members[4], css::uno::UNO_QUERY_THROW);
391 assertEqual(css::uno::TypeClass_INTERFACE_METHOD, method->getTypeClass());
392 assertEqual(
393 OUString( "test.registrytdprovider.XTest1::f2"),
394 method->getName());
395 assertEqual(
396 OUString("f2"),
397 method->getMemberName());
398 assertEqual< sal_Int32 >(7, method->getPosition());
399 assertEqual< bool >(true, method->isOneway());
400 assertEqual< sal_Int32 >(0, method->getParameters().getLength());
401 assertEqual< sal_Int32 >(0, method->getExceptions().getLength());
403 interface.set(
404 provider->getByHierarchicalName(
405 OUString( "test.registrytdprovider.XTest2")),
406 css::uno::UNO_QUERY_THROW);
407 assertEqual(css::uno::TypeClass_INTERFACE, interface->getTypeClass());
408 assertEqual(
409 OUString( "test.registrytdprovider.XTest2"),
410 interface->getName());
411 assertEqual< sal_Int32 >(1, interface->getBaseTypes().getLength());
412 assertEqual(
413 OUString( "test.registrytdprovider.Typedef2"),
414 interface->getBaseTypes()[0]->getName());
415 assertEqual< sal_Int32 >(0, interface->getOptionalBaseTypes().getLength());
416 assertEqual< sal_Int32 >(0, interface->getMembers().getLength());
418 css::uno::Reference< css::reflection::XServiceTypeDescription2 > service;
420 service.set(
421 provider->getByHierarchicalName(
422 OUString( "test.registrytdprovider.Service1")),
423 css::uno::UNO_QUERY_THROW);
424 assertEqual(css::uno::TypeClass_SERVICE, service->getTypeClass());
425 assertEqual(
426 OUString( "test.registrytdprovider.Service1"),
427 service->getName());
428 assertEqual< sal_Int32 >(0, service->getMandatoryServices().getLength());
429 assertEqual< sal_Int32 >(0, service->getOptionalServices().getLength());
430 assertEqual< sal_Int32 >(0, service->getMandatoryInterfaces().getLength());
431 assertEqual< sal_Int32 >(0, service->getOptionalInterfaces().getLength());
432 assertEqual< bool >(true, service->isSingleInterfaceBased());
433 assertEqual(
434 OUString(
435 "test.registrytdprovider.XTest1"),
436 service->getInterface()->getName());
437 assertEqual< sal_Int32 >(2, service->getConstructors().getLength());
438 assertEqual(
439 OUString("c1"),
440 service->getConstructors()[0]->getName());
441 assertEqual< sal_Int32 >(
442 0, service->getConstructors()[0]->getParameters().getLength());
443 assertEqual< sal_Int32 >(
444 0, service->getConstructors()[0]->getExceptions().getLength());
445 assertEqual(
446 OUString("c2"),
447 service->getConstructors()[1]->getName());
448 assertEqual< sal_Int32 >(
449 1, service->getConstructors()[1]->getParameters().getLength());
450 assertEqual(
451 OUString("p"),
452 service->getConstructors()[1]->getParameters()[0]->getName());
453 assertEqual(
454 OUString("any"),
455 (service->getConstructors()[1]->getParameters()[0]->getType()->
456 getName()));
457 assertEqual< bool >(
458 true, service->getConstructors()[1]->getParameters()[0]->isIn());
459 assertEqual< bool >(
460 false, service->getConstructors()[1]->getParameters()[0]->isOut());
461 assertEqual< sal_Int32 >(
462 0, service->getConstructors()[1]->getParameters()[0]->getPosition());
463 assertEqual< bool >(
464 true,
465 service->getConstructors()[1]->getParameters()[0]->isRestParameter());
466 assertEqual< sal_Int32 >(
467 1, service->getConstructors()[1]->getExceptions().getLength());
468 assertEqual(
469 OUString( "com.sun.star.uno.RuntimeException"),
470 service->getConstructors()[1]->getExceptions()[0]->getName());
472 service.set(
473 provider->getByHierarchicalName(
474 OUString( "test.registrytdprovider.Service2")),
475 css::uno::UNO_QUERY_THROW);
476 assertEqual(css::uno::TypeClass_SERVICE, service->getTypeClass());
477 assertEqual(
478 OUString( "test.registrytdprovider.Service2"),
479 service->getName());
480 assertEqual< sal_Int32 >(0, service->getMandatoryServices().getLength());
481 assertEqual< sal_Int32 >(0, service->getOptionalServices().getLength());
482 assertEqual< sal_Int32 >(1, service->getMandatoryInterfaces().getLength());
483 assertEqual(
484 OUString( "test.registrytdprovider.XTest1"),
485 service->getMandatoryInterfaces()[0]->getName());
486 assertEqual< sal_Int32 >(1, service->getOptionalInterfaces().getLength());
487 assertEqual(
488 OUString( "test.registrytdprovider.XBase"),
489 service->getOptionalInterfaces()[0]->getName());
490 assertEqual< bool >(false, service->isSingleInterfaceBased());
491 assertFalse(service->getInterface().is());
492 assertEqual< sal_Int32 >(0, service->getConstructors().getLength());
494 service.set(
495 provider->getByHierarchicalName(
496 OUString( "test.registrytdprovider.Service3")),
497 css::uno::UNO_QUERY_THROW);
498 assertEqual(css::uno::TypeClass_SERVICE, service->getTypeClass());
499 assertEqual(
500 OUString(
501 "test.registrytdprovider.Service3"),
502 service->getName());
503 assertEqual< sal_Int32 >(0, service->getMandatoryServices().getLength());
504 assertEqual< sal_Int32 >(0, service->getOptionalServices().getLength());
505 assertEqual< sal_Int32 >(0, service->getMandatoryInterfaces().getLength());
506 assertEqual< sal_Int32 >(0, service->getOptionalInterfaces().getLength());
507 assertEqual< bool >(true, service->isSingleInterfaceBased());
508 assertEqual(
509 OUString(
510 "test.registrytdprovider.Typedef2"),
511 service->getInterface()->getName());
512 assertEqual< sal_Int32 >(0, service->getConstructors().getLength());
514 css::uno::Reference< css::reflection::XSingletonTypeDescription2 >
515 singleton;
517 singleton.set(
518 provider->getByHierarchicalName(
519 OUString( "test.registrytdprovider.Singleton1")),
520 css::uno::UNO_QUERY_THROW);
521 assertEqual(css::uno::TypeClass_SINGLETON, singleton->getTypeClass());
522 assertEqual(
523 OUString(
524 "test.registrytdprovider.Singleton1"),
525 singleton->getName());
526 assertFalse(singleton->getService().is());
527 assertEqual< bool >(true, singleton->isInterfaceBased());
528 assertEqual(
529 OUString(
530 "test.registrytdprovider.XTest1"),
531 singleton->getInterface()->getName());
533 singleton.set(
534 provider->getByHierarchicalName(
535 OUString( "test.registrytdprovider.Singleton2")),
536 css::uno::UNO_QUERY_THROW);
537 assertEqual(css::uno::TypeClass_SINGLETON, singleton->getTypeClass());
538 assertEqual(
539 OUString(
540 "test.registrytdprovider.Singleton2"),
541 singleton->getName());
542 assertEqual(
543 OUString(
544 "test.registrytdprovider.Service1"),
545 singleton->getService()->getName());
546 assertEqual< bool >(false, singleton->isInterfaceBased());
547 assertFalse(singleton->getInterface().is());
549 singleton.set(
550 provider->getByHierarchicalName(
551 OUString( "test.registrytdprovider.Singleton3")),
552 css::uno::UNO_QUERY_THROW);
553 assertEqual(css::uno::TypeClass_SINGLETON, singleton->getTypeClass());
554 assertEqual(
555 OUString(
556 "test.registrytdprovider.Singleton3"),
557 singleton->getName());
558 assertFalse(singleton->getService().is());
559 assertEqual< bool >(true, singleton->isInterfaceBased());
560 assertEqual(
561 OUString(
562 "test.registrytdprovider.Typedef2"),
563 singleton->getInterface()->getName());
565 css::uno::Reference< css::reflection::XPublished > published;
566 published.set(
567 css::uno::Reference< css::reflection::XTypeDescription >(
568 provider->getByHierarchicalName(
569 OUString( "test.registrytdprovider.Enum1")),
570 css::uno::UNO_QUERY_THROW),
571 css::uno::UNO_QUERY);
572 assertTrue(published.is());
573 assertTrue(published->isPublished());
574 published.set(
575 css::uno::Reference< css::reflection::XTypeDescription >(
576 provider->getByHierarchicalName(
577 OUString( "test.registrytdprovider.Enum2")),
578 css::uno::UNO_QUERY_THROW),
579 css::uno::UNO_QUERY);
580 assertTrue(published.is());
581 assertFalse(published->isPublished());
582 published.set(
583 css::uno::Reference< css::reflection::XTypeDescription >(
584 provider->getByHierarchicalName(
585 OUString( "test.registrytdprovider.Struct1")),
586 css::uno::UNO_QUERY_THROW),
587 css::uno::UNO_QUERY);
588 assertTrue(published.is());
589 assertTrue(published->isPublished());
590 published.set(
591 css::uno::Reference< css::reflection::XTypeDescription >(
592 provider->getByHierarchicalName(
593 OUString( "test.registrytdprovider.Struct2")),
594 css::uno::UNO_QUERY_THROW),
595 css::uno::UNO_QUERY);
596 assertTrue(published.is());
597 assertFalse(published->isPublished());
598 published.set(
599 css::uno::Reference< css::reflection::XTypeDescription >(
600 provider->getByHierarchicalName(
601 OUString( "test.registrytdprovider.Struct3")),
602 css::uno::UNO_QUERY_THROW),
603 css::uno::UNO_QUERY);
604 assertTrue(published.is());
605 assertTrue(published->isPublished());
606 published.set(
607 css::uno::Reference< css::reflection::XStructTypeDescription >(
608 provider->getByHierarchicalName(
609 OUString( "test.registrytdprovider.Struct3")),
610 css::uno::UNO_QUERY_THROW)->getMemberTypes()[0],
611 css::uno::UNO_QUERY);
612 assertFalse(published.is());
613 published.set(
614 css::uno::Reference< css::reflection::XTypeDescription >(
615 provider->getByHierarchicalName(
616 OUString( "test.registrytdprovider.Struct3a")),
617 css::uno::UNO_QUERY_THROW),
618 css::uno::UNO_QUERY);
619 assertTrue(published.is());
620 assertFalse(published->isPublished());
621 published.set(
622 css::uno::Reference< css::reflection::XTypeDescription >(
623 provider->getByHierarchicalName(
624 OUString( "test.registrytdprovider.Exception1")),
625 css::uno::UNO_QUERY_THROW),
626 css::uno::UNO_QUERY);
627 assertTrue(published.is());
628 assertTrue(published->isPublished());
629 published.set(
630 css::uno::Reference< css::reflection::XTypeDescription >(
631 provider->getByHierarchicalName(
632 OUString( "test.registrytdprovider.Exception2")),
633 css::uno::UNO_QUERY_THROW),
634 css::uno::UNO_QUERY);
635 assertTrue(published.is());
636 assertFalse(published->isPublished());
637 published.set(
638 css::uno::Reference< css::reflection::XTypeDescription >(
639 provider->getByHierarchicalName(
640 OUString( "test.registrytdprovider.XTest1")),
641 css::uno::UNO_QUERY_THROW),
642 css::uno::UNO_QUERY);
643 assertTrue(published.is());
644 assertTrue(published->isPublished());
645 published.set(
646 css::uno::Reference< css::reflection::XTypeDescription >(
647 provider->getByHierarchicalName(
648 OUString( "test.registrytdprovider.XTest2")),
649 css::uno::UNO_QUERY_THROW),
650 css::uno::UNO_QUERY);
651 assertTrue(published.is());
652 assertFalse(published->isPublished());
653 published.set(
654 css::uno::Reference< css::reflection::XTypeDescription >(
655 provider->getByHierarchicalName(
656 OUString( "test.registrytdprovider.Typedef1")),
657 css::uno::UNO_QUERY_THROW),
658 css::uno::UNO_QUERY);
659 assertTrue(published.is());
660 assertTrue(published->isPublished());
661 published.set(
662 css::uno::Reference< css::reflection::XTypeDescription >(
663 provider->getByHierarchicalName(
664 OUString( "test.registrytdprovider.Typedef2")),
665 css::uno::UNO_QUERY_THROW),
666 css::uno::UNO_QUERY);
667 assertTrue(published.is());
668 assertFalse(published->isPublished());
669 //TODO: check constants test.registrytdprovider.Const1 (published),
670 // test.registrytdprovider.Const2 (unpublished), and
671 // test.registrytdprovider.Consts1.C (no XPublished), which are not
672 // accessible via provider->getByHierarchicalName (see #i31428)
673 published.set(
674 css::uno::Reference< css::reflection::XTypeDescription >(
675 provider->getByHierarchicalName(
676 OUString( "test.registrytdprovider.Consts1")),
677 css::uno::UNO_QUERY_THROW),
678 css::uno::UNO_QUERY);
679 assertTrue(published.is());
680 assertTrue(published->isPublished());
681 published.set(
682 css::uno::Reference< css::reflection::XTypeDescription >(
683 provider->getByHierarchicalName(
684 OUString( "test.registrytdprovider.Consts2")),
685 css::uno::UNO_QUERY_THROW),
686 css::uno::UNO_QUERY);
687 assertTrue(published.is());
688 assertFalse(published->isPublished());
689 published.set(
690 css::uno::Reference< css::reflection::XTypeDescription >(
691 provider->getByHierarchicalName(
692 OUString( "test.registrytdprovider")),
693 css::uno::UNO_QUERY_THROW),
694 css::uno::UNO_QUERY);
695 assertFalse(published.is());
696 published.set(
697 css::uno::Reference< css::reflection::XTypeDescription >(
698 provider->getByHierarchicalName(
699 OUString( "test.registrytdprovider.Service1")),
700 css::uno::UNO_QUERY_THROW),
701 css::uno::UNO_QUERY);
702 assertTrue(published.is());
703 assertTrue(published->isPublished());
704 published.set(
705 css::uno::Reference< css::reflection::XTypeDescription >(
706 provider->getByHierarchicalName(
707 OUString( "test.registrytdprovider.Service2")),
708 css::uno::UNO_QUERY_THROW),
709 css::uno::UNO_QUERY);
710 assertTrue(published.is());
711 assertFalse(published->isPublished());
712 published.set(
713 css::uno::Reference< css::reflection::XTypeDescription >(
714 provider->getByHierarchicalName(
715 OUString( "test.registrytdprovider.Singleton2")),
716 css::uno::UNO_QUERY_THROW),
717 css::uno::UNO_QUERY);
718 assertTrue(published.is());
719 assertTrue(published->isPublished());
720 published.set(
721 css::uno::Reference< css::reflection::XTypeDescription >(
722 provider->getByHierarchicalName(
723 OUString( "test.registrytdprovider.Singleton1")),
724 css::uno::UNO_QUERY_THROW),
725 css::uno::UNO_QUERY);
726 assertTrue(published.is());
727 assertFalse(published->isPublished());
729 return 0;
732 OUString Service::getImplementationName() {
733 return OUString("test.registrytdprovider.impl");
736 css::uno::Sequence< OUString > Service::getSupportedServiceNames() {
737 return css::uno::Sequence< OUString >();
740 css::uno::Reference< css::uno::XInterface > Service::createInstance(
741 css::uno::Reference< css::uno::XComponentContext > const & context)
742 throw (css::uno::Exception)
744 return static_cast< cppu::OWeakObject * >(new Service(context));
747 extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(char const * implName,
748 void * serviceManager, void *) {
749 void * p = 0;
750 if (serviceManager != 0) {
751 css::uno::Reference< css::lang::XSingleComponentFactory > f;
752 if (Service::getImplementationName().equalsAscii(implName)) {
753 f = cppu::createSingleComponentFactory(
754 &Service::createInstance, Service::getImplementationName(),
755 Service::getSupportedServiceNames());
757 if (f.is()) {
758 f->acquire();
759 p = f.get();
762 return p;
765 namespace {
767 bool writeInfo(void * registryKey, OUString const & implementationName,
768 css::uno::Sequence< OUString > const & serviceNames) {
769 OUString keyName = "/" + implementationName + "/UNO/SERVICES";
770 css::uno::Reference< css::registry::XRegistryKey > key;
771 try {
772 key = static_cast< css::registry::XRegistryKey * >(registryKey)->
773 createKey(keyName);
774 } catch (css::registry::InvalidRegistryException &) {}
775 if (!key.is()) {
776 return false;
778 bool success = true;
779 for (sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
780 try {
781 key->createKey(serviceNames[i]);
782 } catch (css::registry::InvalidRegistryException &) {
783 success = false;
784 break;
787 return success;
792 extern "C" sal_Bool SAL_CALL component_writeInfo(void *, void * registryKey) {
793 return registryKey
794 && writeInfo(registryKey, Service::getImplementationName(),
795 Service::getSupportedServiceNames());
798 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */