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