Commit 03bd0c5e authored by Dorian Guillois's avatar Dorian Guillois
Browse files

Add verbose into perl unit test.

parent a6662d20
......@@ -218,6 +218,11 @@ if (WITH_TESTING)
add_test("connector_invalid_flag" "${CONNECTOR}" "--merethis")
set_tests_properties("connector_invalid_flag"
PROPERTIES WILL_FAIL TRUE)
# Execution library.
add_library("test_execute" STATIC
"${TEST_DIR}/connector/misc.cc"
"${TEST_DIR}/connector/misc.hh")
set(TEST_LIBRARIES ${CLIB_LIBRARIES} "test_execute")
# EOF on stdin.
set(TEST_NAME "connector_eof_on_stdin")
add_executable("${TEST_NAME}"
......@@ -228,25 +233,20 @@ if (WITH_TESTING)
set(TEST_NAME "connector_non_existent_script")
add_executable("${TEST_NAME}"
"${TEST_DIR}/connector/non_existent_script.cc")
target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
add_test("${TEST_NAME}" "${TEST_NAME}")
# Graceful timeout.
set(TEST_NAME "connector_timeout_term")
add_executable("${TEST_NAME}"
"${TEST_DIR}/connector/timeout_term.cc")
target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
add_test("${TEST_NAME}" "${TEST_NAME}")
# Forced timeout.
set(TEST_NAME "connector_timeout_kill")
add_executable("${TEST_NAME}"
"${TEST_DIR}/connector/timeout_kill.cc")
target_link_libraries("${TEST_NAME}" ${CLIB_LIBRARIES})
target_link_libraries("${TEST_NAME}" ${TEST_LIBRARIES})
add_test("${TEST_NAME}" "${TEST_NAME}")
# Execution library.
add_library("test_execute" STATIC
"${TEST_DIR}/connector/misc.cc"
"${TEST_DIR}/connector/misc.hh")
set(TEST_LIBRARIES ${CLIB_LIBRARIES} "test_execute")
# Single script execution.
set(TEST_NAME "connector_execute_single_script")
add_executable("${TEST_NAME}"
......
......@@ -111,12 +111,11 @@ int main() {
try {
if (retval)
throw (basic_error() << "invalid return code: " << retval);
if (output.size() != (sizeof(RESULT) - 1))
if (output.size() != (sizeof(RESULT) - 1)
|| memcmp(output.c_str(), RESULT, sizeof(RESULT) - 1))
throw (basic_error()
<< "invalid output size: " << output.size()
<< ", output: " << output);
if (memcmp(output.c_str(), RESULT, sizeof(RESULT) - 1))
throw (basic_error() << "invalid output: " << output);
<< "invalid output: size=" << output.size()
<< ", output=" << replace_null(output));
}
catch (std::exception const& e) {
retval = 1;
......
......@@ -108,12 +108,11 @@ int main() {
try {
if (retval)
throw (basic_error() << "invalid return code: " << retval);
if (output.size() != (sizeof(RESULT) - 1))
if (output.size() != (sizeof(RESULT) - 1)
|| memcmp(output.c_str(), RESULT, sizeof(RESULT) - 1))
throw (basic_error()
<< "invalid output size: " << output.size()
<< ", output: " << output);
if (memcmp(output.c_str(), RESULT, sizeof(RESULT) - 1))
throw (basic_error() << "invalid output: " << output);
<< "invalid output: size=" << output.size()
<< ", output=" << replace_null(output));
}
catch (std::exception const& e) {
retval = 1;
......
......@@ -20,11 +20,26 @@
#include <cstdio>
#include <cstring>
#include <string>
#include "com/centreon/exceptions/basic.hh"
#include "test/connector/misc.hh"
using namespace com::centreon;
/**
* Replace null char by string "\0".
*
* @param[in, out] str The string to replace.
*
* @return The replace string.
*/
std::string& replace_null(std::string& str) {
size_t pos(0);
while ((pos = str.find('\0', pos)) != std::string::npos)
str.replace(pos++, 1, "\\0");
return (str);
}
/**
* Write a file.
*
......
......@@ -21,9 +21,10 @@
#ifndef TEST_CONNECTOR_MISC_HH
# define TEST_CONNECTOR_MISC_HH
void write_file(
char const* filename,
char const* content,
unsigned int size = 0);
std::string& replace_null(std::string& str);
void write_file(
char const* filename,
char const* content,
unsigned int size = 0);
#endif //! TEST_CONNECTOR_MISC_HH
......@@ -25,6 +25,7 @@
#include "com/centreon/clib.hh"
#include "com/centreon/exceptions/basic.hh"
#include "com/centreon/process.hh"
#include "test/connector/misc.hh"
#include "test/connector/paths.hh"
using namespace com::centreon;
......@@ -97,7 +98,7 @@ int main() {
|| memcmp(output.c_str(), RESULT, sizeof(RESULT) - 1)))
throw (basic_error()
<< "invalid output: size=" << output.size()
<< ", output=" << output);
<< ", output=" << replace_null(output));
}
catch (std::exception const& e) {
retval = 1;
......
......@@ -25,6 +25,7 @@
#include "com/centreon/clib.hh"
#include "com/centreon/exceptions/basic.hh"
#include "com/centreon/process.hh"
#include "test/connector/misc.hh"
#include "test/connector/paths.hh"
using namespace com::centreon;
......@@ -91,12 +92,11 @@ int main() {
try {
if (retval)
throw (basic_error() << "invalid return code: " << retval);
if (output.size() != (sizeof(RESULT) - 1))
if (output.size() != (sizeof(RESULT) - 1)
|| memcmp(output.c_str(), RESULT, sizeof(RESULT) - 1))
throw (basic_error()
<< "invalid output size: " << output.size()
<< ", output: " << output);
if (memcmp(output.c_str(), RESULT, sizeof(RESULT) - 1))
throw (basic_error() << "invalid output: " << output);
<< "invalid output: size=" << output.size()
<< ", output=" << replace_null(output));
}
catch (std::exception const& e) {
retval = 1;
......
......@@ -25,6 +25,7 @@
#include "com/centreon/clib.hh"
#include "com/centreon/exceptions/basic.hh"
#include "com/centreon/process.hh"
#include "test/connector/misc.hh"
#include "test/connector/paths.hh"
using namespace com::centreon;
......@@ -95,12 +96,11 @@ int main() {
try {
if (retval)
throw (basic_error() << "invalid return code: " << retval);
if (output.size() != (sizeof(RESULT) - 1))
if (output.size() != (sizeof(RESULT) - 1)
|| memcmp(output.c_str(), RESULT, sizeof(RESULT) - 1))
throw (basic_error()
<< "invalid output size: " << output.size()
<< ", output: " << output);
if (memcmp(output.c_str(), RESULT, sizeof(RESULT) - 1))
throw (basic_error() << "invalid output: " << output);
<< "invalid output: size=" << output.size()
<< ", output=" << replace_null(output));
}
catch (std::exception const& e) {
retval = 1;
......
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