PLY: prepare bugfix by adding missing unittest.
This commit is contained in:
@@ -53,9 +53,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
using namespace Assimp;
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
PLY::EDataType PLY::Property::ParseDataType(const char* pCur,const char** pCurOut)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut);
|
||||
PLY::EDataType PLY::Property::ParseDataType(const char* pCur,const char** pCurOut) {
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
|
||||
PLY::EDataType eOut = PLY::EDT_INVALID;
|
||||
|
||||
if (TokenMatch(pCur,"char",4) ||
|
||||
@@ -100,33 +101,25 @@ PLY::EDataType PLY::Property::ParseDataType(const char* pCur,const char** pCurOu
|
||||
DefaultLogger::get()->info("Found unknown data type in PLY file. This is OK");
|
||||
}
|
||||
*pCurOut = pCur;
|
||||
|
||||
return eOut;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
PLY::ESemantic PLY::Property::ParseSemantic(const char* pCur,const char** pCurOut)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut);
|
||||
PLY::ESemantic PLY::Property::ParseSemantic(const char* pCur,const char** pCurOut) {
|
||||
ai_assert (NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
|
||||
PLY::ESemantic eOut = PLY::EST_INVALID;
|
||||
if (TokenMatch(pCur,"red",3))
|
||||
{
|
||||
if (TokenMatch(pCur,"red",3)) {
|
||||
eOut = PLY::EST_Red;
|
||||
}
|
||||
else if (TokenMatch(pCur,"green",5))
|
||||
{
|
||||
} else if (TokenMatch(pCur,"green",5)) {
|
||||
eOut = PLY::EST_Green;
|
||||
}
|
||||
else if (TokenMatch(pCur,"blue",4))
|
||||
{
|
||||
} else if (TokenMatch(pCur,"blue",4)) {
|
||||
eOut = PLY::EST_Blue;
|
||||
}
|
||||
else if (TokenMatch(pCur,"alpha",5))
|
||||
{
|
||||
} else if (TokenMatch(pCur,"alpha",5)) {
|
||||
eOut = PLY::EST_Alpha;
|
||||
}
|
||||
else if (TokenMatch(pCur,"vertex_index",12) || TokenMatch(pCur,"vertex_indices",14))
|
||||
{
|
||||
} else if (TokenMatch(pCur,"vertex_index",12) || TokenMatch(pCur,"vertex_indices",14)) {
|
||||
eOut = PLY::EST_VertexIndex;
|
||||
}
|
||||
else if (TokenMatch(pCur,"material_index",14))
|
||||
@@ -248,7 +241,8 @@ bool PLY::Property::ParseProperty (const char* pCur,
|
||||
const char** pCurOut,
|
||||
PLY::Property* pOut)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
|
||||
// Forms supported:
|
||||
// "property float x"
|
||||
@@ -256,7 +250,9 @@ bool PLY::Property::ParseProperty (const char* pCur,
|
||||
*pCurOut = pCur;
|
||||
|
||||
// skip leading spaces
|
||||
if (!SkipSpaces(pCur,&pCur))return false;
|
||||
if (!SkipSpaces(pCur,&pCur)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// skip the "property" string at the beginning
|
||||
if (!TokenMatch(pCur,"property",8))
|
||||
@@ -265,7 +261,9 @@ bool PLY::Property::ParseProperty (const char* pCur,
|
||||
return false;
|
||||
}
|
||||
// get next word
|
||||
if (!SkipSpaces(pCur,&pCur))return false;
|
||||
if (!SkipSpaces(pCur,&pCur)) {
|
||||
return false;
|
||||
}
|
||||
if (TokenMatch(pCur,"list",4))
|
||||
{
|
||||
pOut->bIsList = true;
|
||||
@@ -313,6 +311,7 @@ bool PLY::Property::ParseProperty (const char* pCur,
|
||||
|
||||
SkipSpacesAndLineEnd(pCur,&pCur);
|
||||
*pCurOut = pCur;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -350,6 +349,7 @@ PLY::EElementSemantic PLY::Element::ParseSemantic(const char* pCur,
|
||||
eOut = PLY::EEST_Material;
|
||||
}
|
||||
*pCurOut = pCur;
|
||||
|
||||
return eOut;
|
||||
}
|
||||
|
||||
@@ -358,13 +358,17 @@ bool PLY::Element::ParseElement (const char* pCur,
|
||||
const char** pCurOut,
|
||||
PLY::Element* pOut)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
ai_assert( NULL != pOut );
|
||||
|
||||
// Example format: "element vertex 8"
|
||||
*pCurOut = pCur;
|
||||
|
||||
// skip leading spaces
|
||||
if (!SkipSpaces(&pCur))return false;
|
||||
if (!SkipSpaces(&pCur)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// skip the "element" string at the beginning
|
||||
if (!TokenMatch(pCur,"element",7))
|
||||
@@ -405,6 +409,7 @@ bool PLY::Element::ParseElement (const char* pCur,
|
||||
pOut->alProperties.push_back(prop);
|
||||
}
|
||||
*pCurOut = pCur;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -412,30 +417,35 @@ bool PLY::Element::ParseElement (const char* pCur,
|
||||
bool PLY::DOM::SkipComments (const char* pCur,
|
||||
const char** pCurOut)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
*pCurOut = pCur;
|
||||
|
||||
// skip spaces
|
||||
if (!SkipSpaces(pCur,&pCur))return false;
|
||||
if (!SkipSpaces(pCur,&pCur)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (TokenMatch(pCur,"comment",7))
|
||||
{
|
||||
if ( !IsLineEnd(pCur[-1]) )
|
||||
{
|
||||
SkipLine(pCur,&pCur);
|
||||
}
|
||||
if ( !IsLineEnd(pCur[-1]) )
|
||||
{
|
||||
SkipLine(pCur,&pCur);
|
||||
}
|
||||
SkipComments(pCur,&pCur);
|
||||
*pCurOut = pCur;
|
||||
return true;
|
||||
}
|
||||
*pCurOut = pCur;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool PLY::DOM::ParseHeader (const char* pCur,const char** pCurOut,bool isBinary)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut);
|
||||
bool PLY::DOM::ParseHeader (const char* pCur,const char** pCurOut,bool isBinary) {
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
|
||||
DefaultLogger::get()->debug("PLY::DOM::ParseHeader() begin");
|
||||
|
||||
// after ply and format line
|
||||
@@ -479,7 +489,8 @@ bool PLY::DOM::ParseElementInstanceLists (
|
||||
const char* pCur,
|
||||
const char** pCurOut)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
|
||||
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceLists() begin");
|
||||
*pCurOut = pCur;
|
||||
@@ -507,7 +518,8 @@ bool PLY::DOM::ParseElementInstanceListsBinary (
|
||||
const char** pCurOut,
|
||||
bool p_bBE)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut);
|
||||
|
||||
DefaultLogger::get()->debug("PLY::DOM::ParseElementInstanceListsBinary() begin");
|
||||
*pCurOut = pCur;
|
||||
@@ -532,7 +544,8 @@ bool PLY::DOM::ParseElementInstanceListsBinary (
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
bool PLY::DOM::ParseInstanceBinary (const char* pCur,DOM* p_pcOut,bool p_bBE)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != p_pcOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != p_pcOut );
|
||||
|
||||
DefaultLogger::get()->debug("PLY::DOM::ParseInstanceBinary() begin");
|
||||
|
||||
@@ -580,7 +593,10 @@ bool PLY::ElementInstanceList::ParseInstanceList (
|
||||
const PLY::Element* pcElement,
|
||||
PLY::ElementInstanceList* p_pcOut)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
ai_assert( NULL != pcElement );
|
||||
ai_assert( NULL != p_pcOut );
|
||||
|
||||
if (EEST_INVALID == pcElement->eSemantic || pcElement->alProperties.empty())
|
||||
{
|
||||
@@ -614,7 +630,10 @@ bool PLY::ElementInstanceList::ParseInstanceListBinary (
|
||||
PLY::ElementInstanceList* p_pcOut,
|
||||
bool p_bBE /* = false */)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
ai_assert( NULL != pcElement );
|
||||
ai_assert( NULL != p_pcOut );
|
||||
|
||||
// we can add special handling code for unknown element semantics since
|
||||
// we can't skip it as a whole block (we don't know its exact size
|
||||
@@ -636,9 +655,14 @@ bool PLY::ElementInstance::ParseInstance (
|
||||
const PLY::Element* pcElement,
|
||||
PLY::ElementInstance* p_pcOut)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
ai_assert( NULL != pcElement );
|
||||
ai_assert( NULL != p_pcOut );
|
||||
|
||||
if (!SkipSpaces(pCur, &pCur))return false;
|
||||
if (!SkipSpaces(pCur, &pCur)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// allocate enough storage
|
||||
p_pcOut->alProperties.resize(pcElement->alProperties.size());
|
||||
@@ -671,7 +695,10 @@ bool PLY::ElementInstance::ParseInstanceBinary (
|
||||
PLY::ElementInstance* p_pcOut,
|
||||
bool p_bBE /* = false */)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut && NULL != pcElement && NULL != p_pcOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
ai_assert( NULL != pcElement );
|
||||
ai_assert( NULL != p_pcOut );
|
||||
|
||||
// allocate enough storage
|
||||
p_pcOut->alProperties.resize(pcElement->alProperties.size());
|
||||
@@ -696,12 +723,17 @@ bool PLY::ElementInstance::ParseInstanceBinary (
|
||||
bool PLY::PropertyInstance::ParseInstance (const char* pCur,const char** pCurOut,
|
||||
const PLY::Property* prop, PLY::PropertyInstance* p_pcOut)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut && NULL != prop && NULL != p_pcOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
ai_assert( NULL != prop );
|
||||
ai_assert( NULL != p_pcOut );
|
||||
|
||||
*pCurOut = pCur;
|
||||
|
||||
// skip spaces at the beginning
|
||||
if (!SkipSpaces(pCur, &pCur))return false;
|
||||
if (!SkipSpaces(pCur, &pCur)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (prop->bIsList)
|
||||
{
|
||||
@@ -741,7 +773,10 @@ bool PLY::PropertyInstance::ParseInstanceBinary (
|
||||
PLY::PropertyInstance* p_pcOut,
|
||||
bool p_bBE)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut && NULL != prop && NULL != p_pcOut);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
ai_assert( NULL != prop );
|
||||
ai_assert( NULL != p_pcOut );
|
||||
|
||||
if (prop->bIsList)
|
||||
{
|
||||
@@ -770,8 +805,7 @@ bool PLY::PropertyInstance::ParseInstanceBinary (
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
PLY::PropertyInstance::ValueUnion PLY::PropertyInstance::DefaultValue(
|
||||
PLY::EDataType eType)
|
||||
PLY::PropertyInstance::ValueUnion PLY::PropertyInstance::DefaultValue( PLY::EDataType eType )
|
||||
{
|
||||
PLY::PropertyInstance::ValueUnion out;
|
||||
|
||||
@@ -798,7 +832,9 @@ bool PLY::PropertyInstance::ParseValue(
|
||||
PLY::EDataType eType,
|
||||
PLY::PropertyInstance::ValueUnion* out)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut && NULL != out);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
ai_assert( NULL != out );
|
||||
|
||||
bool ret = true;
|
||||
*pCurOut = pCur;
|
||||
@@ -827,7 +863,6 @@ bool PLY::PropertyInstance::ParseValue(
|
||||
break;
|
||||
|
||||
case EDT_Double:
|
||||
|
||||
double d;
|
||||
pCur = fast_atoreal_move<double>(pCur,d);
|
||||
out->fDouble = (double)d;
|
||||
@@ -835,8 +870,10 @@ bool PLY::PropertyInstance::ParseValue(
|
||||
|
||||
default:
|
||||
ret = false;
|
||||
break;
|
||||
}
|
||||
*pCurOut = pCur;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -848,7 +885,9 @@ bool PLY::PropertyInstance::ParseValueBinary(
|
||||
PLY::PropertyInstance::ValueUnion* out,
|
||||
bool p_bBE)
|
||||
{
|
||||
ai_assert(NULL != pCur && NULL != pCurOut && NULL != out);
|
||||
ai_assert( NULL != pCur );
|
||||
ai_assert( NULL != pCurOut );
|
||||
ai_assert( NULL != out );
|
||||
|
||||
bool ret = true;
|
||||
switch (eType)
|
||||
@@ -925,6 +964,7 @@ bool PLY::PropertyInstance::ParseValueBinary(
|
||||
ret = false;
|
||||
}
|
||||
*pCurOut = pCur;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user