/*
* tests/query/BuggyStackUTest.cxxtest
*
* Copyright (C) 2009 Linas Vepstas <linasvepstas@gmail.com>
* All Rights Reserved
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
#include <opencog/atomspace/AtomSpace.h>
#include <opencog/guile/SchemeEval.h>
#include <opencog/util/Logger.h>
#include "test-types.h"
using namespace opencog;
class BuggyStackUTest : public CxxTest::TestSuite
{
private:
AtomSpacePtr as;
Handle restrict;
public:
BuggyStackUTest(void)
{
logger().set_level(Logger::DEBUG);
logger().set_print_to_stdout_flag(true);
#include "test-types.cc"
}
~BuggyStackUTest()
{
// erase the log file if no assertions failed
if (!CxxTest::TestTracker::tracker().suiteFailed())
std::remove(logger().get_filename().c_str());
}
void setUp(void);
void tearDown(void) { }
void test_exec(void);
};
/*
* This function sets up an implication link, and some data.
*/
#define an as->add_node
#define al as->add_link
#define getarity(hand) hand->get_arity()
#define getlink(hand,pos) hand->getOutgoingAtom(pos)
void BuggyStackUTest::setUp(void)
{
as = createAtomSpace();
SchemeEval* eval = SchemeEval::get_scheme_evaluator(as);
eval->eval("(add-to-load-path \"" PROJECT_SOURCE_DIR "\")");
eval->eval("(load-from-path \"tests/query/test_types.scm\")");
eval->eval("(load-from-path \"tests/query/buggy-stack.scm\")");
// Create an implication link that will be tested.
restrict = eval->apply("impy", Handle::UNDEFINED);
}
/*
* Basic implication link test.
*/
void BuggyStackUTest::test_exec(void)
{
logger().debug("BEGIN TEST: %s", __FUNCTION__);
// Make sure the scheme file actually loaded!
TSM_ASSERT("Failed to load test data", Handle::UNDEFINED != restrict);
// Result should be a ListLink w/ one solution
Handle result = HandleCast(restrict->execute(as.get()));
logger().debug("result is %s\n", result->to_string().c_str());
TSM_ASSERT_EQUALS("wrong number of solutions found", 1, getarity(result));
logger().debug("END TEST: %s", __FUNCTION__);
}