소스 검색

Obj: Fix some small issues

Kim Kulling 8 년 전
부모
커밋
b13c30f50e
5개의 변경된 파일98개의 추가작업 그리고 25개의 파일을 삭제
  1. 45 7
      code/IOStreamBuffer.h
  2. 1 0
      test/CMakeLists.txt
  3. 23 0
      test/unit/TestIOStream.h
  4. 1 18
      test/unit/utDefaultIOStream.cpp
  5. 28 0
      test/unit/utIOStreamBuffer.cpp

+ 45 - 7
code/IOStreamBuffer.h

@@ -47,15 +47,43 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
 namespace Assimp {
 namespace Assimp {
 
 
+// ---------------------------------------------------------------------------
+/**
+ *  Implementation of a cached stream buffer.
+ */
 template<class T>
 template<class T>
 class IOStreamBuffer {
 class IOStreamBuffer {
 public:
 public:
+    /// @brief  The class constructor.
     IOStreamBuffer( size_t cache = 4096 * 4096 );
     IOStreamBuffer( size_t cache = 4096 * 4096 );
+
+    /// @brief  The class destructor.
     ~IOStreamBuffer();
     ~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 );
     bool open( IOStream *stream );
+
+    /// @brief  Will close the cached access.
+    /// @return true if successful.
     bool close();
     bool close();
+
+    /// @brief  Returns the filesize.
+    /// @return The filesize.
     size_t size() const;
     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();
     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 );
     bool getNextLine( std::vector<T> &buffer );
 
 
 private:
 private:
@@ -69,14 +97,14 @@ private:
 
 
 template<class T>
 template<class T>
 inline
 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 );
     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>
 template<class T>
@@ -88,6 +116,10 @@ IOStreamBuffer<T>::~IOStreamBuffer() {
 template<class T>
 template<class T>
 inline
 inline
 bool IOStreamBuffer<T>::open( IOStream *stream ) {
 bool IOStreamBuffer<T>::open( IOStream *stream ) {
+    if ( nullptr != m_stream ) {
+        return false;
+    }
+
     if ( nullptr == stream ) {
     if ( nullptr == stream ) {
         return false;
         return false;
     }
     }
@@ -123,6 +155,12 @@ size_t IOStreamBuffer<T>::size() const {
     return m_filesize;
     return m_filesize;
 }
 }
 
 
+template<class T>
+inline
+size_t IOStreamBuffer<T>::cacheSize() const {
+    return m_cacheSize;
+}
+
 template<class T>
 template<class T>
 inline
 inline
 bool IOStreamBuffer<T>::readNextBlock() {
 bool IOStreamBuffer<T>::readNextBlock() {

+ 1 - 0
test/CMakeLists.txt

@@ -70,6 +70,7 @@ SET( TEST_SRCS
   unit/utImporter.cpp
   unit/utImporter.cpp
   unit/utImproveCacheLocality.cpp
   unit/utImproveCacheLocality.cpp
   unit/utIOSystem.cpp
   unit/utIOSystem.cpp
+  unit/utIOStreamBuffer.cpp
   unit/utIssues.cpp
   unit/utIssues.cpp
   unit/utJoinVertices.cpp
   unit/utJoinVertices.cpp
   unit/utLimitBoneWeights.cpp
   unit/utLimitBoneWeights.cpp

+ 23 - 0
test/unit/TestIOStream.h

@@ -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
+    }
+};
+

+ 1 - 18
test/unit/utDefaultIOStream.cpp

@@ -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.
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 -------------------------------------------------------------------------*/
 -------------------------------------------------------------------------*/
 #include <gtest/gtest.h>
 #include <gtest/gtest.h>
-#include "DefaultIOStream.h"
+#include "TestIOStream.h"
 
 
 using namespace ::Assimp;
 using namespace ::Assimp;
 
 
@@ -45,23 +45,6 @@ class utDefaultIOStream : public ::testing::Test {
     // empty
     // 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 ) {
 TEST_F( utDefaultIOStream, FileSizeTest ) {
     char buffer[ L_tmpnam ];
     char buffer[ L_tmpnam ];
     tmpnam( buffer );
     tmpnam( buffer );

+ 28 - 0
test/unit/utIOStreamBuffer.cpp

@@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 
 #include "UnitTestPCH.h"
 #include "UnitTestPCH.h"
 #include "IOStreamBuffer.h"
 #include "IOStreamBuffer.h"
+#include "TestIOStream.h"
 
 
 class IOStreamBufferTest : public ::testing::Test {
 class IOStreamBufferTest : public ::testing::Test {
     // empty
     // empty
@@ -58,6 +59,33 @@ TEST_F( IOStreamBufferTest, creationTest ) {
     EXPECT_TRUE( ok );
     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 ) {
 TEST_F( IOStreamBufferTest, readlineTest ) {
 
 
 }
 }