Skip to content

Commit

Permalink
Fix a bug in the auxilliary function unsigned_integerArray_generate_a…
Browse files Browse the repository at this point in the history
…ligned_str and clean the std macro files.
  • Loading branch information
ArturAssisComp committed Aug 8, 2021
1 parent dd9ce68 commit c85037a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 110 deletions.
6 changes: 4 additions & 2 deletions ctest_library/assert/std_assert_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -2560,7 +2560,7 @@ static char *unsigned_integerArray_generate_aligned_str(unsigned_integer target_
//------------------------------------------------------------------------------
//Declare local varibles:
char *result;
char number_buffer[100];
char number_buffer[50];
size_t current_buffer_size = 100, buffer_chars_used = 0;


Expand Down Expand Up @@ -2607,9 +2607,10 @@ static char *unsigned_integerArray_generate_aligned_str(unsigned_integer target_
}

//Check if there is enough space:
while(buffer_chars_used >= current_buffer_size)
if(buffer_chars_used + n >= current_buffer_size)
{
//Allocate more memory:
current_buffer_size = buffer_chars_used;
current_buffer_size *= 2;
result = realloc(result, sizeof *result * current_buffer_size);
if(!result)
Expand Down Expand Up @@ -2638,6 +2639,7 @@ static char *unsigned_integerArray_generate_aligned_str(unsigned_integer target_

static char *unsigned_integerArray_compared_equal_generate_str(unsigned_integer arr1[], size_t arr1_size, unsigned_integer arr2[], size_t arr2_size, char equal_symbol, char diff_symbol)
{
;
}

static int num_of_digits(unsigned_integer number)
Expand Down
108 changes: 0 additions & 108 deletions ctest_library/assert/std_assert_macros.h
Original file line number Diff line number Diff line change
@@ -1,108 +0,0 @@
/**
* Author: Artur Assis Alves
* Date: 15/05/2021
* Title: Assert macro file.
*/

/**
* Description: This file contains the standard assert macros.
*/

#include "../globals/globals.h"
#include <stdio.h>
#include <stdbool.h>

//Definitions of assert macros:
/*STD assert macros for unsigned_integer type*/

#define ASSERT_UNSIGNED_INTEGER_ARRAY_EQUAL(TARGET_ARRAY,\
TARGET_ARRAY_SIZE,\
REFERENCE_ARRAY,\
REFERENCE_ARRAY_SIZE,\
LINE_NUMBER, CUSTOM_MESSAGE) \
{\
/*------------------------------------------------------------------------------*/\
/*Define and initialize the variables:*/\
int counter;\
const int max_error_msg_sz = 128;\
bool error = false;\
char function_error_message[max_error_msg_sz];\
char assert_name[] = "ASSERT_UNSIGNED_INTEGER_ARRAY_EQUAL";\
char std_message[] = "The target array SHOULD BE EQUAL to the reference array.";\
\
/*Macro parameters*/\
size_t target_array_size = (TARGET_ARRAY_SIZE), reference_array_size = (REFERENCE_ARRAY_SIZE);\
int line_number = (LINE_NUMBER);\
char *custom_message = (CUSTOM_MESSAGE);\
\
/*Reset global result (reset to success with details empty):*/\
reset_global_result();\
\
/*------------------------------------------------------------------------------*/\
/*Check for ignore:*/\
if(ignore)\
goto print;\
\
/*------------------------------------------------------------------------------*/\
/*Execute the test:*/\
if(target_array_size == reference_array_size)\
{\
global_result.was_successful = true;\
\
size_t i;\
for(i = 0; i < target_array_size; i++)\
{\
if((TARGET_ARRAY)[i] != (REFERENCE_ARRAY)[i])\
{\
global_result.was_successful = false;\
break;\
}\
}\
}\
else/*Arrays have different size*/\
{\
global_result.was_successful = false;\
}\
\
/*Check if it is necessary to generate highly verbose details in case of fail:*/\
if(!global_result.was_successful && verbose == HIGH)\
{\
/*------------------------------------------------------------------------------*/\
/*Generate the details for a highly verbose fail message:*/\
counter = snprintf(global_result.result_details, \
MAX_CHARS,\
"> OK\n"\
);\
\
/*------------------------------------------------------------------------------*/\
/*Check for error:*/\
if (counter < 0) \
{\
/*Error creating the result message.*/\
error = true;\
snprintf(function_error_message, \
max_error_msg_sz, \
"\nError while generating the result message (at line %d).\n",\
line_number\
);\
goto finish;\
}\
/*------------------------------------------------------------------------------*/\
}\
\
/*------------------------------------------------------------------------------*/\
/*Print the result:*/\
print:\
print_result(assert_name, std_message, custom_message, line_number);\
\
/*------------------------------------------------------------------------------*/\
/*Finish:*/\
finish:\
if(error)\
{\
fprintf(stderr, function_error_message);\
exit(EXIT_FAILURE);\
}\
\
/*------------------------------------------------------------------------------*/\
}

0 comments on commit c85037a

Please sign in to comment.