Obj: Fix some small issues
parent
cbe2e9af49
commit
b13c30f50e
|
@ -47,15 +47,43 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
namespace Assimp {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
/**
|
||||
* Implementation of a cached stream buffer.
|
||||
*/
|
||||
template<class T>
|
||||
class IOStreamBuffer {
|
||||
public:
|
||||
/// @brief The class constructor.
|
||||
IOStreamBuffer( size_t cache = 4096 * 4096 );
|
||||
|
||||
/// @brief The class destructor.
|
||||
~IOStreamBuffer();
|
||||
|
||||
/// @brief Will open the cached access for a given stream.
|
||||
/// @param stream The stream to cache.
|
||||
/// @return true if successful.
|
||||
bool open( IOStream *stream );
|
||||
|
||||
/// @brief Will close the cached access.
|
||||
/// @return true if successful.
|
||||
bool close();
|
||||
|
||||
/// @brief Returns the filesize.
|
||||
/// @return The filesize.
|
||||
size_t size() const;
|
||||
|
||||
/// @brief Returns the cache size.
|
||||
/// @return The cache size.
|
||||
size_t cacheSize() const;
|
||||
|
||||
/// @brief Will read the next block.
|
||||
/// @return true if successful.
|
||||
bool readNextBlock();
|
||||
|
||||
/// @brief Will read the next line.
|
||||
/// @param buffer The buffer for the next line.
|
||||
/// @return true if successful.
|
||||
bool getNextLine( std::vector<T> &buffer );
|
||||
|
||||
private:
|
||||
|
@ -69,14 +97,14 @@ private:
|
|||
|
||||
template<class T>
|
||||
inline
|
||||
IOStreamBuffer<T>::IOStreamBuffer( size_t cache = 4096 * 4096 )
|
||||
: m_stream( nullptr )
|
||||
, m_filesize( 0 )
|
||||
, m_cacheSize( cache )
|
||||
, m_cachePos( 0 )
|
||||
, m_filePos( 0 ) {
|
||||
IOStreamBuffer<T>::IOStreamBuffer( size_t cache )
|
||||
: m_stream( nullptr )
|
||||
, m_filesize( 0 )
|
||||
, m_cacheSize( cache )
|
||||
, m_cachePos( 0 )
|
||||
, m_filePos( 0 ) {
|
||||
m_cache.resize( cache );
|
||||
std::fill( m_cache.begin(), m_cache.end(), '\0' );
|
||||
std::fill( m_cache.begin(), m_cache.end(), '\n' );
|
||||
}
|
||||
|
||||
template<class T>
|
||||
|
@ -88,6 +116,10 @@ IOStreamBuffer<T>::~IOStreamBuffer() {
|
|||
template<class T>
|
||||
inline
|
||||
bool IOStreamBuffer<T>::open( IOStream *stream ) {
|
||||
if ( nullptr != m_stream ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( nullptr == stream ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -123,6 +155,12 @@ size_t IOStreamBuffer<T>::size() const {
|
|||
return m_filesize;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
size_t IOStreamBuffer<T>::cacheSize() const {
|
||||
return m_cacheSize;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
bool IOStreamBuffer<T>::readNextBlock() {
|
||||
|
|
|
@ -70,6 +70,7 @@ SET( TEST_SRCS
|
|||
unit/utImporter.cpp
|
||||
unit/utImproveCacheLocality.cpp
|
||||
unit/utIOSystem.cpp
|
||||
unit/utIOStreamBuffer.cpp
|
||||
unit/utIssues.cpp
|
||||
unit/utJoinVertices.cpp
|
||||
unit/utLimitBoneWeights.cpp
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include "DefaultIOStream.h"
|
||||
|
||||
using namespace ::Assimp;
|
||||
|
||||
class TestDefaultIOStream : public DefaultIOStream {
|
||||
public:
|
||||
TestDefaultIOStream()
|
||||
: DefaultIOStream() {
|
||||
// empty
|
||||
}
|
||||
|
||||
TestDefaultIOStream( FILE* pFile, const std::string &strFilename )
|
||||
: DefaultIOStream( pFile, strFilename ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
virtual ~TestDefaultIOStream() {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
|
@ -37,7 +37,7 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
-------------------------------------------------------------------------*/
|
||||
#include <gtest/gtest.h>
|
||||
#include "DefaultIOStream.h"
|
||||
#include "TestIOStream.h"
|
||||
|
||||
using namespace ::Assimp;
|
||||
|
||||
|
@ -45,23 +45,6 @@ class utDefaultIOStream : public ::testing::Test {
|
|||
// empty
|
||||
};
|
||||
|
||||
class TestDefaultIOStream : public DefaultIOStream {
|
||||
public:
|
||||
TestDefaultIOStream()
|
||||
: DefaultIOStream() {
|
||||
// empty
|
||||
}
|
||||
|
||||
TestDefaultIOStream( FILE* pFile, const std::string &strFilename )
|
||||
: DefaultIOStream( pFile, strFilename ) {
|
||||
// empty
|
||||
}
|
||||
|
||||
virtual ~TestDefaultIOStream() {
|
||||
// empty
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F( utDefaultIOStream, FileSizeTest ) {
|
||||
char buffer[ L_tmpnam ];
|
||||
tmpnam( buffer );
|
||||
|
|
|
@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||
|
||||
#include "UnitTestPCH.h"
|
||||
#include "IOStreamBuffer.h"
|
||||
#include "TestIOStream.h"
|
||||
|
||||
class IOStreamBufferTest : public ::testing::Test {
|
||||
// empty
|
||||
|
@ -58,6 +59,33 @@ TEST_F( IOStreamBufferTest, creationTest ) {
|
|||
EXPECT_TRUE( ok );
|
||||
}
|
||||
|
||||
TEST_F( IOStreamBufferTest, accessCacheSizeTest ) {
|
||||
IOStreamBuffer<char> myBuffer1;
|
||||
EXPECT_NE( 0, myBuffer1.cacheSize() );
|
||||
|
||||
IOStreamBuffer<char> myBuffer2( 100 );
|
||||
EXPECT_EQ( 100, myBuffer2.cacheSize() );
|
||||
}
|
||||
|
||||
TEST_F( IOStreamBufferTest, open_close_Test ) {
|
||||
IOStreamBuffer<char> myBuffer;
|
||||
|
||||
EXPECT_FALSE( myBuffer.open( nullptr ) );
|
||||
EXPECT_FALSE( myBuffer.close() );
|
||||
|
||||
char buffer[ L_tmpnam ];
|
||||
tmpnam( buffer );
|
||||
std::FILE *fs( std::fopen( buffer, "w+" ) );
|
||||
size_t written( std::fwrite( buffer, 1, sizeof( char ) * L_tmpnam, fs ) );
|
||||
std::fflush( fs );
|
||||
|
||||
TestDefaultIOStream myStream( fs, buffer );
|
||||
|
||||
EXPECT_TRUE( myBuffer.open( &myStream ) );
|
||||
EXPECT_FALSE( myBuffer.open( &myStream ) );
|
||||
EXPECT_TRUE( myBuffer.close() );
|
||||
}
|
||||
|
||||
TEST_F( IOStreamBufferTest, readlineTest ) {
|
||||
|
||||
}
|
Loading…
Reference in New Issue