Skip to content

Commit

Permalink
Worked on tests and Windows test scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Sep 24, 2016
1 parent 2dbd57a commit 166602c
Show file tree
Hide file tree
Showing 9 changed files with 199 additions and 19 deletions.
3 changes: 3 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ before_build:
build:
project: vs2010\libevtx.sln

test_script:
- ps: .\runtests.ps1

2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ( 2.59 )

AC_INIT(
[libevtx],
[20160902],
[20160924],
[joachim.metz@gmail.com])

AC_CONFIG_SRCDIR(
Expand Down
59 changes: 59 additions & 0 deletions runtests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Script that runs the tests
#
# Version: 20160913

$ExitSuccess = 0
$ExitFailure = 1
$ExitIgnore = 77

Set-Location -Path "tests"

Try
{
$Lines = Get-Content "Makefile.am"
$InTests = $FALSE

foreach (${Line} in ${Lines})
{
If (${InTests})
{
If (-Not ${Line})
{
${InTests} = $FALSE

Continue
}
${Line} = ${Line}.TrimStart()

If (${Line}.EndsWith(" \"))
{
${Line} = ${Line}.Substring(0, ${Line}.Length - 2)
}
If (${Line}.EndsWith(".sh"))
{
${Line} = ${Line}.Substring(0, ${Line}.Length - 3)
${Line} = ".\${Line}.ps1"
}
Invoke-Expression ${Line}

if (${LastExitCode} -ne ${ExitSuccess})
{
Break
}
}
ElseIf (${Line}.StartsWith("TESTS = "))
{
${InTests} = $TRUE
}
}
}
Catch
{
${LastExitCode} = ${ExitFailure}
}
Finally
{
Set-Location -Path ".."
}

Exit ${LastExitCode}
4 changes: 2 additions & 2 deletions synclibs.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Script that synchronizes the local library dependencies
#
# Version: 20160318
# Version: 20160912

$GitUrlPrefix = "https://github.com/libyal"
$LocalLibs = @("libbfio","libcdata","libcdirectory","libcerror","libcfile","libclocale","libcnotify","libcpath","libcsplit","libcstring","libcsystem","libcthreads","libexe","libfcache","libfdata","libfdatetime","libfguid","libfvalue","libfwevt","libfwnt","libregf","libuna","libwrc")
$LocalLibs = "libbfio libcdata libcdirectory libcerror libcfile libclocale libcnotify libcpath libcsplit libcstring libcsystem libcthreads libexe libfcache libfdata libfdatetime libfguid libfvalue libfwevt libfwnt libregf libuna libwrc" -split " "

foreach (${LocalLib} in ${LocalLibs})
{
Expand Down
20 changes: 19 additions & 1 deletion synclibs.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh
# Script that synchronizes the local library dependencies
#
# Version: 20160320
# Version: 20160912

GIT_URL_PREFIX="https://github.com/libyal";
LOCAL_LIBS="libbfio libcdata libcdirectory libcerror libcfile libclocale libcnotify libcpath libcsplit libcstring libcsystem libcthreads libexe libfcache libfdata libfdatetime libfguid libfvalue libfwevt libfwnt libregf libuna libwrc";
Expand Down Expand Up @@ -102,6 +102,24 @@ SED_SCRIPT="/^$/ {
sed -i'~' -f ${LOCAL_LIB}-$$.sed ${LOCAL_LIB_MAKEFILE_AM};
rm -f ${LOCAL_LIB}-$$.sed;

# Make the necessary changes to libcfile/Makefile.am
if test ${LOCAL_LIB} = "libcfile";
then
if ! test -f "m4/libuna.m4";
then
sed -i'~' 's?@LIBUNA_CPPFLAGS@?-I$(top_srcdir)/libuna?' ${LOCAL_LIB_MAKEFILE_AM};
fi
fi

# Make the necessary changes to libcsystem/Makefile.am
if test ${LOCAL_LIB} = "libcsystem";
then
if ! test -f "m4/libuna.m4";
then
sed -i'~' 's?@LIBUNA_CPPFLAGS@?-I$(top_srcdir)/libuna?' ${LOCAL_LIB_MAKEFILE_AM};
fi
fi

# Make the necessary changes to libfvalue/Makefile.am
if test ${LOCAL_LIB} = "libfvalue";
then
Expand Down
72 changes: 68 additions & 4 deletions tests/evtx_test_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,52 @@
#if !defined( _EVTX_TEST_MACROS_H )
#define _EVTX_TEST_MACROS_H

#include <common.h>
#include <file_stream.h>

/* TODO: deprecated replace by EVTX_TEST_ASSERT_EQUAL_INT */
#define EVTX_TEST_ASSERT_EQUAL( name, value, expected_value ) \
#if defined( HAVE_STDLIB_H ) || defined( WINAPI )
#include <stdlib.h>
#endif

#define EVTX_TEST_ASSERT_EQUAL_INT( name, value, expected_value ) \
if( value != expected_value ) \
{ \
fprintf( stdout, "%s:%d %s != %d\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

#define EVTX_TEST_ASSERT_EQUAL_INT( name, value, expected_value ) \
#define EVTX_TEST_ASSERT_NOT_EQUAL_INT( name, value, expected_value ) \
if( value == expected_value ) \
{ \
fprintf( stdout, "%s:%d %s == %d\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

#define EVTX_TEST_ASSERT_GREATER_THAN_INT( name, value, expected_value ) \
if( value <= expected_value ) \
{ \
fprintf( stdout, "%s:%d %s <= %d\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

#define EVTX_TEST_ASSERT_LESS_THAN_INT( name, value, expected_value ) \
if( value >= expected_value ) \
{ \
fprintf( stdout, "%s:%d %s >= %d\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

#define EVTX_TEST_ASSERT_EQUAL_SSIZE( name, value, expected_value ) \
if( value != expected_value ) \
{ \
fprintf( stdout, "%s:%d %s != %d\n", __FILE__, __LINE__, name, expected_value ); \
fprintf( stdout, "%s:%d %s != %" PRIzd "\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

#define EVTX_TEST_ASSERT_EQUAL_INT32( name, value, expected_value ) \
if( value != expected_value ) \
{ \
fprintf( stdout, "%s:%d %s != %" PRIi32 "\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

Expand All @@ -46,13 +78,34 @@
goto on_error; \
}

#define EVTX_TEST_ASSERT_LESS_THAN_UINT32( name, value, expected_value ) \
if( value >= expected_value ) \
{ \
fprintf( stdout, "%s:%d %s >= %" PRIu32 "\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

#define EVTX_TEST_ASSERT_EQUAL_INT64( name, value, expected_value ) \
if( value != expected_value ) \
{ \
fprintf( stdout, "%s:%d %s != %" PRIi64 "\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

#define EVTX_TEST_ASSERT_EQUAL_UINT64( name, value, expected_value ) \
if( value != expected_value ) \
{ \
fprintf( stdout, "%s:%d %s != %" PRIu64 "\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

#define EVTX_TEST_ASSERT_LESS_THAN_UINT64( name, value, expected_value ) \
if( value >= expected_value ) \
{ \
fprintf( stdout, "%s:%d %s >= %" PRIu64 "\n", __FILE__, __LINE__, name, expected_value ); \
goto on_error; \
}

#define EVTX_TEST_ASSERT_IS_NOT_NULL( name, value ) \
if( value == NULL ) \
{ \
Expand All @@ -74,5 +127,16 @@
goto on_error; \
}

#if !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 )

#define EVTX_TEST_RUN_WITH_ARGS( name, function, ... ) \
if( function( __VA_ARGS__ ) != 1 ) \
{ \
fprintf( stdout, "Unable to run test: %s\n", name ); \
goto on_error; \
}

#endif /* !defined( __BORLANDC__ ) || ( __BORLANDC__ >= 0x0560 ) */

#endif /* !defined( _EVTX_TEST_MACROS_H ) */

16 changes: 8 additions & 8 deletions tests/evtx_test_memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void *malloc(
if( evtx_test_real_malloc == NULL )
{
evtx_test_real_malloc = dlsym(
RTLD_NEXT,
"malloc" );
RTLD_NEXT,
"malloc" );
}
if( evtx_test_malloc_attempts_before_fail == 0 )
{
Expand Down Expand Up @@ -86,8 +86,8 @@ void *memcpy(
if( evtx_test_real_memcpy == NULL )
{
evtx_test_real_memcpy = dlsym(
RTLD_NEXT,
"memcpy" );
RTLD_NEXT,
"memcpy" );
}
if( evtx_test_memcpy_attempts_before_fail == 0 )
{
Expand Down Expand Up @@ -119,8 +119,8 @@ void *memset(
if( evtx_test_real_memset == NULL )
{
evtx_test_real_memset = dlsym(
RTLD_NEXT,
"memset" );
RTLD_NEXT,
"memset" );
}
if( evtx_test_memset_attempts_before_fail == 0 )
{
Expand Down Expand Up @@ -151,8 +151,8 @@ void *realloc(
if( evtx_test_real_realloc == NULL )
{
evtx_test_real_realloc = dlsym(
RTLD_NEXT,
"realloc" );
RTLD_NEXT,
"realloc" );
}
if( evtx_test_realloc_attempts_before_fail == 0 )
{
Expand Down
37 changes: 37 additions & 0 deletions tests/test_api_functions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Library API functions testing script
#
# Version: 20160912

$ExitSuccess = 0
$ExitFailure = 1
$ExitIgnore = 77

$TestPrefix = Split-Path -path ${Pwd}.Path -parent
$TestPrefix = Split-Path -path ${TestPrefix} -leaf
$TestPrefix = ${TestPrefix}.Substring(3)

$TestFunctions = "get_version error" -split " "

$TestToolDirectory = "..\vs2010\Release"

Function TestAPIFunction
{
param( [string]$TestFunction, [string[]]$Options, [string]$Profile )

$TestExecutable = "${TestToolDirectory}\${TestPrefix}_test_${TestFunction}.exe"

Invoke-Expression ${TestExecutable}
}

Foreach (${TestFunction} in ${TestFunctions})
{
TestAPIFunction ${TestFunction}

if (${LastExitCode} -ne ${ExitSuccess})
{
Break
}
}

Exit ${LastExitCode}

5 changes: 2 additions & 3 deletions tests/test_api_functions.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
# Library API functions testing script
#
# Version: 20160420
# Version: 20160918

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
Expand All @@ -26,7 +26,6 @@ test_api_function()
local OPTION_SETS=$3;

local TEST_TOOL="${TEST_PREFIX}_test_${TEST_FUNCTION}";

local TEST_EXECUTABLE="${TEST_TOOL_DIRECTORY}/${TEST_TOOL}";

if ! test -x "${TEST_EXECUTABLE}";
Expand Down Expand Up @@ -56,8 +55,8 @@ test_api_function_with_input()
local OPTION_SETS=$3;
local INPUT_DIRECTORY=$4;
local INPUT_GLOB=$5;
local TEST_TOOL="${TEST_PREFIX}_test_${TEST_FUNCTION}";

local TEST_TOOL="${TEST_PREFIX}_test_${TEST_FUNCTION}";
local TEST_EXECUTABLE="${TEST_TOOL_DIRECTORY}/${TEST_TOOL}";

if ! test -x "${TEST_EXECUTABLE}";
Expand Down

0 comments on commit 166602c

Please sign in to comment.