Quellcodebibliothek Statistik Leitseite products/sources/formale Sprachen/C/LibreOffice/sal/qa/osl/file/   (Office von Apache Version 25.8.3.2©)  Datei vom 5.10.2025 mit Größe 187 kB image not shown  

Quelle  osl_File.cxx   Sprache: C

 
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */


#include <sal/types.h>
#include <rtl/byteseq.hxx>
#include <rtl/ustring.hxx>

#include <osl/file.hxx>
#include "osl_File_Const.h"

#include <cppunit/TestFixture.h>
#include <cppunit/extensions/HelperMacros.h>

#include <memory>

#ifdef _WIN32
#include <prewin.h>
#include <postwin.h>
#include <o3tl/char16_t2wchar_t.hxx>
#include <tools/urlobj.hxx>
#endif

using namespace osl;

/** detailed wrong message.
*/

static OString errorToString(const osl::FileBase::RC _nError)
{
    OString sResult;
    switch (_nError) {
        case osl::FileBase::E_None:
            sResult = "Success"_ostr;
            break;
        case osl::FileBase::E_PERM:
            sResult = "Operation not permitted"_ostr;
            break;
        case osl::FileBase::E_NOENT:
            sResult = "No such file or directory"_ostr;
            break;
        case osl::FileBase::E_EXIST:
            sResult = "Already Exist"_ostr;
            break;
        case osl::FileBase::E_ACCES:
            sResult = "Permission denied"_ostr;
            break;
        case osl::FileBase::E_INVAL:
            sResult = "The format of the parameters was not valid"_ostr;
            break;
        case osl::FileBase::E_NOTDIR:
            sResult = "Not a directory"_ostr;
            break;
        case osl::FileBase::E_ISDIR:
            sResult = "Is a directory"_ostr;
            break;
        case osl::FileBase::E_BADF:
            sResult = "Bad file"_ostr;
            break;
        case osl::FileBase::E_NOTEMPTY:
            sResult = "The directory is not empty"_ostr;
            break;
        default:
            sResult = "Unknown Error"_ostr;
            break;
    }
    return sResult;
}

static OString errorToStr(osl::FileBase::RC const& nError)
{
    OString suBuf = "The returned error is: " +
        errorToString(nError) +
        "!\n";
    return suBuf;
}

/** compare two TimeValue, unit is "ms", since Windows time precision is better than UNX.
*/

/* FIXME: the above assertion is bogus */

#if (defined UNX)                      // precision of time in Windows is better than UNX
#   define delta 2000                    // time precision, 2000ms
#else
#   define delta 1800                    // time precision, 1.8s
#endif

static bool t_compareTime(TimeValue *m_aEndTime,  TimeValue *m_aStartTime, sal_Int32 nDelta)
{
    sal_Int32 nDeltaSeconds = m_aEndTime->Seconds - m_aStartTime->Seconds;
    sal_Int32 nDeltaNanoSec = sal_Int32(m_aEndTime->Nanosec) - sal_Int32(m_aStartTime->Nanosec);
    if (nDeltaNanoSec < 0)
    {
        nDeltaNanoSec = 1000000000 + nDeltaNanoSec;
        nDeltaSeconds--;
    }

    sal_Int32 nDeltaMilliSec = (nDeltaSeconds * 1000) + (nDeltaNanoSec / 1000000);
    return (nDeltaMilliSec < nDelta);
}

/** compare two OUString file name.
*/

static bool compareFileName(const OUString & ustr1, const OUString & ustr2)
{
    bool bOk;
// on Windows, the separator is '\', so here change to '/', then compare
#if defined(_WIN32)
    OUString ustr1new,ustr2new;
    sal_Unicode reverseSlash = '\\';

    if (ustr1.lastIndexOf(reverseSlash) != -1)
        ustr1new = ustr1.replace(reverseSlash,'/');
    else
        ustr1new = ustr1;
    if (ustr2.lastIndexOf(reverseSlash) != -1)
        ustr2new = ustr2.replace(reverseSlash,'/');
    else
        ustr2new = ustr2;
    bOk = ustr1new.equalsIgnoreAsciiCase(ustr2new);
#else
    bOk = ustr1.equalsIgnoreAsciiCase(ustr2);
#endif
    return bOk;
}

/** simple version to judge if a file name or directory name is a URL or a system path, just to see if it
    is start with "file:///";.
*/

static bool isURL(const OUString& pathname)
{
    return pathname.startsWith(aPreURL);
}

/** concat two part to form a URL or system path, add PATH_SEPARATOR between them if necessary, add "file:///" to beginning if necessary.
*/

static void concatURL(OUString & pathname1, const OUString & pathname2)
{
    // check if pathname1 is full qualified URL;
    if (!isURL(pathname1))
    {
        OUString     aPathName   = pathname1.copy(0);
        osl::FileBase::getFileURLFromSystemPath(pathname1, aPathName); // convert if not full qualified URL
        pathname1   = aPathName.copy(0);
    }

    // check if '/' is in the end of pathname1 or at the begin of pathname2;
    if (!pathname1.endsWith(aSlashURL) && !pathname2.startsWith(aSlashURL))
        pathname1 += aSlashURL;
    pathname1 += pathname2;
}

/** create a temp test file using OUString name of full qualified URL or system path.
*/

static void createTestFile(const OUString& filename)
{
    OUString     aPathURL   = filename.copy(0);
    osl::FileBase::RC nError;

    if (!isURL(filename))
        osl::FileBase::getFileURLFromSystemPath(filename, aPathURL); // convert if not full qualified URL

    File aFile(aPathURL);
    nError = aFile.open(osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create);
    if ((nError != osl::FileBase::E_None) && (nError != osl::FileBase::E_EXIST))
        printf("createTestFile failed!\n");

    aFile.close();

}

/** create a temp test file using OUString name of full qualified URL or system path in a base directory.
*/

static void createTestFile(const OUString& basename, const OUString& filename)
{
    OUString aBaseURL = basename.copy(0);

    concatURL(aBaseURL, filename);
    createTestFile(aBaseURL);
}

/** delete a temp test file using OUString name.
*/

static void deleteTestFile(const OUString& filename)
{
    OUString     aPathURL   = filename.copy(0);
    osl::FileBase::RC nError;

    if (!isURL(filename))
        osl::FileBase::getFileURLFromSystemPath(filename, aPathURL); // convert if not full qualified URL

    nError = File::setAttributes(aPathURL, osl_File_Attribute_GrpWrite| osl_File_Attribute_OwnWrite| osl_File_Attribute_OthWrite); // if readonly, make writable.
    CPPUNIT_ASSERT_MESSAGE("In deleteTestFile Function: set writable ", (osl::FileBase::E_None == nError) || (osl::FileBase::E_NOENT == nError));

    nError = File::remove(aPathURL);
    CPPUNIT_ASSERT_MESSAGE("In deleteTestFile Function: remove ", (osl::FileBase::E_None == nError) || (nError == osl::FileBase::E_NOENT));
}

/** delete a temp test file using OUString name of full qualified URL or system path in a base directory.
*/

static void deleteTestFile(const OUString& basename, const OUString& filename)
{
    OUString aBaseURL   = basename.copy(0);

    concatURL(aBaseURL, filename);
    deleteTestFile(aBaseURL);
}

/** create a temp test directory using OUString name of full qualified URL or system path.
*/

static void createTestDirectory(const OUString& dirname)
{
    OUString aPathURL   = dirname.copy(0);
    osl::FileBase::RC nError;

    if (!isURL(dirname))
        osl::FileBase::getFileURLFromSystemPath(dirname, aPathURL); // convert if not full qualified URL
    nError = Directory::create(aPathURL);
    if ((nError != osl::FileBase::E_None) && (nError != osl::FileBase::E_EXIST))
        printf("createTestDirectory failed: %d!\n"int(nError));
}

/** create a temp test directory using OUString name of full qualified URL or system path in a base directory.
*/

static void createTestDirectory(const OUString& basename, const OUString& dirname)
{
    OUString aBaseURL   = basename.copy(0);

    concatURL(aBaseURL, dirname);
    createTestDirectory(aBaseURL);
}

/** delete a temp test directory using OUString name of full qualified URL or system path.
*/

static void deleteTestDirectory(const OUString& dirname)
{
    OUString aPathURL = dirname.copy(0);
    if (!isURL(dirname))
        osl::FileBase::getFileURLFromSystemPath(dirname, aPathURL); // convert if not full qualified URL

    Directory testDir(aPathURL);
    if (testDir.isOpen())
        testDir.close();  // close if still open.

    osl::FileBase::RC nError = Directory::remove(aPathURL);

    OString strError = "In deleteTestDirectory function: remove Directory " +
        OUStringToOString(aPathURL, RTL_TEXTENCODING_ASCII_US) + " -> result: " + OString::number(nError);
    CPPUNIT_ASSERT_MESSAGE(strError.getStr(), (osl::FileBase::E_None == nError) || (nError == osl::FileBase::E_NOENT));
}

/** delete a temp test directory using OUString name of full qualified URL or system path in a base directory.
*/

static void deleteTestDirectory(const OUString& basename, const OUString& dirname)
{
    OUString aBaseURL   = basename.copy(0);

    concatURL(aBaseURL, dirname);
    deleteTestDirectory(aBaseURL);
}

namespace {

/** Check for the file and directory access right.
*/

enum class oslCheckMode {
    Exist,
    OpenAccess,
    ReadAccess,
    WriteAccess
};

}

/** check if the file exist
*/

static bool ifFileExist(const OUString & str)
{
    File testFile(str);
    return (testFile.open(osl_File_OpenFlag_Read) == osl::FileBase::E_None);
}

/** check if the file can be written
*/

static bool ifFileCanWrite(const OUString & str)
{
    // on Windows, the file has no write right, but can be written
#ifdef _WIN32
    bool bCheckResult = false;
    OUString aUStr = str.copy(0);
    if (isURL(str))
        osl::FileBase::getSystemPathFromFileURL(str, aUStr);

    OString aString = OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US);
    const char *path = aString.getStr();
    if ((_access(path, 2)) != -1)
         bCheckResult = true;
     // on UNX, just test if open success with osl_File_OpenFlag_Write
#else
    File testFile(str);
    bool bCheckResult = (testFile.open(osl_File_OpenFlag_Write) == osl::FileBase::E_None);
#endif
    return bCheckResult;
}

static bool checkDirectory(const OUString& str, oslCheckMode nCheckMode)
{
    OUString aUString;
    DirectoryItem rItem;
    osl::FileBase::RC rc;
    bool bCheckResult= false;

    Directory aDir(str);
    rc = aDir.open();

    if ((rc != osl::FileBase::E_NOENT) && (rc != osl::FileBase::E_ACCES))
    {
        switch (nCheckMode)
        {
            case oslCheckMode::Exist:
                if (rc == ::osl::FileBase::E_None)
                    bCheckResult = true;
                break;
            case oslCheckMode::OpenAccess:
                if (rc == osl::FileBase::E_None)
                    bCheckResult = true;
                break;
            case oslCheckMode::ReadAccess:
                rc = aDir.getNextItem(rItem);
                bCheckResult = (rc == osl::FileBase::E_None) || (rc == osl::FileBase::E_NOENT);
                break;
            case oslCheckMode::WriteAccess:
                ((aUString += str) += aSlashURL) += aTmpName2;
                if (Directory::create(aUString) == osl::FileBase::E_None)
                {
                    bCheckResult = true;
                    rc = Directory::remove(aUString);
                    CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, rc);
                }
                else
                {
                    bCheckResult = false;
                }
                break;

            default:
                bCheckResult = false;
        }

        rc = aDir.close();
        CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, rc);
    }

    return bCheckResult;
}

/** construct error message
*/

static OString outputError(const OString & returnVal, const OString & rightVal, const char * msg = "")
{
    if (returnVal == rightVal)
        return OString();

    OString aString = msg +
        OString::Concat(": the returned value is '") +
        returnVal +
        "', but the value should be '" +
        rightVal +
        "'.";
    return aString;
}

#if (defined UNX) /* chmod() method is different in Windows */
/** Change file mode, two version in UNIX and Windows;.
*/

static void changeFileMode(OUString & filepath, sal_Int32 mode)
{
    OString aString;
    OUString aUStr = filepath.copy(0);

    if (isURL(filepath))
        osl::FileBase::getSystemPathFromFileURL(filepath, aUStr);

    aString = OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US);
    int ret = chmod(aString.getStr(), mode);
    CPPUNIT_ASSERT_EQUAL(0, ret);
}
#else
static void hideFile(const OUString& filepath)
{
    OUString aSysPath(filepath);

    if (isURL(filepath))
        osl::FileBase::getSystemPathFromFileURL(filepath, aSysPath);

    bool ret = SetFileAttributesW(o3tl::toW(aSysPath.getStr()), FILE_ATTRIBUTE_HIDDEN);
    CPPUNIT_ASSERT(ret);
}
#endif

#if 0
#if defined UNX
static OUString getCurrentPID();
#endif
#endif

// Beginning of the test cases for osl::FileBase class

namespace osl_FileBase
{
    // testing the method
    // static inline RC getAbsoluteFileURL(const OUString& ustrBaseDirectoryURL,
    //                                      const OUString& ustrRelativeFileURL,
    //                                      OUString& ustrAbsoluteFileURL)

    class getAbsoluteFileURL : public CppUnit::TestFixture
    {
    public:
        void check_getAbsoluteFileURL(OUString const& _suBaseURL,
                                      OString const& _sRelativeURL,
                                      osl::FileBase::RC _nAssumeError,
                                      OUString const& _suAssumeResultStr);

        void getAbsoluteFileURL_001_1();
        void getAbsoluteFileURL_001_2();
        void getAbsoluteFileURL_001_3();
        void getAbsoluteFileURL_001_4();
        void getAbsoluteFileURL_001_5();
        void getAbsoluteFileURL_001_6();
        void getAbsoluteFileURL_001_7();
        void getAbsoluteFileURL_001_8();
        void getAbsoluteFileURL_002();
        void getAbsoluteFileURL_003();
        void getAbsoluteFileURL_004();

        CPPUNIT_TEST_SUITE(getAbsoluteFileURL);
            CPPUNIT_TEST(getAbsoluteFileURL_001_1);
            CPPUNIT_TEST(getAbsoluteFileURL_001_2);
            CPPUNIT_TEST(getAbsoluteFileURL_001_3);
            CPPUNIT_TEST(getAbsoluteFileURL_001_4);
            CPPUNIT_TEST(getAbsoluteFileURL_001_5);
            CPPUNIT_TEST(getAbsoluteFileURL_001_6);
            CPPUNIT_TEST(getAbsoluteFileURL_001_7);
            CPPUNIT_TEST(getAbsoluteFileURL_001_8);
            CPPUNIT_TEST(getAbsoluteFileURL_002);
            CPPUNIT_TEST(getAbsoluteFileURL_003);
            CPPUNIT_TEST(getAbsoluteFileURL_004);
        CPPUNIT_TEST_SUITE_END();
    };

    void getAbsoluteFileURL::check_getAbsoluteFileURL(OUString const& _suBaseURL,
                                                      OString const& _sRelativeURL,
                                                      osl::FileBase::RC _nAssumeError,
                                                      OUString const& _suAssumeResultStr)
    {
        OUString suRelativeURL = OStringToOUString(_sRelativeURL, RTL_TEXTENCODING_UTF8);
        OString sBaseURL = OUStringToOString(_suBaseURL, RTL_TEXTENCODING_UTF8);
        OUString suResultURL;
        osl::FileBase::RC nError = osl::FileBase::getAbsoluteFileURL(_suBaseURL, suRelativeURL, suResultURL);
        OString sResultURL = OUStringToOString(suResultURL, RTL_TEXTENCODING_UTF8);
        OString sError = errorToString(nError);
        printf("getAbsoluteFileURL('%s','%s') deliver absolute URL: '%s', error '%s'\n",
                sBaseURL.getStr(), _sRelativeURL.getStr(),sResultURL.getStr(), sError.getStr());
        CPPUNIT_ASSERT_EQUAL_MESSAGE("Assumption is wrong: error number is wrong", _nAssumeError, nError);

        if (nError == osl::FileBase::E_None)
        {
            CPPUNIT_ASSERT_EQUAL_MESSAGE("Assumption is wrong: ResultURL is not equal to expected URL ", _suAssumeResultStr, suResultURL);
        }
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_001_1()
    {
        OUString suAssume = aUserDirectoryURL + "/relative/file1";
        check_getAbsoluteFileURL(aUserDirectoryURL, "relative/file1"_ostr,osl::FileBase::E_None, suAssume);
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_001_2()
    {
        OUString suAssume = aUserDirectoryURL + "/relative/file2";
        check_getAbsoluteFileURL(aUserDirectoryURL, "relative/./file2"_ostr,osl::FileBase::E_None, suAssume);
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_001_3()
    {
        OUString suAssume = aUserDirectoryURL + "/file3";
        check_getAbsoluteFileURL(aUserDirectoryURL, "relative/../file3"_ostr,osl::FileBase::E_None, suAssume);
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_001_4()
    {
        OUString suAssume = aUserDirectoryURL + "/file4";
        check_getAbsoluteFileURL(aUserDirectoryURL, "././relative/../file4"_ostr,osl::FileBase::E_None, suAssume);
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_001_5()
    {
        OUString suAssume;
        suAssume = aUserDirectoryURL + "/relative/";
        check_getAbsoluteFileURL(aUserDirectoryURL, "././relative/."_ostr,osl::FileBase::E_None, suAssume);
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_001_6()
    {
        OUString suAssume = aUserDirectoryURL + "/.relative";
        check_getAbsoluteFileURL(aUserDirectoryURL, "./.relative"_ostr,osl::FileBase::E_None, suAssume);
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_001_7()
    {
        OUString suAssume;
        suAssume = aUserDirectoryURL + "/.a/";
        check_getAbsoluteFileURL(aUserDirectoryURL, "./.a/mydir/.."_ostr,osl::FileBase::E_None, suAssume);
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_001_8()
    {
        OUString suAssume = aUserDirectoryURL + "/tmp/ok";
        check_getAbsoluteFileURL(aUserDirectoryURL, "tmp//ok"_ostr,osl::FileBase::E_None, suAssume);
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_002()
    {
#if 0
#if (defined UNX) // Link is not defined in Windows
        OUString aUStr_LnkFileSys(aTempDirectorySys), aUStr_SrcFileSys(aTempDirectorySys);
        aUStr_LnkFileSys += aSlashURL + getCurrentPID() + "/link.file";
        aUStr_SrcFileSys += aSlashURL + getCurrentPID() + "/canonical.name";

        OString strLinkFileName, strSrcFileName;
        strLinkFileName = OUStringToOString(aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US);
        strSrcFileName =  OUStringToOString(aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US);

        createTestFile(aCanURL1);
        sal_Int32 fd = symlink(strSrcFileName.getStr(), strLinkFileName.getStr());
        CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), fd);
        OString sLnkURL = OUStringToOString(aLnkURL1, RTL_TEXTENCODING_ASCII_US);
        OUString suAssume = aUserDirectoryURL + "/canonical.name";
        check_getAbsoluteFileURL(aUserDirectoryURL, sLnkURL, osl::FileBase::E_None, suAssume);
        deleteTestFile(aCanURL1);
        fd = remove(strLinkFileName.getStr());
        CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), fd);
#endif
#endif
    }

    // please see line# 930
    void getAbsoluteFileURL::getAbsoluteFileURL_003()
    {
    }

    void getAbsoluteFileURL::getAbsoluteFileURL_004()
    {
        // create two level directories under $Temp/PID/
        OUString aUStrUpBase = aUserDirectoryURL + "/test1";
        createTestDirectory(aUStrUpBase);
        OUString aUStrBase = aUserDirectoryURL + "/test1/dir1";
        createTestDirectory(aUStrBase);

        OUString suAssume = aUserDirectoryURL + "/mytestfile";
        check_getAbsoluteFileURL(aUStrBase, "../../mytestfile"_ostr , osl::FileBase::E_None, suAssume);
        deleteTestDirectory(aUStrBase);
        deleteTestDirectory(aUStrUpBase);
    }

    // testing two methods:
    // static inline RC getSystemPathFromFileURL(const OUString& ustrFileURL,
    //                OUString& ustrSystemPath)
    // static RC getFileURLFromSystemPath(const OUString & ustrSystemPath,
    //                OUString & ustrFileURL);

    class SystemPath_FileURL : public CppUnit::TestFixture
    {
    public:
        void getSystemPathFromFileURL_001_1();
        void getSystemPathFromFileURL_001_2();
        void getSystemPathFromFileURL_001_21();
        void getSystemPathFromFileURL_001_22();
        void getSystemPathFromFileURL_001_3();
        void getSystemPathFromFileURL_001_31();
        void getSystemPathFromFileURL_001_4();
        void getSystemPathFromFileURL_001_41();
        void getSystemPathFromFileURL_001_5();
        void getSystemPathFromFileURL_001_51();
        void getSystemPathFromFileURL_001_52();
        void getSystemPathFromFileURL_001_53();
        void getSystemPathFromFileURL_001_6();
        void getSystemPathFromFileURL_001_61();
        void getSystemPathFromFileURL_001_7();
        void getSystemPathFromFileURL_001_71();
        void getSystemPathFromFileURL_001_8();
        void getSystemPathFromFileURL_001_81();
        void getSystemPathFromFileURL_001_9();
        void getSystemPathFromFileURL_001_91();
        void getSystemPathFromFileURL_001_92();
        void getSystemPathFromFileURL_004();
        void getSystemPathFromFileURL_005();

        // test case for getFileURLFromSystemPath
        void getFileURLFromSystemPath_001();
        void getFileURLFromSystemPath_002();
        void getFileURLFromSystemPath_003();
        void getFileURLFromSystemPath_004();
        void getFileURLFromSystemPath_004_1();
        void getFileURLFromSystemPath_005();

        CPPUNIT_TEST_SUITE(SystemPath_FileURL);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_1);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_2);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_21);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_22);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_3);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_31);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_4);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_41);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_5);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_51);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_52);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_53);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_6);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_61);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_7);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_71);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_8);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_81);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_9);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_91);
            CPPUNIT_TEST(getSystemPathFromFileURL_001_92);
            CPPUNIT_TEST(getSystemPathFromFileURL_004);
            CPPUNIT_TEST(getSystemPathFromFileURL_005);
            CPPUNIT_TEST(getFileURLFromSystemPath_001);
            CPPUNIT_TEST(getFileURLFromSystemPath_002);
            CPPUNIT_TEST(getFileURLFromSystemPath_003);
            CPPUNIT_TEST(getFileURLFromSystemPath_004);
            CPPUNIT_TEST(getFileURLFromSystemPath_004_1);
            CPPUNIT_TEST(getFileURLFromSystemPath_005);
        CPPUNIT_TEST_SUITE_END();

    private:
        void check_SystemPath_FileURL(
                OString const& _sSource,
                osl::FileBase::RC _nAssumeError,
                OString const& _sAssumeResultStr,
                bool bDirection = true);

        void checkWNTBehaviour_getSystemPathFromFileURL(
                OString const& _sURL,
                osl::FileBase::RC _nAssumeError,
                OString const& _sWNTAssumeResultString);

        void checkUNXBehaviour_getSystemPathFromFileURL(
                OString const& _sURL,
                osl::FileBase::RC _nAssumeError,
                OString const& _sUnixAssumeResultString);

        void checkWNTBehaviour_getFileURLFromSystemPath(OString const& _sSysPath,
                osl::FileBase::RC _nAssumeError,
                OString const& _sWNTAssumeResultString);

        void checkUNXBehaviour_getFileURLFromSystemPath(
                OString const& _sSysPath,
                osl::FileBase::RC _nAssumeError,
                OString const& _sUnixAssumeResultString);

    };

    // if bDirection==sal_True, check getSystemPathFromFileURL
    // if bDirection==sal_False, check getFileURLFromSystemPath
    void SystemPath_FileURL::check_SystemPath_FileURL(
            OString const& _sSource,
            osl::FileBase::RC _nAssumeError,
            OString const& _sAssumeResultStr,
            bool bDirection)
    {
        // PRE: URL as String
        OUString suSource;
        OUString suStr;
        suSource = OStringToOUString(_sSource, RTL_TEXTENCODING_UTF8);
        osl::FileBase::RC nError;

        if (bDirection)
            nError = osl::FileBase::getSystemPathFromFileURL(suSource, suStr);
        else
            nError = osl::FileBase::getFileURLFromSystemPath(suSource, suStr);

        // if the given string is gt length 0,
        // we check also this string
        OString sStr = OUStringToOString(suStr, RTL_TEXTENCODING_UTF8);
        OString sError = errorToString(nError);

        if (bDirection)
            printf("getSystemPathFromFileURL('%s') deliver system path: '%s', error '%s'\n",
                    _sSource.getStr(), sStr.getStr(), sError.getStr());
        else
            printf("getFileURLFromSystemPath('%s') deliver File URL: '%s', error '%s'\n",
                    _sSource.getStr(), sStr.getStr(), sError.getStr());

        if (!_sAssumeResultStr.isEmpty())
        {
            bool bStrAreEqual = _sAssumeResultStr == sStr;
            CPPUNIT_ASSERT_EQUAL_MESSAGE("Assumption is wrong",
                                    _nAssumeError, nError);
            CPPUNIT_ASSERT_MESSAGE("Assumption is wrong",
                                    bStrAreEqual);
        }
        else
        {
            CPPUNIT_ASSERT_EQUAL_MESSAGE("Assumption is wrong", _nAssumeError, nError);
        }
    }

    void SystemPath_FileURL::checkWNTBehaviour_getSystemPathFromFileURL(
            OString const& _sURL,
            osl::FileBase::RC _nAssumeError,
            OString const& _sWNTAssumeResultString)
    {
#if defined(_WIN32)
        check_SystemPath_FileURL(_sURL, _nAssumeError, _sWNTAssumeResultString);
#else
        (void)_sURL;
        (void)_nAssumeError;
        (void)_sWNTAssumeResultString;
#endif
    }

    void SystemPath_FileURL::checkUNXBehaviour_getSystemPathFromFileURL(
            OString const& _sURL,
            osl::FileBase::RC _nAssumeError,
            OString const& _sUnixAssumeResultString)
    {
#if (defined UNX)
        check_SystemPath_FileURL(_sURL, _nAssumeError, _sUnixAssumeResultString);
#else
        (void)_sURL;
        (void)_nAssumeError;
        (void)_sUnixAssumeResultString;
#endif
    }

    void SystemPath_FileURL::checkWNTBehaviour_getFileURLFromSystemPath(
            OString const& _sSysPath,
            osl::FileBase::RC _nAssumeError,
            OString const& _sWNTAssumeResultString)
    {
#if defined(_WIN32)
        check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sWNTAssumeResultString, false);
#else
        (void)_sSysPath;
        (void)_nAssumeError;
        (void)_sWNTAssumeResultString;
#endif
    }

    void SystemPath_FileURL::checkUNXBehaviour_getFileURLFromSystemPath(
            OString const& _sSysPath,
            osl::FileBase::RC _nAssumeError,
            OString const& _sUnixAssumeResultString)
    {
#if (defined UNX)
        check_SystemPath_FileURL(_sSysPath, _nAssumeError, _sUnixAssumeResultString, false);
#else
        (void)_sSysPath;
        (void)_nAssumeError;
        (void)_sUnixAssumeResultString;
#endif
    }

    /** Test for getSystemPathFromFileURL()
        this test is split into 2 different OS tests,
        the first function checkUNXBehaviour... runs only on Unix based Systems,
        the second only on windows based systems
        the first parameter are a file URL where we want to get the system path of,
        the second parameter is the assumed error of the osl_getSystemPathFromFileURL() function,
        the third parameter is the assumed result string, the string will only test, if its length is greater than 0
    */


    void SystemPath_FileURL::getSystemPathFromFileURL_001_1()
    {
        OString sURL(""_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_2()
    {
        OString sURL("/"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "\\"_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_21()
    {
        /* From RFC3986, "2.2. Reserved Characters":

           "The purpose of reserved characters is to provide a set of delimiting
           characters that are distinguishable from other data within a URI.
           URIs that differ in the replacement of a reserved character with its
           corresponding percent-encoded octet are not equivalent.  Percent-
           encoding a reserved character, or decoding a percent-encoded octet
           that corresponds to a reserved character, will change how the URI is
           interpreted by most applications.  Thus, characters in the reserved
           set are protected from normalization and are therefore safe to be
           used by scheme-specific and producer-specific algorithms for
           delimiting data subcomponents within a URI."

           In other words, %2F ("/") is NOT the same as /.
        */

        OString sURL("%2F"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_22()
    {
        OString sURL("file:///tmp%2Fmydir"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_3()
    {
        OString sURL("a"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "a"_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_31()
    {
        OString sURL("tmpname"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "tmpname"_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_4()
    {
        OString sURL("file://"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, ""_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_41()
    {
        OString sURL("file://localhost/tmp"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, ""_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_5()
    {
        OString sURL("file:///tmp"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_51()
    {
        OString sURL("file://c:/tmp"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_52()
    {
        OString sURL("file:///c:/tmp"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp"_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_53()
    {
        OString sURL("file:///c|/tmp"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c|/tmp"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp"_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_6()
    {
        OString sURL("file:///tmp/first"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_61()
    {
        OString sURL("file:///c:/tmp/first"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first"_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_7()
    {
        OString sURL("file:///tmp/../second"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/../second"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_71()
    {
        OString sURL("file:///c:/tmp/../second"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/../second"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\..\\second"_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_8()
    {
        OString sURL("../tmp"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "../tmp"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "..\\tmp"_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_81()
    {
#if 0
        OString sURL("file://~/tmp");
        char* home_path;
        home_path = getenv("HOME");
        OString expResult(home_path ? home_path : "");
        expResult += "/tmp";
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, expResult);
#endif
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_9()
    {
        OString sURL("file:///tmp/first%20second"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/tmp/first second"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_91()
    {
        OString sURL("file:///c:/tmp/first%20second"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "/c:/tmp/first second"_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_None, "c:\\tmp\\first second"_ostr);
    }

    void SystemPath_FileURL::getSystemPathFromFileURL_001_92()
    {
        OString sURL("ca@#;+.,$///78no%01ni..name"_ostr);
        checkUNXBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
        checkWNTBehaviour_getSystemPathFromFileURL(sURL, osl::FileBase::E_INVAL, ""_ostr);
    }

    // normal legal case
    void SystemPath_FileURL::getSystemPathFromFileURL_004()
    {
        OUString aUStr;
        OUString aUNormalURL(aTmpName6);
        OUString aUResultURL (aSysPath4);
        osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL(aUNormalURL, aUStr);

        bool bOk = compareFileName(aUStr, aUResultURL);

        OString sError =
            "test for getSystemPathFromFileURL(' " +
            OUStringToOString(aUNormalURL, RTL_TEXTENCODING_ASCII_US) +
            " ') function:use an absolute file URL, " +
            outputError(OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US),
                        OUStringToOString(aUResultURL, RTL_TEXTENCODING_ASCII_US));

        CPPUNIT_ASSERT_EQUAL_MESSAGE(sError.getStr(), osl::FileBase::E_None, nError);
        CPPUNIT_ASSERT_MESSAGE(sError.getStr(), bOk);

    }

    // CJK characters case
    void SystemPath_FileURL::getSystemPathFromFileURL_005()
    {
        OUString aUStr;
        createTestDirectory(aTmpName10);
        OUString aUNormalURL(aTmpName10);
        OUString aUResultURL (aSysPath5);

        osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL(aUNormalURL, aUStr);

        bool bOk = compareFileName(aUStr, aUResultURL);

        OString sError =
            "test for getSystemPathFromFileURL(' " +
            OUStringToOString(aUNormalURL, RTL_TEXTENCODING_ASCII_US) +
            " ') function:use a CJK coded absolute URL, " +
            outputError(OUStringToOString(aUStr, RTL_TEXTENCODING_ASCII_US),
                        OUStringToOString(aUResultURL, RTL_TEXTENCODING_ASCII_US));
        deleteTestDirectory(aTmpName10);

        CPPUNIT_ASSERT_EQUAL_MESSAGE(sError.getStr(), osl::FileBase::E_None, nError);
        CPPUNIT_ASSERT_MESSAGE(sError.getStr(), bOk);
    }

    void SystemPath_FileURL::getFileURLFromSystemPath_001()
    {
        OString sSysPath("~/tmp"_ostr);
        char* home_path;
        home_path = getenv("HOME");
        OString expResult(home_path ? home_path : "");
        expResult = "file://"+ expResult + "/tmp";
        checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, expResult);
        checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "~/tmp"_ostr);
    }

    void SystemPath_FileURL::getFileURLFromSystemPath_002()
    {
        OString sSysPath("c:/tmp"_ostr);
        checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "c:/tmp"_ostr);
        checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///c:/tmp"_ostr);
    }

    void SystemPath_FileURL::getFileURLFromSystemPath_003()
    {
        OString sSysPath("file:///temp"_ostr);
        checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""_ostr);
        checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getFileURLFromSystemPath_004()
    {
        OString sSysPath("//tmp//first start"_ostr);
        checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///tmp/first%20start"_ostr);
        checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getFileURLFromSystemPath_004_1()
    {
        OString sSysPath("/tmp///first start"_ostr);
        checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_None, "file:///tmp/first%20start"_ostr);
        checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""_ostr);
    }

    void SystemPath_FileURL::getFileURLFromSystemPath_005()
    {
        OString sSysPath(""_ostr);
        checkUNXBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""_ostr);
        checkWNTBehaviour_getFileURLFromSystemPath(sSysPath, osl::FileBase::E_INVAL, ""_ostr);
    }

    // testing the method
    // static inline RC searchFileURL( const OUString& ustrFileName,
    //                                  const OUString& ustrSearchPath,
    //                                  OUString& ustrFileURL)

    class searchFileURL : public CppUnit::TestFixture
    {
    private:
        OUString aUStr;

    public:
        void searchFileURL_001()
        {
            /* search file is passed by system filename */
            auto nError1 = osl::FileBase::searchFileURL(aTmpName1, aUserDirectorySys, aUStr);
            /* search file is passed by full qualified file URL */
            auto nError2 = osl::FileBase::searchFileURL(aCanURL1, aUserDirectorySys, aUStr);
            /* search file is passed by relative file path */
            auto nError3 = osl::FileBase::searchFileURL(aRelURL4, aUserDirectorySys, aUStr);

            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched files that is not exist, but it reply invalid error, did not pass in (W32) ",
                                     osl::FileBase::E_NOENT, nError1);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched files that is not exist, but it reply invalid error, did not pass in (W32) ",
                                     osl::FileBase::E_NOENT, nError2);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched files that is not exist, but it reply invalid error, did not pass in (W32) ",
                                    osl::FileBase::E_NOENT, nError3);
        }

         void searchFileURL_002()
        {
#ifndef UNX
            /* search file is passed by system filename */
            OUString strRootSys = INetURLObject(aTempDirectoryURL).GetLastName();
            auto nError1 = osl::FileBase::searchFileURL(aTempDirectorySys, strRootSys, aUStr);
            bool bOk1 = compareFileName(aUStr, aTempDirectoryURL);
            /* search file is passed by full qualified file URL */
            auto nError2 = osl::FileBase::searchFileURL(aTempDirectoryURL, strRootSys, aUStr);
            bool bOk2 = compareFileName(aUStr, aTempDirectoryURL);
#ifndef _WIN32
            /* search file is passed by relative file path */
            auto nError3 = osl::FileBase::searchFileURL(aRelURL5, strRootSys, aUStr);
            bool bOk3 = compareFileName(aUStr, aTempDirectoryURL);
#endif
            /* search file is passed by an exist file */
            createTestFile(aCanURL1);
            auto nError4 = osl::FileBase::searchFileURL(aCanURL4, aUserDirectorySys, aUStr);
            bool bOk4 = compareFileName(aUStr, aCanURL1);
            deleteTestFile(aCanURL1);

            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename, system directory, searched file already exist.",
                                    osl::FileBase::E_None, nError1);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: URL filename, system directory, searched file already exist.",
                                    osl::FileBase::E_None, nError2);
#ifndef _WIN32
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: relative path, system directory, searched file already exist.",
                                    osl::FileBase::E_None, nError3);
#endif
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.",
                                    osl::FileBase::E_None, nError4);
            CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: system filename, system directory, searched file already exist.",
                                    bOk1);
            CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: URL filename, system directory, searched file already exist.",
                                    bOk2);
#ifndef _WIN32
            CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: relative path, system directory, searched file already exist.",
                                    bOk3);
#endif
            CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: system filename/URL filename/relative path, system directory, searched file already exist.",
                                    bOk4);
#endif
        }

        void searchFileURL_003()
        {
            OUString aSystemPathList(aRootSys + PATH_LIST_DELIMITER + aTempDirectorySys + PATH_LIST_DELIMITER + aRootSys + "system/path");
            auto nError1 = osl::FileBase::searchFileURL(aUserDirectoryURL, aSystemPathList, aUStr);
            bool bOk = compareFileName(aUStr, aUserDirectoryURL);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: search directory is a list of system paths",
                                    osl::FileBase::E_None, nError1);
            CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: search directory is a list of system paths",
                                    bOk);
        }

        void searchFileURL_004()
        {
            OUString aSystemPathList(aRootSys + PATH_LIST_DELIMITER + aTempDirectorySys + PATH_LIST_DELIMITER + aRootSys + "system/path/../name");
            auto nError1 = osl::FileBase::searchFileURL(aUserDirectoryURL, aSystemPathList, aUStr);
            bool bOk = compareFileName(aUStr, aUserDirectoryURL);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: search directory is a list of system paths",
                                    osl::FileBase::E_None, nError1);
            CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: search directory is a list of system paths",
                                    bOk);
        }

        void searchFileURL_005()
        {
            auto nError1 = osl::FileBase::searchFileURL(aUserDirectoryURL, aNullURL, aUStr);
            bool bOk = compareFileName(aUStr, aUserDirectoryURL);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for searchFileURL function: search directory is NULL",
                                    osl::FileBase::E_None, nError1);
            CPPUNIT_ASSERT_MESSAGE("test for searchFileURL function: search directory is NULL",
                                    bOk);
        }

        CPPUNIT_TEST_SUITE(searchFileURL);
            CPPUNIT_TEST(searchFileURL_001);
            CPPUNIT_TEST(searchFileURL_002);
            CPPUNIT_TEST(searchFileURL_003);
            CPPUNIT_TEST(searchFileURL_004);
            CPPUNIT_TEST(searchFileURL_005);
        CPPUNIT_TEST_SUITE_END();
    };

    // testing the method
    // static inline RC getTempDirURL(OUString& ustrTempDirURL)

    class getTempDirURL : public CppUnit::TestFixture
    {
    private:
        OUString aUStr;

    public:
        void setUp() override
        {
            osl::FileBase::RC nError = osl::FileBase::getTempDirURL(aUStr);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for getTempDirURL function: execution",
                                     osl::FileBase::E_None, nError);
        }

        void getTempDirURL_002()
        {
            CPPUNIT_ASSERT_MESSAGE("test for getTempDirURL function: test for open and write access rights",
                                    checkDirectory(aUStr, oslCheckMode::OpenAccess));
            CPPUNIT_ASSERT_MESSAGE("test for getTempDirURL function: test for open and write access rights",
                                    checkDirectory(aUStr, oslCheckMode::ReadAccess));
            CPPUNIT_ASSERT_MESSAGE("test for getTempDirURL function: test for open and write access rights",
                                    checkDirectory(aUStr, oslCheckMode::WriteAccess));
        }

        CPPUNIT_TEST_SUITE(getTempDirURL);
            CPPUNIT_TEST(getTempDirURL_002);
        CPPUNIT_TEST_SUITE_END();
    };

    //  testing the method
    //  static inline RC createTempFile(OUString* pustrDirectoryURL,
    //                                   oslFileHandle* pHandle,
    //                                   OUString* pustrTempFileURL)

    class createTempFile : public CppUnit::TestFixture
    {
    private:
        std::unique_ptr<oslFileHandle> pHandle;
        std::unique_ptr<OUString> pUStr_DirURL;
        std::unique_ptr<OUString> pUStr_FileURL;

    public:
        void setUp() override
        {
            pHandle.reset(new oslFileHandle());
            pUStr_DirURL.reset(new OUString(aUserDirectoryURL));
            pUStr_FileURL.reset(new OUString());
        }

        void tearDown() override
        {
            pUStr_DirURL.reset();
            pUStr_FileURL.reset();
            pHandle.reset();
        }

        void createTempFile_001()
        {
            auto nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), pHandle.get(), pUStr_FileURL.get());
            File testFile(*pUStr_FileURL);
            auto nError2 = testFile.open(osl_File_OpenFlag_Create);

            if (nError2 == osl::FileBase::E_EXIST)
            {
                osl_closeFile(*pHandle);
                deleteTestFile(*pUStr_FileURL);
            }

            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for createTempFile function: create temp file and test the existence",
                                     osl::FileBase::E_None, nError1);
            CPPUNIT_ASSERT_MESSAGE("test for createTempFile function: create temp file and test the existence",
                                     (pHandle != nullptr));
            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for createTempFile function: create temp file and test the existence",
                                     osl::FileBase::E_EXIST, nError2);
        }

        void createTempFile_002()
        {
            bool bOK = false;
            auto nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), pHandle.get(), pUStr_FileURL.get());
            File testFile(*pUStr_FileURL);
            auto nError2 = testFile.open(osl_File_OpenFlag_Create);

            CPPUNIT_ASSERT_EQUAL_MESSAGE("createTempFile function: create a temp file, but it does not exist",
                osl::FileBase::E_None, nError1);
            CPPUNIT_ASSERT_MESSAGE("createTempFile function: create a temp file, but it does not exist",
                (pHandle != nullptr));
            CPPUNIT_ASSERT_EQUAL_MESSAGE("createTempFile function: create a temp file, but it does not exist",
                osl::FileBase::E_EXIST, nError2);

            // check file if have the write permission
            if (nError2 == osl::FileBase::E_EXIST)
            {
                bOK = ifFileCanWrite(*pUStr_FileURL);
                osl_closeFile(*pHandle);
                deleteTestFile(*pUStr_FileURL);
            }

            CPPUNIT_ASSERT_MESSAGE("test for open and write access rights, in (W32), it did not have write access right, but it should be writable.",
                                     bOK);
        }

        void createTempFile_003()
        {
            auto nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), pHandle.get(), nullptr);
            // the temp file will be removed when return from createTempFile
            bool bOK = (pHandle != nullptr && nError1 == osl::FileBase::E_None);
            if (bOK)
                osl_closeFile(*pHandle);

            CPPUNIT_ASSERT_EQUAL_MESSAGE("test for createTempFile function: set pUStrFileURL to 0 to let it remove the file after call.",
                                osl::FileBase::E_None, nError1);
            CPPUNIT_ASSERT_MESSAGE("test for createTempFile function: set pUStrFileURL to 0 to let it remove the file after call.",
                                bOK);
        }

        void createTempFile_004()
        {
            auto nError1 = osl::FileBase::createTempFile(pUStr_DirURL.get(), nullptr, pUStr_FileURL.get());
            bool bOK = (pUStr_FileURL != nullptr);
            CPPUNIT_ASSERT(bOK);
            File testFile(*pUStr_FileURL);
            auto nError2 = testFile.open(osl_File_OpenFlag_Create);
            deleteTestFile(*pUStr_FileURL);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("createTempFile function: create a temp file, but it does not exist",
                osl::FileBase::E_None, nError1);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("createTempFile function: create a temp file, but it does not exist",
                osl::FileBase::E_EXIST, nError2);
            CPPUNIT_ASSERT_MESSAGE("createTempFile function: create a temp file, but it does not exist",
                bOK);

        }

        CPPUNIT_TEST_SUITE(createTempFile);
            CPPUNIT_TEST(createTempFile_001);
            CPPUNIT_TEST(createTempFile_002);
            CPPUNIT_TEST(createTempFile_003);
            CPPUNIT_TEST(createTempFile_004);
        CPPUNIT_TEST_SUITE_END();
    };

    // FIXME: remove the _disabled to enable:
    CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::getAbsoluteFileURL, "osl_osl::FileBase");
    CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::SystemPath_FileURL, "osl_osl::FileBase");
    CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::searchFileURL, "osl_osl::FileBase");
    CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::getTempDirURL, "osl_osl::FileBase");
    CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(osl_FileBase::createTempFile, "osl_osl::FileBase");

    CPPUNIT_REGISTRY_ADD_TO_DEFAULT("osl_osl::FileBase");
}

namespace osl_FileStatus
{
    //  testing the method
    //  FileStatus(sal_uInt32 nMask): _nMask(nMask)
    class ctors : public CppUnit::TestFixture
    {
    private:
        OUString aUStr;
        DirectoryItem rItem;

    public:
        void setUp() override
        {
            // create a tempfile in $TEMP/tmpdir/tmpname.
            createTestDirectory(aTmpName3);
            createTestFile(aTmpName4);

            Directory aDir(aTmpName3);
            auto nError1 = aDir.open();
            CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1);
            nError1 = aDir.getNextItem(rItem);
            CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1);
            aDir.close();
        }

        void tearDown() override
        {
            // remove the tempfile in $TEMP/tmpdir/tmpname.
            deleteTestFile(aTmpName4);
            deleteTestDirectory(aTmpName3);
        }

        void ctors_001()
        {
            FileStatus rFileStatus(osl_FileStatus_Mask_All);
            auto nError1 = rItem.getFileStatus(rFileStatus);
            CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1);
            aUStr = rFileStatus.getFileName();

            CPPUNIT_ASSERT_MESSAGE("test for ctors function: mask all and see the file name",
                                   compareFileName(aUStr, aTmpName2));
        }

        void ctors_002()
        {
            FileStatus rFileStatus(0);
            auto nError1 = rItem.getFileStatus(rFileStatus);
            CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1);
            aUStr = rFileStatus.getFileName();

            CPPUNIT_ASSERT_MESSAGE("test for ctors function: mask is empty",
                                   compareFileName(aUStr, aNullURL));
        }

        CPPUNIT_TEST_SUITE(ctors);
            CPPUNIT_TEST(ctors_001);
            CPPUNIT_TEST(ctors_002);
        CPPUNIT_TEST_SUITE_END();
    };

    //  testing the method
    //  inline sal_Bool isValid(sal_uInt32 nMask) const

    class isValid : public CppUnit::TestFixture
    {
    private:
        std::unique_ptr<Directory> pDir;
        DirectoryItem rItem_file, rItem_link;

    public:
        void setUp() override
        {
            // create a tempfile in $TEMP/tmpdir/tmpname.
            createTestDirectory(aTmpName3);
            createTestFile(aTmpName4);

            pDir.reset(new Directory(aTmpName3));
            osl::FileBase::RC nError1 = pDir->open();
            CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1);
            nError1 = pDir->getNextItem(rItem_file, 1);
            CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1);
        }

        void tearDown() override
        {
            osl::FileBase::RC nError1 = pDir->close();
            pDir.reset();
            CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError1).getStr(), osl::FileBase::E_None, nError1);

            // remove the tempfile in $TEMP/tmpdir/tmpname.
            deleteTestFile(aTmpName4);
            deleteTestDirectory(aTmpName3);
        }

        void isValid_001()
        {
            sal_uInt32 mask = 0;
            FileStatus rFileStatus(mask);
            osl::FileBase::RC nError1 = rItem_file.getFileStatus(rFileStatus);
            CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1);
            bool bOk = rFileStatus.isValid(mask);

            CPPUNIT_ASSERT_MESSAGE("test for isValid function: no fields specified", bOk);
        }

        void check_FileStatus(FileStatus const& _aStatus)
        {
            OString sStat;
            if (_aStatus.isValid(osl_FileStatus_Mask_Type))
                sStat += "type ";
            if (_aStatus.isValid(osl_FileStatus_Mask_Attributes))
                sStat += "attributes ";
            if (_aStatus.isValid(osl_FileStatus_Mask_CreationTime))
                sStat += "ctime ";
            if (_aStatus.isValid(osl_FileStatus_Mask_AccessTime))
                sStat += "atime ";
            if (_aStatus.isValid(osl_FileStatus_Mask_ModifyTime))
                sStat += "mtime ";
            if (_aStatus.isValid(osl_FileStatus_Mask_FileSize))
                sStat += "filesize ";
            if (_aStatus.isValid(osl_FileStatus_Mask_FileName))
                sStat += "filename ";
            if (_aStatus.isValid(osl_FileStatus_Mask_FileURL))
                sStat += "fileurl ";
            printf("mask: %s\n", sStat.getStr());
        }

        void isValid_002()
        {
            createTestFile(aTmpName6);
            sal_uInt32 mask_file = osl_FileStatus_Mask_Type |
                                   osl_FileStatus_Mask_Attributes |
                                   osl_FileStatus_Mask_CreationTime |
                                   osl_FileStatus_Mask_AccessTime |
                                   osl_FileStatus_Mask_ModifyTime |
                                   osl_FileStatus_Mask_FileSize |
                                   osl_FileStatus_Mask_FileName |
                                   osl_FileStatus_Mask_FileURL;

            FileStatus rFileStatus(mask_file);
            DirectoryItem::get(aTmpName6, rItem_file);
            osl::FileBase::RC nError1 = rItem_file.getFileStatus(rFileStatus);

            CPPUNIT_ASSERT_EQUAL_MESSAGE(errorToStr(nError1).getStr(), osl::FileBase::E_None, nError1);

            check_FileStatus(rFileStatus);
            deleteTestFile(aTmpName6);

        }

        /** Check if is a valid linked file.

            Link is not defined in Windows, and on Linux, we can not get the directory item of the linked file.
            We have to defer to filesystems, normal filesystems support links (EXT2, ...), castrated filesystems
            don't have links (FAT, FAT32) and Windows NT NTFS support links, but the Windows API doesn't :-(
        */

        void isValid_003()
        {
#if 0
#if defined (UNX)
            sal_Int32 fd;

            OUString aUStr_LnkFileSys(aTempDirectorySys), aUStr_SrcFileSys(aTempDirectorySys);
            aUStr_LnkFileSys += aSlashURL + getCurrentPID() + "/tmpdir/link.file";
            aUStr_SrcFileSys += aSlashURL + getCurrentPID() + "/tmpdir/tmpname";

            OString strLinkFileName;
            OString strSrcFileName;
            strLinkFileName = OUStringToOString(aUStr_LnkFileSys, RTL_TEXTENCODING_ASCII_US);
            strSrcFileName = OUStringToOString(aUStr_SrcFileSys, RTL_TEXTENCODING_ASCII_US);

            // create a link file and link it to file "/tmp/PID/tmpdir/tmpname"
            fd = symlink(strSrcFileName.getStr(), strLinkFileName.getStr());
            CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), fd);

            // testDirectory is "/tmp/PID/tmpdir/"
            Directory testDirectory(aTmpName3);
            testDirectory.open();
            OUString aFileName ("link.file");
            bool bOk = false;
            while (true)
            {
                osl::FileBase::RC nError1 = testDirectory.getNextItem(rItem_link, 4);

                if (nError1 == osl::FileBase::E_None)
                {
                    sal_uInt32 mask_link = osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_LinkTargetURL;
                    FileStatus rFileStatus(mask_link);
                    rItem_link.getFileStatus(rFileStatus);

                    if (compareFileName(rFileStatus.getFileName(), aFileName))
                    {
                        if (rFileStatus.isValid(osl_FileStatus_Mask_LinkTargetURL))
                        {
                            bOk = true;
                            break;
                        }
                    }
                }
                else
                {
                    break;
                }
            };

            fd = remove(strLinkFileName.getStr());
            CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(0), fd);

            CPPUNIT_ASSERT_MESSAGE("test for isValid function: link file, check for LinkTargetURL", bOk);
#endif
#endif
        }

        void isValid_004()
        {
            sal_uInt32 mask_file_all = osl_FileStatus_Mask_All;
            FileStatus   rFileStatus_all(mask_file_all);
            osl::FileBase::RC nError1 = rItem_file.getFileStatus(rFileStatus_all);
            CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1);

            check_FileStatus(rFileStatus_all);

            sal_uInt32 mask_file_val = osl_FileStatus_Mask_Validate;
            FileStatus   rFileStatus_val(mask_file_val);
            nError1 = rItem_file.getFileStatus(rFileStatus_val);
            CPPUNIT_ASSERT_EQUAL(osl::FileBase::E_None, nError1);

            check_FileStatus(rFileStatus_val);
        }

        CPPUNIT_TEST_SUITE(isValid);
            CPPUNIT_TEST(isValid_001);
            CPPUNIT_TEST(isValid_002);
            CPPUNIT_TEST(isValid_003);
            CPPUNIT_TEST(isValid_004);
        CPPUNIT_TEST_SUITE_END();
    };

    // testing the method
    // inline Type getFileType() const

    class getFileType : public CppUnit::TestFixture
    {
    private:
        DirectoryItem m_aItem_1, m_aItem_2, m_aVolumeItem, m_aFifoItem;
        DirectoryItem m_aLinkItem, m_aSocketItem, m_aSpecialItem;

    public:
        void setUp() override
        {
            // create a tempfile: $TEMP/tmpdir/tmpname.
            //        a tempdirectory: $TEMP/tmpdir/tmpdir.
            //        use $ROOT/staroffice as volume ---> use dev/fd as volume.
            // and get their directory item.
            createTestDirectory(aTmpName3);
            createTestFile(aTmpName3, aTmpName2);
            createTestDirectory(aTmpName3, aTmpName1);

            std::unique_ptr<Directory> xDir(new Directory(aTmpName3));
            auto nError1 = xDir->open();
            CPPUNIT_ASSERT_EQUAL_MESSAGE("open aTmpName3 failed!", osl::FileBase::E_None, nError1);
            // getNextItem can not assure which item retrieved
            nError1 = xDir->getNextItem(m_aItem_1, 1);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("get first item failed!", osl::FileBase::E_None, nError1);

            nError1 = xDir->getNextItem(m_aItem_2);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("get second item failed!", osl::FileBase::E_None, nError1);
            xDir->close();
            // FIXME mindy: failed on my RH9, so removed temporarily
            // nError1 = DirectoryItem::get(aVolURL2, m_aVolumeItem);
            // CPPUNIT_ASSERT_MESSAGE("get volume item failed!", osl::FileBase::E_None == nError1);
        }

        void tearDown() override
        {
            // remove all in $TEMP/tmpdir.
            deleteTestDirectory(aTmpName3, aTmpName1);
            deleteTestFile(aTmpName3, aTmpName2);
            deleteTestDirectory(aTmpName3);
        }

        void getFileType_001()
        {
            FileStatus   rFileStatus(osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName);
            auto nError1 = m_aItem_1.getFileStatus(rFileStatus);
            CPPUNIT_ASSERT_EQUAL_MESSAGE("getFileStatus failed", osl::FileBase::E_None, nError1);

            check_FileType(rFileStatus);
        }

        void check_FileType(osl::FileStatus const& _rFileStatus)
        {
            if (_rFileStatus.isValid(osl_FileStatus_Mask_FileName))
            {
                OUString suFilename = _rFileStatus.getFileName();

                if (_rFileStatus.isValid(osl_FileStatus_Mask_Type))
                {
                    osl::FileStatus::Type eType = _rFileStatus.getFileType();
                    bool bOK = false;

                    if (compareFileName(suFilename, aTmpName2))
                        bOK = (eType == osl::FileStatus::Regular);

                    if (compareFileName(suFilename, aTmpName1))
                        bOK = (eType == FileStatus::Directory);

                    CPPUNIT_ASSERT_MESSAGE("test for getFileType function: ", bOK);
                }
            }
--> --------------------

--> maximum size reached

--> --------------------

Messung V0.5
C=93 H=100 G=96

¤ Dauer der Verarbeitung: 0.21 Sekunden  (vorverarbeitet)  ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

Beweissystem der NASA

Beweissystem Isabelle

NIST Cobol Testsuite

Cephes Mathematical Library

Wiener Entwicklungsmethode

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.