summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2015-12-19 21:25:02 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2015-12-21 03:43:10 +0000
commit86fd23381c55a8a981313104a3526d9d61fb97fe (patch)
tree0ba5905db78126ce284baf5553c72fc860fca89e
parentAdd support for getting a news item by Id (diff)
downloadgentoobrowse-api-86fd23381c55a8a981313104a3526d9d61fb97fe.tar.bz2
gentoobrowse-api-86fd23381c55a8a981313104a3526d9d61fb97fe.tar.xz
gentoobrowse-api-86fd23381c55a8a981313104a3526d9d61fb97fe.zip
Use fixture test suite to reduce repetition
-rw-r--r--gentoobrowse-api/unittests/testPortage.cpp57
1 files changed, 15 insertions, 42 deletions
diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp
index 8a8d5bb..c5c85f6 100644
--- a/gentoobrowse-api/unittests/testPortage.cpp
+++ b/gentoobrowse-api/unittests/testPortage.cpp
@@ -14,17 +14,26 @@ class MockPool : public AdHoc::ResourcePool<DB::Connection> {
}
};
+class TestPortage {
+ public:
+ TestPortage() :
+ p(new Portage(mp))
+ {
+ }
+
+ MockPool mp;
+ Portage::PointerType p;
+};
+
+BOOST_FIXTURE_TEST_SUITE(tp, TestPortage)
+
BOOST_AUTO_TEST_CASE( getCategoryMissing )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
BOOST_REQUIRE_THROW(p->getCategory(0, Ice::Current()), std::exception);
}
BOOST_AUTO_TEST_CASE( getCategory )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto cat = p->getCategory(316, Ice::Current());
BOOST_REQUIRE(cat);
BOOST_REQUIRE_EQUAL(316, cat->categoryid);
@@ -35,8 +44,6 @@ BOOST_AUTO_TEST_CASE( getCategory )
BOOST_AUTO_TEST_CASE( getAllCategories )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto cats = p->getAllCategories(Ice::Current());
BOOST_REQUIRE_EQUAL(5, cats.size());
BOOST_REQUIRE_EQUAL(316, cats.front()->categoryid);
@@ -47,8 +54,6 @@ BOOST_AUTO_TEST_CASE( getAllCategories )
BOOST_AUTO_TEST_CASE( getCategoriesInSuper )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto cats = p->getCategoriesInSuper("dev", Ice::Current());
BOOST_REQUIRE_EQUAL(2, cats.size());
BOOST_REQUIRE_EQUAL("dev-ml", cats.front()->name);
@@ -61,8 +66,6 @@ BOOST_AUTO_TEST_CASE( getCategoriesInSuper )
BOOST_AUTO_TEST_CASE( getOverviewCategoriesInSuper )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto cats = p->getOverviewCategoriesInSuper("dev", Ice::Current());
BOOST_REQUIRE_EQUAL(2, cats.size());
BOOST_REQUIRE_EQUAL("dev-ml", cats.front()->name);
@@ -77,15 +80,11 @@ BOOST_AUTO_TEST_CASE( getOverviewCategoriesInSuper )
BOOST_AUTO_TEST_CASE( getPackageMissing )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
BOOST_REQUIRE_THROW(p->getPackage(0, Ice::Current()), std::exception);
}
BOOST_AUTO_TEST_CASE( getPackage )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto pkg = p->getPackage(53258, Ice::Current());
BOOST_REQUIRE(pkg);
BOOST_REQUIRE_EQUAL(53258, pkg->packageid);
@@ -100,16 +99,12 @@ BOOST_AUTO_TEST_CASE( getPackage )
BOOST_AUTO_TEST_CASE( findPackage )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto cat = p->findPackage("not", "here", Ice::Current());
BOOST_REQUIRE(!cat);
}
BOOST_AUTO_TEST_CASE( findPackageMissing )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto pkg = p->findPackage("dev-vcs", "archway", Ice::Current());
BOOST_REQUIRE(pkg);
BOOST_REQUIRE_EQUAL(53258, (*pkg)->packageid);
@@ -117,8 +112,6 @@ BOOST_AUTO_TEST_CASE( findPackageMissing )
BOOST_AUTO_TEST_CASE( getPackagesInCategory )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto pkgs = p->getPackagesInCategory(311, Ice::Current());
BOOST_REQUIRE_EQUAL(88, pkgs.size());
BOOST_REQUIRE_EQUAL("archway", pkgs.front()->name);
@@ -127,16 +120,12 @@ BOOST_AUTO_TEST_CASE( getPackagesInCategory )
BOOST_AUTO_TEST_CASE( searchEmpty )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto matches = p->getPackagesSearch("", Ice::Current());
BOOST_REQUIRE(matches.empty());
}
BOOST_AUTO_TEST_CASE( search )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto matches = p->getPackagesSearch("git", Ice::Current());
BOOST_REQUIRE_EQUAL(40, matches.size());
BOOST_REQUIRE_EQUAL(58252, matches.front()->packageid);
@@ -145,16 +134,12 @@ BOOST_AUTO_TEST_CASE( search )
BOOST_AUTO_TEST_CASE( searchNotFound )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto matches = p->getPackagesSearch("something that doesn't exist", Ice::Current());
BOOST_REQUIRE(matches.empty());
}
BOOST_AUTO_TEST_CASE( getPackageVersions )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto es = p->getPackageVersions(58252);
BOOST_REQUIRE_EQUAL(9, es.size());
BOOST_REQUIRE_EQUAL(634225, es.front()->ebuildid);
@@ -170,8 +155,6 @@ BOOST_AUTO_TEST_CASE( getPackageVersions )
BOOST_AUTO_TEST_CASE( getPackageChangeLog )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto cl = p->getPackageChangeLog(64582);
BOOST_REQUIRE_EQUAL(3, cl.size());
BOOST_REQUIRE_EQUAL(64582, cl.front()->packageid);
@@ -190,8 +173,6 @@ BOOST_AUTO_TEST_CASE( getPackageChangeLog )
BOOST_AUTO_TEST_CASE( getRecentAdditions )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto es = p->getRecentAdditions(2);
BOOST_REQUIRE_EQUAL(8, es.size());
BOOST_REQUIRE_EQUAL(680617, es.front()->ebuildid);
@@ -206,8 +187,6 @@ BOOST_AUTO_TEST_CASE( getRecentAdditions )
BOOST_AUTO_TEST_CASE( getBug )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto b = p->getBug(567064);
BOOST_REQUIRE(b);
BOOST_REQUIRE_EQUAL(567064, b->bugid);
@@ -219,8 +198,6 @@ BOOST_AUTO_TEST_CASE( getBug )
BOOST_AUTO_TEST_CASE( getPackageBugs )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto bs = p->getPackageBugs(55925);
BOOST_REQUIRE_EQUAL(1, bs.size());
BOOST_REQUIRE_EQUAL(567166, bs.front()->bugid);
@@ -229,8 +206,6 @@ BOOST_AUTO_TEST_CASE( getPackageBugs )
BOOST_AUTO_TEST_CASE( getBugsSearch )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto bs = p->getBugsSearch("cpu");
BOOST_REQUIRE_EQUAL(3, bs.size());
BOOST_REQUIRE_EQUAL(567154, bs[0]->bugid);
@@ -242,8 +217,6 @@ BOOST_AUTO_TEST_CASE( getBugsSearch )
BOOST_AUTO_TEST_CASE( getNewsItem )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto n = p->getNewsItem("2015-02-01-use-libav");
BOOST_REQUIRE(n);
BOOST_REQUIRE_EQUAL("2015-02-01-use-libav", n->newsid);
@@ -270,8 +243,6 @@ BOOST_AUTO_TEST_CASE( getNewsItem )
BOOST_AUTO_TEST_CASE( cache )
{
- MockPool mp;
- auto p = Portage::PointerType(new Portage(mp));
auto c1 = p->getCategory(311, Ice::Current());
BOOST_REQUIRE(c1);
BOOST_REQUIRE_EQUAL(311, c1->categoryid);
@@ -287,3 +258,5 @@ BOOST_AUTO_TEST_CASE( cache )
BOOST_REQUIRE_EQUAL(311, c2->categoryid);
}
+BOOST_AUTO_TEST_SUITE_END();
+