Tests how o adress this topic.

pull/1289/head
Kim Kulling 2017-05-28 22:25:06 +02:00
parent 8cc80a3d9c
commit d30b1e585c
3 changed files with 53 additions and 10 deletions

View File

@ -161,7 +161,7 @@ void ObjFileParser::parseFile( IOStreamBuffer<char> &streamBuffer ) {
{ {
++m_DataIt; ++m_DataIt;
if (*m_DataIt == ' ' || *m_DataIt == '\t') { if (*m_DataIt == ' ' || *m_DataIt == '\t') {
size_t numComponents = getNumComponentsInLine(); size_t numComponents = getNumComponentsInDataDefinition();
if (numComponents == 3) { if (numComponents == 3) {
// read in vertex definition // read in vertex definition
getVector3(m_pModel->m_Vertices); getVector3(m_pModel->m_Vertices);
@ -274,21 +274,40 @@ void ObjFileParser::copyNextWord(char *pBuffer, size_t length) {
pBuffer[index] = '\0'; pBuffer[index] = '\0';
} }
size_t ObjFileParser::getNumComponentsInLine() { static bool isDataDefinitionEnd( const char *tmp ) {
if ( *tmp == '\\' ) {
tmp++;
if ( IsLineEnd( tmp ) ) {
return false;
}
} else {
return IsLineEnd( tmp );
}
return false;
}
size_t ObjFileParser::getNumComponentsInDataDefinition() {
size_t numComponents( 0 ); size_t numComponents( 0 );
const char* tmp( &m_DataIt[0] ); const char* tmp( &m_DataIt[0] );
while( !IsLineEnd( *tmp ) ) { while ( !isDataDefinitionEnd( tmp ) ) {
//while( !IsLineEnd( *tmp ) ) {
if ( !SkipSpaces( &tmp ) ) { if ( !SkipSpaces( &tmp ) ) {
break; break;
} }
const bool isNum( IsNumeric( *tmp ) );
SkipToken( tmp ); SkipToken( tmp );
if ( isNum ) {
++numComponents; ++numComponents;
} }
if ( !SkipSpaces( &tmp ) ) {
break;
}
}
return numComponents; return numComponents;
} }
void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) { void ObjFileParser::getVector( std::vector<aiVector3D> &point3d_array ) {
size_t numComponents = getNumComponentsInLine(); size_t numComponents = getNumComponentsInDataDefinition();
ai_real x, y, z; ai_real x, y, z;
if( 2 == numComponents ) { if( 2 == numComponents ) {
copyNextWord( m_buffer, Buffersize ); copyNextWord( m_buffer, Buffersize );

View File

@ -91,6 +91,8 @@ protected:
void copyNextWord(char *pBuffer, size_t length); void copyNextWord(char *pBuffer, size_t length);
/// Method to copy the new line. /// Method to copy the new line.
// void copyNextLine(char *pBuffer, size_t length); // void copyNextLine(char *pBuffer, size_t length);
/// Get the number of components in a line.
size_t getNumComponentsInDataDefinition();
/// Stores the vector /// Stores the vector
void getVector( std::vector<aiVector3D> &point3d_array ); void getVector( std::vector<aiVector3D> &point3d_array );
/// Stores the following 3d vector. /// Stores the following 3d vector.
@ -129,8 +131,6 @@ protected:
bool needsNewMesh( const std::string &rMaterialName ); bool needsNewMesh( const std::string &rMaterialName );
/// Error report in token /// Error report in token
void reportErrorTokenInFace(); void reportErrorTokenInFace();
/// Get the number of components in a line.
size_t getNumComponentsInLine();
private: private:
// Copy and assignment constructor should be private // Copy and assignment constructor should be private

View File

@ -51,13 +51,23 @@ class utObjTools : public ::testing::Test {
class TestObjFileParser : public ObjFileParser { class TestObjFileParser : public ObjFileParser {
public: public:
TestObjFileParser() : ObjFileParser(){} TestObjFileParser() : ObjFileParser(){
~TestObjFileParser() {} // empty
}
~TestObjFileParser() {
// empty
}
void testCopyNextWord( char *pBuffer, size_t length ) { void testCopyNextWord( char *pBuffer, size_t length ) {
copyNextWord( pBuffer, length ); copyNextWord( pBuffer, length );
} }
size_t testGetNumComponentsInDataDefinition() {
return getNumComponentsInDataDefinition();
}
}; };
TEST_F( utObjTools, skipDataLine_OneLine_Success ) { TEST_F( utObjTools, skipDataLine_OneLine_Success ) {
std::vector<char> buffer; std::vector<char> buffer;
std::string data( "v -0.5 -0.5 0.5\nend" ); std::string data( "v -0.5 -0.5 0.5\nend" );
@ -91,3 +101,17 @@ TEST_F( utObjTools, skipDataLine_TwoLines_Success ) {
test_parser.testCopyNextWord( data_buffer, Size ); test_parser.testCopyNextWord( data_buffer, Size );
EXPECT_EQ( data_buffer[ 0 ], '-' ); EXPECT_EQ( data_buffer[ 0 ], '-' );
} }
TEST_F( utObjTools, countComponents_TwoLines_Success ) {
TestObjFileParser test_parser;
std::string data( "-2.061493116917992e-15 -0.9009688496589661 \\n-0.4338837265968323" );
std::vector<char> buffer;
buffer.resize( data.size() );
::memcpy( &buffer[ 0 ], &data[ 0 ], data.size() );
test_parser.setBuffer( buffer );
static const size_t Size = 4096UL;
char data_buffer[ Size ];
size_t numComps = test_parser.testGetNumComponentsInDataDefinition();
EXPECT_EQ( 3U, numComps );
}