1
0
mirror of https://github.com/pevans/erc-c.git synced 2024-11-18 22:06:01 +00:00
erc-c/tests/log.c

34 lines
805 B
C
Raw Normal View History

2017-12-02 19:05:53 +00:00
#include <criterion/criterion.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "log.h"
Test(log, write) {
char message[] = "we write the logs";
char message_buffer[128];
FILE *fp;
int message_length;
message_length = strlen(message);
2017-12-06 22:53:15 +00:00
log_open(NULL);
2017-12-02 19:05:53 +00:00
log_write(0, message);
log_close();
fp = fopen(LOG_FILENAME, "r");
cr_assert_neq(fp, NULL, "Unable to open " LOG_FILENAME);
fread(message_buffer, sizeof(char), sizeof(message), fp);
message_buffer[message_length] = '\0';
cr_assert_str_eq(message_buffer,
message,
"log_write() did not write correct data ([%s], [%s])",
message_buffer,
message);
fclose(fp);
unlink(LOG_FILENAME);
}