1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-03 17:56:21 +03:00

0024537: GCC compiler warnings in byte order reversion code

Eliminate warnings in byte order inversion functionality by using unions.
Add test case simulating conversion to big endian.
This commit is contained in:
rkv 2015-09-24 14:17:41 +03:00 committed by kgv
parent 81b47143f1
commit 10a4116e31
6 changed files with 441 additions and 134 deletions

View File

@ -24,6 +24,7 @@
#include <TDF_Data.hxx>
#include <TDF_Label.hxx>
#include <TDF_Tool.hxx>
#include <FSD_BinaryFile.hxx>
#define BP_INTSIZE ((Standard_Integer)sizeof(Standard_Integer))
#define BP_EXTCHARSIZE ((Standard_Integer)sizeof(Standard_ExtCharacter))
@ -1053,7 +1054,7 @@ void BinObjMgt_Persistent::inverseExtCharData
Standard_ExtCharacter *aData = (Standard_ExtCharacter*)
( (char*) myData(anIndex) + anOffset);
for (Standard_Integer i=0; i < aLenInPiece / BP_EXTCHARSIZE; i++)
aData[i] = InverseExtChar (aData[i]);
aData[i] = FSD_BinaryFile::InverseExtChar (aData[i]);
aLen -= aLenInPiece;
anOffset += aLenInPiece;
if (anOffset >= BP_PIECESIZE) {
@ -1080,7 +1081,7 @@ void BinObjMgt_Persistent::inverseIntData
Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
Standard_Integer *aData = (Standard_Integer*) ((char*)myData(anIndex) + anOffset);
for (Standard_Integer i=0; i < aLenInPiece / BP_INTSIZE; i++)
aData[i] = InverseInt (aData[i]);
aData[i] = FSD_BinaryFile::InverseInt (aData[i]);
aLen -= aLenInPiece;
anOffset += aLenInPiece;
if (anOffset >= BP_PIECESIZE) {
@ -1103,22 +1104,30 @@ void BinObjMgt_Persistent::inverseRealData
Standard_Integer anIndex = theIndex;
Standard_Integer anOffset = theOffset;
Standard_Integer aLen = theSize;
union {
Standard_Real* aRealData;
Standard_Integer* aIntData;
} aWrapUnion;
void *aPrevPtr = 0;
while (aLen > 0) {
Standard_Integer aLenInPiece = Min (aLen, BP_PIECESIZE - anOffset);
Standard_Real *aData = (Standard_Real*) ((char*)myData(anIndex) + anOffset);
aWrapUnion.aRealData = (Standard_Real*) ((char*)myData(anIndex) + anOffset);
if (aPrevPtr) {
Standard_Integer aTmp;
aTmp = InverseInt (*(Standard_Integer*)aPrevPtr);
*(Standard_Integer*)aPrevPtr = InverseInt (*(Standard_Integer*)aData);
*(Standard_Integer*)aData = aTmp;
((Standard_Integer*&)aData)++;
aTmp = FSD_BinaryFile::InverseInt (*(Standard_Integer*)aPrevPtr);
*(Standard_Integer*)aPrevPtr = FSD_BinaryFile::InverseInt (*aWrapUnion.aIntData);
*aWrapUnion.aIntData = aTmp;
aWrapUnion.aIntData++;
aPrevPtr = 0;
}
for (Standard_Integer i=0; i < aLenInPiece / BP_REALSIZE; i++)
aData[i] = InverseReal (aData[i]);
aWrapUnion.aRealData[i] = FSD_BinaryFile::InverseReal(aWrapUnion.aRealData[i]);
if (aLenInPiece % BP_REALSIZE)
aPrevPtr = &aData[aLenInPiece / BP_REALSIZE];
aPrevPtr = &aWrapUnion.aRealData[aLenInPiece / BP_REALSIZE];
aLen -= aLenInPiece;
anOffset += aLenInPiece;
if (anOffset >= BP_PIECESIZE) {
@ -1146,7 +1155,7 @@ void BinObjMgt_Persistent::inverseShortRealData
Standard_ShortReal *aData =
(Standard_ShortReal *) ((char *)myData(anIndex) + anOffset);
for (Standard_Integer i=0; i < aLenInPiece / BP_INTSIZE; i++)
aData[i] = InverseShortReal (aData[i]);
aData[i] = FSD_BinaryFile::InverseShortReal (aData[i]);
aLen -= aLenInPiece;
anOffset += aLenInPiece;
if (anOffset >= BP_PIECESIZE) {

View File

@ -23,6 +23,7 @@
#include <Storage_StreamWriteError.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <Standard_Assert.hxx>
const Standard_CString MAGICNUMBER = "BINFILE";
@ -190,7 +191,7 @@ void FSD_BinaryFile::SkipObject()
Storage_BaseDriver& FSD_BinaryFile::PutReference(const Standard_Integer aValue)
{
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
Standard_Integer t = InverseInt (aValue);
if (!fwrite(&t,sizeof(Standard_Integer),1,myStream)) Storage_StreamWriteError::Raise();
@ -218,7 +219,7 @@ Storage_BaseDriver& FSD_BinaryFile::PutCharacter(const Standard_Character aValue
Storage_BaseDriver& FSD_BinaryFile::PutExtCharacter(const Standard_ExtCharacter aValue)
{
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
Standard_ExtCharacter t = InverseExtChar (aValue);
if (!fwrite(&t,sizeof(Standard_ExtCharacter),1,myStream)) Storage_StreamWriteError::Raise();
@ -235,7 +236,7 @@ Storage_BaseDriver& FSD_BinaryFile::PutExtCharacter(const Standard_ExtCharacter
Storage_BaseDriver& FSD_BinaryFile::PutInteger(const Standard_Integer aValue)
{
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
Standard_Integer t = InverseInt (aValue);
if (!fwrite(&t,sizeof(Standard_Integer),1,myStream)) Storage_StreamWriteError::Raise();
@ -253,7 +254,7 @@ Storage_BaseDriver& FSD_BinaryFile::PutInteger(const Standard_Integer aValue)
Storage_BaseDriver& FSD_BinaryFile::PutBoolean(const Standard_Boolean aValue)
{
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
Standard_Integer t = InverseInt ((Standard_Integer) aValue);
if (!fwrite(&t,sizeof(Standard_Integer),1,myStream)) Storage_StreamWriteError::Raise();
@ -270,7 +271,7 @@ Storage_BaseDriver& FSD_BinaryFile::PutBoolean(const Standard_Boolean aValue)
Storage_BaseDriver& FSD_BinaryFile::PutReal(const Standard_Real aValue)
{
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
Standard_Real t = InverseReal (aValue);
if (!fwrite(&t,sizeof(Standard_Real),1,myStream)) Storage_StreamWriteError::Raise();
@ -287,7 +288,7 @@ Storage_BaseDriver& FSD_BinaryFile::PutReal(const Standard_Real aValue)
Storage_BaseDriver& FSD_BinaryFile::PutShortReal(const Standard_ShortReal aValue)
{
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
Standard_ShortReal t = InverseShortReal (aValue);
if (!fwrite(&t,sizeof(Standard_ShortReal),1,myStream)) Storage_StreamWriteError::Raise();
@ -306,7 +307,7 @@ Storage_BaseDriver& FSD_BinaryFile::GetReference(Standard_Integer& aValue)
{
if (!fread(&aValue,sizeof(Standard_Integer),1,myStream))
Storage_StreamTypeMismatchError::Raise();
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
aValue = InverseInt (aValue);
#endif
return *this;
@ -333,7 +334,7 @@ Storage_BaseDriver& FSD_BinaryFile::GetExtCharacter(Standard_ExtCharacter& aValu
{
if (!fread(&aValue,sizeof(Standard_ExtCharacter),1,myStream))
Storage_StreamTypeMismatchError::Raise();
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
aValue = InverseExtChar (aValue);
#endif
return *this;
@ -348,7 +349,7 @@ Storage_BaseDriver& FSD_BinaryFile::GetInteger(Standard_Integer& aValue)
{
if (!fread(&aValue,sizeof(Standard_Integer),1,myStream))
Storage_StreamTypeMismatchError::Raise();
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
aValue = InverseInt (aValue);
#endif
return *this;
@ -363,7 +364,7 @@ Storage_BaseDriver& FSD_BinaryFile::GetBoolean(Standard_Boolean& aValue)
{
if (!fread(&aValue,sizeof(Standard_Boolean),1,myStream))
Storage_StreamTypeMismatchError::Raise();
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
aValue = InverseInt ((Standard_Integer) aValue);
#endif
return *this;
@ -378,7 +379,7 @@ Storage_BaseDriver& FSD_BinaryFile::GetReal(Standard_Real& aValue)
{
if (!fread(&aValue,sizeof(Standard_Real),1,myStream))
Storage_StreamTypeMismatchError::Raise();
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
aValue = InverseReal (aValue);
#endif
return *this;
@ -393,7 +394,7 @@ Storage_BaseDriver& FSD_BinaryFile::GetShortReal(Standard_ShortReal& aValue)
{
if (!fread(&aValue,sizeof(Standard_ShortReal),1,myStream))
Storage_StreamTypeMismatchError::Raise();
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
aValue = InverseShortReal (aValue);
#endif
return *this;
@ -418,12 +419,18 @@ void FSD_BinaryFile::Destroy()
Storage_Error FSD_BinaryFile::BeginWriteInfoSection()
{
char ti[4];
ti[0] = 1;
ti[1] = 2;
ti[2] = 3;
ti[3] = 4;
myHeader.testindian = *((int*)ti);
union {
char ti2[4];
Standard_Integer aResult;
} aWrapUnion;
aWrapUnion.ti2[0] = 1;
aWrapUnion.ti2[1] = 2;
aWrapUnion.ti2[2] = 3;
aWrapUnion.ti2[3] = 4;
myHeader.testindian = aWrapUnion.aResult;
if (!fwrite(FSD_BinaryFile::MagicNumber(),
strlen(FSD_BinaryFile::MagicNumber()),
1,
@ -1108,7 +1115,7 @@ void FSD_BinaryFile::WriteExtendedString(const TCollection_ExtendedString& aStri
if (size > 0) {
Standard_ExtString anExtStr;
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
TCollection_ExtendedString aCopy = aString;
anExtStr = aCopy.ToExtString();
@ -1142,7 +1149,7 @@ void FSD_BinaryFile::ReadExtendedString(TCollection_ExtendedString& aString)
if (!fread(c,size*sizeof(Standard_ExtCharacter),1,myStream))
Storage_StreamWriteError::Raise();
c[size] = '\0';
#if DO_INVERSE
#if OCCT_BINARY_FILE_DO_INVERSE
for (Standard_Integer i=0; i < size; i++)
c[i] = InverseExtChar (c[i]);
#endif
@ -1208,3 +1215,80 @@ Storage_Position FSD_BinaryFile::Tell()
{
return (Storage_Position) ftell(myStream);
}
//=======================================================================
//function : InverseReal
//purpose : Inverses bytes in the real value
//=======================================================================
Standard_Real FSD_BinaryFile::InverseReal (const Standard_Real theValue)
{
Standard_STATIC_ASSERT(sizeof(Standard_Real) == 2 * sizeof(Standard_Integer));
union {
Standard_Integer i[2];
Standard_Real aValue;
} aWrapUnion;
aWrapUnion.aValue = theValue;
Standard_Integer aTemp = aWrapUnion.i[1];
aWrapUnion.i[1] = InverseInt(aWrapUnion.i[0]);
aWrapUnion.i[0] = InverseInt(aTemp);
return aWrapUnion.aValue;
}
//=======================================================================
//function : InverseShortReal
//purpose : Inverses bytes in the short real value
//=======================================================================
Standard_ShortReal FSD_BinaryFile::InverseShortReal (const Standard_ShortReal theValue)
{
Standard_STATIC_ASSERT(sizeof(Standard_ShortReal) == sizeof(Standard_Integer));
union {
Standard_ShortReal aValue;
Standard_Integer aResult;
} aWrapUnion;
aWrapUnion.aValue = theValue;
aWrapUnion.aResult = InverseInt (aWrapUnion.aResult);
return aWrapUnion.aValue;
}
//=======================================================================
//function : InverseSize
//purpose : Inverses bytes in size_t type instance
//=======================================================================
template<int size>
inline Standard_Size OCCT_InverseSizeSpecialized (const Standard_Size theValue, int);
template<>
inline Standard_Size OCCT_InverseSizeSpecialized <4> (const Standard_Size theValue, int)
{
return FSD_BinaryFile::InverseInt(static_cast<Standard_Integer>(theValue));
}
template<>
inline Standard_Size OCCT_InverseSizeSpecialized <8> (const Standard_Size theValue, int)
{
union {
Standard_Integer i[2];
Standard_Size aValue;
} aWrapUnion;
aWrapUnion.aValue = theValue;
Standard_Integer aTemp = aWrapUnion.i[1];
aWrapUnion.i[1] = FSD_BinaryFile::InverseInt(aWrapUnion.i[0]);
aWrapUnion.i[0] = FSD_BinaryFile::InverseInt(aTemp);
return aWrapUnion.aValue;
}
Standard_Size FSD_BinaryFile::InverseSize (const Standard_Size theValue)
{
return OCCT_InverseSizeSpecialized <sizeof(Standard_Size)> (theValue, 0);
}

View File

@ -46,6 +46,18 @@ class TCollection_ExtendedString;
class Storage_BaseDriver;
// Macro that tells if bytes must be reversed when read/write
// data to/from a binary file. It is needed to provide binary file compatibility
// between little and big endian platforms.
#ifndef OCCT_BINARY_FILE_DO_INVERSE
#if defined ( SOLARIS ) || defined ( IRIX )
// Do inverse on big endian platform
#define OCCT_BINARY_FILE_DO_INVERSE 1
#else
#define OCCT_BINARY_FILE_DO_INVERSE 0
#endif
#endif
class FSD_BinaryFile : public Storage_BaseDriver
{
@ -251,8 +263,30 @@ Storage_BaseDriver& operator >> (Standard_ShortReal& aValue)
Destroy();
}
///Inverse bytes in integer value
static Standard_Integer InverseInt(const Standard_Integer theValue)
{
return (0 | (( theValue & 0x000000ff ) << 24 )
| (( theValue & 0x0000ff00 ) << 8 )
| (( theValue & 0x00ff0000 ) >> 8 )
| (( theValue >> 24 ) & 0x000000ff ) );
}
///Inverse bytes in extended character value
static Standard_ExtCharacter InverseExtChar(const Standard_ExtCharacter theValue)
{
return (0 | (( theValue & 0x00ff ) << 8 )
| (( theValue & 0xff00 ) >> 8 ) );
}
///Inverse bytes in real value
Standard_EXPORT static Standard_Real InverseReal(const Standard_Real theValue);
///Inverse bytes in short real value
Standard_EXPORT static Standard_ShortReal InverseShortReal(const Standard_ShortReal theValue);
///Inverse bytes in size value
Standard_EXPORT static Standard_Size InverseSize(const Standard_Size theValue);
protected:

View File

@ -32,108 +32,4 @@ struct FSD_FileHeader {
Standard_Integer edata;
};
#ifndef DO_INVERSE
#if defined ( SOLARIS ) || defined ( IRIX )
#define DO_INVERSE 1
#else
#define DO_INVERSE 0
#endif
#endif
//=======================================================================
//function : InverseInt
//purpose : Inverses bytes in the word
//=======================================================================
inline Standard_Integer InverseInt (const Standard_Integer theValue)
{
return (0 | (( theValue & 0x000000ff ) << 24 )
| (( theValue & 0x0000ff00 ) << 8 )
| (( theValue & 0x00ff0000 ) >> 8 )
| (( theValue >> 24 ) & 0x000000ff ) );
}
//=======================================================================
//function : InverseLong
//purpose : Inverses bytes in the long word
//=======================================================================
inline long InverseLong (const long theValue)
{
return (long) InverseInt ((Standard_Integer) theValue);
}
//=======================================================================
//function : InverseExtChar
//purpose : Inverses bytes in the extended character
//=======================================================================
inline Standard_ExtCharacter InverseExtChar (const Standard_ExtCharacter theValue)
{
return (0 | (( theValue & 0x00ff ) << 8 )
| (( theValue & 0xff00 ) >> 8 ) );
}
//=======================================================================
//function : InverseReal
//purpose : Inverses bytes in the real value
//=======================================================================
inline Standard_Real InverseReal (const Standard_Real theValue)
{
Standard_Real aResult;
Standard_Integer *i = (Standard_Integer*) &theValue;
Standard_Integer *j = (Standard_Integer*) &aResult;
j[1] = InverseInt (i[0]);
j[0] = InverseInt (i[1]);
return aResult;
}
//=======================================================================
//function : InverseShortReal
//purpose : Inverses bytes in the short real value
//=======================================================================
inline Standard_ShortReal InverseShortReal (const Standard_ShortReal theValue)
{
Standard_ShortReal aResult;
Standard_Integer *i = (Standard_Integer*) &aResult;
*i = InverseInt (*(Standard_Integer*) &theValue);
return aResult;
}
//=======================================================================
//function : InverseSize
//purpose : Inverses bytes in size_t type instance
//=======================================================================
template<int size>
inline Standard_Size InverseSizeSpecialized (const Standard_Size theValue, int);
template<>
inline Standard_Size InverseSizeSpecialized <4> (const Standard_Size theValue, int)
{
return (0 | (( theValue & 0x000000ff ) << 24 )
| (( theValue & 0x0000ff00 ) << 8 )
| (( theValue & 0x00ff0000 ) >> 8 )
| (( theValue >> 24 ) & 0x000000ff ) );
}
template<>
inline Standard_Size InverseSizeSpecialized <8> (const Standard_Size theValue, int)
{
Standard_Size aResult;
Standard_Integer *i = (Standard_Integer*) &theValue;
Standard_Integer *j = (Standard_Integer*) &aResult;
j[1] = InverseInt (i[0]);
j[0] = InverseInt (i[1]);
return aResult;
}
inline Standard_Size InverseSize (const Standard_Size theValue)
{
return InverseSizeSpecialized <sizeof(Standard_Size)> (theValue, 0);
}
#endif

View File

@ -4217,6 +4217,274 @@ Standard_Integer OCC26525 (Draw_Interpretor& di,
return 0;
}
//=======================================================================
//function : OCC24537
//purpose : Puts inverted numbers (in the sense of little/big endian inversion)
// from predefined arrays.
//=======================================================================
#include <FSD_BinaryFile.hxx>
template<int size>
inline const unsigned char* SizeRef ();
template<>
inline const unsigned char* SizeRef <8> ()
{
static const unsigned char aSizeRef[] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x02,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x05,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x06,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x09,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
return aSizeRef;
}
template<>
inline const unsigned char* SizeRef <4> ()
{
static const unsigned char aSizeRef[] = {
0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,
0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x04,
0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x06,
0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x08,
0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x00};
return aSizeRef;
}
static Standard_Integer OCC24537(
Draw_Interpretor& theDI,
Standard_Integer argc,
const char ** argv)
{
std::ofstream aF;
if (argc > 1)
{
aF.open(argv[1]);
if (!aF.is_open())
{
cout << "cannot create file " << argv[1] << endl;
return 1;
}
}
Standard_Boolean isErr = Standard_False;
// 1. InverseInt
const unsigned char anIntRef[] = {
0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x02,
0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x04,
0x00,0x00,0x00,0x05,0x00,0x00,0x00,0x06,
0x00,0x00,0x00,0x07,0x00,0x00,0x00,0x08,
0x00,0x00,0x00,0x09,0x00,0x00,0x00,0x00};
Standard_Integer anIntArr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
if (aF.is_open())
{
for(int i = 0; i < 10; ++i)
{
Standard_Integer anInv = FSD_BinaryFile::InverseInt(anIntArr[i]);
aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
}
}
else
{
Standard_Integer anInv[10];
for(int i = 0; i < 10; ++i)
anInv[i] = FSD_BinaryFile::InverseInt(anIntArr[i]);
if (memcmp(anInv, anIntRef, sizeof(anIntRef)) != 0)
{
theDI << "Error: incorrect conversion of an integer value\n";
isErr = Standard_True;
}
}
// 1a. Random InverseInt
const unsigned char aRndIntRef[] = {
0xFF,0xC2,0xF7,0x00,0xFF,0xFF,0xFB,0x2E,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x00,0x00,0x04,0xD2,0x00,0x00,0x04,0xD3,
0xFF,0xFF,0xFD,0x1E,0xFF,0xFF,0xFF,0xFB,
0x00,0x00,0x03,0x8D,0x00,0x3D,0x09,0x00};
Standard_Integer aRndIntArr[] = {-4000000, -1234, 0, 1, 1234, 1235, -738, -5, 909, 4000000};
if (aF.is_open())
{
for(int i = 0; i < 10; ++i)
{
Standard_Integer anInv = FSD_BinaryFile::InverseInt(aRndIntArr[i]);
aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
}
}
else
{
Standard_Integer anInv[10];
for(int i = 0; i < 10; ++i)
anInv[i] = FSD_BinaryFile::InverseInt(aRndIntArr[i]);
if (memcmp(anInv, aRndIntRef, sizeof(aRndIntRef)) != 0)
{
theDI << "Error: incorrect conversion of a dispersed integer value\n";
isErr = Standard_True;
}
}
// 2. InverseReal
const unsigned char aRealRef[] = {
0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x14,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x22,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const Standard_Real aRealArr[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 0.0};
if (aF.is_open())
{
for(int i = 0; i < 10; ++i)
{
Standard_Real anInv = FSD_BinaryFile::InverseReal(aRealArr[i]);
aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
}
}
else
{
Standard_Real anInv[10];
for(int i = 0; i < 10; ++i)
anInv[i] = FSD_BinaryFile::InverseReal(aRealArr[i]);
if (memcmp(anInv, aRealRef, sizeof(aRealRef)) != 0)
{
theDI << "Error: incorrect conversion of a real value\n";
isErr = Standard_True;
}
}
// 2a. Random InverseReal
const unsigned char aRndRealRef[] = {
0xFE,0x37,0xE4,0x3C,0x88,0x00,0x75,0x9C,
0xBE,0x11,0x2E,0x0B,0xE8,0x26,0xD6,0x95,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x3E,0x11,0x2E,0x0B,0xE8,0x26,0xD6,0x95,
0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x40,0x09,0x21,0xDA,0x45,0x5B,0x53,0xE4,
0x54,0xB2,0x49,0xAD,0x25,0x94,0xC3,0x7D,
0x40,0x20,0x00,0x00,0x00,0x00,0x00,0x00,
0xC0,0x23,0xCC,0xCC,0xCC,0xCC,0xCC,0xCD,
0x40,0x23,0xCC,0xCC,0xCC,0xCC,0xCC,0xCD};
const Standard_Real aRndRealArr[] = {-1e300, -1.e-9, 0., 1.e-9, 1., 3.1415296, 1.e100, 8.0, -9.9, 9.9};
if (aF.is_open())
{
for(int i = 0; i < 10; ++i)
{
Standard_Real anInv = FSD_BinaryFile::InverseReal(aRndRealArr[i]);
aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
}
}
else
{
Standard_Real anInv[10];
for(int i = 0; i < 10; ++i)
anInv[i] = FSD_BinaryFile::InverseReal(aRndRealArr[i]);
if (memcmp(anInv, aRndRealRef, sizeof(aRndRealRef)) != 0)
{
theDI << "Error: incorrect conversion of a dispersed real value\n";
isErr = Standard_True;
}
}
// 3. InverseShortReal
const unsigned char aShortRealRef[] = {
0x3F,0x80,0x00,0x00,0x40,0x00,0x00,0x00,
0x40,0x40,0x00,0x00,0x40,0x80,0x00,0x00,
0x40,0xA0,0x00,0x00,0x40,0xC0,0x00,0x00,
0x40,0xE0,0x00,0x00,0x41,0x00,0x00,0x00,
0x41,0x10,0x00,0x00,0x00,0x00,0x00,0x00};
const Standard_ShortReal aShortRealArr[] = {
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 0.0f};
if (aF.is_open())
{
for(int i = 0; i < 10; ++i)
{
Standard_ShortReal anInv = FSD_BinaryFile::InverseShortReal(aShortRealArr[i]);
aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
}
}
else
{
Standard_ShortReal anInv[10];
for(int i = 0; i < 10; ++i)
anInv[i] = FSD_BinaryFile::InverseShortReal(aShortRealArr[i]);
if (memcmp(anInv, aShortRealRef, sizeof(aShortRealRef)) != 0)
{
theDI << "Error: incorrect conversion of a short real value\n";
isErr = Standard_True;
}
}
// 3a. Random InverseShortReal
const unsigned char aRndShortRealRef[] = {
0xB0,0x89,0x70,0x5F,0x00,0x00,0x00,0x00,
0x30,0x89,0x70,0x5F,0x3F,0x80,0x00,0x00,
0x40,0x49,0x0E,0x56,0xC0,0xD6,0x66,0x66,
0x40,0xD6,0x66,0x66,0x42,0xC5,0xCC,0xCD,
0xC2,0xC7,0xCC,0xCD,0x42,0xC7,0xCC,0xCD};
const Standard_ShortReal aRndShortRealArr[] = {
-1.e-9f, 0.f, 1.e-9f, 1.f, 3.1415f, -6.7f, 6.7f, 98.9f, -99.9f, 99.9f};
if (aF.is_open())
{
for(int i = 0; i < 10; ++i)
{
Standard_ShortReal anInv = FSD_BinaryFile::InverseShortReal(aRndShortRealArr[i]);
aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
}
}
else
{
Standard_ShortReal anInv[10];
for(int i = 0; i < 10; ++i)
anInv[i] = FSD_BinaryFile::InverseShortReal(aRndShortRealArr[i]);
if (memcmp(anInv, aRndShortRealRef, sizeof(aRndShortRealRef)) != 0)
{
theDI << "Error: incorrect conversion of a dispersed short real value\n";
isErr = Standard_True;
}
}
// 4. InverseSize
const Standard_Size aSizeArr[] = {1ul, 2ul, 3ul, 4ul, 5ul, 6ul, 7ul, 8ul, 9ul, 0ul};
if (aF.is_open())
{
for(int i = 0; i < 10; ++i)
{
Standard_Size anInv = FSD_BinaryFile::InverseSize(aSizeArr[i]);
aF.write(reinterpret_cast<char*>(&anInv), sizeof(anInv));
}
}
else
{
Standard_Size anInv[10];
const unsigned char* aSizeRef = SizeRef<sizeof(Standard_Size)>();
for(int i = 0; i < 10; ++i)
anInv[i] = FSD_BinaryFile::InverseSize(aSizeArr[i]);
if (memcmp(anInv, aSizeRef, sizeof(Standard_Size)*10) != 0)
{
theDI << "Error: incorrect conversion of a size value\n";
isErr = Standard_True;
}
}
if (!aF.is_open() && !isErr)
theDI << "Conversion was done OK";
if (aF.is_open())
{
cout << "the file " << argv[1] << " has been created" << endl;
aF.close();
}
return 0;
}
void QABugs::Commands_19(Draw_Interpretor& theCommands) {
const char *group = "QABugs";
@ -4308,5 +4576,6 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
theCommands.Add ("OCC26313", "OCC26313 result shape", __FILE__, OCC26313, group);
theCommands.Add ("OCC26525", "OCC26525 result edge face ", __FILE__, OCC26525, group);
theCommands.Add ("OCC24537", "OCC24537 [file]", __FILE__, OCC24537, group);
return;
}

View File

@ -0,0 +1,15 @@
puts "================"
puts "OCC24537"
puts "================"
puts ""
#######################################################################
# GCC compiler warnings in byte order reversion code.
# The matter of this test is to ensure correctness of work of the methods
# (in the file FSD_FileHeader.hxx) of inversion of numbers between little/big endian.
# Attention! The test is created for working on a little endian platform.
#######################################################################
pload QAcommands
# The following command gives an error output if conversion is wrong
OCC24537