#include "UImgOperateTest.h"
//#include "uimg-installer/UImgOperate.h"
#include "utils/Device.h"

TEST_F(UImgOperateTest, installImgFile)
{
    // ghost 文件要放在非安装的磁盘里，即不在destDevices列表中
    // 手动将ghost 文件 mount 到 /mnt目录下
    bool retCode = false;
    QString ghostDir = "/media/zxm/837131d7-3826-4c1a-880d-c68cb0f0d6df/soft/";
    QString ghostName = "ghost_23_Community_2000_100_amd64_20221016-162515_legacy_twodiskfull.uimg";
    QString imgFile = ghostDir + ghostName;
    QStringList destDevices;
    destDevices<<"/dev/sda";
    destDevices<<"/dev/sdb";
//    UImgOperate uop;
//    uop.installImgFile(imgFile, destDevices);
    EXPECT_TRUE(retCode);
}

TEST_F(UImgOperateTest, renameVgName)
{
    bool retCode = false;
    // 对应ghost里的partition
    QString partitionFile = "/home/zxm/Desktop/test_partition.json";
    QStringList sysVgNameList;
    retCode = Device::getVGNames(sysVgNameList);
    EXPECT_TRUE(retCode);

//    UImgOperate uop;
//    uop.renameVgName(partitionFile, sysVgNameList);
    EXPECT_TRUE(retCode);
}

TEST_F(UImgOperateTest, updateCrypttab)
{
    bool retCode = false;
   // retCode = UImgOperate::updateCrypttab();
    EXPECT_TRUE(retCode);
}

TEST_F(UImgOperateTest, updateUdisksRules)
{
    bool retCode = false;
    QString fstabPath = "/etc/fstab";
    QString udiskRulePath = "/home/zxm/Desktop/80-udisks-installer.rules";
    QString rootPath = "/";
//    DiskInfo diskInfo;
//    Device::getAllTypeDevice(diskInfo.diskList, diskInfo.cryptDevList, diskInfo.noCryptDevList,
//                             diskInfo.partitionList, diskInfo.lvmList);
    //retCode = UImgOperate::updateUdisksRules(rootPath, fstabPath, udiskRulePath, diskInfo);
    EXPECT_TRUE(retCode);
}

TEST_F(UImgOperateTest, updateSystemRecoveryUUID)
{
    bool retCode = false;
    QString recoveryUUID = "189c345e-e693-4f83-a799-715a93944598";
    QString rootPath = "/";
   //retCode = UImgOperate::updateSystemRecoveryUUID(rootPath, recoveryUUID);
    EXPECT_TRUE(retCode);
}

TEST_F(UImgOperateTest, checkImgFile)
{
    // ghost 文件要放在非安装的磁盘里，即不在destDevices列表中
    // 手动将ghost 文件 mount 到 /mnt目录下
    bool retCode = false;
    QString ghostDir = "/media/zxm/Rootb/ghost/";
    QString ghostName = "ghost_20_Professional_1050_110_amd64_efi_20230130-170934.uimg";
    QString imgFile = ghostDir + ghostName;
    QStringList destDevices;
    destDevices<<"/dev/sda";
    destDevices<<"/dev/sdb";
//    UImgOperate uop;
//    uop.checkImgFile(imgFile, destDevices);
    EXPECT_TRUE(retCode);
}

TEST_F(UImgOperateTest, checkUImg)
{
    // ghost 文件要放在非安装的磁盘里，即不在destDevices列表中
    // 手动将ghost 文件 mount 到 /mnt目录下
    bool retCode = false;
    QString ghostDir = "/home/zxm/Desktop/";
    QString ghostName = "ghost_20_Professional_1050_110_amd64_efi_20230131-153201.uimg";
    QString imgFile = ghostDir + ghostName;
    QStringList destDevices;
    destDevices<<"/dev/sda";
    destDevices<<"/dev/sdb";
//    UImgOperate uop;
//    uop.checkUImg(imgFile, destDevices);
    EXPECT_TRUE(retCode);
}

TEST_F(UImgOperateTest, updateABRecoveryUUID)
{
    bool retCode = false;
    QString roota = "1111345e-e693-4f83-a799-715a93944598";
    QString rootb = "2222345e-e693-4f83-a799-715a93944598";
    QString rootPath = "/";
    //retCode = UImgOperate::updateABRecoveryUUID(rootPath, roota, rootb);
    EXPECT_TRUE(retCode);
}
