OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace / tests / atoms / scope / DontExecUTest.cxxtest

122 lines · cxxtest ref:
/*
 * tests/query/DontExecUTest.cxxtest
 *
 * Copyright (C) 2017 OpenCog Foundation
 * All Rights Reserved
 * Author: Nil Geisweiller
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License v3 as
 * published by the Free Software Foundation and including the exceptions
 * at http://opencog.org/wiki/Licenses
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, write to:
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <opencog/guile/SchemeEval.h>
#include <opencog/atomspace/AtomSpace.h>
#include <opencog/util/Logger.h>
#include <cxxtest/TestSuite.h>

using namespace opencog;

#define al as->add_link
#define an as->add_node

class DontExecUTest: public CxxTest::TestSuite
{
private:
	AtomSpacePtr as;
	SchemeEval* eval;

public:
	DontExecUTest() : as(createAtomSpace()), eval(SchemeEval::get_scheme_evaluator(as))
	{
		logger().set_level(Logger::DEBUG);
		logger().set_sync_flag(true);
		logger().set_print_to_stdout_flag(true);

		eval->eval("(add-to-load-path \"" PROJECT_SOURCE_DIR "\")");
	}

	~DontExecUTest()
	{
		// Erase the log file if no assertions failed.
		if (!CxxTest::TestTracker::tracker().suiteFailed())
				std::remove(logger().get_filename().c_str());
	}

	void setUp();
	void tearDown();

	void xtest_DontExecLink_simple();
	void test_DontExecLink_multi();
};

void DontExecUTest::tearDown()
{
}

void DontExecUTest::setUp()
{
}

/**
 * Test that DontExecLink are properly consumed when executed.
 * XXX FIXME ... the PutLink is still implemented as spaghetti code
 * and is not stable against perturbations. So just disable this
 * test for now.
 */
void DontExecUTest::xtest_DontExecLink_simple()
{
	logger().debug("BEGIN TEST: %s", __FUNCTION__);
	eval->eval("(load-from-path \"tests/atoms/scope/dont-exec-simple.scm\")");

	Handle band = eval->eval_h("bad-and");
	Handle dand = eval->eval_h("dont-and");
	Handle want_band = eval->eval_h("(cog-execute! dont-and)");

	logger().debug() << "simple result = " << oc_to_string(want_band);
	logger().debug() << "simple expected = " << oc_to_string(band);
	TS_ASSERT_EQUALS(want_band, band);

	Handle put_band = eval->eval_h("(cog-execute! put-and)");

	logger().debug() << "put result = " << oc_to_string(put_band);
	logger().debug() << "put expected = " << oc_to_string(band);

	TS_ASSERT_EQUALS(put_band, band);
	logger().debug("END TEST: %s", __FUNCTION__);
}

/**
 * Test that DontExecLink are properly consumed, even when
 * wrapped in a set.
 */
void DontExecUTest::test_DontExecLink_multi()
{
	logger().debug("BEGIN TEST: %s", __FUNCTION__);
	eval->eval("(load-from-path \"tests/atoms/scope/dont-exec-simple.scm\")");

	Handle got = eval->eval_h("(cog-execute! put-eval)");
	Handle want = eval->eval_h("eval-expected");

	TS_ASSERT_EQUALS(got, want);

	logger().debug() << "put-multi result = " << oc_to_string(got);
	logger().debug() << "put-multi expected = " << oc_to_string(want);

	logger().debug("END TEST: %s", __FUNCTION__);
}

#undef al
#undef an