made why2-test failure much better for debugging & made it more variable

I hope I am deallocating all new things :D
This commit is contained in:
Václav Šmejkal 2022-07-23 15:37:54 +02:00
parent cfdfd2aa2c
commit a0ebfd19e2
No known key found for this signature in database
GPG Key ID: FD749A97DF2D5E19

View File

@ -9,8 +9,11 @@ int main(void)
//VARIABLES //VARIABLES
char *textBuffer = malloc(128); char *textBuffer = malloc(128);
char *keyBuffer; char *keyBuffer;
char *statusBuffer;
char *outputBuffer = malloc(1); //THIS IS TEMP ALLOCATION
int exitCode = 0; int exitCode = 0;
unsigned long timeBuffer; unsigned long timeBuffer;
FILE *outputStreamBuffer = stdout;
//FLAGS //FLAGS
inputFlags flags = inputFlags flags =
@ -30,6 +33,9 @@ int main(void)
//SET ENCRYPTION_SEPARATOR TO '|' //SET ENCRYPTION_SEPARATOR TO '|'
setEncryptionSeparator('|'); setEncryptionSeparator('|');
//SET outputBuffer to NULL
outputBuffer[0] = '\0';
//ENCRYPT //ENCRYPT
outputFlags encrypted = encryptText(TEST_TEXT, NULL); outputFlags encrypted = encryptText(TEST_TEXT, NULL);
@ -46,31 +52,44 @@ int main(void)
timeBuffer += encrypted.elapsedTime; //GET TIME 1 timeBuffer += encrypted.elapsedTime; //GET TIME 1
//COMPARE DIFFERENCE //COMPARE DIFFERENCE
if (strcmp(encrypted.outputText, TEST_TEXT) == 0 && encrypted.exitCode == 0) if (strcmp(encrypted.outputText, TEST_TEXT) == 0 && encrypted.exitCode == 0) //SUCCESS
{ {
printf statusBuffer = malloc(11);
( strcpy(statusBuffer, "successful");
"Test successful!\n\n" }
else //FAILURE
{
statusBuffer = malloc(8);
strcpy(statusBuffer, "failed");
"TEXT: \t\t\"%s\"\n" outputBuffer = realloc(outputBuffer, strlen(encrypted.outputText) + 6);
sprintf(outputBuffer, "\t\t\"%s\"\n", encrypted.outputText);
outputStreamBuffer = stderr;
exitCode = 1;
}
//PRINT OUTPUT
fprintf
(
outputStreamBuffer,
"Test %s!\n\n"
"TEXT: \t\t\"%s\"\n%s"
"OUTPUT: \t\"%s\"\n" "OUTPUT: \t\"%s\"\n"
"KEY: \t\t\"%s\"\n" "KEY: \t\t\"%s\"\n"
"TIME: \t\t\"%lums\"\n" "TIME: \t\t\"%lums\"\n"
"UNUSED KEY: \t\"%lu\"\n" "UNUSED KEY: \t\"%lu\"\n"
"EXIT CODE: \t\"%d\"\n" "EXIT CODE: \t\"%d\"\n"
, TEST_TEXT, textBuffer, encrypted.usedKey, timeBuffer / 1000, encrypted.unusedKeySize, encrypted.exitCode , statusBuffer, TEST_TEXT, outputBuffer, textBuffer, encrypted.usedKey, timeBuffer / 1000, encrypted.unusedKeySize, encrypted.exitCode
); );
}
else
{
fprintf(stderr, "Test failed! (%u)\n\n%s // %s\n", encrypted.exitCode, encrypted.outputText, TEST_TEXT);
exitCode = 1;
}
//DEALLOCATION //DEALLOCATION
free(textBuffer); free(textBuffer);
free(keyBuffer); free(keyBuffer);
free(statusBuffer);
deallocateOutput(encrypted); deallocateOutput(encrypted);
return exitCode; return exitCode;