Exemple #1
0
void SessionImpl::open(const std::string& connect)
{
	if (connect != connectionString())
	{
		if (isConnected())
			throw InvalidAccessException("Session already connected");

		if (!connect.empty())
			setConnectionString(connect);
	}

	poco_assert_dbg (!connectionString().empty());

	try
	{
		ActiveConnector connector(connectionString(), &_pDB);
		ActiveResult<int> result = connector.connect();
		if (!result.tryWait(getLoginTimeout() * 1000))
			throw ConnectionFailedException("Timed out.");

		int rc = result.data();
		if (rc != 0)
		{
			close();
			Utility::throwException(rc);
		}
	} 
	catch (SQLiteException& ex)
	{
		throw ConnectionFailedException(ex.displayText());
	}

	_connected = true;
}
Exemple #2
0
void ActiveMethodTest::testVoidInOut()
{
	ActiveObject activeObj;
	ActiveResult<void> result = activeObj.testVoidInOut();
	activeObj.cont();
	result.wait();
	assert (result.available());
	assert (!result.failed());
}
void ActiveDispatcherTest::testVoid()
{
	ActiveObject activeObj;
	ActiveResult<void> result = activeObj.testVoid(123);
	assert (!result.available());
	activeObj.cont();
	result.wait();
	assert (result.available());
	assert (!result.failed());
}
void ActiveDispatcherTest::testFailure()
{
	ActiveObject activeObj;
	ActiveResult<int> result = activeObj.testMethod(100);
	result.wait();
	assert (result.available());
	assert (result.failed());
	std::string msg = result.error();
	assert (msg == "n == 100");
}
Exemple #5
0
void ActiveMethodTest::testVoidIn()
{
	ActiveObject activeObj;
	ActiveResult<int> result = activeObj.testVoidIn();
	activeObj.cont();
	result.wait();
	assert (result.available());
	assert (!result.failed());
	assert (result.data() == 123);
}
Exemple #6
0
int main(int argc, char** argv)
{
	ActiveMethodExample example;
	
	ActiveMethodExample::AddArgs args = {1, 2};
	ActiveResult<int> result = example.activeAdd(args);
	result.wait();
	std::cout << result.data() << std::endl;
	
	return 0;
}
Exemple #7
0
void FTPClientSessionTest::testDownloadPORT()
{
	DialogServer server;
	server.addResponse("220 localhost FTP ready");
	server.addResponse("331 Password required");
	server.addResponse("230 Welcome");
	server.addResponse("200 Type set to I");
	FTPClientSession session("localhost", server.port());
	session.setPassive(false);
	session.login("user", "password");
	server.clearCommands();
	
	server.addResponse("500 EPRT not understood");
	server.addResponse("200 PORT OK");
	server.addResponse("150 Sending data\r\n226 Transfer complete");

	ActiveDownloader dl(session);
	ActiveResult<std::string> result = dl.download("test.txt");
		
	std::string cmd = server.popCommandWait();
	assert (cmd.substr(0, 4) == "EPRT");
	
	cmd = server.popCommandWait();
	assert (cmd.substr(0, 4) == "PORT");

	std::string dummy;
	int x, lo, hi;
	for (std::string::iterator it = cmd.begin(); it != cmd.end(); ++it)
	{
		if (*it == ',') *it = ' ';
	}
	std::istringstream istr(cmd);
	istr >> dummy >> x >> x >> x >> x >> hi >> lo;
	int port = hi*256 + lo;

	cmd = server.popCommandWait();
	assert (cmd == "RETR test.txt");

	SocketAddress sa("localhost", (Poco::UInt16) port);
	DialogSocket dataSock;
	dataSock.connect(sa);

	std::string data("This is some data");
	dataSock.sendString(data);
	dataSock.close();

	result.wait();
	std::string received = result.data();
	assert (received == data);
	
	server.addResponse("221 Good Bye");
	session.close();
}
Exemple #8
0
void FTPClientSessionTest::testDownloadEPRT()
{
	DialogServer server;
	server.addResponse("220 localhost FTP ready");
	server.addResponse("331 Password required");
	server.addResponse("230 Welcome");
	server.addResponse("200 Type set to I");
	FTPClientSession session("localhost", server.port());
	session.setPassive(false);
	session.login("user", "password");
	server.clearCommands();
	
	server.addResponse("200 EPRT OK");
	server.addResponse("150 Sending data\r\n226 Transfer complete");

	ActiveDownloader dl(session);
	ActiveResult<std::string> result = dl.download("test.txt");
		
	std::string cmd = server.popCommandWait();
	assert (cmd.substr(0, 4) == "EPRT");
	
	std::string dummy;
	char c;
	int d;
	int port;
	std::istringstream istr(cmd);
	istr >> dummy >> c >> d >> c >> d >> c >> d >> c >> d >> c >> d >> c >> port >> c;
	
	cmd = server.popCommandWait();
	assert (cmd == "RETR test.txt");
	
	SocketAddress sa("localhost", (Poco::UInt16) port);
	DialogSocket dataSock;
	dataSock.connect(sa);

	std::string data("This is some data");
	dataSock.sendString(data);
	dataSock.close();

	result.wait();
	std::string received = result.data();
	assert (received == data);
	
	server.addResponse("221 Good Bye");
	session.close();
}
Exemple #9
0
void SessionImpl::open(const std::string& connect)
{
	if (connect != connectionString())
	{
		if (isConnected())
			throw InvalidAccessException("Session already connected");

		if (!connect.empty())
			setConnectionString(connect);
	}

	poco_assert_dbg (!connectionString().empty());

	try
	{
		ActiveConnector connector(connectionString(), &_pDB);
		ActiveResult<int> result = connector.connect();
		if (!result.tryWait(getLoginTimeout() * 1000))
			throw ConnectionFailedException("Timed out.");

		int rc = result.data();
		if (rc != 0)
		{
			close();
			Utility::throwException(rc);
		}
	} catch (SQLiteException& ex)
	{
		throw ConnectionFailedException(ex.displayText());
	}

	if (SQLITE_OK != sqlite3_exec(_pDB,
		"attach database ':memory:' as sys;"
		"create table sys.dual (dummy);", 
		0, 0, 0))
	{
		throw ExecutionException("Cannot create system database.");
	}

	_connected = true;
}
void ActiveDispatcherTest::testTryWait()
{
	ActiveObject activeObj;
	ActiveResult<int> result = activeObj.testMethod(123);
	assert (!result.available());
	assert (!result.tryWait(200));
	activeObj.cont();
	assert (result.tryWait(10000));
	assert (result.available());
	assert (result.data() == 123);
	assert (!result.failed());
}
void ActiveDispatcherTest::testWaitInterval()
{
	ActiveObject activeObj;
	ActiveResult<int> result = activeObj.testMethod(123);
	assert (!result.available());
	try
	{
		result.wait(100);
		fail("wait must fail");
	}
	catch (Exception&)
	{
	}
	activeObj.cont();
	result.wait(10000);
	assert (result.available());
	assert (result.data() == 123);
	assert (!result.failed());
}
Exemple #12
0
void ActiveMethodTest::testCopy()
{
	ActiveObject activeObj;

	ActiveObject::IntIntType ii = activeObj.testMethod;
	ActiveResult<int> rii = ii(123);
	assert (!rii.available());
	activeObj.cont();
	rii.wait();
	assert (rii.available());
	assert (rii.data() == 123);
	assert (!rii.failed());

	ActiveObject::VoidIntType  vi = activeObj.testVoid;
	ActiveResult<void> rvi = vi(123);
	assert (!rvi.available());
	activeObj.cont();
	rvi.wait();
	assert (rvi.available());
	assert (!rvi.failed());

	ActiveObject::VoidVoidType vv = activeObj.testVoidInOut;
	ActiveResult<void> rvv = vv();
	assert (!rvv.available());
	activeObj.cont();
	rvv.wait();
	assert (rvv.available());
	assert (!rvv.failed());

	ActiveObject::IntVoidType  iv = activeObj.testVoidIn;
	ActiveResult<int> riv = iv();
	assert (!riv.available());
	activeObj.cont();
	riv.wait();
	assert (riv.available());
	assert (riv.data() == 123);
	assert (!riv.failed());
}