-
-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
backend: update proto and add camera
- Loading branch information
1 parent
1ae7eb1
commit e2184d9
Showing
11 changed files
with
149 additions
and
11 deletions.
There are no files selected for viewing
Submodule proto
updated
from 72834b to f2e8b2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#include "camera/camera.h" | ||
#include "camera/camera.grpc.pb.h" | ||
|
||
namespace dronecore { | ||
namespace backend { | ||
|
||
template <typename Camera = Camera> | ||
class CameraServiceImpl final : public rpc::camera::CameraService::Service | ||
{ | ||
public: | ||
CameraServiceImpl(Camera &camera) | ||
: _camera(camera) {} | ||
|
||
grpc::Status TakePhoto(grpc::ServerContext * /* context */, | ||
const rpc::camera::TakePhotoRequest * /* request */, | ||
rpc::camera::TakePhotoResponse *response) override | ||
{ | ||
auto camera_result = _camera.take_photo(); | ||
|
||
if (response != nullptr) { | ||
fillResponseWithResult(response, camera_result); | ||
} | ||
|
||
return grpc::Status::OK; | ||
} | ||
|
||
template <typename ResponseType> | ||
void fillResponseWithResult(ResponseType *response, dronecore::Camera::Result &camera_result) const | ||
{ | ||
auto rpc_result = static_cast<rpc::camera::CameraResult::Result>(camera_result); | ||
|
||
auto *rpc_camera_result = new rpc::camera::CameraResult(); | ||
rpc_camera_result->set_result(rpc_result); | ||
rpc_camera_result->set_result_str(dronecore::Camera::result_str(camera_result)); | ||
|
||
response->set_allocated_camera_result(rpc_camera_result); | ||
} | ||
|
||
private: | ||
Camera &_camera; | ||
}; | ||
|
||
} // namespace backend | ||
} // namespace dronecore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include <gmock/gmock.h> | ||
|
||
#include "camera/camera_service_impl.h" | ||
#include "camera/mocks/camera_mock.h" | ||
|
||
namespace { | ||
|
||
using testing::NiceMock; | ||
using testing::Return; | ||
|
||
using MockCamera = NiceMock<dronecore::testing::MockCamera>; | ||
using CameraServiceImpl = dronecore::backend::CameraServiceImpl<MockCamera>; | ||
|
||
using CameraResult = dronecore::rpc::camera::CameraResult; | ||
using InputPair = std::pair<std::string, dronecore::Camera::Result>; | ||
|
||
std::vector<InputPair> generateInputPairs(); | ||
|
||
class CameraServiceImplTest : public ::testing::TestWithParam<InputPair> | ||
{ | ||
protected: | ||
CameraServiceImplTest() | ||
: _camera_service(_camera) {} | ||
|
||
MockCamera _camera; | ||
CameraServiceImpl _camera_service; | ||
}; | ||
|
||
TEST_P(CameraServiceImplTest, takePhotoResultIsTranslatedCorrectly) | ||
{ | ||
ON_CALL(_camera, take_photo()) | ||
.WillByDefault(Return(GetParam().second)); | ||
dronecore::rpc::camera::TakePhotoResponse response; | ||
|
||
_camera_service.TakePhoto(nullptr, nullptr, &response); | ||
|
||
EXPECT_EQ(GetParam().first, CameraResult::Result_Name(response.camera_result().result())); | ||
} | ||
|
||
TEST_F(CameraServiceImplTest, takesPhotoEvenWhenArgsAreNull) | ||
{ | ||
EXPECT_CALL(_camera, take_photo()) | ||
.Times(1); | ||
|
||
_camera_service.TakePhoto(nullptr, nullptr, nullptr); | ||
} | ||
|
||
INSTANTIATE_TEST_CASE_P(CameraResultCorrespondences, | ||
CameraServiceImplTest, | ||
::testing::ValuesIn(generateInputPairs())); | ||
|
||
std::vector<InputPair> generateInputPairs() | ||
{ | ||
std::vector<InputPair> input_pairs; | ||
input_pairs.push_back(std::make_pair("SUCCESS", dronecore::Camera::Result::SUCCESS)); | ||
input_pairs.push_back(std::make_pair("IN_PROGRESS", | ||
dronecore::Camera::Result::IN_PROGRESS)); | ||
input_pairs.push_back(std::make_pair("BUSY", dronecore::Camera::Result::BUSY)); | ||
input_pairs.push_back(std::make_pair("DENIED", dronecore::Camera::Result::DENIED)); | ||
input_pairs.push_back(std::make_pair("ERROR", | ||
dronecore::Camera::Result::ERROR)); | ||
input_pairs.push_back(std::make_pair("TIMEOUT", dronecore::Camera::Result::TIMEOUT)); | ||
input_pairs.push_back(std::make_pair("WRONG_ARGUMENT", | ||
dronecore::Camera::Result::WRONG_ARGUMENT)); | ||
input_pairs.push_back(std::make_pair("UNKNOWN", dronecore::Camera::Result::UNKNOWN)); | ||
|
||
return input_pairs; | ||
} | ||
|
||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <gmock/gmock.h> | ||
|
||
#include "camera/camera.h" | ||
|
||
namespace dronecore { | ||
namespace testing { | ||
|
||
class MockCamera | ||
{ | ||
public: | ||
MOCK_CONST_METHOD0(take_photo, Camera::Result()); | ||
}; | ||
|
||
} // namespace testing | ||
} // namespace dronecore |