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