pull/1468/head
Kim Kulling 2017-09-29 21:59:11 +02:00
commit 5adc029225
6 changed files with 135 additions and 56 deletions

View File

@ -1118,11 +1118,12 @@ inline std::string Asset::FindUniqueID(const std::string& str, const char* suffi
if (it == mUsedIds.end())
return id;
char buffer[256];
int offset = ai_snprintf(buffer, sizeof(buffer), "%s_", id.c_str());
std::vector<char> buffer;
buffer.resize(id.size() + 16);
int offset = ai_snprintf(buffer.data(), buffer.size(), "%s_", id.c_str());
for (int i = 0; it != mUsedIds.end(); ++i) {
ai_snprintf(buffer + offset, sizeof(buffer) - offset, "%d", i);
id = buffer;
ai_snprintf(buffer.data() + offset, buffer.size() - offset, "%d", i);
id = buffer.data();
it = mUsedIds.find(id);
}

View File

@ -32,7 +32,7 @@
/***********************************************************************
* Return the next byte in the pseudo-random sequence
*/
static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
static int decrypt_byte(unsigned long* pkeys, const z_crc_t* pcrc_32_tab)
{
unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an
* unpredictable manner on 16-bit systems; not a problem
@ -45,7 +45,7 @@ static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab)
/***********************************************************************
* Update the encryption keys with the next byte of plain text
*/
static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c)
static int update_keys(unsigned long* pkeys,const z_crc_t* pcrc_32_tab,int c)
{
(*(pkeys+0)) = CRC32((*(pkeys+0)), c);
(*(pkeys+1)) += (*(pkeys+0)) & 0xff;
@ -62,7 +62,7 @@ static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int
* Initialize the encryption keys and the random header according to
* the given password.
*/
static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab)
static void init_keys(const char* passwd,unsigned long* pkeys,const z_crc_t* pcrc_32_tab)
{
*(pkeys+0) = 305419896L;
*(pkeys+1) = 591751049L;

View File

@ -147,7 +147,7 @@ typedef struct
int encrypted;
# ifndef NOUNCRYPT
unsigned long keys[3]; /* keys defining the pseudo-random sequence */
const unsigned long* pcrc_32_tab;
const z_crc_t* pcrc_32_tab;
# endif
} unz_s;

View File

@ -0,0 +1,76 @@
/*
---------------------------------------------------------------------------
Open Asset Import Library (assimp)
---------------------------------------------------------------------------
Copyright (c) 2006-2017, assimp team
All rights reserved.
Redistribution and use of this software in source and binary forms,
with or without modification, are permitted provided that the following
conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* Neither the name of the assimp team, nor the names of its
contributors may be used to endorse or promote products
derived from this software without specific prior
written permission of the assimp team.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
---------------------------------------------------------------------------
*/
#pragma once
#include <cstdio>
#include <cstdlib>
#include <gtest/gtest.h>
#if defined(__GNUC__) || defined(__clang__)
#define TMP_PATH "/tmp/"
inline FILE* MakeTmpFile(char* tmplate)
{
auto fd = mkstemp(tmplate);
EXPECT_NE(-1, fd);
if(fd == -1)
{
return nullptr;
}
auto fs = fdopen(fd, "w+");
EXPECT_NE(nullptr, fs);
return fs;
}
#elif defined(_MSC_VER)
#include <io.h>
#define TMP_PATH "./"
inline FILE* MakeTmpFile(char* tmplate)
{
auto pathtemplate = _mktemp(tmplate);
EXPECT_NE(pathtemplate, nullptr);
if(pathtemplate == nullptr)
{
return nullptr;
}
auto* fs = std::fopen(pathtemplate, "w+");
EXPECT_NE(fs, nullptr);
return fs;
}
#endif

View File

@ -39,35 +39,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------*/
#include <gtest/gtest.h>
#include "TestIOStream.h"
#include "UnitTestFileGenerator.h"
#include <cstdio>
#include <cstdlib>
#include <string>
#if defined(__GNUC__) || defined(__clang__)
#define TMP_PATH "/tmp/"
void MakeTmpFilePath(char* tmplate)
{
auto err = mkstemp(tmplate);
ASSERT_NE(err, -1);
}
#elif defined(_MSC_VER)
#include <io.h>
#define TMP_PATH "./"
void MakeTmpFilePath(char* tmplate)
{
auto pathtemplate = _mktemp(tmplate);
ASSERT_NE(pathtemplate, nullptr);
}
#endif
using namespace ::Assimp;
class utDefaultIOStream : public ::testing::Test {
// empty
};
const char data[]{"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Qui\
sque luctus sem diam, ut eleifend arcu auctor eu. Vestibulum id est vel nulla l\
obortis malesuada ut sed turpis. Nulla a volutpat tortor. Nunc vestibulum portt\
@ -78,18 +60,18 @@ TEST_F( utDefaultIOStream, FileSizeTest ) {
const auto dataCount = dataSize / sizeof(*data);
char fpath[] = { TMP_PATH"rndfp.XXXXXX" };
MakeTmpFilePath(fpath);
auto* fs = MakeTmpFile(fpath);
ASSERT_NE(nullptr, fs);
{
auto written = std::fwrite(data, sizeof(*data), dataCount, fs );
EXPECT_NE( 0U, written );
auto *fs = std::fopen(fpath, "w+" );
ASSERT_NE(fs, nullptr);
auto written = std::fwrite(data, sizeof(*data), dataCount, fs );
EXPECT_NE( 0U, written );
auto vflush = std::fflush( fs );
ASSERT_EQ(vflush, 0);
auto vflush = std::fflush( fs );
ASSERT_EQ(vflush, 0);
TestDefaultIOStream myStream( fs, fpath);
size_t size = myStream.FileSize();
EXPECT_EQ( size, dataSize);
TestDefaultIOStream myStream( fs, fpath);
size_t size = myStream.FileSize();
EXPECT_EQ( size, dataSize);
}
remove(fpath);
}

View File

@ -43,6 +43,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "UnitTestPCH.h"
#include "IOStreamBuffer.h"
#include "TestIOStream.h"
#include "UnitTestFileGenerator.h"
class IOStreamBufferTest : public ::testing::Test {
// empty
@ -68,40 +69,59 @@ TEST_F( IOStreamBufferTest, accessCacheSizeTest ) {
EXPECT_EQ( 100U, myBuffer2.cacheSize() );
}
const char data[]{"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Qui\
sque luctus sem diam, ut eleifend arcu auctor eu. Vestibulum id est vel nulla l\
obortis malesuada ut sed turpis. Nulla a volutpat tortor. Nunc vestibulum portt\
itor sapien ornare sagittis volutpat."};
TEST_F( IOStreamBufferTest, open_close_Test ) {
IOStreamBuffer<char> myBuffer;
EXPECT_FALSE( myBuffer.open( nullptr ) );
EXPECT_FALSE( myBuffer.close() );
const auto dataSize = sizeof(data);
const auto dataCount = dataSize / sizeof(*data);
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 ) );
char fname[]={ "octest.XXXXXX" };
auto* fs = MakeTmpFile(fname);
ASSERT_NE(nullptr, fs);
auto written = std::fwrite( data, sizeof(*data), dataCount, fs );
EXPECT_NE( 0U, written );
std::fflush( fs );
{
TestDefaultIOStream myStream( fs, fname );
TestDefaultIOStream myStream( fs, buffer );
EXPECT_TRUE( myBuffer.open( &myStream ) );
EXPECT_FALSE( myBuffer.open( &myStream ) );
EXPECT_TRUE( myBuffer.close() );
EXPECT_TRUE( myBuffer.open( &myStream ) );
EXPECT_FALSE( myBuffer.open( &myStream ) );
EXPECT_TRUE( myBuffer.close() );
}
remove(fname);
}
TEST_F( IOStreamBufferTest, readlineTest ) {
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 ) );
const auto dataSize = sizeof(data);
const auto dataCount = dataSize / sizeof(*data);
char fname[]={ "readlinetest.XXXXXX" };
auto* fs = MakeTmpFile(fname);
ASSERT_NE(nullptr, fs);
auto written = std::fwrite( data, sizeof(*data), dataCount, fs );
EXPECT_NE( 0U, written );
std::fflush( fs );
IOStreamBuffer<char> myBuffer( 26 );
EXPECT_EQ( 26U, myBuffer.cacheSize() );
const auto tCacheSize = 26u;
TestDefaultIOStream myStream( fs, buffer );
size_t size( myStream.FileSize() );
size_t numBlocks( size / myBuffer.cacheSize() );
IOStreamBuffer<char> myBuffer( tCacheSize );
EXPECT_EQ(tCacheSize, myBuffer.cacheSize() );
TestDefaultIOStream myStream( fs, fname );
auto size = myStream.FileSize();
auto numBlocks = size / myBuffer.cacheSize();
if ( size % myBuffer.cacheSize() > 0 ) {
numBlocks++;
}