/* SPDX-License-Identifier: GPL-3.0-only */
#include "n3n_path.h"

#include <stdio.h>

static int failures;

static void expect_path(const char *name, htp_n3n_peer_path actual, htp_n3n_peer_path expected) {
    if (actual == expected) return;
    fprintf(stderr, "%s: expected %d, got %d\n", name, expected, actual);
    failures += 1;
}

int main(void) {
    expect_path("disconnected", htp_n3n_classify_peer_path(
        HTP_N3N_TRANSPORT_UDP_P2P, 0, 20, 10), HTP_N3N_PEER_PATH_UNKNOWN);
    expect_path("udp relay", htp_n3n_classify_peer_path(
        HTP_N3N_TRANSPORT_UDP_RELAY, 1, 0, 0), HTP_N3N_PEER_PATH_RELAY);
    expect_path("tcp relay", htp_n3n_classify_peer_path(
        HTP_N3N_TRANSPORT_TCP_RELAY, 1, 0, 0), HTP_N3N_PEER_PATH_RELAY);
    expect_path("no traffic", htp_n3n_classify_peer_path(
        HTP_N3N_TRANSPORT_UDP_P2P, 1, 0, 0), HTP_N3N_PEER_PATH_UNKNOWN);
    expect_path("latest p2p", htp_n3n_classify_peer_path(
        HTP_N3N_TRANSPORT_UDP_P2P, 1, 20, 10), HTP_N3N_PEER_PATH_P2P);
    expect_path("latest relay", htp_n3n_classify_peer_path(
        HTP_N3N_TRANSPORT_UDP_P2P, 1, 10, 20), HTP_N3N_PEER_PATH_RELAY);
    expect_path("same second", htp_n3n_classify_peer_path(
        HTP_N3N_TRANSPORT_UDP_P2P, 1, 20, 20), HTP_N3N_PEER_PATH_UNKNOWN);
    return failures == 0 ? 0 : 1;
}
