/*
* tests/proxy/MCPUTest.cxxtest
*
* Copyright (C) 2016, 2022 Linas Vepstas
* All Rights Reserved
*
* 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, see http://www.gnu.org/licenses/
*/
#include <thread>
#include <opencog/atomspace/AtomSpace.h>
#include <opencog/atoms/atom_types/atom_names.h>
#include <opencog/atoms/value/FloatValue.h>
#include <opencog/atoms/value/VoidValue.h>
#include <opencog/cogserver/atoms/CogServerNode.h>
using namespace opencog;
class MCPUTest : public CxxTest::TestSuite
{
private:
AtomSpacePtr asp;
CogServerNodePtr csrv;
public:
MCPUTest()
{
// logger().set_level(Logger::DEBUG);
logger().set_level(Logger::INFO);
logger().set_print_to_stdout_flag(true);
asp = createAtomSpace();
Handle hcsn = asp->add_node(COG_SERVER_NODE, "test-cogserver");
csrv = CogServerNodeCast(hcsn);
// Set ports and start the server (MCP only)
csrv->setValue(asp->add_atom(Predicate("*-telnet-port-*")),
createFloatValue(0.0));
csrv->setValue(asp->add_atom(Predicate("*-web-port-*")),
createFloatValue(0.0));
csrv->setValue(asp->add_atom(Predicate("*-mcp-port-*")),
createFloatValue(17445.0));
csrv->setValue(asp->add_atom(Predicate("*-start-*")),
createVoidValue());
}
~MCPUTest()
{
csrv->setValue(asp->add_atom(Predicate("*-stop-*")),
createVoidValue());
csrv = nullptr;
asp = nullptr;
// erase the log file if no assertions failed
if (!CxxTest::TestTracker::tracker().suiteFailed())
std::remove(logger().get_filename().c_str());
}
void setUp()
{
}
void tearDown()
{
}
// Try to run the example program. See if it works.
void test_mcp_checker()
{
int rc;
logger().debug("BEGIN TEST: %s", __FUNCTION__);
rc = system(PROJECT_BINARY_DIR "/examples/mcp/mcp-checker --port 17445");
if (rc != 0) printf("Error: cannot run mcp checker\n");
TS_ASSERT_EQUALS(rc, 0);
logger().debug("END TEST: %s", __FUNCTION__);
}
};