コード例 #1
0
/*!
	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()));
	}
}
コード例 #2
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
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");
}
コード例 #3
0
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));
			}
		}
	}
}
コード例 #4
0
ファイル: ODBCTest.cpp プロジェクト: Blonder/poco
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;
}
コード例 #5
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
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");
}
コード例 #6
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
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]");
}
コード例 #7
0
ファイル: ODBCAccessTest.cpp プロジェクト: carvalhomb/tsmells
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;
}
コード例 #8
0
ファイル: ODBCSQLiteTest.cpp プロジェクト: Blonder/poco
void ODBCSQLiteTest::dropObject(const std::string& type, const std::string& name)
{
	try
	{
		session() << format("DROP %s %s", type, name), 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 (1 == it->_nativeError)//(no such table)
			{
				ignoreError = true;
				break;
			}
		}

		if (!ignoreError) 
		{
			std::cout << ex.toString() << std::endl;
			throw;
		}
	}
}
コード例 #9
0
ファイル: ODBCOracleTest.cpp プロジェクト: tjizep/treestore
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;
		}
	}
}
コード例 #10
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
void FormatTest::testMultiple()
{
	std::string s(format("aaa%dbbb%4dccc", 1, 2));
	assert (s == "aaa1bbb   2ccc");

	s = format("%%%d%%%d%%%d", 1, 2, 3);
	assert (s == "%1%2%3");
	
	s = format("%d%d%d%d", 1, 2, 3, 4);
	assert (s == "1234");

	s = format("%d%d%d%d%d", 1, 2, 3, 4, 5);
	assert (s == "12345");

	s = format("%d%d%d%d%d%d", 1, 2, 3, 4, 5, 6);
	assert (s == "123456");
}
コード例 #11
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
void FormatTest::testString()
{
	std::string foo("foo");
	std::string s(format("%s", foo));
	assert (s == "foo");
	
	s = format("%5s", foo);
	assert (s == "  foo");

	s = format("%-5s", foo);
	assert (s == "foo  ");

	s = format("%s%%a", foo);
	assert (s == "foo%a");

	s = format("'%s%%''%s%%'", foo, foo);
	assert (s == "'foo%''foo%'");
}
コード例 #12
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
void FormatTest::testFloatFix()
{
	double d = 1.5;
	std::string s(format("%f", d));
	assert (s.find("1.50") == 0);

	s = format("%10f", d);
	assert (s.find(" 1.50") != std::string::npos);

	s = format("%6.2f", d);
	assert (s == "  1.50");
	s = format("%-6.2f", d);
	assert (s == "1.50  ");
	
	float f = 1.5;
	s = format("%hf", f);
	assert (s.find("1.50") == 0);
}
コード例 #13
0
void BaosIpEnumerator::waitForSearchResponseFrames(MulticastSocket& socket)
{
	std::vector<unsigned char> buffer;
	while (waitForRx(socket, buffer))
	{
		poco_trace(LOGGER(), format("Received search response: %s", LoggerFormatter::toHex(buffer)));
		addDevice(buffer, socket.address().host());
	}
}
コード例 #14
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
void FormatTest::testFloatSci()
{
	double d = 1.5;
	std::string s(format("%e", d));
	assert (s.find("1.50") == 0);
	assert (s.find("0e+0") != std::string::npos);

	s = format("%20e", d);
	assert (s.find(" 1.50") != std::string::npos);
	assert (s.find("0e+0") != std::string::npos);

	s = format("%10.2e", d);
	assert (s == " 1.50e+000" || s == "  1.50e+00");
	s = format("%-10.2e", d);
	assert (s == "1.50e+000 " || s == "1.50e+00  ");
	s = format("%-10.2E", d);
	assert (s == "1.50E+000 " || s == "1.50E+00  ");
}
コード例 #15
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
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 ");
	
	try
	{
		s = format("%c", std::string("foo"));
		fail("bad argument - must throw");
	}
	catch (BadCastException&)
	{
	}
}
コード例 #16
0
ファイル: ODBCOracleTest.cpp プロジェクト: Kampbell/poco
void ODBCOracleTest::recreateNullsTable(const std::string& notNull)
{
	dropObject("TABLE", ExecUtil::nulltest());
	try { *_pSession << format("CREATE TABLE %s (i INTEGER %s, r NUMBER %s, v VARCHAR(30) %s)",ExecUtil::nulltest(),
		notNull,
		notNull,
		notNull), now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
}
コード例 #17
0
ファイル: ODBCPostgreSQLTest.cpp プロジェクト: 12307/poco
void ODBCPostgreSQLTest::recreateNullsTable(const std::string& notNull)
{
	dropObject("TABLE", "NullTest");
	try { session() << format("CREATE TABLE NullTest (i INTEGER %s, r FLOAT %s, v VARCHAR(30) %s)",
		notNull,
		notNull,
		notNull), now; }
	catch(ConnectionException& ce){ std::cout << ce.toString() << std::endl; fail ("recreateNullsTable()"); }
	catch(StatementException& se){ std::cout << se.toString() << std::endl; fail ("recreateNullsTable()"); }
}
コード例 #18
0
ファイル: MySQLTest.cpp プロジェクト: as2120/ZPoco
void MySQLTest::dropTable(const std::string& tableName)
{
    try
    {
        *_pSession << format("DROP TABLE %s", tableName), now;
    }
    catch (StatementException& )
    {
        //throw;
    }
}
コード例 #19
0
ファイル: ODBCAccessTest.cpp プロジェクト: as2120/ZPoco
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);
}
コード例 #20
0
int main(int argc, char* argv[])
{
	// configure the logging channel
	INIT_ROOT_CONSOLE_LOGGER();

	std::string ipAdress;

	if (argc > 1)
	{
		ipAdress = argv[1];
	}

	// Here we create the help text when the IP-Adress is missing or the user typed in '/?' for help
	if (argc < 2 || ipAdress == "/?")
	{
		std::cout << argv[0] << std::endl << std::endl << "Please type in the IP-Adress after the .exe" << std::endl <<
		          "to find out the Serial Number of the Baos device." << std::endl << "Use '/?' for help!" << std::endl;

		return EXIT_FAILURE;
	}
	std::cout << argv[1] << std::endl;

	try
	{
		// create a TPC/IP connection with the remote BAOS device
		StreamConnector2x::Ptr connector = std::make_shared<StreamConnector2x>();
		connector->open(ipAdress);

		// create baosServerItems value with the information of the baos device
		BaosServerItems baosServerItems(connector);

		// Get the Serial Number and show it to the user
		poco_information(LOGGER(), format("Serial Number: %s", LoggerFormatter::toHex(baosServerItems.getSerialNumber())));
	}
	catch (Exception& exception)
	{
		LOGGER().log(exception);
	}

	return EXIT_SUCCESS;
}
コード例 #21
0
ファイル: ODBCPostgreSQLTest.cpp プロジェクト: 12307/poco
void ODBCPostgreSQLTest::configurePLPgSQL()
{
	try
	{
		session() << format("CREATE FUNCTION plpgsql_call_handler () "
			"RETURNS OPAQUE "
			"AS '%splpgsql.dll' "
			"LANGUAGE 'C';", _libDir), now;
		
		session() << "CREATE LANGUAGE 'plpgsql' "
			"HANDLER plpgsql_call_handler "
			"LANCOMPILER 'PL/pgSQL'", now;

	}catch(StatementException& ex) 
	{  
		if (7 != ex.diagnostics().nativeError(0)) 
			throw;
	}

	return;
}
コード例 #22
0
ファイル: ODBCSQLiteTest.cpp プロジェクト: as2120/ZPoco
void ODBCSQLiteTest::checkODBCSetup()
{
    static bool beenHere = false;

    if (!beenHere)
    {
        beenHere = true;
        bool driverFound = false;
        std::string driverName;

        Utility::DriverMap::iterator itDriver = _drivers.begin();
        for (; itDriver != _drivers.end(); ++itDriver)
        {
            if (((itDriver->first).find("SQLite3") != std::string::npos))
            {
                std::cout << "Driver found: " << itDriver->first
                          << " (" << itDriver->second << ')' << std::endl;

                driverName = itDriver->first;
                driverFound = true;
                break;
            }
        }

        if (driverFound)
        {
            if (_dbConnString.empty() && !driverName.empty())
            {
                _dbConnString = format("Driver=%s;Database=dummy.db;", driverName);
                return;
            }
            else if (driverName.empty())
            {
                std::cout << "SQLite3 driver not found. Tests not available." << std::endl;
                return;
            }
        }
    }
}
コード例 #23
0
ファイル: ODBCDB2Test.cpp プロジェクト: tjizep/treestore
void ODBCDB2Test::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 (-204 == it->_nativeError)//(table does not exist)
			{
				ignoreError = true;
				break;
			}
		}

		if (!ignoreError) throw;
	}
}
コード例 #24
0
ファイル: ODBCPostgreSQLTest.cpp プロジェクト: 12307/poco
void ODBCPostgreSQLTest::dropObject(const std::string& type, const std::string& name)
{
	try
	{
		session() << format("DROP %s %s", type, name), 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 (7 == it->_nativeError)//(table does not exist)
			{
				ignoreError = true;
				break;
			}
		}

		if (!ignoreError) throw;
	}
}
コード例 #25
0
ファイル: ODBCOracleTest.cpp プロジェクト: 9drops/poco
void ODBCOracleTest::dropObject(const std::string& type, const std::string& name)
{
	try
	{
		*_pSession << format("DROP %s %s", type, name), 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 (4043 == it->_nativeError || //ORA-04043 (object does not exist)
				942 == it->_nativeError)//ORA-00942 (table does not exist)
			{
				ignoreError = true;
				break;
			}
		}

		if (!ignoreError) throw;
	}
}
コード例 #26
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
void FormatTest::testInt()
{
	int i = 42;
	std::string s(format("%d", i));
	assert (s == "42");
	s = format("%4d", i);
	assert (s == "  42");
	s = format("%04d", i);
	assert (s == "0042");

	short h = 42;
	s = format("%hd", h);
	assert (s == "42");
	s = format("%4hd", h);
	assert (s == "  42");
	s = format("%04hd", h);
	assert (s == "0042");

	unsigned short hu = 42;
	s = format("%hu", hu);
	assert (s == "42");
	s = format("%4hu", hu);
	assert (s == "  42");
	s = format("%04hu", hu);
	assert (s == "0042");
	
	unsigned x = 0x42;
	s = format("%x", x);
	assert (s == "42");
	s = format("%4x", x);
	assert (s == "  42");
	s = format("%04x", x);
	assert (s == "0042");

	unsigned o = 042;
	s = format("%o", o);
	assert (s == "42");
	s = format("%4o", o);
	assert (s == "  42");
	s = format("%04o", o);
	assert (s == "0042");

	unsigned u = 42;
	s = format("%u", u);
	assert (s == "42");
	s = format("%4u", u);
	assert (s == "  42");
	s = format("%04u", u);
	assert (s == "0042");
	
	long l = 42;
	s = format("%ld", l);
	assert (s == "42");
	s = format("%4ld", l);
	assert (s == "  42");
	s = format("%04ld", l);
	assert (s == "0042");

	unsigned long ul = 42;
	s = format("%lu", ul);
	assert (s == "42");
	s = format("%4lu", ul);
	assert (s == "  42");
	s = format("%04lu", ul);
	assert (s == "0042");
	
	unsigned long xl = 0x42;
	s = format("%lx", xl);
	assert (s == "42");
	s = format("%4lx", xl);
	assert (s == "  42");
	s = format("%04lx", xl);
	assert (s == "0042");
	
	Int64 i64 = 42;
	s = format("%Ld", i64);
	assert (s == "42");
	s = format("%4Ld", i64);
	assert (s == "  42");
	s = format("%04Ld", i64);
	assert (s == "0042");
	
	UInt64 ui64 = 42;
	s = format("%Lu", ui64);
	assert (s == "42");
	s = format("%4Lu", ui64);
	assert (s == "  42");
	s = format("%04Lu", ui64);
	assert (s == "0042");
	
	x = 0xaa;
	s = format("%x", x);
	assert (s == "aa");
	s = format("%X", x);
	assert (s == "AA");
	
	i = 42;
	s = format("%+d", i);
	assert (s == "+42");

	i = -42;
	s = format("%+d", i);
	assert (s == "-42");
	s = format("%d", i);
	assert (s == "-42");

	s = format("%d", i);
	assert (s == "-42");
	
	x = 0x42;
	s = format("%#x", x);
	assert (s == "0x42");
	
	try
	{
		s = format("%d", l);
		fail("bad argument - must throw");
	}
	catch (BadCastException&)
	{
	}
}
コード例 #27
0
ファイル: NumberParserTest.cpp プロジェクト: Chingliu/poco
void NumberParserTest::testParse()
{
	std::string sep(".,");

	for (int i = 0; i < 2; ++i)
	{
		char ts = sep[i];

		assert(NumberParser::parse("123") == 123);
		assert(NumberParser::parse(format("123%c456", ts), ts) == 123456);
		assert(NumberParser::parse(format("1%c234%c567", ts, ts), ts) == 1234567);
	}

	assert(NumberParser::parse("+123") == 123);
	assert(NumberParser::parse("-123") == -123);
	assert(NumberParser::parse("0") == 0);
	assert(NumberParser::parse("000") == 0);
	assert(NumberParser::parse("  123  ") == 123);
	assert(NumberParser::parse(" 123") == 123);
	assert(NumberParser::parse("123 ") == 123);
	assert(NumberParser::parse("0123") == 123);
	assert(NumberParser::parse("+0123") == 123);
	assert(NumberParser::parse("-0123") == -123);
	assert(NumberParser::parse("-123") == -123);
	assert(NumberParser::parseUnsigned("123") == 123);
	assert(NumberParser::parseHex("12AB") == 0x12ab);
	assert(NumberParser::parseHex("0X12AB") == 0x12ab);
	assert(NumberParser::parseHex("0x12AB") == 0x12ab);
	assert(NumberParser::parseHex("0x12aB") == 0x12ab);
	assert(NumberParser::parseHex("0X98Fe") == 0x98fe);
	assert(NumberParser::parseHex("0x0") == 0);
	assert(NumberParser::parseHex("00") == 0);
	assert(NumberParser::parseOct("123") == 0123);
	assert(NumberParser::parseOct("0123") == 0123);
	assert(NumberParser::parseOct("0") == 0);
	assert(NumberParser::parseOct("000") == 0);

	assert(NumberParser::parseBool("0") == false);
	assert(NumberParser::parseBool("FALSE") == false);
	assert(NumberParser::parseBool("no") == false);
	assert(NumberParser::parseBool("1") == true);
	assert(NumberParser::parseBool("True") == true);
	assert(NumberParser::parseBool("YeS") == true);

#if defined(POCO_HAVE_INT64)
	assert(NumberParser::parse64("123") == 123);
	assert(NumberParser::parse64("-123") == -123);
	assert(NumberParser::parse64("0123") == 123);
	assert(NumberParser::parse64("-0123") == -123);
	assert(NumberParser::parseUnsigned64("123") == 123);
	assert(NumberParser::parseHex64("12AB") == 0x12ab);
	assert(NumberParser::parseHex64("0x12AB") == 0x12ab);
	assert(NumberParser::parseOct64("123") == 0123);
	assert(NumberParser::parseOct64("0123") == 0123);
#endif

#ifndef POCO_NO_FPENVIRONMENT
	for (int i = 0; i < 2; ++i)
	{
		char ts = sep[i];
		for (int j = 0; j < 2; ++j)
		{
			char dp = sep[j];
			if (ts == dp) continue;

			assertEqualDelta(1.0, NumberParser::parseFloat(format("1", dp), dp, ts), 0.01);
			assertEqualDelta(0.0, NumberParser::parseFloat(format("0%c0", dp), dp, ts), 0.01);
			assertEqualDelta(0., NumberParser::parseFloat(format("0%c0", dp), dp, ts), 0.01);
			assertEqualDelta(.0, NumberParser::parseFloat(format("0%c0", dp), dp, ts), 0.01);
			assertEqualDelta(12.34, NumberParser::parseFloat(format("12%c34", dp), dp, ts), 0.01);
			assertEqualDelta(12.34, NumberParser::parseFloat(format("12%c34f", dp), dp, ts), 0.01);
			assertEqualDelta(12.34, NumberParser::parseFloat(format("12%c34", dp), dp, ts), 0.01);
			assertEqualDelta(-12.34, NumberParser::parseFloat(format("-12%c34", dp), dp, ts), 0.01);
			assertEqualDelta(.34, NumberParser::parseFloat(format("%c34", dp), dp, ts), 0.01);
			assertEqualDelta(-.34, NumberParser::parseFloat(format("-%c34", dp), dp, ts), 0.01);
			assertEqualDelta(12., NumberParser::parseFloat(format("12%c", dp), dp, ts), 0.01);
			assertEqualDelta(-12., NumberParser::parseFloat(format("-12%c", dp), dp, ts), 0.01);
			assertEqualDelta(12, NumberParser::parseFloat("12", dp, ts), 0.01);
			assertEqualDelta(-12, NumberParser::parseFloat("-12", dp, ts), 0.01);
			assertEqualDelta(12.34, NumberParser::parseFloat(format("12%c3456789012345678901234567890", dp), dp, ts), 0.01);

			assertEqualDelta(1234.3456789, NumberParser::parseFloat(format("1%c234%c3456789012345678901234567890", ts, dp), dp, ts), 0.00000001);
			assertEqualDelta(12345.3456789, NumberParser::parseFloat(format("12%c345%c3456789012345678901234567890", ts, dp), dp, ts), 0.00000001);
			assertEqualDelta(123456.3456789, NumberParser::parseFloat(format("123%c456%c3456789012345678901234567890", ts, dp), dp, ts), 0.00000001);
			assertEqualDelta(1234567.3456789, NumberParser::parseFloat(format("1%c234%c567%c3456789012345678901234567890", ts, ts, dp), dp, ts), 0.00000001);
			assertEqualDelta(12345678.3456789, NumberParser::parseFloat(format("12%c345%c678%c3456789012345678901234567890", ts, ts, dp), dp, ts), 0.00000001);
			assertEqualDelta(123456789.3456789, NumberParser::parseFloat(format("123%c456%c789%c3456789012345678901234567890", ts, ts, dp), dp, ts), 0.00000001);

			if ((std::numeric_limits<double>::max() / 10) < 1.23456e10)
				fail ("test value larger than max value for this platform");
			else
			{
				double d = 1.234e100;
				assertEqualDelta(d, NumberParser::parseFloat(format("1%c234e100", dp), dp, ts), 0.01);
				assertEqualDelta(d, NumberParser::parseFloat(format("1%c234E+100", dp), dp, ts), 0.01);
		
				d = 1.234e-100;
				assertEqualDelta(d, NumberParser::parseFloat(format("1%c234E-100", dp), dp, ts), 0.01);
		
				d = -1.234e100;
				assertEqualDelta(d, NumberParser::parseFloat(format("-1%c234e+100", dp), dp, ts), 0.01);
				assertEqualDelta(d, NumberParser::parseFloat(format("-1%c234E100", dp), dp, ts), 0.01);
		
				d = 1.234e-100;
				assertEqualDelta(d, NumberParser::parseFloat(format(" 1%c234e-100 ", dp), dp, ts), 0.01);
				assertEqualDelta(d, NumberParser::parseFloat(format(" 1%c234e-100 ", dp), dp, ts), 0.01);
				assertEqualDelta(d, NumberParser::parseFloat(format("  1%c234e-100 ", dp), dp, ts), 0.01);

				d = 1234.234e-100;
				assertEqualDelta(d, NumberParser::parseFloat(format(" 1%c234%c234e-100 ", ts, dp), dp, ts), 0.01);
				d = 12345.234e-100;
				assertEqualDelta(d, NumberParser::parseFloat(format(" 12%c345%c234e-100 ", ts, dp), dp, ts), 0.01);
				d = 123456.234e-100;
				assertEqualDelta(d, NumberParser::parseFloat(format("  123%c456%c234e-100 ", ts, dp), dp, ts), 0.01);

				d = -1234.234e-100;
				assertEqualDelta(d, NumberParser::parseFloat(format(" -1%c234%c234e-100 ", ts, dp), dp, ts), 0.01);
				d = -12345.234e-100;
				assertEqualDelta(d, NumberParser::parseFloat(format(" -12%c345%c234e-100 ", ts, dp), dp, ts), 0.01);
				d = -123456.234e-100;
				assertEqualDelta(d, NumberParser::parseFloat(format("  -123%c456%c234e-100 ", ts, dp), dp, ts), 0.01);
			}

			double d = 12.34e-10;
			assertEqualDelta(d, NumberParser::parseFloat(format("12%c34e-10", dp), dp, ts), 0.01);
			assertEqualDelta(-12.34, NumberParser::parseFloat(format("-12%c34", dp), dp, ts), 0.01);
	
			assertEqualDelta(12.34, NumberParser::parseFloat(format("   12%c34", dp),dp, ts), 0.01);
			assertEqualDelta(12.34, NumberParser::parseFloat(format("12%c34   ", dp), dp, ts), 0.01);
			assertEqualDelta(12.34, NumberParser::parseFloat(format(" 12%c34  ", dp), dp, ts), 0.01);

			assertEqualDelta(12.34, NumberParser::parseFloat(format("\t\n 12%c34  \v\f\r", dp), dp, ts), 0.01);
		}
	}
#endif // POCO_NO_FPENVIRONMENT
}
コード例 #28
0
ファイル: ODBCDB2Test.cpp プロジェクト: tjizep/treestore
void ODBCDB2Test::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("IBM DB2") != std::string::npos))
			{
				std::cout << "Driver found: " << itDrv->first 
					<< " (" << itDrv->second << ')' << std::endl;
				driverFound = true;
				break;
			}
		}

		if (!driverFound) 
		{
			std::cout << "DB2 driver NOT found, tests will fail." << std::endl;
			return;
		}
		
		Utility::DSNMap::iterator itDSN = _dataSources.begin();
		for (; itDSN != _dataSources.end(); ++itDSN)
		{
			if (((itDSN->first).find(_dsn) != std::string::npos) &&
				((itDSN->second).find("IBM DB2") != std::string::npos))
			{
				std::cout << "DSN found: " << itDSN->first 
					<< " (" << itDSN->second << ')' << std::endl;
				dsnFound = true;
				break;
			}
		}

		if (!dsnFound) 
		{
			if (!_pSession && _dbConnString.empty())
			{
				std::cout << "DB2 DSN NOT found, will attempt to connect without it." << std::endl;
				_dbConnString = "Driver=" DB2_ODBC_DRIVER ";"
					"Database=" DB2_DB ";"
					"Hostname=" DB2_SERVER ";"
					"Port=" DB2_PORT ";"
					"Protocol=TCPIP;"
					"Uid=" DB2_UID ";"
					"Pwd=" DB2_PWD ";";
			}
			else if (!_dbConnString.empty())
			{
				std::cout << "DB2 tests not available." << std::endl;
				return;
			}
		}
	}

	if (!_pSession)
		format(_dbConnString, "DSN=%s;Uid=db2admin;Pwd=db2admin;", _dsn);
}
コード例 #29
0
ファイル: FormatTest.cpp プロジェクト: RangelReale/sandbox
void FormatTest::testAnyInt()
{
	char c = 42;
	std::string s(format("%?i", c));
	assert (s == "42");
	
	bool b = true;
	s = format("%?i", b);
	assert (s == "1");

	signed char sc = -42;
	s = format("%?i", sc);
	assert (s == "-42");
	
	unsigned char uc = 65;
	s = format("%?i", uc);
	assert (s == "65");
	
	short ss = -134;
	s = format("%?i", ss);
	assert (s == "-134");
	
	unsigned short us = 200;
	s = format("%?i", us);
	assert (s == "200");
	
	int i = -12345;
	s = format("%?i", i);
	assert (s == "-12345");
	
	unsigned ui = 12345;
	s = format("%?i", ui);
	assert (s == "12345");
	
	long l = -54321;
	s = format("%?i", l);
	assert (s == "-54321");
	
	unsigned long ul = 54321;
	s = format("%?i", ul);
	assert (s == "54321");
	
	Int64 i64 = -12345678;
	s = format("%?i", i64);
	assert (s == "-12345678");

	UInt64 ui64 = 12345678;
	s = format("%?i", ui64);
	assert (s == "12345678");
	
	ss = 0x42;
	s = format("%?x", ss);
	assert (s == "42");

	ss = 042;
	s = format("%?o", ss);
	assert (s == "42");
}
コード例 #30
0
void MySQLTest::dropTable(const std::string& tableName)
{
	try { *_pSession << format("DROP TABLE IF EXISTS %s", tableName), now; }
	catch(ConnectionException& ce){ std::cout << ce.displayText() << std::endl; fail ("dropTable()"); }
	catch(StatementException& se){ std::cout << se.displayText() << std::endl; fail ("dropTable()"); }
}