#include "TestSupport.h"
#include "File.h"
#include <stdio.h>
#include "gtest/gtest.h"

std::shared_ptr<std::vector<uint8_t>> TestSupport::read_file(const char * filename)
{
    File file;
    if (!file.open(filename))
    {
        fprintf(stderr, "Could not open %s\n", filename);
        return nullptr;
    }

    size_t size = file.get_size();
    auto buffer = std::make_shared<std::vector<uint8_t>>(size, 0u);

    if (!file.read(&(*buffer)[0], size))
    {
        fprintf(stderr, "Failed to read file %s\n", filename);
        return nullptr;
    }

    return buffer;
}

void TestSupport::compare_files(const char * f1, const char * f2)
{
    auto fl1 = read_file(f1);
    auto fl2 = read_file(f2);
    ASSERT_EQ(fl1->size(), fl2->size());
    for (size_t i = 0; i < fl1->size(); i++)
    {
        ASSERT_EQ((*fl1)[i], (*fl2)[i]);
    }
}
