@ -24,12 +24,15 @@
*/
*/
# include <sstream>
# include <sstream>
# include <vector>
# include <Corrade/Containers/Array.h>
# include <Corrade/Containers/Array.h>
# include <Corrade/Containers/StridedArrayView.h>
# include <Corrade/TestSuite/Tester.h>
# include <Corrade/TestSuite/Tester.h>
# include <Corrade/TestSuite/Compare/Container.h>
# include <Corrade/TestSuite/Compare/Container.h>
# include <Corrade/Utility/DebugStl.h>
# include <Corrade/Utility/DebugStl.h>
# include <Corrade/Utility/Endianness.h>
# include <Corrade/Utility/Endianness.h>
# include "Magnum/Math/TypeTraits.h"
# include "Magnum/MeshTools/CompressIndices.h"
# include "Magnum/MeshTools/CompressIndices.h"
namespace Magnum { namespace MeshTools { namespace Test { namespace {
namespace Magnum { namespace MeshTools { namespace Test { namespace {
@ -37,42 +40,91 @@ namespace Magnum { namespace MeshTools { namespace Test { namespace {
struct CompressIndicesTest : TestSuite : : Tester {
struct CompressIndicesTest : TestSuite : : Tester {
explicit CompressIndicesTest ( ) ;
explicit CompressIndicesTest ( ) ;
void compressChar ( ) ;
template < class T > void compressUnsignedByte ( ) ;
void compressShort ( ) ;
template < class T > void compressUnsignedShort ( ) ;
void compressInt ( ) ;
template < class T > void compressUnsignedInt ( ) ;
void compressUnsignedByteInflateToShort ( ) ;
# ifdef MAGNUM_BUILD_DEPRECATED
void compressDeprecated ( ) ;
# endif
void compressAsShort ( ) ;
void compressAsShort ( ) ;
} ;
} ;
CompressIndicesTest : : CompressIndicesTest ( ) {
CompressIndicesTest : : CompressIndicesTest ( ) {
addTests ( { & CompressIndicesTest : : compressChar ,
addTests ( { & CompressIndicesTest : : compressUnsignedByte < UnsignedByte > ,
& CompressIndicesTest : : compressShort ,
& CompressIndicesTest : : compressUnsignedByte < UnsignedShort > ,
& CompressIndicesTest : : compressInt ,
& CompressIndicesTest : : compressUnsignedByte < UnsignedInt > ,
& CompressIndicesTest : : compressUnsignedShort < UnsignedShort > ,
& CompressIndicesTest : : compressUnsignedShort < UnsignedInt > ,
& CompressIndicesTest : : compressUnsignedInt < UnsignedInt > ,
& CompressIndicesTest : : compressUnsignedByteInflateToShort ,
# ifdef MAGNUM_BUILD_DEPRECATED
& CompressIndicesTest : : compressDeprecated ,
# endif
& CompressIndicesTest : : compressAsShort } ) ;
& CompressIndicesTest : : compressAsShort } ) ;
}
}
void CompressIndicesTest : : compressChar ( ) {
template < class T > void CompressIndicesTest : : compressUnsignedByte ( ) {
Containers : : Array < char > data ;
setTestCaseTemplateName ( Math : : TypeTraits < T > : : name ( ) ) ;
MeshIndexType type ;
UnsignedInt start , end ;
std : : tie ( data , type , start , end ) = MeshTools : : compressIndices (
std : : vector < UnsignedInt > { 1 , 2 , 3 , 0 , 4 } ) ;
CORRADE_COMPARE ( start , 0 ) ;
const T indices [ ] { 1 , 2 , 3 , 0 , 4 } ;
CORRADE_COMPARE ( end , 4 ) ;
/* By default it has 16-byte type as minimum, override */
CORRADE_COMPARE ( type , MeshIndexType : : UnsignedByte ) ;
std : : pair < Containers : : Array < char > , MeshIndexType > out =
CORRADE_COMPARE_AS ( Containers : : arrayCast < UnsignedByte > ( data ) ,
compressIndices ( indices , MeshIndexType : : UnsignedByte ) ;
CORRADE_COMPARE ( out . second , MeshIndexType : : UnsignedByte ) ;
CORRADE_COMPARE_AS ( Containers : : arrayCast < UnsignedByte > ( out . first ) ,
Containers : : arrayView < UnsignedByte > ( { 1 , 2 , 3 , 0 , 4 } ) ,
Containers : : arrayView < UnsignedByte > ( { 1 , 2 , 3 , 0 , 4 } ) ,
TestSuite : : Compare : : Container ) ;
TestSuite : : Compare : : Container ) ;
}
}
void CompressIndicesTest : : compressShort ( ) {
template < class T > void CompressIndicesTest : : compressUnsignedShort ( ) {
setTestCaseTemplateName ( Math : : TypeTraits < T > : : name ( ) ) ;
const T indices [ ] { 1 , 256 , 0 , 5 } ;
std : : pair < Containers : : Array < char > , MeshIndexType > out = compressIndices ( indices ) ;
CORRADE_COMPARE ( out . second , MeshIndexType : : UnsignedShort ) ;
CORRADE_COMPARE_AS ( Containers : : arrayCast < UnsignedShort > ( out . first ) ,
Containers : : arrayView < UnsignedShort > ( { 1 , 256 , 0 , 5 } ) ,
TestSuite : : Compare : : Container ) ;
}
template < class T > void CompressIndicesTest : : compressUnsignedInt ( ) {
setTestCaseTemplateName ( Math : : TypeTraits < T > : : name ( ) ) ;
const T indices [ ] { 65536 , 3 , 2 } ;
std : : pair < Containers : : Array < char > , MeshIndexType > out = compressIndices ( indices ) ;
CORRADE_COMPARE ( out . second , MeshIndexType : : UnsignedInt ) ;
CORRADE_COMPARE_AS ( Containers : : arrayCast < UnsignedInt > ( out . first ) ,
Containers : : arrayView < UnsignedInt > ( { 65536 , 3 , 2 } ) ,
TestSuite : : Compare : : Container ) ;
}
void CompressIndicesTest : : compressUnsignedByteInflateToShort ( ) {
const UnsignedByte indices [ ] { 1 , 2 , 3 , 0 , 4 } ;
/* That's the default */
std : : pair < Containers : : Array < char > , MeshIndexType > out = compressIndices ( indices ) ;
CORRADE_COMPARE ( out . second , MeshIndexType : : UnsignedShort ) ;
CORRADE_COMPARE_AS ( Containers : : arrayCast < UnsignedShort > ( out . first ) ,
Containers : : arrayView < UnsignedShort > ( { 1 , 2 , 3 , 0 , 4 } ) ,
TestSuite : : Compare : : Container ) ;
}
# ifdef MAGNUM_BUILD_DEPRECATED
void CompressIndicesTest : : compressDeprecated ( ) {
Containers : : Array < char > data ;
Containers : : Array < char > data ;
MeshIndexType type ;
MeshIndexType type ;
UnsignedInt start , end ;
UnsignedInt start , end ;
CORRADE_IGNORE_DEPRECATED_PUSH
std : : tie ( data , type , start , end ) = MeshTools : : compressIndices (
std : : tie ( data , type , start , end ) = MeshTools : : compressIndices (
std : : vector < UnsignedInt > { 1 , 256 , 0 , 5 } ) ;
std : : vector < UnsignedInt > { 1 , 256 , 0 , 5 } ) ;
CORRADE_IGNORE_DEPRECATED_POP
CORRADE_COMPARE ( start , 0 ) ;
CORRADE_COMPARE ( start , 0 ) ;
CORRADE_COMPARE ( end , 256 ) ;
CORRADE_COMPARE ( end , 256 ) ;
@ -81,21 +133,7 @@ void CompressIndicesTest::compressShort() {
Containers : : arrayView < UnsignedShort > ( { 1 , 256 , 0 , 5 } ) ,
Containers : : arrayView < UnsignedShort > ( { 1 , 256 , 0 , 5 } ) ,
TestSuite : : Compare : : Container ) ;
TestSuite : : Compare : : Container ) ;
}
}
# endif
void CompressIndicesTest : : compressInt ( ) {
Containers : : Array < char > data ;
MeshIndexType type ;
UnsignedInt start , end ;
std : : tie ( data , type , start , end ) = MeshTools : : compressIndices (
std : : vector < UnsignedInt > { 65536 , 3 , 2 } ) ;
CORRADE_COMPARE ( start , 2 ) ;
CORRADE_COMPARE ( end , 65536 ) ;
CORRADE_COMPARE ( type , MeshIndexType : : UnsignedInt ) ;
CORRADE_COMPARE_AS ( Containers : : arrayCast < UnsignedInt > ( data ) ,
Containers : : arrayView < UnsignedInt > ( { 65536 , 3 , 2 } ) ,
TestSuite : : Compare : : Container ) ;
}
void CompressIndicesTest : : compressAsShort ( ) {
void CompressIndicesTest : : compressAsShort ( ) {
CORRADE_COMPARE_AS ( MeshTools : : compressIndicesAs < UnsignedShort > ( { 123 , 456 } ) ,
CORRADE_COMPARE_AS ( MeshTools : : compressIndicesAs < UnsignedShort > ( { 123 , 456 } ) ,