Commit ce3ac82c authored by Matthieu Kermagoret's avatar Matthieu Kermagoret
Browse files

Connector SSH: added check_result unit tests.

parent 9545dd38
......@@ -167,6 +167,56 @@ if (WITH_TESTING)
enable_testing()
set(BUILD_UNIT_TEST "Yes")
# check_result tests.
# Default constructor.
set(TEST_NAME "check_result_ctor_default")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_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")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/command_id.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Error property.
set(TEST_NAME "check_result_error")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/error.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Executed
set(TEST_NAME "check_result_executed")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_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")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/exit_code.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Output property.
set(TEST_NAME "check_result_output")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/output.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Copy constructor.
set(TEST_NAME "check_result_ctor_copy")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/ctor_copy.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# Assignment operator.
set(TEST_NAME "check_result_assignment")
add_executable("${TEST_NAME}"
"${TEST_DIR}/check_result/assignment.cc")
target_link_libraries("${TEST_NAME}" "${CONNECTORLIB}")
add_test("${TEST_NAME}" "${TEST_NAME}")
# multiplexer tests.
# Check singleton.
set(TEST_NAME "multiplexer_singleton")
......
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
using namespace com::centreon::connector::ssh;
/**
* Check that check_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");
// Copied object.
check_result cr2;
cr2 = cr1;
// 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");
// 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()
!= "another random string, but for the output property"));
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
#define ID1 71184
#define ID2 15
#define ID3 741258963148368872ull
/**
* Check check_result's command_id property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
// Checks.
int retval(0);
cr.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);
for (unsigned int i = 0; i < 10000; ++i)
retval |= (cr.get_command_id() != ID3);
// Return check result.
return (retval);
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
using namespace com::centreon::connector::ssh;
/**
* Check that check_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");
// Copied object.
check_result cr2(cr1);
// 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");
// 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()
!= "another random string, but for the output property"));
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
/**
* Check that check_result is properly default constructed.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
// Check.
return ((cr.get_command_id() != 0)
|| !cr.get_error().empty()
|| cr.get_executed()
|| (cr.get_exit_code() != -1)
|| !cr.get_output().empty());
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_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.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
// Checks.
int retval(0);
cr.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);
for (unsigned int i = 0; i < 10000; ++i)
retval |= (cr.get_error() != STR3);
// Return check result.
return (retval);
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
/**
* Check check_result's executed property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
// Checks.
int retval(0);
cr.set_executed(false);
retval |= cr.get_executed();
cr.set_executed(true);
for (unsigned int i = 0; i < 10000; ++i)
retval |= !cr.get_executed();
cr.set_executed(false);
for (unsigned int i = 0; i < 10000; ++i)
retval |= cr.get_executed();
// Return check result.
return (retval);
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_result.hh"
#define CODE1 71184
#define CODE2 3
#define CODE3 -47829
/**
* Check check_result's exit_code property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
// Checks.
int retval(0);
cr.set_exit_code(CODE1);
for (unsigned int i = 0; i < 100; ++i)
retval |= (cr.get_exit_code() != CODE1);
cr.set_exit_code(CODE2);
retval |= (cr.get_exit_code() != CODE2);
cr.set_exit_code(CODE3);
for (unsigned int i = 0; i < 10000; ++i)
retval |= (cr.get_exit_code() != CODE3);
// Return check result.
return (retval);
}
/*
** Copyright 2011 Merethis
**
** This file is part of Centreon Connector SSH.
**
** Centreon Connector SSH is free software: you can redistribute it
** and/or modify it under the terms of the GNU Affero General Public
** License as published by the Free Software Foundation, either version
** 3 of the License, or (at your option) any later version.
**
** Centreon Connector SSH is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied warranty
** of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public
** License along with Centreon Connector SSH. If not, see
** <http://www.gnu.org/licenses/>.
*/
#include "com/centreon/connector/ssh/check_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 output property.
*
* @return 0 on success.
*/
int main() {
// Object.
com::centreon::connector::ssh::check_result cr;
// Checks.
int retval(0);
cr.set_output(STR1);
for (unsigned int i = 0; i < 100; ++i)
retval |= (cr.get_output() != STR1);
cr.set_output(STR2);
retval |= (cr.get_output() != STR2);
cr.set_output(STR3);
for (unsigned int i = 0; i < 10000; ++i)
retval |= (cr.get_output() != STR3);
// Return check result.
return (retval);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment