//========================================================================
//
// testgoo.cc
//
// Test suite for goo functions.
//
// Copyright 2026 Adam Sampson <ats@offog.org>
//
//========================================================================

#include <assert.h>
#include <stdio.h>

#include "gfile-xpdf.h"

int main(int argc, char *argv[]) {
    // Not tested: xpdfGetHomeDir

    fprintf(stderr, "Testing xpdfAppendToPath\n");
    assert(xpdfAppendToPath("/x/y", "z") == "/x/y/z");
    assert(xpdfAppendToPath("x/y", "z") == "x/y/z");
    assert(xpdfAppendToPath("x", "y/z") == "x/y/z");
    assert(xpdfAppendToPath("/x/y/z", ".") == "/x/y/z");
    assert(xpdfAppendToPath("/x/y/z", "..") == "/x/y");
    assert(xpdfAppendToPath("x/y/z", ".") == "x/y/z");
    assert(xpdfAppendToPath("x/y/z", "..") == "x/y");
    assert(xpdfAppendToPath("x", "y") == "x/y");
    assert(xpdfAppendToPath("x", "") == "x/");
    assert(xpdfAppendToPath("/x", "..") == "/");
    assert(xpdfAppendToPath("x", "..") == ".."); // XXX as in xpdf
    assert(xpdfAppendToPath("/", "z") == "/z");
    assert(xpdfAppendToPath("/", "..") == "/");
    assert(xpdfAppendToPath("", "z") == "z");
    assert(xpdfAppendToPath("", ".") == "");
    assert(xpdfAppendToPath("", "..") == "..");
    assert(xpdfAppendToPath("", "") == "");

    fprintf(stderr, "Testing xpdfDirName\n");
    assert(xpdfDirName("/x/y/z") == "/x/y");
    assert(xpdfDirName("/x/y") == "/x");
    assert(xpdfDirName("/x") == ""); // XXX as in xpdf
    assert(xpdfDirName("x/y/z") == "x/y");
    assert(xpdfDirName("x/y") == "x");
    assert(xpdfDirName("x") == "");
    assert(xpdfDirName("") == "");

    fprintf(stderr, "Testing xpdfIsAbsolutePath\n");
    assert(xpdfIsAbsolutePath("/"));
    assert(xpdfIsAbsolutePath("/x"));
    assert(xpdfIsAbsolutePath("/x/y"));
    assert(!xpdfIsAbsolutePath("x"));
    assert(!xpdfIsAbsolutePath("x/y"));
    assert(!xpdfIsAbsolutePath(".."));
    assert(!xpdfIsAbsolutePath("."));
    assert(!xpdfIsAbsolutePath(""));

    fprintf(stderr, "Testing endsWithDotPDF\n");
    assert(endsWithDotPDF("/x/y.pdf"));
    assert(endsWithDotPDF("/x/y.PDF"));
    assert(endsWithDotPDF("/x/y.pDf"));
    assert(endsWithDotPDF(".pdf"));
    assert(!endsWithDotPDF("/x/y.png"));
    assert(!endsWithDotPDF("/x/y"));
    assert(!endsWithDotPDF("/"));
    assert(!endsWithDotPDF("x"));
    assert(!endsWithDotPDF(""));

    // Not tested: xpdfGetModTime

    // Not tested: xpdfMakePathAbsolute

    return 0;
}
