diff options
Diffstat (limited to 'gentoobrowse-api/unittests')
-rw-r--r-- | gentoobrowse-api/unittests/Jamfile.jam | 17 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/mockDefs.cpp | 9 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/mockDefs.h | 14 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testInit.cpp | 26 | ||||
-rw-r--r-- | gentoobrowse-api/unittests/testPortage.cpp | 74 |
5 files changed, 44 insertions, 96 deletions
diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam index e2a5b28..1a6f41c 100644 --- a/gentoobrowse-api/unittests/Jamfile.jam +++ b/gentoobrowse-api/unittests/Jamfile.jam @@ -21,9 +21,16 @@ lib testCommon : <define>ROOT=\"$(me)\" <library>..//boost_system <library>..//boost_filesystem + <library>..//Ice + <library>..//IceUtil + <library>..//IceBox + <library>../../icetray//dryice + <library>../service//gentoobrowse-service : : <library>..//dbppcore <library>..//adhocutil + <library>..//IceBox + <library>../../icetray//dryice ; @@ -53,13 +60,3 @@ run testPerf.cpp <library>boost_utf : testPerf ; -run testInit.cpp - : : : - <define>BOOST_TEST_DYN_LINK - <library>../service//gentoobrowse-service - <library>boost_utf - <library>..//Ice - <library>..//IceBox - <library>dl - : testInit ; - diff --git a/gentoobrowse-api/unittests/mockDefs.cpp b/gentoobrowse-api/unittests/mockDefs.cpp index abcff03..3d7a679 100644 --- a/gentoobrowse-api/unittests/mockDefs.cpp +++ b/gentoobrowse-api/unittests/mockDefs.cpp @@ -1,10 +1,15 @@ #include "mockDefs.h" #include <definedDirs.h> -StandardMockDatabase::StandardMockDatabase() : - PQ::Mock("user=postgres dbname=postgres", "postgres", { +Service::Service() : + PQ::Mock("user=postgres dbname=postgres", "GentooBrowseAPI", { rootDir.parent_path() / "db" / "schema.sql", rootDir / "data.sql" }) { } +TestClient::TestClient() : + p(Gentoo::PortagePrx::checkedCast(ic->stringToProxy("portage:tcp -p 9002"))) +{ +} + diff --git a/gentoobrowse-api/unittests/mockDefs.h b/gentoobrowse-api/unittests/mockDefs.h index ca43d4d..8b4d642 100644 --- a/gentoobrowse-api/unittests/mockDefs.h +++ b/gentoobrowse-api/unittests/mockDefs.h @@ -3,12 +3,20 @@ #include <mock.h> #include <visibility.h> +#include <dryice.h> +#include <portage.h> -#define DECLAREMOCK(Name) class DLL_PUBLIC Name : public PQ::Mock { public: Name(); } +class DLL_PUBLIC Service : public IceTray::DryIce, PQ::Mock { + public: + Service(); +}; -DECLAREMOCK(StandardMockDatabase); +class DLL_PUBLIC TestClient : public IceTray::DryIceClient { + public: + TestClient(); -#undef DECLAREMOCK + Gentoo::PortagePrx p; +}; #endif diff --git a/gentoobrowse-api/unittests/testInit.cpp b/gentoobrowse-api/unittests/testInit.cpp deleted file mode 100644 index 15479ac..0000000 --- a/gentoobrowse-api/unittests/testInit.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#define BOOST_TEST_MODULE TestInit -#include <boost/test/unit_test.hpp> -#include <dlfcn.h> -#include <Ice/Ice.h> -#include <IceBox/IceBox.h> - -typedef IceBox::Service *(* SetupFunction)(Ice::CommunicatorPtr); - -BOOST_AUTO_TEST_CASE( init ) -{ - void * i = dlsym(NULL, "createGentooBrowseAPI"); - BOOST_REQUIRE(i); - auto sf = (SetupFunction)i; - BOOST_REQUIRE(sf); - Ice::StringSeq args; - Ice::InitializationData id; - id.properties = Ice::createProperties(); - id.properties->setProperty("GentooBrowseAPI.Endpoints", "tcp -p 9002"); - auto ic = Ice::initialize(args, id); - IceBox::Service * s = sf(nullptr); - s->start("GentooBrowseAPI", ic, {}); - s->stop(); - delete s; - ic->destroy(); -} - diff --git a/gentoobrowse-api/unittests/testPortage.cpp b/gentoobrowse-api/unittests/testPortage.cpp index 271ff34..fee3751 100644 --- a/gentoobrowse-api/unittests/testPortage.cpp +++ b/gentoobrowse-api/unittests/testPortage.cpp @@ -4,37 +4,18 @@ #include "mockDefs.h" #include <portageimpl.h> -BOOST_GLOBAL_FIXTURE( StandardMockDatabase ); +BOOST_GLOBAL_FIXTURE( Service ); -class MockPool : public AdHoc::ResourcePool<DB::Connection> { - public: - MockPool() : AdHoc::ResourcePool<DB::Connection>(1, 1) { } - DB::Connection * createResource() const override { - return DB::MockDatabase::openConnectionTo("postgres"); - } -}; - -class TestPortage { - public: - TestPortage() : - p(new Portage(mp)) - { - } - - MockPool mp; - Portage::PointerType p; -}; - -BOOST_FIXTURE_TEST_SUITE(tp, TestPortage) +BOOST_FIXTURE_TEST_SUITE(tp, TestClient) BOOST_AUTO_TEST_CASE( getCategoryMissing ) { - BOOST_REQUIRE_THROW(p->getCategory(0, Ice::Current()), std::exception); + BOOST_REQUIRE_THROW(p->getCategory(0), std::exception); } BOOST_AUTO_TEST_CASE( getCategory ) { - auto cat = p->getCategory(316, Ice::Current()); + auto cat = p->getCategory(316); BOOST_REQUIRE(cat); BOOST_REQUIRE_EQUAL(316, cat->categoryid); BOOST_REQUIRE_EQUAL("app-backup", cat->name); @@ -44,7 +25,7 @@ BOOST_AUTO_TEST_CASE( getCategory ) BOOST_AUTO_TEST_CASE( getAllCategories ) { - auto cats = p->getAllCategories(Ice::Current()); + auto cats = p->getAllCategories(); BOOST_REQUIRE_EQUAL(5, cats.size()); BOOST_REQUIRE_EQUAL(316, cats.front()->categoryid); BOOST_REQUIRE_EQUAL(313, cats.back()->categoryid); @@ -54,38 +35,38 @@ BOOST_AUTO_TEST_CASE( getAllCategories ) BOOST_AUTO_TEST_CASE( getCategoriesInSuper ) { - auto cats = p->getCategoriesInSuper("dev", Ice::Current()); + auto cats = p->getCategoriesInSuper("dev"); BOOST_REQUIRE_EQUAL(2, cats.size()); BOOST_REQUIRE_EQUAL("dev-ml", cats.front()->name); BOOST_REQUIRE_EQUAL("dev-vcs", cats.back()->name); - cats = p->getCategoriesInSuper("net", Ice::Current()); + cats = p->getCategoriesInSuper("net"); BOOST_REQUIRE_EQUAL(1, cats.size()); - cats = p->getCategoriesInSuper("sys", Ice::Current()); + cats = p->getCategoriesInSuper("sys"); BOOST_REQUIRE_EQUAL(0, cats.size()); } BOOST_AUTO_TEST_CASE( getOverviewCategoriesInSuper ) { - auto cats = p->getOverviewCategoriesInSuper("dev", Ice::Current()); + auto cats = p->getOverviewCategoriesInSuper("dev"); BOOST_REQUIRE_EQUAL(2, cats.size()); BOOST_REQUIRE_EQUAL("dev-ml", cats.front()->name); BOOST_REQUIRE_EQUAL("dev-vcs", cats.back()->name); BOOST_REQUIRE_EQUAL(136, cats.front()->packagecount); BOOST_REQUIRE_EQUAL(88, cats.back()->packagecount); - cats = p->getOverviewCategoriesInSuper("net", Ice::Current()); + cats = p->getOverviewCategoriesInSuper("net"); BOOST_REQUIRE_EQUAL(1, cats.size()); - cats = p->getOverviewCategoriesInSuper("sys", Ice::Current()); + cats = p->getOverviewCategoriesInSuper("sys"); BOOST_REQUIRE_EQUAL(0, cats.size()); } BOOST_AUTO_TEST_CASE( getPackageMissing ) { - BOOST_REQUIRE_THROW(p->getPackage(0, Ice::Current()), std::exception); + BOOST_REQUIRE_THROW(p->getPackage(0), std::exception); } BOOST_AUTO_TEST_CASE( getPackage ) { - auto pkg = p->getPackage(53258, Ice::Current()); + auto pkg = p->getPackage(53258); BOOST_REQUIRE(pkg); BOOST_REQUIRE_EQUAL(53258, pkg->packageid); BOOST_REQUIRE_EQUAL(311, pkg->categoryid); @@ -99,20 +80,20 @@ BOOST_AUTO_TEST_CASE( getPackage ) BOOST_AUTO_TEST_CASE( findPackage ) { - auto cat = p->findPackage("not", "here", Ice::Current()); + auto cat = p->findPackage("not", "here"); BOOST_REQUIRE(!cat); } BOOST_AUTO_TEST_CASE( findPackageMissing ) { - auto pkg = p->findPackage("dev-vcs", "archway", Ice::Current()); + auto pkg = p->findPackage("dev-vcs", "archway"); BOOST_REQUIRE(pkg); BOOST_REQUIRE_EQUAL(53258, (*pkg)->packageid); } BOOST_AUTO_TEST_CASE( getPackagesInCategory ) { - auto pkgs = p->getPackagesInCategory(311, Ice::Current()); + auto pkgs = p->getPackagesInCategory(311); BOOST_REQUIRE_EQUAL(88, pkgs.size()); BOOST_REQUIRE_EQUAL("archway", pkgs.front()->name); BOOST_REQUIRE_EQUAL("veracity", pkgs.back()->name); @@ -120,13 +101,13 @@ BOOST_AUTO_TEST_CASE( getPackagesInCategory ) BOOST_AUTO_TEST_CASE( searchEmpty ) { - auto matches = p->getPackagesSearch("", Ice::Current()); + auto matches = p->getPackagesSearch(""); BOOST_REQUIRE(matches.empty()); } BOOST_AUTO_TEST_CASE( search ) { - auto matches = p->getPackagesSearch("git", Ice::Current()); + auto matches = p->getPackagesSearch("git"); BOOST_REQUIRE_EQUAL(40, matches.size()); BOOST_REQUIRE_EQUAL(58252, matches.front()->packageid); BOOST_REQUIRE_CLOSE(0.72, matches.front()->rank, 1.0); @@ -134,7 +115,7 @@ BOOST_AUTO_TEST_CASE( search ) BOOST_AUTO_TEST_CASE( searchNotFound ) { - auto matches = p->getPackagesSearch("something that doesn't exist", Ice::Current()); + auto matches = p->getPackagesSearch("something that doesn't exist"); BOOST_REQUIRE(matches.empty()); } @@ -259,22 +240,5 @@ BOOST_AUTO_TEST_CASE( getNewsRecent ) BOOST_REQUIRE_EQUAL("2015-10-07T00:00:00", ns.back()->posted); } -BOOST_AUTO_TEST_CASE( cache ) -{ - auto c1 = p->getCategory(311, Ice::Current()); - BOOST_REQUIRE(c1); - BOOST_REQUIRE_EQUAL(311, c1->categoryid); - auto c2 = p->getCategory(311, Ice::Current()); - BOOST_REQUIRE(c2); - BOOST_REQUIRE_EQUAL(311, c2->categoryid); - BOOST_REQUIRE_EQUAL(c1.get(), c2.get()); - auto c3 = p->getCategory(316, Ice::Current()); - BOOST_REQUIRE(c3); - BOOST_REQUIRE_EQUAL(316, c3->categoryid); - BOOST_REQUIRE(c1.get() != c3.get()); - BOOST_REQUIRE_EQUAL(311, c1->categoryid); - BOOST_REQUIRE_EQUAL(311, c2->categoryid); -} - BOOST_AUTO_TEST_SUITE_END(); |