changed UniqueId::IdType from unsigned int to long long int

added UniqueId constructor from, and conversion to, std::string
got WebStorageClient::existsAudioClip() to work
This commit is contained in:
fgerlits 2004-12-20 22:08:19 +00:00
parent c687ab5a52
commit 48be2884b4
8 changed files with 371 additions and 40 deletions

View file

@ -20,8 +20,8 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
# Author : $Author: maroy $
# Version : $Revision: 1.16 $
# Author : $Author: fgerlits $
# Version : $Revision: 1.17 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/etc/Makefile.in,v $
#
# @configure_input@
@ -118,6 +118,7 @@ CORE_LIB_OBJS = ${TMP_DIR}/UniqueId.o \
${TMP_DIR}/LocalizedConfigurable.o
TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \
${TMP_DIR}/UniqueIdTest.o \
${TMP_DIR}/AudioClipTest.o \
${TMP_DIR}/FadeInfoTest.o \
${TMP_DIR}/PlaylistElementTest.o \

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.2 $
Author : $Author: fgerlits $
Version : $Revision: 1.3 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/include/LiveSupport/Core/UniqueId.h,v $
------------------------------------------------------------------------------*/
@ -40,7 +40,9 @@
#include "configure.h"
#endif
#include <string>
#include <sstream>
#include <iomanip>
#include "LiveSupport/Core/Ptr.h"
namespace LiveSupport {
@ -57,8 +59,8 @@ namespace Core {
/**
* A class representing globally unique identifiers.
*
* @author $Author: maroy $
* @version $Revision: 1.2 $
* @author $Author: fgerlits $
* @version $Revision: 1.3 $
*/
class UniqueId
{
@ -66,7 +68,12 @@ class UniqueId
/**
* The value of the id.
*/
unsigned long int id;
long long int id;
/**
* A string representation of the id, in hexadecimal notation.
*/
std::string idAsString;
/**
* Default constructor.
@ -79,18 +86,38 @@ class UniqueId
public:
/**
* The type for the numeric value the unique id is represented in.
* This is set to 'long long int', i.e., 32-bit signed integers.
*/
typedef unsigned long int IdType;
typedef long long int IdType;
/**
* Constructor to create a UniqueId with a specific value.
* TODO: remove this later, as this is for testing purposes only.
* Constructor to create a UniqueId with a specific integer value.
* The argument is expected to be between 0 and 2^31-1 (inclusive).
*
* @param id the value of the created id object.
* @param id the numeric value of the created id object.
*/
UniqueId(const IdType id) throw ()
UniqueId(const IdType id) throw ()
{
this->id = id;
std::stringstream idWriter;
idWriter << std::hex << std::setw(16) << std::setfill('0') << id;
this->idAsString = idWriter.str();
}
/**
* Constructor to create a UniqueId with a specific string value.
* If the argument is not a valid hexadecimal number between 0 and
* 2^31-1 (inclusive), the integer value of the UniqueId will be
* bogus.
*
* @param idAsString the string value of the created id object.
*/
UniqueId(const std::string idAsString) throw ()
{
this->idAsString = idAsString;
// TODO: add error checking
std::stringstream idReader(idAsString);
idReader >> std::hex >> this->id;
}
/**
@ -120,7 +147,8 @@ class UniqueId
}
/**
* Generate a globally unique id.
* Generate a globally unique id. This is used for testing.
* In real life, unique IDs are generated by the storage server.
*/
static Ptr<UniqueId>::Ref
generateId(void) throw ();
@ -135,6 +163,27 @@ class UniqueId
{
return id;
}
/**
* Return the numeric value of this globally unique id
* (alternative syntax).
*
* @return the numeric value of this id.
*/
operator long long int () const throw ()
{
return id;
}
/**
* Return the string value of this globally unique id.
*
* @return the string value of this id.
*/
operator std::string () const throw ()
{
return idAsString;
}
};

View file

@ -21,8 +21,8 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Author : $Author: maroy $
Version : $Revision: 1.1 $
Author : $Author: fgerlits $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/UniqueId.cxx,v $
------------------------------------------------------------------------------*/
@ -60,8 +60,7 @@ UniqueId :: generateId(void) throw ()
// TODO: implement this properly, e.g. use a GUID pattern
// one example is the algorithm found in xdoclet for GUID
Ptr<UniqueId>::Ref id(new UniqueId());
id->id = rand();
Ptr<UniqueId>::Ref id(new UniqueId(rand()));
return id;
}

View file

@ -0,0 +1,129 @@
/*------------------------------------------------------------------------------
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: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/UniqueIdTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include "LiveSupport/Core/UniqueId.h"
#include "UniqueIdTest.h"
using namespace std;
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(UniqueIdTest);
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
UniqueIdTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
UniqueIdTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Test to see if the singleton Hello object is accessible
*----------------------------------------------------------------------------*/
void
UniqueIdTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
UniqueId::IdType idNumeric = 51966;
std::string idAsString = "000000000000cafe";
Ptr<UniqueId>::Ref id;
id.reset(new UniqueId(idNumeric));
CPPUNIT_ASSERT(id->getId() == idNumeric);
CPPUNIT_ASSERT(UniqueId::IdType(*id) == idNumeric);
CPPUNIT_ASSERT(std::string(*id) == idAsString);
id.reset(new UniqueId(idAsString));
CPPUNIT_ASSERT(id->getId() == idNumeric);
CPPUNIT_ASSERT(UniqueId::IdType(*id) == idNumeric);
CPPUNIT_ASSERT(std::string(*id) == idAsString);
id = UniqueId::generateId();
idNumeric = UniqueId::IdType(*id);
idAsString = std::string(*id);
std::stringstream idReader(idAsString);
UniqueId::IdType idNumericCheck;
idReader >> std::hex >> idNumericCheck;
CPPUNIT_ASSERT(idNumeric == idNumericCheck);
// OK if initialized with bad strings, but the integral value is bogus
std::string idAsVeryLongString = "123456789abcdef0123456789abcdef0";
id.reset(new UniqueId(idAsVeryLongString));
CPPUNIT_ASSERT(std::string(*id) == idAsVeryLongString);
// std::cout << std::endl << std::hex << UniqueId::IdType(*id) << std::endl;
std::string idAsSillyString = "this is not a number";
id.reset(new UniqueId(idAsSillyString));
CPPUNIT_ASSERT(std::string(*id) == idAsSillyString);
// std::cout << std::hex << UniqueId::IdType(*id) << std::endl;
/* // this works fine, but please don't use
UniqueId::IdType idSillyNumeric = -3;
id.reset(new UniqueId(idSillyNumeric));
CPPUNIT_ASSERT(UniqueId::IdType(*id) == idSillyNumeric);
CPPUNIT_ASSERT(std::string(*id) == "fffffffffffffffd"); */
}

View file

@ -0,0 +1,107 @@
/*------------------------------------------------------------------------------
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: fgerlits $
Version : $Revision: 1.1 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/core/src/UniqueIdTest.h,v $
------------------------------------------------------------------------------*/
#ifndef UniqueIdTest_h
#define UniqueIdTest_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 UniqueId class.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
* @see UniqueId
*/
class UniqueIdTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(UniqueIdTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(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 // UniqueIdTest_h