From 8c8efe5db6874e467ce9d210b7a43f1da1317ea3 Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Thu, 4 Mar 2021 06:42:51 +0100 Subject: [PATCH] Worked on tests --- .gitignore | 3 + msvscpp/Makefile.am | 3 + .../evtx_test_tools_info_handle.vcproj | 234 ++++++++++++++ .../evtx_test_tools_output.vcproj | 218 +++++++++++++ .../evtx_test_tools_signal.vcproj | 218 +++++++++++++ msvscpp/libevtx.sln | 31 ++ tests/Makefile.am | 45 ++- tests/evtx_test_tools_info_handle.c | 299 ++++++++++++++++++ tests/evtx_test_tools_output.c | 105 ++++++ tests/evtx_test_tools_signal.c | 213 +++++++++++++ tests/test_tools.sh | 189 +++++++++++ 11 files changed, 1556 insertions(+), 2 deletions(-) create mode 100644 msvscpp/evtx_test_tools_info_handle/evtx_test_tools_info_handle.vcproj create mode 100644 msvscpp/evtx_test_tools_output/evtx_test_tools_output.vcproj create mode 100644 msvscpp/evtx_test_tools_signal/evtx_test_tools_signal.vcproj create mode 100644 tests/evtx_test_tools_info_handle.c create mode 100644 tests/evtx_test_tools_output.c create mode 100644 tests/evtx_test_tools_signal.c create mode 100755 tests/test_tools.sh diff --git a/.gitignore b/.gitignore index 16a7d928..da23c747 100644 --- a/.gitignore +++ b/.gitignore @@ -138,6 +138,9 @@ stamp-h[1-9] /tests/evtx_test_record_values /tests/evtx_test_support /tests/evtx_test_template_definition +/tests/evtx_test_tools_info_handle +/tests/evtx_test_tools_output +/tests/evtx_test_tools_signal /tests/input /tests/tmp* diff --git a/msvscpp/Makefile.am b/msvscpp/Makefile.am index 8429e2cd..8aa438b2 100644 --- a/msvscpp/Makefile.am +++ b/msvscpp/Makefile.am @@ -9,6 +9,9 @@ MSVSCPP_FILES = \ evtx_test_record_values/evtx_test_record_values.vcproj \ evtx_test_support/evtx_test_support.vcproj \ evtx_test_template_definition/evtx_test_template_definition.vcproj \ + evtx_test_tools_info_handle/evtx_test_tools_info_handle.vcproj \ + evtx_test_tools_output/evtx_test_tools_output.vcproj \ + evtx_test_tools_signal/evtx_test_tools_signal.vcproj \ evtxexport/evtxexport.vcproj \ evtxinfo/evtxinfo.vcproj \ libbfio/libbfio.vcproj \ diff --git a/msvscpp/evtx_test_tools_info_handle/evtx_test_tools_info_handle.vcproj b/msvscpp/evtx_test_tools_info_handle/evtx_test_tools_info_handle.vcproj new file mode 100644 index 00000000..f6ffa882 --- /dev/null +++ b/msvscpp/evtx_test_tools_info_handle/evtx_test_tools_info_handle.vcproj @@ -0,0 +1,234 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvscpp/evtx_test_tools_output/evtx_test_tools_output.vcproj b/msvscpp/evtx_test_tools_output/evtx_test_tools_output.vcproj new file mode 100644 index 00000000..0bf56de2 --- /dev/null +++ b/msvscpp/evtx_test_tools_output/evtx_test_tools_output.vcproj @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvscpp/evtx_test_tools_signal/evtx_test_tools_signal.vcproj b/msvscpp/evtx_test_tools_signal/evtx_test_tools_signal.vcproj new file mode 100644 index 00000000..45648dec --- /dev/null +++ b/msvscpp/evtx_test_tools_signal/evtx_test_tools_signal.vcproj @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvscpp/libevtx.sln b/msvscpp/libevtx.sln index 76301925..7a16b3e5 100644 --- a/msvscpp/libevtx.sln +++ b/msvscpp/libevtx.sln @@ -118,6 +118,25 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "evtx_test_template_definiti {5299814A-9BDD-4F91-ADF9-723068B3B642} = {5299814A-9BDD-4F91-ADF9-723068B3B642} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "evtx_test_tools_info_handle", "evtx_test_tools_info_handle\evtx_test_tools_info_handle.vcproj", "{BE305497-DE84-4503-BCAF-80C8D5C3F730}" + ProjectSection(ProjectDependencies) = postProject + {754A36B3-E1DC-4975-89E4-EF0D82ACBC3B} = {754A36B3-E1DC-4975-89E4-EF0D82ACBC3B} + {91D35439-5C77-4084-B94A-45B055A97971} = {91D35439-5C77-4084-B94A-45B055A97971} + {5299814A-9BDD-4F91-ADF9-723068B3B642} = {5299814A-9BDD-4F91-ADF9-723068B3B642} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "evtx_test_tools_output", "evtx_test_tools_output\evtx_test_tools_output.vcproj", "{1A14908D-59D7-4894-87AA-50712BA07F64}" + ProjectSection(ProjectDependencies) = postProject + {91D35439-5C77-4084-B94A-45B055A97971} = {91D35439-5C77-4084-B94A-45B055A97971} + {5299814A-9BDD-4F91-ADF9-723068B3B642} = {5299814A-9BDD-4F91-ADF9-723068B3B642} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "evtx_test_tools_signal", "evtx_test_tools_signal\evtx_test_tools_signal.vcproj", "{3FBC46FE-518B-4351-87DF-22B3F8DF6A35}" + ProjectSection(ProjectDependencies) = postProject + {91D35439-5C77-4084-B94A-45B055A97971} = {91D35439-5C77-4084-B94A-45B055A97971} + {5299814A-9BDD-4F91-ADF9-723068B3B642} = {5299814A-9BDD-4F91-ADF9-723068B3B642} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libevtx", "libevtx\libevtx.vcproj", "{91D35439-5C77-4084-B94A-45B055A97971}" ProjectSection(ProjectDependencies) = postProject {5299814A-9BDD-4F91-ADF9-723068B3B642} = {5299814A-9BDD-4F91-ADF9-723068B3B642} @@ -392,6 +411,18 @@ Global {F7453089-EA30-4F71-9C6E-630C02E37383}.Release|Win32.Build.0 = Release|Win32 {F7453089-EA30-4F71-9C6E-630C02E37383}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 {F7453089-EA30-4F71-9C6E-630C02E37383}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {BE305497-DE84-4503-BCAF-80C8D5C3F730}.Release|Win32.ActiveCfg = Release|Win32 + {BE305497-DE84-4503-BCAF-80C8D5C3F730}.Release|Win32.Build.0 = Release|Win32 + {BE305497-DE84-4503-BCAF-80C8D5C3F730}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {BE305497-DE84-4503-BCAF-80C8D5C3F730}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {1A14908D-59D7-4894-87AA-50712BA07F64}.Release|Win32.ActiveCfg = Release|Win32 + {1A14908D-59D7-4894-87AA-50712BA07F64}.Release|Win32.Build.0 = Release|Win32 + {1A14908D-59D7-4894-87AA-50712BA07F64}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {1A14908D-59D7-4894-87AA-50712BA07F64}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {3FBC46FE-518B-4351-87DF-22B3F8DF6A35}.Release|Win32.ActiveCfg = Release|Win32 + {3FBC46FE-518B-4351-87DF-22B3F8DF6A35}.Release|Win32.Build.0 = Release|Win32 + {3FBC46FE-518B-4351-87DF-22B3F8DF6A35}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {3FBC46FE-518B-4351-87DF-22B3F8DF6A35}.VSDebug|Win32.Build.0 = VSDebug|Win32 {91D35439-5C77-4084-B94A-45B055A97971}.Release|Win32.ActiveCfg = Release|Win32 {91D35439-5C77-4084-B94A-45B055A97971}.Release|Win32.Build.0 = Release|Win32 {91D35439-5C77-4084-B94A-45B055A97971}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 diff --git a/tests/Makefile.am b/tests/Makefile.am index 3b80dc14..c441085a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -28,6 +28,7 @@ endif TESTS = \ test_library.sh \ + test_tools.sh \ test_evtxinfo.sh \ test_evtxexport.sh \ test_evtxexport_xml.sh \ @@ -42,7 +43,8 @@ check_SCRIPTS = \ test_library.sh \ test_manpage.sh \ test_python_module.sh \ - test_runner.sh + test_runner.sh \ + test_tools.sh EXTRA_DIST = \ $(check_SCRIPTS) @@ -57,7 +59,10 @@ check_PROGRAMS = \ evtx_test_record \ evtx_test_record_values \ evtx_test_support \ - evtx_test_template_definition + evtx_test_template_definition \ + evtx_test_tools_info_handle \ + evtx_test_tools_output \ + evtx_test_tools_signal evtx_test_chunk_SOURCES = \ evtx_test_chunk.c \ @@ -205,6 +210,42 @@ evtx_test_template_definition_LDADD = \ ../libevtx/libevtx.la \ @LIBCERROR_LIBADD@ +evtx_test_tools_info_handle_SOURCES = \ + ../evtxtools/evtxinput.c ../evtxtools/evtxinput.h \ + ../evtxtools/info_handle.c ../evtxtools/info_handle.h \ + evtx_test_libcerror.h \ + evtx_test_macros.h \ + evtx_test_memory.c evtx_test_memory.h \ + evtx_test_tools_info_handle.c \ + evtx_test_unused.h + +evtx_test_tools_info_handle_LDADD = \ + @LIBCLOCALE_LIBADD@ \ + ../libevtx/libevtx.la \ + @LIBCERROR_LIBADD@ + +evtx_test_tools_output_SOURCES = \ + ../evtxtools/evtxtools_output.c ../evtxtools/evtxtools_output.h \ + evtx_test_libcerror.h \ + evtx_test_macros.h \ + evtx_test_tools_output.c \ + evtx_test_unused.h + +evtx_test_tools_output_LDADD = \ + ../libevtx/libevtx.la \ + @LIBCERROR_LIBADD@ + +evtx_test_tools_signal_SOURCES = \ + ../evtxtools/evtxtools_signal.c ../evtxtools/evtxtools_signal.h \ + evtx_test_libcerror.h \ + evtx_test_macros.h \ + evtx_test_tools_signal.c \ + evtx_test_unused.h + +evtx_test_tools_signal_LDADD = \ + ../libevtx/libevtx.la \ + @LIBCERROR_LIBADD@ + MAINTAINERCLEANFILES = \ Makefile.in diff --git a/tests/evtx_test_tools_info_handle.c b/tests/evtx_test_tools_info_handle.c new file mode 100644 index 00000000..1d0ef8eb --- /dev/null +++ b/tests/evtx_test_tools_info_handle.c @@ -0,0 +1,299 @@ +/* + * Tools info_handle type test program + * + * Copyright (C) 2011-2021, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include +#include + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "evtx_test_libcerror.h" +#include "evtx_test_macros.h" +#include "evtx_test_memory.h" +#include "evtx_test_unused.h" + +#include "../evtxtools/info_handle.h" + +/* Tests the info_handle_initialize function + * Returns 1 if successful or 0 if not + */ +int evtx_test_tools_info_handle_initialize( + void ) +{ + info_handle_t *info_handle = NULL; + libcerror_error_t *error = NULL; + int result = 0; + +#if defined( HAVE_EVTX_TEST_MEMORY ) + int number_of_malloc_fail_tests = 1; + int number_of_memset_fail_tests = 1; + int test_number = 0; +#endif + + /* Test regular cases + */ + result = info_handle_initialize( + &info_handle, + &error ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EVTX_TEST_ASSERT_IS_NOT_NULL( + "info_handle", + info_handle ); + + EVTX_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = info_handle_free( + &info_handle, + &error ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EVTX_TEST_ASSERT_IS_NULL( + "info_handle", + info_handle ); + + EVTX_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = info_handle_initialize( + NULL, + &error ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EVTX_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + info_handle = (info_handle_t *) 0x12345678UL; + + result = info_handle_initialize( + &info_handle, + &error ); + + info_handle = NULL; + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EVTX_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + +#if defined( HAVE_EVTX_TEST_MEMORY ) + + for( test_number = 0; + test_number < number_of_malloc_fail_tests; + test_number++ ) + { + /* Test info_handle_initialize with malloc failing + */ + evtx_test_malloc_attempts_before_fail = test_number; + + result = info_handle_initialize( + &info_handle, + &error ); + + if( evtx_test_malloc_attempts_before_fail != -1 ) + { + evtx_test_malloc_attempts_before_fail = -1; + + if( info_handle != NULL ) + { + info_handle_free( + &info_handle, + NULL ); + } + } + else + { + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EVTX_TEST_ASSERT_IS_NULL( + "info_handle", + info_handle ); + + EVTX_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } + for( test_number = 0; + test_number < number_of_memset_fail_tests; + test_number++ ) + { + /* Test info_handle_initialize with memset failing + */ + evtx_test_memset_attempts_before_fail = test_number; + + result = info_handle_initialize( + &info_handle, + &error ); + + if( evtx_test_memset_attempts_before_fail != -1 ) + { + evtx_test_memset_attempts_before_fail = -1; + + if( info_handle != NULL ) + { + info_handle_free( + &info_handle, + NULL ); + } + } + else + { + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EVTX_TEST_ASSERT_IS_NULL( + "info_handle", + info_handle ); + + EVTX_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } +#endif /* defined( HAVE_EVTX_TEST_MEMORY ) */ + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( info_handle != NULL ) + { + info_handle_free( + &info_handle, + NULL ); + } + return( 0 ); +} + +/* Tests the info_handle_free function + * Returns 1 if successful or 0 if not + */ +int evtx_test_tools_info_handle_free( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test error cases + */ + result = info_handle_free( + NULL, + &error ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EVTX_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* The main program + */ +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc EVTX_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] EVTX_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc EVTX_TEST_ATTRIBUTE_UNUSED, + char * const argv[] EVTX_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + EVTX_TEST_UNREFERENCED_PARAMETER( argc ) + EVTX_TEST_UNREFERENCED_PARAMETER( argv ) + + EVTX_TEST_RUN( + "info_handle_initialize", + evtx_test_tools_info_handle_initialize ); + + EVTX_TEST_RUN( + "info_handle_free", + evtx_test_tools_info_handle_free ); + + return( EXIT_SUCCESS ); + +on_error: + return( EXIT_FAILURE ); +} + diff --git a/tests/evtx_test_tools_output.c b/tests/evtx_test_tools_output.c new file mode 100644 index 00000000..a9d49804 --- /dev/null +++ b/tests/evtx_test_tools_output.c @@ -0,0 +1,105 @@ +/* + * Tools output functions test program + * + * Copyright (C) 2011-2021, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#include + +#if defined( HAVE_IO_H ) || defined( WINAPI ) +#include +#endif + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "evtx_test_libcerror.h" +#include "evtx_test_macros.h" +#include "evtx_test_unused.h" + +#include "../evtxtools/evtxtools_output.h" + +/* Tests the evtxtools_output_initialize and function + * Returns 1 if successful or 0 if not + */ +int evtx_test_tools_output_initialize( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + result = evtxtools_output_initialize( + _IONBF, + &error ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EVTX_TEST_ASSERT_IS_NULL( + "error", + error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* The main program + */ +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc EVTX_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] EVTX_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc EVTX_TEST_ATTRIBUTE_UNUSED, + char * const argv[] EVTX_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + EVTX_TEST_UNREFERENCED_PARAMETER( argc ) + EVTX_TEST_UNREFERENCED_PARAMETER( argv ) + + EVTX_TEST_RUN( + "evtxtools_output_initialize", + evtx_test_tools_output_initialize ) + + /* TODO add tests for evtxtools_output_copyright_fprint */ + + /* TODO add tests for evtxtools_output_version_fprint */ + + /* TODO add tests for evtxtools_output_version_detailed_fprint */ + + return( EXIT_SUCCESS ); + +on_error: + return( EXIT_FAILURE ); +} + diff --git a/tests/evtx_test_tools_signal.c b/tests/evtx_test_tools_signal.c new file mode 100644 index 00000000..528bea30 --- /dev/null +++ b/tests/evtx_test_tools_signal.c @@ -0,0 +1,213 @@ +/* + * Tools signal functions test program + * + * Copyright (C) 2011-2021, Joachim Metz + * + * Refer to AUTHORS for acknowledgements. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +#include +#include +#include + +#if defined( HAVE_STDLIB_H ) || defined( WINAPI ) +#include +#endif + +#include "evtx_test_libcerror.h" +#include "evtx_test_macros.h" +#include "evtx_test_unused.h" + +#include "../evtxtools/evtxtools_signal.h" + +void evtx_test_tools_signal_handler_function( + evtxtools_signal_t signal EVTX_TEST_ATTRIBUTE_UNUSED ) +{ + EVTX_TEST_UNREFERENCED_PARAMETER( signal ) +} + +#if defined( WINAPI ) + +/* Tests the evtxtools_signal_handler function + * Returns 1 if successful or 0 if not + */ +int evtx_test_tools_signal_handler( + void ) +{ + BOOL result = 0; + + /* Test regular cases + */ + result = evtxtools_signal_handler( + CTRL_C_EVENT ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + (int) TRUE ); + + result = evtxtools_signal_handler( + CTRL_LOGOFF_EVENT ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + (int) FALSE ); + + return( 1 ); + +on_error: + return( 0 ); +} + +#if defined( _MSC_VER ) + + /* TODO add tests for evtxtools_signal_initialize_memory_debug */ + +#endif /* defined( _MSC_VER ) */ + +#endif /* defined( WINAPI ) */ + +/* Tests the evtxtools_signal_attach function + * Returns 1 if successful or 0 if not + */ +int evtx_test_tools_signal_attach( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test regular cases + */ + result = evtxtools_signal_attach( + evtx_test_tools_signal_handler_function, + &error ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EVTX_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = evtxtools_signal_attach( + NULL, + &error ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + EVTX_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* Tests the evtxtools_signal_detach function + * Returns 1 if successful or 0 if not + */ +int evtx_test_tools_signal_detach( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test regular cases + */ + result = evtxtools_signal_detach( + &error ); + + EVTX_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + EVTX_TEST_ASSERT_IS_NULL( + "error", + error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +/* The main program + */ +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc EVTX_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] EVTX_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc EVTX_TEST_ATTRIBUTE_UNUSED, + char * const argv[] EVTX_TEST_ATTRIBUTE_UNUSED ) +#endif +{ + EVTX_TEST_UNREFERENCED_PARAMETER( argc ) + EVTX_TEST_UNREFERENCED_PARAMETER( argv ) + +#if defined( WINAPI ) + + EVTX_TEST_RUN( + "evtxtools_signal_handler", + evtx_test_tools_signal_handler ) + +#if defined( _MSC_VER ) + + /* TODO add tests for evtxtools_signal_initialize_memory_debug */ + +#endif /* defined( _MSC_VER ) */ + +#endif /* defined( WINAPI ) */ + + EVTX_TEST_RUN( + "evtxtools_signal_attach", + evtx_test_tools_signal_attach ) + + EVTX_TEST_RUN( + "evtxtools_signal_detach", + evtx_test_tools_signal_detach ) + + return( EXIT_SUCCESS ); + +on_error: + return( EXIT_FAILURE ); +} + diff --git a/tests/test_tools.sh b/tests/test_tools.sh new file mode 100755 index 00000000..432f7bb2 --- /dev/null +++ b/tests/test_tools.sh @@ -0,0 +1,189 @@ +#!/bin/bash +# Tests tools functions and types. +# +# Version: 20200705 + +EXIT_SUCCESS=0; +EXIT_FAILURE=1; +EXIT_IGNORE=77; + +TOOLS_TESTS="info_handle output signal"; +TOOLS_TESTS_WITH_INPUT=""; +OPTION_SETS=""; + +INPUT_GLOB="*"; + +run_test() +{ + local TEST_NAME=$1; + + local TEST_DESCRIPTION="Testing: ${TEST_NAME}"; + local TEST_EXECUTABLE="./evtx_test_tools_${TEST_NAME}"; + + if ! test -x "${TEST_EXECUTABLE}"; + then + TEST_EXECUTABLE="${TEST_EXECUTABLE}.exe"; + fi + + # TODO: add support for TEST_PROFILE and OPTION_SETS? + run_test_with_arguments "${TEST_DESCRIPTION}" "${TEST_EXECUTABLE}"; + local RESULT=$?; + + return ${RESULT}; +} + +run_test_with_input() +{ + local TEST_NAME=$1; + + local TEST_DESCRIPTION="Testing: ${TEST_NAME}"; + local TEST_EXECUTABLE="./evtx_test_tools_${TEST_NAME}"; + + if ! test -x "${TEST_EXECUTABLE}"; + then + TEST_EXECUTABLE="${TEST_EXECUTABLE}.exe"; + fi + + if ! test -d "input"; + then + echo "Test input directory not found."; + + return ${EXIT_IGNORE}; + fi + local RESULT=`ls input/* | tr ' ' '\n' | wc -l`; + + if test ${RESULT} -eq ${EXIT_SUCCESS}; + then + echo "No files or directories found in the test input directory"; + + return ${EXIT_IGNORE}; + fi + + local TEST_PROFILE_DIRECTORY=$(get_test_profile_directory "input" "evtxtools"); + + local IGNORE_LIST=$(read_ignore_list "${TEST_PROFILE_DIRECTORY}"); + + RESULT=${EXIT_SUCCESS}; + + for TEST_SET_INPUT_DIRECTORY in input/*; + do + if ! test -d "${TEST_SET_INPUT_DIRECTORY}"; + then + continue; + fi + if check_for_directory_in_ignore_list "${TEST_SET_INPUT_DIRECTORY}" "${IGNORE_LIST}"; + then + continue; + fi + + local TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}"); + + local OLDIFS=${IFS}; + + # IFS="\n" is not supported by all platforms. + IFS=" +"; + + if test -f "${TEST_SET_DIRECTORY}/files"; + then + for INPUT_FILE in `cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?"`; + do + if test "${OSTYPE}" = "msys"; + then + # A test executable built with MinGW expects a Windows path. + INPUT_FILE=`echo ${INPUT_FILE} | sed 's?/?\\\\?g'`; + fi + run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}"; + RESULT=$?; + + if test ${RESULT} -ne ${EXIT_SUCCESS}; + then + break; + fi + done + else + for INPUT_FILE in `ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}`; + do + if test "${OSTYPE}" = "msys"; + then + # A test executable built with MinGW expects a Windows path. + INPUT_FILE=`echo ${INPUT_FILE} | sed 's?/?\\\\?g'`; + fi + run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}"; + RESULT=$?; + + if test ${RESULT} -ne ${EXIT_SUCCESS}; + then + break; + fi + done + fi + IFS=${OLDIFS}; + + if test ${RESULT} -ne ${EXIT_SUCCESS}; + then + break; + fi + done + + return ${RESULT}; +} + +if test -n "${SKIP_TOOLS_TESTS}"; +then + exit ${EXIT_IGNORE}; +fi + +TEST_RUNNER="tests/test_runner.sh"; + +if ! test -f "${TEST_RUNNER}"; +then + TEST_RUNNER="./test_runner.sh"; +fi + +if ! test -f "${TEST_RUNNER}"; +then + echo "Missing test runner: ${TEST_RUNNER}"; + + exit ${EXIT_FAILURE}; +fi + +source ${TEST_RUNNER}; + +RESULT=${EXIT_IGNORE}; + +for TEST_NAME in ${TOOLS_TESTS}; +do + run_test "${TEST_NAME}"; + RESULT=$?; + + if test ${RESULT} -ne ${EXIT_SUCCESS}; + then + break; + fi +done + +if test ${RESULT} -ne ${EXIT_SUCCESS} && test ${RESULT} -ne ${EXIT_IGNORE}; +then + exit ${RESULT}; +fi + +for TEST_NAME in ${TOOLS_TESTS_WITH_INPUT}; +do + if test -d "input"; + then + run_test_with_input "${TEST_NAME}"; + RESULT=$?; + else + run_test "${TEST_NAME}"; + RESULT=$?; + fi + + if test ${RESULT} -ne ${EXIT_SUCCESS}; + then + break; + fi +done + +exit ${RESULT}; +