Skip to content

Commit

Permalink
Restore unit tests (badly merge)
Browse files Browse the repository at this point in the history
  • Loading branch information
jano42 committed Jan 4, 2021
1 parent a40fd77 commit 40f070a
Show file tree
Hide file tree
Showing 7 changed files with 266 additions and 43 deletions.
33 changes: 15 additions & 18 deletions tests/unit/sources/plugins/OrangeBusiness/urlManagerMock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
#include "urlManagerMock.h"

urlManagerMock::urlManagerMock()
: RegisteredEquipments(shared::CDataContainer::make()),
DeviceInformation(shared::CDataContainer::make()),
DeviceMessages(shared::CDataContainer::make())
: RegisteredEquipments(shared::CDataContainer::make()),
DeviceInformation(shared::CDataContainer::make()),
DeviceMessages(shared::CDataContainer::make())
{
}

boost::shared_ptr<shared::CDataContainer> urlManagerMock::getRegisteredEquipments(
const std::string& apikey,
const int page,
const bool activated,
int timeoutSeconds)
boost::shared_ptr<shared::CDataContainer> urlManagerMock::getRegisteredEquipments(const std::string &apikey,
const int page,
const bool activated,
const boost::posix_time::time_duration& timeout)
{
return boost::make_shared<shared::CDataContainer>();
}
Expand All @@ -27,19 +26,17 @@ void urlManagerMock::addMessagesForEquipment(boost::shared_ptr<shared::CDataCont
DeviceMessages = newMessage;
}

boost::shared_ptr<shared::CDataContainer> urlManagerMock::getDeviceInformation(
const std::string& apikey,
const std::string& devEUI,
int timeoutSeconds)
boost::shared_ptr<shared::CDataContainer> urlManagerMock::getDeviceInformation(const std::string &apikey,
const std::string &devEUI,
const boost::posix_time::time_duration& timeout)
{
return RegisteredEquipments;
}

boost::shared_ptr<shared::CDataContainer> urlManagerMock::listDeviceCommands(
const std::string& apikey,
const std::string& devEUI,
const int page,
int timeoutSeconds)
boost::shared_ptr<shared::CDataContainer> urlManagerMock::listDeviceCommands(const std::string &apikey,
const std::string &devEUI,
const int page,
const boost::posix_time::time_duration& timeout)
{
return DeviceMessages;
}
}
35 changes: 16 additions & 19 deletions tests/unit/sources/plugins/OrangeBusiness/urlManagerMock.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,45 +20,42 @@ class urlManagerMock : public IurlManager
/// \brief get all equipments from the website
/// \param[in] apikey the apiKey to access the web site
/// \param[in] page the page of 20 equipments we want to read
/// \param[in] activated true, if we want to retrieve only activated equipments
/// \param[in] timeoutSeconds optional, the timeout (seconds) of the request
/// \param[in] activated true, if we want to retreive only activated equipments
/// \param[in] timeout optional, the timeout of the request
/// \return the json response
//--------------------------------------------------------------
boost::shared_ptr<shared::CDataContainer> getRegisteredEquipments(
const std::string& apikey,
int page,
bool activated,
int timeoutSeconds = shared::http::CHttpMethods::HttpRequestDefaultTimeoutSeconds) override;
boost::shared_ptr<shared::CDataContainer> getRegisteredEquipments(const std::string &apikey,
const int page,
const bool activated,
const boost::posix_time::time_duration& timeout = shared::HttpRequestDefaultTimeout);

//--------------------------------------------------------------
/// \brief get information from a specific device
/// \param[in] apikey the apiKey to access the web site
/// \param[in] devEUI the device unique ID
/// \param[in] timeoutSeconds optional, the timeout (seconds) of the request
/// \param[in] timeout optional, the timeout of the request
/// \return the json response
//--------------------------------------------------------------
boost::shared_ptr<shared::CDataContainer> getDeviceInformation(
const std::string& apikey,
const std::string& devEUI,
int timeoutSeconds = shared::http::CHttpMethods::HttpRequestDefaultTimeoutSeconds) override;
boost::shared_ptr<shared::CDataContainer> getDeviceInformation(const std::string &apikey,
const std::string &devEUI,
const boost::posix_time::time_duration& timeout = shared::HttpRequestDefaultTimeout);

//--------------------------------------------------------------
/// \brief list command information
/// \param[in] apikey the apiKey to access the web site
/// \param[in] devEUI the device unique ID
/// \param[in] timeoutSeconds optional, the timeout (seconds) of the request
/// \param[in] timeout optional, the timeout of the request
/// \return the json response
//--------------------------------------------------------------
boost::shared_ptr<shared::CDataContainer> listDeviceCommands(
const std::string& apikey,
const std::string& devEUI,
int page,
int timeoutSeconds = shared::http::CHttpMethods::HttpRequestDefaultTimeoutSeconds) override;
boost::shared_ptr<shared::CDataContainer> listDeviceCommands(const std::string &apikey,
const std::string &devEUI,
const int page,
const boost::posix_time::time_duration& timeout = shared::HttpRequestDefaultTimeout);

private:

// All simulated messages
boost::shared_ptr<shared::CDataContainer> RegisteredEquipments;
boost::shared_ptr<shared::CDataContainer> DeviceInformation;
boost::shared_ptr<shared::CDataContainer> DeviceMessages;
};
};
10 changes: 5 additions & 5 deletions tests/unit/sources/shared/event/TestEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ BOOST_AUTO_TEST_CASE(EventWithBadData)
BOOST_CHECK_EQUAL(evtHandler.waitForEvents(boost::date_time::min_date_time), idEvent);

BOOST_CHECK(!evtHandler.isEventType<CEventData>());
BOOST_REQUIRE_THROW(evtHandler.getEventData<CEventData>(), std::bad_cast);
BOOST_REQUIRE_THROW(evtHandler.getEventData<CEventData>(), shared::exception::CBadConversion);

BOOST_CHECK(evtHandler.isEventType<std::string>());
BOOST_REQUIRE_NO_THROW(evtHandler.getEventData<std::string>());
Expand All @@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(EventWithBadData)
BOOST_CHECK_EQUAL(evtHandler.waitForEvents(boost::date_time::min_date_time), idEvent);

BOOST_CHECK(!evtHandler.isEventType<CEventData>());
BOOST_REQUIRE_THROW(evtHandler.getEventData<CEventData>(), std::bad_cast);
BOOST_REQUIRE_THROW(evtHandler.getEventData<CEventData>(), shared::exception::CBadConversion);
}

//--------------------------------------------------------------
Expand Down Expand Up @@ -322,12 +322,12 @@ BOOST_AUTO_TEST_CASE(EventIdGetter)
{
shared::event::CEventHandler evtHandler;

BOOST_REQUIRE_THROW(evtHandler.getEventId(), std::runtime_error);
BOOST_REQUIRE_THROW(evtHandler.getEventId(), shared::exception::CNullReference);

evtHandler.postEvent(idEvent);
evtHandler.postEvent(idEvent + 1, CEventData(42, "Yadoms test"));

BOOST_REQUIRE_THROW(evtHandler.getEventId(), std::runtime_error);
BOOST_REQUIRE_THROW(evtHandler.getEventId(), shared::exception::CNullReference);

BOOST_CHECK_EQUAL(evtHandler.waitForEvents(boost::date_time::min_date_time), idEvent);
BOOST_CHECK_EQUAL(evtHandler.getEventId(), idEvent);
Expand All @@ -337,7 +337,7 @@ BOOST_AUTO_TEST_CASE(EventIdGetter)
BOOST_CHECK_EQUAL(evtHandler.getEventId(), idEvent + 1); // Can be called several times

BOOST_CHECK_EQUAL(evtHandler.waitForEvents(boost::date_time::min_date_time), shared::event::kNoEvent);
BOOST_REQUIRE_THROW(evtHandler.getEventId(), std::runtime_error);
BOOST_REQUIRE_THROW(evtHandler.getEventId(), shared::exception::CNullReference);
}

//--------------------------------------------------------------
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/sources/shared/event/TestTimePoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <boost/test/unit_test.hpp>

// Includes needed to compile tested classes
#include "../../../../sources/shared/shared/exception/InvalidParameter.hpp"
#include "../../../../sources/shared/shared/event/EventTimePoint.h"
#include "../../../../sources/shared/shared/event/EventHandler.hpp"

Expand Down Expand Up @@ -74,7 +75,7 @@ BOOST_AUTO_TEST_SUITE(TestTimePoint)
useTimeMock();
const auto timePoint(shared::currentTime::Provider().now() - boost::posix_time::seconds(3));
const auto evtId = 123456;
BOOST_REQUIRE_THROW(shared::event::CEventTimePoint timer(evtId, timePoint), std::invalid_argument);
BOOST_REQUIRE_THROW(shared::event::CEventTimePoint timer(evtId, timePoint), shared::exception::CInvalidParameter);
}

//--------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/sources/shared/http/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# List subdirectories here
add_subdirectory(ssdp)



set (YADOMS_TESTS_SRC ${YADOMS_TESTS_SRC} PARENT_SCOPE)
12 changes: 12 additions & 0 deletions tests/unit/sources/shared/http/ssdp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#dd current directory tests
IF(NOT DISABLE_TEST_HTTP_SSDP)
ADD_YADOMS_SOURCES(
shared/shared/http/ssdp/DiscoveredDevice.h
shared/shared/http/ssdp/DiscoveredDevice.cpp
)
ADD_SOURCES(TestDiscoveredDevice.cpp)

ENDIF()


set (YADOMS_TESTS_SRC ${YADOMS_TESTS_SRC} PARENT_SCOPE)
Loading

0 comments on commit 40f070a

Please sign in to comment.