summaryrefslogtreecommitdiff
path: root/site/test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'site/test.cpp')
-rw-r--r--site/test.cpp99
1 files changed, 48 insertions, 51 deletions
diff --git a/site/test.cpp b/site/test.cpp
index 4cd9763..bcff64b 100644
--- a/site/test.cpp
+++ b/site/test.cpp
@@ -1,68 +1,66 @@
#define BOOST_TEST_MODULE mirrorsearchsite
#include <boost/test/unit_test.hpp>
-#include <testRequest.h>
-#include <core.h>
#include <api.h>
+#include <core.h>
+#include <testRequest.h>
-#include <Ice/ObjectAdapter.h>
#include <Ice/Initialize.h>
+#include <Ice/ObjectAdapter.h>
using namespace IceSpider;
using namespace MirrorSearch;
class TestSerice : public Search {
- public:
- virtual SearchServices getServices(const ::Ice::Current& = ::Ice::Current()) override
- {
- return {};
+public:
+ virtual SearchServices
+ getServices(const ::Ice::Current & = ::Ice::Current()) override
+ {
+ return {};
+ }
+ virtual SearchHits
+ getMatches(const ::std::string fn, const ::Ice::Current & = ::Ice::Current()) override
+ {
+ BOOST_TEST_INFO(fn);
+ if (fn == "good.txt") {
+ return {std::make_shared<SearchHit>(1, 1, "file:///some/file/path"),
+ std::make_shared<SearchHit>(1, 1, "file:///some/other/path")};
}
- virtual SearchHits getMatches(const ::std::string fn, const ::Ice::Current& = ::Ice::Current()) override
- {
- BOOST_TEST_INFO(fn);
- if (fn == "good.txt") {
- return {
- std::make_shared<SearchHit>(1, 1, "file:///some/file/path"),
- std::make_shared<SearchHit>(1, 1, "file:///some/other/path")
- };
- }
- return {};
- }
- virtual ::Ice::optional<::std::string> feelingLucky(const ::std::string fn, const ::Ice::Current & c = ::Ice::Current()) override
- {
- auto ms = getMatches(fn, c);
- if (ms.empty()) {
- return IceUtil::None;
-
- }
- return ms.front()->url;
+ return {};
+ }
+ virtual ::Ice::optional<::std::string>
+ feelingLucky(const ::std::string fn, const ::Ice::Current & c = ::Ice::Current()) override
+ {
+ auto ms = getMatches(fn, c);
+ if (ms.empty()) {
+ return IceUtil::None;
}
+ return ms.front()->url;
+ }
};
class TestApp : public CoreWithDefaultRouter {
- public:
- TestApp() :
- CoreWithDefaultRouter({
- "--MirrorSearch.Search=Search"
- }),
- adp(communicator->createObjectAdapterWithEndpoints("test", "default"))
- {
- adp->activate();
- adp->add(std::make_shared<TestSerice>(), Ice::stringToIdentity("Search"));
- }
-
- ~TestApp()
- {
- adp->deactivate();
- adp->destroy();
- }
-
- Ice::ObjectAdapterPtr adp;
+public:
+ TestApp() :
+ CoreWithDefaultRouter({"--MirrorSearch.Search=Search"}),
+ adp(communicator->createObjectAdapterWithEndpoints("test", "default"))
+ {
+ adp->activate();
+ adp->add(std::make_shared<TestSerice>(), Ice::stringToIdentity("Search"));
+ }
+
+ ~TestApp()
+ {
+ adp->deactivate();
+ adp->destroy();
+ }
+
+ Ice::ObjectAdapterPtr adp;
};
BOOST_FIXTURE_TEST_SUITE(ta, TestApp);
-BOOST_AUTO_TEST_CASE( testCallIndexNoFile )
+BOOST_AUTO_TEST_CASE(testCallIndexNoFile)
{
TestRequest requestGetIndex(this, HttpMethod::GET, "/list");
process(&requestGetIndex);
@@ -70,7 +68,7 @@ BOOST_AUTO_TEST_CASE( testCallIndexNoFile )
BOOST_CHECK_EQUAL(h["Status"], "404 Not found");
}
-BOOST_AUTO_TEST_CASE( testCallServiceList )
+BOOST_AUTO_TEST_CASE(testCallServiceList)
{
TestRequest requestGetIndex(this, HttpMethod::GET, "/services");
process(&requestGetIndex);
@@ -79,7 +77,7 @@ BOOST_AUTO_TEST_CASE( testCallServiceList )
BOOST_CHECK_EQUAL(h["Content-Type"], "application/json");
}
-BOOST_AUTO_TEST_CASE( testCallIndex )
+BOOST_AUTO_TEST_CASE(testCallIndex)
{
TestRequest requestGetIndex(this, HttpMethod::GET, "/list/somefile.txt");
process(&requestGetIndex);
@@ -88,7 +86,7 @@ BOOST_AUTO_TEST_CASE( testCallIndex )
BOOST_CHECK_EQUAL(h["Content-Type"], "application/json");
}
-BOOST_AUTO_TEST_CASE( testCallDownloadNotFile )
+BOOST_AUTO_TEST_CASE(testCallDownloadNotFile)
{
TestRequest requestGetIndex(this, HttpMethod::GET, "/download");
process(&requestGetIndex);
@@ -96,7 +94,7 @@ BOOST_AUTO_TEST_CASE( testCallDownloadNotFile )
BOOST_CHECK_EQUAL(h["Status"], "404 Not found");
}
-BOOST_AUTO_TEST_CASE( testCallDownloadBad )
+BOOST_AUTO_TEST_CASE(testCallDownloadBad)
{
TestRequest requestGetIndex(this, HttpMethod::GET, "/download/bad.txt");
process(&requestGetIndex);
@@ -104,7 +102,7 @@ BOOST_AUTO_TEST_CASE( testCallDownloadBad )
BOOST_CHECK_EQUAL(h["Status"], "404 No mirror found");
}
-BOOST_AUTO_TEST_CASE( testCallDownloadGood )
+BOOST_AUTO_TEST_CASE(testCallDownloadGood)
{
TestRequest requestGetIndex(this, HttpMethod::GET, "/download/good.txt");
process(&requestGetIndex);
@@ -114,4 +112,3 @@ BOOST_AUTO_TEST_CASE( testCallDownloadGood )
}
BOOST_AUTO_TEST_SUITE_END();
-