mirror of
https://github.com/pocoproject/poco.git
synced 2025-03-04 19:13:30 +01:00
Add more tests
This commit is contained in:
parent
c2dbb70b0b
commit
58958d2655
@ -144,6 +144,8 @@ void MongoDBTest::testQueryRequest()
|
||||
assert(birthDate.year() == 1969 && birthDate.month() == 3 && birthDate.day() == 9);
|
||||
Poco::Timestamp lastupdatedTimestamp = doc->get<Poco::Timestamp>("lastupdated");
|
||||
assert(doc->isType<NullValue>("unknown"));
|
||||
bool active = doc->get<bool>("active");
|
||||
assert(!active);
|
||||
|
||||
std::string id = doc->get("_id")->toString();
|
||||
std::cout << id << std::endl;
|
||||
@ -261,6 +263,20 @@ void MongoDBTest::testDBCountCommand()
|
||||
}
|
||||
|
||||
|
||||
void MongoDBTest::testDBCount2Command()
|
||||
{
|
||||
if ( ! _connected )
|
||||
{
|
||||
std::cout << "test skipped." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Poco::MongoDB::Database db("team");
|
||||
double count = db.count(_mongo, "players");
|
||||
assert(count == 1);
|
||||
}
|
||||
|
||||
|
||||
void MongoDBTest::testDeleteRequest()
|
||||
{
|
||||
if ( ! _connected )
|
||||
@ -276,6 +292,42 @@ void MongoDBTest::testDeleteRequest()
|
||||
}
|
||||
|
||||
|
||||
void MongoDBTest::testBuildInfo()
|
||||
{
|
||||
if ( ! _connected )
|
||||
{
|
||||
std::cout << "test skipped." << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
Poco::MongoDB::QueryRequest request("team.$cmd");
|
||||
request.numberToReturn(1);
|
||||
request.query().add("buildInfo", 1);
|
||||
|
||||
Poco::MongoDB::ResponseMessage response;
|
||||
|
||||
try
|
||||
{
|
||||
_mongo.sendRequest(request, response);
|
||||
}
|
||||
catch(Poco::NotImplementedException& nie)
|
||||
{
|
||||
std::cout << nie.message() << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( response.documents().size() > 0 )
|
||||
{
|
||||
Poco::MongoDB::Document::Ptr doc = response.documents()[0];
|
||||
std::cout << doc->toString();
|
||||
}
|
||||
else
|
||||
{
|
||||
fail("Didn't get a response from the buildinfo command");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MongoDBTest::testConnectionPool()
|
||||
{
|
||||
Poco::PoolableObjectFactory<Poco::MongoDB::Connection, Poco::MongoDB::Connection::Ptr> factory("localhost:27017");
|
||||
@ -300,18 +352,6 @@ void MongoDBTest::testConnectionPool()
|
||||
{
|
||||
fail("Didn't get a response from the count command");
|
||||
}
|
||||
|
||||
/*
|
||||
Poco::MongoDB::Connection::Ptr pooledConnection1 = pool.borrowObject();
|
||||
assert(!pooledConnection1.isNull());
|
||||
pool.returnObject(pooledConnection1);
|
||||
|
||||
std::cout << "Available: " << pool.available() << std::endl;
|
||||
|
||||
Poco::MongoDB::Connection::Ptr pooledConnection2 = pool.borrowObject();
|
||||
assert(!pooledConnection2.isNull());
|
||||
|
||||
pool.returnObject(pooledConnection2);*/
|
||||
}
|
||||
|
||||
CppUnit::Test* MongoDBTest::suite()
|
||||
@ -323,8 +363,10 @@ CppUnit::Test* MongoDBTest::suite()
|
||||
CppUnit_addTest(pSuite, MongoDBTest, testDBQueryRequest);
|
||||
CppUnit_addTest(pSuite, MongoDBTest, testCountCommand);
|
||||
CppUnit_addTest(pSuite, MongoDBTest, testDBCountCommand);
|
||||
CppUnit_addTest(pSuite, MongoDBTest, testDBCount2Command);
|
||||
CppUnit_addTest(pSuite, MongoDBTest, testConnectionPool);
|
||||
CppUnit_addTest(pSuite, MongoDBTest, testDeleteRequest);
|
||||
CppUnit_addTest(pSuite, MongoDBTest, testBuildInfo);
|
||||
|
||||
return pSuite;
|
||||
}
|
||||
|
@ -66,9 +66,15 @@ public:
|
||||
void testDBCountCommand();
|
||||
|
||||
|
||||
void testDBCount2Command();
|
||||
|
||||
|
||||
void testDeleteRequest();
|
||||
|
||||
|
||||
void testBuildInfo();
|
||||
|
||||
|
||||
void testConnectionPool();
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user