got rid of tempnam() and fopen()
This commit is contained in:
parent
accb53809b
commit
321955070f
|
@ -21,8 +21,8 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: maroy $
|
Author : $Author: fgerlits $
|
||||||
Version : $Revision: 1.11 $
|
Version : $Revision: 1.12 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.cxx,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClient.cxx,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -39,6 +39,7 @@
|
||||||
#error "Need unistd.h"
|
#error "Need unistd.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||||
|
|
||||||
#include "TestStorageClient.h"
|
#include "TestStorageClient.h"
|
||||||
|
@ -253,11 +254,24 @@ TestStorageClient :: acquirePlaylist(Ptr<const UniqueId>::Ref id) const
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string smilFileName = "file://";
|
char fileName[] = "/tmp/tempPlaylistXXXXXX";
|
||||||
smilFileName += tempnam(0, "smil");
|
if (!mkstemp(fileName)) {
|
||||||
|
throw std::logic_error("could not create temp file");
|
||||||
|
}
|
||||||
|
std::string sysCommand = "mv ";
|
||||||
|
sysCommand += fileName;
|
||||||
|
sysCommand += " ";
|
||||||
|
sysCommand += fileName;
|
||||||
|
sysCommand += ".smil > /dev/null 2>&1";
|
||||||
|
if (system(sysCommand.c_str()) != 0) {
|
||||||
|
throw std::logic_error("could not rename temp file");
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string smilFileName("file://");
|
||||||
|
smilFileName += fileName;
|
||||||
smilFileName += ".smil";
|
smilFileName += ".smil";
|
||||||
smilDocument->write_to_file(smilFileName, "UTF-8");
|
smilDocument->write_to_file(smilFileName, "UTF-8");
|
||||||
|
|
||||||
Ptr<std::string>::Ref playlistUri(new std::string(smilFileName));
|
Ptr<std::string>::Ref playlistUri(new std::string(smilFileName));
|
||||||
newPlaylist->setUri(playlistUri);
|
newPlaylist->setUri(playlistUri);
|
||||||
return newPlaylist;
|
return newPlaylist;
|
||||||
|
@ -275,15 +289,12 @@ TestStorageClient :: releasePlaylist(Ptr<const Playlist>::Ref playlist) const
|
||||||
throw std::logic_error("playlist URI not found");
|
throw std::logic_error("playlist URI not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
std::ifstream ifs(playlist->getUri()->substr(7).c_str());
|
||||||
std::FILE * f = fopen(playlist->getUri()->substr(7).c_str(), "r");
|
if (ifs) {
|
||||||
if (!f) {
|
ifs.close();
|
||||||
throw std::logic_error("playlist temp file not found");
|
|
||||||
}
|
|
||||||
std::fclose(f);
|
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
else {
|
||||||
throw std::logic_error("playlist temp file I/O error");
|
throw std::logic_error("playlist temp file not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::remove(playlist->getUri()->substr(7).c_str());
|
std::remove(playlist->getUri()->substr(7).c_str());
|
||||||
|
@ -415,16 +426,11 @@ TestStorageClient :: acquireAudioClip(Ptr<const UniqueId>::Ref id) const
|
||||||
// cut the "file:" off
|
// cut the "file:" off
|
||||||
std::string audioClipFileName = storedAudioClip->getUri()->substr(5);
|
std::string audioClipFileName = storedAudioClip->getUri()->substr(5);
|
||||||
|
|
||||||
try {
|
std::ifstream ifs(audioClipFileName.c_str());
|
||||||
std::FILE * f = fopen(audioClipFileName.c_str(), "r");
|
if (ifs) {
|
||||||
if (f) {
|
ifs.close();
|
||||||
std::fclose(f);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw std::logic_error("could not read audio clip");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
else {
|
||||||
throw std::logic_error("could not read audio clip");
|
throw std::logic_error("could not read audio clip");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
|
|
||||||
Author : $Author: fgerlits $
|
Author : $Author: fgerlits $
|
||||||
Version : $Revision: 1.10 $
|
Version : $Revision: 1.11 $
|
||||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClientTest.cxx,v $
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/storage/src/TestStorageClientTest.cxx,v $
|
||||||
|
|
||||||
------------------------------------------------------------------------------*/
|
------------------------------------------------------------------------------*/
|
||||||
|
@ -41,6 +41,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "TestStorageClient.h"
|
#include "TestStorageClient.h"
|
||||||
|
@ -270,12 +271,11 @@ TestStorageClientTest :: acquirePlaylistTest(void)
|
||||||
CPPUNIT_ASSERT(playlist->getUri());
|
CPPUNIT_ASSERT(playlist->getUri());
|
||||||
CPPUNIT_ASSERT(playlist->getUri()->substr(0,7) == "file://");
|
CPPUNIT_ASSERT(playlist->getUri()->substr(0,7) == "file://");
|
||||||
|
|
||||||
try {
|
std::ifstream ifs1(playlist->getUri()->substr(7).c_str());
|
||||||
std::FILE * f = fopen(playlist->getUri()->substr(7).c_str(), "r");
|
if (ifs1) {
|
||||||
CPPUNIT_ASSERT(f);
|
ifs1.close();
|
||||||
std::fclose(f);
|
|
||||||
}
|
}
|
||||||
catch (std::exception &e) {
|
else {
|
||||||
CPPUNIT_FAIL("temp file not created correctly");
|
CPPUNIT_FAIL("temp file not created correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,11 +288,10 @@ TestStorageClientTest :: acquirePlaylistTest(void)
|
||||||
eMsg += e.what();
|
eMsg += e.what();
|
||||||
CPPUNIT_FAIL(eMsg);
|
CPPUNIT_FAIL(eMsg);
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
std::FILE * f = fopen(savedTempFilePath.c_str(), "r");
|
std::ifstream ifs2(playlist->getUri()->substr(7).c_str());
|
||||||
CPPUNIT_ASSERT(!f);
|
if (ifs2) {
|
||||||
}
|
ifs2.close();
|
||||||
catch (std::exception &e) {
|
|
||||||
CPPUNIT_FAIL("temp file not destroyed correctly");
|
CPPUNIT_FAIL("temp file not destroyed correctly");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue