#include "powercap.hpp"
#include "utils.hpp"

#include <occ_events.hpp>
#include <occ_manager.hpp>

#include <filesystem>

#include <gtest/gtest.h>

using namespace open_power::occ;
using namespace open_power::occ::utils;

class VerifyOccInput : public ::testing::Test
{
  public:
    VerifyOccInput() :
        rc(sd_event_default(&event)), eventP(event), manager(eventP),
        occStatus(eventP, "/test/path/occ1", manager
#ifdef POWER10
                  ,
                  powerMode
#endif
                  ),
        pcap(occStatus)
    {
        EXPECT_GE(rc, 0);
        event = nullptr;
    }
    ~VerifyOccInput() {}

    sd_event* event;
    int rc;
    open_power::occ::EventPtr eventP;

    Manager manager;
    Status occStatus;
#ifdef POWER10
    std::unique_ptr<powermode::PowerMode> powerMode = nullptr;
#endif
    powercap::PowerCap pcap;
};

TEST(VerifyPathParsing, EmptyPath)
{
    std::filesystem::path path = "";
    std::string parsed = Device::getPathBack(path);

    EXPECT_STREQ(parsed.c_str(), "");
}

TEST(VerifyPathParsing, FilenamePath)
{
    std::filesystem::path path = "/test/foo.bar";
    std::string parsed = Device::getPathBack(path);

    EXPECT_STREQ(parsed.c_str(), "foo.bar");
}

TEST(VerifyPathParsing, DirectoryPath)
{
    std::filesystem::path path = "/test/bar/";
    std::string parsed = Device::getPathBack(path);

    EXPECT_STREQ(parsed.c_str(), "bar");
}