Hello Andreas,
a)I have separated the ConfigItemTest.cxx, now each config item will have a single test code like AccessibilityOptTest.cxx,HistoryOptTest.cxx. b)In the HistoryOptTest.cxx, when clearing the list in XML directly I referenced the comphelper/../configurationhelper.cxx.
c)Perhaps I have to test more deep.
Need your help for reviewing the attached files.

Regards,
Yan Wu
#*************************************************************************
#
#   OpenOffice.org - a multi-platform office productivity suite
#
#   $RCSfile: makefile.mk,v $
#
#   $Revision: 1.1.2.2 $
#
#   last change: $Author: as $ $Date: 2007/05/29 09:19:15 $
#
#   The Contents of this file are made available subject to
#   the terms of GNU Lesser General Public License Version 2.1.
#
#
#     GNU Lesser General Public License Version 2.1
#     =============================================
#     Copyright 2005 by Sun Microsystems, Inc.
#     901 San Antonio Road, Palo Alto, CA 94303, USA
#
#     This library is free software; you can redistribute it and/or
#     modify it under the terms of the GNU Lesser General Public
#     License version 2.1, as published by the Free Software Foundation.
#
#     This library is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#     Lesser General Public License for more details.
#
#     You should have received a copy of the GNU Lesser General Public
#     License along with this library; if not, write to the Free Software
#     Foundation, Inc., 59 Temple Place, Suite 330, Boston,
#     MA  02111-1307  USA
#
#*************************************************************************
PRJ=..$/..$/..$/..

PRJNAME=                        svtools
TARGET=                         ConfigItemTest
USE_DEFFILE=            TRUE
ENABLE_EXCEPTIONS=      TRUE
NO_BSYMBOLIC=           TRUE

# --- Settings -----------------------------------------------------

.INCLUDE :              settings.mk

# --- Generate -----------------------------------------------------


# --- light services library 
----------------------------------------------------

SHL1TARGET=             svt_$(TARGET)

SHL1OBJS=       \
                                $(SLO)$/ConfigItemTest.obj                      
\
                                $(SLO)$/AccessibilityOptTest.obj        \
                                $(SLO)$/HistoryOptTest.obj                      
\

SHL1STDLIBS=    \
                                $(SVTOOLLIB)                                    
        \
                                $(SVLLIB)                                       
            \
                                $(UNOTOOLSLIB)                                  
        \
                                $(COMPHELPERLIB)                                
        \
                                $(CPPUHELPERLIB)                                
        \
                                $(CPPULIB)                                      
                \
                                $(SALLIB)

SHL1DEF=        $(MISC)$/$(SHL1TARGET).def
#SHL1DEPN=       $(SHL1IMPLIBN) $(SHL1TARGETN)

DEF1NAME=       $(SHL1TARGET)

SHL1VERSIONMAP= exports.map

# --- Targets ------------------------------------------------------

.INCLUDE :                      target.mk

#ifndef  _SVT_OPTTEST_HXX_
#define  _SVT_OPTTEST_HXX_

#ifndef  INCLUDED_SVTOOLS_ACCESSIBILITYOPTIONS_HXX
#include <accessibilityoptions.hxx>
#endif

#ifndef  INCLUDED_SVTOOLS_HISTORYOPTIONS_HXX
#include <historyoptions.hxx>
#endif

class AccessibilityOptTest
{
public:
        AccessibilityOptTest();
        ~AccessibilityOptTest();

        void impl_checkAccessibilityOptions();

private:
        SvtAccessibilityOptions* pAccessibilityOpt;
};

class HistoryOptTest
{
public:
        HistoryOptTest();
        ~HistoryOptTest();

        void impl_checkPicklist();
        void impl_checkURLHistory();
        void impl_checkHelpBookmarks();

private:
        sal_Bool impl_isListEmpty(rtl::OUString sList);
        void     impl_clearList(rtl::OUString sList);

private:
        SvtHistoryOptions* pHistoryOpt;
};

#endif // #ifndef  _SVT_OPTTEST_HXX_
#ifndef  _SVT_OPTTEST_HXX_
#include <opttest.hxx>
#endif

#ifndef  INCLUDED_SVTOOLS_ACCESSIBILITYOPTIONS_HXX
#include <accessibilityoptions.hxx>
#endif

AccessibilityOptTest::AccessibilityOptTest()
{
        pAccessibilityOpt   = new SvtAccessibilityOptions;
}

AccessibilityOptTest::~AccessibilityOptTest()
{
        if (pAccessibilityOpt)
        {
                delete pAccessibilityOpt;
                pAccessibilityOpt = NULL;
        }
}

//=============================================================================
void AccessibilityOptTest::impl_checkAccessibilityOptions()
{
        
pAccessibilityOpt->SetAutoDetectSystemHC(pAccessibilityOpt->GetAutoDetectSystemHC());
        
pAccessibilityOpt->SetIsForPagePreviews(pAccessibilityOpt->GetIsForPagePreviews());
        
pAccessibilityOpt->SetIsHelpTipsDisappear(pAccessibilityOpt->GetIsHelpTipsDisappear());
        
pAccessibilityOpt->SetIsAllowAnimatedGraphics(pAccessibilityOpt->GetIsAllowAnimatedGraphics());
        
pAccessibilityOpt->SetIsAllowAnimatedText(pAccessibilityOpt->GetIsAllowAnimatedText());
        
pAccessibilityOpt->SetIsAutomaticFontColor(pAccessibilityOpt->GetIsAutomaticFontColor());
        
pAccessibilityOpt->SetIsSystemFont(pAccessibilityOpt->GetIsSystemFont());
        
pAccessibilityOpt->SetHelpTipSeconds(pAccessibilityOpt->GetHelpTipSeconds());
        pAccessibilityOpt->SetHelpTipSeconds(5);//only for test
        
pAccessibilityOpt->SetSelectionInReadonly(pAccessibilityOpt->IsSelectionInReadonly());
}
/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: ConfigItemTest.cxx,v $
 *
 *  $Revision: 1.1.2.1 $
 *
 *  last change: $Author: as $ $Date: 2007/05/14 11:49:36 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <com/sun/star/task/XJob.hpp>
#include <com/sun/star/beans/NamedValue.hpp>

#include <sal/config.h>
#include <rtl/ustring.hxx>
#include <cppuhelper/implbase2.hxx>
#include <cppuhelper/implementationentry.hxx>
#include <opttest.hxx>

//=============================================================================
namespace css = ::com::sun::star;

namespace svtools{

//=============================================================================
class ConfigItemTest : public ::cppu::WeakImplHelper2< css::task::XJob         ,
                                                        css::lang::XServiceInfo 
>
{
    //-------------------------------------------------------------------------
    // interface
    public:
        explicit ConfigItemTest(const css::uno::Reference< 
css::uno::XComponentContext >& xContext);
    
        // css::task::XJob
        virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< 
css::beans::NamedValue >& lArguments)
            throw (css::uno::RuntimeException         ,
                   css::lang::IllegalArgumentException,
                   css::uno::Exception                );

        // css::lang::XServiceInfo
        virtual ::rtl::OUString SAL_CALL getImplementationName()
            throw (css::uno::RuntimeException);
    
        virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString& 
sServiceName)
            throw (css::uno::RuntimeException);
    
        virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL 
getSupportedServiceNames()
            throw (css::uno::RuntimeException);
    
    //-------------------------------------------------------------------------
    // internal
    private:
        ConfigItemTest(ConfigItemTest &); // not defined
        virtual ~ConfigItemTest() {}
        void operator=(ConfigItemTest &); // not defined
    
    //-------------------------------------------------------------------------
    // helper for registration !
    public:
        static ::rtl::OUString SAL_CALL st_getImplementationName();
        static css::uno::Sequence< ::rtl::OUString > SAL_CALL 
st_getSupportedServiceNames();
        static css::uno::Reference< css::uno::XInterface > SAL_CALL 
st_create(const css::uno::Reference< css::uno::XComponentContext >& XContext);
        
    //-------------------------------------------------------------------------
    // member
    private:
        css::uno::Reference< css::uno::XComponentContext >  m_xContext;
};

//=============================================================================
ConfigItemTest::ConfigItemTest(const css::uno::Reference< 
css::uno::XComponentContext >& xContext)
    : m_xContext(xContext)
{}

//=============================================================================
// css::task::XJob
css::uno::Any SAL_CALL ConfigItemTest::execute(const css::uno::Sequence< 
css::beans::NamedValue >& lArguments)
    throw (css::uno::RuntimeException         ,
           css::lang::IllegalArgumentException,
           css::uno::Exception                )
{
    ::rtl::OUString sTest;
    ::sal_Int32     i    = 0;
    ::sal_Int32     c    = lArguments.getLength();
    for (i=0; i<c; ++i)
    {
        const css::beans::NamedValue& rArg = lArguments[0];
        if (rArg.Name.equalsAscii("Test"))
            rArg.Value >>= sTest;
    }

        if (sTest.equalsAscii("checkPicklist"))
        {
                HistoryOptTest* pOptTest = new HistoryOptTest;
                pOptTest->impl_checkPicklist();
        }
        else if (sTest.equalsAscii("checkURLHistory"))
        {
                HistoryOptTest* pOptTest = new HistoryOptTest;
                pOptTest->impl_checkURLHistory();
        }
        else if (sTest.equalsAscii("checkHelpBookmarks"))
        {
                HistoryOptTest* pOptTest = new HistoryOptTest;
                pOptTest->impl_checkHelpBookmarks();
        }
        else if (sTest.equalsAscii("checkAccessibilityOptions"))
        {
                AccessibilityOptTest* pOptTest = new AccessibilityOptTest;
                pOptTest->impl_checkAccessibilityOptions();
        }

    return css::uno::Any();
}

//=============================================================================
// com::sun::star::uno::XServiceInfo
::rtl::OUString SAL_CALL ConfigItemTest::getImplementationName()
    throw (css::uno::RuntimeException)
{
    return ConfigItemTest::st_getImplementationName();
}

//=============================================================================
// com::sun::star::uno::XServiceInfo
::sal_Bool SAL_CALL ConfigItemTest::supportsService(const ::rtl::OUString& 
sServiceName)
    throw (css::uno::RuntimeException)
{
    css::uno::Sequence< ::rtl::OUString > lServiceNames = 
ConfigItemTest::st_getSupportedServiceNames();
    for (::sal_Int32 i = 0; i < lServiceNames.getLength(); ++i)
    {
        if (lServiceNames[i].equals(sServiceName))
            return sal_True;
    }
    return sal_False;
}

//=============================================================================
// com::sun::star::uno::XServiceInfo
css::uno::Sequence< ::rtl::OUString > SAL_CALL 
ConfigItemTest::getSupportedServiceNames()
    throw (css::uno::RuntimeException)
{
    return ConfigItemTest::st_getSupportedServiceNames();
}

//=============================================================================
::rtl::OUString SAL_CALL ConfigItemTest::st_getImplementationName()
{
    return 
::rtl::OUString::createFromAscii("com.sun.star.comp.svtools.ConfigItemTest");
}

//=============================================================================
css::uno::Sequence< ::rtl::OUString > SAL_CALL 
ConfigItemTest::st_getSupportedServiceNames()
{
    css::uno::Sequence< ::rtl::OUString > lServices(1);
    lServices[0] = 
::rtl::OUString::createFromAscii("com.sun.star.test.ConfigItems");
    return lServices;
}

//=============================================================================
css::uno::Reference< css::uno::XInterface > SAL_CALL 
ConfigItemTest::st_create(const css::uno::Reference< 
css::uno::XComponentContext >& xContext)
{
    ConfigItemTest*                            pObject = new 
ConfigItemTest(xContext);
    css::uno::Reference< css::uno::XInterface > xObject (static_cast< 
::cppu::OWeakObject* >(pObject));
    return xObject;
}

} // namespace svtools

//=============================================================================
static ::cppu::ImplementationEntry const lRegEntries[] =
{
    {
        &::svtools::ConfigItemTest::st_create,
        &::svtools::ConfigItemTest::st_getImplementationName,
        &::svtools::ConfigItemTest::st_getSupportedServiceNames,
        &::cppu::createSingleComponentFactory, 0, 0
    },

    { 0, 0, 0, 0, 0, 0 }
};

//=============================================================================
extern "C" void SAL_CALL component_getImplementationEnvironment(const char**    
        pEnvTypeName,
                                                                      
uno_Environment**             )
{
    *pEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
}

//=============================================================================
extern "C" void * SAL_CALL component_getFactory(const char* sImplName      ,
                                                      void* pServiceManager,
                                                      void* pRegistryKey   )
{
    return ::cppu::component_getFactoryHelper(sImplName, pServiceManager, 
pRegistryKey, lRegEntries);
}

//=============================================================================
extern "C" sal_Bool SAL_CALL component_writeInfo(void* pServiceManager,
                                                 void* pRegistryKey   )
{
    return ::cppu::component_writeInfoHelper(pServiceManager, pRegistryKey, 
lRegEntries);
}
#ifndef  _SVT_OPTTEST_HXX_
#include <opttest.hxx>
#endif

#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_
#include <com/sun/star/uno/Sequence.hxx>
#endif

#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_
#include <com/sun/star/beans/PropertyValue.hpp>
#endif

#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_
#include <com/sun/star/beans/XPropertySet.hpp>
#endif

#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_
#include <com/sun/star/container/XNameAccess.hpp>
#endif

#ifndef _COM_SUN_STAR_CONTAINER_XNAMECONTAINER_HPP_ 
#include <com/sun/star/container/XNameContainer.hpp> 
#endif

#ifndef  INCLUDED_SVTOOLS_HISTORYOPTIONS_HXX
#include <historyoptions.hxx>
#endif

#ifndef _COMPHELPER_CONFIGURATIONHELPER_HXX_
#include <comphelper/configurationhelper.hxx>
#endif

#ifndef _UNOTOOLS_PROCESSFACTORY_HXX_
#include <unotools/processfactory.hxx>
#endif

#ifndef _SVT_LOGHELPER_HXX
#include <loghelper.hxx>
#endif

namespace css = ::com::sun::star;

HistoryOptTest::HistoryOptTest()
{
        pHistoryOpt = new SvtHistoryOptions;
}

HistoryOptTest::~HistoryOptTest()
{
        if (pHistoryOpt)
        {
                delete pHistoryOpt;
                pHistoryOpt = NULL;
        }
}
//=============================================================================
// use configuration API (not ConfigItem!) to verify the results within XML ! 
sal_Bool HistoryOptTest::impl_isListEmpty(rtl::OUString sList)
{
        css::uno::Reference< css::container::XNameAccess > xCfg;
        css::uno::Reference< css::container::XNameAccess > xItemList;
        css::uno::Reference< css::container::XNameAccess > xOrderList;
        sal_Bool bRet = sal_True;

        rtl::OUString sRootNode = 
rtl::OUString::createFromAscii("org.openoffice.Office.Histories/");
        sRootNode += sList;
        xCfg = css::uno::Reference< css::container::XNameAccess >(
                ::comphelper::ConfigurationHelper::openConfig(
                utl::getProcessServiceFactory(),
                sRootNode,
                ::comphelper::ConfigurationHelper::E_STANDARD),
                css::uno::UNO_QUERY);

    if (xCfg.is())
        {
                xCfg->getByName(rtl::OUString::createFromAscii("ItemList"))  
>>= xItemList;
                xCfg->getByName(rtl::OUString::createFromAscii("OrderList")) 
>>= xOrderList;

                css::uno::Sequence< rtl::OUString > sItemList  = 
xItemList->getElementNames();
                css::uno::Sequence< rtl::OUString > sOrderList = 
xOrderList->getElementNames();
                if (sItemList.getLength()!=0 || sOrderList.getLength()!=0)
                        bRet = sal_False;
        }

        return bRet;
}

//=============================================================================
// clear the list in XML directly
void HistoryOptTest::impl_clearList(rtl::OUString sList)
{
        css::uno::Reference< css::container::XNameAccess >    xCfg;
        css::uno::Reference< css::container::XNameContainer > xItemOrder;
        css::uno::Reference< css::beans::XPropertySet >       xFirstItem;
        css::uno::Sequence< rtl::OUString >                                     
  sFileList;

        rtl::OUString sRootNode = 
rtl::OUString::createFromAscii("org.openoffice.Office.Histories/");
        sRootNode += sList;
        xCfg = css::uno::Reference< css::container::XNameAccess >(
                ::comphelper::ConfigurationHelper::openConfig(
                utl::getProcessServiceFactory(),
                sRootNode,
                ::comphelper::ConfigurationHelper::E_STANDARD),
                css::uno::UNO_QUERY);

        try
        {
                xCfg->getByName(rtl::OUString::createFromAscii("ItemList"))  
>>= xItemOrder  ;                          
                sFileList = xItemOrder->getElementNames();  
                for(sal_Int32 i=0; i<sFileList.getLength(); ++i)
                        xItemOrder->removeByName(sFileList[i]);

                xCfg->getByName(rtl::OUString::createFromAscii("OrderList")) 
>>= xItemOrder ;
                sFileList = xItemOrder->getElementNames();  
                for(sal_Int32 j=0; j<sFileList.getLength(); ++j)
                        xItemOrder->removeByName(sFileList[j]);

                xFirstItem = css::uno::Reference< css::beans::XPropertySet 
>(xCfg, css::uno::UNO_QUERY);
                xFirstItem->setPropertyValue( 
rtl::OUString::createFromAscii("FirstItem"), css::uno::makeAny((sal_Int32)0) );

                ::comphelper::ConfigurationHelper::flush(xCfg);
        }
        catch(const css::uno::Exception& ex)
        {
                LogHelper::logIt(ex);
        }
}

//=============================================================================
void HistoryOptTest::impl_checkPicklist()
{
        pHistoryOpt->SetSize( ePICKLIST, pHistoryOpt->GetSize(ePICKLIST) );

        pHistoryOpt->AppendItem( ePICKLIST  , 
                rtl::OUString::createFromAscii("file:///c/test1"),
                rtl::OUString::createFromAscii("writer8"),
                rtl::OUString::createFromAscii("test1"),
                rtl::OUString::createFromAscii("")               ); 

        pHistoryOpt->Clear( ePICKLIST );//if don't execute Clear(),it will 
throw error
        if ( !impl_isListEmpty(rtl::OUString::createFromAscii("PickList")) )
                throw css::uno::RuntimeException(
                ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
                "null com.sun.star.configuration."
                "List is not empty!")),
                0);
}

//=============================================================================
void HistoryOptTest::impl_checkURLHistory()
{
        pHistoryOpt->SetSize( eHISTORY, pHistoryOpt->GetSize(eHISTORY) );
        
        pHistoryOpt->AppendItem( eHISTORY  , 
                rtl::OUString::createFromAscii("file:///c/test1"),
                rtl::OUString::createFromAscii("writer8"),
                rtl::OUString::createFromAscii("test1"),
                rtl::OUString::createFromAscii("")               ); 

        impl_clearList(rtl::OUString::createFromAscii("URLHistory"));//if don't 
execute impl_clearList(),it will throw error
        css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > 
aHistoryList = pHistoryOpt->GetList( eHISTORY );
        if(aHistoryList.getLength()!=0)
                throw css::uno::RuntimeException(
                ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
                "null com.sun.star.configuration."
                "List is not empty!")),
                0);
}

//=============================================================================
void HistoryOptTest::impl_checkHelpBookmarks()
{
        pHistoryOpt->SetSize( eHELPBOOKMARKS, 
pHistoryOpt->GetSize(eHELPBOOKMARKS) );

        pHistoryOpt->AppendItem( eHELPBOOKMARKS  , 
                rtl::OUString::createFromAscii("file:///c/test2"),
                rtl::OUString::createFromAscii(""),
                rtl::OUString::createFromAscii("test2"),
                rtl::OUString::createFromAscii("")               ); 
        
        css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > 
aHistoryList = pHistoryOpt->GetList( eHELPBOOKMARKS );
        if ( aHistoryList.getLength()!=0 )
                throw css::uno::RuntimeException(
                ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
                "null com.sun.star.configuration."
                "List is not empty!")),
                0);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to