Files
2026-04-30 14:17:48 +02:00

51 lines
1.8 KiB
C++

#include "../CoffLoader.hpp"
#include "../../tests/TestHelpers.hpp"
#include <filesystem>
#include <iostream>
#include <vector>
using namespace test_helpers;
int main()
{
bool ok = true;
{
CoffLoader module;
std::vector<std::string> cmd = {"coffLoader", "missing.o", "go"};
C2Message message;
ok &= expect(module.init(cmd, message) == -1, "missing COFF file should be rejected");
ok &= expect(message.returnvalue().find("Couldn't open file") != std::string::npos, "missing COFF error should mention open failure");
}
{
const auto coff = writeTempFile("c2core_dummy.o", "coff-bytes");
CoffLoader module;
std::vector<std::string> cmd = {"coffLoader", coff.string(), "go", "Zs", "c:\\", "0"};
C2Message message;
ok &= expect(module.init(cmd, message) == 0, "existing COFF file should be accepted");
ok &= expect(message.instruction() == "coffLoader", "instruction should be set");
ok &= expect(message.inputfile() == coff.string(), "input file should be packed");
ok &= expect(message.cmd() == "go", "function name should be packed");
ok &= expect(message.args() == "Zs c:\\ 0", "COFF arguments should be packed");
ok &= expect(message.data() == "coff-bytes", "COFF bytes should be packed");
std::filesystem::remove(coff);
}
{
CoffLoader module;
C2Message ret;
ret.set_errorCode(1);
ret.set_returnvalue("Failed to run/parse the COFF file\n");
std::string errorMsg;
ok &= expect(module.errorCodeToMsg(ret, errorMsg) == 0, "COFF execution failure should map error text");
ok &= expect(errorMsg == ret.returnvalue(), "COFF execution error text should come from returnvalue");
}
return ok ? 0 : 1;
}