From: Kim Kulling Date: Fri, 12 Aug 2016 15:13:18 +0000 (+0200) Subject: closes https://github.com/assimp/assimp/issues/901 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bdcff35d5d9d52f9b4b3d228e3087e6c01effdae;p=platform%2Fupstream%2Fassimp.git closes https://github.com/assimp/assimp/issues/901 --- diff --git a/code/DefaultIOStream.cpp b/code/DefaultIOStream.cpp index f1809d8..73bfb35 100644 --- a/code/DefaultIOStream.cpp +++ b/code/DefaultIOStream.cpp @@ -55,6 +55,7 @@ DefaultIOStream::~DefaultIOStream() { if (mFile) { ::fclose(mFile); + mFile = nullptr; } } @@ -111,7 +112,7 @@ size_t DefaultIOStream::FileSize() const if (SIZE_MAX == cachedSize) { - // Although fseek/ftell would allow us to reuse the exising file handle here, + // Although fseek/ftell would allow us to reuse the existing file handle here, // it is generally unsafe because: // - For binary streams, it is not technically well-defined // - For text files the results are meaningless @@ -125,12 +126,14 @@ size_t DefaultIOStream::FileSize() const if (0 != err) return 0; cachedSize = (size_t) (fileStat.st_size); -#else +#elif defined __gnu_linux__ struct stat fileStat; int err = stat(mFilename.c_str(), &fileStat ); if (0 != err) return 0; cachedSize = (size_t) (fileStat.st_size); +#else +# error "Unknown platform" #endif } return cachedSize; diff --git a/code/DefaultIOStream.h b/code/DefaultIOStream.h index 7d7450c..7798588 100644 --- a/code/DefaultIOStream.h +++ b/code/DefaultIOStream.h @@ -59,11 +59,11 @@ class ASSIMP_API DefaultIOStream : public IOStream { friend class DefaultIOSystem; #if __ANDROID__ -#if __ANDROID_API__ > 9 -#if defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT) +# if __ANDROID_API__ > 9 +# if defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT) friend class AndroidJNIIOSystem; -#endif // defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT) -#endif // __ANDROID_API__ > 9 +# endif // defined(AI_CONFIG_ANDROID_JNI_ASSIMP_MANAGER_SUPPORT) +# endif // __ANDROID_API__ > 9 #endif // __ANDROID__ protected: diff --git a/test/unit/utDefaultIOStream.cpp b/test/unit/utDefaultIOStream.cpp index a4461ea..7d3c07f 100644 --- a/test/unit/utDefaultIOStream.cpp +++ b/test/unit/utDefaultIOStream.cpp @@ -48,7 +48,12 @@ class utDefaultIOStream : public ::testing::Test { class TestDefaultIOStream : public DefaultIOStream { public: TestDefaultIOStream() - : DefaultIOStream() { + : DefaultIOStream() { + // empty + } + + TestDefaultIOStream( FILE* pFile, const std::string &strFilename ) + : DefaultIOStream( pFile, strFilename ) { // empty } @@ -58,7 +63,14 @@ public: }; TEST_F( utDefaultIOStream, FileSizeTest ) { - TestDefaultIOStream myStream; + 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 ); size_t size = myStream.FileSize(); - EXPECT_EQ( size, 0 ); + EXPECT_EQ( size, sizeof( char ) * L_tmpnam ); + remove( buffer ); }