// SPDX-FileCopyrightText: 2025 - 2026 UnionTech Software Technology Co., Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

#include <gtest/gtest.h>
#include <QTest>
#include <QUrl>
#include <QFileInfo>
#include <QDir>
#include <QTemporaryFile>
#include <QStandardPaths>
#include <QSet>
#include <QRegularExpression>
#include <QProcess>
#include <QDBusReply>
#include <QDBusMessage>
#include <QDBusConnection>
#include <QDBusInterface>
#include <QApplication>
#include <QScreen>
#include <QImage>
#include <QColorSpace>
#include <QTimer>
// #include <QTextCodec>  // Qt6中已移除
// #include <QTextDecoder> // Qt6中已移除
#include <QByteArray>
#include <QCollator>
#include <QDateTime>
#include <QThread>
#include <QMutex>
#include <QMutexLocker>
#include <QRegularExpressionMatch>
#include <QList>
#include <QMap>
#include <QPair>
#include <QStringList>
#include <QByteArray>
#include <QChar>
#include <QDir>
#include <QFile>
#include <QTextStream>
#include <QStandardPaths>
#include <QTemporaryDir>
#include <QDebug>

#include <dfm-base/utils/fileutils.h>
#include <dfm-base/utils/desktopfile.h>
#include <dfm-base/utils/sysinfoutils.h>
#include <dfm-base/utils/systempathutil.h>
#include <dfm-base/utils/protocolutils.h>
#include <dfm-base/utils/networkutils.h>
#include <dfm-base/base/standardpaths.h>
#include <dfm-base/base/application/application.h>
#include <dfm-base/base/application/settings.h>
#include <dfm-base/mimetype/dmimedatabase.h>
#include <dfm-base/base/configs/dconfig/dconfigmanager.h>
#include <dfm-base/dfm_global_defines.h>
#include <dfm-base/base/device/deviceutils.h>
#include <dfm-base/base/application/settings.h>
#include <dfm-base/utils/universalutils.h>
#include <dfm-io/dfmio_utils.h>
#include <dfm-io/denumerator.h>
#include <dfm-io/dfile.h>
#include <dfm-base/utils/finallyutil.h>
#include <dfm-base/base/urlroute.h>
#include <dfm-base/base/device/deviceproxymanager.h>
#include <dfm-base/base/schemefactory.h>
#include <dfm-base/utils/windowutils.h>

// Include stub headers
#include "stubext.h"
#include "stub.h"

#include <sys/stat.h>
#include <unistd.h>
#include <linux/limits.h>

using namespace dfmbase;

// Test fixture for FileUtils class

class TestFileUtils : public testing::Test {
protected:
    void SetUp() override {
        // Setup code before each test
    }

    void TearDown() override {
        // Cleanup code after each test
    }
};

// Test formatSize function
TEST_F(TestFileUtils, TestFormatSize) {
    EXPECT_EQ(FileUtils::formatSize(0), "0 B");
    EXPECT_EQ(FileUtils::formatSize(1023), "1023 B");
    EXPECT_EQ(FileUtils::formatSize(1024), "1 KB");
    EXPECT_EQ(FileUtils::formatSize(1025), "1.0009765625 KB");
    EXPECT_EQ(FileUtils::formatSize(1024 * 1024), "1 MB");
    EXPECT_EQ(FileUtils::formatSize(1024 * 1024 * 1024), "1 GB");
    
    // Test with precision
    EXPECT_EQ(FileUtils::formatSize(1025, true, 2), "1 KB");
    
    // Test with custom units
    QStringList customUnits { "Bytes", "KB", "MB" };
    EXPECT_EQ(FileUtils::formatSize(1024, true, 0, -1, customUnits), "1 KB");
}

// Test supportedMaxLength function
TEST_F(TestFileUtils, TestSupportedMaxLength) {
    EXPECT_EQ(FileUtils::supportedMaxLength("vfat"), 11);
    EXPECT_EQ(FileUtils::supportedMaxLength("ext2"), 16);
    EXPECT_EQ(FileUtils::supportedMaxLength("ext3"), 16);
    EXPECT_EQ(FileUtils::supportedMaxLength("ext4"), 16);
    EXPECT_EQ(FileUtils::supportedMaxLength("btrfs"), 255);
    EXPECT_EQ(FileUtils::supportedMaxLength("f2fs"), 512);
    EXPECT_EQ(FileUtils::supportedMaxLength("jfs"), 16);
    EXPECT_EQ(FileUtils::supportedMaxLength("exfat"), 15);
    EXPECT_EQ(FileUtils::supportedMaxLength("nilfs2"), 80);
    EXPECT_EQ(FileUtils::supportedMaxLength("ntfs"), 32);
    EXPECT_EQ(FileUtils::supportedMaxLength("reiserfs"), 15);
    EXPECT_EQ(FileUtils::supportedMaxLength("xfs"), 12);
    
    // Test with unknown filesystem
    EXPECT_EQ(FileUtils::supportedMaxLength("unknown"), 40);
}

// Test preprocessingFileName function
TEST_F(TestFileUtils, TestPreprocessingFileName) {
    // This function uses Application::genericObtuselySetting() which we need to stub
    stub_ext::StubExt stub;
    
    // Create a mock setting that returns a regex for prohibited characters
    QString prohibitedChars = "[\\:*\"?<>|\r\n]";  // Default value
    
    // Stub Application::genericObtuselySetting() to return a mock settings object
    // We'll stub the value() method to return the prohibited characters
    
    // For this test, let's create a filename with prohibited characters
    QString originalName = "test:file?.txt";
    QString expected = "testfile.txt";  // After removing prohibited chars
    
    // Since we can't easily stub complex nested calls, let's test with an empty value
    // which should return the original name
    auto stubFunc = []() {
        class MockSetting {
        public:
            QString value(const QString &, const QString &) {
                return QString();  // Return empty string
            }
        };
        return new MockSetting();
    };
    
    // For now, just test the case where the value is empty
    QString name = "test:file?.txt";
    QString result = FileUtils::preprocessingFileName(name);
    EXPECT_EQ(result, name);  // Should return original if no prohibited chars regex is set
}

// Test processLength function
TEST_F(TestFileUtils, TestProcessLength) {
    QString srcText = "test";
    int srcPos = 2;
    int maxLen = 10;
    bool useCharCount = true;
    QString dstText;
    int dstPos = 0;
    
    bool result = FileUtils::processLength(srcText, srcPos, maxLen, useCharCount, dstText, dstPos);
    
    EXPECT_FALSE(result);  // Should return false since text length is less than maxLen
    EXPECT_EQ(dstText, srcText);
    EXPECT_EQ(dstPos, srcPos);
    
    // Test with text that exceeds max length
    srcText = "this is a very long string";
    maxLen = 5;
    result = FileUtils::processLength(srcText, srcPos, maxLen, useCharCount, dstText, dstPos);
    
    EXPECT_TRUE(result);  // Should return true since text was truncated
    EXPECT_EQ(dstText.length(), maxLen);
    EXPECT_EQ(dstPos, 5);  // Position should be adjusted
}

// Test isDesktopFileSuffix function
TEST_F(TestFileUtils, TestIsDesktopFileSuffix) {
    QUrl desktopUrl("file:///path/to/file.desktop");
    QUrl nonDesktopUrl("file:///path/to/file.txt");
    
    EXPECT_TRUE(FileUtils::isDesktopFileSuffix(desktopUrl));
    EXPECT_FALSE(FileUtils::isDesktopFileSuffix(nonDesktopUrl));
}

// Test trashRootUrl function
TEST_F(TestFileUtils, TestTrashRootUrl) {
    QUrl expected;
    expected.setScheme(DFMBASE_NAMESPACE::Global::Scheme::kTrash);
    expected.setPath("/");
    expected.setHost("");
    
    QUrl actual = FileUtils::trashRootUrl();
    
    EXPECT_EQ(actual.scheme(), expected.scheme());
    EXPECT_EQ(actual.path(), expected.path());
    EXPECT_EQ(actual.host(), expected.host());
}

// Test isTrashFile function
TEST_F(TestFileUtils, TestIsTrashFile) {
    QUrl trashUrl;
    trashUrl.setScheme(DFMBASE_NAMESPACE::Global::Scheme::kTrash);
    
    EXPECT_TRUE(FileUtils::isTrashFile(trashUrl));
    
    QUrl nonTrashUrl("file:///path/to/file.txt");
    EXPECT_FALSE(FileUtils::isTrashFile(nonTrashUrl));
}

// Test isTrashRootFile function
TEST_F(TestFileUtils, TestIsTrashRootFile) {
    QUrl trashRoot = FileUtils::trashRootUrl();
    EXPECT_TRUE(FileUtils::isTrashRootFile(trashRoot));
    
    QUrl nonTrashRoot("file:///path/to/file.txt");
    EXPECT_FALSE(FileUtils::isTrashRootFile(nonTrashRoot));
}

// Test getFileNameLength function
TEST_F(TestFileUtils, TestGetFileNameLength) {
    QUrl url("file:///path/to/file.txt");
    QString name = "test_file.txt";
    
    int length = FileUtils::getFileNameLength(url, name);
    
    // Should return byte length for local files by default
    EXPECT_EQ(length, name.toLocal8Bit().length());
}

// Test cutFileName function
TEST_F(TestFileUtils, TestCutFileName) {
    QString name = "very_long_filename.txt";
    int maxLength = 10;
    bool useCharCount = false;
    
    QString result = FileUtils::cutFileName(name, maxLength, useCharCount);
    
    EXPECT_LE(result.toLocal8Bit().length(), maxLength);
    
    // Test with character count
    useCharCount = true;
    result = FileUtils::cutFileName(name, maxLength, useCharCount);
    EXPECT_LE(result.length(), maxLength);
}

// Test encryptString and decryptString functions
TEST_F(TestFileUtils, TestEncryptDecryptString) {
    QString original = "test_string";
    
    QString encrypted = FileUtils::encryptString(original);
    QString decrypted = FileUtils::decryptString(encrypted);
    
    EXPECT_EQ(original, decrypted);
}

// Test dateTimeFormat function
TEST_F(TestFileUtils, TestDateTimeFormat) {
    QString expected = "yyyy/MM/dd HH:mm:ss";
    QString actual = FileUtils::dateTimeFormat();
    
    EXPECT_EQ(expected, actual);
}

// Test getMemoryPageSize function
TEST_F(TestFileUtils, TestGetMemoryPageSize) {
    quint16 pageSize = FileUtils::getMemoryPageSize();
    
    // Page size should be positive
    EXPECT_GT(pageSize, 0);
}

// Test getCpuProcessCount function
TEST_F(TestFileUtils, TestGetCpuProcessCount) {
    qint32 cpuCount = FileUtils::getCpuProcessCount();
    
    // CPU count should be positive
    EXPECT_GT(cpuCount, 0);
}

// Test cacheCopyingFileUrl, removeCopyingFileUrl, containsCopyingFileUrl functions
TEST_F(TestFileUtils, TestCopyingFileUrlFunctions) {
    QUrl testUrl("file:///path/to/test.txt");
    
    // Initially should not contain the URL
    EXPECT_FALSE(FileUtils::containsCopyingFileUrl(testUrl));
    
    // Add the URL
    FileUtils::cacheCopyingFileUrl(testUrl);
    EXPECT_TRUE(FileUtils::containsCopyingFileUrl(testUrl));
    
    // Remove the URL
    FileUtils::removeCopyingFileUrl(testUrl);
    EXPECT_FALSE(FileUtils::containsCopyingFileUrl(testUrl));
}

// Test DesktopAppUrl functions
TEST_F(TestFileUtils, TestDesktopAppUrl) {
    QUrl trashUrl = DesktopAppUrl::trashDesktopFileUrl();
    QUrl computerUrl = DesktopAppUrl::computerDesktopFileUrl();
    QUrl homeUrl = DesktopAppUrl::homeDesktopFileUrl();
    
    EXPECT_FALSE(trashUrl.isEmpty());
    EXPECT_FALSE(computerUrl.isEmpty());
    EXPECT_FALSE(homeUrl.isEmpty());
    
    EXPECT_TRUE(trashUrl.toString().contains("/dde-trash.desktop"));
    EXPECT_TRUE(computerUrl.toString().contains("/dde-computer.desktop"));
    EXPECT_TRUE(homeUrl.toString().contains("/dde-home.desktop"));
}

// Test symlinkTarget function - this requires creating an actual symlink
TEST_F(TestFileUtils, TestSymlinkTarget) {
    // Create a temporary file
    QTemporaryFile tempFile;
    tempFile.open();
    QString tempFilePath = tempFile.fileName();
    tempFile.close();
    
    // Create a temporary symlink
    QString linkPath = tempFilePath + ".link";
    bool linkCreated = QFile::link(tempFilePath, linkPath);
    
    if (linkCreated) {
        QUrl linkUrl = QUrl::fromLocalFile(linkPath);
        QString target = FileUtils::symlinkTarget(linkUrl);
        
        EXPECT_EQ(target, tempFilePath);
        
        // Clean up
        QFile::remove(linkPath);
    } else {
        // On systems where symlinks are not supported, just test with empty result
        QUrl fakeUrl = QUrl::fromLocalFile("/nonexistent");
        QString target = FileUtils::symlinkTarget(fakeUrl);
        EXPECT_TRUE(target.isEmpty());
    }
}

// Test isSameFile function with paths
TEST_F(TestFileUtils, TestIsSameFileWithPaths) {
    // Create a temporary file
    QTemporaryFile tempFile;
    tempFile.open();
    QString tempFilePath = tempFile.fileName();
    tempFile.close();
    
    // Same file should be identified as the same
    EXPECT_TRUE(FileUtils::isSameFile(tempFilePath, tempFilePath));
    
    // Create another temporary file
    QTemporaryFile tempFile2;
    tempFile2.open();
    QString tempFilePath2 = tempFile2.fileName();
    tempFile2.close();
    
    // Different files should not be the same
    EXPECT_FALSE(FileUtils::isSameFile(tempFilePath, tempFilePath2));
    
    // Non-existent files should return false
    EXPECT_FALSE(FileUtils::isSameFile("/nonexistent1", "/nonexistent2"));
}

// Test findIconFromXdg function
TEST_F(TestFileUtils, TestFindIconFromXdg) {
    // This function calls QProcess to run qtxdg-iconfinder
    // We'll stub QProcess to avoid external dependencies
    stub_ext::StubExt stub;
    
    // For now, just test with a mock that returns empty string
    // since qtxdg-iconfinder may not be installed
    QString result = FileUtils::findIconFromXdg("nonexistent-icon");
    
    // The function returns empty string if qtxdg-iconfinder is not found
    // This is acceptable behavior
    EXPECT_TRUE(result.isEmpty());
}

// Test toUnicode function
TEST_F(TestFileUtils, TestToUnicode) {
    QByteArray data = "test data";
    QString fileName = "test.txt";
    
    QString result = FileUtils::toUnicode(data, fileName);
    
    // Should return local 8-bit string if no codec is detected
    EXPECT_EQ(result, QString::fromLocal8Bit(data));
}

// Test isCdRomDevice function
TEST_F(TestFileUtils, TestIsCdRomDevice) {
    QUrl cdromUrl("file:///dev/sr0");
    QUrl nonCdromUrl("file:///dev/sda1");
    
    // We need to stub DFMIO::DFMUtils::devicePathFromUrl
    stub_ext::StubExt stub;
    
    // For this test, we'll verify the function logic with stubs
    // Since the actual function depends on DFMIO, we'll test with stubs
    EXPECT_FALSE(FileUtils::isCdRomDevice(nonCdromUrl));
}

// Test isSameDevice function
TEST_F(TestFileUtils, TestIsSameDevice) {
    QUrl url1("file:///path/to/file1");
    QUrl url2("file:///path/to/file2");
    QUrl differentSchemeUrl("http://example.com/file");
    
    // URLs with different schemes should not be on the same device
    EXPECT_FALSE(FileUtils::isSameDevice(url1, differentSchemeUrl));
    
    // For local files, we'd need to stub DFMIO::DFMUtils::devicePathFromUrl
    // For now, test with the same URL
    EXPECT_TRUE(FileUtils::isSameDevice(url1, url1));
}

// Test isSameFile function with URLs
TEST_F(TestFileUtils, TestIsSameFileWithUrls) {
    QUrl url1("file:///tmp/test1.txt");
    QUrl url2("file:///tmp/test1.txt");
    QUrl url3("file:///tmp/test2.txt");
    
    // Same URL should be the same file
    EXPECT_TRUE(FileUtils::isSameFile(url1, url2));
    
    // Different URLs might not be the same file
    // This depends on actual file system, so we'll test with stubs
    stub_ext::StubExt stub;
    
    // For now, just ensure no crash
    EXPECT_FALSE(FileUtils::isSameFile(url1, url3));
}

// Test isHigherHierarchy function
TEST_F(TestFileUtils, TestIsHigherHierarchy) {
    QUrl baseUrl("file:///home/user");
    QUrl compareUrl("file:///home/user/subdir/file.txt");
    
    // baseUrl should be higher in hierarchy than compareUrl
    // This requires stubbing DFMIO::DFMUtils::directParentUrl
    stub_ext::StubExt stub;
    
    // For now, just ensure no crash
    bool result = FileUtils::isHigherHierarchy(baseUrl, compareUrl);
    (void)result;  // Suppress unused variable warning
}

// Test fileBatchReplaceText function
TEST_F(TestFileUtils, TestFileBatchReplaceText) {
    QList<QUrl> urls;
    QPair<QString, QString> pair("old", "new");
    
    // Test with empty list
    QMap<QUrl, QUrl> result = FileUtils::fileBatchReplaceText(urls, pair);
    EXPECT_TRUE(result.isEmpty());
    
    // Add a URL to test
    urls << QUrl("file:///path/to/old_file.txt");
    
    // This function requires stubbing InfoFactory::create<FileInfo>
    stub_ext::StubExt stub;
    
    // For now, just ensure no crash
    result = FileUtils::fileBatchReplaceText(urls, pair);
    EXPECT_TRUE(result.isEmpty());  // Will be empty since we can't create FileInfo
}

// Test fileBatchAddText function
TEST_F(TestFileUtils, TestFileBatchAddText) {
    QList<QUrl> urls;
    QPair<QString, AbstractJobHandler::FileNameAddFlag> pair("prefix_", AbstractJobHandler::FileNameAddFlag::kPrefix);
    
    // Test with empty list
    QMap<QUrl, QUrl> result = FileUtils::fileBatchAddText(urls, pair);
    EXPECT_TRUE(result.isEmpty());
    
    // Add a URL to test
    urls << QUrl("file:///path/to/file.txt");
    
    // This function requires stubbing InfoFactory::create<FileInfo>
    stub_ext::StubExt stub;
    
    // For now, just ensure no crash
    result = FileUtils::fileBatchAddText(urls, pair);
    EXPECT_TRUE(result.isEmpty());  // Will be empty since we can't create FileInfo
}

// Test fileBatchCustomText function
TEST_F(TestFileUtils, TestFileBatchCustomText) {
    QList<QUrl> urls;
    QPair<QString, QString> pair("test", "1");
    
    // Test with empty list
    QMap<QUrl, QUrl> result = FileUtils::fileBatchCustomText(urls, pair);
    EXPECT_TRUE(result.isEmpty());
    
    // Add a URL to test
    urls << QUrl("file:///path/to/file.txt");
    
    // This function requires stubbing InfoFactory::create<FileInfo>
    stub_ext::StubExt stub;
    
    // For now, just ensure no crash
    result = FileUtils::fileBatchCustomText(urls, pair);
    EXPECT_TRUE(result.isEmpty());  // Will be empty since we can't create FileInfo
}

// Test resolveSymlink function
TEST_F(TestFileUtils, TestResolveSymlink) {
    // Create a temporary file
    QTemporaryFile tempFile;
    tempFile.open();
    QString tempFilePath = tempFile.fileName();
    tempFile.close();
    
    // Create a temporary symlink
    QString linkPath = tempFilePath + ".link";
    bool linkCreated = QFile::link(tempFilePath, linkPath);
    
    if (linkCreated) {
        QUrl linkUrl = QUrl::fromLocalFile(linkPath);
        QString resolved = FileUtils::resolveSymlink(linkUrl);
        
        // The resolved path should match the target file path
        EXPECT_EQ(resolved, tempFilePath);
        
        // Clean up
        QFile::remove(linkPath);
    } else {
        // On systems where symlinks are not supported, just test with empty result
        QUrl fakeUrl = QUrl::fromLocalFile("/nonexistent");
        QString resolved = FileUtils::resolveSymlink(fakeUrl);
        EXPECT_TRUE(resolved.isEmpty());
    }
}

// Test isContainProhibitPath function
TEST_F(TestFileUtils, TestIsContainProhibitPath) {
    // This function requires stubbing SystemPathUtil and SysInfoUtils
    stub_ext::StubExt stub;
    
    QList<QUrl> urls;
    urls << QUrl("file:///home/user/Desktop/test.txt");
    
    // For now, just ensure no crash
    bool result = FileUtils::isContainProhibitPath(urls);
    (void)result;  // Suppress unused variable warning
}

// Test isDesktopFile function
TEST_F(TestFileUtils, TestIsDesktopFile) {
    // This function requires stubbing InfoFactory::create<FileInfo>
    stub_ext::StubExt stub;
    
    QUrl desktopUrl("file:///path/to/file.desktop");
    
    // For now, just ensure no crash
    bool result = FileUtils::isDesktopFile(desktopUrl);
    (void)result;  // Suppress unused variable warning
}

// Test isDesktopFileInfo function
TEST_F(TestFileUtils, TestIsDesktopFileInfo) {
    // This function requires a FileInfoPointer
    stub_ext::StubExt stub;
    
    // For now, just test with a nullptr to ensure it doesn't crash
    // Note: This will cause Q_ASSERT to fail, so we'll skip this test for now
    // FileInfoPointer info = nullptr;
    // bool result = FileUtils::isDesktopFileInfo(info);
}

// Test isTrashDesktopFile function
TEST_F(TestFileUtils, TestIsTrashDesktopFile) {
    // Create a temporary .desktop file
    QTemporaryFile desktopFile;
    desktopFile.setFileTemplate("/tmp/test_XXXXXX.desktop");
    desktopFile.open();
    QString desktopFilePath = desktopFile.fileName();
    desktopFile.close();
    
    QUrl desktopUrl = QUrl::fromLocalFile(desktopFilePath);
    
    // For now, just ensure no crash
    // Note: This requires creating a DesktopFile object with proper content
    bool result = FileUtils::isTrashDesktopFile(desktopUrl);
    (void)result;  // Suppress unused variable warning
}

// Test isComputerDesktopFile function
TEST_F(TestFileUtils, TestIsComputerDesktopFile) {
    QTemporaryFile desktopFile;
    desktopFile.setFileTemplate("/tmp/test_XXXXXX.desktop");
    desktopFile.open();
    QString desktopFilePath = desktopFile.fileName();
    desktopFile.close();
    
    QUrl desktopUrl = QUrl::fromLocalFile(desktopFilePath);
    
    bool result = FileUtils::isComputerDesktopFile(desktopUrl);
    (void)result;  // Suppress unused variable warning
}

// Test isHomeDesktopFile function
TEST_F(TestFileUtils, TestIsHomeDesktopFile) {
    QTemporaryFile desktopFile;
    desktopFile.setFileTemplate("/tmp/test_XXXXXX.desktop");
    desktopFile.open();
    QString desktopFilePath = desktopFile.fileName();
    desktopFile.close();
    
    QUrl desktopUrl = QUrl::fromLocalFile(desktopFilePath);
    
    bool result = FileUtils::isHomeDesktopFile(desktopUrl);
    (void)result;  // Suppress unused variable warning
}

// Test refreshIconCache function
TEST_F(TestFileUtils, TestRefreshIconCache) {
    // This function just calls QIcon::setThemeSearchPaths
    FileUtils::refreshIconCache();
    
    // Just ensure no crash
    SUCCEED();
}

// Test trashIsEmpty function
TEST_F(TestFileUtils, TestTrashIsEmpty) {
    // This function requires stubbing NetworkUtils and InfoFactory
    stub_ext::StubExt stub;
    
    bool result = FileUtils::trashIsEmpty();
    (void)result;  // Suppress unused variable warning
}

// Test dirFfileCount function
TEST_F(TestFileUtils, TestDirFileCount) {
    QUrl dirUrl = QUrl::fromLocalFile(QDir::tempPath());
    
    int count = FileUtils::dirFfileCount(dirUrl);
    
    // Directory should have some files, but could be 0
    EXPECT_GE(count, 0);
}

// Test fileCanTrash function
TEST_F(TestFileUtils, TestFileCanTrash) {
    // This function requires stubbing multiple dependencies
    stub_ext::StubExt stub;
    
    QUrl fileUrl("file:///tmp/test.txt");
    bool result = FileUtils::fileCanTrash(fileUrl);
    (void)result;  // Suppress unused variable warning
}

// Test bindUrlTransform function
TEST_F(TestFileUtils, TestBindUrlTransform) {
    QUrl normalUrl("file:///path/to/file");
    QUrl result = FileUtils::bindUrlTransform(normalUrl);
    
    // For a normal URL, result should be the same
    EXPECT_EQ(result, normalUrl);
}

// Test trashPathToNormal and normalPathToTrash functions
TEST_F(TestFileUtils, TestPathTransformFunctions) {
    QString trashPath = "\\home\\user\\file.txt";
    QString normalPath = FileUtils::trashPathToNormal(trashPath);
    
    EXPECT_EQ(normalPath, "/home/user/file.txt");
    
    QString backToTrash = FileUtils::normalPathToTrash(normalPath);
    EXPECT_EQ(backToTrash, "/home/user/file.txt");  // Note: adds leading slash
}

// Test supportLongName function
TEST_F(TestFileUtils, TestSupportLongName) {
    QUrl url("file:///path/to/file");
    
    // This function requires stubbing dfmio::DFMUtils::fsTypeFromUrl
    stub_ext::StubExt stub;
    
    bool result = FileUtils::supportLongName(url);
    (void)result;  // Suppress unused variable warning
}

// Test setBackGround function
TEST_F(TestFileUtils, TestSetBackGround) {
    // This function makes D-Bus calls
    QString imagePath = "/tmp/test_image.jpg";
    
    bool result = FileUtils::setBackGround(imagePath);
    
    // Function should return true in most cases (even if D-Bus call fails)
    EXPECT_TRUE(result);
}

// Test bindPathTransform function
TEST_F(TestFileUtils, TestBindPathTransform) {
    QString path = "/dev/mapper/test";
    bool toDevice = false;
    
    // This function calls DeviceUtils::bindPathTransform
    stub_ext::StubExt stub;
    
    QString result = FileUtils::bindPathTransform(path, toDevice);
    (void)result;  // Suppress unused variable warning
}

