#!/bin/sh
set -eu

tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT

cat > "$tmpdir/smoke.c" <<'EOF'
#include <stdlib.h>
#include <string.h>

#include <gssw.h>

int main(void) {
    const char *ref = "GATTACA";
    const char *read = "GATTACA";
    int8_t *nt_table = gssw_create_nt_table();
    int8_t *score_matrix = gssw_create_score_matrix(1, 4);
    gssw_node *node = gssw_node_create(NULL, 1, ref, nt_table, score_matrix);
    gssw_graph *graph = gssw_graph_create(1);
    gssw_graph_mapping *mapping;

    if (node == NULL || graph == NULL) {
        return 1;
    }

    gssw_graph_add_node(graph, node);
    gssw_graph_fill(graph, read, nt_table, score_matrix, 6, 1, 0, 0, 15, 2, true);
    mapping = gssw_graph_trace_back(graph, read, strlen(read), nt_table,
                                    score_matrix, 6, 1, 0, 0);
    if (mapping == NULL || mapping->score <= 0) {
        return 2;
    }

    gssw_graph_mapping_destroy(mapping);
    gssw_graph_destroy(graph);
    free(nt_table);
    free(score_matrix);
    return 0;
}
EOF

cc -std=c99 -Wall -Wextra -o "$tmpdir/smoke" "$tmpdir/smoke.c" -lgssw -lm
"$tmpdir/smoke"
ldd "$tmpdir/smoke" | grep -q 'libgssw\.so'
