diff options
author | Mathias Bauer <mba@openoffice.org> | 2009-10-08 12:20:11 +0200 |
---|---|---|
committer | Mathias Bauer <mba@openoffice.org> | 2009-10-08 12:20:11 +0200 |
commit | e6b4345c7f4026cb9b3e8dee6ecc84b3531e1950 (patch) | |
tree | 35a66a82b052424c4664f1c4bb77b6ef71f654ba /svl/qa | |
parent | b429c6949ce70e47538f90f5c67979b9d0ec0333 (diff) |
#i103496#: split svtools in two libs, depending on whether the code needs vcl or not
Diffstat (limited to 'svl/qa')
24 files changed, 4659 insertions, 0 deletions
diff --git a/svl/qa/complex/ConfigItems/CheckConfigItems.java b/svl/qa/complex/ConfigItems/CheckConfigItems.java new file mode 100644 index 000000000000..97cc21fdec9f --- /dev/null +++ b/svl/qa/complex/ConfigItems/CheckConfigItems.java @@ -0,0 +1,186 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: CheckConfigItems.java,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:22 $ + * + * 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 + * + ************************************************************************/ + +package complex.ConfigItems; + +import com.sun.star.beans.*; +import com.sun.star.lang.*; +import com.sun.star.uno.*; +import com.sun.star.task.*; + +import complexlib.*; + +import java.lang.*; +import java.util.*; + +//----------------------------------------------- +/** @short todo document me + */ +public class CheckConfigItems extends ComplexTestCase +{ + //------------------------------------------- + // some const + + //------------------------------------------- + // member + + /** points to the global uno service manager. */ + private XMultiServiceFactory m_xSmgr = null; + + /** implements real config item tests in C++. */ + private XJob m_xTest = null; + + //------------------------------------------- + // test environment + + //------------------------------------------- + /** @short A function to tell the framework, + which test functions are available. + + @return All test methods. + @todo Think about selection of tests from outside ... + */ + public String[] getTestMethodNames() + { + return new String[] + { + "checkPicklist", + "checkURLHistory", + "checkHelpBookmarks", + "checkPrintOptions", + "checkAccessibilityOptions", + "checkUserOptions" + }; + } + + //------------------------------------------- + /** @short Create the environment for following tests. + + @descr Use either a component loader from desktop or + from frame + */ + public void before() + throws java.lang.Exception + { + // get uno service manager from global test environment + m_xSmgr = (XMultiServiceFactory)param.getMSF(); + + // TODO register helper service + + // create module manager + m_xTest = (XJob)UnoRuntime.queryInterface( + XJob.class, + m_xSmgr.createInstance("com.sun.star.comp.svtools.ConfigItemTest")); + } + + //------------------------------------------- + /** @short close the environment. + */ + public void after() + throws java.lang.Exception + { + // TODO deregister helper service + + m_xTest = null; + m_xSmgr = null; + } + + //------------------------------------------- + /** @todo document me + */ + public void checkPicklist() + throws java.lang.Exception + { + impl_triggerTest("checkPicklist"); + } + + //------------------------------------------- + /** @todo document me + */ + public void checkURLHistory() + throws java.lang.Exception + { + impl_triggerTest("checkURLHistory"); + } + + //------------------------------------------- + /** @todo document me + */ + public void checkHelpBookmarks() + throws java.lang.Exception + { + impl_triggerTest("checkHelpBookmarks"); + } + + //------------------------------------------- + /** @todo document me + */ + public void checkPrintOptions() + throws java.lang.Exception + { + impl_triggerTest("checkPrintOptions"); + } + + //------------------------------------------- + /** @todo document me + */ + public void checkAccessibilityOptions() + throws java.lang.Exception + { + impl_triggerTest("checkAccessibilityOptions"); + } + + //------------------------------------------- + /** @todo document me + */ + public void checkUserOptions() + throws java.lang.Exception + { + impl_triggerTest("checkUserOptions"); + } + + //------------------------------------------- + /** @todo document me + */ + private void impl_triggerTest(String sTest) + throws java.lang.Exception + { + NamedValue[] lArgs = new NamedValue[1]; + lArgs[0] = new NamedValue(); + lArgs[0].Name = "Test"; + lArgs[0].Value = sTest; + m_xTest.execute(lArgs); + } +} diff --git a/svl/qa/complex/ConfigItems/helper/AccessibilityOptTest.cxx b/svl/qa/complex/ConfigItems/helper/AccessibilityOptTest.cxx new file mode 100644 index 000000000000..d853bf926467 --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/AccessibilityOptTest.cxx @@ -0,0 +1,400 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: AccessibilityOptTest.cxx,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:23 $ + * + * 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 "AccessibilityOptTest.hxx" +#include "configitems/accessibilityoptions_const.hxx" + +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> + +#include <comphelper/configurationhelper.hxx> +#include <unotools/processfactory.hxx> + +namespace css = ::com::sun::star; + +AccessibilityOptTest::AccessibilityOptTest() +{ + m_xCfg = css::uno::Reference< css::container::XNameAccess >( + ::comphelper::ConfigurationHelper::openConfig( + ::utl::getProcessServiceFactory(), + s_sAccessibility, + ::comphelper::ConfigurationHelper::E_STANDARD), + css::uno::UNO_QUERY); +} + +AccessibilityOptTest::~AccessibilityOptTest() +{ + if (m_xCfg.is()) + m_xCfg.clear(); +} + +//============================================================================= +//test GetAutoDetectSystemHC() +void AccessibilityOptTest::impl_checkGetAutoDetectSystemHC() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bAutoDetectSystemHC; + sal_Bool bAutoDetectSystemHC_; + + bAutoDetectSystemHC = aAccessibilityOpt.GetAutoDetectSystemHC(); + xSet->setPropertyValue( s_sAutoDetectSystemHC, css::uno::makeAny(bAutoDetectSystemHC ? sal_False:sal_True) ); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + bAutoDetectSystemHC_ = aAccessibilityOpt.GetAutoDetectSystemHC(); + + if ( bAutoDetectSystemHC_ == bAutoDetectSystemHC )//old config item will not throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetAutoDetectSystemHC() error!")), 0); +} + +//============================================================================= +//test GetIsForPagePreviews() +void AccessibilityOptTest::impl_checkGetIsForPagePreviews() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsForPagePreviews ; + sal_Bool bIsForPagePreviews_; + + bIsForPagePreviews = aAccessibilityOpt.GetIsForPagePreviews(); + xSet->setPropertyValue( s_sIsForPagePreviews, css::uno::makeAny(bIsForPagePreviews ? sal_False:sal_True) ); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + bIsForPagePreviews_ = aAccessibilityOpt.GetIsForPagePreviews(); + + if ( bIsForPagePreviews_ == bIsForPagePreviews )//old config item will not throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetIsForPagePreviews() error!")), 0); +} + +//============================================================================= +//test impl_checkGetIsHelpTipsDisappear() +void AccessibilityOptTest::impl_checkGetIsHelpTipsDisappear() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsHelpTipsDisappear ; + sal_Bool bIsHelpTipsDisappear_; + + bIsHelpTipsDisappear = aAccessibilityOpt.GetIsHelpTipsDisappear(); + xSet->setPropertyValue( s_sIsHelpTipsDisappear, css::uno::makeAny(bIsHelpTipsDisappear ? sal_False:sal_True) ); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + bIsHelpTipsDisappear_ = aAccessibilityOpt.GetIsHelpTipsDisappear(); + + if ( bIsHelpTipsDisappear_ == bIsHelpTipsDisappear )//old config item will not throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetIsHelpTipsDisappear() error!")), 0); +} + +//============================================================================= +//test impl_checkGetIsAllowAnimatedGraphics() +void AccessibilityOptTest::impl_checkGetIsAllowAnimatedGraphics() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsAllowAnimatedGraphics ; + sal_Bool bIsAllowAnimatedGraphics_; + + bIsAllowAnimatedGraphics = aAccessibilityOpt.GetIsAllowAnimatedGraphics(); + xSet->setPropertyValue( s_sIsAllowAnimatedGraphics, css::uno::makeAny(bIsAllowAnimatedGraphics ? sal_False:sal_True) ); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + bIsAllowAnimatedGraphics_ = aAccessibilityOpt.GetIsAllowAnimatedGraphics(); + + if ( bIsAllowAnimatedGraphics_ == bIsAllowAnimatedGraphics )//old config item will not throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetIsAllowAnimatedGraphics() error!")), 0); +} + +//============================================================================= +//test impl_checkGetIsAllowAnimatedText() +void AccessibilityOptTest::impl_checkGetIsAllowAnimatedText() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsAllowAnimatedText ; + sal_Bool bIsAllowAnimatedText_; + + bIsAllowAnimatedText = aAccessibilityOpt.GetIsAllowAnimatedText(); + xSet->setPropertyValue( s_sIsAllowAnimatedText, css::uno::makeAny(bIsAllowAnimatedText ? sal_False:sal_True) ); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + bIsAllowAnimatedText_ = aAccessibilityOpt.GetIsAllowAnimatedText(); + + if ( bIsAllowAnimatedText_ == bIsAllowAnimatedText )//old config item will not throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetIsAllowAnimatedText() error!")), 0); +} + +//============================================================================= +//test impl_checkGetIsAutomaticFontColor() +void AccessibilityOptTest::impl_checkGetIsAutomaticFontColor() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsAutomaticFontColor ; + sal_Bool bIsAutomaticFontColor_; + + bIsAutomaticFontColor = aAccessibilityOpt.GetIsAutomaticFontColor(); + xSet->setPropertyValue( s_sIsAutomaticFontColor, css::uno::makeAny(bIsAutomaticFontColor ? sal_False:sal_True) ); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + bIsAutomaticFontColor_ = aAccessibilityOpt.GetIsAutomaticFontColor(); + + if ( bIsAutomaticFontColor_ == bIsAutomaticFontColor )//old config item will not throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetIsAutomaticFontColor() error!")), 0); +} + +//============================================================================= +//test impl_checkGetIsSystemFont() +void AccessibilityOptTest::impl_checkGetIsSystemFont() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsSystemFont ; + sal_Bool bIsSystemFont_; + + bIsSystemFont = aAccessibilityOpt.GetIsSystemFont(); + xSet->setPropertyValue( s_sIsSystemFont, css::uno::makeAny(bIsSystemFont ? sal_False:sal_True) ); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + bIsSystemFont_ = aAccessibilityOpt.GetIsSystemFont(); + + if ( bIsSystemFont_ == bIsSystemFont )//old config item will not throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetIsSystemFont() error!")), 0); +} + +//============================================================================= +//test impl_checkGetHelpTipSeconds() +void AccessibilityOptTest::impl_checkGetHelpTipSeconds() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Int16 nHelpTipSeconds ; + sal_Int16 nHelpTipSeconds_; + + nHelpTipSeconds = aAccessibilityOpt.GetHelpTipSeconds(); + xSet->setPropertyValue( s_sHelpTipSeconds, css::uno::makeAny(sal_Int16(nHelpTipSeconds+1)) ); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + nHelpTipSeconds_ = aAccessibilityOpt.GetHelpTipSeconds(); + + if ( nHelpTipSeconds_ == nHelpTipSeconds )//old config item will not throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetHelpTipSeconds() error!")), 0); +} + +//============================================================================= +//test impl_checkIsSelectionInReadonly() +void AccessibilityOptTest::impl_checkIsSelectionInReadonly() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsSelectionInReadonly ; + sal_Bool bIsSelectionInReadonly_; + + bIsSelectionInReadonly = aAccessibilityOpt.IsSelectionInReadonly(); + xSet->setPropertyValue( s_sIsSelectionInReadonly, css::uno::makeAny(bIsSelectionInReadonly ? sal_False:sal_True) ); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + bIsSelectionInReadonly_ = aAccessibilityOpt.IsSelectionInReadonly(); + + if ( bIsSelectionInReadonly_ == bIsSelectionInReadonly )//old config item will not throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsSelectionInReadonly() error!")), 0); +} + +//============================================================================= +//test SetAutoDetectSystemHC() +void AccessibilityOptTest::impl_checkSetAutoDetectSystemHC() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bAutoDetectSystemHC; + sal_Bool bAutoDetectSystemHC_; + + xSet->getPropertyValue(s_sAutoDetectSystemHC) >>= bAutoDetectSystemHC; + aAccessibilityOpt.SetAutoDetectSystemHC( bAutoDetectSystemHC ? sal_False:sal_True ); + xSet->getPropertyValue(s_sAutoDetectSystemHC) >>= bAutoDetectSystemHC_; + + if ( bAutoDetectSystemHC_ == bAutoDetectSystemHC )//old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetAutoDetectSystemHC() error!")), 0); +} + +//============================================================================= +//test SetIsForPagePreviews() +void AccessibilityOptTest::impl_checkSetIsForPagePreviews() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsForPagePreviews ; + sal_Bool bIsForPagePreviews_; + + xSet->getPropertyValue(s_sIsForPagePreviews) >>= bIsForPagePreviews; + aAccessibilityOpt.SetIsForPagePreviews( bIsForPagePreviews ? sal_False:sal_True ); + xSet->getPropertyValue(s_sIsForPagePreviews) >>= bIsForPagePreviews_; + + if ( bIsForPagePreviews_ == bIsForPagePreviews )//old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetIsForPagePreviews() error!")), 0); +} + +//============================================================================= +//test impl_checkSetIsHelpTipsDisappear() +void AccessibilityOptTest::impl_checkSetIsHelpTipsDisappear() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsHelpTipsDisappear ; + sal_Bool bIsHelpTipsDisappear_; + + xSet->getPropertyValue(s_sIsHelpTipsDisappear) >>= bIsHelpTipsDisappear; + aAccessibilityOpt.SetIsHelpTipsDisappear( bIsHelpTipsDisappear ? sal_False:sal_True ); + xSet->getPropertyValue(s_sIsHelpTipsDisappear) >>= bIsHelpTipsDisappear_; + + if ( bIsHelpTipsDisappear_ == bIsHelpTipsDisappear )//old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetIsHelpTipsDisappear() error!")), 0); +} + +//============================================================================= +//test impl_checkSetIsAllowAnimatedGraphics() +void AccessibilityOptTest::impl_checkSetIsAllowAnimatedGraphics() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsAllowAnimatedGraphics ; + sal_Bool bIsAllowAnimatedGraphics_; + + xSet->getPropertyValue(s_sIsAllowAnimatedGraphics) >>= bIsAllowAnimatedGraphics; + aAccessibilityOpt.SetIsAllowAnimatedGraphics( bIsAllowAnimatedGraphics ? sal_False:sal_True ); + xSet->getPropertyValue(s_sIsAllowAnimatedGraphics) >>= bIsAllowAnimatedGraphics_; + + if ( bIsAllowAnimatedGraphics_ == bIsAllowAnimatedGraphics )//old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetIsAllowAnimatedGraphics() error!")), 0); +} + +//============================================================================= +//test impl_checkSetIsAllowAnimatedText() +void AccessibilityOptTest::impl_checkSetIsAllowAnimatedText() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsAllowAnimatedText ; + sal_Bool bIsAllowAnimatedText_; + + xSet->getPropertyValue(s_sIsAllowAnimatedText) >>= bIsAllowAnimatedText; + aAccessibilityOpt.SetIsAllowAnimatedText( bIsAllowAnimatedText ? sal_False:sal_True ); + xSet->getPropertyValue(s_sIsAllowAnimatedText) >>= bIsAllowAnimatedText_; + + if ( bIsAllowAnimatedText_ == bIsAllowAnimatedText )//old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetIsAllowAnimatedText() error!")), 0); +} + +//============================================================================= +//test impl_checkSetIsAutomaticFontColor() +void AccessibilityOptTest::impl_checkSetIsAutomaticFontColor() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsAutomaticFontColor ; + sal_Bool bIsAutomaticFontColor_; + + xSet->getPropertyValue(s_sIsAutomaticFontColor) >>= bIsAutomaticFontColor; + aAccessibilityOpt.SetIsAutomaticFontColor( bIsAutomaticFontColor ? sal_False:sal_True ); + xSet->getPropertyValue(s_sIsAutomaticFontColor) >>= bIsAutomaticFontColor_; + + if ( bIsAutomaticFontColor_ == bIsAutomaticFontColor )//old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetIsAutomaticFontColor() error!")), 0); +} + +//============================================================================= +//test impl_checkSetIsSystemFont() +void AccessibilityOptTest::impl_checkSetIsSystemFont() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsSystemFont ; + sal_Bool bIsSystemFont_; + + xSet->getPropertyValue(s_sIsSystemFont) >>= bIsSystemFont; + aAccessibilityOpt.SetIsSystemFont( bIsSystemFont ? sal_False:sal_True ); + xSet->getPropertyValue(s_sIsSystemFont) >>= bIsSystemFont_; + + if ( bIsSystemFont_ == bIsSystemFont )//old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetIsSystemFont() error!")), 0); +} + +//============================================================================= +//test impl_checkSetHelpTipSeconds() +void AccessibilityOptTest::impl_checkSetHelpTipSeconds() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Int16 nHelpTipSeconds ; + sal_Int16 nHelpTipSeconds_; + + xSet->getPropertyValue(s_sHelpTipSeconds) >>= nHelpTipSeconds; + aAccessibilityOpt.SetHelpTipSeconds( sal_Int16(nHelpTipSeconds+1) ); + xSet->getPropertyValue(s_sHelpTipSeconds) >>= nHelpTipSeconds_; + + if ( nHelpTipSeconds_ == nHelpTipSeconds )//old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetHelpTipSeconds() error!")), 0); +} + +//============================================================================= +//test impl_checkSetSelectionInReadonly() +void AccessibilityOptTest::impl_checkSetSelectionInReadonly() +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCfg, css::uno::UNO_QUERY); + sal_Bool bIsSelectionInReadonly ; + sal_Bool bIsSelectionInReadonly_; + + xSet->getPropertyValue(s_sIsSelectionInReadonly) >>= bIsSelectionInReadonly; + aAccessibilityOpt.SetSelectionInReadonly( bIsSelectionInReadonly ? sal_False:sal_True ); + xSet->getPropertyValue(s_sIsSelectionInReadonly) >>= bIsSelectionInReadonly_; + + if ( bIsSelectionInReadonly_ == bIsSelectionInReadonly )//old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetSelectionInReadonly() error!")), 0); +} + +//============================================================================= +void AccessibilityOptTest::impl_checkAccessibilityOptions() +{ + impl_checkGetAutoDetectSystemHC(); + impl_checkGetIsForPagePreviews(); + impl_checkGetIsHelpTipsDisappear(); + impl_checkGetIsAllowAnimatedGraphics(); + impl_checkGetIsAllowAnimatedText(); + impl_checkGetIsAutomaticFontColor(); + impl_checkGetIsSystemFont(); + impl_checkGetHelpTipSeconds(); + impl_checkIsSelectionInReadonly(); + + impl_checkSetAutoDetectSystemHC(); + impl_checkSetIsForPagePreviews(); + impl_checkSetIsHelpTipsDisappear(); + impl_checkSetIsAllowAnimatedGraphics(); + impl_checkSetIsAllowAnimatedText(); + impl_checkSetIsAutomaticFontColor(); + impl_checkSetIsSystemFont(); + impl_checkSetHelpTipSeconds(); + impl_checkSetSelectionInReadonly(); +} diff --git a/svl/qa/complex/ConfigItems/helper/AccessibilityOptTest.hxx b/svl/qa/complex/ConfigItems/helper/AccessibilityOptTest.hxx new file mode 100644 index 000000000000..fc2f4681e4fe --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/AccessibilityOptTest.hxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: AccessibilityOptTest.hxx,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:23 $ + * + * 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 + * + ************************************************************************/ + +#ifndef SVTOOLS_ACCESSIBILITYOPTTEST_HXX +#define SVTOOLS_ACCESSIBILITYOPTTEST_HXX + +#include <com/sun/star/container/XNameAccess.hpp> +#include <svtools/accessibilityoptions.hxx> + +namespace css = ::com::sun::star; + +class AccessibilityOptTest +{ +public: + AccessibilityOptTest(); + ~AccessibilityOptTest(); + + void impl_checkAccessibilityOptions(); + +private: + void impl_checkGetAutoDetectSystemHC(); + void impl_checkGetIsForPagePreviews(); + void impl_checkGetIsHelpTipsDisappear(); + void impl_checkGetIsAllowAnimatedGraphics(); + void impl_checkGetIsAllowAnimatedText(); + void impl_checkGetIsAutomaticFontColor(); + void impl_checkGetIsSystemFont(); + void impl_checkGetHelpTipSeconds(); + void impl_checkIsSelectionInReadonly(); + + void impl_checkSetAutoDetectSystemHC(); + void impl_checkSetIsForPagePreviews(); + void impl_checkSetIsHelpTipsDisappear(); + void impl_checkSetIsAllowAnimatedGraphics(); + void impl_checkSetIsAllowAnimatedText(); + void impl_checkSetIsAutomaticFontColor(); + void impl_checkSetIsSystemFont(); + void impl_checkSetHelpTipSeconds(); + void impl_checkSetSelectionInReadonly(); + +private: + css::uno::Reference< css::container::XNameAccess > m_xCfg; + SvtAccessibilityOptions aAccessibilityOpt; +}; + +#endif // #ifndef SVTOOLS_ACCESSIBILITYOPTTEST_HXX diff --git a/svl/qa/complex/ConfigItems/helper/ConfigItemTest.cxx b/svl/qa/complex/ConfigItems/helper/ConfigItemTest.cxx new file mode 100644 index 000000000000..b21d9d76755e --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/ConfigItemTest.cxx @@ -0,0 +1,253 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: ConfigItemTest.cxx,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:23 $ + * + * 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 "HistoryOptTest.hxx" +#include "AccessibilityOptTest.hxx" +#include "PrintOptTest.hxx" +#include "UserOptTest.hxx" + +#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> + +//============================================================================= +namespace css = ::com::sun::star; + +namespace svtools{ + +//============================================================================= +static const ::rtl::OUString PROP_TEST = ::rtl::OUString::createFromAscii("Test"); +static const ::rtl::OUString TEST_PICKLIST = ::rtl::OUString::createFromAscii("checkPicklist"); +static const ::rtl::OUString TEST_URLHISTORY = ::rtl::OUString::createFromAscii("checkURLHistory"); +static const ::rtl::OUString TEST_HELPBOOKMARKS = ::rtl::OUString::createFromAscii("checkHelpBookmarks"); +static const ::rtl::OUString TEST_ACCESSIBILITYOPTIONS = ::rtl::OUString::createFromAscii("checkAccessibilityOptions"); +static const ::rtl::OUString TEST_PRINTOPTIONS = ::rtl::OUString::createFromAscii("checkPrintOptions"); +static const ::rtl::OUString TEST_USEROPTIONS = ::rtl::OUString::createFromAscii("checkUserOptions"); + +//============================================================================= +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.equals(PROP_TEST)) + rArg.Value >>= sTest; + } + + if (sTest.equals(TEST_PICKLIST)) + { + HistoryOptTest aOptTest; + aOptTest.checkPicklist(); + } + else if (sTest.equals(TEST_URLHISTORY)) + { + HistoryOptTest aOptTest; + aOptTest.checkURLHistory(); + } + else if (sTest.equals(TEST_HELPBOOKMARKS)) + { + HistoryOptTest aOptTest; + aOptTest.checkHelpBookmarks(); + } + else if (sTest.equals(TEST_ACCESSIBILITYOPTIONS)) + { + AccessibilityOptTest aOptTest; + aOptTest.impl_checkAccessibilityOptions(); + } + else if (sTest.equals(TEST_PRINTOPTIONS)) + { + PrintOptTest aOptTest; + aOptTest.impl_checkPrint(); + } + else if (sTest.equals(TEST_USEROPTIONS)) + { + UserOptTest aOptTest; + aOptTest.impl_checkUserData(); + } + + 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); +} diff --git a/svl/qa/complex/ConfigItems/helper/HistoryOptTest.cxx b/svl/qa/complex/ConfigItems/helper/HistoryOptTest.cxx new file mode 100644 index 000000000000..082328835fca --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/HistoryOptTest.cxx @@ -0,0 +1,806 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: HistoryOptTest.cxx,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:23 $ + * + * 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 "HistoryOptTest.hxx" +#include <unotools/historyoptions_const.hxx> + +#include <com/sun/star/uno/Sequence.hxx> +#include <com/sun/star/beans/PropertyValue.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/container/XNameContainer.hpp> + +#include <comphelper/configurationhelper.hxx> +#include <comphelper/sequenceashashmap.hxx> +#include <unotools/processfactory.hxx> + +namespace css = ::com::sun::star; + +//============================================================================= +static const ::rtl::OUString MESSAGE_CLEAR_FAILED = ::rtl::OUString::createFromAscii("Clearing the list failed."); +static const ::rtl::OUString MESSAGE_SETSIZE_FAILED = ::rtl::OUString::createFromAscii("Setting a new size for a list failed."); +static const ::rtl::OUString MESSAGE_MISS_HISTORY = ::rtl::OUString::createFromAscii("Could not get config access to history list inside config."); +static const ::rtl::OUString MESSAGE_MISS_ITEMLIST = ::rtl::OUString::createFromAscii("Could not get config access to item list inside config."); +static const ::rtl::OUString MESSAGE_MISS_ORDERLIST = ::rtl::OUString::createFromAscii("Could not get config access to order list inside config."); +static const ::rtl::OUString MESSAGE_MISS_ITEM = ::rtl::OUString::createFromAscii("Could not locate item."); +static const ::rtl::OUString MESSAGE_UNEXPECTED_ITEM = ::rtl::OUString::createFromAscii("Found an unexpected item."); +static const ::rtl::OUString MESSAGE_WRONG_ORDER = ::rtl::OUString::createFromAscii("Wrong order in history list."); + +//============================================================================= +HistoryOptTest::HistoryOptTest() + : m_aConfigItem ( ) + , m_eList (ePICKLIST) + , m_xHistoriesXCU( ) + , m_xCommonXCU ( ) +{ +} + +//============================================================================= +HistoryOptTest::~HistoryOptTest() +{ + m_xHistoriesXCU.clear(); + m_xCommonXCU.clear(); +} + +//============================================================================= +void HistoryOptTest::checkPicklist() +{ + impl_testHistory(ePICKLIST, 4); +} + +//============================================================================= +void HistoryOptTest::checkURLHistory() +{ + impl_testHistory(eHISTORY, 10); +} + +//============================================================================= +void HistoryOptTest::checkHelpBookmarks() +{ + impl_testHistory(eHELPBOOKMARKS, 100); +} + +//============================================================================= +void HistoryOptTest::impl_testHistory(EHistoryType eHistory , + ::sal_Int32 nMaxItems) +{ + try + { + m_eList = eHistory; + ::sal_Int32 c = nMaxItems; + ::sal_Int32 i = 0; + + impl_clearList( ); + impl_setSize (c); + + // a) fill list completely and check if all items could be realy created. + // But dont check its order here! Because every new item will change that order. + for (i=0; i<c; ++i) + { + impl_appendItem(i); + if ( ! impl_existsItem(i)) + throw css::uno::Exception(MESSAGE_MISS_ITEM, 0); + } + + // b) Check order of all items in list now. + // It must be reverse to the item number ... + // item max = index 0 + // item max-1 = index 1 + // ... + for (i=0; i<c; ++i) + { + ::sal_Int32 nExpectedIndex = (c-1)-i; + if ( ! impl_existsItemAtIndex(i, nExpectedIndex)) + throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); + } + + // c) increase prio of "first" item so it will switch + // to "second" and "second" will switch to "first" :-) + // Check also if all other items was not touched. + ::sal_Int32 nFirstItem = (c-1); + ::sal_Int32 nSecondItem = (c-2); + impl_appendItem(nSecondItem); + + if ( + ( ! impl_existsItemAtIndex(nSecondItem, 0)) || + ( ! impl_existsItemAtIndex(nFirstItem , 1)) + ) + throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); + + for (i=0; i<nSecondItem; ++i) + { + ::sal_Int32 nExpectedIndex = (c-1)-i; + if ( ! impl_existsItemAtIndex(i, nExpectedIndex)) + throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); + } + + // d) Check if appending new items will destroy the oldest one. + ::sal_Int32 nNewestItem = c; + ::sal_Int32 nOldestItem = 0; + + impl_appendItem(nNewestItem); + + if ( ! impl_existsItemAtIndex(nNewestItem, 0)) + throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); + + if (impl_existsItem(nOldestItem)) + throw css::uno::Exception(MESSAGE_UNEXPECTED_ITEM, 0); + + // e) Check if decreasing list size will remove oldest items. + // Note: impl_setSize() will make sure that 3 items exists only. + // Otherwhise it throws an exception. If we further check + // positions of three items no further items must be checked. + // They cant exists :-) + ::sal_Int32 nNewSize = 3; + impl_setSize(nNewSize); + if ( + ( ! impl_existsItemAtIndex(nNewestItem, 0)) || + ( ! impl_existsItemAtIndex(nSecondItem, 1)) || + ( ! impl_existsItemAtIndex(nFirstItem , 2)) + ) + throw css::uno::Exception(MESSAGE_WRONG_ORDER, 0); + + // finaly we should try to clean up all used structures so the same office can be used + // without problems :-) + impl_clearList(); + } + catch (const css::uno::Exception& ex) + { + impl_clearList(); + throw ex; + } + +} + +//============================================================================= +void HistoryOptTest::impl_clearList() +{ + m_aConfigItem.Clear(m_eList); + ::sal_Int32 nCount = m_aConfigItem.GetList(m_eList).getLength(); + + if (nCount != 0) + throw css::uno::Exception(MESSAGE_CLEAR_FAILED, 0); + + css::uno::Reference< css::container::XNameAccess > xList; + xList = impl_getItemList(); + nCount = xList->getElementNames().getLength(); + + if (nCount != 0) + throw css::uno::Exception(MESSAGE_CLEAR_FAILED, 0); + + xList = impl_getOrderList(); + nCount = xList->getElementNames().getLength(); + + if (nCount != 0) + throw css::uno::Exception(MESSAGE_CLEAR_FAILED, 0); +} + +//============================================================================= +void HistoryOptTest::impl_setSize(::sal_Int32 nSize) +{ + m_aConfigItem.SetSize (m_eList, nSize); + + // a) size info returned by GetSize() means "MaxSize" + // so it must match exactly ! + ::sal_Int32 nCheck = m_aConfigItem.GetSize(m_eList); + if (nCheck != nSize) + throw css::uno::Exception(MESSAGE_SETSIZE_FAILED, 0); + + // b) current size of used XCU lists reflects the current state of + // history list and not max size. So it can be less then size ! + css::uno::Reference< css::container::XNameAccess > xList; + xList = impl_getItemList(); + nCheck = xList->getElementNames().getLength(); + if (nCheck > nSize) + throw css::uno::Exception(MESSAGE_SETSIZE_FAILED, 0); + + xList = impl_getOrderList(); + nCheck = xList->getElementNames().getLength(); + if (nCheck > nSize) + throw css::uno::Exception(MESSAGE_SETSIZE_FAILED, 0); +} + +//============================================================================= +void HistoryOptTest::impl_appendItem(::sal_Int32 nItem) +{ + const ::rtl::OUString sURL = impl_createItemURL (nItem); + const ::rtl::OUString sTitle = impl_createItemTitle (nItem); + const ::rtl::OUString sPassword = impl_createItemPassword(nItem); + + m_aConfigItem.AppendItem(m_eList, sURL, ::rtl::OUString(), sTitle, sPassword); +} + +//============================================================================= +::rtl::OUString HistoryOptTest::impl_createItemURL(::sal_Int32 nItem) +{ + ::rtl::OUStringBuffer sURL(256); + sURL.appendAscii("file:///ooo_api_test/non_existing_test_url_"); + sURL.append ((::sal_Int32)nItem ); + sURL.appendAscii(".odt" ); + + return sURL.makeStringAndClear(); +} + +//============================================================================= +::rtl::OUString HistoryOptTest::impl_createItemTitle(::sal_Int32 nItem) +{ + ::rtl::OUStringBuffer sTitle(256); + sTitle.appendAscii("Non Existing Test Item Nr "); + sTitle.append ((::sal_Int32)nItem ); + + return sTitle.makeStringAndClear(); +} + +//============================================================================= +::rtl::OUString HistoryOptTest::impl_createItemPassword(::sal_Int32 nItem) +{ + ::rtl::OUStringBuffer sPassword(256); + sPassword.appendAscii("Password_" ); + sPassword.append ((::sal_Int32)nItem); + + return sPassword.makeStringAndClear(); +} + +//============================================================================= +::sal_Bool HistoryOptTest::impl_existsItem(::sal_Int32 nItem) +{ + const ::rtl::OUString sURL = impl_createItemURL(nItem); + const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > lItems = m_aConfigItem.GetList(m_eList); + const ::sal_Int32 c = lItems.getLength (); + ::sal_Int32 i = 0; + ::sal_Bool bFound = sal_False; + + for (i=0; i<c; ++i) + { + const ::comphelper::SequenceAsHashMap aItem(lItems[i]); + const ::rtl::OUString& sCheck = aItem.getUnpackedValueOrDefault(s_sURL, ::rtl::OUString()); + + bFound = sCheck.equals(sURL); + if (bFound) + break; + } + + if ( ! bFound) + return sal_False; + bFound = sal_False; + + try + { + css::uno::Reference< css::container::XNameAccess > xItemList = impl_getItemList(); + css::uno::Reference< css::container::XNameAccess > xItem ; + xItemList->getByName(sURL) >>= xItem; + + bFound = xItem.is(); + } + catch(const css::container::NoSuchElementException&) + {} + + return bFound; +} + +//============================================================================= +::sal_Bool HistoryOptTest::impl_existsItemAtIndex(::sal_Int32 nItem , + ::sal_Int32 nIndex) +{ + const ::rtl::OUString sURL = impl_createItemURL(nItem); + const css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > lItems = m_aConfigItem.GetList(m_eList); + const ::sal_Int32 c = lItems.getLength (); + ::sal_Bool bFound = sal_False; + + if (nIndex >= c) + return sal_False; + + const ::comphelper::SequenceAsHashMap aItem(lItems[nIndex]); + ::rtl::OUString sCheck = aItem.getUnpackedValueOrDefault(s_sURL, ::rtl::OUString()); + + bFound = sCheck.equals(sURL); + if ( ! bFound) + return sal_False; + bFound = sal_False; + + try + { + css::uno::Reference< css::container::XNameAccess > xItemList = impl_getItemList(); + css::uno::Reference< css::container::XNameAccess > xItem ; + xItemList->getByName(sURL) >>= xItem; + + bFound = xItem.is(); + } + catch(const css::container::NoSuchElementException&) + {} + + if ( ! bFound) + return sal_False; + bFound = sal_False; + + try + { + const ::rtl::OUString sOrder = ::rtl::OUString::valueOf(nIndex); + css::uno::Reference< css::container::XNameAccess > xOrderList = impl_getOrderList(); + css::uno::Reference< css::container::XNameAccess > xOrder ; + xOrderList->getByName(sOrder) >>= xOrder; + + if (xOrder.is()) + { + xOrder->getByName(s_sHistoryItemRef) >>= sCheck; + bFound = sCheck.equals(sURL); + } + } + catch(const css::container::NoSuchElementException&) + {} + + return bFound; +} + +//============================================================================= +css::uno::Reference< css::container::XNameAccess > HistoryOptTest::impl_getItemList() +{ + css::uno::Reference< css::container::XNameAccess > xHistory = impl_getNewHistory(); + css::uno::Reference< css::container::XNameAccess > xList ; + xHistory->getByName (s_sItemList) >>= xList; + + if ( ! xList.is()) + throw css::uno::Exception(MESSAGE_MISS_ITEMLIST, 0); + + return xList; +} + +//============================================================================= +css::uno::Reference< css::container::XNameAccess > HistoryOptTest::impl_getOrderList() +{ + css::uno::Reference< css::container::XNameAccess > xHistory = impl_getNewHistory(); + css::uno::Reference< css::container::XNameAccess > xList ; + xHistory->getByName (s_sOrderList) >>= xList; + + if ( ! xList.is()) + throw css::uno::Exception(MESSAGE_MISS_ORDERLIST, 0); + + return xList; +} + +//============================================================================= +css::uno::Reference< css::container::XNameAccess > HistoryOptTest::impl_getNewHistory() +{ + if ( ! m_xHistoriesXCU.is()) + { + m_xHistoriesXCU = css::uno::Reference< css::container::XNameAccess >( + ::comphelper::ConfigurationHelper::openConfig( + ::utl::getProcessServiceFactory(), + s_sHistories, + ::comphelper::ConfigurationHelper::E_STANDARD), + css::uno::UNO_QUERY_THROW); + } + + css::uno::Reference< css::container::XNameAccess > xHistory; + + switch (m_eList) + { + case ePICKLIST : + m_xHistoriesXCU->getByName(s_sPickList) >>= xHistory; + break; + + case eHISTORY : + m_xHistoriesXCU->getByName(s_sURLHistory) >>= xHistory; + break; + + case eHELPBOOKMARKS : + m_xHistoriesXCU->getByName(s_sHelpBookmarks) >>= xHistory; + break; + } + + if ( ! xHistory.is()) + throw css::uno::Exception(MESSAGE_MISS_HISTORY, 0); + + return xHistory; +} + +//============================================================================= +css::uno::Reference< css::container::XNameAccess > HistoryOptTest::impl_getOldHistory() +{ + if ( ! m_xCommonXCU.is()) + { + m_xCommonXCU = css::uno::Reference< css::container::XNameAccess >( + ::comphelper::ConfigurationHelper::openConfig( + ::utl::getProcessServiceFactory(), + s_sCommonHistory, + ::comphelper::ConfigurationHelper::E_STANDARD), + css::uno::UNO_QUERY_THROW); + } + + css::uno::Reference< css::container::XNameAccess > xHistory; + + switch (m_eList) + { + case ePICKLIST : + m_xCommonXCU->getByName(s_sPickList) >>= xHistory; + break; + + case eHISTORY : + m_xCommonXCU->getByName(s_sURLHistory) >>= xHistory; + break; + + case eHELPBOOKMARKS : + m_xCommonXCU->getByName(s_sHelpBookmarks) >>= xHistory; + break; + } + + if ( ! xHistory.is()) + throw css::uno::Exception(MESSAGE_MISS_HISTORY, 0); + + return xHistory; +} + +/* +//============================================================================= +// clear the list in XML directly when using the new Histories.xcs +void HistoryOptTest::impl_clearList(const ::rtl::OUString& sList) +{ + css::uno::Reference< css::container::XNameAccess > xListAccess; + css::uno::Reference< css::container::XNameContainer > xItemOrder; + css::uno::Reference< css::beans::XPropertySet > xFirstItem; + css::uno::Sequence< ::rtl::OUString > sFileList; + + if (sList.equalsAscii("PickList")) + m_xCfg->getByName(s_sPickList) >>= xListAccess; + + else if (sList.equalsAscii("URLHistory")) + m_xCfg->getByName(s_sURLHistory) >>= xListAccess; + + else if (sList.equalsAscii("HelpBookmarks")) + m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess; + + if (xListAccess.is()) + { + xListAccess->getByName(s_sItemList) >>= xItemOrder ; + sFileList = xItemOrder->getElementNames(); + for(sal_Int32 i=0; i<sFileList.getLength(); ++i) + xItemOrder->removeByName(sFileList[i]); + + xListAccess->getByName(s_sOrderList) >>= xItemOrder ; + sFileList = xItemOrder->getElementNames(); + for(sal_Int32 j=0; j<sFileList.getLength(); ++j) + xItemOrder->removeByName(sFileList[j]); + + xFirstItem = css::uno::Reference< css::beans::XPropertySet >(xListAccess, css::uno::UNO_QUERY); + xFirstItem->setPropertyValue( s_sFirstItem, css::uno::makeAny((sal_Int32)0) ); + + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } +} + +//============================================================================= +// use configuration API (not ConfigItem!) to verify the results within XML ! +sal_Bool HistoryOptTest::impl_isListEmpty(const ::rtl::OUString& sList) +{ + css::uno::Reference< css::container::XNameAccess > xListAccess; + css::uno::Reference< css::container::XNameAccess > xItemList; + css::uno::Reference< css::container::XNameAccess > xOrderList; + sal_Bool bRet = sal_True; + + if (sList.equalsAscii("PickList")) + m_xCfg->getByName(s_sPickList) >>= xListAccess; + + else if (sList.equalsAscii("URLHistory")) + m_xCfg->getByName(s_sURLHistory) >>= xListAccess; + + else if (sList.equalsAscii("HelpBookmarks")) + m_xCfg->getByName(s_sHelpBookmarks) >>= xListAccess; + + if (xListAccess.is()) + { + xListAccess->getByName(s_sItemList) >>= xItemList; + xListAccess->getByName(s_sOrderList) >>= 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; +} + +//============================================================================= +// append a item: use configuration API (not ConfigItem!) to verify the results within XML ! +void HistoryOptTest::impl_appendItem(const ::rtl::OUString& sList) +{//to do... +} + +//============================================================================= +// test SvtHistoryOptions::GetSize() +void HistoryOptTest::impl_checkGetSize(const ::rtl::OUString& sList) +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCommonXCU, css::uno::UNO_QUERY); + + sal_uInt32 nSize = 0; + sal_uInt32 nSize_ = 0; + + if (sList.equalsAscii("PickList")) + { + nSize = aHistoryOpt.GetSize(ePICKLIST); + + xSet->setPropertyValue(s_sPickListSize, css::uno::makeAny(nSize+1)); + ::comphelper::ConfigurationHelper::flush(m_xCommonXCU); + + nSize_ = aHistoryOpt.GetSize(ePICKLIST); + if (nSize_ == nSize) + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetSize(ePICKLIST) error!")), 0); + } + + else if (sList.equalsAscii("URLHistory")) + { + nSize = aHistoryOpt.GetSize(eHISTORY); + + xSet->setPropertyValue(s_sURLHistorySize, css::uno::makeAny(nSize+1)); + ::comphelper::ConfigurationHelper::flush(m_xCommonXCU); + + nSize_ = aHistoryOpt.GetSize(eHISTORY); + + if (nSize_ == nSize) + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetSize(eHISTORY) error!")), 0); + } + + else if (sList.equalsAscii("HelpBookmarks")) + { + nSize = aHistoryOpt.GetSize(eHELPBOOKMARKS); + + xSet->setPropertyValue(s_sHelpBookmarksSize, css::uno::makeAny(nSize+1)); + ::comphelper::ConfigurationHelper::flush(m_xCommonXCU); + + nSize_ = aHistoryOpt.GetSize(eHELPBOOKMARKS); + + if (nSize_ == nSize) + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetSize(eHELPBOOKMARKS) error!")), 0); + } +} + +//============================================================================= +// test SvtHistoryOptions::SetSize() +void HistoryOptTest::impl_checkSetSize(const ::rtl::OUString& sList) +{ + css::uno::Reference< css::beans::XPropertySet > xSet(m_xCommonXCU, css::uno::UNO_QUERY); + + sal_uInt32 nSize = 0; + sal_uInt32 nSize_ = 0; + + if (sList.equalsAscii("PickList")) + { + xSet->getPropertyValue(s_sPickListSize) >>= nSize; + aHistoryOpt.SetSize(ePICKLIST, (nSize+1)); + xSet->getPropertyValue(s_sPickListSize) >>= nSize_; + + if (nSize_ == nSize) //old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetSize(ePICKLIST) error!")), 0); + } + + else if (sList.equalsAscii("URLHistory")) + { + xSet->getPropertyValue(s_sURLHistorySize) >>= nSize; + aHistoryOpt.SetSize(eHISTORY, (nSize+1)); + xSet->getPropertyValue(s_sURLHistorySize) >>= nSize_; + + if (nSize_ == nSize) //old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetSize(eHISTORY) error!")), 0); + } + + else if (sList.equalsAscii("HelpBookmarks")) + { + xSet->getPropertyValue(s_sHelpBookmarksSize) >>= nSize; + aHistoryOpt.SetSize(eHELPBOOKMARKS, (nSize+1)); + xSet->getPropertyValue(s_sHelpBookmarksSize) >>= nSize_; + + if (nSize_ == nSize) //old config item will throw error + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SetSize(eHELPBOOKMARKS) error!")), 0); + } +} + +//============================================================================= +// test SvtHistoryOptions::Clear() +void HistoryOptTest::impl_checkClear(const ::rtl::OUString& sList) +{ + if (sList.equalsAscii("PickList")) + { + aHistoryOpt.Clear(ePICKLIST); + if ( !impl_isListEmpty(s_sPickList) ) + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Clear(ePICKLIST) error!")), 0); + } + + else if (sList.equalsAscii("URLHistory")) + { + aHistoryOpt.Clear(eHISTORY); + if ( !impl_isListEmpty(s_sURLHistory) ) + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Clear(eHISTORY) error!")), 0); + } + + else if (sList.equalsAscii("HelpBookmarks")) + { + aHistoryOpt.Clear(eHELPBOOKMARKS); + if ( !impl_isListEmpty(s_sHelpBookmarks) ) + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Clear(eHELPBOOKMARKS) error!")), 0); + } +} + +//============================================================================= +// test SvtHistoryOptions::GetList() +void HistoryOptTest::impl_checkGetList(const ::rtl::OUString& sList) +{ + if (sList.equalsAscii("PickList")) + { + impl_clearList(s_sPickList); + aHistoryOpt.AppendItem( ePICKLIST , + ::rtl::OUString::createFromAscii("file:///c/test1"), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii("") ); + css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aHistoryList = aHistoryOpt.GetList( ePICKLIST ); + + if ( aHistoryList.getLength()==0 ) + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetList(ePICKLIST) error!")), 0); + } + + else if (sList.equalsAscii("URLHistory")) + { + impl_clearList(s_sURLHistory); + aHistoryOpt.AppendItem( eHISTORY , + ::rtl::OUString::createFromAscii("file:///c/test1"), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii("") ); + css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aHistoryList = aHistoryOpt.GetList( eHISTORY ); + + if ( aHistoryList.getLength()==0 ) + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetList(eHISTORY) error!")), 0); + } + + else if (sList.equalsAscii("HelpBookmarks")) + { + impl_clearList(s_sHelpBookmarks); + aHistoryOpt.AppendItem( eHELPBOOKMARKS , + ::rtl::OUString::createFromAscii("file:///c/test1"), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii("") ); + css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aHistoryList = aHistoryOpt.GetList( eHELPBOOKMARKS ); + + if ( aHistoryList.getLength()==0 ) + throw css::uno::RuntimeException( + ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GetList(eHELPBOOKMARKS) error!")), 0); + } +} + +void HistoryOptTest::impl_checkAppendItem(const ::rtl::OUString& sList) +{ + if (sList.equalsAscii("PickList")) + { + impl_clearList(s_sPickList); + sal_Int32 nListSize = aHistoryOpt.GetSize(ePICKLIST); + + for (sal_Int32 i=0; i<nListSize; ++i) + aHistoryOpt.AppendItem( ePICKLIST , + ::rtl::OUString::valueOf(i), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii("") ); + + aHistoryOpt.AppendItem( ePICKLIST , + ::rtl::OUString::valueOf(nListSize), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii("") ); + } + + else if (sList.equalsAscii("URLHistory")) + { + impl_clearList(s_sURLHistory); + sal_Int32 nListSize = aHistoryOpt.GetSize(eHISTORY); + + for (sal_Int32 i=0; i<nListSize; ++i) + aHistoryOpt.AppendItem( eHISTORY , + ::rtl::OUString::valueOf(i), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii("") ); + + aHistoryOpt.AppendItem( eHISTORY , + ::rtl::OUString::valueOf(nListSize), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii(""), + ::rtl::OUString::createFromAscii("") ); + } + + else if (sList.equalsAscii("HelpBookmarks")) + { + //impl_clearList(s_sHelpBookmarks); + //sal_Int32 nListSize = aHistoryOpt.GetSize(eHELPBOOKMARKS); + + //for (sal_Int32 i=0; i<nListSize; ++i) + // aHistoryOpt.AppendItem( eHELPBOOKMARKS , + // ::rtl::OUString::valueOf(i), + // ::rtl::OUString::createFromAscii(""), + // ::rtl::OUString::createFromAscii(""), + // ::rtl::OUString::createFromAscii("") ); + + //aHistoryOpt.AppendItem( eHELPBOOKMARKS , + // ::rtl::OUString::valueOf(nListSize), + // ::rtl::OUString::createFromAscii(""), + // ::rtl::OUString::createFromAscii(""), + // ::rtl::OUString::createFromAscii("") ); + } +} + +//============================================================================= +void HistoryOptTest::impl_checkPicklist() +{ + impl_checkGetSize(s_sPickList); + impl_checkSetSize(s_sPickList); + + impl_checkClear(s_sPickList); + impl_checkGetList(s_sPickList); + impl_checkAppendItem(s_sPickList); +} + +//============================================================================= +void HistoryOptTest::impl_checkURLHistory() +{ + impl_checkGetSize(s_sURLHistory); + impl_checkSetSize(s_sURLHistory); + + impl_checkClear(s_sURLHistory); + impl_checkGetList(s_sURLHistory); + impl_checkAppendItem(s_sURLHistory); +} + +//============================================================================= +void HistoryOptTest::impl_checkHelpBookmarks() +{ + impl_checkGetSize(s_sHelpBookmarks); + impl_checkSetSize(s_sHelpBookmarks); + + impl_checkClear(s_sHelpBookmarks); + impl_checkGetList(s_sHelpBookmarks); + impl_checkAppendItem(s_sHelpBookmarks); +} +*/ diff --git a/svl/qa/complex/ConfigItems/helper/HistoryOptTest.hxx b/svl/qa/complex/ConfigItems/helper/HistoryOptTest.hxx new file mode 100644 index 000000000000..8415d9f989b9 --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/HistoryOptTest.hxx @@ -0,0 +1,211 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: HistoryOptTest.hxx,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:24 $ + * + * 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 + * + ************************************************************************/ + +#ifndef SVTOOLS_HISTORYOPTTEST_HXX +#define SVTOOLS_HISTORYOPTTEST_HXX + +#include <com/sun/star/container/XNameAccess.hpp> +#include <unotools/historyoptions.hxx> + +namespace css = ::com::sun::star; + +class HistoryOptTest +{ + public: + + HistoryOptTest(); + virtual ~HistoryOptTest(); + + //--------------------------------------------------------------------- + /** unit test of picklist */ + void checkPicklist(); + + //--------------------------------------------------------------------- + /** unit test of URL list */ + void checkURLHistory(); + + //--------------------------------------------------------------------- + /** unit test of Help bookmarks */ + void checkHelpBookmarks(); + + private: + + //--------------------------------------------------------------------- + /** test every well known history list in the same way. + * Only the count of created and tested items can be defined from outside + * e.g. usefull for stress tests. + * + * @param eHistory + * specify the history list for testing. + * + * @param nMaxItems + * max count of new created and tested history items. + */ + void impl_testHistory(EHistoryType eHistory , + ::sal_Int32 nMaxItems); + + //--------------------------------------------------------------------- + /** try to clear the whole list and check the results. + * If list could not be cleared successfully an exception is thrown. + */ + void impl_clearList(); + + //--------------------------------------------------------------------- + /** define a new size for the current list and check the results. + * Note: The given size must match against the defined constraints. + * That must be checked before this method is called. + * + * @param nSize + * the new size. + */ + void impl_setSize(::sal_Int32 nSize); + + //--------------------------------------------------------------------- + /** create a new item (means it's properties using a special schema using the + * item id). + * + * Note: This method does not check if creation was successfully. + * Therefore exists more specialized method impl_existsItem() + * and impl_existsItemAtPosition(). + * + * @param nItem + * id of the item + */ + void impl_appendItem(::sal_Int32 nItem); + + //--------------------------------------------------------------------- + /** check if an entry for given item id realy exists (in memory and xcu file). + * + * @param nItem + * id of the item + * + * @return true if item exists - false otherwise. + */ + ::sal_Bool impl_existsItem(::sal_Int32 nItem); + + //--------------------------------------------------------------------- + /** check if an entry for given item id realy exists (in memory and xcu file). + * Further it checks if the requested item is placed at the also specified + * position inside history list. + * + * @param nItem + * id of the item + * + * @param nIndex + * expected position of item inside history list. + * + * @return true if item exists at right position - false otherwise. + */ + ::sal_Bool impl_existsItemAtIndex(::sal_Int32 nItem , + ::sal_Int32 nIndex); + + //--------------------------------------------------------------------- + /** create an URL suitable for the given item id. + * + * @param nItem + * id of the item + * + * @return the new created URL. + */ + ::rtl::OUString impl_createItemURL(::sal_Int32 nItem); + + //--------------------------------------------------------------------- + /** create a title suitable for the given item id. + * + * @param nItem + * id of the item + * + * @return the new created title. + */ + ::rtl::OUString impl_createItemTitle(::sal_Int32 nItem); + + //--------------------------------------------------------------------- + /** create a password suitable for the given item id. + * + * @param nItem + * id of the item + * + * @return the new created password. + */ + ::rtl::OUString impl_createItemPassword(::sal_Int32 nItem); + + //--------------------------------------------------------------------- + /** returns direct access to the item list inside histories.xcu + * suitable for the current defined list type (m_eList). + * + * @return reference to the item list configuration + */ + css::uno::Reference< css::container::XNameAccess > impl_getItemList(); + + //--------------------------------------------------------------------- + /** returns direct access to the order list inside histories.xcu + * suitable for the current defined list type (m_eList). + * + * @return reference to the order list configuration + */ + css::uno::Reference< css::container::XNameAccess > impl_getOrderList(); + + //--------------------------------------------------------------------- + /** returns direct access to the history list inside histories.xcu + * suitable for the current defined list type (m_eList). + * + * @return reference to the history list configuration + */ + css::uno::Reference< css::container::XNameAccess > impl_getNewHistory(); + + //--------------------------------------------------------------------- + /** returns direct access to the history config inside common.xcu + * suitable for the current defined list type (m_eList). + * + * @return reference to the history configuration + */ + css::uno::Reference< css::container::XNameAccess > impl_getOldHistory(); + + private: + + // the config item which should be tested here + SvtHistoryOptions m_aConfigItem; + + // defines the special list for testing (picklist, history or url list) + EHistoryType m_eList; + + // underlying configuration of the tested config items for cross over checks + css::uno::Reference< css::container::XNameAccess > m_xHistoriesXCU; + + // underlying configuration of the tested config items for cross over checks + css::uno::Reference< css::container::XNameAccess > m_xCommonXCU; +}; + +#endif // #ifndef SVTOOLS_HISTORYOPTTEST_HXX diff --git a/svl/qa/complex/ConfigItems/helper/PrintOptTest.cxx b/svl/qa/complex/ConfigItems/helper/PrintOptTest.cxx new file mode 100644 index 000000000000..69504e4d5d7e --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/PrintOptTest.cxx @@ -0,0 +1,743 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: PrintOptTest.cxx,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:24 $ + * + * 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 "PrintOptTest.hxx" + +#include <com/sun/star/beans/XPropertySet.hpp> + +#include <unotools/processfactory.hxx> +#include <comphelper/configurationhelper.hxx> + +namespace css = ::com::sun::star; + +// using test only +#define ROOTNODE_PRINTOPTION rtl::OUString::createFromAscii("org.openoffice.Office.Common/Print/Option") +#define PROPERTYNAME_REDUCETRANSPARENCY rtl::OUString::createFromAscii("ReduceTransparency") +#define PROPERTYNAME_REDUCEDTRANSPARENCYMODE rtl::OUString::createFromAscii("ReducedTransparencyMode") +#define PROPERTYNAME_REDUCEGRADIENTS rtl::OUString::createFromAscii("ReduceGradients") +#define PROPERTYNAME_REDUCEDGRADIENTMODE rtl::OUString::createFromAscii("ReducedGradientMode") +#define PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT rtl::OUString::createFromAscii("ReducedGradientStepCount") +#define PROPERTYNAME_REDUCEBITMAPS rtl::OUString::createFromAscii("ReduceBitmaps") +#define PROPERTYNAME_REDUCEDBITMAPMODE rtl::OUString::createFromAscii("ReducedBitmapMode") +#define PROPERTYNAME_REDUCEDBITMAPRESOLUTION rtl::OUString::createFromAscii("ReducedBitmapResolution") +#define PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY rtl::OUString::createFromAscii("ReducedBitmapIncludesTransparency") +#define PROPERTYNAME_CONVERTTOGREYSCALES rtl::OUString::createFromAscii("ConvertToGreyscales") + +PrintOptTest::PrintOptTest() +{ + m_xCfg = css::uno::Reference< css::container::XNameAccess >( + ::comphelper::ConfigurationHelper::openConfig( + ::utl::getProcessServiceFactory(), + rtl::OUString::createFromAscii("org.openoffice.Office.Common/Print/Option"), + ::comphelper::ConfigurationHelper::E_STANDARD), + css::uno::UNO_QUERY); + + if (m_xCfg.is()) + { + //UniString sTmp = UniString("printer"); + //xub_StrLen nTokenCount = sTmp.GetTokenCount('/'); + //sTmp = sTmp.GetToken(nTokenCount - 1, '/'); + m_xCfg->getByName(rtl::OUString::createFromAscii("Printer")) >>= m_xNode; + } +} + +sal_Int16 PrintOptTest::impl_GetReducedTransparencyMode() const +{ + sal_Int16 nRet = 0; + if (m_xNode.is()) + { + css::uno::Reference< css::beans::XPropertySet > xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + xSet->getPropertyValue(PROPERTYNAME_REDUCEDTRANSPARENCYMODE) >>= nRet; + } + return nRet; +} +void PrintOptTest::impl_SetReducedTransparencyMode(sal_Int16 nMode ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Int16 nUpdate; + xSet->getPropertyValue(PROPERTYNAME_REDUCEDTRANSPARENCYMODE) >>= nUpdate; + if (nUpdate != nMode) + { + xSet->setPropertyValue( PROPERTYNAME_REDUCEDTRANSPARENCYMODE, css::uno::makeAny(nMode)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + +sal_Bool PrintOptTest::impl_IsReduceTransparency() const +{ + sal_Bool bRet = sal_False; + if (m_xNode.is()) + { + css::uno::Reference< css::beans::XPropertySet > xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + xSet->getPropertyValue(PROPERTYNAME_REDUCETRANSPARENCY) >>= bRet; + } + return bRet; +} +void PrintOptTest::impl_SetReduceTransparency(sal_Bool bState ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Bool bUpdate; + xSet->getPropertyValue(PROPERTYNAME_REDUCETRANSPARENCY) >>= bUpdate; + if (bUpdate != bState) + { + xSet->setPropertyValue( PROPERTYNAME_REDUCETRANSPARENCY, css::uno::makeAny(bState)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + +sal_Bool PrintOptTest::impl_IsReduceGradients() const +{ + sal_Bool bRet = sal_False; + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + xSet->getPropertyValue(PROPERTYNAME_REDUCEGRADIENTS) >>= bRet; + } + } + return bRet; +} + +void PrintOptTest::impl_SetReduceGradients(sal_Bool bState ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Bool bUpdate; + xSet->getPropertyValue(PROPERTYNAME_REDUCEGRADIENTS) >>= bUpdate; + if (bUpdate != bState) + { + xSet->setPropertyValue( PROPERTYNAME_REDUCEGRADIENTS, css::uno::makeAny(bState)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + +sal_Int16 PrintOptTest::impl_GetReducedGradientMode() const +{ + sal_Int16 nRet = 0; + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTMODE) >>= nRet; + } + } + return nRet; +} + +void PrintOptTest::impl_SetReducedGradientMode(sal_Int16 nMode ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Int16 nUpdate; + xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTMODE) >>= nUpdate; + if (nUpdate != nMode) + { + xSet->setPropertyValue( PROPERTYNAME_REDUCEDGRADIENTMODE, css::uno::makeAny(nMode)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + +sal_Int16 PrintOptTest::impl_GetReducedGradientStepCount() const +{ + sal_Int16 nRet = 64; + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT) >>= nRet; + } + } + return nRet; +} +void PrintOptTest::impl_SetReducedGradientStepCount(sal_Int16 nStepCount ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Int16 nUpdate; + xSet->getPropertyValue(PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT) >>= nUpdate; + if (nUpdate != nStepCount) + { + xSet->setPropertyValue( PROPERTYNAME_REDUCEDGRADIENTSTEPCOUNT, css::uno::makeAny(nStepCount)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + +sal_Bool PrintOptTest::impl_IsReduceBitmaps() const +{ + sal_Bool bRet = sal_False; + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + xSet->getPropertyValue(PROPERTYNAME_REDUCEBITMAPS) >>= bRet; + } + } + return bRet; +} + +void PrintOptTest::impl_SetReduceBitmaps(sal_Bool bState ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Bool bUpdate; + xSet->getPropertyValue(PROPERTYNAME_REDUCEBITMAPS) >>= bUpdate; + if (bUpdate != bState) + { + xSet->setPropertyValue( PROPERTYNAME_REDUCEBITMAPS, css::uno::makeAny(bState)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + +sal_Int16 PrintOptTest::impl_GetReducedBitmapMode() const +{ + sal_Int16 nRet = 1; + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPMODE) >>= nRet; + } + } + return nRet; +} + +void PrintOptTest::impl_SetReducedBitmapMode(sal_Int16 nMode ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Int16 nUpdate; + xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPMODE) >>= nUpdate; + if (nUpdate != nMode) + { + xSet->setPropertyValue( PROPERTYNAME_REDUCEDBITMAPMODE, css::uno::makeAny(nMode)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + +sal_Int16 PrintOptTest::impl_GetReducedBitmapResolution() const +{ + sal_Int16 nRet = 3; + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPRESOLUTION) >>= nRet; + } + } + return nRet; +} + +void PrintOptTest::impl_SetReducedBitmapResolution(sal_Int16 nResolution ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Int16 nUpdate; + xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPRESOLUTION) >>= nUpdate; + if (nUpdate != nResolution) + { + xSet->setPropertyValue( PROPERTYNAME_REDUCEDBITMAPRESOLUTION, css::uno::makeAny(nResolution)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + +sal_Bool PrintOptTest::impl_IsReducedBitmapIncludesTransparency() const +{ + sal_Bool bRet = sal_True; + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY) >>= bRet; + } + } + return bRet; +} + +void PrintOptTest::impl_SetReducedBitmapIncludesTransparency(sal_Bool bState ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Bool bUpdate; + xSet->getPropertyValue(PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY) >>= bUpdate; + if (bUpdate != bState) + { + xSet->setPropertyValue( PROPERTYNAME_REDUCEDBITMAPINCLUDESTRANSPARENCY, css::uno::makeAny(bState)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + +sal_Bool PrintOptTest::impl_IsConvertToGreyscales() const +{ + sal_Bool bRet = sal_False; + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + xSet->getPropertyValue(PROPERTYNAME_CONVERTTOGREYSCALES) >>= bRet; + } + } + return bRet; +} + +void PrintOptTest::impl_SetConvertToGreyscales(sal_Bool bState ) +{ + if (m_xNode.is()) + { + css::uno::Reference<css::beans::XPropertySet> xSet(m_xNode, css::uno::UNO_QUERY); + if (xSet.is()) + { + sal_Bool bUpdate; + xSet->getPropertyValue(PROPERTYNAME_CONVERTTOGREYSCALES) >>= bUpdate; + if (bUpdate != bState) + { + xSet->setPropertyValue( PROPERTYNAME_CONVERTTOGREYSCALES, css::uno::makeAny(bState)); + ::comphelper::ConfigurationHelper::flush(m_xCfg); + } + } + } +} + + +PrintOptTest::~PrintOptTest() +{ +} + +void PrintOptTest::impl_checkPrint() +{ + //test SetReduceTransparency() + sal_Bool bNewValue = sal_False; + sal_Bool bOldValue = sal_False; + bOldValue = PrintOptTest::impl_IsReduceTransparency(); + bNewValue = !bOldValue; + aPrintOpt.SetReduceTransparency(bNewValue) ; + bNewValue = impl_IsReduceTransparency(); + // if(bNewValue != bOldValue) // test the old source + if ( bNewValue == bOldValue ) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetReduceTransparency() error!"), + 0); + } + + //test IsReduceTransparemcy() + bNewValue = bOldValue = sal_False; + bOldValue = impl_IsReduceTransparency(); + bNewValue = !bOldValue; + impl_SetReduceTransparency(bNewValue); + bNewValue = aPrintOpt.IsReduceTransparency(); + //if(bNewValue != bOldValue) // test the old source + if(bNewValue == bOldValue) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the IsReduceTransparency() error!"), + 0); + } + + // test SetReducedTransparencyMode() + sal_Int16 nOldMode, nNewMode; + nOldMode = nNewMode = 0; + nOldMode = impl_GetReducedTransparencyMode(); + nNewMode = nOldMode + 1; + aPrintOpt.SetReducedTransparencyMode( nNewMode ); + nNewMode = impl_GetReducedTransparencyMode(); + //if(nNewMode != nOldMode) // test the old source + if ( nNewMode == nOldMode ) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetReducedTransparencyMode() error!"), + 0); + } + + //test IsReducedTransparencyMode() + nOldMode = nNewMode = 0; + nOldMode = impl_GetReducedTransparencyMode(); + nNewMode = nOldMode + 1; + impl_SetReducedTransparencyMode(nNewMode); + nNewMode = aPrintOpt.GetReducedTransparencyMode(); + //if(nNewMode != nOldMode) // test the old source + if(nNewMode == nOldMode) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the IsReducedTransparencyMode() error!" + "nOldMode's value is :"), + 0); + } + + // test the SetReduceGradients() + bNewValue = bOldValue = sal_False; + bOldValue = impl_IsReduceGradients(); + bNewValue = !bOldValue; + aPrintOpt.SetReduceGradients(bNewValue); + bNewValue = impl_IsReduceGradients(); + //if (bNewValue != bOldValue) //test the old source + if (bNewValue == bOldValue) //test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetReduceGradients() error!"), + 0); + + } + + // test the IsReduceGradients() + bNewValue = bOldValue = sal_False; + bOldValue = impl_IsReduceGradients(); + bNewValue = !bOldValue; + this->impl_SetReduceGradients(bNewValue); + bNewValue = aPrintOpt.IsReduceGradients(); + // if (bNewValue != bOldValue) // test the old source + if (bNewValue == bOldValue) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the IsReduceGradients() error!"), + 0); + + } + + //test SetRedecedGradientMode() + nOldMode = nNewMode = 0; + nOldMode = this->impl_GetReducedGradientMode(); + nNewMode = nOldMode + 1; + aPrintOpt.SetReducedGradientMode(nNewMode); + nNewMode = this->impl_GetReducedGradientMode(); + //if (nNewMode != nOldMode) // test the old source + if (nNewMode == nOldMode)// test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetRedecedGradientMode() error!"), + 0); + } + + // test GetReducedGradientMode() + nOldMode = nNewMode = 0; + nOldMode = this->impl_GetReducedGradientMode(); + nNewMode = nOldMode + 1; + this->impl_SetReducedGradientMode(nNewMode); + nNewMode = aPrintOpt.GetReducedGradientMode(); + //if (nNewMode != nOldMode) // test the old source + if (nNewMode == nOldMode) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the GetReducedGradientMode() error!"), + 0); + + } + + //test the SetReducedGradientStepCount() + sal_Int16 nNewStepCount; + sal_Int16 nOldStepCount; + nNewStepCount = nOldStepCount = 0; + nOldStepCount = this->impl_GetReducedGradientStepCount(); + nNewStepCount = nOldStepCount + 1; + aPrintOpt.SetReducedGradientStepCount(nNewStepCount); + nNewStepCount = this->impl_GetReducedGradientStepCount(); + // if (nNewStepCount != nOldStepCount) // test the old source + if (nNewStepCount == nOldStepCount) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetReducedGradientStepCount() error!"), + 0); + + } + + // test the GetReduceGradientStepCount() + nNewStepCount = nOldStepCount = 0; + nOldStepCount = this->impl_GetReducedGradientStepCount(); + nNewStepCount = nOldStepCount + 1; + this->impl_SetReducedGradientStepCount(nNewStepCount); + nNewStepCount = aPrintOpt.GetReducedGradientStepCount(); + // if (nNewStepCount != nOldStepCount) //test the old source + if (nNewStepCount == nOldStepCount) //test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the GetReduceGradientStepCount() error!"), + 0); + } + + // test the SetReduceBitmaps() + bNewValue = bOldValue = sal_False; + bOldValue = this->impl_IsReduceBitmaps(); + bNewValue = !bOldValue; + aPrintOpt.SetReduceBitmaps(bNewValue); + bNewValue = this->impl_IsReduceBitmaps(); + //if (bNewValue != bOldValue) // test the old source + if (bNewValue == bOldValue) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetReduceBitmaps() error!"), + 0); + } + + // test the IsReduceBitmaps() + bNewValue = bOldValue = sal_False; + bOldValue = this->impl_IsReduceBitmaps(); + bNewValue = !bOldValue; + this->impl_SetReduceBitmaps(bNewValue); + bNewValue = aPrintOpt.IsReduceBitmaps(); + //if (bNewValue != bOldValue) // test the old source + if (bNewValue == bOldValue) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the IsReduceBitmaps() error!"), + 0); + } + + // test the SetReduceBitmap() + nNewMode = nOldMode = 0; + nOldMode = impl_GetReducedBitmapMode(); + nNewMode = nOldMode + 1; + aPrintOpt.SetReducedBitmapMode(nNewMode); + nNewMode = impl_GetReducedBitmapMode(); + //if (nNewMode != nOldMode) // test the old source + if (nNewMode == nOldMode)// test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetReduceBitmap() error!"), + 0); + } + + // test the SetReduceBitmapMode() + nNewMode = nOldMode = 0; + nOldMode = this->impl_GetReducedBitmapMode(); + nNewMode = nOldMode + 1; + aPrintOpt.SetReducedBitmapMode(nNewMode); + nNewMode = this->impl_GetReducedBitmapMode(); + //if (nNewMode != nOldMode) // test the old source + if (nNewMode == nOldMode) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetReduceBitmapMode() error!"), + 0); + } + + // test the GetReduceBitmapMode() + nNewMode = nOldMode = 0; + nOldMode = this->impl_GetReducedBitmapMode(); + nNewMode = nOldMode + 1; + this->impl_SetReducedBitmapMode(nNewMode); + nNewMode = aPrintOpt.GetReducedBitmapMode(); + //if (nNewMode != nOldMode) // test the old source + if (nNewMode == nOldMode)// test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the GetReduceBitmapMode() error!"), + 0); + + } + + // test the SetReducedBitmapResolution() + sal_Int16 nOldResolution ; + sal_Int16 nNewResolution ; + nNewResolution = nOldResolution = 0; + nOldResolution = impl_GetReducedBitmapResolution(); + nNewResolution = nOldResolution + 1; + aPrintOpt.SetReducedBitmapResolution(nNewResolution); + nNewResolution = impl_GetReducedBitmapResolution(); + //if (nNewResolution != nOldResolution) // test the old source + if (nNewResolution == nOldResolution)// test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetReducedBitmapResolution() error!"), + 0); + } + + // test the GetReduceBitmapResolution() + nNewResolution = nOldResolution = 0; + nOldResolution = impl_GetReducedBitmapResolution(); + nNewResolution = nOldResolution + 1; + impl_SetReducedBitmapResolution(nNewResolution); + nNewResolution = impl_GetReducedBitmapResolution(); + //if (nNewResolution != nOldResolution) // test the old source + if (nNewResolution == nOldResolution) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the GetReduceBitmapResolution() error!"), + 0); + } + + // test SetReducedBitmapIncludesTransparency() + bNewValue = bOldValue = sal_False; + bOldValue = impl_IsReducedBitmapIncludesTransparency(); + bNewValue = !bOldValue; + aPrintOpt.SetReducedBitmapIncludesTransparency(bNewValue); + bNewValue = impl_IsReducedBitmapIncludesTransparency(); + //if (bNewValue != bOldValue) // test the new source + if (bNewValue == bOldValue) // test the old source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetReducedBitmapIncludesTransparency() error!"), + 0); + } + + // test the IsReducedBitmapIncludesTransparency() + bNewValue = bOldValue = sal_False; + bOldValue = impl_IsReducedBitmapIncludesTransparency(); + bNewValue = !bOldValue; + impl_SetReducedBitmapIncludesTransparency(bNewValue); + bNewValue = aPrintOpt.IsReducedBitmapIncludesTransparency(); + //if (bNewValue != bOldValue) // test the old source + if (bNewValue == bOldValue) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the IsReducedBitmapIncludesTransparency() error!"), + 0); + } + + // test the SetConvertToGreyscales() + bNewValue = bOldValue = sal_False; + bOldValue = this->impl_IsConvertToGreyscales(); + bNewValue = !bOldValue; + aPrintOpt.SetConvertToGreyscales(bNewValue); + bNewValue = this->impl_IsConvertToGreyscales(); + //if (bNewValue != bOldValue) // test the old source + if (bNewValue == bOldValue) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the SetConvertToGreyscales() error!"), + 0); + } + + // test the IsConvertToGreyscales() + bNewValue = bOldValue = sal_False; + bOldValue = this->impl_IsConvertToGreyscales(); + bNewValue = !bOldValue; + impl_SetConvertToGreyscales(bNewValue); + bNewValue = aPrintOpt.IsConvertToGreyscales(); + //if (bNewValue != bOldValue) // test the old source + if (bNewValue == bOldValue) // test the new source + { + throw css::uno::RuntimeException( + rtl::OUString::createFromAscii( + "null com.sun.star.configuration." + "the IsConvertToGreyscales() error!"), + 0); + } +} diff --git a/svl/qa/complex/ConfigItems/helper/PrintOptTest.hxx b/svl/qa/complex/ConfigItems/helper/PrintOptTest.hxx new file mode 100644 index 000000000000..14d4267b8878 --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/PrintOptTest.hxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: PrintOptTest.hxx,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:24 $ + * + * 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 + * + ************************************************************************/ + +#ifndef SVTOOLS_PRINTOPTTEST_HXX +#define SVTOOLS_PRINTOPTTEST_HXX + +#include <com/sun/star/container/XNameAccess.hpp> +#include <svtools/printoptions.hxx> + +namespace css = ::com::sun::star; + +class PrintOptTest +{ +public: + + PrintOptTest(); + ~PrintOptTest(); + + void impl_checkPrint(); + +private: //members + + SvtPrinterOptions aPrintOpt; + css::uno::Reference< css::container::XNameAccess > m_xCfg; + css::uno::Reference< css::container::XNameAccess > m_xNode; + +private: // methods + sal_Bool impl_IsReduceTransparency() const ; + void impl_SetReduceTransparency( sal_Bool bState ) ; + + sal_Int16 impl_GetReducedTransparencyMode() const ; + void impl_SetReducedTransparencyMode( sal_Int16 nMode ) ; + + sal_Bool impl_IsReduceGradients() const ; + void impl_SetReduceGradients( sal_Bool bState ) ; + + sal_Int16 impl_GetReducedGradientMode() const ; + void impl_SetReducedGradientMode( sal_Int16 nMode ) ; + + sal_Int16 impl_GetReducedGradientStepCount() const ; + void impl_SetReducedGradientStepCount( sal_Int16 nStepCount ); + + sal_Bool impl_IsReduceBitmaps() const ; + void impl_SetReduceBitmaps( sal_Bool bState ) ; + + sal_Int16 impl_GetReducedBitmapMode() const ; + void impl_SetReducedBitmapMode( sal_Int16 nMode ) ; + + sal_Int16 impl_GetReducedBitmapResolution() const ; + void impl_SetReducedBitmapResolution( sal_Int16 nResolution ) ; + + sal_Bool impl_IsReducedBitmapIncludesTransparency() const ; + void impl_SetReducedBitmapIncludesTransparency( sal_Bool bState ) ; + + sal_Bool impl_IsConvertToGreyscales() const; + void impl_SetConvertToGreyscales( sal_Bool bState ) ; + +}; + +#endif // #ifndef SVTOOLS_PRINTOPTTEST_HXX diff --git a/svl/qa/complex/ConfigItems/helper/UserOptTest.cxx b/svl/qa/complex/ConfigItems/helper/UserOptTest.cxx new file mode 100644 index 000000000000..14ee513ee0cb --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/UserOptTest.cxx @@ -0,0 +1,274 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: UserOptTest.cxx,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:24 $ + * + * 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 "UserOptTest.hxx" + +namespace css = ::com::sun::star; + +//============================================================================= +static const ::rtl::OUString MESSAGE_SETCOMPANY_FAILED = ::rtl::OUString::createFromAscii("set company failed") ; +static const ::rtl::OUString MESSAGE_SETFIRSTNAME_FAILED = ::rtl::OUString::createFromAscii("set firstname failed") ; +static const ::rtl::OUString MESSAGE_SETLASTNAME_FAILED = ::rtl::OUString::createFromAscii("set lastname failed") ; +static const ::rtl::OUString MESSAGE_SETID_FAILED = ::rtl::OUString::createFromAscii("set ID failed") ; +static const ::rtl::OUString MESSAGE_SETSTREET_FAILED = ::rtl::OUString::createFromAscii("set street failed") ; +static const ::rtl::OUString MESSAGE_SETCITY_FAILED = ::rtl::OUString::createFromAscii("set city failed") ; +static const ::rtl::OUString MESSAGE_SETSTATE_FAILED = ::rtl::OUString::createFromAscii("set state failed") ; +static const ::rtl::OUString MESSAGE_SETZIP_FAILED = ::rtl::OUString::createFromAscii("set zip failed") ; +static const ::rtl::OUString MESSAGE_SETCOUNTRY_FAILED = ::rtl::OUString::createFromAscii("set country failed") ; +static const ::rtl::OUString MESSAGE_SETPOSITION_FAILED = ::rtl::OUString::createFromAscii("set position failed") ; +static const ::rtl::OUString MESSAGE_SETTITLE_FAILED = ::rtl::OUString::createFromAscii("set title failed") ; +static const ::rtl::OUString MESSAGE_SETTELEPHONEHOME_FAILED = ::rtl::OUString::createFromAscii("set telephonehome failed") ; +static const ::rtl::OUString MESSAGE_SETTELEPHONEWORK_FAILED = ::rtl::OUString::createFromAscii("set telephonework failed") ; +static const ::rtl::OUString MESSAGE_SETFAX_FAILED = ::rtl::OUString::createFromAscii("set fax failed") ; +static const ::rtl::OUString MESSAGE_SETEMAIL_FAILED = ::rtl::OUString::createFromAscii("set email failed") ; +static const ::rtl::OUString MESSAGE_SETCUSTOMERNUMBER_FAILED = ::rtl::OUString::createFromAscii("set customernumber failed"); +static const ::rtl::OUString MESSAGE_SETFATHERSNAME_FAILED = ::rtl::OUString::createFromAscii("set fathersname failed") ; +static const ::rtl::OUString MESSAGE_SETAPARTMENT_FAILED = ::rtl::OUString::createFromAscii("set apartment failed") ; + +//============================================================================= + + +UserOptTest::UserOptTest() + :m_aConfigItem() + ,m_xCfg() +{ +} + +UserOptTest::~UserOptTest() +{ +} + +void UserOptTest::impl_checkUserData() +{ + impl_checkSetCompany( ::rtl::OUString() ); + impl_checkSetFirstName( ::rtl::OUString() ); + impl_checkSetLastName( ::rtl::OUString() ); + impl_checkSetID( ::rtl::OUString() ); + impl_checkSetStreet( ::rtl::OUString() ); + impl_checkSetCity( ::rtl::OUString() ); + impl_checkSetState( ::rtl::OUString() ); + impl_checkSetZip( ::rtl::OUString() ); + impl_checkSetCountry( ::rtl::OUString() ); + impl_checkSetPosition( ::rtl::OUString() ); + impl_checkSetTitle( ::rtl::OUString() ); + impl_checkSetTelephoneHome( ::rtl::OUString() ); + impl_checkSetTelephoneWork( ::rtl::OUString() ); + impl_checkSetFax( ::rtl::OUString() ); + impl_checkSetEmail( ::rtl::OUString() ); + //impl_checkSetCustomerNumber( ::rtl::OUString() ); + impl_checkSetFathersName( ::rtl::OUString() ); + impl_checkSetApartment( ::rtl::OUString() ); + + impl_checkSetCompany( ::rtl::OUString::createFromAscii("RedFlag2000") ); + impl_checkSetFirstName( ::rtl::OUString::createFromAscii("Yan") ); + impl_checkSetLastName( ::rtl::OUString::createFromAscii("Wu") ); + impl_checkSetID( ::rtl::OUString::createFromAscii("wuy") ); + impl_checkSetStreet( ::rtl::OUString::createFromAscii("SouthFifthRing") ); + impl_checkSetCity( ::rtl::OUString::createFromAscii("Beijing") ); + impl_checkSetState( ::rtl::OUString::createFromAscii("Beijing") ); + impl_checkSetZip( ::rtl::OUString::createFromAscii("100176") ); + impl_checkSetCountry( ::rtl::OUString::createFromAscii("China") ); + impl_checkSetPosition( ::rtl::OUString::createFromAscii("Engineer") ); + impl_checkSetTitle( ::rtl::OUString::createFromAscii("Software Engineer") ); + impl_checkSetTelephoneHome( ::rtl::OUString::createFromAscii("010-51570010") ); + impl_checkSetTelephoneWork( ::rtl::OUString::createFromAscii("010-51570010") ); + impl_checkSetFax( ::rtl::OUString::createFromAscii("010-51570010") ); + impl_checkSetEmail( ::rtl::OUString::createFromAscii("wuy@redflag2000.cn") ); + //impl_checkSetCustomerNumber( ::rtl::OUString::createFromAscii("87654321") ); + impl_checkSetFathersName( ::rtl::OUString::createFromAscii("father") ); + impl_checkSetApartment( ::rtl::OUString::createFromAscii("apartment") ); +} + +void UserOptTest::impl_checkSetCompany( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetCompany( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetCompany(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETCOMPANY_FAILED, 0); +} + +void UserOptTest::impl_checkSetFirstName( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetFirstName( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetFirstName(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETFIRSTNAME_FAILED, 0); +} + +void UserOptTest::impl_checkSetLastName( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetLastName( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetLastName(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETLASTNAME_FAILED, 0); +} + +void UserOptTest::impl_checkSetID( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetID( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetID(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETID_FAILED, 0); +} + +void UserOptTest::impl_checkSetStreet( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetStreet( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetStreet(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETSTREET_FAILED, 0); +} + +void UserOptTest::impl_checkSetCity( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetCity( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetCity(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETCITY_FAILED, 0); +} + +void UserOptTest::impl_checkSetState( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetState( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetState(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETSTATE_FAILED, 0); +} + +void UserOptTest::impl_checkSetZip( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetZip( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetZip(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETZIP_FAILED, 0); +} + +void UserOptTest::impl_checkSetCountry( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetCountry( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetCountry(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETCOUNTRY_FAILED, 0); +} + +void UserOptTest::impl_checkSetPosition( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetPosition( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetPosition(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETPOSITION_FAILED, 0); +} + +void UserOptTest::impl_checkSetTitle( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetTitle( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetTitle(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETTITLE_FAILED, 0); +} + +void UserOptTest::impl_checkSetTelephoneHome( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetTelephoneHome( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetTelephoneHome(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETTELEPHONEHOME_FAILED, 0); +} + +void UserOptTest::impl_checkSetTelephoneWork( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetTelephoneWork( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetTelephoneWork(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETTELEPHONEWORK_FAILED, 0); +} + +void UserOptTest::impl_checkSetFax( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetFax( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetFax(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETFAX_FAILED, 0); +} + +void UserOptTest::impl_checkSetEmail( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetEmail( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetEmail(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETEMAIL_FAILED, 0); +} + +void UserOptTest::impl_checkSetCustomerNumber( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetCustomerNumber( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetCustomerNumber(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETCUSTOMERNUMBER_FAILED, 0); +} + +void UserOptTest::impl_checkSetFathersName( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetFathersName( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetFathersName(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETFATHERSNAME_FAILED, 0); +} + +void UserOptTest::impl_checkSetApartment( const ::rtl::OUString& sUserData ) +{ + m_aConfigItem.SetApartment( sUserData ); + + ::rtl::OUString sCheck = m_aConfigItem.GetApartment(); + if ( sCheck != sUserData ) + throw css::uno::Exception(MESSAGE_SETAPARTMENT_FAILED, 0); +} diff --git a/svl/qa/complex/ConfigItems/helper/UserOptTest.hxx b/svl/qa/complex/ConfigItems/helper/UserOptTest.hxx new file mode 100644 index 000000000000..72ff71cafe2d --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/UserOptTest.hxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: UserOptTest.hxx,v $ + * + * $Revision: 1.1.4.2 $ + * + * last change: $Author: as $ $Date: 2008/03/19 11:09:25 $ + * + * 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 + * + ************************************************************************/ + +#ifndef SVTOOLS_USEROPTTEST_HXX +#define SVTOOLS_USEROPTTEST_HXX + +#include <com/sun/star/container/XNameAccess.hpp> +#include <unotools/useroptions.hxx> + +namespace css = ::com::sun::star; + +class UserOptTest +{ +public: + UserOptTest(); + ~UserOptTest(); + + void impl_checkUserData(); + +private: + void impl_checkSetCompany( const ::rtl::OUString& sUserData ); + void impl_checkSetFirstName( const ::rtl::OUString& sUserData ); + void impl_checkSetLastName( const ::rtl::OUString& sUserData ); + void impl_checkSetID( const ::rtl::OUString& sUserData ); + void impl_checkSetStreet( const ::rtl::OUString& sUserData ); + void impl_checkSetCity( const ::rtl::OUString& sUserData ); + void impl_checkSetState( const ::rtl::OUString& sUserData ); + void impl_checkSetZip( const ::rtl::OUString& sUserData ); + void impl_checkSetCountry( const ::rtl::OUString& sUserData ); + void impl_checkSetPosition( const ::rtl::OUString& sUserData ); + void impl_checkSetTitle( const ::rtl::OUString& sUserData ); + void impl_checkSetTelephoneHome( const ::rtl::OUString& sUserData ); + void impl_checkSetTelephoneWork( const ::rtl::OUString& sUserData ); + void impl_checkSetFax( const ::rtl::OUString& sUserData ); + void impl_checkSetEmail( const ::rtl::OUString& sUserData ); + void impl_checkSetCustomerNumber( const ::rtl::OUString& sUserData ); + void impl_checkSetFathersName( const ::rtl::OUString& sUserData ); + void impl_checkSetApartment( const ::rtl::OUString& sUserData ); + +private: + SvtUserOptions m_aConfigItem; + + css::uno::Reference< css::container::XNameAccess > m_xCfg; +}; + +#endif // #ifndef SVTOOLS_USEROPTTEST_HXX diff --git a/svl/qa/complex/ConfigItems/helper/exports.map b/svl/qa/complex/ConfigItems/helper/exports.map new file mode 100644 index 000000000000..85610ad80888 --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/exports.map @@ -0,0 +1,10 @@ +UDK_3_0_0 { + global: + GetVersionInfo; + component_getImplementationEnvironment; + component_getFactory; + component_writeInfo; + + local: + *; +}; diff --git a/svl/qa/complex/ConfigItems/helper/makefile.mk b/svl/qa/complex/ConfigItems/helper/makefile.mk new file mode 100644 index 000000000000..6070d25b7bd4 --- /dev/null +++ b/svl/qa/complex/ConfigItems/helper/makefile.mk @@ -0,0 +1,81 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.4.2 $ +# +# last change: $Author: as $ $Date: 2008/03/19 11:09:25 $ +# +# 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 ----------------------------------------------------- + +INCPOST += $(PRJ)$/source$/inc + +# --- light services library ---------------------------------------------------- + +SHL1TARGET= svt_$(TARGET) + +SHL1OBJS= \ + $(SLO)$/UserOptTest.obj \ + $(SLO)$/PrintOptTest.obj \ + $(SLO)$/AccessibilityOptTest.obj \ + $(SLO)$/HistoryOptTest.obj \ + $(SLO)$/ConfigItemTest.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 + diff --git a/svl/qa/complex/ConfigItems/makefile.mk b/svl/qa/complex/ConfigItems/makefile.mk new file mode 100644 index 000000000000..f85c5b0a8e65 --- /dev/null +++ b/svl/qa/complex/ConfigItems/makefile.mk @@ -0,0 +1,91 @@ +#************************************************************************* +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.4.2 $ +# +# last change: $Author: as $ $Date: 2008/03/19 11:09:22 $ +# +# 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 = ..$/..$/.. +TARGET = CheckConfigItems +PRJNAME = svtools +PACKAGE = complex$/ConfigItems + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = mysql.jar ridl.jar unoil.jar jurt.jar juh.jar jut.jar java_uno.jar \ + OOoRunner.jar + +JAVAFILES = CheckConfigItems.java + +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +SUBDIRS = helper + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +# --- Parameters for the test -------------------------------------- + +# start an office if the parameter is set for the makefile +.IF "$(OFFICE)" == "" +CT_APPEXECCOMMAND = +.ELSE +CT_APPEXECCOMMAND = -AppExecutionCommand "$(OFFICE)$/soffice -accept=socket,host=localhost,port=8100;urp;" +.ENDIF + +# test base is java complex +CT_TESTBASE = -TestBase java_complex + +# test looks something like the.full.package.TestName +CT_TEST = -o $(PACKAGE:s\$/\.\).$(JAVAFILES:b) + +# start the runner application +CT_APP = org.openoffice.Runner + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + +RUN: run + +run: + java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_APPEXECCOMMAND) $(CT_TEST) + + + diff --git a/svl/qa/complex/passwordcontainer/MasterPasswdHandler.java b/svl/qa/complex/passwordcontainer/MasterPasswdHandler.java new file mode 100644 index 000000000000..bf6159ee38c5 --- /dev/null +++ b/svl/qa/complex/passwordcontainer/MasterPasswdHandler.java @@ -0,0 +1,61 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +/** + * + * @author zxf + */ + +package complex.passwordcontainer; + +import com.sun.star.lib.uno.helper.WeakBase; +import com.sun.star.task.XInteractionContinuation; +import com.sun.star.ucb.XInteractionSupplyAuthentication; +import com.sun.star.task.XInteractionRequest; +import com.sun.star.task.XInteractionHandler; +import com.sun.star.task.MasterPasswordRequest; +import com.sun.star.uno.UnoRuntime; + +public class MasterPasswdHandler extends WeakBase + implements XInteractionHandler { + XInteractionHandler m_xHandler; + + public MasterPasswdHandler( XInteractionHandler xHandler ) { + m_xHandler = xHandler; + } + + public void handle( XInteractionRequest xRequest ) { + try { + MasterPasswordRequest aMasterPasswordRequest; + if( xRequest.getRequest() instanceof MasterPasswordRequest ) { + aMasterPasswordRequest = (MasterPasswordRequest)xRequest.getRequest(); + if( aMasterPasswordRequest != null ) { + XInteractionContinuation xContinuations[] = xRequest.getContinuations(); + XInteractionSupplyAuthentication xAuthentication = null; + + for( int i = 0; i < xContinuations.length; ++i ) { + xAuthentication = (XInteractionSupplyAuthentication)UnoRuntime.queryInterface( XInteractionSupplyAuthentication.class, xContinuations[i]); + if( xAuthentication != null ) + break; + } + if( xAuthentication.canSetPassword() ) + xAuthentication.setPassword( "abcdefghijklmnopqrstuvwxyz123456" ); + xAuthentication.select(); + } + } else { + m_xHandler.handle( xRequest ); + } + } catch( Exception e ) { + System.out.println( "MasterPasswordHandler Error: " + e ); + } + } +} + + + + + + + diff --git a/svl/qa/complex/passwordcontainer/PasswordContainerTest.java b/svl/qa/complex/passwordcontainer/PasswordContainerTest.java new file mode 100644 index 000000000000..5da0676f8bb9 --- /dev/null +++ b/svl/qa/complex/passwordcontainer/PasswordContainerTest.java @@ -0,0 +1,36 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: PasswordContainerTest.java,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.passwordcontainer; + +public interface PasswordContainerTest { + boolean test(); +} diff --git a/svl/qa/complex/passwordcontainer/PasswordContainerUnitTest.java b/svl/qa/complex/passwordcontainer/PasswordContainerUnitTest.java new file mode 100644 index 000000000000..aee1c9355a3f --- /dev/null +++ b/svl/qa/complex/passwordcontainer/PasswordContainerUnitTest.java @@ -0,0 +1,77 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: PasswordContainerUnitTest.java,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.passwordcontainer; + +import complexlib.ComplexTestCase; +import com.sun.star.lang.XMultiServiceFactory; + +public class PasswordContainerUnitTest extends ComplexTestCase { + private XMultiServiceFactory m_xMSF = null; + + public String[] getTestMethodNames() { + return new String[] { + "ExecuteTest01", + "ExecuteTest02", + "ExecuteTest03"}; + } + public String getTestObjectName() { + return "PasswordContainerUnitTest"; + } + + public void before() { + try { + m_xMSF = (XMultiServiceFactory) param.getMSF(); + } catch (Exception e) { + failed ("Cannot create service factory!"); + } + if (m_xMSF == null) { + failed ("Cannot create service factory!"); + } + } + + public void after() { + m_xMSF = null; + } + + public void ExecuteTest01() { + PasswordContainerTest aTest = new Test01(m_xMSF, log); + assure("Test01 failed!", aTest.test()); + } + public void ExecuteTest02() { + PasswordContainerTest aTest = new Test02(m_xMSF, log); + assure("Test02 failed!", aTest.test()); + } + public void ExecuteTest03() { + PasswordContainerTest aTest = new Test03(m_xMSF, log); + assure("Test03 failed!", aTest.test()); + } +} diff --git a/svl/qa/complex/passwordcontainer/Test01.java b/svl/qa/complex/passwordcontainer/Test01.java new file mode 100644 index 000000000000..6de96de05ec9 --- /dev/null +++ b/svl/qa/complex/passwordcontainer/Test01.java @@ -0,0 +1,115 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: Test01.java,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.passwordcontainer; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.task.XInteractionHandler; +import com.sun.star.task.XPasswordContainer; +import com.sun.star.task.UrlRecord; +import com.sun.star.task.UserRecord; +import com.sun.star.task.XMasterPasswordHandling; + +import com.sun.star.uno.UnoRuntime; + +import share.LogWriter; + +public class Test01 implements PasswordContainerTest { + XMultiServiceFactory m_xMSF = null; + XPasswordContainer m_xPasswordContainer = null; + TestHelper m_aTestHelper = null; + + public Test01 ( XMultiServiceFactory xMSF, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_aTestHelper = new TestHelper (aLogWriter, "Test01: "); + } + + public boolean test() { + final String sURL = "http://www.openoffice.org"; + final String sUserPre = "OOoUser"; + final String sPwdPre = "Password"; + final int iUserNum1 = 10; + final int iUserNum2 = 5; + + UserRecord aInputUserList1[] = new UserRecord[iUserNum1]; + for(int i = 0; i < iUserNum1; i++) { + String sTemp[] = {sPwdPre + "_1_" + i}; // currently one password for one user + aInputUserList1[i] = new UserRecord(sUserPre + "_1_" + i, sTemp); + } + UserRecord aInputUserList2[] = new UserRecord[iUserNum2]; + for(int i = 0; i < iUserNum2; i++) { + String sTemp[] = {sPwdPre + "_2_" + i}; + aInputUserList2[i] = new UserRecord(sUserPre + "_2_" + i, sTemp); + } + try { + Object oPasswordContainer = m_xMSF.createInstance( "com.sun.star.task.PasswordContainer" ); + XPasswordContainer xContainer = (XPasswordContainer)UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer); + Object oHandler = m_xMSF.createInstance( "com.sun.star.task.InteractionHandler" ); + XInteractionHandler xHandler = (XInteractionHandler)UnoRuntime.queryInterface(XInteractionHandler.class, oHandler); + MasterPasswdHandler aMHandler = new MasterPasswdHandler( xHandler ); + + // add a set of users and passwords for the same URL for runtime + for(int i = 0; i < iUserNum1; i++) { + xContainer.add(sURL, aInputUserList1[i].UserName, aInputUserList1[i].Passwords, aMHandler); + } + for (int i = 0; i < iUserNum2; i++) { + xContainer.add(sURL, aInputUserList2[i].UserName, aInputUserList2[i].Passwords, aMHandler); + } + + // remove some of the passwords + for (int i = 0; i < iUserNum1; i++) { + xContainer.remove(sURL, aInputUserList1[i].UserName); + } + + // get the result and check it with the expected one + UrlRecord aRecord = xContainer.find(sURL, aMHandler); + if(!aRecord.Url.equals(sURL)) { + m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL); + return false; + } + if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList2)) { + m_aTestHelper.Error("User list is not the expected"); + return false; + } + + // remove the runtime passwords + aRecord = xContainer.find(sURL, aMHandler); + for(int i = 0; i < aRecord.UserList.length; i++) { + xContainer.remove(sURL, aRecord.UserList[i].UserName); + } + } catch(Exception e) { + m_aTestHelper.Error("Exception: " + e); + return false; + } + return true; + } +} diff --git a/svl/qa/complex/passwordcontainer/Test02.java b/svl/qa/complex/passwordcontainer/Test02.java new file mode 100644 index 000000000000..5d65d8090cf9 --- /dev/null +++ b/svl/qa/complex/passwordcontainer/Test02.java @@ -0,0 +1,159 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: Test02.java,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.passwordcontainer; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.task.XPasswordContainer; +import com.sun.star.task.XMasterPasswordHandling; +import com.sun.star.task.XInteractionHandler; +import com.sun.star.task.UrlRecord; +import com.sun.star.task.UserRecord; + +import com.sun.star.uno.UnoRuntime; + +import share.LogWriter; + +public class Test02 implements PasswordContainerTest { + XMultiServiceFactory m_xMSF = null; + XPasswordContainer m_xPasswordContainer = null; + TestHelper m_aTestHelper = null; + + public Test02 ( XMultiServiceFactory xMSF, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_aTestHelper = new TestHelper (aLogWriter, "Test02: "); + } + + public boolean test() { + final String sURL = "http://www.openoffice.org"; + final String sUserPre = "OOoUser"; + final String sPwdPre = "Password"; + final int iUserNum1 = 10; + final int iUserNum2 = 5; + + UserRecord aInputUserList1[] = new UserRecord[iUserNum1]; + for(int i = 0; i < iUserNum1; i++) { + String sTemp[] = {sPwdPre + "_1_" + i}; // currently one password for one user + aInputUserList1[i] = new UserRecord(sUserPre + "_1_" + i, sTemp); + } + UserRecord aInputUserList2[] = new UserRecord[iUserNum2]; + for(int i = 0; i < iUserNum2; i++) { + String sTemp[] = {sPwdPre + "_2_" + i}; + aInputUserList2[i] = new UserRecord(sUserPre + "_2_" + i, sTemp); + } + + try { + Object oPasswordContainer = m_xMSF.createInstance("com.sun.star.task.PasswordContainer"); + XPasswordContainer xContainer = (XPasswordContainer)UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer); + Object oHandler = m_xMSF.createInstance("com.sun.star.task.InteractionHandler"); + XInteractionHandler xHandler = (XInteractionHandler)UnoRuntime.queryInterface(XInteractionHandler.class, oHandler); + MasterPasswdHandler aMHandler = new MasterPasswdHandler(xHandler); + XMasterPasswordHandling xMHandling = (XMasterPasswordHandling)UnoRuntime.queryInterface(XMasterPasswordHandling.class, oPasswordContainer); + + // allow the storing of the passwords + xMHandling.allowPersistentStoring(true); + + // add a set of users and passwords for the same URL persistently + for(int i = 0; i < iUserNum1; ++i) { + xContainer.addPersistent(sURL, aInputUserList1[i].UserName, aInputUserList1[i].Passwords, aMHandler); + } + for(int i = 0; i < iUserNum2; ++i) { + xContainer.addPersistent(sURL, aInputUserList2[i].UserName, aInputUserList2[i].Passwords, aMHandler); + } + + // remove some of the passwords + for(int i = 0; i < iUserNum1; ++i) { + xContainer.remove(sURL, aInputUserList1[i].UserName); + } + + // get the result with find() and check it with the expected one + UrlRecord aRecord = xContainer.find(sURL, aMHandler); + if(!aRecord.Url.equals(sURL)) { + m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL); + return false; + } + if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList2)) { + m_aTestHelper.Error("User list is not the expected"); + return false; + } + + // get the result with getAllPersistent() and check + UrlRecord aRecords[] = xContainer.getAllPersistent(aMHandler); + if(!aRecords[0].Url.equals(sURL)) { + m_aTestHelper.Error("URL mismatch"); + return false; + } + if(!m_aTestHelper.sameLists(aRecords[0].UserList, aInputUserList2)) { + m_aTestHelper.Error("User list is not the expected"); + return false; + } + + // remove all the persistent passwords + xContainer.removeAllPersistent(); + + // remove the runtime passwords + for(int i = 0; i < aRecords[0].UserList.length; ++i) { + xContainer.remove(sURL, aRecords[0].UserList[i].UserName); + } + + // disallow the storing of the passwords + xMHandling.allowPersistentStoring(false); + } catch(Exception e) { + m_aTestHelper.Error("Exception: " + e); + return false; + } + return true; + } +} + + + + + + + + + + + + + + + + + + + + + + + diff --git a/svl/qa/complex/passwordcontainer/Test03.java b/svl/qa/complex/passwordcontainer/Test03.java new file mode 100644 index 000000000000..69de8b88578b --- /dev/null +++ b/svl/qa/complex/passwordcontainer/Test03.java @@ -0,0 +1,122 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: Test03.java,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.passwordcontainer; + +import com.sun.star.lang.XMultiServiceFactory; +import com.sun.star.task.UrlRecord; +import com.sun.star.task.UserRecord; +import com.sun.star.task.XPasswordContainer; +import com.sun.star.task.XMasterPasswordHandling; +import com.sun.star.task.XInteractionHandler; + + +import com.sun.star.uno.UnoRuntime; +import share.LogWriter; + +public class Test03 implements PasswordContainerTest { + XMultiServiceFactory m_xMSF = null; + XPasswordContainer m_xPasswordContainer = null; + TestHelper m_aTestHelper = null; + + public Test03 ( XMultiServiceFactory xMSF, LogWriter aLogWriter ) + { + m_xMSF = xMSF; + m_aTestHelper = new TestHelper (aLogWriter, "Test03: "); + } + + public boolean test() { + final String sURL = "http://www.openoffice.org"; + final String sUserPre = "OOoUser"; + final String sPwdPre = "Password"; + final int iPersistentUserNum = 10; + final int iRuntimeUserNum = 5; + + UserRecord aInputUserList[] = new UserRecord[iPersistentUserNum+iRuntimeUserNum]; + for(int i = 0; i < iPersistentUserNum; i++) { + String sTemp[] = {sPwdPre + "_1_" + i}; // currently one password for one user + aInputUserList[i] = new UserRecord(sUserPre + "_1_" + i, sTemp); + } + for(int i = 0; i < iRuntimeUserNum; i++) { + String sTemp[] = {sPwdPre + "_2_" + i}; + aInputUserList[i+iPersistentUserNum] = new UserRecord(sUserPre + "_2_" + i, sTemp); + } + + try { + Object oPasswordContainer = m_xMSF.createInstance("com.sun.star.task.PasswordContainer"); + XPasswordContainer xContainer = (XPasswordContainer)UnoRuntime.queryInterface(XPasswordContainer.class, oPasswordContainer); + Object oHandler = m_xMSF.createInstance("com.sun.star.task.InteractionHandler"); + XInteractionHandler xHandler = (XInteractionHandler)UnoRuntime.queryInterface(XInteractionHandler.class, oHandler); + MasterPasswdHandler aMHandler = new MasterPasswdHandler(xHandler); + XMasterPasswordHandling xMHandling = (XMasterPasswordHandling)UnoRuntime.queryInterface(XMasterPasswordHandling.class, oPasswordContainer); + + // allow the storing of the passwords + xMHandling.allowPersistentStoring(true); + + // add a set of users and passwords for the same URL persistently + for(int i = 0; i < iPersistentUserNum; i++) { + xContainer.addPersistent(sURL, aInputUserList[i].UserName, aInputUserList[i].Passwords, aMHandler); + } + + // add a set of users and passwords for the same URL for runtime + for(int i = 0; i < iRuntimeUserNum; i++) { + xContainer.add(sURL, aInputUserList[i+iPersistentUserNum].UserName, aInputUserList[i+iPersistentUserNum].Passwords, aMHandler); + } + + // get the result for the URL and check that it contains persistent and runtime passwords + UrlRecord aRecord = xContainer.find(sURL, aMHandler); + if(!aRecord.Url.equals(sURL)) { + m_aTestHelper.Error("URL mismatch. Got " + aRecord.Url + "; should be " + sURL); + return false; + } + if(!m_aTestHelper.sameLists(aRecord.UserList, aInputUserList)) { + m_aTestHelper.Error("User list is not the expected"); + return false; + } + + // remove all the persistent passwords + xContainer.removeAllPersistent(); + + // remove the runtime passwords + aRecord = xContainer.find(sURL, aMHandler); + for(int i = 0; i < aRecord.UserList.length; i++) { + xContainer.remove(sURL, aRecord.UserList[i].UserName); + } + + // disallow the storing of the passwords + xMHandling.allowPersistentStoring(false); + }catch(Exception e){ + m_aTestHelper.Error("Exception: " + e); + return false; + } + return true; + } +} diff --git a/svl/qa/complex/passwordcontainer/TestHelper.java b/svl/qa/complex/passwordcontainer/TestHelper.java new file mode 100644 index 000000000000..0f83a9ef9963 --- /dev/null +++ b/svl/qa/complex/passwordcontainer/TestHelper.java @@ -0,0 +1,92 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: TestHelper.java,v $ + * + * $Revision: 1.2 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +package complex.passwordcontainer; + +import com.sun.star.task.UserRecord; + +import share.LogWriter; + +public class TestHelper { + LogWriter m_aLogWriter; + String m_sTestPrefix; + + public TestHelper( LogWriter aLogWriter, String sTestPrefix ) { + m_aLogWriter = aLogWriter; + m_sTestPrefix = sTestPrefix; + } + + public void Error( String sError ) { + m_aLogWriter.println( m_sTestPrefix + "Error: " + sError ); + } + + public void Message( String sMessage ) { + m_aLogWriter.println( m_sTestPrefix + sMessage ); + } + + public boolean sameLists(UserRecord aUserList1[], UserRecord aUserList2[]) { + // only works when every name is unique within the list containing it + + if(aUserList1.length != aUserList2.length) { + Message("User list lengths: " + aUserList1.length + " <--> " + aUserList2.length + " respectively "); + return false; + } + + for(int i = 0; i < aUserList1.length; i++) { + int j; + for(j = 0; j < aUserList2.length; j++) { + if(!aUserList1[i].UserName.equals(aUserList2[j].UserName)) + continue; + if(aUserList1[i].Passwords[0].equals(aUserList2[j].Passwords[0])) { + break; + } + } + if(j == aUserList2.length) { + for(int k = 0; k < aUserList1.length; k++) { + Message(aUserList1[k].UserName + " <--> " + aUserList2[i].UserName); + } + return false; + } + } + return true; + } +} + + + + + + + + + + + diff --git a/svl/qa/complex/passwordcontainer/makefile.mk b/svl/qa/complex/passwordcontainer/makefile.mk new file mode 100644 index 000000000000..4ce811bd3616 --- /dev/null +++ b/svl/qa/complex/passwordcontainer/makefile.mk @@ -0,0 +1,91 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.2.38.1 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ = ..$/..$/.. +TARGET = PasswordContainerUnitTest +PRJNAME = svtools +PACKAGE = complex$/passwordcontainer + +# --- Settings ----------------------------------------------------- +.INCLUDE: settings.mk + + +#----- compile .java files ----------------------------------------- + +JARFILES = ridl.jar unoil.jar jurt.jar juh.jar java_uno.jar OOoRunner.jar + +JAVAFILES =\ + PasswordContainerUnitTest.java\ + PasswordContainerTest.java\ + TestHelper.java\ + Test01.java\ + Test02.java\ + Test03.java\ + MasterPasswdHandler.java + +JAVACLASSFILES = $(foreach,i,$(JAVAFILES) $(CLASSDIR)$/$(PACKAGE)$/$(i:b).class) + +#----- make a jar from compiled files ------------------------------ + +MAXLINELENGTH = 100000 + +JARCLASSDIRS = $(PACKAGE) +JARTARGET = $(TARGET).jar +JARCOMPRESS = TRUE + +# --- Parameters for the test -------------------------------------- + +# start an office if the parameter is set for the makefile +.IF "$(OFFICE)" == "" +CT_APPEXECCOMMAND = +.ELSE +CT_APPEXECCOMMAND = -AppExecutionCommand "$(OFFICE)$/soffice -accept=socket,host=localhost,port=8100;urp;" +.ENDIF + +# test base is java complex +CT_TESTBASE = -TestBase java_complex + +# test looks something like the.full.package.TestName +CT_TEST = -o $(PACKAGE:s\$/\.\).$(JAVAFILES:b) + +# start the runner application +CT_APP = org.openoffice.Runner + +# --- Targets ------------------------------------------------------ + +.INCLUDE: target.mk + +RUN: run + +run: + +java -cp $(CLASSPATH) $(CT_APP) $(CT_TESTBASE) $(CT_APPEXECCOMMAND) $(CT_TEST) + + diff --git a/svl/qa/export.map b/svl/qa/export.map new file mode 100755 index 000000000000..80373c145ac1 --- /dev/null +++ b/svl/qa/export.map @@ -0,0 +1,38 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: export.map,v $ +# +# $Revision: 1.4 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +UDK_3_0_0 { + global: + registerAllTestFunction; + + local: + *; +}; diff --git a/svl/qa/makefile.mk b/svl/qa/makefile.mk new file mode 100644 index 000000000000..c56dc2804a64 --- /dev/null +++ b/svl/qa/makefile.mk @@ -0,0 +1,103 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2008 by Sun Microsystems, Inc. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.5 $ +# +# This file is part of OpenOffice.org. +# +# OpenOffice.org is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License version 3 +# only, as published by the Free Software Foundation. +# +# OpenOffice.org 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 version 3 for more details +# (a copy is included in the LICENSE file that accompanied this code). +# +# You should have received a copy of the GNU Lesser General Public License +# version 3 along with OpenOffice.org. If not, see +# <http://www.openoffice.org/license.html> +# for a copy of the LGPLv3 License. +# +#************************************************************************* + +PRJ = .. +PRJNAME = svtools +TARGET = qa + +ENABLE_EXCEPTIONS = true + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk + +# BEGIN ---------------------------------------------------------------- +# auto generated Target:job by codegen.pl +SHL1OBJS= \ + $(SLO)$/test_URIHelper.obj + +SHL1TARGET= URIHelper +SHL1STDLIBS=\ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(SALLIB) \ + $(SVTOOLLIB) \ + $(TOOLSLIB) \ + $(UNOTOOLSLIB) \ + $(TESTSHL2LIB) \ + $(CPPUNITLIB) + +SHL1IMPLIB= i$(SHL1TARGET) +DEF1NAME =$(SHL1TARGET) +SHL1VERSIONMAP= export.map +# auto generated Target:job +# END ------------------------------------------------------------------ + +#------------------------------- All object files ------------------------------- +# do this here, so we get right dependencies +# SLOFILES=$(SHL1OBJS) + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk +.INCLUDE : _cppunit.mk + +# LLA: old stuff +# USE_DEFFILE = true +# +# .INCLUDE: settings.mk +# +# .IF "$(OS)" == "WNT" +# REGEXP = "s/^[\#].*$$//" +# .ELSE # OS, WNT +# REGEXP = 's/^[\#].*$$//' +# .ENDIF # OS, WNT +# +# SHL1TARGET = URIHelper +# SHL1OBJS = \ +# $(SLO)$/test_URIHelper.obj +# SHL1STDLIBS = \ +# $(CPPULIB) \ +# $(CPPUHELPERLIB) \ +# $(SALLIB) \ +# $(SVTOOLLIB) \ +# $(TOOLSLIB) \ +# $(UNOTOOLSLIB) +# +# DEF1NAME = $(SHL1TARGET) +# DEF1EXPORTFILE = $(MISC)$/$(SHL1TARGET).dxp +# +# .INCLUDE: target.mk +# +# $(MISC)$/$(SHL1TARGET).dxp: sce$/$(SHL1TARGET).sce +# + $(TYPE) $< | sed $(REGEXP) > $@ +# + $(TYPE) $@ | sed "s/^/test_/" > $(MISC)$/$(SHL1TARGET).tst +# + $(TYPE) $(MISC)$/$(SHL1TARGET).tst | sed "/test_./ w $@" diff --git a/svl/qa/test_URIHelper.cxx b/svl/qa/test_URIHelper.cxx new file mode 100644 index 000000000000..a90fbe039b6d --- /dev/null +++ b/svl/qa/test_URIHelper.cxx @@ -0,0 +1,462 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: test_URIHelper.cxx,v $ + * $Revision: 1.11 $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org 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 version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svtools.hxx" + +#include "sal/config.h" + +#include <cstddef> + +#include "com/sun/star/lang/Locale.hpp" +#include "com/sun/star/lang/XComponent.hpp" +#include "com/sun/star/lang/XMultiComponentFactory.hpp" +#include "com/sun/star/lang/XMultiServiceFactory.hpp" +#include "com/sun/star/ucb/Command.hpp" +#include "com/sun/star/ucb/CommandAbortedException.hpp" +#include "com/sun/star/ucb/IllegalIdentifierException.hpp" +#include "com/sun/star/ucb/XCommandProcessor.hpp" +#include "com/sun/star/ucb/XContent.hpp" +#include "com/sun/star/ucb/XContentIdentifier.hpp" +#include "com/sun/star/ucb/XContentProvider.hpp" +#include "com/sun/star/ucb/XContentProviderManager.hpp" +#include "com/sun/star/uno/Any.hxx" +#include "com/sun/star/uno/Exception.hpp" +#include "com/sun/star/uno/Reference.hxx" +#include "com/sun/star/uno/RuntimeException.hpp" +#include "com/sun/star/uno/Sequence.hxx" +#include "com/sun/star/uno/XComponentContext.hpp" +#include "com/sun/star/uri/XUriReference.hpp" +#include "cppuhelper/bootstrap.hxx" +#include "cppuhelper/implbase1.hxx" +#include "cppuhelper/implbase2.hxx" +#include "testshl/simpleheader.hxx" +#include "osl/diagnose.h" +#include "rtl/strbuf.hxx" +#include "rtl/string.h" +#include "rtl/string.hxx" +#include "rtl/textenc.h" +#include "rtl/ustring.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "tools/solar.h" +#include "unotools/charclass.hxx" + +#include "urihelper.hxx" + +// This test needs a UNO component context that supports various services (the +// UCB, an UriReferenceFactory, ...), so it is best executed within an OOo +// installation. + +namespace com { namespace sun { namespace star { namespace ucb { + class XCommandEnvironment; + class XContentEventListener; +} } } } + +namespace { + +namespace css = com::sun::star; + +// This class only implements that subset of functionality of a proper +// css::ucb::Content that is known to be needed here: +class Content: + public cppu::WeakImplHelper2< + css::ucb::XContent, css::ucb::XCommandProcessor > +{ +public: + explicit Content( + css::uno::Reference< css::ucb::XContentIdentifier > const & identifier); + + virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL + getIdentifier() throw (css::uno::RuntimeException) { + return m_identifier; + } + + virtual rtl::OUString SAL_CALL getContentType() + throw (css::uno::RuntimeException) + { + return rtl::OUString(); + } + + virtual void SAL_CALL addContentEventListener( + css::uno::Reference< css::ucb::XContentEventListener > const &) + throw (css::uno::RuntimeException) + {} + + virtual void SAL_CALL removeContentEventListener( + css::uno::Reference< css::ucb::XContentEventListener > const &) + throw (css::uno::RuntimeException) + {} + + virtual sal_Int32 SAL_CALL createCommandIdentifier() + throw (css::uno::RuntimeException) + { + return 0; + } + + virtual css::uno::Any SAL_CALL execute( + css::ucb::Command const & command, sal_Int32 commandId, + css::uno::Reference< css::ucb::XCommandEnvironment > const &) + throw ( + css::uno::Exception, css::ucb::CommandAbortedException, + css::uno::RuntimeException); + + virtual void SAL_CALL abort(sal_Int32) throw (css::uno::RuntimeException) {} + +private: + static char const m_prefix[]; + + css::uno::Reference< css::ucb::XContentIdentifier > m_identifier; +}; + +char const Content::m_prefix[] = "test:"; + +Content::Content( + css::uno::Reference< css::ucb::XContentIdentifier > const & identifier): + m_identifier(identifier) +{ + OSL_ASSERT(m_identifier.is()); + rtl::OUString uri(m_identifier->getContentIdentifier()); + if (!uri.matchIgnoreAsciiCaseAsciiL(RTL_CONSTASCII_STRINGPARAM(m_prefix)) + || uri.indexOf('#', RTL_CONSTASCII_LENGTH(m_prefix)) != -1) + { + throw css::ucb::IllegalIdentifierException(); + } +} + +css::uno::Any Content::execute( + css::ucb::Command const & command, sal_Int32, + css::uno::Reference< css::ucb::XCommandEnvironment > const &) + throw ( + css::uno::Exception, css::ucb::CommandAbortedException, + css::uno::RuntimeException) +{ + if (!command.Name.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM("getCasePreservingURL"))) + { + throw css::uno::RuntimeException(); + } + // If any non-empty segment starts with anything but '0', '1', or '2', fail; + // otherwise, if the last non-empty segment starts with '1', add a final + // slash, and if the last non-empty segment starts with '2', remove a final + // slash (if any); also, turn the given uri into all-lowercase: + rtl::OUString uri(m_identifier->getContentIdentifier()); + sal_Unicode c = '0'; + for (sal_Int32 i = RTL_CONSTASCII_LENGTH(m_prefix); i != -1;) { + rtl::OUString seg(uri.getToken(0, '/', i)); + if (seg.getLength() > 0) { + c = seg[0]; + if (c < '0' || c > '2') { + throw css::uno::Exception(); + } + } + } + switch (c) { + case '1': + uri += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/")); + break; + case '2': + if (uri.getLength() > 0 && uri[uri.getLength() - 1] == '/') { + uri = uri.copy(0, uri.getLength() -1); + } + break; + } + return css::uno::makeAny(uri.toAsciiLowerCase()); +} + +class Provider: public cppu::WeakImplHelper1< css::ucb::XContentProvider > { +public: + virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent( + css::uno::Reference< css::ucb::XContentIdentifier > const & identifier) + throw (css::ucb::IllegalIdentifierException, css::uno::RuntimeException) + { + return new Content(identifier); + } + + virtual sal_Int32 SAL_CALL compareContentIds( + css::uno::Reference< css::ucb::XContentIdentifier > const & id1, + css::uno::Reference< css::ucb::XContentIdentifier > const & id2) + throw (css::uno::RuntimeException) + { + OSL_ASSERT(id1.is() && id2.is()); + return + id1->getContentIdentifier().compareTo(id2->getContentIdentifier()); + } +}; + +class Test: public CppUnit::TestFixture { +public: + virtual void setUp(); + + void finish(); + + void testNormalizedMakeRelative(); + + void testFindFirstURLInText(); + + CPPUNIT_TEST_SUITE(Test); + CPPUNIT_TEST(testNormalizedMakeRelative); + CPPUNIT_TEST(testFindFirstURLInText); + CPPUNIT_TEST(finish); + CPPUNIT_TEST_SUITE_END(); + +private: + static css::uno::Reference< css::uno::XComponentContext > m_context; +}; + +void Test::setUp() { + // For whatever reason, on W32 it does not work to create/destroy a fresh + // component context for each test in Test::setUp/tearDown; therefore, a + // single component context is used for all tests and destroyed in the last + // pseudo-test "finish": + if (!m_context.is()) { + m_context = cppu::defaultBootstrap_InitialComponentContext(); + } +} + +void Test::finish() { + css::uno::Reference< css::lang::XComponent >( + m_context, css::uno::UNO_QUERY_THROW)->dispose(); +} + +void Test::testNormalizedMakeRelative() { + css::uno::Sequence< css::uno::Any > args(2); + args[0] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Local")); + args[1] <<= rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Office")); + css::uno::Reference< css::ucb::XContentProviderManager >( + (css::uno::Reference< css::lang::XMultiComponentFactory >( + m_context->getServiceManager(), css::uno::UNO_QUERY_THROW)-> + createInstanceWithArgumentsAndContext( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "com.sun.star.ucb.UniversalContentBroker")), + args, m_context)), + css::uno::UNO_QUERY_THROW)->registerContentProvider( + new Provider, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test")), + true); + struct Test { + char const * base; + char const * absolute; + char const * relative; + }; + static Test const tests[] = { + { "hierarchical:/", "mailto:def@a.b.c.", "mailto:def@a.b.c." }, + { "hierarchical:/", "a/b/c", "a/b/c" }, + { "hierarchical:/a", "hierarchical:/a/b/c?d#e", "/a/b/c?d#e" }, + { "hierarchical:/a/", "hierarchical:/a/b/c?d#e", "b/c?d#e" }, + { "test:/0/0/a", "test:/0/b", "../b" }, + { "test:/1/1/a", "test:/1/b", "../b" }, + { "test:/2/2//a", "test:/2/b", "../../b" }, + { "test:/0a/b", "test:/0A/c#f", "c#f" }, + { "file:///usr/bin/nonex1/nonex2", + "file:///usr/bin/nonex1/nonex3/nonex4", "nonex3/nonex4" }, + { "file:///usr/bin/nonex1/nonex2#fragmentA", + "file:///usr/bin/nonex1/nonex3/nonex4#fragmentB", + "nonex3/nonex4#fragmentB" }, + { "file:///usr/nonex1/nonex2", "file:///usr/nonex3", "../nonex3" }, + { "file:///c:/windows/nonex1", "file:///c:/nonex2", "../nonex2" }, +#if defined WNT + { "file:///c:/nonex1/nonex2", "file:///C:/nonex1/nonex3/nonex4", + "nonex3/nonex4" } +#endif + }; + for (std::size_t i = 0; i < sizeof tests / sizeof tests[0]; ++i) { + css::uno::Reference< css::uri::XUriReference > ref( + URIHelper::normalizedMakeRelative( + m_context, rtl::OUString::createFromAscii(tests[i].base), + rtl::OUString::createFromAscii(tests[i].absolute))); + bool ok = tests[i].relative == 0 + ? !ref.is() + : ref.is() && ref->getUriReference().equalsAscii(tests[i].relative); + rtl::OString msg; + if (!ok) { + rtl::OStringBuffer buf; + buf.append('<'); + buf.append(tests[i].base); + buf.append(RTL_CONSTASCII_STRINGPARAM(">, <")); + buf.append(tests[i].absolute); + buf.append(RTL_CONSTASCII_STRINGPARAM(">: ")); + if (ref.is()) { + buf.append('<'); + buf.append( + rtl::OUStringToOString( + ref->getUriReference(), RTL_TEXTENCODING_UTF8)); + buf.append('>'); + } else { + buf.append(RTL_CONSTASCII_STRINGPARAM("none")); + } + buf.append(RTL_CONSTASCII_STRINGPARAM(" instead of ")); + if (tests[i].relative == 0) { + buf.append(RTL_CONSTASCII_STRINGPARAM("none")); + } else { + buf.append('<'); + buf.append(tests[i].relative); + buf.append('>'); + } + msg = buf.makeStringAndClear(); + } + CPPUNIT_ASSERT_MESSAGE(msg.getStr(), ok); + } +} + +void Test::testFindFirstURLInText() { + struct Test { + char const * input; + char const * result; + xub_StrLen begin; + xub_StrLen end; + }; + static Test const tests[] = { + { "...ftp://bla.bla.bla/blubber/...", + "ftp://bla.bla.bla/blubber/", 3, 29 }, + { "..\\ftp://bla.bla.bla/blubber/...", 0, 0, 0 }, + { "..\\ftp:\\\\bla.bla.bla\\blubber/...", + "file://bla.bla.bla/blubber%2F", 7, 29 }, + { "http://sun.com", "http://sun.com/", 0, 14 }, + { "http://sun.com/", "http://sun.com/", 0, 15 }, + { "http://www.xerox.com@www.pcworld.com/go/3990332.htm", 0, 0, 0 }, + { "ftp://www.xerox.com@www.pcworld.com/go/3990332.htm", + "ftp://www.xerox.com@www.pcworld.com/go/3990332.htm", 0, 50 }, + { "Version.1.2.3", 0, 0, 0 }, + { "Version:1.2.3", 0, 0, 0 }, + { "a.b.c", 0, 0, 0 }, + { "file:///a|...", "file:///a:", 0, 10 }, + { "file:///a||...", "file:///a%7C%7C", 0, 11 }, + { "file:///a|/bc#...", "file:///a:/bc", 0, 13 }, + { "file:///a|/bc#de...", "file:///a:/bc#de", 0, 16 }, + { "abc.def.ghi,ftp.xxx.yyy/zzz...", "ftp://ftp.xxx.yyy/zzz", 12, 27 }, + { "abc.def.ghi,Ftp.xxx.yyy/zzz...", "ftp://Ftp.xxx.yyy/zzz", 12, 27 }, + { "abc.def.ghi,www.xxx.yyy...", "http://www.xxx.yyy/", 12, 23 }, + { "abc.def.ghi,wwww.xxx.yyy...", 0, 0, 0 }, + { "abc.def.ghi,wWW.xxx.yyy...", "http://wWW.xxx.yyy/", 12, 23 }, + { "Bla {mailto.me@abc.def.g.h.i}...", + "mailto:%7Bmailto.me@abc.def.g.h.i", 4, 28 }, + { "abc@def@ghi", 0, 0, 0 }, + { "lala@sun.com", "mailto:lala@sun.com", 0, 12 }, + { "1lala@sun.com", "mailto:1lala@sun.com", 0, 13 }, + { "aaa_bbb@xxx.yy", "mailto:aaa_bbb@xxx.yy", 0, 14 }, + { "{a:\\bla/bla/bla...}", "file:///a:/bla/bla/bla", 1, 15 }, + { "#b:/c/d#e#f#", "file:///b:/c/d", 1, 7 }, + { "a:/", "file:///a:/", 0, 3 }, + { ".component:", 0, 0, 0 }, + { ".uno:", 0, 0, 0 }, + { "cid:", 0, 0, 0 }, + { "data:", 0, 0, 0 }, + { "db:", 0, 0, 0 }, + { "file:", 0, 0, 0 }, + { "ftp:", 0, 0, 0 }, + { "http:", 0, 0, 0 }, + { "https:", 0, 0, 0 }, + { "imap:", 0, 0, 0 }, + { "javascript:", 0, 0, 0 }, + { "ldap:", 0, 0, 0 }, + { "macro:", 0, 0, 0 }, + { "mailto:", 0, 0, 0 }, + { "news:", 0, 0, 0 }, + { "out:", 0, 0, 0 }, + { "pop3:", 0, 0, 0 }, + { "private:", 0, 0, 0 }, + { "slot:", 0, 0, 0 }, + { "staroffice.component:", 0, 0, 0 }, + { "staroffice.db:", 0, 0, 0 }, + { "staroffice.factory:", 0, 0, 0 }, + { "staroffice.helpid:", 0, 0, 0 }, + { "staroffice.java:", 0, 0, 0 }, + { "staroffice.macro:", 0, 0, 0 }, + { "staroffice.out:", 0, 0, 0 }, + { "staroffice.pop3:", 0, 0, 0 }, + { "staroffice.private:", 0, 0, 0 }, + { "staroffice.searchfolder:", 0, 0, 0 }, + { "staroffice.slot:", 0, 0, 0 }, + { "staroffice.trashcan:", 0, 0, 0 }, + { "staroffice.uno:", 0, 0, 0 }, + { "staroffice.vim:", 0, 0, 0 }, + { "staroffice:", 0, 0, 0 }, + { "vim:", 0, 0, 0 }, + { "vnd.sun.star.cmd:", 0, 0, 0 }, + { "vnd.sun.star.help:", 0, 0, 0 }, + { "vnd.sun.star.hier:", 0, 0, 0 }, + { "vnd.sun.star.odma:", 0, 0, 0 }, + { "vnd.sun.star.pkg:", 0, 0, 0 }, + { "vnd.sun.star.script:", 0, 0, 0 }, + { "vnd.sun.star.webdav:", 0, 0, 0 }, + { "vnd.sun.star.wfs:", 0, 0, 0 }, + { "generic:path", 0, 0, 0 }, + { "wfs:", 0, 0, 0 } + }; + CharClass charClass( + css::uno::Reference< css::lang::XMultiServiceFactory >( + m_context->getServiceManager(), css::uno::UNO_QUERY_THROW), + com::sun::star::lang::Locale( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en")), + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("US")), rtl::OUString())); + for (std::size_t i = 0; i < sizeof tests / sizeof tests[0]; ++i) { + rtl::OUString input(rtl::OUString::createFromAscii(tests[i].input)); + xub_StrLen begin = 0; + xub_StrLen end = static_cast< xub_StrLen >(input.getLength()); + rtl::OUString result( + URIHelper::FindFirstURLInText(input, begin, end, charClass)); + bool ok = tests[i].result == 0 + ? (result.getLength() == 0 && begin == input.getLength() + && end == input.getLength()) + : (result.equalsAscii(tests[i].result) && begin == tests[i].begin + && end == tests[i].end); + rtl::OString msg; + if (!ok) { + rtl::OStringBuffer buf; + buf.append('"'); + buf.append(tests[i].input); + buf.append(RTL_CONSTASCII_STRINGPARAM("\" -> ")); + buf.append(tests[i].result == 0 ? "none" : tests[i].result); + buf.append(RTL_CONSTASCII_STRINGPARAM(" (")); + buf.append(static_cast< sal_Int32 >(tests[i].begin)); + buf.append(RTL_CONSTASCII_STRINGPARAM(", ")); + buf.append(static_cast< sal_Int32 >(tests[i].end)); + buf.append(')'); + buf.append(RTL_CONSTASCII_STRINGPARAM(" != ")); + buf.append(rtl::OUStringToOString(result, RTL_TEXTENCODING_UTF8)); + buf.append(RTL_CONSTASCII_STRINGPARAM(" (")); + buf.append(static_cast< sal_Int32 >(begin)); + buf.append(RTL_CONSTASCII_STRINGPARAM(", ")); + buf.append(static_cast< sal_Int32 >(end)); + buf.append(')'); + msg = buf.makeStringAndClear(); + } + CPPUNIT_ASSERT_MESSAGE(msg.getStr(), ok); + } +} + +css::uno::Reference< css::uno::XComponentContext > Test::m_context; + +CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(Test, "alltests"); + +} + +NOADDITIONAL; |