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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_stoc.hxx" 26 27 #include "com/sun/star/beans/XPropertySet.hpp" 28 #include "com/sun/star/container/XHierarchicalNameAccess.hpp" 29 #include "com/sun/star/lang/XMain.hpp" 30 #include "com/sun/star/lang/XSingleComponentFactory.hpp" 31 #include "com/sun/star/reflection/XCompoundTypeDescription.hpp" 32 #include "com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp" 33 #include "com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp" 34 #include "com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp" 35 #include "com/sun/star/reflection/XInterfaceTypeDescription2.hpp" 36 #include "com/sun/star/reflection/XPublished.hpp" 37 #include "com/sun/star/reflection/XServiceTypeDescription2.hpp" 38 #include "com/sun/star/reflection/XSingletonTypeDescription2.hpp" 39 #include "com/sun/star/reflection/XStructTypeDescription.hpp" 40 #include "com/sun/star/reflection/XTypeDescription.hpp" 41 #include "com/sun/star/registry/InvalidRegistryException.hpp" 42 #include "com/sun/star/registry/XRegistryKey.hpp" 43 #include "com/sun/star/uno/Any.hxx" 44 #include "com/sun/star/uno/Exception.hpp" 45 #include "com/sun/star/uno/Reference.hxx" 46 #include "com/sun/star/uno/RuntimeException.hpp" 47 #include "com/sun/star/uno/Sequence.hxx" 48 #include "com/sun/star/uno/TypeClass.hpp" 49 #include "com/sun/star/uno/XComponentContext.hpp" 50 #include "com/sun/star/uno/XInterface.hpp" 51 #include "cppuhelper/factory.hxx" 52 #include "cppuhelper/implbase1.hxx" 53 #include "cppuhelper/weak.hxx" 54 #include "rtl/textenc.h" 55 #include "rtl/ustring.h" 56 #include "rtl/ustring.hxx" 57 #include "sal/types.h" 58 #include "uno/environment.h" 59 #include "uno/lbnames.h" 60 61 #include /*MSVC trouble: <cstdlib>*/ <stdlib.h> 62 #include <iostream> 63 #include <ostream> 64 65 namespace css = com::sun::star; 66 67 namespace { 68 69 class Service: public cppu::WeakImplHelper1< css::lang::XMain > { 70 public: 71 virtual sal_Int32 SAL_CALL 72 run(css::uno::Sequence< rtl::OUString > const & arguments) 73 throw (css::uno::RuntimeException); 74 75 static rtl::OUString getImplementationName(); 76 77 static css::uno::Sequence< rtl::OUString > getSupportedServiceNames(); 78 79 static css::uno::Reference< css::uno::XInterface > SAL_CALL createInstance( 80 css::uno::Reference< css::uno::XComponentContext > const & context) 81 throw (css::uno::Exception); 82 83 private: 84 explicit Service( 85 css::uno::Reference< css::uno::XComponentContext > const & context): 86 m_context(context) 87 {} 88 89 css::uno::Reference< css::uno::XComponentContext > m_context; 90 }; 91 92 } 93 94 namespace { 95 96 std::ostream & operator <<(std::ostream & out, rtl::OUString const & value) { 97 return out << rtl::OUStringToOString(value, RTL_TEXTENCODING_UTF8).getStr(); 98 } 99 100 void assertTrue(bool argument) { 101 if (!argument) { 102 std::cerr 103 << "assertTrue(" << argument << ") failed" << std::endl; 104 /*MSVC trouble: std::*/abort(); 105 } 106 } 107 108 void assertFalse(bool argument) { 109 if (argument) { 110 std::cerr 111 << "assertFalse(" << argument << ") failed" << std::endl; 112 /*MSVC trouble: std::*/abort(); 113 } 114 } 115 116 template< typename T > void assertEqual(T const & value, T const & argument) { 117 if (argument != value) { 118 std::cerr 119 << "assertEqual(" << value << ", " << argument << ") failed" 120 << std::endl; 121 /*MSVC trouble: std::*/abort(); 122 } 123 } 124 125 } 126 127 sal_Int32 Service::run(css::uno::Sequence< rtl::OUString > const &) 128 throw (css::uno::RuntimeException) 129 { 130 css::uno::Reference< css::lang::XMultiComponentFactory > factory( 131 m_context->getServiceManager()); 132 assertTrue(factory.is()); 133 css::uno::Sequence< css::uno::Any > args(1); 134 args[0] = css::uno::Reference< css::beans::XPropertySet >( 135 factory, css::uno::UNO_QUERY_THROW)->getPropertyValue( 136 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Registry"))); 137 css::uno::Reference< css::container::XHierarchicalNameAccess > provider( 138 factory->createInstanceWithArgumentsAndContext( 139 rtl::OUString( 140 RTL_CONSTASCII_USTRINGPARAM( 141 "com.sun.star.comp.stoc.RegistryTypeDescriptionProvider")), 142 args, m_context), 143 css::uno::UNO_QUERY_THROW); 144 145 // The following assumes that interface members are sorted by increasing 146 // values of XInterfaceMemberTypeDescription.getPosition, the exceptions 147 // of interface attributes and interface methods, the constructors of 148 // services, and the exceptions of service constructors are sorted as given 149 // in the UNOIDL source code: 150 151 assertEqual< bool >( 152 false, 153 provider->hasByHierarchicalName( 154 rtl::OUString( 155 RTL_CONSTASCII_USTRINGPARAM("[][]boolean")))); 156 assertEqual< bool >( 157 false, 158 provider->hasByHierarchicalName( 159 rtl::OUString( 160 RTL_CONSTASCII_USTRINGPARAM( 161 "test.registrytdprovider.Struct3<boolean,boolean>")))); 162 assertEqual< bool >( 163 false, 164 provider->hasByHierarchicalName( 165 rtl::OUString( 166 RTL_CONSTASCII_USTRINGPARAM( 167 "com.sun.star.uno.XComponentContext::getValueByName")))); 168 169 css::uno::Reference< css::reflection::XCompoundTypeDescription > exception; 170 exception 171 = css::uno::Reference< css::reflection::XCompoundTypeDescription >( 172 provider->getByHierarchicalName( 173 rtl::OUString( 174 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception"))), 175 css::uno::UNO_QUERY_THROW); 176 assertEqual(css::uno::TypeClass_EXCEPTION, exception->getTypeClass()); 177 assertEqual( 178 rtl::OUString( 179 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception")), 180 exception->getName()); 181 assertFalse(exception->getBaseType().is()); 182 exception 183 = css::uno::Reference< css::reflection::XCompoundTypeDescription >( 184 provider->getByHierarchicalName( 185 rtl::OUString( 186 RTL_CONSTASCII_USTRINGPARAM( 187 "com.sun.star.uno.RuntimeException"))), 188 css::uno::UNO_QUERY_THROW); 189 assertEqual(css::uno::TypeClass_EXCEPTION, exception->getTypeClass()); 190 assertEqual( 191 rtl::OUString( 192 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException")), 193 exception->getName()); 194 assertEqual( 195 rtl::OUString( 196 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception")), 197 exception->getBaseType()->getName()); 198 199 css::uno::Reference< css::reflection::XStructTypeDescription > structure; 200 201 structure = css::uno::Reference< css::reflection::XStructTypeDescription >( 202 provider->getByHierarchicalName( 203 rtl::OUString( 204 RTL_CONSTASCII_USTRINGPARAM( 205 "test.registrytdprovider.Struct2"))), 206 css::uno::UNO_QUERY_THROW); 207 assertEqual(css::uno::TypeClass_STRUCT, structure->getTypeClass()); 208 assertEqual( 209 rtl::OUString( 210 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Struct2")), 211 structure->getName()); 212 assertFalse(structure->getBaseType().is()); 213 assertEqual< sal_Int32 >(1, structure->getMemberTypes().getLength()); 214 assertEqual( 215 rtl::OUString( 216 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Struct1")), 217 structure->getMemberTypes()[0]->getName()); 218 assertEqual< sal_Int32 >(1, structure->getMemberNames().getLength()); 219 assertEqual( 220 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("s1")), 221 structure->getMemberNames()[0]); 222 assertEqual< sal_Int32 >(0, structure->getTypeParameters().getLength()); 223 assertEqual< sal_Int32 >(0, structure->getTypeArguments().getLength()); 224 225 structure = css::uno::Reference< css::reflection::XStructTypeDescription >( 226 provider->getByHierarchicalName( 227 rtl::OUString( 228 RTL_CONSTASCII_USTRINGPARAM( 229 "test.registrytdprovider.Struct3"))), 230 css::uno::UNO_QUERY_THROW); 231 assertEqual(css::uno::TypeClass_STRUCT, structure->getTypeClass()); 232 assertEqual( 233 rtl::OUString( 234 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Struct3")), 235 structure->getName()); 236 assertFalse(structure->getBaseType().is()); 237 assertEqual< sal_Int32 >(1, structure->getMemberTypes().getLength()); 238 assertEqual( 239 css::uno::TypeClass_UNKNOWN, 240 structure->getMemberTypes()[0]->getTypeClass()); 241 assertEqual( 242 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("U")), 243 structure->getMemberTypes()[0]->getName()); 244 assertEqual< sal_Int32 >(1, structure->getMemberNames().getLength()); 245 assertEqual( 246 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("s2")), 247 structure->getMemberNames()[0]); 248 assertEqual< sal_Int32 >(2, structure->getTypeParameters().getLength()); 249 assertEqual( 250 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("T")), 251 structure->getTypeParameters()[0]); 252 assertEqual( 253 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("U")), 254 structure->getTypeParameters()[1]); 255 assertEqual< sal_Int32 >(0, structure->getTypeArguments().getLength()); 256 257 structure = css::uno::Reference< css::reflection::XStructTypeDescription >( 258 provider->getByHierarchicalName( 259 rtl::OUString( 260 RTL_CONSTASCII_USTRINGPARAM( 261 "test.registrytdprovider.Struct4"))), 262 css::uno::UNO_QUERY_THROW); 263 assertEqual(css::uno::TypeClass_STRUCT, structure->getTypeClass()); 264 assertEqual( 265 rtl::OUString( 266 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Struct4")), 267 structure->getName()); 268 assertEqual( 269 rtl::OUString( 270 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Struct2")), 271 structure->getBaseType()->getName()); 272 assertEqual< sal_Int32 >(1, structure->getMemberTypes().getLength()); 273 assertEqual( 274 rtl::OUString( 275 RTL_CONSTASCII_USTRINGPARAM( 276 "test.registrytdprovider.Struct3<" 277 "test.registrytdprovider.Struct2," 278 "test.registrytdprovider.Struct3<boolean,any>>")), 279 structure->getMemberTypes()[0]->getName()); 280 assertEqual< sal_Int32 >(1, structure->getMemberNames().getLength()); 281 assertEqual( 282 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("s2")), 283 structure->getMemberNames()[0]); 284 assertEqual< sal_Int32 >(0, structure->getTypeParameters().getLength()); 285 assertEqual< sal_Int32 >(0, structure->getTypeArguments().getLength()); 286 287 css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > 288 interface; 289 290 interface 291 = css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >( 292 provider->getByHierarchicalName( 293 rtl::OUString( 294 RTL_CONSTASCII_USTRINGPARAM( 295 "test.registrytdprovider.XTest1"))), 296 css::uno::UNO_QUERY_THROW); 297 assertEqual(css::uno::TypeClass_INTERFACE, interface->getTypeClass()); 298 assertEqual( 299 rtl::OUString( 300 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest1")), 301 interface->getName()); 302 css::uno::Sequence< 303 css::uno::Reference< css::reflection::XTypeDescription > > bases( 304 interface->getBaseTypes()); 305 assertEqual< sal_Int32 >(1, bases.getLength()); 306 assertEqual( 307 rtl::OUString( 308 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.XInterface")), 309 bases[0]->getName()); 310 css::uno::Sequence< 311 css::uno::Reference< css::reflection::XTypeDescription > > 312 optionalBases(interface->getOptionalBaseTypes()); 313 assertEqual< sal_Int32 >(1, optionalBases.getLength()); 314 assertEqual( 315 rtl::OUString( 316 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XBase")), 317 optionalBases[0]->getName()); 318 css::uno::Sequence< 319 css::uno::Reference< 320 css::reflection::XInterfaceMemberTypeDescription > > members( 321 interface->getMembers()); 322 assertEqual< sal_Int32 >(5, members.getLength()); 323 324 css::uno::Reference< css::reflection::XInterfaceAttributeTypeDescription2 > 325 attribute; 326 css::uno::Sequence< 327 css::uno::Reference< css::reflection::XCompoundTypeDescription > > 328 getExceptions; 329 css::uno::Sequence< 330 css::uno::Reference< css::reflection::XCompoundTypeDescription > > 331 setExceptions; 332 css::uno::Reference< css::reflection::XInterfaceMethodTypeDescription > 333 method; 334 335 attribute = css::uno::Reference< 336 css::reflection::XInterfaceAttributeTypeDescription2 >( 337 members[0], css::uno::UNO_QUERY_THROW); 338 assertEqual( 339 css::uno::TypeClass_INTERFACE_ATTRIBUTE, attribute->getTypeClass()); 340 assertEqual( 341 rtl::OUString( 342 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest1::a1")), 343 attribute->getName()); 344 assertEqual( 345 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a1")), 346 attribute->getMemberName()); 347 assertEqual< sal_Int32 >(3, attribute->getPosition()); 348 assertEqual< bool >(false, attribute->isReadOnly()); 349 assertEqual( 350 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("short")), 351 attribute->getType()->getName()); 352 assertEqual< bool >(true, attribute->isBound()); 353 getExceptions = attribute->getGetExceptions(); 354 assertEqual< sal_Int32 >(0, getExceptions.getLength()); 355 setExceptions = attribute->getSetExceptions(); 356 assertEqual< sal_Int32 >(0, setExceptions.getLength()); 357 358 attribute = css::uno::Reference< 359 css::reflection::XInterfaceAttributeTypeDescription2 >( 360 members[1], css::uno::UNO_QUERY_THROW); 361 assertEqual( 362 css::uno::TypeClass_INTERFACE_ATTRIBUTE, attribute->getTypeClass()); 363 assertEqual( 364 rtl::OUString( 365 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest1::a2")), 366 attribute->getName()); 367 assertEqual( 368 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a2")), 369 attribute->getMemberName()); 370 assertEqual< sal_Int32 >(4, attribute->getPosition()); 371 assertEqual< bool >(false, attribute->isReadOnly()); 372 assertEqual( 373 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("long")), 374 attribute->getType()->getName()); 375 assertEqual< bool >(false, attribute->isBound()); 376 getExceptions = attribute->getGetExceptions(); 377 assertEqual< sal_Int32 >(2, getExceptions.getLength()); 378 assertEqual( 379 rtl::OUString( 380 RTL_CONSTASCII_USTRINGPARAM( 381 "com.sun.star.lang.WrappedTargetException")), 382 getExceptions[0]->getName()); 383 assertEqual( 384 rtl::OUString( 385 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException")), 386 getExceptions[1]->getName()); 387 setExceptions = attribute->getSetExceptions(); 388 assertEqual< sal_Int32 >(2, setExceptions.getLength()); 389 assertEqual( 390 rtl::OUString( 391 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.Exception")), 392 setExceptions[0]->getName()); 393 assertEqual( 394 rtl::OUString( 395 RTL_CONSTASCII_USTRINGPARAM( 396 "com.sun.star.lang.WrappedTargetException")), 397 setExceptions[1]->getName()); 398 399 attribute = css::uno::Reference< 400 css::reflection::XInterfaceAttributeTypeDescription2 >( 401 members[2], css::uno::UNO_QUERY_THROW); 402 assertEqual( 403 css::uno::TypeClass_INTERFACE_ATTRIBUTE, attribute->getTypeClass()); 404 assertEqual( 405 rtl::OUString( 406 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest1::a3")), 407 attribute->getName()); 408 assertEqual( 409 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("a3")), 410 attribute->getMemberName()); 411 assertEqual< sal_Int32 >(5, attribute->getPosition()); 412 assertEqual< bool >(true, attribute->isReadOnly()); 413 assertEqual( 414 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("hyper")), 415 attribute->getType()->getName()); 416 assertEqual< bool >(true, attribute->isBound()); 417 getExceptions = attribute->getGetExceptions(); 418 assertEqual< sal_Int32 >(1, getExceptions.getLength()); 419 assertEqual( 420 rtl::OUString( 421 RTL_CONSTASCII_USTRINGPARAM( 422 "com.sun.star.lang.WrappedTargetException")), 423 getExceptions[0]->getName()); 424 setExceptions = attribute->getSetExceptions(); 425 assertEqual< sal_Int32 >(0, setExceptions.getLength()); 426 427 method = css::uno::Reference< 428 css::reflection::XInterfaceMethodTypeDescription >( 429 members[3], css::uno::UNO_QUERY_THROW); 430 assertEqual(css::uno::TypeClass_INTERFACE_METHOD, method->getTypeClass()); 431 assertEqual( 432 rtl::OUString( 433 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest1::f1")), 434 method->getName()); 435 assertEqual( 436 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("f1")), 437 method->getMemberName()); 438 assertEqual< sal_Int32 >(6, method->getPosition()); 439 assertEqual< bool >(false, method->isOneway()); 440 assertEqual< sal_Int32 >(1, method->getParameters().getLength()); 441 assertEqual( 442 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("p")), 443 method->getParameters()[0]->getName()); 444 assertEqual( 445 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any")), 446 method->getParameters()[0]->getType()->getName()); 447 assertEqual< bool >(false, method->getParameters()[0]->isIn()); 448 assertEqual< bool >(true, method->getParameters()[0]->isOut()); 449 assertEqual< sal_Int32 >(0, method->getParameters()[0]->getPosition()); 450 assertEqual< sal_Int32 >(1, method->getExceptions().getLength()); 451 assertEqual( 452 rtl::OUString( 453 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException")), 454 method->getExceptions()[0]->getName()); 455 456 method = css::uno::Reference< 457 css::reflection::XInterfaceMethodTypeDescription >( 458 members[4], css::uno::UNO_QUERY_THROW); 459 assertEqual(css::uno::TypeClass_INTERFACE_METHOD, method->getTypeClass()); 460 assertEqual( 461 rtl::OUString( 462 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest1::f2")), 463 method->getName()); 464 assertEqual( 465 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("f2")), 466 method->getMemberName()); 467 assertEqual< sal_Int32 >(7, method->getPosition()); 468 assertEqual< bool >(true, method->isOneway()); 469 assertEqual< sal_Int32 >(0, method->getParameters().getLength()); 470 assertEqual< sal_Int32 >(0, method->getExceptions().getLength()); 471 472 interface 473 = css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >( 474 provider->getByHierarchicalName( 475 rtl::OUString( 476 RTL_CONSTASCII_USTRINGPARAM( 477 "test.registrytdprovider.XTest2"))), 478 css::uno::UNO_QUERY_THROW); 479 assertEqual(css::uno::TypeClass_INTERFACE, interface->getTypeClass()); 480 assertEqual( 481 rtl::OUString( 482 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest2")), 483 interface->getName()); 484 assertEqual< sal_Int32 >(1, interface->getBaseTypes().getLength()); 485 assertEqual( 486 rtl::OUString( 487 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Typedef2")), 488 interface->getBaseTypes()[0]->getName()); 489 assertEqual< sal_Int32 >(0, interface->getOptionalBaseTypes().getLength()); 490 assertEqual< sal_Int32 >(0, interface->getMembers().getLength()); 491 492 css::uno::Reference< css::reflection::XServiceTypeDescription2 > service; 493 494 service = css::uno::Reference< css::reflection::XServiceTypeDescription2 >( 495 provider->getByHierarchicalName( 496 rtl::OUString( 497 RTL_CONSTASCII_USTRINGPARAM( 498 "test.registrytdprovider.Service1"))), 499 css::uno::UNO_QUERY_THROW); 500 assertEqual(css::uno::TypeClass_SERVICE, service->getTypeClass()); 501 assertEqual( 502 rtl::OUString( 503 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Service1")), 504 service->getName()); 505 assertEqual< sal_Int32 >(0, service->getMandatoryServices().getLength()); 506 assertEqual< sal_Int32 >(0, service->getOptionalServices().getLength()); 507 assertEqual< sal_Int32 >(0, service->getMandatoryInterfaces().getLength()); 508 assertEqual< sal_Int32 >(0, service->getOptionalInterfaces().getLength()); 509 assertEqual< bool >(true, service->isSingleInterfaceBased()); 510 assertEqual( 511 rtl::OUString( 512 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest1")), 513 service->getInterface()->getName()); 514 assertEqual< sal_Int32 >(2, service->getConstructors().getLength()); 515 assertEqual( 516 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("c1")), 517 service->getConstructors()[0]->getName()); 518 assertEqual< sal_Int32 >( 519 0, service->getConstructors()[0]->getParameters().getLength()); 520 assertEqual< sal_Int32 >( 521 0, service->getConstructors()[0]->getExceptions().getLength()); 522 assertEqual( 523 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("c2")), 524 service->getConstructors()[1]->getName()); 525 assertEqual< sal_Int32 >( 526 1, service->getConstructors()[1]->getParameters().getLength()); 527 assertEqual( 528 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("p")), 529 service->getConstructors()[1]->getParameters()[0]->getName()); 530 assertEqual( 531 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("any")), 532 (service->getConstructors()[1]->getParameters()[0]->getType()-> 533 getName())); 534 assertEqual< bool >( 535 true, service->getConstructors()[1]->getParameters()[0]->isIn()); 536 assertEqual< bool >( 537 false, service->getConstructors()[1]->getParameters()[0]->isOut()); 538 assertEqual< sal_Int32 >( 539 0, service->getConstructors()[1]->getParameters()[0]->getPosition()); 540 assertEqual< bool >( 541 true, 542 service->getConstructors()[1]->getParameters()[0]->isRestParameter()); 543 assertEqual< sal_Int32 >( 544 1, service->getConstructors()[1]->getExceptions().getLength()); 545 assertEqual( 546 rtl::OUString( 547 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.uno.RuntimeException")), 548 service->getConstructors()[1]->getExceptions()[0]->getName()); 549 550 service = css::uno::Reference< css::reflection::XServiceTypeDescription2 >( 551 provider->getByHierarchicalName( 552 rtl::OUString( 553 RTL_CONSTASCII_USTRINGPARAM( 554 "test.registrytdprovider.Service2"))), 555 css::uno::UNO_QUERY_THROW); 556 assertEqual(css::uno::TypeClass_SERVICE, service->getTypeClass()); 557 assertEqual( 558 rtl::OUString( 559 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Service2")), 560 service->getName()); 561 assertEqual< sal_Int32 >(0, service->getMandatoryServices().getLength()); 562 assertEqual< sal_Int32 >(0, service->getOptionalServices().getLength()); 563 assertEqual< sal_Int32 >(1, service->getMandatoryInterfaces().getLength()); 564 assertEqual( 565 rtl::OUString( 566 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest1")), 567 service->getMandatoryInterfaces()[0]->getName()); 568 assertEqual< sal_Int32 >(1, service->getOptionalInterfaces().getLength()); 569 assertEqual( 570 rtl::OUString( 571 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XBase")), 572 service->getOptionalInterfaces()[0]->getName()); 573 assertEqual< bool >(false, service->isSingleInterfaceBased()); 574 assertFalse(service->getInterface().is()); 575 assertEqual< sal_Int32 >(0, service->getConstructors().getLength()); 576 577 service = css::uno::Reference< css::reflection::XServiceTypeDescription2 >( 578 provider->getByHierarchicalName( 579 rtl::OUString( 580 RTL_CONSTASCII_USTRINGPARAM( 581 "test.registrytdprovider.Service3"))), 582 css::uno::UNO_QUERY_THROW); 583 assertEqual(css::uno::TypeClass_SERVICE, service->getTypeClass()); 584 assertEqual( 585 rtl::OUString( 586 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Service3")), 587 service->getName()); 588 assertEqual< sal_Int32 >(0, service->getMandatoryServices().getLength()); 589 assertEqual< sal_Int32 >(0, service->getOptionalServices().getLength()); 590 assertEqual< sal_Int32 >(0, service->getMandatoryInterfaces().getLength()); 591 assertEqual< sal_Int32 >(0, service->getOptionalInterfaces().getLength()); 592 assertEqual< bool >(true, service->isSingleInterfaceBased()); 593 assertEqual( 594 rtl::OUString( 595 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Typedef2")), 596 service->getInterface()->getName()); 597 assertEqual< sal_Int32 >(0, service->getConstructors().getLength()); 598 599 css::uno::Reference< css::reflection::XSingletonTypeDescription2 > 600 singleton; 601 602 singleton = css::uno::Reference< 603 css::reflection::XSingletonTypeDescription2 >( 604 provider->getByHierarchicalName( 605 rtl::OUString( 606 RTL_CONSTASCII_USTRINGPARAM( 607 "test.registrytdprovider.Singleton1"))), 608 css::uno::UNO_QUERY_THROW); 609 assertEqual(css::uno::TypeClass_SINGLETON, singleton->getTypeClass()); 610 assertEqual( 611 rtl::OUString( 612 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Singleton1")), 613 singleton->getName()); 614 assertFalse(singleton->getService().is()); 615 assertEqual< bool >(true, singleton->isInterfaceBased()); 616 assertEqual( 617 rtl::OUString( 618 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.XTest1")), 619 singleton->getInterface()->getName()); 620 621 singleton = css::uno::Reference< 622 css::reflection::XSingletonTypeDescription2 >( 623 provider->getByHierarchicalName( 624 rtl::OUString( 625 RTL_CONSTASCII_USTRINGPARAM( 626 "test.registrytdprovider.Singleton2"))), 627 css::uno::UNO_QUERY_THROW); 628 assertEqual(css::uno::TypeClass_SINGLETON, singleton->getTypeClass()); 629 assertEqual( 630 rtl::OUString( 631 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Singleton2")), 632 singleton->getName()); 633 assertEqual( 634 rtl::OUString( 635 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Service1")), 636 singleton->getService()->getName()); 637 assertEqual< bool >(false, singleton->isInterfaceBased()); 638 assertFalse(singleton->getInterface().is()); 639 640 singleton = css::uno::Reference< 641 css::reflection::XSingletonTypeDescription2 >( 642 provider->getByHierarchicalName( 643 rtl::OUString( 644 RTL_CONSTASCII_USTRINGPARAM( 645 "test.registrytdprovider.Singleton3"))), 646 css::uno::UNO_QUERY_THROW); 647 assertEqual(css::uno::TypeClass_SINGLETON, singleton->getTypeClass()); 648 assertEqual( 649 rtl::OUString( 650 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Singleton3")), 651 singleton->getName()); 652 assertFalse(singleton->getService().is()); 653 assertEqual< bool >(true, singleton->isInterfaceBased()); 654 assertEqual( 655 rtl::OUString( 656 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider.Typedef2")), 657 singleton->getInterface()->getName()); 658 659 css::uno::Reference< css::reflection::XPublished > published; 660 published = css::uno::Reference< css::reflection::XPublished >( 661 css::uno::Reference< css::reflection::XTypeDescription >( 662 provider->getByHierarchicalName( 663 rtl::OUString( 664 RTL_CONSTASCII_USTRINGPARAM( 665 "test.registrytdprovider.Enum1"))), 666 css::uno::UNO_QUERY_THROW), 667 css::uno::UNO_QUERY); 668 assertTrue(published.is()); 669 assertTrue(published->isPublished()); 670 published = css::uno::Reference< css::reflection::XPublished >( 671 css::uno::Reference< css::reflection::XTypeDescription >( 672 provider->getByHierarchicalName( 673 rtl::OUString( 674 RTL_CONSTASCII_USTRINGPARAM( 675 "test.registrytdprovider.Enum2"))), 676 css::uno::UNO_QUERY_THROW), 677 css::uno::UNO_QUERY); 678 assertTrue(published.is()); 679 assertFalse(published->isPublished()); 680 published = css::uno::Reference< css::reflection::XPublished >( 681 css::uno::Reference< css::reflection::XTypeDescription >( 682 provider->getByHierarchicalName( 683 rtl::OUString( 684 RTL_CONSTASCII_USTRINGPARAM( 685 "test.registrytdprovider.Struct1"))), 686 css::uno::UNO_QUERY_THROW), 687 css::uno::UNO_QUERY); 688 assertTrue(published.is()); 689 assertTrue(published->isPublished()); 690 published = css::uno::Reference< css::reflection::XPublished >( 691 css::uno::Reference< css::reflection::XTypeDescription >( 692 provider->getByHierarchicalName( 693 rtl::OUString( 694 RTL_CONSTASCII_USTRINGPARAM( 695 "test.registrytdprovider.Struct2"))), 696 css::uno::UNO_QUERY_THROW), 697 css::uno::UNO_QUERY); 698 assertTrue(published.is()); 699 assertFalse(published->isPublished()); 700 published = css::uno::Reference< css::reflection::XPublished >( 701 css::uno::Reference< css::reflection::XTypeDescription >( 702 provider->getByHierarchicalName( 703 rtl::OUString( 704 RTL_CONSTASCII_USTRINGPARAM( 705 "test.registrytdprovider.Struct3"))), 706 css::uno::UNO_QUERY_THROW), 707 css::uno::UNO_QUERY); 708 assertTrue(published.is()); 709 assertTrue(published->isPublished()); 710 published = css::uno::Reference< css::reflection::XPublished >( 711 css::uno::Reference< css::reflection::XStructTypeDescription >( 712 provider->getByHierarchicalName( 713 rtl::OUString( 714 RTL_CONSTASCII_USTRINGPARAM( 715 "test.registrytdprovider.Struct3"))), 716 css::uno::UNO_QUERY_THROW)->getMemberTypes()[0], 717 css::uno::UNO_QUERY); 718 assertFalse(published.is()); 719 published = css::uno::Reference< css::reflection::XPublished >( 720 css::uno::Reference< css::reflection::XTypeDescription >( 721 provider->getByHierarchicalName( 722 rtl::OUString( 723 RTL_CONSTASCII_USTRINGPARAM( 724 "test.registrytdprovider.Struct3a"))), 725 css::uno::UNO_QUERY_THROW), 726 css::uno::UNO_QUERY); 727 assertTrue(published.is()); 728 assertFalse(published->isPublished()); 729 published = css::uno::Reference< css::reflection::XPublished >( 730 css::uno::Reference< css::reflection::XTypeDescription >( 731 provider->getByHierarchicalName( 732 rtl::OUString( 733 RTL_CONSTASCII_USTRINGPARAM( 734 "test.registrytdprovider.Exception1"))), 735 css::uno::UNO_QUERY_THROW), 736 css::uno::UNO_QUERY); 737 assertTrue(published.is()); 738 assertTrue(published->isPublished()); 739 published = css::uno::Reference< css::reflection::XPublished >( 740 css::uno::Reference< css::reflection::XTypeDescription >( 741 provider->getByHierarchicalName( 742 rtl::OUString( 743 RTL_CONSTASCII_USTRINGPARAM( 744 "test.registrytdprovider.Exception2"))), 745 css::uno::UNO_QUERY_THROW), 746 css::uno::UNO_QUERY); 747 assertTrue(published.is()); 748 assertFalse(published->isPublished()); 749 published = css::uno::Reference< css::reflection::XPublished >( 750 css::uno::Reference< css::reflection::XTypeDescription >( 751 provider->getByHierarchicalName( 752 rtl::OUString( 753 RTL_CONSTASCII_USTRINGPARAM( 754 "test.registrytdprovider.XTest1"))), 755 css::uno::UNO_QUERY_THROW), 756 css::uno::UNO_QUERY); 757 assertTrue(published.is()); 758 assertTrue(published->isPublished()); 759 published = css::uno::Reference< css::reflection::XPublished >( 760 css::uno::Reference< css::reflection::XTypeDescription >( 761 provider->getByHierarchicalName( 762 rtl::OUString( 763 RTL_CONSTASCII_USTRINGPARAM( 764 "test.registrytdprovider.XTest2"))), 765 css::uno::UNO_QUERY_THROW), 766 css::uno::UNO_QUERY); 767 assertTrue(published.is()); 768 assertFalse(published->isPublished()); 769 published = css::uno::Reference< css::reflection::XPublished >( 770 css::uno::Reference< css::reflection::XTypeDescription >( 771 provider->getByHierarchicalName( 772 rtl::OUString( 773 RTL_CONSTASCII_USTRINGPARAM( 774 "test.registrytdprovider.Typedef1"))), 775 css::uno::UNO_QUERY_THROW), 776 css::uno::UNO_QUERY); 777 assertTrue(published.is()); 778 assertTrue(published->isPublished()); 779 published = css::uno::Reference< css::reflection::XPublished >( 780 css::uno::Reference< css::reflection::XTypeDescription >( 781 provider->getByHierarchicalName( 782 rtl::OUString( 783 RTL_CONSTASCII_USTRINGPARAM( 784 "test.registrytdprovider.Typedef2"))), 785 css::uno::UNO_QUERY_THROW), 786 css::uno::UNO_QUERY); 787 assertTrue(published.is()); 788 assertFalse(published->isPublished()); 789 //TODO: check constants test.registrytdprovider.Const1 (published), 790 // test.registrytdprovider.Const2 (unpublished), and 791 // test.registrytdprovider.Consts1.C (no XPublished), which are not 792 // accessible via provider->getByHierarchicalName (see #i31428) 793 published = css::uno::Reference< css::reflection::XPublished >( 794 css::uno::Reference< css::reflection::XTypeDescription >( 795 provider->getByHierarchicalName( 796 rtl::OUString( 797 RTL_CONSTASCII_USTRINGPARAM( 798 "test.registrytdprovider.Consts1"))), 799 css::uno::UNO_QUERY_THROW), 800 css::uno::UNO_QUERY); 801 assertTrue(published.is()); 802 assertTrue(published->isPublished()); 803 published = css::uno::Reference< css::reflection::XPublished >( 804 css::uno::Reference< css::reflection::XTypeDescription >( 805 provider->getByHierarchicalName( 806 rtl::OUString( 807 RTL_CONSTASCII_USTRINGPARAM( 808 "test.registrytdprovider.Consts2"))), 809 css::uno::UNO_QUERY_THROW), 810 css::uno::UNO_QUERY); 811 assertTrue(published.is()); 812 assertFalse(published->isPublished()); 813 published = css::uno::Reference< css::reflection::XPublished >( 814 css::uno::Reference< css::reflection::XTypeDescription >( 815 provider->getByHierarchicalName( 816 rtl::OUString( 817 RTL_CONSTASCII_USTRINGPARAM("test.registrytdprovider"))), 818 css::uno::UNO_QUERY_THROW), 819 css::uno::UNO_QUERY); 820 assertFalse(published.is()); 821 published = css::uno::Reference< css::reflection::XPublished >( 822 css::uno::Reference< css::reflection::XTypeDescription >( 823 provider->getByHierarchicalName( 824 rtl::OUString( 825 RTL_CONSTASCII_USTRINGPARAM( 826 "test.registrytdprovider.Service1"))), 827 css::uno::UNO_QUERY_THROW), 828 css::uno::UNO_QUERY); 829 assertTrue(published.is()); 830 assertTrue(published->isPublished()); 831 published = css::uno::Reference< css::reflection::XPublished >( 832 css::uno::Reference< css::reflection::XTypeDescription >( 833 provider->getByHierarchicalName( 834 rtl::OUString( 835 RTL_CONSTASCII_USTRINGPARAM( 836 "test.registrytdprovider.Service2"))), 837 css::uno::UNO_QUERY_THROW), 838 css::uno::UNO_QUERY); 839 assertTrue(published.is()); 840 assertFalse(published->isPublished()); 841 published = css::uno::Reference< css::reflection::XPublished >( 842 css::uno::Reference< css::reflection::XTypeDescription >( 843 provider->getByHierarchicalName( 844 rtl::OUString( 845 RTL_CONSTASCII_USTRINGPARAM( 846 "test.registrytdprovider.Singleton2"))), 847 css::uno::UNO_QUERY_THROW), 848 css::uno::UNO_QUERY); 849 assertTrue(published.is()); 850 assertTrue(published->isPublished()); 851 published = css::uno::Reference< css::reflection::XPublished >( 852 css::uno::Reference< css::reflection::XTypeDescription >( 853 provider->getByHierarchicalName( 854 rtl::OUString( 855 RTL_CONSTASCII_USTRINGPARAM( 856 "test.registrytdprovider.Singleton1"))), 857 css::uno::UNO_QUERY_THROW), 858 css::uno::UNO_QUERY); 859 assertTrue(published.is()); 860 assertFalse(published->isPublished()); 861 862 return 0; 863 } 864 865 rtl::OUString Service::getImplementationName() { 866 return rtl::OUString::createFromAscii("test.registrytdprovider.impl"); 867 } 868 869 css::uno::Sequence< rtl::OUString > Service::getSupportedServiceNames() { 870 return css::uno::Sequence< rtl::OUString >(); 871 } 872 873 css::uno::Reference< css::uno::XInterface > Service::createInstance( 874 css::uno::Reference< css::uno::XComponentContext > const & context) 875 throw (css::uno::Exception) 876 { 877 return static_cast< cppu::OWeakObject * >(new Service(context)); 878 } 879 880 extern "C" void SAL_CALL component_getImplementationEnvironment( 881 char const ** envTypeName, uno_Environment **) 882 { 883 if (envTypeName != 0) { 884 *envTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; 885 } 886 } 887 888 extern "C" void * SAL_CALL component_getFactory(char const * implName, 889 void * serviceManager, void *) { 890 void * p = 0; 891 if (serviceManager != 0) { 892 css::uno::Reference< css::lang::XSingleComponentFactory > f; 893 if (Service::getImplementationName().equalsAscii(implName)) { 894 f = cppu::createSingleComponentFactory( 895 &Service::createInstance, Service::getImplementationName(), 896 Service::getSupportedServiceNames()); 897 } 898 if (f.is()) { 899 f->acquire(); 900 p = f.get(); 901 } 902 } 903 return p; 904 } 905 906 namespace { 907 908 bool writeInfo(void * registryKey, rtl::OUString const & implementationName, 909 css::uno::Sequence< rtl::OUString > const & serviceNames) { 910 rtl::OUString keyName(rtl::OUString::createFromAscii("/")); 911 keyName += implementationName; 912 keyName += rtl::OUString::createFromAscii("/UNO/SERVICES"); 913 css::uno::Reference< css::registry::XRegistryKey > key; 914 try { 915 key = static_cast< css::registry::XRegistryKey * >(registryKey)-> 916 createKey(keyName); 917 } catch (css::registry::InvalidRegistryException &) {} 918 if (!key.is()) { 919 return false; 920 } 921 bool success = true; 922 for (sal_Int32 i = 0; i < serviceNames.getLength(); ++i) { 923 try { 924 key->createKey(serviceNames[i]); 925 } catch (css::registry::InvalidRegistryException &) { 926 success = false; 927 break; 928 } 929 } 930 return success; 931 } 932 933 } 934 935 extern "C" sal_Bool SAL_CALL component_writeInfo(void *, void * registryKey) { 936 return registryKey 937 && writeInfo(registryKey, Service::getImplementationName(), 938 Service::getSupportedServiceNames()); 939 } 940