Enable SIBImport test.
parent
2193a93875
commit
c80777f13f
|
@ -40,7 +40,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** @file Defines the StreamReader class which reads data from
|
/** @file Defines the StreamReader class which reads data from
|
||||||
* a binary stream with a well-defined endianness. */
|
* a binary stream with a well-defined endianness.
|
||||||
|
*/
|
||||||
|
|
||||||
#ifndef AI_STREAMREADER_H_INCLUDED
|
#ifndef AI_STREAMREADER_H_INCLUDED
|
||||||
#define AI_STREAMREADER_H_INCLUDED
|
#define AI_STREAMREADER_H_INCLUDED
|
||||||
|
@ -66,9 +67,7 @@ namespace Assimp {
|
||||||
template <bool SwapEndianess = false, bool RuntimeSwitch = false>
|
template <bool SwapEndianess = false, bool RuntimeSwitch = false>
|
||||||
class StreamReader
|
class StreamReader
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// FIXME: use these data types throughout the whole library,
|
// FIXME: use these data types throughout the whole library,
|
||||||
// then change them to 64 bit values :-)
|
// then change them to 64 bit values :-)
|
||||||
|
|
||||||
|
@ -76,8 +75,6 @@ public:
|
||||||
typedef unsigned int pos;
|
typedef unsigned int pos;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Construction from a given stream with a well-defined endianness.
|
/** Construction from a given stream with a well-defined endianness.
|
||||||
*
|
*
|
||||||
|
@ -178,14 +175,12 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Get the remaining stream size (to the end of the srream) */
|
/** Get the remaining stream size (to the end of the stream) */
|
||||||
unsigned int GetRemainingSize() const {
|
unsigned int GetRemainingSize() const {
|
||||||
return (unsigned int)(end - current);
|
return (unsigned int)(end - current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Get the remaining stream size (to the current read limit). The
|
/** Get the remaining stream size (to the current read limit). The
|
||||||
* return value is the remaining size of the stream if no custom
|
* return value is the remaining size of the stream if no custom
|
||||||
|
@ -194,7 +189,6 @@ public:
|
||||||
return (unsigned int)(limit - current);
|
return (unsigned int)(limit - current);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Increase the file pointer (relative seeking) */
|
/** Increase the file pointer (relative seeking) */
|
||||||
void IncPtr(size_t plus) {
|
void IncPtr(size_t plus) {
|
||||||
|
@ -210,7 +204,6 @@ public:
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Set current file pointer (Get it from #GetPtr). This is if you
|
/** Set current file pointer (Get it from #GetPtr). This is if you
|
||||||
* prefer to do pointer arithmetics on your own or want to copy
|
* prefer to do pointer arithmetics on your own or want to copy
|
||||||
|
@ -218,7 +211,6 @@ public:
|
||||||
* @param p The new pointer, which is validated against the size
|
* @param p The new pointer, which is validated against the size
|
||||||
* limit and buffer boundaries. */
|
* limit and buffer boundaries. */
|
||||||
void SetPtr(int8_t* p) {
|
void SetPtr(int8_t* p) {
|
||||||
|
|
||||||
current = p;
|
current = p;
|
||||||
if (current > limit || current < buffer) {
|
if (current > limit || current < buffer) {
|
||||||
throw DeadlyImportError("End of file or read limit was reached");
|
throw DeadlyImportError("End of file or read limit was reached");
|
||||||
|
@ -230,14 +222,12 @@ public:
|
||||||
* @param out Destination for copying
|
* @param out Destination for copying
|
||||||
* @param bytes Number of bytes to copy */
|
* @param bytes Number of bytes to copy */
|
||||||
void CopyAndAdvance(void* out, size_t bytes) {
|
void CopyAndAdvance(void* out, size_t bytes) {
|
||||||
|
|
||||||
int8_t* ur = GetPtr();
|
int8_t* ur = GetPtr();
|
||||||
SetPtr(ur+bytes); // fire exception if eof
|
SetPtr(ur+bytes); // fire exception if eof
|
||||||
|
|
||||||
memcpy(out,ur,bytes);
|
::memcpy(out,ur,bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Get the current offset from the beginning of the file */
|
/** Get the current offset from the beginning of the file */
|
||||||
int GetCurrentPos() const {
|
int GetCurrentPos() const {
|
||||||
|
@ -271,14 +261,14 @@ public:
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Get the current read limit in bytes. Reading over this limit
|
/** Get the current read limit in bytes. Reading over this limit
|
||||||
* accidentially raises an exception. */
|
* accidentally raises an exception. */
|
||||||
unsigned int GetReadLimit() const {
|
unsigned int GetReadLimit() const {
|
||||||
return (unsigned int)(limit - buffer);
|
return (unsigned int)(limit - buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Skip to the read limit in bytes. Reading over this limit
|
/** Skip to the read limit in bytes. Reading over this limit
|
||||||
* accidentially raises an exception. */
|
* accidentally raises an exception. */
|
||||||
void SkipToReadLimit() {
|
void SkipToReadLimit() {
|
||||||
current = limit;
|
current = limit;
|
||||||
}
|
}
|
||||||
|
@ -292,18 +282,17 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
/** Generic read method. ByteSwap::Swap(T*) *must* be defined */
|
/** Generic read method. ByteSwap::Swap(T*) *must* be defined */
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T Get() {
|
T Get() {
|
||||||
if (current + sizeof(T) > limit) {
|
if ( current + sizeof(T) > limit) {
|
||||||
throw DeadlyImportError("End of file or stream limit was reached");
|
throw DeadlyImportError("End of file or stream limit was reached");
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __arm__
|
#ifdef __arm__
|
||||||
T f;
|
T f;
|
||||||
memcpy (&f, current, sizeof(T));
|
::memcpy (&f, current, sizeof(T));
|
||||||
#else
|
#else
|
||||||
T f = *((const T*)current);
|
T f = *((const T*)current);
|
||||||
#endif
|
#endif
|
||||||
|
@ -316,7 +305,7 @@ private:
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
void InternBegin() {
|
void InternBegin() {
|
||||||
if (!stream) {
|
if (!stream) {
|
||||||
// incase someone wonders: StreamReader is frequently invoked with
|
// in case someone wonders: StreamReader is frequently invoked with
|
||||||
// no prior validation whether the input stream is valid. Since
|
// no prior validation whether the input stream is valid. Since
|
||||||
// no one bothers changing the error message, this message here
|
// no one bothers changing the error message, this message here
|
||||||
// is passed down to the caller and 'unable to open file'
|
// is passed down to the caller and 'unable to open file'
|
||||||
|
@ -337,14 +326,11 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<IOStream> stream;
|
std::shared_ptr<IOStream> stream;
|
||||||
int8_t *buffer, *current, *end, *limit;
|
int8_t *buffer, *current, *end, *limit;
|
||||||
bool le;
|
bool le;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------------
|
||||||
// `static` StreamReaders. Their byte order is fixed and they might be a little bit faster.
|
// `static` StreamReaders. Their byte order is fixed and they might be a little bit faster.
|
||||||
#ifdef AI_BUILD_BIG_ENDIAN
|
#ifdef AI_BUILD_BIG_ENDIAN
|
||||||
|
|
|
@ -41,6 +41,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#include "UnitTestPCH.h"
|
#include "UnitTestPCH.h"
|
||||||
|
|
||||||
#include "SIBImporter.h"
|
#include "SIBImporter.h"
|
||||||
|
#include <assimp/Importer.hpp>
|
||||||
|
|
||||||
using namespace ::Assimp;
|
using namespace ::Assimp;
|
||||||
|
|
||||||
|
@ -57,3 +58,10 @@ TEST_F( utSIBImporter, createTest ) {
|
||||||
}
|
}
|
||||||
EXPECT_TRUE( ok );
|
EXPECT_TRUE( ok );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F( utSIBImporter, importTest ) {
|
||||||
|
Assimp::Importer importer;
|
||||||
|
|
||||||
|
const aiScene *scene = importer.ReadFile( ASSIMP_TEST_MODELS_DIR "/SIB/heffalump.sib", 0 );
|
||||||
|
EXPECT_NE( nullptr, scene );
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue