Commit 13b1a65b authored by Matthieu Kermagoret's avatar Matthieu Kermagoret
Browse files

Connector SSH: moved check_result to checks::result.

parent 6d39c2ed
......@@ -123,7 +123,7 @@ set(CONNECTORLIB "centreonconnectorssh")
add_library("${CONNECTORLIB}"
# Sources.
# "${SRC_DIR}/channel.cc"
"${SRC_DIR}/check_result.cc"
"${SRC_DIR}/checks/result.cc"
# "${SRC_DIR}/commander.cc"
# "${SRC_DIR}/credentials.cc"
"${SRC_DIR}/multiplexer.cc"
......@@ -134,7 +134,7 @@ add_library("${CONNECTORLIB}"
# "${SRC_DIR}/socket_handle.cc"
# Headers.
# "${INC_DIR}/channel.hh"
"${INC_DIR}/check_result.hh"
"${INC_DIR}/checks/result.hh"
# "${INC_DIR}/commander.hh"
# "${INC_DIR}/credentials.hh"
"${INC_DIR}/multiplexer.hh"
......@@ -172,53 +172,54 @@ if (WITH_TESTING)
set(BUILD_UNIT_TEST "Yes")
include_directories("${PROJECT_SOURCE_DIR}")
# check_result tests.
# checks namespace tests.
# result tests.
# Default constructor.
set(TEST_NAME "check_result_ctor_default")
set(TEST_NAME "checks_result_ctor_default")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/ctor_default.cc")
"${TEST_DIR}/checks/result/ctor_default.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Command ID property.
set(TEST_NAME "check_result_command_id")
set(TEST_NAME "checks_result_command_id")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/command_id.cc")
"${TEST_DIR}/checks/result/command_id.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Error property.
set(TEST_NAME "check_result_error")
set(TEST_NAME "checks_result_error")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/error.cc")
"${TEST_DIR}/checks/result/error.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Executed
set(TEST_NAME "check_result_executed")
set(TEST_NAME "checks_result_executed")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/executed.cc")
"${TEST_DIR}/checks/result/executed.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Exit code property.
set(TEST_NAME "check_result_exit_code")
set(TEST_NAME "checks_result_exit_code")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/exit_code.cc")
"${TEST_DIR}/checks/result/exit_code.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Output property.
set(TEST_NAME "check_result_output")
set(TEST_NAME "checks_result_output")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/output.cc")
"${TEST_DIR}/checks/result/output.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Copy constructor.
set(TEST_NAME "check_result_ctor_copy")
set(TEST_NAME "checks_result_ctor_copy")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/ctor_copy.cc")
"${TEST_DIR}/checks/result/ctor_copy.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Assignment operator.
set(TEST_NAME "check_result_assignment")
set(TEST_NAME "checks_result_assignment")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/assignment.cc")
"${TEST_DIR}/checks/result/assignment.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
......
......@@ -18,47 +18,49 @@
** <http://www.gnu.org/licenses/>.
*/
#ifndef CCCS_CHECK_RESULT_HH
# define CCCS_CHECK_RESULT_HH
#ifndef CCCS_CHECKS_RESULT_HH
# define CCCS_CHECKS_RESULT_HH
# include <string>
# include "com/centreon/connector/ssh/namespace.hh"
CCCS_BEGIN()
/**
* @class check_result check_result.hh "com/centreon/connector/ssh/check_result.hh"
* @brief Check result.
*
* Store check result.
*/
class check_result {
public:
check_result();
check_result(check_result const& cr);
~check_result();
check_result& operator=(check_result const& cr);
unsigned long long get_command_id() const throw ();
std::string const& get_error() const throw ();
bool get_executed() const throw ();
int get_exit_code() const throw ();
std::string const& get_output() const throw ();
void set_command_id(unsigned long long cmd_id) throw ();
void set_error(std::string const& error);
void set_executed(bool executed) throw ();
void set_exit_code(int code) throw ();
void set_output(std::string const& output);
namespace checks {
/**
* @class result result.hh "com/centreon/connector/ssh/checks/result.hh"
* @brief Check result.
*
* Store check result.
*/
class result {
public:
result();
result(result const& r);
~result();
result& operator=(result const& r);
unsigned long long get_command_id() const throw ();
std::string const& get_error() const throw ();
bool get_executed() const throw ();
int get_exit_code() const throw ();
std::string const& get_output() const throw ();
void set_command_id(unsigned long long cmd_id) throw ();
void set_error(std::string const& error);
void set_executed(bool executed) throw ();
void set_exit_code(int code) throw ();
void set_output(std::string const& output);
private:
void _internal_copy(check_result const& cr);
private:
void _internal_copy(result const& r);
unsigned long long _cmd_id;
std::string _error;
bool _executed;
int _exit_code;
std::string _output;
};
unsigned long long _cmd_id;
std::string _error;
bool _executed;
int _exit_code;
std::string _output;
};
}
CCCS_END()
#endif // !CCCS_CHECK_RESULT_HH
#endif // !CCCS_CHECKS_RESULT_HH
......@@ -18,9 +18,9 @@
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
#include "com/centreon/connector/ssh/checks/result.hh"
using namespace com::centreon::connector::ssh;
using namespace com::centreon::connector::ssh::checks;
/**************************************
* *
......@@ -31,33 +31,32 @@ using namespace com::centreon::connector::ssh;
/**
* Default constructor.
*/
check_result::check_result()
: _cmd_id(0), _executed(false), _exit_code(-1) {}
result::result() : _cmd_id(0), _executed(false), _exit_code(-1) {}
/**
* Copy constructor.
*
* @param[in] cr Object to copy.
* @param[in] r Object to copy.
*/
check_result::check_result(check_result const& cr) {
_internal_copy(cr);
result::result(result const& r) {
_internal_copy(r);
}
/**
* Destructor.
*/
check_result::~check_result() {}
result::~result() {}
/**
* Assignment operator.
*
* @param[in] cr Object to copy.
* @param[in] r Object to copy.
*
* @return This object.
*/
check_result& check_result::operator=(check_result const& cr) {
if (this != &cr)
_internal_copy(cr);
result& result::operator=(result const& r) {
if (this != &r)
_internal_copy(r);
return (*this);
}
......@@ -66,7 +65,7 @@ check_result& check_result::operator=(check_result const& cr) {
*
* @return Command ID.
*/
unsigned long long check_result::get_command_id() const throw () {
unsigned long long result::get_command_id() const throw () {
return (_cmd_id);
}
......@@ -75,7 +74,7 @@ unsigned long long check_result::get_command_id() const throw () {
*
* @return Check error string.
*/
std::string const& check_result::get_error() const throw () {
std::string const& result::get_error() const throw () {
return (_error);
}
......@@ -84,7 +83,7 @@ std::string const& check_result::get_error() const throw () {
*
* @return true if check was executed, false otherwise.
*/
bool check_result::get_executed() const throw () {
bool result::get_executed() const throw () {
return (_executed);
}
......@@ -93,7 +92,7 @@ bool check_result::get_executed() const throw () {
*
* @return Check exit code.
*/
int check_result::get_exit_code() const throw () {
int result::get_exit_code() const throw () {
return (_exit_code);
}
......@@ -102,7 +101,7 @@ int check_result::get_exit_code() const throw () {
*
* @return Check output.
*/
std::string const& check_result::get_output() const throw () {
std::string const& result::get_output() const throw () {
return (_output);
}
......@@ -111,7 +110,7 @@ std::string const& check_result::get_output() const throw () {
*
* @param[in] cmd_id Command ID.
*/
void check_result::set_command_id(unsigned long long cmd_id) throw () {
void result::set_command_id(unsigned long long cmd_id) throw () {
_cmd_id = cmd_id;
return ;
}
......@@ -121,7 +120,7 @@ void check_result::set_command_id(unsigned long long cmd_id) throw () {
*
* @param[in] error Error string.
*/
void check_result::set_error(std::string const& error) {
void result::set_error(std::string const& error) {
_error = error;
return ;
}
......@@ -132,7 +131,7 @@ void check_result::set_error(std::string const& error) {
* @param[in] executed Set to true if check was executed, false
* otherwise.
*/
void check_result::set_executed(bool executed) throw () {
void result::set_executed(bool executed) throw () {
_executed = executed;
return ;
}
......@@ -142,7 +141,7 @@ void check_result::set_executed(bool executed) throw () {
*
* @param[in] code Check exit code.
*/
void check_result::set_exit_code(int code) throw () {
void result::set_exit_code(int code) throw () {
_exit_code = code;
return ;
}
......@@ -152,7 +151,7 @@ void check_result::set_exit_code(int code) throw () {
*
* @param[in] output Check output.
*/
void check_result::set_output(std::string const& output) {
void result::set_output(std::string const& output) {
_output = output;
return ;
}
......@@ -166,13 +165,13 @@ void check_result::set_output(std::string const& output) {
/**
* Copy internal data members.
*
* @param[in] cr Object to copy.
* @param[in] r Object to copy.
*/
void check_result::_internal_copy(check_result const& cr) {
_cmd_id = cr._cmd_id;
_error = cr._error;
_executed = cr._executed;
_exit_code = cr._exit_code;
_output = cr._output;
void result::_internal_copy(result const& r) {
_cmd_id = r._cmd_id;
_error = r._error;
_executed = r._executed;
_exit_code = r._exit_code;
_output = r._output;
return ;
}
......@@ -18,45 +18,45 @@
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
#include "com/centreon/connector/ssh/checks/result.hh"
using namespace com::centreon::connector::ssh;
using namespace com::centreon::connector::ssh::checks;
/**
* Check that check_result's copy constructor works properly.
* Check that result's copy constructor works properly.
*
* @return 0 on success.
*/
int main() {
// Base object.
check_result cr1;
cr1.set_command_id(14598753ull);
cr1.set_error("a random error string");
cr1.set_executed(true);
cr1.set_exit_code(-46582);
cr1.set_output("another random string, but for the output property");
result r1;
r1.set_command_id(14598753ull);
r1.set_error("a random error string");
r1.set_executed(true);
r1.set_exit_code(-46582);
r1.set_output("another random string, but for the output property");
// Copied object.
check_result cr2;
cr2 = cr1;
result r2;
r2 = r1;
// Reset base object.
cr1.set_command_id(42);
cr1.set_error("foo bar");
cr1.set_executed(false);
cr1.set_exit_code(7536);
cr1.set_output("baz qux");
r1.set_command_id(42);
r1.set_error("foo bar");
r1.set_executed(false);
r1.set_exit_code(7536);
r1.set_output("baz qux");
// Check content.
return ((cr1.get_command_id() != 42)
|| (cr1.get_error() != "foo bar")
|| cr1.get_executed()
|| (cr1.get_exit_code() != 7536)
|| (cr1.get_output() != "baz qux")
|| (cr2.get_command_id() != 14598753ull)
|| (cr2.get_error() != "a random error string")
|| !cr2.get_executed()
|| (cr2.get_exit_code() != -46582)
|| (cr2.get_output()
return ((r1.get_command_id() != 42)
|| (r1.get_error() != "foo bar")
|| r1.get_executed()
|| (r1.get_exit_code() != 7536)
|| (r1.get_output() != "baz qux")
|| (r2.get_command_id() != 14598753ull)
|| (r2.get_error() != "a random error string")
|| !r2.get_executed()
|| (r2.get_exit_code() != -46582)
|| (r2.get_output()
!= "another random string, but for the output property"));
}
......@@ -18,31 +18,31 @@
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
#include "com/centreon/connector/ssh/checks/result.hh"
#define ID1 71184
#define ID2 15
#define ID3 741258963148368872ull
/**
* Check check_result's command_id property.
* Check result's command_id property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
com::centreon::connector::ssh::checks::result r;
// Checks.
int retval(0);
cr.set_command_id(ID1);
r.set_command_id(ID1);
for (unsigned int i = 0; i < 100; ++i)
retval |= (cr.get_command_id() != ID1);
cr.set_command_id(ID2);
retval |= (cr.get_command_id() != ID2);
cr.set_command_id(ID3);
retval |= (r.get_command_id() != ID1);
r.set_command_id(ID2);
retval |= (r.get_command_id() != ID2);
r.set_command_id(ID3);
for (unsigned int i = 0; i < 10000; ++i)
retval |= (cr.get_command_id() != ID3);
retval |= (r.get_command_id() != ID3);
// Return check result.
return (retval);
......
......@@ -18,44 +18,44 @@
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
#include "com/centreon/connector/ssh/checks/result.hh"
using namespace com::centreon::connector::ssh;
using namespace com::centreon::connector::ssh::checks;
/**
* Check that check_result's copy constructor works properly.
* Check that result's copy constructor works properly.
*
* @return 0 on success.
*/
int main() {
// Base object.
check_result cr1;
cr1.set_command_id(14598753ull);
cr1.set_error("a random error string");
cr1.set_executed(true);
cr1.set_exit_code(-46582);
cr1.set_output("another random string, but for the output property");
result r1;
r1.set_command_id(14598753ull);
r1.set_error("a random error string");
r1.set_executed(true);
r1.set_exit_code(-46582);
r1.set_output("another random string, but for the output property");
// Copied object.
check_result cr2(cr1);
result r2(r1);
// Reset base object.
cr1.set_command_id(42);
cr1.set_error("foo bar");
cr1.set_executed(false);
cr1.set_exit_code(7536);
cr1.set_output("baz qux");
r1.set_command_id(42);
r1.set_error("foo bar");
r1.set_executed(false);
r1.set_exit_code(7536);
r1.set_output("baz qux");
// Check content.
return ((cr1.get_command_id() != 42)
|| (cr1.get_error() != "foo bar")
|| cr1.get_executed()
|| (cr1.get_exit_code() != 7536)
|| (cr1.get_output() != "baz qux")
|| (cr2.get_command_id() != 14598753ull)
|| (cr2.get_error() != "a random error string")
|| !cr2.get_executed()
|| (cr2.get_exit_code() != -46582)
|| (cr2.get_output()
return ((r1.get_command_id() != 42)
|| (r1.get_error() != "foo bar")
|| r1.get_executed()
|| (r1.get_exit_code() != 7536)
|| (r1.get_output() != "baz qux")
|| (r2.get_command_id() != 14598753ull)
|| (r2.get_error() != "a random error string")
|| !r2.get_executed()
|| (r2.get_exit_code() != -46582)
|| (r2.get_output()
!= "another random string, but for the output property"));
}
......@@ -18,21 +18,21 @@
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
#include "com/centreon/connector/ssh/checks/result.hh"
/**
* Check that check_result is properly default constructed.
* Check that result is properly default constructed.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
com::centreon::connector::ssh::checks::result r;
// Check.
return ((cr.get_command_id() != 0)
|| !cr.get_error().empty()
|| cr.get_executed()
|| (cr.get_exit_code() != -1)
|| !cr.get_output().empty());
return ((r.get_command_id() != 0)
|| !r.get_error().empty()
|| r.get_executed()
|| (r.get_exit_code() != -1)
|| !r.get_output().empty());
}
......@@ -18,31 +18,31 @@
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
#include "com/centreon/connector/ssh/checks/result.hh"
#define STR1 "this is the first string"
#define STR2 "this string might be longer"
#define STR3 "this is the last string that makes Centreon Connector SSH rocks !"
/**
* Check check_result's error property.
* Check result's error property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
com::centreon::connector::ssh::checks::result r;
// Checks.
int retval(0);
cr.set_error(STR1);
r.set_error(STR1);
for (unsigned int i = 0; i < 100; ++i)
retval |= (cr.get_error() != STR1);
cr.set_error(STR2);
retval |= (cr.get_error() != STR2);
cr.set_error(STR3);
retval |= (r.get_error() != STR1);
r.set_error(STR2);
retval |= (r.get_error() != STR2);
r.set_error(STR3);
for (unsigned int i = 0; i < 10000; ++i)
retval |= (cr.get_error() != STR3);
retval |= (r.get_error() != STR3);
// Return check result.
return (retval);
......
......@@ -18,27 +18,27 @@
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
#include "com/centreon/connector/ssh/checks/result.hh"
/**
* Check check_result's executed property.
* Check result's executed property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
com::centreon::connector::ssh::checks::result r;
// Checks.
int retval(0);