Beispiel #1
0
void FormatTest::testBool()
{
	bool b = true;
	std::string s = format("%b", b);
	assert (s == "1");

	b = false;
	s = format("%b", b);
	assert (s == "0");

	std::vector<Poco::Any> bv;
	bv.push_back(false);
	bv.push_back(true);
	bv.push_back(false);
	bv.push_back(true);
	bv.push_back(false);
	bv.push_back(true);
	bv.push_back(false);
	bv.push_back(true);
	bv.push_back(false);
	bv.push_back(true);

	s.clear();
	format(s, "%b%b%b%b%b%b%b%b%b%b", bv);
	assert (s == "0101010101");
}
void BaosIpEnumerator::addDevice(const std::vector<unsigned char>& buffer, const IPAddress& networkInterface)
{
	if (buffer.size() > 68)
	{
		const int svcdiblen = buffer.at(68);
		const std::string ipAddress = format("%d.%d.%d.%d", (int) buffer.at(8), (int) buffer.at(9), (int) buffer.at(10), (int) buffer.at(11));
		const std::string deviceName = extract(&buffer.at(38), 30);
		const int manOffset = 68 + svcdiblen;

		if (static_cast<std::size_t>(manOffset + 7) < buffer.size())
		{
			const unsigned short mancode = buffer.at(manOffset + 2) << 8 | buffer.at(manOffset + 3);
			const unsigned char protocol = buffer.at(manOffset + 6);
			const unsigned char version = buffer.at(manOffset + 7);

			if (mancode == 0x00C5 && protocol == 0xF0)
			{
				poco_information(LOGGER(),
				                 format("Found: %s %s %d",
				                        deviceName, ipAddress, static_cast<int>(version)));

				devices_.push_back(std::make_tuple(deviceName, networkInterface.toString(), ipAddress, version));
			}
		}
	}
}
Beispiel #3
0
	void compile(const std::string& path)
	{
		Page page;

		FileInputStream srcStream(path);
		PageReader pageReader(page, path);
		pageReader.emitLineDirectives(_emitLineDirectives);
		pageReader.parse(srcStream);

		Path p(path);
		config().setString("inputFileName", p.getFileName());
		config().setString("inputFilePath", p.toString());
		
		DateTime now;
		config().setString("dateTime", DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT));

		std::string clazz;
		if (page.has("page.class"))
		{
			clazz = page.get("page.class");
			p.setBaseName(clazz);
		}
		else
		{
			clazz = p.getBaseName() + "Handler";
			clazz[0] = Poco::Ascii::toUpper(clazz[0]);
		}			

		std::auto_ptr<CodeWriter> pCodeWriter(createCodeWriter(page, clazz));

		if (!_outputDir.empty())
		{
			p = Path(_outputDir, p.getBaseName());
		}
		p.setExtension("cpp");
		std::string implPath = p.toString();
		std::string implFileName = p.getFileName();

		if (!_headerOutputDir.empty())
		{
			p = Path(_headerOutputDir, p.getBaseName());
		}
		p.setExtension("h");
		std::string headerPath = p.toString();
		std::string headerFileName = p.getFileName();

		config().setString("outputFileName", implFileName);
		config().setString("outputFilePath", implPath);
		FileOutputStream implStream(implPath);
		OutputLineEndingConverter implLEC(implStream);
		writeFileHeader(implLEC);
		pCodeWriter->writeImpl(implLEC, _headerPrefix + headerFileName);

		config().setString("outputFileName", headerFileName);
		config().setString("outputFilePath", headerPath);
		FileOutputStream headerStream(headerPath);
		OutputLineEndingConverter headerLEC(headerStream);
		writeFileHeader(headerLEC);
		pCodeWriter->writeHeader(headerLEC, headerFileName);
	}
Beispiel #4
0
void FileChannelTest::testRotateAtTimeMinLocal()
{
	std::string name = filename();
	try
	{
		AutoPtr<FileChannel> pChannel = new FileChannel(name);
		pChannel->setProperty(FileChannel::PROP_TIMES, "local");
		pChannel->setProperty(FileChannel::PROP_ROTATION, rotation<LocalDateTime>(MIN));
		pChannel->open();
		Message msg("source", "This is a log file entry", Message::PRIO_INFORMATION);
		int min = DateTime().minute();
		while (DateTime().minute() == min)
		{
			pChannel->log(msg);
			Thread::sleep(1000);
		}
		pChannel->log(msg);
		File f(name + ".0");
		assert (f.exists());
	}
	catch (...)
	{
		remove(name);
		throw;
	}
	remove(name);
}
Beispiel #5
0
void StringTest::testCat()
{
    std::string s1("one");
    std::string s2("two");
    std::string s3("three");
    std::string s4("four");
    std::string s5("five");
    std::string s6("six");

    assert (cat(s1, s2) == "onetwo");
    assert (cat(s1, s2, s3) == "onetwothree");
    assert (cat(s1, s2, s3, s4) == "onetwothreefour");
    assert (cat(s1, s2, s3, s4, s5) == "onetwothreefourfive");
    assert (cat(s1, s2, s3, s4, s5, s6) == "onetwothreefourfivesix");

    std::vector<std::string> vec;
    assert (cat(std::string(), vec.begin(), vec.end()) == "");
    assert (cat(std::string(","), vec.begin(), vec.end()) == "");
    vec.push_back(s1);
    assert (cat(std::string(","), vec.begin(), vec.end()) == "one");
    vec.push_back(s2);
    assert (cat(std::string(","), vec.begin(), vec.end()) == "one,two");
    vec.push_back(s3);
    assert (cat(std::string(","), vec.begin(), vec.end()) == "one,two,three");
}
Beispiel #6
0
void TextIteratorTest::testLatin1()
{
	Latin1Encoding encoding;
	std::string text("Latin1");
	TextIterator it(text, encoding);
	TextIterator end(text);
	
	assert (it != end);
	assert (*it++ == 'L');
	assert (it != end);
	assert (*it++ == 'a');
	assert (it != end);
	assert (*it++ == 't');
	assert (it != end);
	assert (*it++ == 'i');
	assert (it != end);
	assert (*it++ == 'n');
	assert (it != end);
	assert (*it++ == '1');
	assert (it == end);
	
	std::string empty;
	it  = TextIterator(empty, encoding);
	end = TextIterator(empty);
	assert (it == end);
}
/*!
	Scans an interface and enumerates all baos devices.
	It sends a search request as outlined in the BAOS 1.2 protocol
	documentation and waits for the responses. There are lots of
	magic numbers here and hard-coded offsets... See the spec
	for more information on what is happening here...

	We implement a receive timeout, and keep receiving until this
	timeout elapses. If this timeout is too fast, increase it to 500
	or 1000 for example.
*/
void BaosIpEnumerator::scanInterface(const NetworkInterface& networkInterface)
{
	poco_information(LOGGER(),
	                 format("Search devices on interface: %s (%s)",
	                        networkInterface.displayName(),
	                        networkInterface.address().toString()));

	try
	{
		// initialize socket
		MulticastSocket socket;
		socket.bind(SocketAddress(networkInterface.address(), 0));
		socket.setTimeToLive(DefaultMulticastTTL);

		// builds and sends a SEARCH_REQUEST to the socket
		sendSearchRequestFrame(socket);

		// wait for SEARCH_RESPONSES and collect it
		waitForSearchResponseFrames(socket);
	}
	catch (Poco::Exception& e)
	{
		poco_warning(LOGGER(), format("... search failed with error: %s", e.displayText()));
	}
}
Beispiel #8
0
void DateTimeTest::testArithmetics()
{
    DateTime dt1(2005, 1, 1, 0, 15, 30);
    DateTime dt2(2005, 1, 2, 0, 15, 30);
	
    Timespan s = dt2 - dt1;
    assert (s.days() == 1);
	
    DateTime dt3 = dt1 + s;
    assert (dt3 == dt2);
	
    dt3 -= s;
    assert (dt3 == dt1);
    dt1 += s;
    assert (dt1 == dt2);

    static const struct 
    {
        int lineNum;		// source line number
        int year1;			// operand/result date1 year
        int month1;			// operand/result date1 month
        unsigned int day1;	// operand/result date1 day
        int numDays;		// operand/result 'int' number of days
        int year2;			// operand/result date2 year
        int month2;			// operand/result date2 month
        unsigned int day2;	// operand/result date2 day
    } data[] = 
    {
        //          - - - -first- - - -           - - - second - - - 
        //line no.  year   month   day   numDays  year   month   day
        //-------   -----  -----  -----  -------  -----  -----  ----- 
        { __LINE__,       1,     1,     1,      1,      1,     1,     2 },
        { __LINE__,      10,     2,    28,      1,     10,     3,     1 },
        { __LINE__,     100,     3,    31,      2,    100,     4,     2 },
        { __LINE__,    1000,     4,    30,      4,   1000,     5,     4 },
        { __LINE__,    1000,     6,     1,    -31,   1000,     5,     1 },
        { __LINE__,    1001,     1,     1,   -365,   1000,     1,     1 },
        { __LINE__,    1100,     5,    31,     30,   1100,     6,    30 },
        { __LINE__,    1200,     6,    30,     32,   1200,     8,     1 },
        { __LINE__,    1996,     2,    28,    367,   1997,     3,     1 },
        { __LINE__,    1997,     2,    28,    366,   1998,     3,     1 },
        { __LINE__,    1998,     2,    28,    365,   1999,     2,    28 },
        { __LINE__,    1999,     2,    28,    364,   2000,     2,    27 },
        { __LINE__,    1999,     2,    28,   1096,   2002,     2,    28 },
        { __LINE__,    2002,     2,    28,  -1096,   1999,     2,    28 },
    };

    const int num_data = sizeof data / sizeof *data;
    for (int di = 0; di < num_data; ++di) 
    {
        const int line     = data[di].lineNum;
        const int num_days = data[di].numDays;
        DateTime x = DateTime(data[di].year1, data[di].month1, data[di].day1);
        const DateTime& X = x;
        x += Timespan(num_days, 0, 0, 0, 0);
        loop_1_assert(line, data[di].year2 == X.year());
        loop_1_assert(line, data[di].month2 == X.month());
        loop_1_assert(line, data[di].day2 == X.day());
    }
}
Beispiel #9
0
XplDevice::XplDevice
(
    string const& _vendorId,
    string const& _deviceId,
    string const& _version,
    bool const _bFilterMsgs,
    XplComms* _pComms
) :
    m_version ( _version ),
    m_bFilterMsgs ( _bFilterMsgs ),
    m_pComms ( _pComms ),
    m_bConfigRequired ( true ),
    m_bInitialised ( false ),
    m_heartbeatInterval ( 5 ),
    m_nextHeartbeat ( 0 ),
    m_bExitThread ( false ),

    m_bWaitingForHub ( true ),
    m_rapidHeartbeatCounter ( c_rapidHeartbeatTimeout/c_rapidHeartbeatFastInterval ),
    devLog ( Logger::get ( "xplsdk.device" ) )

{
    devLog.setLevel ("trace");
//     Logger::setLevel("xplsdk.device", Message::PRIO_TRACE  );
    assert ( devLog.trace() );

    m_vendorId = toLower ( _vendorId );
    m_deviceId = toLower ( _deviceId );
    m_instanceId = "default";
    
    SetCompleteId();

    m_hRxInterrupt = new Poco::Event ( false );

}
Beispiel #10
0
void StringTest::testTranslate()
{
    std::string s = "aabbccdd";
    assert (translate(s, "abc", "ABC") == "AABBCCdd");
    assert (translate(s, "abc", "AB") == "AABBdd");
    assert (translate(s, "abc", "") == "dd");
    assert (translate(s, "cba", "CB") == "BBCCdd");
    assert (translate(s, "", "CB") == "aabbccdd");
}
Beispiel #11
0
bool ODBCTest::canConnect(const std::string& driver,
	std::string& dsn,
	std::string& uid,
	std::string& pwd,
	std::string& dbConnString,
	const std::string& db)
{
	Utility::DriverMap::iterator itDrv = _drivers.begin();
	for (; itDrv != _drivers.end(); ++itDrv)
	{
		if (((itDrv->first).find(driver) != std::string::npos))
		{
			std::cout << "Driver found: " << itDrv->first 
				<< " (" << itDrv->second << ')' << std::endl;
			break;
		}
	}

	if (_drivers.end() == itDrv) 
	{
		dsn = "";
		uid = "";
		pwd = "";
		dbConnString = "";
		std::cout << driver << " driver NOT found, tests not available." << std::endl;
		return false;
	}

	Utility::DSNMap dataSources;
	Utility::dataSources(dataSources);
	if (dataSources.size() > 0)
	{
		Utility::DSNMap::iterator itDSN = dataSources.begin();
		std::cout << dataSources.size() << " DSNs found, enumerating ..." << std::endl;
		for (; itDSN != dataSources.end(); ++itDSN)
		{
			if (itDSN->first == dsn && itDSN->second == driver)
			{
				std::cout << "DSN found: " << itDSN->first
					<< " (" << itDSN->second << ')' << std::endl;

				dbConnString = format("DSN=%s;UID=%s;PWD=%s;", dsn, uid, pwd);
				if (!db.empty())
					format(dbConnString, "DATABASE=%s;", db);

				return true;
			}
		}
	}
	else
		std::cout << "No DSNs found, will attempt DSN-less connection ..." << std::endl;

	dsn = "";
	return true;
}
Beispiel #12
0
	DBEventHandler(RequestHandlerFactory& factory):
		_session("SQLite", "sample.db"),
		_factory(factory),
		_notifier(_session)
		/// Constructor; opens/initializes the database and associates
		/// notification events with their respective handlers.
	{
		initDB();
		_notifier.insert += delegate(this, &DBEventHandler::onInsert);
		_notifier.update += delegate(this, &DBEventHandler::onUpdate);
	}
Beispiel #13
0
void FormatTest::testIndex()
{
	std::string s(format("%[1]d%[0]d", 1, 2));
	assert(s == "21");

	s = format("%[5]d%[4]d%[3]d%[2]d%[1]d%[0]d", 1, 2, 3, 4, 5, 6);
	assert(s == "654321");

	s = format("%%%[1]d%%%[2]d%%%d", 1, 2, 3);
	assert(s == "%2%3%1");
}
Beispiel #14
0
void SocketTest::testFIFOBuffer()
{
	Buffer<char> b(5);
	b[0] = 'h';
	b[1] = 'e';
	b[2] = 'l';
	b[3] = 'l';
	b[4] = 'o';

	FIFOBuffer f(5, true);

	f.readable += delegate(this, &SocketTest::onReadable);
	f.writable += delegate(this, &SocketTest::onWritable);

	assert(0 == _notToReadable);
	assert(0 == _readableToNot);
	assert(0 == _notToWritable);
	assert(0 == _writableToNot);
	f.write(b);
	assert(1 == _notToReadable);
	assert(0 == _readableToNot);
	assert(0 == _notToWritable);
	assert(1 == _writableToNot);

	EchoServer echoServer;
	StreamSocket ss;
	ss.connect(SocketAddress("localhost", echoServer.port()));
	int n = ss.sendBytes(f);
	assert (n == 5);
	assert(1 == _notToReadable);
	assert(1 == _readableToNot);
	assert(1 == _notToWritable);
	assert(1 == _writableToNot);
	assert (f.isEmpty());

	n = ss.receiveBytes(f);
	assert (n == 5);
	
	assert(2 == _notToReadable);
	assert(1 == _readableToNot);
	assert(1 == _notToWritable);
	assert(2 == _writableToNot);

	assert (f[0] == 'h');
	assert (f[1] == 'e');
	assert (f[2] == 'l');
	assert (f[3] == 'l');
	assert (f[4] == 'o');

	f.readable -= delegate(this, &SocketTest::onReadable);
	f.writable -= delegate(this, &SocketTest::onWritable);

	ss.close();
}
Beispiel #15
0
void ODBCAccessTest::checkODBCSetup()
{
    static bool beenHere = false;

    if (!beenHere)
    {
        beenHere = true;

        bool driverFound = false;
        bool dsnFound = false;

        Utility::DriverMap::iterator itDrv = _drivers.begin();
        for (; itDrv != _drivers.end(); ++itDrv)
        {
            if (((itDrv->first).find("Microsoft Access Driver") != std::string::npos))
            {
                std::cout << "Driver found: " << itDrv->first
                          << " (" << itDrv->second << ')' << std::endl;
                driverFound = true;
                break;
            }
        }

        if (!driverFound)
        {
            std::cout << "Driver NOT found, will throw." << std::endl;
            throw NotFoundException("Microsoft Access ODBC driver.");
        }

        Utility::DSNMap::iterator itDSN = _dataSources.begin();
        for (; itDSN != _dataSources.end(); ++itDSN)
        {
            if (((itDSN->first).find(_dsn) != std::string::npos) &&
                    ((itDSN->second).find("Microsoft Access Driver") != std::string::npos))
            {
                std::cout << "DSN found: " << itDSN->first
                          << " (" << itDSN->second << ')' << std::endl;
                dsnFound = true;
                break;
            }
        }

        if (!dsnFound)
        {
            std::cout << "Access DSN NOT found, tests will fail." << std::endl;
            return;
        }
    }

    if (!_pSession)
        format(_dbConnString, "DSN=%s;Uid=Admin;Pwd=;", _dsn);
}
Beispiel #16
0
	void write(const std::string& path, const Page& page, const std::string& clazz)
	{
		Path p(path);
		config().setString("inputFileName", p.getFileName());
		config().setString("inputFilePath", p.toString());

		DateTime now;
		config().setString("dateTime", DateTimeFormatter::format(now, DateTimeFormat::SORTABLE_FORMAT));

		if (page.has("page.class"))
		{
			p.setBaseName(clazz);
		}

		std::unique_ptr<CodeWriter> pCodeWriter(createCodeWriter(page, clazz));

		if (!_outputDir.empty())
		{
			p = Path(_outputDir, p.getBaseName());
		}

		if (!_base.empty())
		{
			p.setBaseName(_base);
		}

		p.setExtension("cpp");
		std::string implPath = p.toString();
		std::string implFileName = p.getFileName();

		if (!_headerOutputDir.empty())
		{
			p = Path(_headerOutputDir, p.getBaseName());
		}
		p.setExtension("h");
		std::string headerPath = p.toString();
		std::string headerFileName = p.getFileName();

		config().setString("outputFileName", implFileName);
		config().setString("outputFilePath", implPath);
		FileOutputStream implStream(implPath);
		OutputLineEndingConverter implLEC(implStream);
		writeFileHeader(implLEC);
		pCodeWriter->writeImpl(implLEC, _headerPrefix + headerFileName);

		config().setString("outputFileName", headerFileName);
		config().setString("outputFilePath", headerPath);
		FileOutputStream headerStream(headerPath);
		OutputLineEndingConverter headerLEC(headerStream);
		writeFileHeader(headerLEC);
		pCodeWriter->writeHeader(headerLEC, headerFileName);
	}
/**
* @brief Performs connection throw a SpotChannel.
* @param GSpotTestUT The test case name.
* @param TestSpotChannel The test name.
* @since 1.0.0
*/
TEST(GSpotTestUT, TestSpotChannel)
{
  std::cout << std::endl << std::endl;
  std::cout << "//////////////////////////////////////////////////////////////////////" << std::endl;
  std::cout << "//////                    TestSpotChannel                     ////////" << std::endl;
  std::cout << "//////////////////////////////////////////////////////////////////////" << std::endl;

  EchoServer echoServer;

  ChannelListenerWorker listenerOne("Listener One");

  SpotChannel spotChannel("localhost", echoServer.port());

  spotChannel.start();

  spotChannel.subscribe( listenerOne );

  listenerOne.setChannel(spotChannel);

  EXPECT_EQ(spotChannel.getError(), SpotChannel::SpotChannelError::CNoError);

  if( spotChannel.getStatus() == SpotChannel::SpotChannelStatus::CStatusConnected )
  {
    std::string str = "hello";
    gvr::communication::IChannel::BufferType data(str.begin(), str.end());

    spotChannel.send(data);
    EXPECT_EQ(spotChannel.getError(), SpotChannel::SpotChannelError::CNoError);

    // Check the condition in a maximum elased time ...
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Timestamp initialTime;
    const unsigned long usTimeout = 800000; // timeout in microseconds... 1000 microseconds are 1 millisecond.
    while (
            ( listenerOne.getLastBufferReceived().empty()                ) &&
            ( Timestamp::TimeDiff((Timestamp()-initialTime)) < usTimeout )
          )
    {
      Thread::sleep(1);
    }
    std::cout << "Elapsed time ...[" << std::dec << Timestamp::TimeDiff( (Timestamp()-initialTime) ) << " us]." << std::endl;
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    EXPECT_EQ(listenerOne.getLastBufferReceived(), "hello");
  }

  spotChannel.stop();

  std::cout << "SpotChannel was stopped..." << std::endl;
  std::cout << "//////////////////////////////////////////////////////////////////////" << std::endl;
  std::cout << std::endl << std::endl;
}
Beispiel #18
0
void StringTest::testTrimLeft()
{
    {
        std::string s = "abc";
        assert (trimLeft(s) == "abc");
    }
    std::string s = " abc ";
    assert (trimLeft(s) == "abc ");
    {
        std::string s = "  ab c ";
        assert (trimLeft(s) == "ab c ");
    }
}
Beispiel #19
0
void FormatTest::testChar()
{
	char c = 'a';
	std::string s(format("%c", c));
	assert(s == "a");
	s = format("%2c", c);
	assert(s == " a");
	s = format("%-2c", c);
	assert(s == "a ");

	s = format("%c", std::string("foo"));
	assert(s == "[ERRFMT]");
}
Beispiel #20
0
void StringTest::testTrimRight()
{
    {
        std::string s = "abc";
        assert (trimRight(s) == "abc");
    }
    {
        std::string s = " abc ";
        assert (trimRight(s) == " abc");
    }
    {
        std::string s = "  ab c  ";
        assert (trimRight(s) == "  ab c");
    }
}
Beispiel #21
0
void StringTest::testTrimLeftInPlace()
{
    {
        std::string s = "abc";
        assert (trimLeftInPlace(s) == "abc");
    }
    {
        std::string s = " abc ";
        assert (trimLeftInPlace(s) == "abc ");
    }
    {
        std::string s = "  ab c ";
        assert (trimLeftInPlace(s) == "ab c ");
    }
}
	EchoServiceHandler(StreamSocket& socket, SocketReactor& reactor):
		_socket(socket),
		_reactor(reactor),
		_fifoIn(BUFFER_SIZE, true),
		_fifoOut(BUFFER_SIZE, true)
	{
		Application& app = Application::instance();
		app.logger().information("Connection from " + socket.peerAddress().toString());

		_reactor.addEventHandler(_socket, NObserver<EchoServiceHandler, ReadableNotification>(*this, &EchoServiceHandler::onSocketReadable));
		_reactor.addEventHandler(_socket, NObserver<EchoServiceHandler, ShutdownNotification>(*this, &EchoServiceHandler::onSocketShutdown));

		_fifoOut.readable += delegate(this, &EchoServiceHandler::onFIFOOutReadable);
		_fifoIn.writable += delegate(this, &EchoServiceHandler::onFIFOInWritable);
	}
Beispiel #23
0
void FileTest::testDirectory()
{
	File d("testdir");
	try
	{
		d.remove(true);
	}
	catch (...)
	{
	}
	TemporaryFile::registerForDeletion("testdir");

	bool created = d.createDirectory();
	assert (created);
	assert (d.isDirectory());
	assert (!d.isFile());
	std::vector<std::string> files;
	d.list(files);
	assert (files.empty());

	File f = Path("testdir/file1", Path::PATH_UNIX);
	f.createFile();
	f = Path("testdir/file2", Path::PATH_UNIX);
	f.createFile();
	f = Path("testdir/file3", Path::PATH_UNIX);
	f.createFile();

	d.list(files);
	assert (files.size() == 3);

	std::set<std::string> fs;
	fs.insert(files.begin(), files.end());
	assert (fs.find("file1") != fs.end());
	assert (fs.find("file2") != fs.end());
	assert (fs.find("file3") != fs.end());

	File dd(Path("testdir/testdir2/testdir3", Path::PATH_UNIX));
	dd.createDirectories();
	assert (dd.exists());
	assert (dd.isDirectory());

	File ddd(Path("testdir/testdirB/testdirC/testdirD", Path::PATH_UNIX));
	ddd.createDirectories();
	assert (ddd.exists());
	assert (ddd.isDirectory());

	d.remove(true);
}
Beispiel #24
0
bool ODBCAccessTest::canConnect(const std::string& driver, const std::string& dsn)
{
	Utility::DriverMap::iterator itDrv = _drivers.begin();
	for (; itDrv != _drivers.end(); ++itDrv)
	{
		if (((itDrv->first).find(driver) != std::string::npos))
		{
			std::cout << "Driver found: " << itDrv->first 
				<< " (" << itDrv->second << ')' << std::endl;
			break;
		}
	}

	if (_drivers.end() == itDrv) 
	{
		std::cout << driver << " driver NOT found, tests not available." << std::endl;
		return false;
	}

	Utility::DSNMap dataSources;
	Utility::dataSources(dataSources);
	Utility::DSNMap::iterator itDSN = dataSources.begin();
	for (; itDSN != dataSources.end(); ++itDSN)
	{
		if (itDSN->first == dsn && itDSN->second == driver)
		{
			std::cout << "DSN found: " << itDSN->first 
				<< " (" << itDSN->second << ')' << std::endl;
			format(_dbConnString, "DSN=%s", dsn);
			return true;
		}
	}

	// DSN not found, try connect without it
	format(_dbConnString, "DRIVER=%s;"
		"UID=admin;"
		"UserCommitSync=Yes;"
		"Threads=3;"
		"SafeTransactions=0;"
		"PageTimeout=5;"
		"MaxScanRows=8;"
		"MaxBufferSize=2048;"
		"FIL=MS Access;"
		"DriverId=25;"
		"DBQ=test.mdb;", driver);

	return true;
}
Beispiel #25
0
//--------------------------------------------------------------
void ofApp::newHttpPacket(ofxSnifferHttpPacket &packet){
    if(packet.srcIp == "172.29.5.185") {
        ofLog() << "skipping self";
        return;
    }
    string url = "http://" + packet.host + packet.request;
    cout << ".";
    
    if(RegularExpression(".*vidible.*").match(url)) {
        ofLog() << "ignoring ad";
        return;
    }
    
    RegularExpression regex(".*\\.(png|gif|jpe?g).*");
    if(regex.match(url)) {
        ofLog() << "match: " << url;
        size_t hash = Hash<string>()(url);
        string filename = ofToString(hash)+".jpg";
        if(ofFile(filename).exists()) {
            ofLog() << "file exists";
            return;
        }
        files.push_back(url);
    }
}
Beispiel #26
0
void ServerApplication::beDaemon()
{
#if !defined(POCO_NO_FORK_EXEC)
	pid_t pid;
	if ((pid = fork()) < 0)
		throw SystemException("cannot fork daemon process");
	else if (pid != 0)
		exit(0);
	
	setsid();
	umask(027);
	
	// attach stdin, stdout, stderr to /dev/null
	// instead of just closing them. This avoids
	// issues with third party/legacy code writing
	// stuff to stdout/stderr.
	FILE* fin  = freopen("/dev/null", "r+", stdin);
	if (!fin) throw Poco::OpenFileException("Cannot attach stdin to /dev/null");
	FILE* fout = freopen("/dev/null", "r+", stdout);
	if (!fout) throw Poco::OpenFileException("Cannot attach stdout to /dev/null");
	FILE* ferr = freopen("/dev/null", "r+", stderr);
	if (!ferr) throw Poco::OpenFileException("Cannot attach stderr to /dev/null");
#else
	throw Poco::NotImplementedException("platform does not allow fork/exec");
#endif
}
Beispiel #27
0
void AnthaxiaApp::initialize(Application& self) {
    Settings::loadSettings("procsim.rc");

    Poco::AutoPtr<AbstractConfiguration> pConfig;
    if (Path("logging.cfg").isFile())
    {
        pConfig = new PropertyFileConfiguration("logging.cfg");
    } else
    {
        pConfig = new MapConfiguration();
    }
    LoggingConfigurator configurator;
    configurator.configure(pConfig);

    Poco::LogStream log_stream(Poco::Logger::get("core.AnthaxiaApp"));
    LOG_DEBUG("Logging initialized; continue initialization of the rest");

    addSubsystem( new PluginManager() );

    // Make sure the model control is instantiated
    (void)ModelControl::getInstance();
    // Make sure the service system is present
    (void)ServiceSystem::getServiceSystem();
    registerModelControlService();

    Application::initialize(self);
}
Beispiel #28
0
void ODBCOracleTest::dropTable(const std::string& tableName)
{
	try
	{
		*_pSession << format("DROP TABLE %s", tableName), now;
	}
	catch (StatementException& ex)
	{
		bool ignoreError = false;
		const StatementDiagnostics::FieldVec& flds = ex.diagnostics().fields();
		StatementDiagnostics::Iterator it = flds.begin();
		for (; it != flds.end(); ++it)
		{
			if (942 == it->_nativeError)//ORA-00942 (table does not exist)
			{
				ignoreError = true;
				break;
			}
		}

		if (!ignoreError) 
		{
			std::cout << ex.displayText() << std::endl;
			throw;
		}
	}
}
Beispiel #29
0
std::string FileChannelTest::filename() const
{
	std::string name = "log_";
	name.append(DateTimeFormatter::format(Timestamp(), "%Y%m%d%H%M%S"));
	name.append(".log");
	return name;
}
/** Handling requests */
bool KeyValueStore::handleRequest(StreamSocket& client, Config::ThreadControl& control, char*& buf)
{
  char req;
  unsigned contentLength = 0;

  client.receiveBytes(&req, sizeof(req));

  if(req == Protocol::EXIT) {
    return true;
  }

  // Always expect that content-length will be the next sent.
  client.receiveBytes(&contentLength, sizeof(contentLength));
  if(contentLength < 0)
    throw Exception("Invalid content-length detected. Dropping client");

  buf = new char[contentLength+1];
  buf[contentLength] = '\0';
  client.receiveBytes(buf, contentLength);

  KeyValueStore::handleQuery(client, control, req, buf);

  delete [] buf;
  buf = NULL;

  return false;
}