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

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.7 $
Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClient.cxx,v $
------------------------------------------------------------------------------*/
@ -458,9 +458,9 @@ WebStorageClient :: existsAudioClip(Ptr<SessionId>::Ref sessionId,
storageServerPath.c_str(), false);
parameters[existsAudioClipMethodSessionIdParamName]
= sessionId->getId().c_str();
= sessionId->getId();
parameters[existsAudioClipMethodAudioClipIdParamName]
= int(id->getId());
= std::string(*id);
if (!xmlRpcClient.execute(existsAudioClipMethodName.c_str(),
parameters, result)) {
@ -501,9 +501,9 @@ WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId,
storageServerPath.c_str(), false);
parameters[getAudioClipMethodSessionIdParamName]
= sessionId->getId().c_str();
= sessionId->getId();
parameters[getAudioClipMethodAudioClipIdParamName]
= int(id->getId());
= std::string(*id);
if (!xmlRpcClient.execute(getAudioClipMethodName.c_str(),
parameters, result)) {
@ -526,6 +526,29 @@ WebStorageClient :: getAudioClip(Ptr<SessionId>::Ref sessionId,
}
std::string xmlAudioClip(result[getAudioClipMethodResultParamName]);
int offset = 353;
std::cout << "\n" << xmlAudioClip.at(offset+0) << "\n";
std::cout << xmlAudioClip.at(offset+1) << "\n";
std::cout << xmlAudioClip.at(offset+2) << "\n";
std::cout << xmlAudioClip.at(offset+3) << "\n";
std::cout << xmlAudioClip.at(offset+4) << "\n";
std::cout << xmlAudioClip.at(offset+5) << "\n";
std::cout << xmlAudioClip.at(offset+6) << "\n";
std::cout << xmlAudioClip.at(offset+7) << "\n";
std::cout << xmlAudioClip.at(offset+8) << "\n";
std::cout << xmlAudioClip.at(offset+9) << "\n";
std::cout << xmlAudioClip.at(offset+10) << "\n";
std::cout << xmlAudioClip.at(offset+11) << "\n";
std::cout << xmlAudioClip.at(offset+12) << "\n";
std::cout << xmlAudioClip.at(offset+13) << "\n";
std::cout << xmlAudioClip.at(offset+14) << "\n";
std::cout << xmlAudioClip.at(offset+15) << "\n";
std::cout << xmlAudioClip.at(offset+16) << "\n";
std::cout << xmlAudioClip.at(offset+17) << "\n";
std::cout << xmlAudioClip.at(offset+18) << "\n";
std::cout << xmlAudioClip.at(offset+19) << "\n";
std::cout << xmlAudioClip.at(offset+20) << "\n";
Ptr<AudioClip>::Ref audioClip;
try {
@ -721,7 +744,7 @@ WebStorageClient :: reset(void)
<< result;
throw std::logic_error(eMsg.str());
}
Ptr<UniqueId>::Ref uniqueId(new UniqueId(10001 + i)); // TODO: fix!!!
Ptr<UniqueId>::Ref uniqueId(new UniqueId(std::string(uniqueIdArray[i])));
returnValue->push_back(uniqueId);
}

View File

@ -22,7 +22,7 @@
Author : $Author: fgerlits $
Version : $Revision: 1.7 $
Version : $Revision: 1.8 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/WebStorageClientTest.cxx,v $
------------------------------------------------------------------------------*/
@ -159,22 +159,45 @@ void
WebStorageClientTest :: audioClipTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<UniqueId>::Ref id01;
Ptr<UniqueId>::Ref id77(new UniqueId(10077));
Ptr<SessionId>::Ref sessionId;
Ptr<std::vector<Ptr<UniqueId>::Ref> >::Ref uniqueIdVector = wsc->reset();
/*
NOTE: this is incorrect, as WebStorageClient fakes the UniqueId's
TODO: fix!!!
std::cout << "\nReset storage result:\n";
CPPUNIT_ASSERT(uniqueIdVector->size() > 0);
Ptr<UniqueId>::Ref id01 = uniqueIdVector->at(0);
/* std::cout << "\nReset storage result:\n";
for (unsigned i=0; i<uniqueIdVector->size(); i++) {
std::cout << uniqueIdVector->at(i)->getId() << std::endl;
}
*/
CPPUNIT_ASSERT( sessionId = authentication->login("root", "q"));
std::cout << std::hex << uniqueIdVector->at(i)->getId() << std::endl;
} */
CPPUNIT_ASSERT(!wsc->existsAudioClip(sessionId, id77));
Ptr<SessionId>::Ref sessionId = authentication->login("root", "q");
CPPUNIT_ASSERT(sessionId);
bool exists;
try {
exists = wsc->existsAudioClip(sessionId, id01);
}
catch (std::logic_error &e) {
CPPUNIT_FAIL(e.what());
}
CPPUNIT_ASSERT(exists);
/*
Ptr<AudioClip>::Ref audioClip;
try {
audioClip = wsc->getAudioClip(sessionId, id01);
}
catch (std::logic_error &e) {
CPPUNIT_FAIL(e.what());
}
std::cout << "\nid: " << audioClip->getId()->getId()
<< "\nplaylength: " << audioClip->getPlaylength() << "\n";
*/
Ptr<UniqueId>::Ref id77(new UniqueId(10077));
try {
exists = wsc->existsAudioClip(sessionId, id77);
}
catch (std::logic_error &e) {
CPPUNIT_FAIL(e.what());
}
CPPUNIT_ASSERT(!exists);
/*
Ptr<time_duration>::Ref playlength(new time_duration(0,0,11,0));
Ptr<std::string>::Ref uri(new std::string("file:var/test10001.mp3"));

View File

@ -7,7 +7,7 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>
<dc:title >File Title txt</dc:title>
<dcterms:alternative >Alternative File Title txt</dcterms:alternative>
<dcterms:alternative >Alternative File Title ín sőmé %$#@* LÁNGŰAGÉ</dcterms:alternative>
<dc:subject >Keywords: qwe, asd, zcx</dc:subject>
<dc:description >Abstract txt</dc:description>
<dc:date >2004-05-21</dc:date>
@ -30,4 +30,4 @@
<xbmf:name>John X</xbmf:name>
<xbmf:phone>123456789</xbmf:phone>
</xbmf:contributor>
</metadata>
</metadata>