update dev300-m58
[ooovba.git] / configmgr / workben / memory / memorytests.cxx
blob263bd7186d79e1b61b725044c7b5c7cf374e927c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: memorytests.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_configmgr.hxx"
33 #define _PRIVATE_TEST_
35 #include <iostream>
36 #include <vector>
37 #include "treeload.hxx"
39 #include <fstream>
41 #define ENABLE_MEMORYMEASURE
42 #define ENABLE_LOGMECHANISM
44 // If you wish to enable this memory measure macros ... you need "windows.h"
45 // But it's not agood idea to include it in your header!!! Because it's not compatible to VCL header .-(
46 // So you must include it here ... in cxx, where you whish to use it.
47 #ifdef ENABLE_MEMORYMEASURE
48 #define VCL_NEED_BASETSD
49 #include <tools/presys.h>
50 #include <windows.h>
51 #include <tools/postsys.h>
52 #undef VCL_NEED_BASETSD
53 #endif
54 #include "memorymeasure.hxx"
56 #include "logmechanism.hxx"
58 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
59 #include <com/sun/star/uno/Type.hxx>
60 #include <com/sun/star/uno/TypeClass.hpp>
62 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
63 #include <com/sun/star/container/XNameAccess.hpp>
64 #include <com/sun/star/container/XHierarchicalName.hpp>
65 #include <com/sun/star/container/XNamed.hpp>
66 #include <com/sun/star/container/XNameReplace.hpp>
67 #include <com/sun/star/container/XChild.hpp>
68 #include <com/sun/star/beans/XExactName.hpp>
69 #include <com/sun/star/util/XChangesBatch.hpp>
70 #include <com/sun/star/lang/XComponent.hpp>
72 #include <rtl/ustring.hxx>
73 #include <rtl/string.hxx>
74 #include <cppuhelper/servicefactory.hxx>
75 #include <com/sun/star/uno/Sequence.h>
76 #include <com/sun/star/uno/Any.h>
77 #include <osl/profile.hxx>
78 #include <osl/process.h>
79 #include <osl/file.h>
81 #include <conio.h>
83 #include "createpropertyvalue.hxx"
85 #include "typeconverter.hxx"
87 #include "testmodules.hxx"
89 #include "valuenode.hxx"
91 namespace configmgr
94 using namespace std;
96 namespace css = com::sun::star;
97 namespace uno = css::uno;
98 namespace lang = css::lang;
100 using namespace uno;
101 using namespace lang;
103 using namespace ::com::sun::star::container;
104 using namespace ::com::sun::star::beans;
105 using namespace ::com::sun::star::util;
107 using ::rtl::OUString;
108 using ::rtl::OString;
110 using namespace ::cppu;
112 #define ASCII(x) ::rtl::OUString::createFromAscii(x)
114 ostream& operator << (ostream& out, rtl::OUString const& aStr)
116 sal_Unicode const* const pStr = aStr.getStr();
117 sal_Unicode const* const pEnd = pStr + aStr.getLength();
118 for (sal_Unicode const* p = pStr; p < pEnd; ++p)
119 if (0 < *p && *p < 127) // ASCII
120 out << char(*p);
121 else
122 out << "[\\u" << hex << *p << "]";
123 return out;
126 void showSequence(const Sequence<OUString> &aSeq)
128 OUString aArray;
129 const OUString *pStr = aSeq.getConstArray();
130 for (int i=0;i<aSeq.getLength();i++)
132 OUString aStr = pStr[i];
133 // aArray += aStr + ASCII(", ");
134 cout << aStr << endl;
136 volatile int dummy = 0;
139 //=============================================================================
141 inline void operator <<= (::rtl::OUString& _rUnicodeString, const sal_Char* _pAsciiString)
143 _rUnicodeString = ::rtl::OUString::createFromAscii(_pAsciiString);
146 inline void operator <<= (::rtl::OUString& _rUnicodeString, const ::rtl::OString& _rAsciiString)
148 _rUnicodeString <<= _rAsciiString.getStr();
151 inline void operator <<= (Any& _rUnoValue, const sal_Char* _pAsciiString)
153 _rUnoValue <<= ::rtl::OUString::createFromAscii(_pAsciiString);
156 inline void operator <<= (Any& _rUnoValue, const ::rtl::OString& _rAsciiString)
158 _rUnoValue <<= _rAsciiString.getStr();
161 inline void operator <<= (::rtl::OString& _rAsciiString, ::rtl::OUString const& _rUnicodeString )
163 _rAsciiString = rtl::OUStringToOString(_rUnicodeString, RTL_TEXTENCODING_ASCII_US).getStr();
166 // -----------------------------------------------------------------------------
168 rtl::OString input(const char* pDefaultText, char cEcho)
170 // PRE: a Default Text would be shown, cEcho is a Value which will show if a key is pressed.
171 const int MAX_INPUT_LEN = 500;
172 char aBuffer[MAX_INPUT_LEN];
174 strcpy(aBuffer, pDefaultText);
175 int nLen = strlen(aBuffer);
177 #ifdef WNT
178 char ch = '\0';
180 cout << aBuffer;
181 cout.flush();
183 while(ch != 13)
185 ch = getch();
186 if (ch == 8)
188 if (nLen > 0)
190 cout << "\b \b";
191 cout.flush();
192 --nLen;
193 aBuffer[nLen] = '\0';
195 else
197 cout << "\a";
198 cout.flush();
201 else if (ch != 13)
203 if (nLen < MAX_INPUT_LEN)
205 if (cEcho == 0)
207 cout << ch;
209 else
211 cout << cEcho;
213 cout.flush();
214 aBuffer[nLen++] = ch;
215 aBuffer[nLen] = '\0';
217 else
219 cout << "\a";
220 cout.flush();
224 #else
225 if (!cin.getline(aBuffer,sizeof aBuffer))
226 return OString();
227 #endif
228 return rtl::OString(aBuffer);
231 // -----------------------------------------------------------------------------
232 rtl::OUString enterValue(const char* _aStr, const char* _aDefault, bool _bIsAPassword)
234 cout << _aStr;
235 cout.flush();
237 rtl::OUString sValue;
238 sValue <<= input(_aDefault, _bIsAPassword ? '*' : 0);
239 return sValue;
241 //=============================================================================
243 uno::Reference< lang::XMultiServiceFactory > getORB();
244 // -----------------------------------------------------------------------------
247 Reference< XChangesBatch > xChangesBatch = NULL;
248 void commit()
250 if (xChangesBatch.is())
252 xChangesBatch->commitChanges();
256 // -----------------------------------------------------------------------------
257 static sal_Bool s_bInitialized = sal_False;
258 #ifdef LLA_PRIVAT_DEBUG
259 // static const sal_Char* s_pSourcePath = "//./l|/src632/configmgr/workben/local_io/share";
260 // static const sal_Char* s_pUpdatePath = "//./l|/src632/configmgr/workben/local_io/user";
261 static const sal_Char* s_pSourcePath = "file:///f:/office60_633/share/config/registry";
262 static const sal_Char* s_pUpdatePath = "file:///f:/office60_633/user/config/registry";
263 static const sal_Char* s_pRootNode = "org.openoffice.test";
264 static const sal_Char* s_pServerType = "local";
265 static const sal_Char* s_pLocale = "de-DE";
266 static const sal_Char* s_pServer = "";
267 static const sal_Char* s_pUser = "";
268 static const sal_Char* s_pPassword = "";
269 #else
270 static const sal_Char* s_pSourcePath = "file:///g:/src/configmgr/workben/local_io/share";
271 static const sal_Char* s_pUpdatePath = "file:///g:/src/configmgr/workben/local_io/user";
272 static const sal_Char* s_pRootNode = "org.openoffice.test";
273 static const sal_Char* s_pServerType = "local";
274 static const sal_Char* s_pLocale = "de-DE";
275 static const sal_Char* s_pServer = "lautrec-3108:19205";
276 static const sal_Char* s_pUser = "lars";
277 static const sal_Char* s_pPassword = "";
278 #endif
280 static bool m_bChange = false;
281 // -----------------------------------------------------------------------------
282 static void loadDefaults()
284 if (s_bInitialized)
285 return;
287 s_bInitialized = sal_True;
291 // the executable file name
292 ::rtl::OUString sExecutable;
293 osl_getExecutableFile(&sExecutable.pData);
294 // cut the name, add a cfgapi.ini to the path
295 sal_Int32 nLastSep = sExecutable.lastIndexOf('/');
296 if (-1 != nLastSep)
297 sExecutable = sExecutable.copy(0, nLastSep + 1);
298 #ifdef UNX
299 sExecutable += ::rtl::OUString::createFromAscii("cfgapirc");
300 #else
301 sExecutable += ::rtl::OUString::createFromAscii("cfgapi.ini");
302 #endif
303 ::rtl::OUString sNormalized;
304 sNormalized = sExecutable;
305 if (1) // osl_File_E_None == osl_normalizePath(sExecutable.pData, &sNormalized.pData))
307 ::osl::Profile aProfile(sNormalized);
309 static ::rtl::OString sSection("defaults");
310 static ::rtl::OString sSourcePath("sourcepath");
311 static ::rtl::OString sUpdatePath("updatepath");
312 static ::rtl::OString sRootNode("rootnode");
313 static ::rtl::OString sServerType("servertype");
314 static ::rtl::OString sLocale("Locale");
315 static ::rtl::OString sServer("Server");
316 static ::rtl::OString sUser("User");
317 static ::rtl::OString sPassword("Password");
319 // read some strings.
320 // Do this static because we want to redirect the global static character pointers to the buffers.
321 static ::rtl::OString s_sSourcePath = aProfile.readString(sSection, sSourcePath, s_pSourcePath);
322 static ::rtl::OString s_sUpdatePath = aProfile.readString(sSection, sUpdatePath, s_pUpdatePath);
323 static ::rtl::OString s_sRootNode = aProfile.readString(sSection, sRootNode, s_pRootNode);
324 static ::rtl::OString s_sServerType = aProfile.readString(sSection, sServerType, s_pServerType);
325 static ::rtl::OString s_sLocale = aProfile.readString(sSection, sLocale, s_pLocale);
326 static ::rtl::OString s_sServer = aProfile.readString(sSection, sServer, s_pServer);
327 static ::rtl::OString s_sUser = aProfile.readString(sSection, sUser, s_pUser);
328 static ::rtl::OString s_sPassword = aProfile.readString(sSection, sPassword, s_pPassword);
330 // do this redirection
331 s_pSourcePath = s_sSourcePath.getStr();
332 s_pUpdatePath = s_sUpdatePath.getStr();
333 s_pRootNode = s_sRootNode.getStr();
334 s_pServerType = s_sServerType.getStr();
335 s_pLocale = s_sLocale.getStr();
336 s_pServer = s_sServer.getStr();
337 s_pUser = s_sUser.getStr();
338 s_pPassword = s_sPassword.getStr();
341 catch(std::exception& e)
343 e.what(); // silence warnings
347 // -----------------------------------------------------------------------------
348 Sequence<Any> createSequence(const OUString &sUser, const OUString &sPasswd)
350 Sequence< Any > aCPArgs;
352 if (sUser.getLength() > 0)
354 aCPArgs.realloc(1);
355 aCPArgs[0] <<= configmgr::createPropertyValue(ASCII("user"), sUser);
357 if (sPasswd.getLength() > 0)
359 aCPArgs.realloc(2);
360 aCPArgs[1] <<= configmgr::createPropertyValue(ASCII("password"), sPasswd);
362 return aCPArgs;
365 //=============================================================================
366 #include <string.h>
367 #if (defined UNX) || (defined OS2)
368 #else
369 #include <conio.h>
370 #endif
372 // -----------------------------------------------------------------------------
374 void test_configuration_provider(uno::Reference<lang::XMultiServiceFactory> _xCfgProvider,
375 rtl::OUString const& _sUser, bool _bLocal, sal_Int32 _nCount);
378 // -----------------------------------------------------------------------------
380 uno::Reference<lang::XMultiServiceFactory>
381 getProvider(
382 uno::Reference< lang::XMultiServiceFactory > _xServiceRegistry,
383 rtl::OUString const& _sServerType,
384 rtl::OUString const& _sSharePath, rtl::OUString const& _sUserPath,
385 bool &_bLocal)
389 Sequence< Any > aCPArgs;
391 OUString sServerType = _sServerType; // enterValue("servertype: ", s_pServerType, false);
393 rtl::OUString sUser;
395 _bLocal = sServerType.equalsIgnoreAsciiCase(ASCII("local")) || sServerType.equalsIgnoreAsciiCase(ASCII("setup"));
396 if (!_bLocal)
398 rtl::OUString sServer;
399 sServer = enterValue("server : ", s_pServer,false);
400 cout << endl;
402 sUser = enterValue("user : ", s_pUser, false);
403 cout << endl;
405 OUString sPasswd = enterValue("password: ", s_pPassword, true);
406 cout << endl;
408 aCPArgs = createSequence(sUser, sPasswd);
410 aCPArgs.realloc(aCPArgs.getLength() + 1);
411 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("server"), sServer);
413 OUString sTimeout = ASCII("10000");
414 aCPArgs.realloc(aCPArgs.getLength() + 1);
415 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("timeout"), sTimeout);
418 else
420 rtl::OUString sSharePath, sUserPath;
421 sSharePath = _sSharePath;// enterValue("share path: ", s_pSourcePath, false);
422 // cout << endl;
423 sUserPath = _sUserPath; // enterValue("user path : ", s_pUpdatePath, false);
424 // cout << endl;
426 aCPArgs.realloc(aCPArgs.getLength() + 1);
427 sal_Int32 nCount = aCPArgs.getLength() - 1;
428 Any *pAny = &aCPArgs[nCount];
429 *pAny <<= configmgr::createPropertyValue(ASCII("sourcepath"), sSharePath);
430 aCPArgs.realloc(aCPArgs.getLength() + 1);
431 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("updatepath"), sUserPath);
434 aCPArgs.realloc(aCPArgs.getLength() + 1);
435 aCPArgs[aCPArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("servertype"), sServerType);
437 Reference< XMultiServiceFactory > xCfgProvider(
438 _xServiceRegistry->createInstanceWithArguments(
439 ::rtl::OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"),
440 aCPArgs),
441 UNO_QUERY);
442 if (!xCfgProvider.is())
444 ::flush(cout);
445 cerr << "Could not create the configuration provider !\n\n";
446 return 0;
448 // -----------------------------------------------------------------------------
449 return xCfgProvider;
451 catch (Exception& e)
453 ::flush(cout);
454 cerr << "Caught exception: " << e.Message << endl;
456 return 0;
459 // -----------------------------------------------------------------------------
460 sal_Int32 m_nCount = 0;
462 void test(uno::Reference<lang::XMultiServiceFactory> _xORB, rtl::OUString const& _sSharePath,
463 rtl::OUString const& _sUserPath)
466 rtl::OUString sUser;
467 bool bLocal;
468 cout << ++m_nCount << ". start test with new provider\n";
470 START_MEMORYMEASURE_FOR( aMemoryInfo, "*** API Test Execution ***" );
472 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "initialisierungs-check" );
474 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "- Erzeuge Provider" );
476 uno::Reference<lang::XMultiServiceFactory>xCfgProvider =
477 getProvider(_xORB, ASCII("local"), _sSharePath, _sUserPath,
478 bLocal);
480 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "- Habe Provider, starte Test" );
482 test_configuration_provider(xCfgProvider, sUser, bLocal, 0); // xml
484 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "- Test gelaufen, starte erneut" );
486 test_configuration_provider(xCfgProvider, sUser, bLocal, 0); // xml
488 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "- Test gelaufen, entsorge Provider" );
490 uno::Reference<lang::XComponent>xComponent(xCfgProvider,UNO_QUERY);
491 xComponent->dispose();
493 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "- Provider disposed" );
495 LOG_MEMORYMEASURE( "---------------- API Memory Test 2-----------------------------", "- Test memory traces.", aMemoryInfo );
498 cout << "finish provider test\n";
500 // Test Version 1 and 3, it MUST be equal
503 // -----------------------------------------------------------------------------
504 // -----------------------------------------------------------------------------
505 // -----------------------------------------------------------------------------
506 static rtl::OUString makeFileURL(OUString const& sMaybeURL)
508 rtl::OUString const fileURLStart(RTL_CONSTASCII_USTRINGPARAM("file:/"));
510 if ( 0 != fileURLStart.compareTo(sMaybeURL, fileURLStart.getLength()) )
512 OUString sURL;
513 if (!osl_getFileURLFromSystemPath(sMaybeURL.pData, &sURL.pData))
514 return sURL;
517 return sMaybeURL;
519 // -----------------------------------------------------------------------------
520 static rtl::OUString makeSystemPath(OUString const& sMaybeURL)
522 rtl::OUString const fileURLStart(RTL_CONSTASCII_USTRINGPARAM("file:/"));
524 if ( 0 == fileURLStart.compareTo(sMaybeURL, fileURLStart.getLength()) )
526 OUString sSysPath;
527 if (!osl_getSystemPathFromFileURL(sMaybeURL.pData, &sSysPath.pData))
528 return sSysPath;
531 return sMaybeURL;
533 // -----------------------------------------------------------------------------
534 // ---------------------------------- M A I N ----------------------------------
535 // -----------------------------------------------------------------------------
537 int main( int argc, char * argv[] )
539 TimeValue aTimeout;
540 aTimeout.Seconds = 5;
541 aTimeout.Nanosec = 0;
543 sal_Int32 nSizeISubtree = sizeof(ISubtree);
544 sal_Int32 nSizeINode = sizeof(INode);
545 sal_Int32 nSizeIValueNode = sizeof(ValueNode);
547 loadDefaults();
549 Reference< XMultiServiceFactory > xORB = getORB();
551 rtl::OUString sSharePath = makeSystemPath(enterValue("share path: ", s_pSourcePath, false));
552 cout << endl;
553 rtl::OUString sUserPath = makeSystemPath(enterValue("user path : ", s_pUpdatePath, false));
554 cout << endl;
556 // test(xORB, sSharePath, sUserPath, ASCII("org.openoffice.test"));
558 // char* pMem = new char[1000 * 1000 * 10];
559 // showMemoryStatistic();
561 // test(xORB, sSharePath, sUserPath, ASCII("org.openoffice.Office.Views"));
563 START_MEMORYMEASURE_FOR( aMemoryInfo, "*** API Test Main ***" );
565 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "initialisierungs-check" );
567 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "starte test !" );
569 test(xORB, sSharePath, sUserPath);
571 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "tests beendet !" );
573 // stop the programm clear.
574 Reference< XComponent > xComponent(xORB, UNO_QUERY);
575 xComponent->dispose();
576 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "ORB disposed." );
578 LOG_MEMORYMEASURE( "---------------- API Memory Test-------------------------------", "Outer memory traces.", aMemoryInfo );
580 return 0;
583 ///////////////////////////////////////////////////////////////////////////////////////////
584 void test(Reference< XHierarchicalName >& xAccessName)
586 if (xAccessName.is())
588 // cout << "Accessing Node: " << xAccessName->getHierarchicalName();
590 else
592 // cout << "BUG: XHierarchicalName not available";
594 // cout << endl;
596 void test(Reference< XNamed >& xAccess)
598 if (xAccess.is())
600 // cout << "Node is named: " << xAccess->getName();
602 else
604 // cout << "BUG: XNamed not available";
606 // cout << endl;
609 ///////////////////////////////////////////////////////////////////////////////////////////
610 void fillAllNames(Reference<XNameAccess >& xAccess, Sequence<OUString>& _aSeq)
612 if (xAccess.is())
614 _aSeq = Sequence <OUString>(xAccess->getElementNames());
616 // cout << "Element Names: (" << _aSeq.getLength() << ")";
617 // for (int i = 0; i < _aSeq.getLength(); ++i)
618 // cout << "\n[" << i << "] -\t" << _aSeq[i];
619 //cout << endl;
621 else
623 // cout << "BUG: XNameAccess not available";
625 // cout << endl;
627 void write(Reference< XChild >& xChild)
629 if (xChild.is())
631 // cout << "\n[ P ] -\tParent";
633 else
635 // cout << "BUG: Parent not available (no XChild)";
637 // cout << endl;
639 ///////////////////////////////////////////////////////////////////////////////////////////
641 // -----------------------------------------------------------------------------
642 Reference< XInterface > readaccess(uno::Reference< lang::XMultiServiceFactory > &xMSF,
643 uno::Reference< uno::XInterface > const& xIface,
644 rtl::OString const& buf,
645 ostream& outStream)
647 Reference< XInterface > xNext;
650 Reference< XNameAccess > xAccess(xIface, UNO_QUERY);
651 Reference< XHierarchicalNameAccess > xDeepAccess(xIface, UNO_QUERY);
652 Reference< XExactName > xExactName(xIface, UNO_QUERY);
654 if (xAccess.is() || xDeepAccess.is())
656 OUString aName;
657 OUString aInput = OUString::createFromAscii(buf);
659 if (xExactName.is())
661 ::rtl::OUString sTemp = xExactName->getExactName(aInput);
662 if (sTemp.getLength())
663 aInput = sTemp;
666 if (xAccess.is() && xAccess->hasByName(aInput))
668 aName = aInput;
670 else if (xDeepAccess.is() && xDeepAccess->hasByHierarchicalName(aInput))
672 aName = aInput;
674 else if ('0' <= buf[0] && buf[0] <= '9' && xAccess.is())
676 int n = atoi(buf);
677 Sequence<OUString> aNames = xAccess->getElementNames();
678 if (0 <= n && n < aNames.getLength())
679 aName = aNames[n];
682 if (aName.getLength())
684 bool bNest = aInput.indexOf(sal_Unicode('/')) >= 0;
686 Any aElement = bNest ?
687 ( xDeepAccess.is() ?
688 xDeepAccess->getByHierarchicalName(aName) : Any()
690 ( xAccess.is() ?
691 xAccess->getByName(aName) : Any()
694 while (aElement.getValueTypeClass() == TypeClass_ANY)
696 Any aWrap(aElement);
697 aWrap >>= aElement;
699 sal_Bool bValue = true;
700 sal_Bool bValueOk = false;
702 switch (aElement.getValueTypeClass() )
704 case TypeClass_INTERFACE:
705 bValue = false;
706 if (aElement >>= xNext)
708 outStream << "Group: " << aName << endl;
710 else
712 outStream << "ERROR: can't get the interface" << endl;
714 break;
715 case TypeClass_BOOLEAN:
717 sal_Bool* pVal = (sal_Bool*)aElement.getValue();
718 bValueOk = (pVal != 0);
720 outStream << "VALUE '" << aName << "' is a BOOLEAN = ";
721 if (!bValueOk)
722 outStream << "NULL (error!!)";
723 else if (*pVal)
724 outStream << "'TRUE'";
725 else
726 outStream << "'FALSE'";
728 outStream << endl;
730 // tryToChange(xAccess, aName, pVal);
731 break;
733 case TypeClass_SHORT:
735 sal_Int16 aValue;
736 outStream << "VALUE '" << aName << "' is a SHORT (16 bit) = ";
737 if (bValueOk = (aElement >>= aValue))
739 outStream << aValue;
740 // tryToChange(xAccess, aName, aValue);
742 else
744 outStream << "ERROR RETRIEVING VALUE";
746 outStream << endl;
748 break;
750 case TypeClass_LONG:
753 sal_Int32 aValue;
754 outStream << "VALUE '" << aName << "' is a INT (32 bit) = ";
755 if (bValueOk = (aElement >>= aValue))
757 outStream << aValue;
758 // tryToChange(xAccess, aName, aValue);
760 else
762 outStream << "ERROR RETRIEVING VALUE";
764 outStream << endl;
765 break;
767 case TypeClass_HYPER:
769 sal_Int64 aValue;
770 outStream << "VALUE '" << aName << "' is a LONG (64 bit) = ";
771 if (bValueOk = (aElement >>= aValue))
773 outStream << double(aValue);
774 // tryToChange(xAccess, aName, aValue);
776 else
778 outStream << "ERROR RETRIEVING VALUE";
780 outStream << endl;
781 break;
783 case TypeClass_DOUBLE:
785 double aValue;
786 outStream << "VALUE '" << aName << "' is a DOUBLE = ";
787 if (bValueOk = (aElement >>= aValue))
789 outStream << aValue;
791 else
793 outStream << "ERROR RETRIEVING VALUE";
795 outStream << endl;
796 break;
798 case TypeClass_STRING:
800 OUString aValue;
801 outStream << "VALUE '" << aName << "' is a STRING = ";
802 if (bValueOk = (aElement >>= aValue))
804 outStream << "\"" << aValue << "\"";
805 // tryToChange(xAccess, aName, aValue);
807 else
809 outStream << "ERROR RETRIEVING VALUE";
811 outStream << endl;
812 break;
814 case TypeClass_SEQUENCE:
816 outStream << "VALUE '" << aName << "' is a SEQUENCE or BINARY" << endl;
818 Type aTypeS = configmgr::getSequenceElementType(aElement.getValueType());
819 OUString sType = configmgr::toTypeName(aTypeS.getTypeClass());
820 outStream << "UNO type is " << aElement.getValueType().getTypeName() << endl;
821 outStream << "Real type is Sequence<" << sType << ">" << endl;
822 // outSequence(aElement, aTypeS, outStream);
823 bValueOk = true;
824 break;
826 case TypeClass_VOID:
827 outStream << "ELEMENT '" << aName << "' is NULL and VOID " << endl;
828 bValueOk = true;
829 break;
830 default:
831 outStream << "Error: ELEMENT '" << aName << "' is of unknown or unrecognized type" << endl;
832 break;
836 else
838 outStream << "Error: No element \"" << aInput << "\" found." <<endl;
842 catch (Exception& e)
844 outStream << "An Exception occurred: " << e.Message << endl;
846 catch (...)
848 outStream << "An UNKNOWN Exception occurred !" << endl;
851 return xNext;
857 // -----------------------------------------------------------------------------
858 void test_read_access( uno::Reference< lang::XMultiServiceFactory > &xMSF,
859 uno::Reference< uno::XInterface >& xIface,
860 ofstream & out)
862 Sequence<OUString> aAllNames;
864 using com::sun::star::uno::UNO_QUERY;
866 // cout << "\n\n---------------------------------------------------------------" << endl;
867 Reference< XNameAccess > xAccess(xIface, UNO_QUERY);
868 Reference< XChild > xChild(xIface, UNO_QUERY);
869 Reference< XHierarchicalName > xAccessPath(xIface,UNO_QUERY);
870 Reference< XNamed > xAccessName(xIface,UNO_QUERY);
871 // Reference< XHierarchicalNameAccess >& xAccess(xIface, UNO_QUERY);
873 test(xAccessPath);
874 test(xAccessName);
875 fillAllNames(xAccess, aAllNames);
876 write(xChild);
878 for (sal_Int32 i=0;i<aAllNames.getLength();i++)
880 OString aValue;
881 aValue <<= aAllNames[i];
882 uno::Reference<uno::XInterface> xFace = readaccess(xMSF, xIface, aValue, out);
883 if (xFace.is())
885 test_read_access(xMSF, xFace, out);
890 // -----------------------------------------------------------------------------
891 void test_read_access( uno::Reference< lang::XMultiServiceFactory > &xMSF,
892 uno::Reference< uno::XInterface >& xIface,
893 rtl::OString aFilename)
895 ofstream out(aFilename.getStr());
896 test_read_access(xMSF, xIface, out);
899 // -----------------------------------------------------------------------------
900 void test_configuration_provider(uno::Reference<lang::XMultiServiceFactory> _xCfgProvider,
901 rtl::OUString const& _sUser, bool _bLocal,
902 sal_Int32 _nCount)
904 START_MEMORYMEASURE_FOR( aMemoryInfo, "*** Configuration Provider Loop Test ***" );
905 START_MEMORYMEASURE_FOR( aInnerMemoryInfo, "*** Configuration Provider Module Details ***" );
907 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "initialisierungs-check" );
908 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, "initialisierungs-check" );
910 std::vector< Reference< XInterface > > aLoadedModules;
911 aLoadedModules.reserve(configtest::s_nTestModules);
913 Sequence< Any > aArgs;
914 aArgs = createSequence(_sUser, ASCII(""));
916 if (!_bLocal)
918 OUString sLocale = enterValue("locale : ", s_pLocale, false);
919 cout << endl;
920 aArgs.realloc(aArgs.getLength() + 1);
921 aArgs[aArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("locale"), sLocale);
924 #if 0
925 sal_Bool bLazyWrite = true;
926 aArgs.realloc(aArgs.getLength() + 1);
927 aArgs[aArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("lazywrite"), bLazyWrite);
928 #else
929 sal_Bool bNoCache = true;
930 aArgs.realloc(aArgs.getLength() + 1);
931 aArgs[aArgs.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("nocache"), bNoCache);
932 #endif
934 sal_Int32 nPathIdx = aArgs.getLength();
935 aArgs.realloc(nPathIdx + 1);
937 const OString sInnerInfoText("- - - Loading module: ");
938 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, "- - - Before Loading Modules" );
939 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "- - Prepared Arguments - Lade Module" );
941 for (char const * const * ppTestModule = configtest::s_aTestModules; *ppTestModule; ++ppTestModule)
943 OUString sPath = OUString::createFromAscii(*ppTestModule);
944 cout << "\t" << ++_nCount << ". test with node: " << sPath << endl;
946 aArgs[nPathIdx] <<= configmgr::createPropertyValue(ASCII("nodepath"), sPath);
948 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, sInnerInfoText.concat(*ppTestModule) );
949 Reference< XInterface > xIFace = _xCfgProvider->createInstanceWithArguments(
950 /* OUString::createFromAscii("com.sun.star.configuration.ConfigurationUpdateAccess"), */
951 OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"),
952 aArgs);
953 // cout << "---------------------------------------------------------------\n Configuration Read/Write Access created !\n---------------------------------------------------------------" << endl;
955 aLoadedModules.push_back(xIFace);
957 xChangesBatch = Reference< XChangesBatch >(xIFace, UNO_QUERY);
959 Sequence<OUString> aSeq = _xCfgProvider->getAvailableServiceNames();
961 OString sPath;
962 sPath <<= _sPath;
964 OString aFilename = "c:\\temp\\fileout_";
965 aFilename += sPath;
966 aFilename += OString::valueOf(_nCount);
967 aFilename += ".txt";
968 test_read_access(_xCfgProvider, xIFace, aFilename);
971 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, "- - - Done Loading modules" );
973 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "- - Alle Module geladen" );
975 aLoadedModules.clear();
977 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "- - Module released" );
979 LOG_MEMORYMEASURE( "---------------- API Memory Test 3 -----------------------------", "- - Provider memory traces.", aMemoryInfo );
980 LOG_MEMORYMEASURE( "---------------- API Memory Test 4 -----------------------------", "- - - Module memory traces.", aInnerMemoryInfo );
985 // -----------------------------------------------------------------------------
986 // ----------------------------------- Main 2 -----------------------------------
987 // -----------------------------------------------------------------------------
989 int requestTest( int argc, char * argv[] )
991 TimeValue aTimeout;
992 aTimeout.Seconds = 5;
993 aTimeout.Nanosec = 0;
995 sal_Int32 nSizeISubtree = sizeof(ISubtree);
996 sal_Int32 nSizeINode = sizeof(INode);
997 sal_Int32 nSizeIValueNode = sizeof(ValueNode);
999 loadDefaults();
1001 Reference< XMultiServiceFactory > xORB = getORB();
1003 rtl::OUString sSharePath = makeFileURL(enterValue("share path: ", s_pSourcePath, false));
1004 cout << endl;
1005 rtl::OUString sUserPath = makeFileURL(enterValue("user path : ", s_pUpdatePath, false));
1006 cout << endl;
1008 START_MEMORYMEASURE_FOR( aMemoryInfo, "*** Request Tree Test ***" );
1010 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "initialisierungs-check" );
1012 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "create tree manager" );
1014 OTreeLoad aTreeLoad(xORB, sSharePath, sUserPath);
1015 sal_Int32 nIdx = 0;
1017 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "created tree manager" );
1019 OString const sInnerInfoText("- Loading module: ");
1021 START_MEMORYMEASURE_FOR( aInnerMemoryInfo, "*** Request Tree Test Details ***" );
1022 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, "initialisierungs-check" );
1024 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, "- before loading modules" );
1025 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "request subtrees" );
1027 for (char const * const * ppRequestModule = configtest::s_aTestModules; *ppRequestModule; ++ppRequestModule)
1029 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, sInnerInfoText.concat(*ppRequestModule) );
1030 aTreeLoad.requestSubtree( OUString::createFromAscii(*ppRequestModule));
1033 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, "- loaded all modules" );
1034 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "release subtrees" );
1036 for (char const * const * ppReleaseModule = configtest::s_aTestModules; *ppReleaseModule; ++ppReleaseModule)
1037 aTreeLoad.releaseSubtree( OUString::createFromAscii(*ppReleaseModule));
1039 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "ich habe fertig." );
1040 LOG_MEMORYMEASURE( "---------------- Request Memory Test ---------------------------", "Direct Cache Access memory traces.", aMemoryInfo );
1041 LOG_MEMORYMEASURE( "---------------- Request Memory Detail -------------------------", "Module request memory traces.", aInnerMemoryInfo );
1043 return 0;
1046 // -----------------------------------------------------------------------------
1047 // --------------------------------- Trust Test ---------------------------------
1048 // -----------------------------------------------------------------------------
1050 int trust( int argc, char * argv[] )
1052 Reference< XMultiServiceFactory > xORB = getORB();
1054 std::vector<char*> aMemHolder;
1055 aMemHolder.reserve(1024);
1057 START_MEMORYMEASURE_FOR( aMemoryInfo, "Allocator check" );
1059 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "initialisierungs-check" );
1061 sal_Int32 const total_alloc = 8 * 1024 * 1024;
1063 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "get 8 MB" );
1065 char* pChar = new char[total_alloc];
1067 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "free 8 MB" );
1069 delete [] pChar;
1071 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "deleted 8 MB" );
1073 sal_Int32 const chunk = 8 * 1024;
1074 sal_Int32 const alloc_count = total_alloc/chunk;
1076 sal_Int32 const msg_count = 16;
1077 sal_Int32 const loop_count = alloc_count/msg_count;
1078 sal_Int32 const loop_allocation = loop_count * chunk;
1080 OString const sPieces = OString::valueOf(alloc_count).concat(" pieces");
1081 OString const sInnerMessage = OString("Allocating ").concat(OString::valueOf(loop_count))
1082 .concat(" chunks [").concat(OString::valueOf(loop_allocation)).concat(" Bytes].");
1084 START_MEMORYMEASURE( aInnerMemoryInfo );
1085 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, "initialisierungs-check" );
1087 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, OString("get 8 MB as ").concat(sPieces) );
1089 for (sal_Int32 i=0;i<alloc_count/loop_count;i++)
1091 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, sInnerMessage );
1092 for (sal_Int32 j=0;j<loop_count;j++)
1095 pChar = new char[8 * 1024];
1096 aMemHolder.push_back(pChar);
1099 MAKE_MEMORY_SNAPSHOT( aInnerMemoryInfo, "last allocation done" );
1101 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "free pieces" );
1103 pChar = NULL;
1104 for (std::vector<char*>::iterator it = aMemHolder.begin();
1105 it != aMemHolder.end();
1106 it++)
1108 pChar = *it;
1109 delete []pChar;
1111 aMemHolder.clear();
1113 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, OString("get another 8 MB as ").concat(sPieces) );
1116 for (sal_Int32 j=0;j<alloc_count;j++)
1118 pChar = new char[8 * 1024];
1119 aMemHolder.push_back(pChar);
1122 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "free second set of pieces" );
1124 pChar = NULL;
1125 for (std::vector<char*>::iterator jt = aMemHolder.begin();
1126 jt != aMemHolder.end();
1127 jt++)
1129 pChar = *jt;
1130 delete []pChar;
1132 aMemHolder.clear();
1134 MAKE_MEMORY_SNAPSHOT( aMemoryInfo, "ich habe fertig." );
1135 LOG_MEMORYMEASURE( "---------------- Trust Memory Test ----------------------------", "Cross-checked memory traces.", aMemoryInfo );
1136 LOG_MEMORYMEASURE( "---------------- Small Allocation Loop ------------------------", "Allocation Loop Detail memory traces.", aInnerMemoryInfo );
1138 return 0;
1141 // -----------------------------------------------------------------------------
1142 static uno::Reference< lang::XMultiServiceFactory > g_xORB;
1143 static void createORB(char const* pRegistry)
1145 if (!g_xORB.is())
1148 rtl::OUString const sServiceRegistry = OUString::createFromAscii(pRegistry);
1150 g_xORB = createRegistryServiceFactory( sServiceRegistry, ::rtl::OUString() );
1153 catch (uno::Exception &e)
1155 cerr << "Exception creating the service factory: " << e.Message << "\n";
1157 else
1158 cerr << "Trying to recreate the service factory\n";
1160 if (!g_xORB.is())
1162 ::flush(cout);
1163 cerr << "Could not create the service factory '" << pRegistry << "' !\n";
1164 exit(-2);
1167 uno::Reference< lang::XMultiServiceFactory > getORB()
1169 if (!g_xORB.is())
1171 createORB( "applicat.rdb" );
1173 return g_xORB;
1175 // -----------------------------------------------------------------------------
1178 } // namespace configmgr
1179 // -----------------------------------------------------------------------------
1180 void usage()
1182 cerr << "Wrong or missing parameters.\nUsage:\n"
1183 "\tmemorytest [-r <registry.rdb>] (all | trust | request | api)+ [clear] [(+<module>|-<module>)+]\n";
1185 exit(-1);
1188 // -----------------------------------------------------------------------------
1189 // ------------------------------------ Main ------------------------------------
1190 // -----------------------------------------------------------------------------
1191 #if (defined UNX) || (defined OS2)
1192 int main( int argc, char * argv[] )
1193 #else
1194 int _cdecl main( int argc, char * argv[] )
1195 #endif
1197 if (argc > 1 && !::rtl_str_compare(argv[1], "-r" ) )
1199 if (!argv[2]) usage();
1201 configmgr::createORB(argv[2]);
1203 argv += 2;
1204 argc -= 2;
1206 configmgr::getORB(); // ensures there is one
1208 enum TestSelect { TEST_TRUST = 01, TEST_REQUEST = 02, TEST_API = 04, TEST_ALL = 07 };
1210 unsigned nSelect = 0;
1211 while (argc >= 1 && argv[1] != NULL)
1213 if ( !::rtl_str_compareIgnoreAsciiCase(argv[1], "trust" ) ) nSelect |= TEST_TRUST;
1214 else if ( !::rtl_str_compareIgnoreAsciiCase(argv[1], "request") ) nSelect |= TEST_REQUEST;
1215 else if ( !::rtl_str_compareIgnoreAsciiCase(argv[1], "api" ) ) nSelect |= TEST_API;
1216 else if ( !::rtl_str_compareIgnoreAsciiCase(argv[1], "all" ) ) nSelect |= TEST_ALL;
1217 else break;
1219 // here we found a known selector, so look on
1220 ++argv;
1221 --argc;
1224 if (nSelect == 0) usage();
1226 //--------------------
1227 #define DO_TEST( test, func ) \
1228 if (nSelect & TEST_##test) \
1230 char const * const test_name = #test; \
1231 if (int nRet = func(argc, argv)) \
1232 cerr << "Test: " << test_name << " returned with error code " << nRet << endl; \
1233 else \
1234 cerr << "Test: " << test_name << " finished without error !\n" ; \
1235 } else // to allow a semicolon
1236 //--------------------
1238 DO_TEST( TRUST , configmgr::trust );
1239 DO_TEST( REQUEST , configmgr::requestTest );
1240 DO_TEST( API , configmgr::main );
1242 return 0;