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