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 "precompiled_configmgr.hxx"
25 #include "sal/config.h"
26
27 #include <cstddef>
28
29 #include "com/sun/star/beans/NamedValue.hpp"
30 #include "com/sun/star/beans/PropertyChangeEvent.hpp"
31 #include "com/sun/star/beans/XPropertyChangeListener.hpp"
32 #include "com/sun/star/beans/XPropertySet.hpp"
33 #include "com/sun/star/beans/XPropertyState.hpp"
34 #include "com/sun/star/container/XHierarchicalNameAccess.hpp"
35 #include "com/sun/star/container/XNameReplace.hpp"
36 #include "com/sun/star/container/XNamed.hpp"
37 #include "com/sun/star/lang/EventObject.hpp"
38 #include "com/sun/star/lang/XComponent.hpp"
39 #include "com/sun/star/lang/XMultiServiceFactory.hpp"
40 #include "com/sun/star/uno/Any.hxx"
41 #include "com/sun/star/uno/Reference.hxx"
42 #include "com/sun/star/uno/RuntimeException.hpp"
43 #include "com/sun/star/uno/Sequence.hxx"
44 #include "com/sun/star/uno/XComponentContext.hpp"
45 #include "com/sun/star/uno/XInterface.hpp"
46 #include "com/sun/star/util/XChangesBatch.hpp"
47 #include "cppuhelper/implbase1.hxx"
48 #include "cppuhelper/servicefactory.hxx"
49 #include "osl/conditn.hxx"
50 #include "osl/thread.h"
51 #include "osl/thread.hxx"
52 #include "osl/time.h"
53 #include "rtl/ref.hxx"
54 #include "rtl/string.h"
55 #include "rtl/textcvt.h"
56 #include "rtl/ustrbuf.hxx"
57 #include "rtl/ustring.h"
58 #include "rtl/ustring.hxx"
59 #include "sal/types.h"
60 #include "testshl/simpleheader.hxx"
61
62 namespace {
63
64 namespace css = com::sun::star;
65
normalize(rtl::OUString const & path,rtl::OUString const & relative,rtl::OUString * normalizedPath,rtl::OUString * name)66 void normalize(
67 rtl::OUString const & path, rtl::OUString const & relative,
68 rtl::OUString * normalizedPath, rtl::OUString * name)
69 {
70 sal_Int32 i = relative.lastIndexOf('/');
71 if (i == -1) {
72 *normalizedPath = path;
73 *name = relative;
74 } else {
75 rtl::OUStringBuffer buf(path);
76 buf.append(sal_Unicode('/'));
77 buf.append(relative.copy(0, i));
78 *normalizedPath = buf.makeStringAndClear();
79 *name = relative.copy(i + 1);
80 }
81 }
82
83 class Test: public CppUnit::TestFixture {
84 public:
85 virtual void setUp();
86
87 virtual void tearDown();
88
89 void testKeyFetch();
90
91 void testKeySet();
92
93 void testKeyReset();
94
95 void testSetSetMemberName();
96
97 void testReadCommands();
98
99 void testThreads();
100
101 void testRecursive();
102
103 void testCrossThreads();
104
105 css::uno::Any getKey(
106 rtl::OUString const & path, rtl::OUString const & relative) const;
107
108 void setKey(
109 rtl::OUString const & path, rtl::OUString const & name,
110 css::uno::Any const & value) const;
111
112 bool resetKey(rtl::OUString const & path, rtl::OUString const & name) const;
113
114 css::uno::Reference< css::uno::XInterface > createViewAccess(
115 rtl::OUString const & path) const;
116
117 css::uno::Reference< css::uno::XInterface > createUpdateAccess(
118 rtl::OUString const & path) const;
119
120 CPPUNIT_TEST_SUITE(Test);
121 CPPUNIT_TEST(testKeyFetch);
122 CPPUNIT_TEST(testKeySet);
123 CPPUNIT_TEST(testKeyReset);
124 CPPUNIT_TEST(testSetSetMemberName);
125 CPPUNIT_TEST(testReadCommands);
126 CPPUNIT_TEST(testThreads);
127 CPPUNIT_TEST(testRecursive);
128 CPPUNIT_TEST(testCrossThreads);
129 CPPUNIT_TEST_SUITE_END();
130
131 private:
132 css::uno::Reference< css::uno::XComponentContext > context_;
133 css::uno::Reference< css::lang::XMultiServiceFactory > provider_;
134 };
135
136 class TestThread: public osl::Thread {
137 public:
138 TestThread(osl::Condition & stop);
139
140 bool getSuccess() const;
141
142 protected:
143 virtual bool iteration() = 0;
144
145 private:
146 virtual void SAL_CALL run();
147
148 osl::Condition & stop_;
149 bool success_;
150 };
151
TestThread(osl::Condition & stop)152 TestThread::TestThread(
153 osl::Condition & stop):
154 stop_(stop), success_(true)
155 {}
156
getSuccess() const157 bool TestThread::getSuccess() const {
158 return success_;
159 }
160
run()161 void TestThread::run() {
162 try {
163 while (!stop_.check()) {
164 if (!iteration()) {
165 success_ = false;
166 }
167 }
168 } catch (...) {
169 success_ = false;
170 }
171 }
172
173 class ReaderThread: public TestThread {
174 public:
175 ReaderThread(
176 osl::Condition & stop, Test const & test, rtl::OUString const & path,
177 rtl::OUString const & relative);
178
179 private:
180 virtual bool iteration();
181
182 Test const & test_;
183 rtl::OUString path_;
184 rtl::OUString relative_;
185 };
186
ReaderThread(osl::Condition & stop,Test const & test,rtl::OUString const & path,rtl::OUString const & relative)187 ReaderThread::ReaderThread(
188 osl::Condition & stop, Test const & test, rtl::OUString const & path,
189 rtl::OUString const & relative):
190 TestThread(stop), test_(test), path_(path), relative_(relative)
191 {
192 create();
193 }
194
iteration()195 bool ReaderThread::iteration() {
196 return test_.getKey(path_, relative_).hasValue();
197 }
198
199 class WriterThread: public TestThread {
200 public:
201 WriterThread(
202 osl::Condition & stop, Test const & test, rtl::OUString const & path,
203 rtl::OUString const & relative);
204
205 private:
206 virtual bool iteration();
207
208 Test const & test_;
209 rtl::OUString path_;
210 rtl::OUString name_;
211 std::size_t index_;
212 };
213
WriterThread(osl::Condition & stop,Test const & test,rtl::OUString const & path,rtl::OUString const & relative)214 WriterThread::WriterThread(
215 osl::Condition & stop, Test const & test, rtl::OUString const & path,
216 rtl::OUString const & relative):
217 TestThread(stop), test_(test), index_(0)
218 {
219 normalize(path, relative, &path_, &name_);
220 create();
221 }
222
iteration()223 bool WriterThread::iteration() {
224 rtl::OUString options[] = {
225 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("fish")),
226 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("chips")),
227 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("kippers")),
228 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bloaters")) };
229 test_.setKey(path_, name_, css::uno::makeAny(options[index_]));
230 index_ = (index_ + 1) % (sizeof options / sizeof (rtl::OUString));
231 return true;
232 }
233
234 class RecursiveTest:
235 public cppu::WeakImplHelper1< css::beans::XPropertyChangeListener >
236 {
237 public:
238 RecursiveTest(Test const & theTest, int count, bool * destroyed);
239
240 void test();
241
242 protected:
243 virtual ~RecursiveTest();
244
245 virtual void step() const = 0;
246
247 Test const & test_;
248
249 private:
250 virtual void SAL_CALL disposing(css::lang::EventObject const &)
251 throw (css::uno::RuntimeException);
252
253 virtual void SAL_CALL propertyChange(
254 css::beans::PropertyChangeEvent const &)
255 throw (css::uno::RuntimeException);
256
257 int count_;
258 bool * destroyed_;
259 css::uno::Reference< css::beans::XPropertySet > properties_;
260 };
261
RecursiveTest(Test const & theTest,int count,bool * destroyed)262 RecursiveTest::RecursiveTest(
263 Test const & theTest, int count, bool * destroyed):
264 test_(theTest), count_(count), destroyed_(destroyed)
265 {}
266
test()267 void RecursiveTest::test() {
268 properties_ = css::uno::Reference< css::beans::XPropertySet >(
269 test_.createUpdateAccess(
270 rtl::OUString(
271 RTL_CONSTASCII_USTRINGPARAM(
272 "/org.openoffice.UI.GenericCommands/UserInterface/Commands/"
273 "dotuno:WebHtml"))),
274 css::uno::UNO_QUERY_THROW);
275 properties_->addPropertyChangeListener(
276 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label")), this);
277 step();
278 CPPUNIT_ASSERT(count_ == 0);
279 css::uno::Reference< css::lang::XComponent >(
280 properties_, css::uno::UNO_QUERY_THROW)->dispose();
281 }
282
~RecursiveTest()283 RecursiveTest::~RecursiveTest() {
284 *destroyed_ = true;
285 }
286
disposing(css::lang::EventObject const & Source)287 void RecursiveTest::disposing(css::lang::EventObject const & Source)
288 throw (css::uno::RuntimeException)
289 {
290 CPPUNIT_ASSERT(properties_.is() && Source.Source == properties_);
291 properties_.clear();
292 }
293
propertyChange(css::beans::PropertyChangeEvent const & evt)294 void RecursiveTest::propertyChange(css::beans::PropertyChangeEvent const & evt)
295 throw (css::uno::RuntimeException)
296 {
297 CPPUNIT_ASSERT(
298 evt.Source == properties_ &&
299 evt.PropertyName.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Label")));
300 if (count_ > 0) {
301 --count_;
302 step();
303 }
304 }
305
306 class SimpleRecursiveTest: public RecursiveTest {
307 public:
308 SimpleRecursiveTest(Test const & theTest, int count, bool * destroyed);
309
310 private:
311 virtual void step() const;
312 };
313
SimpleRecursiveTest(Test const & theTest,int count,bool * destroyed)314 SimpleRecursiveTest::SimpleRecursiveTest(
315 Test const & theTest, int count, bool * destroyed):
316 RecursiveTest(theTest, count, destroyed)
317 {}
318
step() const319 void SimpleRecursiveTest::step() const {
320 test_.setKey(
321 rtl::OUString(
322 RTL_CONSTASCII_USTRINGPARAM(
323 "/org.openoffice.UI.GenericCommands/UserInterface/Commands/"
324 "dotuno:WebHtml")),
325 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label")),
326 css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("step"))));
327 }
328
329 class CrossThreadTest: public RecursiveTest {
330 public:
331 CrossThreadTest(Test const & theTest, int count, bool * destroyed);
332
333 private:
334 virtual void step() const;
335 };
336
CrossThreadTest(Test const & theTest,int count,bool * destroyed)337 CrossThreadTest::CrossThreadTest(
338 Test const & theTest, int count, bool * destroyed):
339 RecursiveTest(theTest, count, destroyed)
340 {}
341
step() const342 void CrossThreadTest::step() const {
343 osl::Condition stop;
344 stop.set();
345 WriterThread(
346 stop, test_,
347 rtl::OUString(
348 RTL_CONSTASCII_USTRINGPARAM(
349 "/org.openoffice.UI.GenericCommands/UserInterface/Commands/"
350 "dotuno:WebHtml")),
351 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label"))).join();
352 test_.resetKey(
353 rtl::OUString(
354 RTL_CONSTASCII_USTRINGPARAM(
355 "/org.openoffice.UI.GenericCommands/UserInterface/Commands/"
356 "dotuno:WebHtml")),
357 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label")));
358 }
359
setUp()360 void Test::setUp() {
361 char const * forward = getForwardString();
362 rtl_uString * registry = 0;
363 CPPUNIT_ASSERT(
364 rtl_convertStringToUString(
365 ®istry, forward, rtl_str_getLength(forward),
366 osl_getThreadTextEncoding(),
367 (RTL_TEXTTOUNICODE_FLAGS_UNDEFINED_ERROR |
368 RTL_TEXTTOUNICODE_FLAGS_MBUNDEFINED_ERROR |
369 RTL_TEXTTOUNICODE_FLAGS_INVALID_ERROR)));
370 context_ = css::uno::Reference< css::uno::XComponentContext >(
371 css::uno::Reference< css::beans::XPropertySet >(
372 cppu::createRegistryServiceFactory(
373 rtl::OUString(registry, SAL_NO_ACQUIRE)),
374 css::uno::UNO_QUERY_THROW)->getPropertyValue(
375 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext"))),
376 css::uno::UNO_QUERY_THROW);
377 CPPUNIT_ASSERT(
378 context_->getValueByName(
379 rtl::OUString(
380 RTL_CONSTASCII_USTRINGPARAM(
381 "/singletons/"
382 "com.sun.star.configuration.theDefaultProvider"))) >>=
383 provider_);
384 }
385
tearDown()386 void Test::tearDown() {
387 css::uno::Reference< css::lang::XComponent >(
388 context_, css::uno::UNO_QUERY_THROW)->dispose();
389 }
390
testKeyFetch()391 void Test::testKeyFetch() {
392 rtl::OUString s;
393 CPPUNIT_ASSERT(
394 getKey(
395 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
396 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooLocale"))) >>=
397 s);
398 CPPUNIT_ASSERT(
399 getKey(
400 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
401 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Test/AString"))) >>=
402 s);
403 }
404
testKeySet()405 void Test::testKeySet() {
406 setKey(
407 rtl::OUString(
408 RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Test")),
409 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AString")),
410 css::uno::makeAny(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("baa"))));
411 rtl::OUString s;
412 CPPUNIT_ASSERT(
413 getKey(
414 rtl::OUString(
415 RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Test")),
416 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AString"))) >>=
417 s);
418 CPPUNIT_ASSERT(s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("baa")));
419 }
420
testKeyReset()421 void Test::testKeyReset() {
422 if (resetKey(
423 rtl::OUString(
424 RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Test")),
425 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AString"))))
426 {
427 rtl::OUString s;
428 CPPUNIT_ASSERT(
429 getKey(
430 rtl::OUString(
431 RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup/Test")),
432 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AString"))) >>=
433 s);
434 CPPUNIT_ASSERT(s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Foo")));
435 }
436 }
437
testSetSetMemberName()438 void Test::testSetSetMemberName() {
439 rtl::OUString s;
440 CPPUNIT_ASSERT(
441 getKey(
442 rtl::OUString(
443 RTL_CONSTASCII_USTRINGPARAM(
444 "/org.openoffice.UI.GenericCommands/UserInterface/Commands/"
445 ".uno:FontworkShapeType")),
446 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label"))) >>=
447 s);
448 CPPUNIT_ASSERT(
449 s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Fontwork Shape")));
450
451 css::uno::Reference< css::container::XNameAccess > access(
452 createUpdateAccess(
453 rtl::OUString(
454 RTL_CONSTASCII_USTRINGPARAM(
455 "/org.openoffice.UI.GenericCommands/UserInterface/"
456 "Commands"))),
457 css::uno::UNO_QUERY_THROW);
458 css::uno::Reference< css::container::XNamed > member;
459 access->getByName(
460 rtl::OUString(
461 RTL_CONSTASCII_USTRINGPARAM(".uno:FontworkGalleryFloater"))) >>=
462 member;
463 CPPUNIT_ASSERT(member.is());
464 member->setName(
465 rtl::OUString(
466 RTL_CONSTASCII_USTRINGPARAM(".uno:FontworkShapeType")));
467 css::uno::Reference< css::util::XChangesBatch >(
468 access, css::uno::UNO_QUERY_THROW)->commitChanges();
469 css::uno::Reference< css::lang::XComponent >(
470 access, css::uno::UNO_QUERY_THROW)->dispose();
471
472 CPPUNIT_ASSERT(
473 getKey(
474 rtl::OUString(
475 RTL_CONSTASCII_USTRINGPARAM(
476 "/org.openoffice.UI.GenericCommands/UserInterface/Commands/"
477 ".uno:FontworkShapeType")),
478 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label"))) >>=
479 s);
480 CPPUNIT_ASSERT(
481 s.equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("Fontwork Gallery")));
482 }
483
testReadCommands()484 void Test::testReadCommands() {
485 css::uno::Reference< css::container::XNameAccess > access(
486 createViewAccess(
487 rtl::OUString(
488 RTL_CONSTASCII_USTRINGPARAM(
489 "/org.openoffice.UI.GenericCommands/UserInterface/"
490 "Commands"))),
491 css::uno::UNO_QUERY_THROW);
492 css::uno::Sequence< rtl::OUString > names(access->getElementNames());
493 CPPUNIT_ASSERT(names.getLength() == 695);
494 // testSetSetMemberName() already removed ".uno:FontworkGalleryFloater"
495 sal_uInt32 n = osl_getGlobalTimer();
496 for (int i = 0; i < 8; ++i) {
497 for (sal_Int32 j = 0; j < names.getLength(); ++j) {
498 css::uno::Reference< css::container::XNameAccess > child;
499 if (access->getByName(names[j]) >>= child) {
500 CPPUNIT_ASSERT(child.is());
501 child->getByName(
502 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Label")));
503 child->getByName(
504 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ContextLabel")));
505 child->getByName(
506 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Properties")));
507 }
508 }
509 }
510 n = osl_getGlobalTimer() - n;
511 t_print("Reading elements took %" SAL_PRIuUINT32 " ms\n", n);
512 css::uno::Reference< css::lang::XComponent >(
513 access, css::uno::UNO_QUERY_THROW)->dispose();
514 }
515
testThreads()516 void Test::testThreads() {
517 struct Entry { rtl::OUString path; rtl::OUString relative; };
518 Entry list[] = {
519 { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
520 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Test/AString")) },
521 { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
522 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Test/AString")) },
523 { rtl::OUString(
524 RTL_CONSTASCII_USTRINGPARAM(
525 "/org.openoffice.UI.GenericCommands")),
526 rtl::OUString(
527 RTL_CONSTASCII_USTRINGPARAM(
528 "UserInterface/Commands/dotuno:WebHtml/Label")) },
529 { rtl::OUString(
530 RTL_CONSTASCII_USTRINGPARAM(
531 "/org.openoffice.UI.GenericCommands")),
532 rtl::OUString(
533 RTL_CONSTASCII_USTRINGPARAM(
534 "UserInterface/Commands/dotuno:NewPresentation/Label")) },
535 { rtl::OUString(
536 RTL_CONSTASCII_USTRINGPARAM(
537 "/org.openoffice.UI.GenericCommands")),
538 rtl::OUString(
539 RTL_CONSTASCII_USTRINGPARAM(
540 "UserInterface/Commands/dotuno:RecentFileList/Label")) },
541 { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
542 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("L10N/ooLocale")) },
543 { rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/org.openoffice.Setup")),
544 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Test/ABoolean")) }
545 };
546 std::size_t const numReaders = sizeof list / sizeof (Entry);
547 std::size_t const numWriters = numReaders - 2;
548 ReaderThread * readers[numReaders];
549 WriterThread * writers[numWriters];
550 osl::Condition stop;
551 for (std::size_t i = 0; i < numReaders; ++i) {
552 CPPUNIT_ASSERT(getKey(list[i].path, list[i].relative).hasValue());
553 readers[i] = new ReaderThread(
554 stop, *this, list[i].path, list[i].relative);
555 }
556 for (std::size_t i = 0; i < numWriters; ++i) {
557 writers[i] = new WriterThread(
558 stop, *this, list[i].path, list[i].relative);
559 }
560 for (int i = 0; i < 5; ++i) {
561 for (std::size_t j = 0; j < numReaders; ++j) {
562 rtl::OUString path;
563 rtl::OUString name;
564 normalize(list[j].path, list[j].relative, &path, &name);
565 resetKey(path, name);
566 osl::Thread::yield();
567 }
568 }
569 stop.set();
570 bool success = true;
571 for (std::size_t i = 0; i < numReaders; ++i) {
572 readers[i]->join();
573 success = success && readers[i]->getSuccess();
574 delete readers[i];
575 }
576 for (std::size_t i = 0; i < numWriters; ++i) {
577 writers[i]->join();
578 success = success && writers[i]->getSuccess();
579 delete writers[i];
580 }
581 CPPUNIT_ASSERT(success);
582 }
583
testRecursive()584 void Test::testRecursive() {
585 bool destroyed = false;
586 rtl::Reference< RecursiveTest >(
587 new SimpleRecursiveTest(*this, 100, &destroyed))->test();
588 CPPUNIT_ASSERT(destroyed);
589 }
590
testCrossThreads()591 void Test::testCrossThreads() {
592 bool destroyed = false;
593 rtl::Reference< RecursiveTest >(
594 new SimpleRecursiveTest(*this, 10, &destroyed))->test();
595 CPPUNIT_ASSERT(destroyed);
596 }
597
getKey(rtl::OUString const & path,rtl::OUString const & relative) const598 css::uno::Any Test::getKey(
599 rtl::OUString const & path, rtl::OUString const & relative) const
600 {
601 css::uno::Reference< css::container::XHierarchicalNameAccess > access(
602 createViewAccess(path), css::uno::UNO_QUERY_THROW);
603 css::uno::Any value(access->getByHierarchicalName(relative));
604 css::uno::Reference< css::lang::XComponent >(
605 access, css::uno::UNO_QUERY_THROW)->dispose();
606 return value;
607 }
608
setKey(rtl::OUString const & path,rtl::OUString const & name,css::uno::Any const & value) const609 void Test::setKey(
610 rtl::OUString const & path, rtl::OUString const & name,
611 css::uno::Any const & value) const
612 {
613 css::uno::Reference< css::container::XNameReplace > access(
614 createUpdateAccess(path), css::uno::UNO_QUERY_THROW);
615 access->replaceByName(name, value);
616 css::uno::Reference< css::util::XChangesBatch >(
617 access, css::uno::UNO_QUERY_THROW)->commitChanges();
618 css::uno::Reference< css::lang::XComponent >(
619 access, css::uno::UNO_QUERY_THROW)->dispose();
620 }
621
resetKey(rtl::OUString const & path,rtl::OUString const & name) const622 bool Test::resetKey(rtl::OUString const & path, rtl::OUString const & name)
623 const
624 {
625 //TODO: support setPropertyToDefault
626 css::uno::Reference< css::util::XChangesBatch > access(
627 createUpdateAccess(path), css::uno::UNO_QUERY_THROW);
628 css::uno::Reference< css::beans::XPropertyState > state(
629 access, css::uno::UNO_QUERY);
630 if (!state.is()) {
631 return false;
632 }
633 state->setPropertyToDefault(name);
634 access->commitChanges();
635 css::uno::Reference< css::lang::XComponent >(
636 access, css::uno::UNO_QUERY_THROW)->dispose();
637 return true;
638 }
639
createViewAccess(rtl::OUString const & path) const640 css::uno::Reference< css::uno::XInterface > Test::createViewAccess(
641 rtl::OUString const & path) const
642 {
643 css::uno::Any arg(
644 css::uno::makeAny(
645 css::beans::NamedValue(
646 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
647 css::uno::makeAny(path))));
648 return provider_->createInstanceWithArguments(
649 rtl::OUString(
650 RTL_CONSTASCII_USTRINGPARAM(
651 "com.sun.star.configuration.ConfigurationAccess")),
652 css::uno::Sequence< css::uno::Any >(&arg, 1));
653 }
654
createUpdateAccess(rtl::OUString const & path) const655 css::uno::Reference< css::uno::XInterface > Test::createUpdateAccess(
656 rtl::OUString const & path) const
657 {
658 css::uno::Any arg(
659 css::uno::makeAny(
660 css::beans::NamedValue(
661 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("nodepath")),
662 css::uno::makeAny(path))));
663 return provider_->createInstanceWithArguments(
664 rtl::OUString(
665 RTL_CONSTASCII_USTRINGPARAM(
666 "com.sun.star.configuration.ConfigurationUpdateAccess")),
667 css::uno::Sequence< css::uno::Any >(&arg, 1));
668 }
669
670 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltest");
671
672 }
673
674 NOADDITIONAL;
675