Zadania rekrutacyjne i ćwiczeniowe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

54 lines
990 B

#include "log/Log.h"
#include <stdio.h>
#include <unistd.h>
#include <assert.h>
#define TAG "TEST"
static const char* LOG_FILE = "/tmp/log-test.log";
static int countLines(const char* filePath) {
int count = 0;
int ch;
FILE* file = fopen(filePath, "r");
if (file == NULL) {
return -1;
}
while ((ch = fgetc(file)) != EOF) {
if (ch == '\n') {
count++;
}
}
fclose(file);
return count;
}
int main(void)
{
int lineCount = 0;
initLogger(LOG_FILE);
clearLogs();
lineCount = countLines(LOG_FILE);
assert(lineCount == 0);
writeLog(TAG, "First log message");
writeLog(TAG, "Second log message");
writeLog(TAG, "Third log message");
lineCount = countLines(LOG_FILE);
assert(lineCount == 3);
writeLog(TAG, "This is %ith line that is %s", 4, "formatted");
lineCount = countLines(LOG_FILE);
assert(lineCount == 4);
closeLogger();
printf("Log file %s contains %d lines\n", LOG_FILE, lineCount);
return 0;
}