// Test program to verify FrHeader checksum is calculated correctly
#include "framecpp/OOInterface/OFrameStream.hh"
#include "framecpp/Universal/FrameH.hh"
#include "framecpp/Common/CheckSum.hh"
#include <iostream>
#include <fstream>

int main()
{
    using namespace FrameCPP;
    using namespace FrameCPP::Universal;

    try
    {
        // Create a simple v8 frame with CRC checksum
        const char* filename = "test_frheader_checksum.gwf";

        // Write a frame
        {
            OFrameStream ofs(filename, 8); // Version 8
            ofs.SetCheckSumFile(Common::CheckSum::CRC); // Enable file checksums

            auto frame = boost::make_shared<FrameH>();
            frame->SetName("Test");
            frame->SetRun(1);
            frame->SetFrameNumber(1);
            frame->SetGTimeS(600000000);
            frame->SetDt(1.0);

            ofs.WriteFrame(frame);
        }

        // Read it back and check the FrEndOfFile
        {
            IFrameStream ifs(filename);

            // Read the frame (this loads everything including FrEndOfFile)
            auto frame = ifs.ReadNextFrame();

            std::cout << "Test complete - check the FrEndOfFile in " << filename << std::endl;
        }

        return 0;
    }
    catch (const std::exception& e)
    {
        std::cerr << "Error: " << e.what() << std::endl;
        return 1;
    }
}
