#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-

%new-style
%enable-all-warnings
%require-types
%strict-args

%requires ../../../../qlib/QUnit.qm

%exec-class GetCallThreadTest

class GetCallThreadTest inherits QUnit::Test {
    constructor() : QUnit::Test("Get Call Thread test", "1.0") {
        addTestCase("Get Call Thread test", \testGetCallThread());
        set_return_value(main());
    }

    auto f2(bool all) {
        return all ? get_all_thread_call_stacks() : get_thread_call_stack();
    }

    auto f1(bool all) {
        return f2(all);
    }

    testGetCallThread() {
        hash<auto> h = f1(True);
        testAssertionValue("get_all_thread_call_stacks-0", h{gettid()}[0].function, "get_all_thread_call_stacks");
        testAssertionValue("get_all_thread_call_stacks-1", h{gettid()}[1].function, "GetCallThreadTest::f2");
        testAssertionValue("get_all_thread_call_stacks-2", h{gettid()}[2].function, "GetCallThreadTest::f1");

        list l = f1(False);
        testAssertionValue("get_thread_call_stack-0", l[0].function, "get_thread_call_stack");
        testAssertionValue("get_thread_call_stack-1", l[1].function, "GetCallThreadTest::f2");
        testAssertionValue("get_thread_call_stack-2", l[2].function, "GetCallThreadTest::f1");

        remove h{gettid()}[0].function;
        remove l[0].function;
        remove h{gettid()}[2].line;
        remove l[2].line;
        remove h{gettid()}[2].endline;
        remove l[2].endline;
        remove h{gettid()}[2].statementid;
        remove l[2].statementid;
        testAssertionValue("stack comparison", h{gettid()}, l);
    }

}
