#include <gtest/gtest.h>

#include "packet_inject_test.h"

TEST(INJECT_IPV4_BASED_TCP_RST, AFTER_RECV_C2S_FIRST_PAYLOAD)
{
    char current_dir[1024] = {0};
    char work_dir[2048] = {0};
    char input_dir[2048] = {0};
    getcwd(current_dir, sizeof(current_dir));
    snprintf(work_dir, sizeof(work_dir), "%s/%s", current_dir, "inject_ipv4_based_tcp_rst_after_recv_c2s_first_payload");
    snprintf(input_dir, sizeof(input_dir), "%s/%s", current_dir, "pcap/inject_ipv4_based_tcp_rst_after_recv_c2s_first_payload/test/");

    struct packet_inject_case test = {
        // descriptor
        .finish_clean_work_dir = 0,
        .descriptor = "Inject IPv4 based TCP RST after receiving C2S first payload packet.",
        .work_dir = work_dir,

        // prefix
        .input_prefix = input_dir,

        // input pcap
        .input_pcap = "input.pcap",

        // compare
        .compares = {
            {
                .expect_pcap = "expect-192.0.2.211:35116-192.0.2.110:80-1.pcap",
                .inject_pcap = "inject-192.0.2.211:35116-192.0.2.110:80-1.pcap",
            },
            {
                .expect_pcap = "expect-192.0.2.110:80-192.0.2.211:35116-2.pcap",
                .inject_pcap = "inject-192.0.2.110:80-192.0.2.211:35116-2.pcap",
            },
            {
                .expect_pcap = NULL,
                .inject_pcap = NULL,
            },
        },

        // packet injector command
        .packet_injector_cmd = {"./packet_injector", "-t", "tcp-rst", "-c", "c2s-packet", "-n", "3"},
        .diff_skip_pattern = "-I frame.time -I frame.time_epoch -I ip.id -I ip.ttl -I ip.checksum -I tcp.checksum -I tcp.window_size",
    };

    packet_inject_test(&test);
}

int main(int argc, char **argv)
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}
