Filesystem paths - Path style support

This commit is contained in:
Emmanuel BENOîT 2018-12-23 18:17:55 +01:00
parent 96d81b9cd3
commit fc3415047f
4 changed files with 114 additions and 82 deletions

View file

@ -11,9 +11,6 @@ class FSPathTest : public CppUnit::TestFixture
CPPUNIT_TEST( testValidComponentOK );
CPPUNIT_TEST( testValidComponentBad );
CPPUNIT_TEST( testValidRootOK );
CPPUNIT_TEST( testValidRootBad );
CPPUNIT_TEST( testConstructDefault );
CPPUNIT_TEST( testConstructValidStringRel );
CPPUNIT_TEST( testConstructValidStringAbs );
@ -33,9 +30,6 @@ public:
void testValidComponentOK( );
void testValidComponentBad( );
void testValidRootOK( );
void testValidRootBad( );
void testConstructDefault( );
void testConstructValidStringRel( );
void testConstructValidStringAbs( );
@ -80,36 +74,6 @@ void FSPathTest::testValidComponentBad( )
/*----------------------------------------------------------------------------*/
void FSPathTest::testValidRootOK( )
{
CPPUNIT_ASSERT( T_FSPath::IsValidRoot( "/" ) );
CPPUNIT_ASSERT( T_FSPath::IsValidRoot( "\\" ) );
#ifdef _WIN32
CPPUNIT_ASSERT( T_FSPath::IsValidRoot( "C:\\" ) );
CPPUNIT_ASSERT( T_FSPath::IsValidRoot( "C:/" ) );
CPPUNIT_ASSERT( T_FSPath::IsValidRoot( "z:/" ) );
CPPUNIT_ASSERT( T_FSPath::IsValidRoot( "z:\\" ) );
#endif
}
void FSPathTest::testValidRootBad( )
{
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "x/" ) );
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "x\\" ) );
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "/x" ) );
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "\\x" ) );
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "x" ) );
#ifdef _WIN32
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "C:!" ) );
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "z!\\" ) );
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "z!/" ) );
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "_:\\" ) );
CPPUNIT_ASSERT( !T_FSPath::IsValidRoot( "_:/" ) );
#endif
}
/*----------------------------------------------------------------------------*/
void FSPathTest::testConstructDefault( )
{
const T_FSPath test{ };
@ -132,7 +96,7 @@ void FSPathTest::testConstructValidStringRel( )
void FSPathTest::testConstructValidStringAbs( )
{
const T_FSPath test{ "/this/is/a/test" };
const T_FSPath test{ "/this/is/a/test" , T_FSPathStyle::Unix( ) };
CPPUNIT_ASSERT( test.isValid( ) );
CPPUNIT_ASSERT( test.root( ).equals( "/" ) );
CPPUNIT_ASSERT_EQUAL( 4u , test.components( ).size( ) );
@ -144,7 +108,7 @@ void FSPathTest::testConstructValidStringAbs( )
void FSPathTest::testConstructInvalidString( )
{
const T_FSPath test{ "/<this!>/<is!>/<SPARTA!>\n" };
const T_FSPath test{ "/<this!>/<is!>/<SPARTA!>\n" , T_FSPathStyle::Unix( ) };
CPPUNIT_ASSERT( !test.isValid( ) );
CPPUNIT_ASSERT( test.root( ).equals( "/" ) );
CPPUNIT_ASSERT_EQUAL( 3u , test.components( ).size( ) );
@ -161,7 +125,7 @@ void FSPathTest::testCopyCons( )
"/this/is/a/test" , "this/is/a/test" , "/<this!>/<is!>/<SPARTA!>\n"
};
for ( char const* test : tests ) {
const T_FSPath src{ test };
const T_FSPath src{ test , T_FSPathStyle::Unix( ) };
const T_FSPath dest{ src };
CPPUNIT_ASSERT_EQUAL( src.isValid( ) , dest.isValid( ) );
CPPUNIT_ASSERT( src.root( ).equals( dest.root( ) ) );
@ -179,7 +143,7 @@ void FSPathTest::testCopyAss( )
"/this/is/a/test" , "this/is/a/test" , "/<this!>/<is!>/<SPARTA!>\n"
};
for ( char const* test : tests ) {
const T_FSPath src{ test };
const T_FSPath src{ test , T_FSPathStyle::Unix( ) };
T_FSPath dest{ "/nope" };
dest = src;
CPPUNIT_ASSERT_EQUAL( src.isValid( ) , dest.isValid( ) );
@ -198,7 +162,7 @@ void FSPathTest::testMoveCons( )
"/this/is/a/test" , "this/is/a/test" , "/<this!>/<is!>/<SPARTA!>\n"
};
for ( char const* test : tests ) {
const T_FSPath src{ test };
const T_FSPath src{ test , T_FSPathStyle::Unix( ) };
T_FSPath moved{ test };
const T_FSPath dest{ std::move( moved ) };
@ -222,7 +186,7 @@ void FSPathTest::testMoveAss( )
"/this/is/a/test" , "this/is/a/test" , "/<this!>/<is!>/<SPARTA!>\n"
};
for ( char const* test : tests ) {
const T_FSPath src{ test };
const T_FSPath src{ test , T_FSPathStyle::Unix( ) };
T_FSPath moved{ test };
T_FSPath dest{ "/nope" };
dest = std::move( moved );
@ -262,7 +226,11 @@ void FSPathTest::testSwap( )
void FSPathTest::testIsRelative( )
{
T_FSPath a{ "/test" } , b{ "test" } , c{ "./test" } , d{ "/../test" } , e{};
T_FSPath a{ "/test" , T_FSPathStyle::Unix( ) } ,
b{ "test" , T_FSPathStyle::Unix( ) } ,
c{ "./test" , T_FSPathStyle::Unix( ) } ,
d{ "/../test" , T_FSPathStyle::Unix( ) } ,
e{ T_FSPathStyle::Unix( ) };
CPPUNIT_ASSERT( !a.isRelative( ) );
CPPUNIT_ASSERT( b.isRelative( ) );
CPPUNIT_ASSERT( c.isRelative( ) );
@ -272,7 +240,11 @@ void FSPathTest::testIsRelative( )
void FSPathTest::testIsAbsolute( )
{
T_FSPath a{ "/test" } , b{ "test" } , c{ "./test" } , d{ "/../test" } , e{};
T_FSPath a{ "/test" , T_FSPathStyle::Unix( ) } ,
b{ "test" , T_FSPathStyle::Unix( ) } ,
c{ "./test" , T_FSPathStyle::Unix( ) } ,
d{ "/../test" , T_FSPathStyle::Unix( ) } ,
e{ T_FSPathStyle::Unix( ) };
CPPUNIT_ASSERT( a.isAbsolute( ) );
CPPUNIT_ASSERT( !b.isAbsolute( ) );
CPPUNIT_ASSERT( !c.isAbsolute( ) );