예제 #1
0
    void TestSetFilename(void)
    {
        // Check that only file name is changed.
        m_path->SetFilename(L"new.file");
#if defined(WIN32)
        CPPUNIT_ASSERT(m_path->Get() == L"some\\path\\new.file");
#else
        CPPUNIT_ASSERT(m_path->Get() == L"some/path/new.file");
#endif
        m_path->SetFilename(L"");
        // Check that empty filename removes filename...
        CPPUNIT_ASSERT(m_path->GetFilename() == L"");
        // ...but not directory
#if defined(WIN32)
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"some\\path\\");
#else
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"some/path/");
#endif

        // Check correct exception thrown when adding folder separators in file name.
        SCXUNIT_RESET_ASSERTION();
        CPPUNIT_ASSERT_THROW(m_path->SetFilename(L"not/valid"), SCXCoreLib::SCXInvalidArgumentException);
        SCXUNIT_ASSERTIONS_FAILED(2); // both in append function and in SCXInvalidArgumentException constructor
        CPPUNIT_ASSERT_THROW(m_path->SetFilename(L"not\\valid"), SCXCoreLib::SCXInvalidArgumentException);
        SCXUNIT_ASSERTIONS_FAILED(2); // both in append function and in SCXInvalidArgumentException constructor
    }
예제 #2
0
    void TestSetFileSuffix(void)
    {
        m_directory->SetFilesuffix(L"new");
        m_file->SetFilesuffix(L"new");
        m_path->SetFilesuffix(L"new");

        // Check no suffix added when file name is empty.
        CPPUNIT_ASSERT(m_directory->GetFilename() == L"");
        // Check file name is changed.
        CPPUNIT_ASSERT(m_file->GetFilename() == L"file.new");
        // Check file suffix is added.
        CPPUNIT_ASSERT(m_path->GetFilename() == L"file.new");
        // Make sure original directories are preserved.
#if defined(WIN32)
        CPPUNIT_ASSERT(m_directory->GetDirectory() == L"dir\\");
        CPPUNIT_ASSERT(m_file->GetDirectory() == L"");
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"some\\path\\");
#else
        CPPUNIT_ASSERT(m_directory->GetDirectory() == L"dir/");
        CPPUNIT_ASSERT(m_file->GetDirectory() == L"");
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"some/path/");
#endif
        // make sure a suffix can be removed (including suffix separator)
        m_file->SetFilesuffix(L"");
        CPPUNIT_ASSERT(m_file->GetFilename() == L"file");
    }
예제 #3
0
    void TestAppend(void)
    {
        m_empty->Append(L"some/append\\path/");
        m_directory->Append(L"some/append\\path/file");
        m_path->Append(L".new.ext");
        // Check correct parsing of folder and file name for empy paths,
        // folder only paths and paths with bor filename and folders.
#if defined(WIN32)
        CPPUNIT_ASSERT(m_empty->GetDirectory() == L"some\\append\\path\\");
        CPPUNIT_ASSERT(m_empty->GetFilename() == L"");
        CPPUNIT_ASSERT(m_directory->GetDirectory() == L"dir\\some\\append\\path\\");
        CPPUNIT_ASSERT(m_directory->GetFilename() == L"file");
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"some\\path\\");
        CPPUNIT_ASSERT(m_path->GetFilename() == L"file.ext.new.ext");
#else
        CPPUNIT_ASSERT(m_empty->GetDirectory() == L"some/append/path/");
        CPPUNIT_ASSERT(m_empty->GetFilename() == L"");
        CPPUNIT_ASSERT(m_directory->GetDirectory() == L"dir/some/append/path/");
        CPPUNIT_ASSERT(m_directory->GetFilename() == L"file");
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"some/path/");
        CPPUNIT_ASSERT(m_path->GetFilename() == L"file.ext.new.ext");
#endif

        // Check for correct exception when folder separators in append string and path 
        // already has a file name.
        SCXUNIT_RESET_ASSERTION();
        CPPUNIT_ASSERT_THROW(m_path->Append(L"path/with\\file"), SCXCoreLib::SCXInvalidArgumentException);
        SCXUNIT_ASSERTIONS_FAILED(2); // both in append function and in SCXInvalidArgumentException constructor

        m_empty->Append(L"/double/");
        // Check that any starting folder separators are removed if appending to existing folder.
#if defined(WIN32)
        CPPUNIT_ASSERT(m_empty->GetDirectory().find(L"\\\\") == std::wstring::npos);
#else
        CPPUNIT_ASSERT(m_empty->GetDirectory().find(L"//") == std::wstring::npos);
#endif
    }
예제 #4
0
    void TestSetDirectory(void)
    {
        m_directory->SetDirectory(L"new/dir\\");
        m_path->SetDirectory(L"new/dir");
        m_file->SetDirectory(L"new/dir\\");
        // Check directiory is correctly set.
#if defined(WIN32)
        CPPUNIT_ASSERT(m_directory->GetDirectory() == L"new\\dir\\");
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"new\\dir\\");
        CPPUNIT_ASSERT(m_file->GetDirectory() == L"new\\dir\\");
#else
        CPPUNIT_ASSERT(m_directory->GetDirectory() == L"new/dir/");
        CPPUNIT_ASSERT(m_path->GetDirectory() == L"new/dir/");
        CPPUNIT_ASSERT(m_file->GetDirectory() == L"new/dir/");
#endif
        // Check file name is not affected
        CPPUNIT_ASSERT(m_directory->GetFilename() == L"");
        CPPUNIT_ASSERT(m_file->GetFilename() == L"file");
        CPPUNIT_ASSERT(m_path->GetFilename() == L"file.ext");
    }
예제 #5
0
 void callDumpStringForCoverage()
 {
     CPPUNIT_ASSERT(m_path->DumpString().find(L"SCXFilePath") != std::wstring::npos);
     CPPUNIT_ASSERT(m_path->DumpString().find(m_path->GetDirectory()) != std::wstring::npos);
     CPPUNIT_ASSERT(m_path->DumpString().find(m_path->GetFilename()) != std::wstring::npos);
 }