Commit a1e484e9 authored by Greg Williams's avatar Greg Williams
Browse files

Cleaned up kinetic_logger tests and file contents assertion to hopefully fix...

Cleaned up kinetic_logger tests and file contents assertion to hopefully fix crash in Ubuntu-64-bit/Travis
parent e4b405dd
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@
*
*/

#include "kinetic_logger.h"
#include "unity_helper.h"
#include "kinetic_logger.h"

void setUp(void)
{
@@ -38,10 +38,7 @@ void test_KineticLogger_KINETIC_LOG_FILE_should_be_defined_properly(void)

void test_KineticLogger_Init_should_initialize_the_logger_with_specified_output_file(void)
{
    char cwd[1024], test_file[1024];
    GET_CWD(cwd);
    sprintf(test_file, "%s/%s", cwd, TEST_LOG_FILE);
    KineticLogger_Init(test_file);
    KineticLogger_Init(TEST_LOG_FILE);

    TEST_ASSERT_FILE_EXISTS(TEST_LOG_FILE);
}
+7 −7
Original line number Diff line number Diff line
@@ -84,7 +84,7 @@ if (expected != actual) { \
/** Custom Unity assertion which validates the contents of a file ('len' - length in bytes) */
#define TEST_ASSERT_EQUAL_FILE_CONTENT(fname, content, len) { \
    FILE* f; \
    char c, buff[len], err[1024 + len]; \
    char c, buff[len], err[1024 + len] = ""; \
    size_t actualLen; \
    TEST_ASSERT_FILE_EXISTS(fname); \
    f = fopen(fname, "r"); \
@@ -94,13 +94,13 @@ if (expected != actual) { \
        if (c == EOF) { printf("EOF found! EOF: 0x%02X", (int)c); break; } \
        buff[actualLen] = c; } \
    buff[actualLen] = '\0'; /* Append NULL terminator */ \
    if (c == EOF) { \
        sprintf(err, "End-of-file unexpectedly reached when length expected to be " \
        "at least %lld at byte %lld in file: '%s'", \
        (long long int)len, (long long int)actualLen, fname); \
            "at least %zd at byte %zd in file: '%s'", \
            (size_t)len, actualLen, fname); } \
    TEST_ASSERT_NOT_EQUAL_MESSAGE(EOF, c, err); \
    sprintf(err, "Failed reading %d bytes from file: %s\n  read: %s", (int)len, fname, buff); \
    TEST_ASSERT_EQUAL_SIZET_MESSAGE(len, actualLen, "File read error (truncated?)"); \
    TEST_ASSERT_EQUAL_STRING_MESSAGE(content, buff, "File contents did not match"); \
    TEST_ASSERT_EQUAL_SIZET_MESSAGE(len, actualLen, "File read error (truncated?)! read: " err); \
    TEST_ASSERT_EQUAL_STRING_MESSAGE(content, buff, "File contents did not match! read:" err); \
    TEST_ASSERT_EQUAL_MESSAGE(0, fclose(f), "Failed closing file: " #fname ); \
    fclose(f); \
}