
#include "KMPermissionConfig.h"
#include <gtest/gtest.h>
#include <fstream>

// 测试用的类，提供一个成员对象
class KMTestPermissionConfig
{
public:
    KMTestPermissionConfig()
        : m_permissionConfig("testapp"){};
    ~KMTestPermissionConfig() = default;

    KMPermissionConfig m_permissionConfig;
};

// 加载文件成功
TEST(KMTestPermissionConfig, test_loadFile_success)
{
    std::string configFile = std::string(std::getenv("HOME")) + "/.config/kaiming-permission.json";
    KMPermissionConfig config("testapp");
    EXPECT_TRUE(config.loadFile(configFile));
}

//加载文件路径错误
TEST(KMTestPermissionConfig, test_loadFile_failure)
{
    KMTestPermissionConfig testpermissionconfig;
    const std::string invalidFile = "/path/to/nonexistent/file.json";
    EXPECT_FALSE(testpermissionconfig.m_permissionConfig.loadFile(invalidFile));
}

//加载配置成功
TEST(KMTestPermissionConfig, test_loadConfiguration)
{
    KMTestPermissionConfig testpermissionconfig;
    bool result = testpermissionconfig.m_permissionConfig.loadConfiguration();
    EXPECT_TRUE(result) << "成功加载kaiming-permission.json的字段";

    AppPermissionConfig config = testpermissionconfig.m_permissionConfig.getPermissionConfig();

    EXPECT_EQ(config.bluetooth, 0);
    EXPECT_EQ(config.camera, 1);
    EXPECT_EQ(config.network, 0);
}
