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:
parent
cfdfd2aa2c
commit
a0ebfd19e2
@ -9,8 +9,11 @@ int main(void)
|
||||
//VARIABLES
|
||||
char *textBuffer = malloc(128);
|
||||
char *keyBuffer;
|
||||
char *statusBuffer;
|
||||
char *outputBuffer = malloc(1); //THIS IS TEMP ALLOCATION
|
||||
int exitCode = 0;
|
||||
unsigned long timeBuffer;
|
||||
FILE *outputStreamBuffer = stdout;
|
||||
|
||||
//FLAGS
|
||||
inputFlags flags =
|
||||
@ -30,6 +33,9 @@ int main(void)
|
||||
//SET ENCRYPTION_SEPARATOR TO '|'
|
||||
setEncryptionSeparator('|');
|
||||
|
||||
//SET outputBuffer to NULL
|
||||
outputBuffer[0] = '\0';
|
||||
|
||||
//ENCRYPT
|
||||
outputFlags encrypted = encryptText(TEST_TEXT, NULL);
|
||||
|
||||
@ -46,31 +52,44 @@ int main(void)
|
||||
timeBuffer += encrypted.elapsedTime; //GET TIME 1
|
||||
|
||||
//COMPARE DIFFERENCE
|
||||
if (strcmp(encrypted.outputText, TEST_TEXT) == 0 && encrypted.exitCode == 0)
|
||||
if (strcmp(encrypted.outputText, TEST_TEXT) == 0 && encrypted.exitCode == 0) //SUCCESS
|
||||
{
|
||||
printf
|
||||
(
|
||||
"Test successful!\n\n"
|
||||
statusBuffer = malloc(11);
|
||||
strcpy(statusBuffer, "successful");
|
||||
}
|
||||
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"
|
||||
"KEY: \t\t\"%s\"\n"
|
||||
"TIME: \t\t\"%lums\"\n"
|
||||
"UNUSED KEY: \t\"%lu\"\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
|
||||
free(textBuffer);
|
||||
free(keyBuffer);
|
||||
free(statusBuffer);
|
||||
deallocateOutput(encrypted);
|
||||
|
||||
return exitCode;
|
||||
|
Loading…
x
Reference in New Issue
Block a user