merge the formfield patch from ooo-build
[ooovba.git] / configmgr / qa / unit / performance.cxx
blob7a3e0475a4c9fd401622822a4083f376cb23a563
1 // To debug me use:
2 // $ export ENVCFGFLAGS='-me -ti -tw -tp -td'
4 /*************************************************************************
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7 *
8 * Copyright 2008 by Sun Microsystems, Inc.
10 * OpenOffice.org - a multi-platform office productivity suite
12 * $RCSfile: performance.cxx,v $
13 * $Revision: 1.3 $
15 * This file is part of OpenOffice.org.
17 * OpenOffice.org is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU Lesser General Public License version 3
19 * only, as published by the Free Software Foundation.
21 * OpenOffice.org is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU Lesser General Public License version 3 for more details
25 * (a copy is included in the LICENSE file that accompanied this code).
27 * You should have received a copy of the GNU Lesser General Public License
28 * version 3 along with OpenOffice.org. If not, see
29 * <http://www.openoffice.org/license.html>
30 * for a copy of the LGPLv3 License.
32 ************************************************************************/
34 #include "common.hxx"
36 void Test::setUp()
38 mpMagic = new Magic();
40 char const * f = getForwardString();
41 rtl::OUString args(
42 f, rtl_str_getLength(f), osl_getThreadTextEncoding());
43 //TODO: handle conversion failure
44 sal_Int32 i = args.indexOf('#');
45 if (i < 0)
46 std::abort();
48 rtl::OUString rdb(args.copy(0, i));
49 rtl::OUString regpath(args.copy(i + 1));
50 rtl::OUString regurl;
51 if (osl::FileBase::getFileURLFromSystemPath(regpath, regurl) !=
52 osl::FileBase::E_None)
53 std::abort();
55 css::uno::Reference< css::beans::XPropertySet > factory(
56 cppu::createRegistryServiceFactory(rdb), css::uno::UNO_QUERY_THROW);
57 css::uno::Reference< css::uno::XComponentContext > context(
58 factory->getPropertyValue(
59 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DefaultContext"))),
60 css::uno::UNO_QUERY_THROW);
61 cppu::ContextEntry_Init entry(
62 rtl::OUString(
63 RTL_CONSTASCII_USTRINGPARAM(
64 "/modules/com.sun.star.configuration/bootstrap/Strata")),
65 css::uno::makeAny(
66 rtl::OUString(
67 RTL_CONSTASCII_USTRINGPARAM(
68 "com.sun.star.comp.configuration.backend.LocalStratum:"))
69 + regurl));
70 mxContext = cppu::createComponentContext(&entry, 1, context);
72 CPPUNIT_ASSERT_MESSAGE ("component context is valid", mxContext.is());
74 try {
75 mxProvider = css::uno::Reference< css::lang::XMultiServiceFactory >(
76 (css::uno::Reference< css::lang::XMultiComponentFactory >(
77 mxContext->getServiceManager(), css::uno::UNO_QUERY_THROW)->
78 createInstanceWithContext(
79 rtl::OUString(
80 RTL_CONSTASCII_USTRINGPARAM(
81 "com.sun.star.configuration.ConfigurationProvider")),
82 mxContext)),
83 css::uno::UNO_QUERY_THROW);
85 } catch (css::uno::Exception&e) {
86 CPPUNIT_FAIL( "exception creating provider" );
87 throw;
91 css::uno::Reference< css::uno::XInterface >
92 Test::createView(const sal_Char *pNodepath, bool bUpdate)
94 rtl::OUString aNodePath = rtl::OUString::createFromAscii(pNodepath);
95 static const rtl::OUString kInfoViewService(
96 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationAccess")) ;
97 static const rtl::OUString kUpdateViewService(
98 RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationUpdateAccess")) ;
99 static const rtl::OUString kNodepath(RTL_CONSTASCII_USTRINGPARAM("nodepath")) ;
100 static const rtl::OUString kAsync(RTL_CONSTASCII_USTRINGPARAM("EnableAsync")) ;
102 const rtl::OUString & kViewService = bUpdate ? kUpdateViewService : kInfoViewService;
103 css::uno::Sequence< css::uno::Any > aViewArgs(2);
104 aViewArgs[0] <<= css::beans::NamedValue( kNodepath, css::uno::makeAny(aNodePath) );
105 aViewArgs[1] <<= css::beans::NamedValue( kAsync, css::uno::makeAny(sal_False) );
107 css::uno::Reference< css::uno::XInterface > xView(
108 mxProvider->createInstanceWithArguments( kViewService, aViewArgs ) );
109 return xView;
112 void disposeComponent (const css::uno::Reference<css::uno::XInterface> &xComp)
114 css::uno::Reference< css::lang::XComponent >(
115 xComp, css::uno::UNO_QUERY_THROW)->dispose();
118 void Test::tearDown()
120 disposeComponent (mxProvider);
121 disposeComponent (mxContext);
123 delete mpMagic;
126 void Test::normalizePathKey (rtl::OString &rPath, rtl::OString &rKey)
128 sal_Int32 idx = rKey.lastIndexOf("/");
129 if (idx > 0) {
130 rPath += "/";
131 rPath += rKey.copy (0, idx);
132 rKey = rKey.copy (idx + 1);
133 // t_print ("write to '%s' '%s'\n", (const sal_Char *)rPath,
134 // (const sal_Char *)rKey);
138 css::uno::Any Test::getKey (const sal_Char *pPath, rtl::OUString aName)
140 css::uno::Reference< css::container::XHierarchicalNameAccess > xNameAccess(
141 createView(pPath, false), css::uno::UNO_QUERY_THROW);
142 css::uno::Any aVal;
143 aVal = xNameAccess->getByHierarchicalName (aName);
144 disposeComponent (xNameAccess);
145 return aVal;
148 void Test::setKey (const sal_Char *pPath, rtl::OUString aName, css::uno::Any a)
150 css::uno::Reference< css::util::XChangesBatch > xAppView;
152 xAppView = css::uno::Reference< css::util::XChangesBatch > (
153 createView(pPath, true), css::uno::UNO_QUERY_THROW );
154 css::uno::Reference< css::container::XNameReplace > xSettings(xAppView, css::uno::UNO_QUERY_THROW);
155 rtl::OUString aStr;
157 // set key
158 xSettings->replaceByName(aName, a);
159 xAppView->commitChanges();
161 disposeComponent(xAppView);
164 void Test::resetKey (const sal_Char *pPath, rtl::OUString aName)
166 css::uno::Reference< css::util::XChangesBatch > xAppView;
168 // reset to default
169 xAppView = css::uno::Reference< css::util::XChangesBatch > ( createView(pPath, true), css::uno::UNO_QUERY_THROW );
170 css::uno::Reference< css::container::XNameReplace > xSettings(xAppView, css::uno::UNO_QUERY_THROW);
172 css::uno::Reference< css::beans::XPropertyState > xSettingsState(xSettings, css::uno::UNO_QUERY);
173 xSettingsState->setPropertyToDefault(aName);
174 xAppView->commitChanges();
176 disposeComponent(xAppView);
179 void Test::keyFetch()
181 try {
182 rtl::OUString aStr;
183 if (!(getKey ("/org.openoffice.Setup", "L10N/ooLocale") >>= aStr))
184 CPPUNIT_FAIL("to fetch key");
185 if (!(getKey ("/org.openoffice.Setup", "Test/AString") >>= aStr))
186 CPPUNIT_FAIL("to fetch key");
187 } CATCH_FAIL ("fetching key")
190 void Test::keySet()
192 try {
193 setKey ("/org.openoffice.Setup/Test",
194 rtl::OUString::createFromAscii("AString"),
195 css::uno::makeAny (rtl::OUString::createFromAscii("baa")));
197 // check value
198 rtl::OUString aStr;
199 if (!(getKey ("/org.openoffice.Setup/Test", "AString") >>= aStr))
200 CPPUNIT_FAIL("to fetch key");
202 CPPUNIT_ASSERT_MESSAGE ("check set value valid", aStr.equalsAscii("baa"));
203 } CATCH_FAIL ("exception setting keys" )
206 void Test::keyReset()
208 try {
209 resetKey ("/org.openoffice.Setup/Test",
210 rtl::OUString::createFromAscii("AString"));
212 // check value
213 rtl::OUString aStr;
214 if (!(getKey ("/org.openoffice.Setup/Test", "AString") >>= aStr))
215 CPPUNIT_FAIL("to fetch key");
217 CPPUNIT_ASSERT_MESSAGE ("check default value valid",
218 aStr == rtl::OUString::createFromAscii("Foo"));
219 } CATCH_FAIL ("exception setting keys" )
222 // This simulates the framework UI description code paths
223 void Test::readCommands()
225 rtl::OUString aPropUILabel( RTL_CONSTASCII_USTRINGPARAM( "Label" ));
226 rtl::OUString aPropUIContextLabel( RTL_CONSTASCII_USTRINGPARAM( "ContextLabel" ));
227 rtl::OUString aPropProperties( RTL_CONSTASCII_USTRINGPARAM( "Properties" ));
229 try {
230 css::uno::Reference< css::container::XNameAccess > xNameAccess (
231 createView("/org.openoffice.UI.GenericCommands/UserInterface/Commands", false),
232 css::uno::UNO_QUERY_THROW);
234 CPPUNIT_ASSERT_MESSAGE ("fetched UI generic commands", xNameAccess.is());
236 css::uno::Any a;
237 css::uno::Sequence< rtl::OUString > aNameSeq = xNameAccess->getElementNames();
239 CPPUNIT_ASSERT_MESSAGE ("right element / sequence", aNameSeq.getLength() == 696);
240 sal_uInt32 end, start = osl_getGlobalTimer();
241 for ( sal_Int32 j = 0; j < 8; j++ )
243 for ( sal_Int32 i = 0; i < aNameSeq.getLength(); i++ )
248 css::uno::Reference< css::container::XNameAccess > xChildNameAccess;
249 // This is the slow bit ! ...
250 // Creating the @#$@#$ing XNameAccess object [ 650 times ]
251 // which we then use to 'getByName' etc.
252 a = xNameAccess->getByName( aNameSeq[i] );
253 if ( a >>= xChildNameAccess )
255 a = xChildNameAccess->getByName( aPropUILabel );
256 a = xChildNameAccess->getByName( aPropUIContextLabel );
257 a = xChildNameAccess->getByName( aPropProperties );
260 } CATCH_FAIL( "fetching keys" );
263 end = osl_getGlobalTimer();
264 t_print ("Reading elements took %d ms\n", (int)(end-start));
265 disposeComponent (xNameAccess);
266 } CATCH_FAIL( "accessing commands" );
269 CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests");
271 NOADDITIONAL;