-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
946 additions
and
281 deletions.
There are no files selected for viewing
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
Submodule proto
updated
from b609b0 to d117c0
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,47 @@ | ||
#include "plugins/info/info.h" | ||
#include "info/info.grpc.pb.h" | ||
|
||
namespace dronecode_sdk { | ||
namespace backend { | ||
|
||
template<typename Info = Info> | ||
class InfoServiceImpl final : public rpc::info::InfoService::Service { | ||
public: | ||
InfoServiceImpl(Info &info) : _info(info) {} | ||
|
||
grpc::Status GetVersion(grpc::ServerContext * /* context */, | ||
const rpc::info::GetVersionRequest * /* request */, | ||
rpc::info::GetVersionResponse *response) override | ||
{ | ||
if (response != nullptr) { | ||
auto result_pair = _info.get_version(); | ||
|
||
auto *rpc_info_result = new rpc::info::InfoResult(); | ||
rpc_info_result->set_result( | ||
static_cast<rpc::info::InfoResult::Result>(result_pair.first)); | ||
rpc_info_result->set_result_str(dronecode_sdk::Info::result_str(result_pair.first)); | ||
|
||
auto *rpc_version = new rpc::info::Version(); | ||
rpc_version->set_flight_sw_major(result_pair.second.flight_sw_major); | ||
rpc_version->set_flight_sw_minor(result_pair.second.flight_sw_minor); | ||
rpc_version->set_flight_sw_patch(result_pair.second.flight_sw_patch); | ||
rpc_version->set_flight_sw_vendor_major(result_pair.second.flight_sw_vendor_major); | ||
rpc_version->set_flight_sw_vendor_minor(result_pair.second.flight_sw_vendor_minor); | ||
rpc_version->set_flight_sw_vendor_patch(result_pair.second.flight_sw_vendor_patch); | ||
rpc_version->set_os_sw_major(result_pair.second.os_sw_major); | ||
rpc_version->set_os_sw_minor(result_pair.second.os_sw_minor); | ||
rpc_version->set_os_sw_patch(result_pair.second.os_sw_patch); | ||
|
||
response->set_allocated_info_result(rpc_info_result); | ||
response->set_allocated_version(rpc_version); | ||
} | ||
|
||
return grpc::Status::OK; | ||
} | ||
|
||
private: | ||
Info &_info; | ||
}; | ||
|
||
} // namespace backend | ||
} // namespace dronecode_sdk |
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,108 @@ | ||
#include <gmock/gmock.h> | ||
#include <string> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "info/info_service_impl.h" | ||
#include "info/mocks/info_mock.h" | ||
|
||
namespace { | ||
|
||
using testing::_; | ||
using testing::NiceMock; | ||
using testing::Return; | ||
|
||
using MockInfo = NiceMock<dronecode_sdk::testing::MockInfo>; | ||
using InfoServiceImpl = dronecode_sdk::backend::InfoServiceImpl<MockInfo>; | ||
|
||
using InfoResult = dronecode_sdk::rpc::info::InfoResult; | ||
using InputPair = std::pair<std::string, dronecode_sdk::Info::Result>; | ||
|
||
static constexpr int ARBITRARY_SW_VERSION_MAJOR = 1; | ||
static constexpr int ARBITRARY_SW_VERSION_MINOR = 2; | ||
static constexpr int ARBITRARY_SW_VERSION_PATCH = 3; | ||
|
||
static constexpr int ARBITRARY_SW_VERSION_VENDOR_MAJOR = 1; | ||
static constexpr int ARBITRARY_SW_VERSION_VENDOR_MINOR = 2; | ||
static constexpr int ARBITRARY_SW_VERSION_VENDOR_PATCH = 3; | ||
|
||
static constexpr int ARBITRARY_SW_VERSION_OS_MAJOR = 4; | ||
static constexpr int ARBITRARY_SW_VERSION_OS_MINOR = 5; | ||
static constexpr int ARBITRARY_SW_VERSION_OS_PATCH = 6; | ||
|
||
std::vector<InputPair> generateInputPairs(); | ||
|
||
class InfoServiceImplTest : public ::testing::TestWithParam<InputPair> {}; | ||
|
||
TEST_F(InfoServiceImplTest, getVersionCallsGetter) | ||
{ | ||
MockInfo info; | ||
InfoServiceImpl infoService(info); | ||
EXPECT_CALL(info, get_version()).Times(1); | ||
dronecode_sdk::rpc::info::GetVersionResponse response; | ||
|
||
infoService.GetVersion(nullptr, nullptr, &response); | ||
} | ||
|
||
TEST_P(InfoServiceImplTest, getsCorrectVersion) | ||
{ | ||
MockInfo info; | ||
InfoServiceImpl infoService(info); | ||
|
||
dronecode_sdk::Info::Version arbitrary_version; | ||
|
||
arbitrary_version.flight_sw_major = ARBITRARY_SW_VERSION_MAJOR; | ||
arbitrary_version.flight_sw_minor = ARBITRARY_SW_VERSION_MINOR; | ||
arbitrary_version.flight_sw_patch = ARBITRARY_SW_VERSION_PATCH; | ||
arbitrary_version.flight_sw_vendor_major = ARBITRARY_SW_VERSION_VENDOR_MAJOR; | ||
arbitrary_version.flight_sw_vendor_minor = ARBITRARY_SW_VERSION_VENDOR_MINOR; | ||
arbitrary_version.flight_sw_vendor_patch = ARBITRARY_SW_VERSION_VENDOR_PATCH; | ||
arbitrary_version.os_sw_major = ARBITRARY_SW_VERSION_OS_MAJOR; | ||
arbitrary_version.os_sw_minor = ARBITRARY_SW_VERSION_OS_MINOR; | ||
arbitrary_version.os_sw_patch = ARBITRARY_SW_VERSION_OS_PATCH; | ||
|
||
const auto expected_pair = std::make_pair<>(GetParam().second, arbitrary_version); | ||
ON_CALL(info, get_version()).WillByDefault(Return(expected_pair)); | ||
dronecode_sdk::rpc::info::GetVersionResponse response; | ||
|
||
infoService.GetVersion(nullptr, nullptr, &response); | ||
|
||
EXPECT_EQ(GetParam().first, InfoResult::Result_Name(response.info_result().result())); | ||
EXPECT_EQ(expected_pair.second.flight_sw_major, response.version().flight_sw_major()); | ||
EXPECT_EQ(expected_pair.second.flight_sw_minor, response.version().flight_sw_minor()); | ||
EXPECT_EQ(expected_pair.second.flight_sw_patch, response.version().flight_sw_patch()); | ||
EXPECT_EQ(expected_pair.second.flight_sw_vendor_major, | ||
response.version().flight_sw_vendor_major()); | ||
EXPECT_EQ(expected_pair.second.flight_sw_vendor_minor, | ||
response.version().flight_sw_vendor_minor()); | ||
EXPECT_EQ(expected_pair.second.flight_sw_vendor_patch, | ||
response.version().flight_sw_vendor_patch()); | ||
EXPECT_EQ(expected_pair.second.os_sw_major, response.version().os_sw_major()); | ||
EXPECT_EQ(expected_pair.second.os_sw_minor, response.version().os_sw_minor()); | ||
EXPECT_EQ(expected_pair.second.os_sw_patch, response.version().os_sw_patch()); | ||
} | ||
|
||
TEST_F(InfoServiceImplTest, getVersionDoesNotCrashWithNullResponse) | ||
{ | ||
MockInfo info; | ||
InfoServiceImpl infoService(info); | ||
|
||
infoService.GetVersion(nullptr, nullptr, nullptr); | ||
} | ||
|
||
INSTANTIATE_TEST_CASE_P(InfoResultCorrespondences, | ||
InfoServiceImplTest, | ||
::testing::ValuesIn(generateInputPairs())); | ||
|
||
std::vector<InputPair> generateInputPairs() | ||
{ | ||
std::vector<InputPair> input_pairs; | ||
input_pairs.push_back(std::make_pair("SUCCESS", dronecode_sdk::Info::Result::SUCCESS)); | ||
input_pairs.push_back(std::make_pair( | ||
"INFORMATION_NOT_RECEIVED_YET", dronecode_sdk::Info::Result::INFORMATION_NOT_RECEIVED_YET)); | ||
input_pairs.push_back(std::make_pair("UNKNOWN", dronecode_sdk::Info::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
Oops, something went wrong.