From 7eaa314e8ac25b381fd45fcfb0d57745a975d53d Mon Sep 17 00:00:00 2001 From: Joachim Metz Date: Fri, 26 Apr 2024 06:43:17 +0200 Subject: [PATCH] Worked on tests --- .gitignore | 1 + ChangeLog | 2 + configure.ac | 2 +- include/libfwevt.h.in | 13 + libfwevt/libfwevt_xml_tag.c | 80 +- libfwevt/libfwevt_xml_tag.h | 11 +- manuals/libfwevt.3 | 10 +- msvscpp/Makefile.am | 1 + .../fwevt_test_xml_value.vcproj | 230 ++++++ msvscpp/libfwevt.sln | 10 + tests/Makefile.am | 17 +- tests/fwevt_test_xml_tag.c | 252 +++---- tests/fwevt_test_xml_value.c | 684 ++++++++++++++++++ tests/test_library.ps1 | 2 +- tests/test_library.sh | 2 +- 15 files changed, 1115 insertions(+), 202 deletions(-) create mode 100644 msvscpp/fwevt_test_xml_value/fwevt_test_xml_value.vcproj create mode 100644 tests/fwevt_test_xml_value.c diff --git a/.gitignore b/.gitignore index 922220e..b5d288a 100644 --- a/.gitignore +++ b/.gitignore @@ -147,6 +147,7 @@ stamp-h[1-9] /tests/fwevt_test_xml_tag /tests/fwevt_test_xml_template_value /tests/fwevt_test_xml_token +/tests/fwevt_test_xml_value /tests/notify_stream.log /tests/tmp* diff --git a/ChangeLog b/ChangeLog index 9589971..5a563ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,6 @@ TODO +* add pyfwevt_xml_value + * Replace libfvalue by native functions ** Check use of libfwevt_xml_tag_get_value diff --git a/configure.ac b/configure.ac index b8ad62e..f069b2b 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,7 @@ AC_PREREQ([2.71]) AC_INIT( [libfwevt], - [20240425], + [20240426], [joachim.metz@gmail.com]) AC_CONFIG_SRCDIR( diff --git a/include/libfwevt.h.in b/include/libfwevt.h.in index ae28bb4..8828614 100644 --- a/include/libfwevt.h.in +++ b/include/libfwevt.h.in @@ -904,9 +904,19 @@ int libfwevt_xml_tag_get_utf16_name( size_t utf16_string_size, libfwevt_error_t **error ); +/* Retrieves the XML value + * Returns 1 if successful or -1 on error + */ +LIBFWEVT_EXTERN \ +int libfwevt_xml_tag_get_value( + libfwevt_xml_tag_t *xml_tag, + libfwevt_xml_value_t **xml_value, + libfwevt_error_t **error ); + /* Retrieves the size of the UTF-8 formatted value * Returns 1 if successful or -1 on error */ +LIBFWEVT_DEPRECATED \ LIBFWEVT_EXTERN \ int libfwevt_xml_tag_get_utf8_value_size( libfwevt_xml_tag_t *xml_tag, @@ -916,6 +926,7 @@ int libfwevt_xml_tag_get_utf8_value_size( /* Retrieves the UTF-8 formatted value * Returns 1 if successful or -1 on error */ +LIBFWEVT_DEPRECATED \ LIBFWEVT_EXTERN \ int libfwevt_xml_tag_get_utf8_value( libfwevt_xml_tag_t *xml_tag, @@ -926,6 +937,7 @@ int libfwevt_xml_tag_get_utf8_value( /* Retrieves the size of the UTF-16 formatted value * Returns 1 if successful or -1 on error */ +LIBFWEVT_DEPRECATED \ LIBFWEVT_EXTERN \ int libfwevt_xml_tag_get_utf16_value_size( libfwevt_xml_tag_t *xml_tag, @@ -935,6 +947,7 @@ int libfwevt_xml_tag_get_utf16_value_size( /* Retrieves the UTF-16 formatted value * Returns 1 if successful or -1 on error */ +LIBFWEVT_DEPRECATED \ LIBFWEVT_EXTERN \ int libfwevt_xml_tag_get_utf16_value( libfwevt_xml_tag_t *xml_tag, diff --git a/libfwevt/libfwevt_xml_tag.c b/libfwevt/libfwevt_xml_tag.c index 1facc69..006c26f 100644 --- a/libfwevt/libfwevt_xml_tag.c +++ b/libfwevt/libfwevt_xml_tag.c @@ -437,46 +437,6 @@ int libfwevt_xml_tag_set_name_data( return( -1 ); } -/* Retrieves the value - * Returns 1 if successful or -1 on error - */ -int libfwevt_xml_tag_get_value( - libfwevt_xml_tag_t *xml_tag, - libfwevt_xml_value_t **xml_value, - libcerror_error_t **error ) -{ - libfwevt_internal_xml_tag_t *internal_xml_tag = NULL; - static char *function = "libfwevt_xml_tag_get_value"; - - if( xml_tag == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML tag.", - function ); - - return( -1 ); - } - internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; - - if( xml_value == NULL ) - { - libcerror_error_set( - error, - LIBCERROR_ERROR_DOMAIN_ARGUMENTS, - LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, - "%s: invalid XML value.", - function ); - - return( -1 ); - } - *xml_value = internal_xml_tag->value; - - return( 1 ); -} - /* Sets the value type * Returns 1 if successful or -1 on error */ @@ -952,6 +912,46 @@ int libfwevt_xml_tag_get_utf16_name( return( 1 ); } +/* Retrieves the value + * Returns 1 if successful or -1 on error + */ +int libfwevt_xml_tag_get_value( + libfwevt_xml_tag_t *xml_tag, + libfwevt_xml_value_t **xml_value, + libcerror_error_t **error ) +{ + libfwevt_internal_xml_tag_t *internal_xml_tag = NULL; + static char *function = "libfwevt_xml_tag_get_value"; + + if( xml_tag == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid XML tag.", + function ); + + return( -1 ); + } + internal_xml_tag = (libfwevt_internal_xml_tag_t *) xml_tag; + + if( xml_value == NULL ) + { + libcerror_error_set( + error, + LIBCERROR_ERROR_DOMAIN_ARGUMENTS, + LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, + "%s: invalid XML value.", + function ); + + return( -1 ); + } + *xml_value = internal_xml_tag->value; + + return( 1 ); +} + /* Retrieves the size of the UTF-8 formatted value * Returns 1 if successful or -1 on error */ diff --git a/libfwevt/libfwevt_xml_tag.h b/libfwevt/libfwevt_xml_tag.h index a793341..cedc0af 100644 --- a/libfwevt/libfwevt_xml_tag.h +++ b/libfwevt/libfwevt_xml_tag.h @@ -91,11 +91,6 @@ int libfwevt_xml_tag_set_name_data( size_t data_size, libcerror_error_t **error ); -int libfwevt_xml_tag_get_value( - libfwevt_xml_tag_t *xml_tag, - libfwevt_xml_value_t **xml_value, - libcerror_error_t **error ); - int libfwevt_xml_tag_set_value_type( libfwevt_xml_tag_t *xml_tag, int value_type, @@ -164,6 +159,12 @@ int libfwevt_xml_tag_get_utf16_name( size_t utf16_string_size, libcerror_error_t **error ); +LIBFWEVT_EXTERN \ +int libfwevt_xml_tag_get_value( + libfwevt_xml_tag_t *xml_tag, + libfwevt_xml_value_t **xml_value, + libcerror_error_t **error ); + LIBFWEVT_EXTERN \ int libfwevt_xml_tag_get_utf8_value_size( libfwevt_xml_tag_t *xml_tag, diff --git a/manuals/libfwevt.3 b/manuals/libfwevt.3 index f1005d6..84ed7b9 100644 --- a/manuals/libfwevt.3 +++ b/manuals/libfwevt.3 @@ -1,4 +1,4 @@ -.Dd April 25, 2024 +.Dd April 26, 2024 .Dt libfwevt 3 .Os libfwevt .Sh NAME @@ -211,13 +211,7 @@ XML tag functions .Ft int .Fn libfwevt_xml_tag_get_utf16_name "libfwevt_xml_tag_t *xml_tag" "uint16_t *utf16_string" "size_t utf16_string_size" "libfwevt_error_t **error" .Ft int -.Fn libfwevt_xml_tag_get_utf8_value_size "libfwevt_xml_tag_t *xml_tag" "size_t *utf8_string_size" "libfwevt_error_t **error" -.Ft int -.Fn libfwevt_xml_tag_get_utf8_value "libfwevt_xml_tag_t *xml_tag" "uint8_t *utf8_string" "size_t utf8_string_size" "libfwevt_error_t **error" -.Ft int -.Fn libfwevt_xml_tag_get_utf16_value_size "libfwevt_xml_tag_t *xml_tag" "size_t *utf16_string_size" "libfwevt_error_t **error" -.Ft int -.Fn libfwevt_xml_tag_get_utf16_value "libfwevt_xml_tag_t *xml_tag" "uint16_t *utf16_string" "size_t utf16_string_size" "libfwevt_error_t **error" +.Fn libfwevt_xml_tag_get_value "libfwevt_xml_tag_t *xml_tag" "libfwevt_xml_value_t **xml_value" "libfwevt_error_t **error" .Ft int .Fn libfwevt_xml_tag_get_number_of_attributes "libfwevt_xml_tag_t *xml_tag" "int *number_of_attributes" "libfwevt_error_t **error" .Ft int diff --git a/msvscpp/Makefile.am b/msvscpp/Makefile.am index 4ca36a4..17b3dfa 100644 --- a/msvscpp/Makefile.am +++ b/msvscpp/Makefile.am @@ -17,6 +17,7 @@ MSVSCPP_FILES = \ fwevt_test_xml_tag/fwevt_test_xml_tag.vcproj \ fwevt_test_xml_template_value/fwevt_test_xml_template_value.vcproj \ fwevt_test_xml_token/fwevt_test_xml_token.vcproj \ + fwevt_test_xml_value/fwevt_test_xml_value.vcproj \ libcdata/libcdata.vcproj \ libcerror/libcerror.vcproj \ libcnotify/libcnotify.vcproj \ diff --git a/msvscpp/fwevt_test_xml_value/fwevt_test_xml_value.vcproj b/msvscpp/fwevt_test_xml_value/fwevt_test_xml_value.vcproj new file mode 100644 index 0000000..0ea9fe9 --- /dev/null +++ b/msvscpp/fwevt_test_xml_value/fwevt_test_xml_value.vcproj @@ -0,0 +1,230 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/msvscpp/libfwevt.sln b/msvscpp/libfwevt.sln index 4230c21..2d51537 100644 --- a/msvscpp/libfwevt.sln +++ b/msvscpp/libfwevt.sln @@ -143,6 +143,12 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fwevt_test_xml_token", "fwe {C5D33EBC-535D-474C-870A-B96A4B30850D} = {C5D33EBC-535D-474C-870A-B96A4B30850D} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fwevt_test_xml_value", "fwevt_test_xml_value\fwevt_test_xml_value.vcproj", "{703A33A3-1A6A-4D9C-B25F-F84BE52BAEA3}" + ProjectSection(ProjectDependencies) = postProject + {B97706AC-46E5-4C2A-836E-582A74DC6A68} = {B97706AC-46E5-4C2A-836E-582A74DC6A68} + {C5D33EBC-535D-474C-870A-B96A4B30850D} = {C5D33EBC-535D-474C-870A-B96A4B30850D} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libuna", "libuna\libuna.vcproj", "{5C6EAD13-CCA8-4B03-8495-EEE2E3092468}" ProjectSection(ProjectDependencies) = postProject {C5D33EBC-535D-474C-870A-B96A4B30850D} = {C5D33EBC-535D-474C-870A-B96A4B30850D} @@ -269,6 +275,10 @@ Global {6AEB4E37-792D-490D-95A5-1A855C166C1B}.Release|Win32.Build.0 = Release|Win32 {6AEB4E37-792D-490D-95A5-1A855C166C1B}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 {6AEB4E37-792D-490D-95A5-1A855C166C1B}.VSDebug|Win32.Build.0 = VSDebug|Win32 + {703A33A3-1A6A-4D9C-B25F-F84BE52BAEA3}.Release|Win32.ActiveCfg = Release|Win32 + {703A33A3-1A6A-4D9C-B25F-F84BE52BAEA3}.Release|Win32.Build.0 = Release|Win32 + {703A33A3-1A6A-4D9C-B25F-F84BE52BAEA3}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 + {703A33A3-1A6A-4D9C-B25F-F84BE52BAEA3}.VSDebug|Win32.Build.0 = VSDebug|Win32 {5C6EAD13-CCA8-4B03-8495-EEE2E3092468}.Release|Win32.ActiveCfg = Release|Win32 {5C6EAD13-CCA8-4B03-8495-EEE2E3092468}.Release|Win32.Build.0 = Release|Win32 {5C6EAD13-CCA8-4B03-8495-EEE2E3092468}.VSDebug|Win32.ActiveCfg = VSDebug|Win32 diff --git a/tests/Makefile.am b/tests/Makefile.am index ae215e8..ac36b7e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -52,7 +52,8 @@ check_PROGRAMS = \ fwevt_test_xml_document \ fwevt_test_xml_tag \ fwevt_test_xml_template_value \ - fwevt_test_xml_token + fwevt_test_xml_token \ + fwevt_test_xml_value fwevt_test_channel_SOURCES = \ fwevt_test_channel.c \ @@ -266,6 +267,20 @@ fwevt_test_xml_token_LDADD = \ ../libfwevt/libfwevt.la \ @LIBCERROR_LIBADD@ +fwevt_test_xml_value_SOURCES = \ + fwevt_test_libcerror.h \ + fwevt_test_libfvalue.h \ + fwevt_test_libfwevt.h \ + fwevt_test_libuna.h \ + fwevt_test_macros.h \ + fwevt_test_memory.c fwevt_test_memory.h \ + fwevt_test_unused.h \ + fwevt_test_xml_value.c + +fwevt_test_xml_value_LDADD = \ + ../libfwevt/libfwevt.la \ + @LIBCERROR_LIBADD@ + DISTCLEANFILES = \ Makefile \ Makefile.in \ diff --git a/tests/fwevt_test_xml_tag.c b/tests/fwevt_test_xml_tag.c index 8c80ef0..fef7b12 100644 --- a/tests/fwevt_test_xml_tag.c +++ b/tests/fwevt_test_xml_tag.c @@ -513,147 +513,6 @@ int fwevt_test_xml_tag_set_name_data( return( 0 ); } -/* Tests the libfwevt_xml_tag_get_value function - * Returns 1 if successful or 0 if not - */ -int fwevt_test_xml_tag_get_value( - void ) -{ - libcerror_error_t *error = NULL; - libfwevt_xml_value_t *xml_value = NULL; - libfwevt_xml_tag_t *xml_tag = NULL; - int result = 0; - - /* Initialize test - */ - result = libfwevt_xml_tag_initialize( - &xml_tag, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - FWEVT_TEST_ASSERT_IS_NOT_NULL( - "xml_tag", - xml_tag ); - - FWEVT_TEST_ASSERT_IS_NULL( - "error", - error ); - - /* Test regular cases - */ - result = libfwevt_xml_tag_get_value( - xml_tag, - &xml_value, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - FWEVT_TEST_ASSERT_IS_NULL( - "error", - error ); - - result = libfwevt_internal_xml_value_free( - (libfwevt_internal_xml_value_t **) &xml_value, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - FWEVT_TEST_ASSERT_IS_NULL( - "xml_value", - xml_value ); - - FWEVT_TEST_ASSERT_IS_NULL( - "error", - error ); - - /* Test error cases - */ - result = libfwevt_xml_tag_get_value( - NULL, - &xml_value, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - FWEVT_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - - result = libfwevt_xml_tag_get_value( - xml_tag, - NULL, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - -1 ); - - FWEVT_TEST_ASSERT_IS_NOT_NULL( - "error", - error ); - - libcerror_error_free( - &error ); - - /* Clean up - */ - result = libfwevt_internal_xml_tag_free( - (libfwevt_internal_xml_tag_t **) &xml_tag, - &error ); - - FWEVT_TEST_ASSERT_EQUAL_INT( - "result", - result, - 1 ); - - FWEVT_TEST_ASSERT_IS_NULL( - "xml_tag", - xml_tag ); - - FWEVT_TEST_ASSERT_IS_NULL( - "error", - error ); - - return( 1 ); - -on_error: - if( error != NULL ) - { - libcerror_error_free( - &error ); - } - if( xml_value != NULL ) - { - libfwevt_internal_xml_value_free( - (libfwevt_internal_xml_value_t **) &xml_value, - NULL ); - } - if( xml_tag != NULL ) - { - libfwevt_internal_xml_tag_free( - (libfwevt_internal_xml_tag_t **) &xml_tag, - NULL ); - } - return( 0 ); -} - /* Tests the libfwevt_xml_tag_set_value_type function * Returns 1 if successful or 0 if not */ @@ -1473,6 +1332,106 @@ int fwevt_test_xml_tag_get_utf16_name( return( 0 ); } +/* Tests the libfwevt_xml_tag_get_value function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_tag_get_value( + libfwevt_xml_tag_t *xml_tag ) +{ + libcerror_error_t *error = NULL; + libfwevt_xml_value_t *xml_value = NULL; + int result = 0; + + /* Test regular cases + */ + result = libfwevt_xml_tag_get_value( + xml_tag, + &xml_value, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "xml_value", + xml_value ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfwevt_xml_value_free( + &xml_value, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "xml_value", + xml_value ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_xml_tag_get_value( + NULL, + &xml_value, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_tag_get_value( + xml_tag, + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( xml_value != NULL ) + { + libfwevt_internal_xml_value_free( + (libfwevt_internal_xml_value_t **) &xml_value, + NULL ); + } + return( 0 ); +} + /* Tests the libfwevt_xml_tag_get_utf8_value_size function * Returns 1 if successful or 0 if not */ @@ -3872,6 +3831,8 @@ int main( "libfwevt_xml_tag_free", fwevt_test_xml_tag_free ); + /* TODO: add tests for libfwevt_internal_xml_tag_free */ + FWEVT_TEST_RUN( "libfwevt_xml_tag_set_type", fwevt_test_xml_tag_set_type ); @@ -3880,10 +3841,6 @@ int main( "libfwevt_xml_tag_set_name_data", fwevt_test_xml_tag_set_name_data ); - FWEVT_TEST_RUN( - "libfwevt_xml_tag_get_value", - fwevt_test_xml_tag_get_value ); - FWEVT_TEST_RUN( "libfwevt_xml_tag_set_value_type", fwevt_test_xml_tag_set_value_type ); @@ -4004,6 +3961,11 @@ int main( fwevt_test_xml_tag_get_utf16_name, xml_tag ); + FWEVT_TEST_RUN_WITH_ARGS( + "libfwevt_xml_tag_get_value", + fwevt_test_xml_tag_get_value, + xml_tag ); + FWEVT_TEST_RUN_WITH_ARGS( "libfwevt_xml_tag_get_utf8_value_size", fwevt_test_xml_tag_get_utf8_value_size, diff --git a/tests/fwevt_test_xml_value.c b/tests/fwevt_test_xml_value.c new file mode 100644 index 0000000..ad97537 --- /dev/null +++ b/tests/fwevt_test_xml_value.c @@ -0,0 +1,684 @@ +/* + * Library xml_value type test program + * + * Copyright (C) 2011-2024, 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 "fwevt_test_libcerror.h" +#include "fwevt_test_libfwevt.h" +#include "fwevt_test_libuna.h" +#include "fwevt_test_macros.h" +#include "fwevt_test_memory.h" +#include "fwevt_test_unused.h" + +#include "../libfwevt/libfwevt_xml_value.h" + +#if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) + +/* Tests the libfwevt_xml_value_initialize function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_value_initialize( + void ) +{ + libcerror_error_t *error = NULL; + libfwevt_xml_value_t *xml_value = NULL; + int result = 0; + +#if defined( HAVE_FWEVT_TEST_MEMORY ) + int number_of_malloc_fail_tests = 2; + int number_of_memset_fail_tests = 1; + int test_number = 0; +#endif + + /* Test regular cases + */ + result = libfwevt_xml_value_initialize( + &xml_value, + LIBFVALUE_VALUE_TYPE_BINARY_DATA, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "xml_value", + xml_value ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfwevt_internal_xml_value_free( + (libfwevt_internal_xml_value_t **) &xml_value, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "xml_value", + xml_value ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_xml_value_initialize( + NULL, + LIBFVALUE_VALUE_TYPE_BINARY_DATA, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + xml_value = (libfwevt_xml_value_t *) 0x12345678UL; + + result = libfwevt_xml_value_initialize( + &xml_value, + LIBFVALUE_VALUE_TYPE_BINARY_DATA, + &error ); + + xml_value = NULL; + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + +#if defined( HAVE_FWEVT_TEST_MEMORY ) + + for( test_number = 0; + test_number < number_of_malloc_fail_tests; + test_number++ ) + { + /* Test libfwevt_xml_value_initialize with malloc failing + */ + fwevt_test_malloc_attempts_before_fail = test_number; + + result = libfwevt_xml_value_initialize( + &xml_value, + LIBFVALUE_VALUE_TYPE_BINARY_DATA, + &error ); + + if( fwevt_test_malloc_attempts_before_fail != -1 ) + { + fwevt_test_malloc_attempts_before_fail = -1; + + if( xml_value != NULL ) + { + libfwevt_internal_xml_value_free( + (libfwevt_internal_xml_value_t **) &xml_value, + NULL ); + } + } + else + { + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "xml_value", + xml_value ); + + FWEVT_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 libfwevt_xml_value_initialize with memset failing + */ + fwevt_test_memset_attempts_before_fail = test_number; + + result = libfwevt_xml_value_initialize( + &xml_value, + LIBFVALUE_VALUE_TYPE_BINARY_DATA, + &error ); + + if( fwevt_test_memset_attempts_before_fail != -1 ) + { + fwevt_test_memset_attempts_before_fail = -1; + + if( xml_value != NULL ) + { + libfwevt_internal_xml_value_free( + (libfwevt_internal_xml_value_t **) &xml_value, + NULL ); + } + } + else + { + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "xml_value", + xml_value ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + } + } +#endif /* defined( HAVE_FWEVT_TEST_MEMORY ) */ + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( xml_value != NULL ) + { + libfwevt_internal_xml_value_free( + (libfwevt_internal_xml_value_t **) &xml_value, + NULL ); + } + return( 0 ); +} + +/* Tests the libfwevt_xml_value_free function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_value_free( + void ) +{ + libcerror_error_t *error = NULL; + int result = 0; + + /* Test error cases + */ + result = libfwevt_xml_value_free( + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_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 libfwevt_xml_value_get_type function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_value_get_type( + libfwevt_xml_value_t *xml_value ) +{ + libcerror_error_t *error = NULL; + int result = 0; + int type = 0; + + /* Test regular cases + */ + result = libfwevt_xml_value_get_type( + xml_value, + &type, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "type", + type, + LIBFVALUE_VALUE_TYPE_BINARY_DATA ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_xml_value_get_type( + NULL, + &type, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_type( + xml_value, + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_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 libfwevt_xml_value_get_number_of_value_entries function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_value_get_number_of_value_entries( + libfwevt_xml_value_t *xml_value ) +{ + libcerror_error_t *error = NULL; + int number_of_value_entries = 0; + int result = 0; + + /* Test regular cases + */ + result = libfwevt_xml_value_get_number_of_value_entries( + xml_value, + &number_of_value_entries, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "number_of_value_entries", + number_of_value_entries, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_xml_value_get_number_of_value_entries( + NULL, + &number_of_value_entries, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_number_of_value_entries( + xml_value, + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_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 libfwevt_xml_value_get_data_size function + * Returns 1 if successful or 0 if not + */ +int fwevt_test_xml_value_get_data_size( + libfwevt_xml_value_t *xml_value ) +{ + libcerror_error_t *error = NULL; + size_t data_size = 0; + int result = 0; + + /* Test regular cases + */ + result = libfwevt_xml_value_get_data_size( + xml_value, + &data_size, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_EQUAL_SIZE( + "data_size", + data_size, + (size_t) 4 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + /* Test error cases + */ + result = libfwevt_xml_value_get_data_size( + NULL, + &data_size, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + result = libfwevt_xml_value_get_data_size( + xml_value, + NULL, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + -1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "error", + error ); + + libcerror_error_free( + &error ); + + return( 1 ); + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + return( 0 ); +} + +#endif /* #if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) */ + +/* The main program + */ +#if defined( HAVE_WIDE_SYSTEM_CHARACTER ) +int wmain( + int argc FWEVT_TEST_ATTRIBUTE_UNUSED, + wchar_t * const argv[] FWEVT_TEST_ATTRIBUTE_UNUSED ) +#else +int main( + int argc FWEVT_TEST_ATTRIBUTE_UNUSED, + char * const argv[] FWEVT_TEST_ATTRIBUTE_UNUSED ) +#endif +{ +#if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) + + libcerror_error_t *error = NULL; + libfwevt_xml_value_t *xml_value = NULL; + int result = 0; + +#endif /* defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) */ + + FWEVT_TEST_UNREFERENCED_PARAMETER( argc ) + FWEVT_TEST_UNREFERENCED_PARAMETER( argv ) + +#if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) + + FWEVT_TEST_RUN( + "libfwevt_xml_value_initialize", + fwevt_test_xml_value_initialize ); + + FWEVT_TEST_RUN( + "libfwevt_xml_value_free", + fwevt_test_xml_value_free ); + + /* TODO: add tests for libfwevt_internal_xml_value_free */ + + /* TODO: add tests for libfwevt_xml_value_set_format_flags */ + + /* TODO: add tests for libfwevt_xml_value_append_data */ + + /* TODO: add tests for libfwevt_xml_value_type_set_data_string */ + +#if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) + + /* Initialize xml_value for tests + */ + result = libfwevt_xml_value_initialize( + &xml_value, + LIBFVALUE_VALUE_TYPE_BINARY_DATA, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NOT_NULL( + "xml_value", + xml_value ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + result = libfwevt_xml_value_set_data( + xml_value, + (uint8_t *) "data", + 4, + 0, + 0, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + + FWEVT_TEST_RUN_WITH_ARGS( + "libfwevt_xml_value_get_type", + fwevt_test_xml_value_get_type, + xml_value ); + + FWEVT_TEST_RUN_WITH_ARGS( + "libfwevt_xml_value_get_number_of_value_entries", + fwevt_test_xml_value_get_number_of_value_entries, + xml_value ); + + FWEVT_TEST_RUN_WITH_ARGS( + "libfwevt_xml_value_get_data_size", + fwevt_test_xml_value_get_data_size, + xml_value ); + + /* TODO: add tests for libfwevt_xml_value_copy_data */ + + /* TODO: add tests for libfwevt_xml_value_copy_to_8bit */ + + /* TODO: add tests for libfwevt_xml_value_copy_to_32bit */ + + /* TODO: add tests for libfwevt_xml_value_copy_to_64bit */ + + /* TODO: add tests for libfwevt_xml_value_get_utf8_string_size_with_index */ + + /* TODO: add tests for libfwevt_xml_value_copy_to_utf8_string_with_index */ + + /* TODO: add tests for libfwevt_xml_value_get_utf8_string_size */ + + /* TODO: add tests for libfwevt_xml_value_copy_to_utf8_string */ + + /* TODO: add tests for libfwevt_xml_value_get_utf16_string_size_with_index */ + + /* TODO: add tests for libfwevt_xml_value_copy_to_utf16_string_with_index */ + + /* TODO: add tests for libfwevt_xml_value_get_utf16_string_size */ + + /* TODO: add tests for libfwevt_xml_value_copy_to_utf16_string */ + +#if defined( HAVE_DEBUG_OUTPUT ) + + /* TODO: add tests for libfwevt_debug_print_xml_value */ + +#endif /* defined( HAVE_DEBUG_OUTPUT ) */ + + /* Clean up + */ + result = libfwevt_internal_xml_value_free( + (libfwevt_internal_xml_value_t **) &xml_value, + &error ); + + FWEVT_TEST_ASSERT_EQUAL_INT( + "result", + result, + 1 ); + + FWEVT_TEST_ASSERT_IS_NULL( + "xml_value", + xml_value ); + + FWEVT_TEST_ASSERT_IS_NULL( + "error", + error ); + +#endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */ + +#endif /* #if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) */ + + return( EXIT_SUCCESS ); + +#if defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) + +on_error: + if( error != NULL ) + { + libcerror_error_free( + &error ); + } + if( xml_value != NULL ) + { + libfwevt_internal_xml_value_free( + (libfwevt_internal_xml_value_t **) &xml_value, + NULL ); + } + return( EXIT_FAILURE ); + +#endif /* defined( __GNUC__ ) && !defined( LIBFWEVT_DLL_IMPORT ) */ +} + diff --git a/tests/test_library.ps1 b/tests/test_library.ps1 index 9a1d81e..dfa97fa 100644 --- a/tests/test_library.ps1 +++ b/tests/test_library.ps1 @@ -6,7 +6,7 @@ $ExitSuccess = 0 $ExitFailure = 1 $ExitIgnore = 77 -$LibraryTests = "channel error event keyword level manifest map notify opcode provider support task template xml_document xml_tag xml_template_value xml_token" +$LibraryTests = "channel error event keyword level manifest map notify opcode provider support task template xml_document xml_tag xml_template_value xml_token xml_value" $LibraryTestsWithInput = "" $OptionSets = "" diff --git a/tests/test_library.sh b/tests/test_library.sh index f612e1f..d115da8 100755 --- a/tests/test_library.sh +++ b/tests/test_library.sh @@ -7,7 +7,7 @@ EXIT_SUCCESS=0; EXIT_FAILURE=1; EXIT_IGNORE=77; -LIBRARY_TESTS="channel error event keyword level manifest map notify opcode provider support task template xml_document xml_tag xml_template_value xml_token"; +LIBRARY_TESTS="channel error event keyword level manifest map notify opcode provider support task template xml_document xml_tag xml_template_value xml_token xml_value"; LIBRARY_TESTS_WITH_INPUT=""; OPTION_SETS=();