1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: memorytests.cxx,v $
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_
37 #include "treeload.hxx"
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>
51 #include <tools/postsys.h>
52 #undef VCL_NEED_BASETSD
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>
83 #include "createpropertyvalue.hxx"
85 #include "typeconverter.hxx"
87 #include "testmodules.hxx"
89 #include "valuenode.hxx"
96 namespace css
= com::sun::star
;
97 namespace uno
= css::uno
;
98 namespace lang
= css::lang
;
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
122 out
<< "[\\u" << hex
<< *p
<< "]";
126 void showSequence(const Sequence
<OUString
> &aSeq
)
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
);
193 aBuffer
[nLen
] = '\0';
203 if (nLen
< MAX_INPUT_LEN
)
214 aBuffer
[nLen
++] = ch
;
215 aBuffer
[nLen
] = '\0';
225 if (!cin
.getline(aBuffer
,sizeof aBuffer
))
228 return rtl::OString(aBuffer
);
231 // -----------------------------------------------------------------------------
232 rtl::OUString
enterValue(const char* _aStr
, const char* _aDefault
, bool _bIsAPassword
)
237 rtl::OUString sValue
;
238 sValue
<<= input(_aDefault
, _bIsAPassword
? '*' : 0);
241 //=============================================================================
243 uno::Reference
< lang::XMultiServiceFactory
> getORB();
244 // -----------------------------------------------------------------------------
247 Reference
< XChangesBatch
> xChangesBatch
= NULL
;
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
= "";
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
= "";
280 static bool m_bChange
= false;
281 // -----------------------------------------------------------------------------
282 static void loadDefaults()
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('/');
297 sExecutable
= sExecutable
.copy(0, nLastSep
+ 1);
299 sExecutable
+= ::rtl::OUString::createFromAscii("cfgapirc");
301 sExecutable
+= ::rtl::OUString::createFromAscii("cfgapi.ini");
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)
355 aCPArgs
[0] <<= configmgr::createPropertyValue(ASCII("user"), sUser
);
357 if (sPasswd
.getLength() > 0)
360 aCPArgs
[1] <<= configmgr::createPropertyValue(ASCII("password"), sPasswd
);
365 //=============================================================================
367 #if (defined UNX) || (defined OS2)
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
>
382 uno::Reference
< lang::XMultiServiceFactory
> _xServiceRegistry
,
383 rtl::OUString
const& _sServerType
,
384 rtl::OUString
const& _sSharePath
, rtl::OUString
const& _sUserPath
,
389 Sequence
< Any
> aCPArgs
;
391 OUString sServerType
= _sServerType
; // enterValue("servertype: ", s_pServerType, false);
395 _bLocal
= sServerType
.equalsIgnoreAsciiCase(ASCII("local")) || sServerType
.equalsIgnoreAsciiCase(ASCII("setup"));
398 rtl::OUString sServer
;
399 sServer
= enterValue("server : ", s_pServer
,false);
402 sUser
= enterValue("user : ", s_pUser
, false);
405 OUString sPasswd
= enterValue("password: ", s_pPassword
, true);
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
);
420 rtl::OUString sSharePath
, sUserPath
;
421 sSharePath
= _sSharePath
;// enterValue("share path: ", s_pSourcePath, false);
423 sUserPath
= _sUserPath
; // enterValue("user path : ", s_pUpdatePath, false);
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"),
442 if (!xCfgProvider
.is())
445 cerr
<< "Could not create the configuration provider !\n\n";
448 // -----------------------------------------------------------------------------
454 cerr
<< "Caught exception: " << e
.Message
<< endl
;
459 // -----------------------------------------------------------------------------
460 sal_Int32 m_nCount
= 0;
462 void test(uno::Reference
<lang::XMultiServiceFactory
> _xORB
, rtl::OUString
const& _sSharePath
,
463 rtl::OUString
const& _sUserPath
)
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
,
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()) )
513 if (!osl_getFileURLFromSystemPath(sMaybeURL
.pData
, &sURL
.pData
))
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()) )
527 if (!osl_getSystemPathFromFileURL(sMaybeURL
.pData
, &sSysPath
.pData
))
533 // -----------------------------------------------------------------------------
534 // ---------------------------------- M A I N ----------------------------------
535 // -----------------------------------------------------------------------------
537 int main( int argc
, char * argv
[] )
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
);
549 Reference
< XMultiServiceFactory
> xORB
= getORB();
551 rtl::OUString sSharePath
= makeSystemPath(enterValue("share path: ", s_pSourcePath
, false));
553 rtl::OUString sUserPath
= makeSystemPath(enterValue("user path : ", s_pUpdatePath
, false));
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
);
583 ///////////////////////////////////////////////////////////////////////////////////////////
584 void test(Reference
< XHierarchicalName
>& xAccessName
)
586 if (xAccessName
.is())
588 // cout << "Accessing Node: " << xAccessName->getHierarchicalName();
592 // cout << "BUG: XHierarchicalName not available";
596 void test(Reference
< XNamed
>& xAccess
)
600 // cout << "Node is named: " << xAccess->getName();
604 // cout << "BUG: XNamed not available";
609 ///////////////////////////////////////////////////////////////////////////////////////////
610 void fillAllNames(Reference
<XNameAccess
>& xAccess
, Sequence
<OUString
>& _aSeq
)
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];
623 // cout << "BUG: XNameAccess not available";
627 void write(Reference
< XChild
>& xChild
)
631 // cout << "\n[ P ] -\tParent";
635 // cout << "BUG: Parent not available (no XChild)";
639 ///////////////////////////////////////////////////////////////////////////////////////////
641 // -----------------------------------------------------------------------------
642 Reference
< XInterface
> readaccess(uno::Reference
< lang::XMultiServiceFactory
> &xMSF
,
643 uno::Reference
< uno::XInterface
> const& xIface
,
644 rtl::OString
const& buf
,
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())
657 OUString aInput
= OUString::createFromAscii(buf
);
661 ::rtl::OUString sTemp
= xExactName
->getExactName(aInput
);
662 if (sTemp
.getLength())
666 if (xAccess
.is() && xAccess
->hasByName(aInput
))
670 else if (xDeepAccess
.is() && xDeepAccess
->hasByHierarchicalName(aInput
))
674 else if ('0' <= buf
[0] && buf
[0] <= '9' && xAccess
.is())
677 Sequence
<OUString
> aNames
= xAccess
->getElementNames();
678 if (0 <= n
&& n
< aNames
.getLength())
682 if (aName
.getLength())
684 bool bNest
= aInput
.indexOf(sal_Unicode('/')) >= 0;
686 Any aElement
= bNest
?
688 xDeepAccess
->getByHierarchicalName(aName
) : Any()
691 xAccess
->getByName(aName
) : Any()
694 while (aElement
.getValueTypeClass() == TypeClass_ANY
)
699 sal_Bool bValue
= true;
700 sal_Bool bValueOk
= false;
702 switch (aElement
.getValueTypeClass() )
704 case TypeClass_INTERFACE
:
706 if (aElement
>>= xNext
)
708 outStream
<< "Group: " << aName
<< endl
;
712 outStream
<< "ERROR: can't get the interface" << endl
;
715 case TypeClass_BOOLEAN
:
717 sal_Bool
* pVal
= (sal_Bool
*)aElement
.getValue();
718 bValueOk
= (pVal
!= 0);
720 outStream
<< "VALUE '" << aName
<< "' is a BOOLEAN = ";
722 outStream
<< "NULL (error!!)";
724 outStream
<< "'TRUE'";
726 outStream
<< "'FALSE'";
730 // tryToChange(xAccess, aName, pVal);
733 case TypeClass_SHORT
:
736 outStream
<< "VALUE '" << aName
<< "' is a SHORT (16 bit) = ";
737 if (bValueOk
= (aElement
>>= aValue
))
740 // tryToChange(xAccess, aName, aValue);
744 outStream
<< "ERROR RETRIEVING VALUE";
754 outStream
<< "VALUE '" << aName
<< "' is a INT (32 bit) = ";
755 if (bValueOk
= (aElement
>>= aValue
))
758 // tryToChange(xAccess, aName, aValue);
762 outStream
<< "ERROR RETRIEVING VALUE";
767 case TypeClass_HYPER
:
770 outStream
<< "VALUE '" << aName
<< "' is a LONG (64 bit) = ";
771 if (bValueOk
= (aElement
>>= aValue
))
773 outStream
<< double(aValue
);
774 // tryToChange(xAccess, aName, aValue);
778 outStream
<< "ERROR RETRIEVING VALUE";
783 case TypeClass_DOUBLE
:
786 outStream
<< "VALUE '" << aName
<< "' is a DOUBLE = ";
787 if (bValueOk
= (aElement
>>= aValue
))
793 outStream
<< "ERROR RETRIEVING VALUE";
798 case TypeClass_STRING
:
801 outStream
<< "VALUE '" << aName
<< "' is a STRING = ";
802 if (bValueOk
= (aElement
>>= aValue
))
804 outStream
<< "\"" << aValue
<< "\"";
805 // tryToChange(xAccess, aName, aValue);
809 outStream
<< "ERROR RETRIEVING VALUE";
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);
827 outStream
<< "ELEMENT '" << aName
<< "' is NULL and VOID " << endl
;
831 outStream
<< "Error: ELEMENT '" << aName
<< "' is of unknown or unrecognized type" << endl
;
838 outStream
<< "Error: No element \"" << aInput
<< "\" found." <<endl
;
844 outStream
<< "An Exception occurred: " << e
.Message
<< endl
;
848 outStream
<< "An UNKNOWN Exception occurred !" << endl
;
857 // -----------------------------------------------------------------------------
858 void test_read_access( uno::Reference
< lang::XMultiServiceFactory
> &xMSF
,
859 uno::Reference
< uno::XInterface
>& xIface
,
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);
875 fillAllNames(xAccess
, aAllNames
);
878 for (sal_Int32 i
=0;i
<aAllNames
.getLength();i
++)
881 aValue
<<= aAllNames
[i
];
882 uno::Reference
<uno::XInterface
> xFace
= readaccess(xMSF
, xIface
, aValue
, out
);
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
,
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(""));
918 OUString sLocale
= enterValue("locale : ", s_pLocale
, false);
920 aArgs
.realloc(aArgs
.getLength() + 1);
921 aArgs
[aArgs
.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("locale"), sLocale
);
925 sal_Bool bLazyWrite
= true;
926 aArgs
.realloc(aArgs
.getLength() + 1);
927 aArgs
[aArgs
.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("lazywrite"), bLazyWrite
);
929 sal_Bool bNoCache
= true;
930 aArgs
.realloc(aArgs
.getLength() + 1);
931 aArgs
[aArgs
.getLength() - 1] <<= configmgr::createPropertyValue(ASCII("nocache"), bNoCache
);
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"),
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();
964 OString aFilename = "c:\\temp\\fileout_";
966 aFilename += OString::valueOf(_nCount);
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
[] )
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
);
1001 Reference
< XMultiServiceFactory
> xORB
= getORB();
1003 rtl::OUString sSharePath
= makeFileURL(enterValue("share path: ", s_pSourcePath
, false));
1005 rtl::OUString sUserPath
= makeFileURL(enterValue("user path : ", s_pUpdatePath
, false));
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
);
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
);
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" );
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" );
1104 for (std::vector
<char*>::iterator it
= aMemHolder
.begin();
1105 it
!= aMemHolder
.end();
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" );
1125 for (std::vector
<char*>::iterator jt
= aMemHolder
.begin();
1126 jt
!= aMemHolder
.end();
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
);
1141 // -----------------------------------------------------------------------------
1142 static uno::Reference
< lang::XMultiServiceFactory
> g_xORB
;
1143 static void createORB(char const* pRegistry
)
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";
1158 cerr
<< "Trying to recreate the service factory\n";
1163 cerr
<< "Could not create the service factory '" << pRegistry
<< "' !\n";
1167 uno::Reference
< lang::XMultiServiceFactory
> getORB()
1171 createORB( "applicat.rdb" );
1175 // -----------------------------------------------------------------------------
1178 } // namespace configmgr
1179 // -----------------------------------------------------------------------------
1182 cerr
<< "Wrong or missing parameters.\nUsage:\n"
1183 "\tmemorytest [-r <registry.rdb>] (all | trust | request | api)+ [clear] [(+<module>|-<module>)+]\n";
1188 // -----------------------------------------------------------------------------
1189 // ------------------------------------ Main ------------------------------------
1190 // -----------------------------------------------------------------------------
1191 #if (defined UNX) || (defined OS2)
1192 int main( int argc
, char * argv
[] )
1194 int _cdecl
main( int argc
, char * argv
[] )
1197 if (argc
> 1 && !::rtl_str_compare(argv
[1], "-r" ) )
1199 if (!argv
[2]) usage();
1201 configmgr::createORB(argv
[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
;
1219 // here we found a known selector, so look on
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; \
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
);