added LocalizedConfigurable

added Glib::ustring functions to LocalizedObject
This commit is contained in:
maroy 2004-12-20 13:58:16 +00:00
parent f81887c4ae
commit 1522d9c053
9 changed files with 721 additions and 12 deletions

View file

@ -21,7 +21,7 @@
# #
# #
# Author : $Author: maroy $ # Author : $Author: maroy $
# Version : $Revision: 1.15 $ # Version : $Revision: 1.16 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $
# #
# @configure_input@ # @configure_input@
@ -114,7 +114,8 @@ CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \
${TMP_DIR}/Playlist.o \ ${TMP_DIR}/Playlist.o \
${TMP_DIR}/TimeConversion.o \ ${TMP_DIR}/TimeConversion.o \
${TMP_DIR}/Thread.o \ ${TMP_DIR}/Thread.o \
${TMP_DIR}/LocalizedObject.o ${TMP_DIR}/LocalizedObject.o \
${TMP_DIR}/LocalizedConfigurable.o
TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \ TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \
${TMP_DIR}/AudioClipTest.o \ ${TMP_DIR}/AudioClipTest.o \
@ -124,7 +125,8 @@ TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \
${TMP_DIR}/TimeConversionTest.o \ ${TMP_DIR}/TimeConversionTest.o \
${TMP_DIR}/TestRunnable.o \ ${TMP_DIR}/TestRunnable.o \
${TMP_DIR}/ThreadTest.o \ ${TMP_DIR}/ThreadTest.o \
${TMP_DIR}/LocalizedObjectTest.o ${TMP_DIR}/LocalizedObjectTest.o \
${TMP_DIR}/LocalizedConfigurableTest.o
TEST_RUNNER_RES = ${TMP_DIR}/${PACKAGE_NAME}_root.res \ TEST_RUNNER_RES = ${TMP_DIR}/${PACKAGE_NAME}_root.res \
${TMP_DIR}/${PACKAGE_NAME}_en.res \ ${TMP_DIR}/${PACKAGE_NAME}_en.res \

View file

@ -0,0 +1,135 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/LocalizedConfigurable.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_Core_LocalizedConfigurable_h
#define LiveSupport_Core_LocalizedConfigurable_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/Core/LocalizedObject.h"
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A configurable element, that is also localized. Reads localization
* information from the configuration file itself.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class LocalizedConfigurable : public Configurable, public LocalizedObject
{
private:
/**
* The path to the resource bundles.
*/
std::string bundlePath;
public:
/**
* The default constructor.
*/
LocalizedConfigurable(void) throw ()
{
}
/**
* A virtual destructor.
*/
virtual
~LocalizedConfigurable(void) throw ()
{
}
/**
* Configure the object based on the XML element supplied.
* The supplied element is expected to be of the name
* returned by configElementName().
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
* @exception std::logic_error if the object has already
* been configured, and can not be reconfigured.
* @see LocalizedObject#getBundle
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error);
/**
* Change the current locale, which was previously specified by
* configure(), to the new locale. This results in a replacement
* of the resource bundle, read from the same path as in the
* configuration element sent to configure(), but with the new
* locale id.
*
* @param newLocale the new locale id.
* @exception std::invalid_argument if there is no bundle by
* the specified locale
*/
virtual void
changeLocale(const std::string newLocale)
throw (std::invalid_argument);
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LiveSupport_Core_LocalizedConfigurable_h

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.4 $ Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/LocalizedObject.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/LocalizedObject.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -64,7 +64,7 @@ namespace Core {
* to make localized life easier. * to make localized life easier.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.4 $ * @version $Revision: 1.5 $
*/ */
class LocalizedObject class LocalizedObject
{ {
@ -80,6 +80,8 @@ class LocalizedObject
*/ */
Ptr<ResourceBundle>::Ref bundle; Ptr<ResourceBundle>::Ref bundle;
protected:
/** /**
* The default constructor. * The default constructor.
*/ */
@ -167,6 +169,17 @@ class LocalizedObject
return bundle; return bundle;
} }
/**
* Change the resource bundle for this object.
*
* @param the new resource bundle used by the object.
*/
virtual void
setBundle(Ptr<ResourceBundle>::Ref bundle) throw ()
{
this->bundle = bundle;
}
/** /**
* Get a resource bundle nested inside our bundle. * Get a resource bundle nested inside our bundle.
* *
@ -229,6 +242,66 @@ class LocalizedObject
unsigned int nArguments) unsigned int nArguments)
throw (std::invalid_argument); throw (std::invalid_argument);
/**
* Convert an ICU unicode string to a Glib ustring.
*
* @param unicodeString the ICU unicode string to convert.
* @return the same string as supplied, in Glib ustring form.
*/
static Ptr<Glib::ustring>::Ref
unicodeStringToUstring(Ptr<const UnicodeString>::Ref unicodeString)
throw ();
/**
* Convert a Glib ustring to an ICU unicode string.
*
* @param gString the Glib ustring to convert
* @return the same string as supplied, in ICU unicode form.
*/
static Ptr<UnicodeString>::Ref
ustringToUnicodeString(Ptr<const Glib::ustring>::Ref gString)
throw ();
/**
* Get a string from the resource bundle, as a Glib ustring.
*
* @param key the key identifying the requested string.
* @return the requested string
* @exception std::invalid_argument if there is no string for the
* specified key.
*/
Ptr<Glib::ustring>::Ref
getResourceUstring(const char * key)
throw (std::invalid_argument)
{
return unicodeStringToUstring(getResourceString(key));
}
/**
* A convenience function to format a message, based on a pattern
* loaded from a resource.
* For more information, see the ICU MessageFormat class
* documentation.
*
* @param patternKey the key of the pattern to format
* @param arguments the arguments to use in the formatting
* @param nArguments the number of arguments supplied
* @return the formatted string, in Glib ustring form
* @exception std::invalid_argument if the pattern is bad, or
* the arguments do not match, or there is no resource
* specified by patternKey
* @see http://oss.software.ibm.com/icu/apiref/classMessageFormat.html
*/
virtual Ptr<Glib::ustring>::Ref
formatMessageUstring(const char * patternKey,
Formattable * arguments,
unsigned int nArguments)
throw (std::invalid_argument)
{
return unicodeStringToUstring(formatMessage(patternKey,
arguments,
nArguments));
}
}; };
/* ================================================= external data structures */ /* ================================================= external data structures */

View file

@ -0,0 +1,117 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedConfigurable.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <unicode/msgfmt.h>
#include "LiveSupport/Core/LocalizedConfigurable.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/**
* The name of the attribute to get the path of the resource bundle.
*/
static const std::string pathAttrName = "path";
/**
* The name of the attribute to get the locale of the resource bundle.
*/
static const std::string localeAttrName = "locale";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Load a resource bunlde based on an XML configuration element.
*----------------------------------------------------------------------------*/
void
LocalizedConfigurable :: configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error)
{
if (element.get_name() != LocalizedObject::getConfigElementName()) {
std::string eMsg = "Bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
const xmlpp::Attribute * attribute;
if (!(attribute = element.get_attribute(pathAttrName))) {
std::string eMsg = "Missing attribute ";
eMsg += pathAttrName;
throw std::invalid_argument(eMsg);
}
bundlePath = attribute->get_value();
if (!(attribute = element.get_attribute(localeAttrName))) {
std::string eMsg = "Missing attribute ";
eMsg += localeAttrName;
throw std::invalid_argument(eMsg);
}
std::string locale = attribute->get_value();
changeLocale(locale);
}
/*------------------------------------------------------------------------------
* Change the resource bundle to reflect the specified locale
*----------------------------------------------------------------------------*/
void
LocalizedConfigurable :: changeLocale(const std::string newLocale)
throw (std::invalid_argument)
{
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref resourceBundle(
new ResourceBundle(bundlePath.c_str(),
newLocale.c_str(),
status));
if (!U_SUCCESS(status)) {
throw std::invalid_argument("opening resource bundle a failure");
}
setBundle(resourceBundle);
}

View file

@ -0,0 +1,173 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedConfigurableTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <string>
#include <iostream>
#include <unicode/resbund.h>
#include "LiveSupport/Core/LocalizedConfigurable.h"
#include "LocalizedConfigurableTest.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(LocalizedConfigurableTest);
/**
* The name of the configuration file for the resource bundle.
*/
static const std::string configFileName = "etc/resourceBundle.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
LocalizedConfigurableTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
LocalizedConfigurableTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* A simple smoke test.
*----------------------------------------------------------------------------*/
void
LocalizedConfigurableTest :: simpleTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<LocalizedConfigurable>::Ref locConf(new LocalizedConfigurable());
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
locConf->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
try {
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locConf->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->compare("fou") == 0);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* A test to see if chaning the locale works.
*----------------------------------------------------------------------------*/
void
LocalizedConfigurableTest :: changeLocaleTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<LocalizedConfigurable>::Ref locConf(new LocalizedConfigurable());
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
locConf->configure(*root);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
// see if all is OK in english
try {
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locConf->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->compare("fou") == 0);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
// see if all is OK when changing to hungarian.
try {
locConf->changeLocale("hu");
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locConf->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->charAt(0) == 0x0066); // 'f'
CPPUNIT_ASSERT(foo->charAt(1) == 0x00fa); // 'u' with acute
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
// see if all is OK when changing to japanese.
try {
locConf->changeLocale("jp");
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locConf->getBundle("section1")));
Ptr<UnicodeString>::Ref foo = section1->getResourceString("foo");
CPPUNIT_ASSERT(foo->charAt(0) == 0x3075); // hiragana fu
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}

View file

@ -0,0 +1,116 @@
/*------------------------------------------------------------------------------
Copyright (c) 2004 Media Development Loan Fund
This file is part of the LiveSupport project.
http://livesupport.campware.org/
To report bugs, send an e-mail to bugs@campware.org
LiveSupport is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
LiveSupport 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with LiveSupport; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedConfigurableTest.h,v $
------------------------------------------------------------------------------*/
#ifndef LocalizedConfigurableTest_h
#define LocalizedConfigurableTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Core {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the LocalizedConfigurable class.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see LocalizedObject
*/
class LocalizedConfigurableTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(LocalizedConfigurableTest);
CPPUNIT_TEST(simpleTest);
CPPUNIT_TEST(changeLocaleTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple smoke test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
simpleTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to see if changing the locale works.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
changeLocaleTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Core
} // namespace LiveSupport
#endif // LocalizedConfigurableTest_h

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.4 $ Version : $Revision: 1.5 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObject.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObject.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -177,3 +177,44 @@ LocalizedObject :: formatMessage(const char * patternKey,
return formatMessage(getResourceString(patternKey), arguments, nArguments); return formatMessage(getResourceString(patternKey), arguments, nArguments);
} }
/*------------------------------------------------------------------------------
* Create a Glib ustring from an ICU UnicodeString
*----------------------------------------------------------------------------*/
Ptr<Glib::ustring>::Ref
LocalizedObject :: unicodeStringToUstring(
Ptr<const UnicodeString>::Ref unicodeString)
throw ()
{
const UChar * uchars = unicodeString->getBuffer();
int32_t length = unicodeString->length();
Ptr<Glib::ustring>::Ref ustr(new Glib::ustring());
ustr->reserve(length);
while (length--) {
ustr->push_back((gunichar) (*(uchars++)));
}
return ustr;
}
/*------------------------------------------------------------------------------
* Create an ICU UnicodeString from a Glib ustring
*----------------------------------------------------------------------------*/
Ptr<UnicodeString>::Ref
LocalizedObject :: ustringToUnicodeString(
Ptr<const Glib::ustring>::Ref gString)
throw ()
{
Ptr<UnicodeString>::Ref uString(new UnicodeString());
Glib::ustring::const_iterator it = gString->begin();
Glib::ustring::const_iterator end = gString->end();
while (it < end) {
uString->append((UChar32) *it++);
}
return uString;
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.3 $ Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObjectTest.cxx,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObjectTest.cxx,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -234,7 +234,7 @@ LocalizedObjectTest :: formatMessageTest(void)
* Test to see if resource bundle can be loaded based on a config file * Test to see if resource bundle can be loaded based on a config file
*----------------------------------------------------------------------------*/ *----------------------------------------------------------------------------*/
void void
LocalizedObjectTest :: loadFromConfig(void) LocalizedObjectTest :: loadFromConfigTest(void)
throw (CPPUNIT_NS::Exception) throw (CPPUNIT_NS::Exception)
{ {
Ptr<ResourceBundle>::Ref bundle; Ptr<ResourceBundle>::Ref bundle;
@ -265,3 +265,46 @@ LocalizedObjectTest :: loadFromConfig(void)
} }
} }
/*------------------------------------------------------------------------------
* Test the ustring related functions.
*----------------------------------------------------------------------------*/
void
LocalizedObjectTest :: ustringTest(void)
throw (CPPUNIT_NS::Exception)
{
UErrorCode status = U_ZERO_ERROR;
Ptr<ResourceBundle>::Ref bundle(new ResourceBundle("./tmp/" PACKAGE_NAME,
"root",
status));
CPPUNIT_ASSERT(U_SUCCESS(status));
// test getting an ustring resource
try {
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle));
Ptr<LocalizedObject>::Ref section1(new LocalizedObject(
locObj->getBundle("section1")));
Ptr<Glib::ustring>::Ref foo = section1->getResourceUstring("foo");
CPPUNIT_ASSERT(*foo == "foo");
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
// test message formatting to ustring
try {
Ptr<Glib::ustring>::Ref message;
Ptr<LocalizedObject>::Ref locObj(new LocalizedObject(bundle));
Ptr<LocalizedObject>::Ref messages(new LocalizedObject(
locObj->getBundle("messages")));
Formattable arguments[] = { "p1", "p2" };
// test formatting through a key
message = messages->formatMessageUstring("aMessage", arguments, 2);
CPPUNIT_ASSERT(*message == "parameter 0: p1, parameter 1: p2");
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
}

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $ Author : $Author: maroy $
Version : $Revision: 1.3 $ Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObjectTest.h,v $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/LocalizedObjectTest.h,v $
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/
@ -58,7 +58,7 @@ namespace Core {
* Unit test for the LocalizedObject class. * Unit test for the LocalizedObject class.
* *
* @author $Author: maroy $ * @author $Author: maroy $
* @version $Revision: 1.3 $ * @version $Revision: 1.4 $
* @see LocalizedObject * @see LocalizedObject
*/ */
class LocalizedObjectTest : public CPPUNIT_NS::TestFixture class LocalizedObjectTest : public CPPUNIT_NS::TestFixture
@ -68,7 +68,8 @@ class LocalizedObjectTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(fallbackTest); CPPUNIT_TEST(fallbackTest);
CPPUNIT_TEST(unicodeTest); CPPUNIT_TEST(unicodeTest);
CPPUNIT_TEST(formatMessageTest); CPPUNIT_TEST(formatMessageTest);
CPPUNIT_TEST(loadFromConfig); CPPUNIT_TEST(loadFromConfigTest);
CPPUNIT_TEST(ustringTest);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
protected: protected:
@ -113,7 +114,15 @@ class LocalizedObjectTest : public CPPUNIT_NS::TestFixture
* @exception CPPUNIT_NS::Exception on test failures. * @exception CPPUNIT_NS::Exception on test failures.
*/ */
void void
loadFromConfig(void) throw (CPPUNIT_NS::Exception); loadFromConfigTest(void) throw (CPPUNIT_NS::Exception);
/**
* A test to check the Glib::ustring related functions.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
ustringTest(void) throw (CPPUNIT_NS::Exception);
public: public: