Compare commits
15 Commits
4c29f89c9d
...
397cdf5293
Author | SHA1 | Date |
---|---|---|
Pradana Aumars | 397cdf5293 | |
Pradana Aumars | f5230ae3d5 | |
Pradana Aumars | fce41edbe5 | |
Pradana Aumars | fc0f657774 | |
Pradana Aumars | d15c8a688e | |
Pradana Aumars | a72786a38f | |
Pradana Aumars | 24ac0e4897 | |
Pradana Aumars | f9f8ce747a | |
Pradana Aumars | 0794691f5a | |
Pradana Aumars | 72f71d4e2b | |
Pradana Aumars | 84cf1b0818 | |
Pradana Aumars | 208cb375e1 | |
Pradana Aumars | ea37ce1732 | |
Pradana Aumars | a6227b8481 | |
Pradana Aumars | 8f72eabf1f |
|
@ -1,11 +1,22 @@
|
||||||
bin_PROGRAMS = modetw
|
bin_PROGRAMS = modetw
|
||||||
lib_LTLIBRARIES = libfile_t.la
|
lib_LTLIBRARIES = libmodetw.la
|
||||||
|
|
||||||
modetw_SOURCES = main.c calibrate.c exception_t.c file_t.c conf.c
|
CFILES = \
|
||||||
modetw_CPPFLAGS = $(XML_CPPFLAGS)
|
exception_t.c \
|
||||||
modetw_CFLAGS = $(GLIB_CFLAGS)
|
file_t.c \
|
||||||
modetw_LDFLAGS= $(XML_LIBS) $(GLIB_LIBS)
|
calibrate.c \
|
||||||
|
conf.c
|
||||||
|
HFILES = \
|
||||||
|
exception_t.h \
|
||||||
|
file_t.h \
|
||||||
|
calibrate.h \
|
||||||
|
conf.h
|
||||||
|
|
||||||
libfile_t_la_SOURCES = file_t.c file_t.h
|
modetw_SOURCES = main.c
|
||||||
|
modetw_LDADD = libmodetw.la
|
||||||
|
|
||||||
|
libmodetw_la_SOURCES = $(CFILES) $(HFILES)
|
||||||
|
libmodetw_la_CPPFLAGS = $(XML_CPPFLAGS)
|
||||||
|
libmodetw_la_CFLAGS = $(GLIB_CFLAGS)
|
||||||
|
libmodetw_la_LDFLAGS= $(XML_LIBS) $(GLIB_LIBS)
|
||||||
|
|
||||||
modetw_LDADD = libfile_t.la
|
|
||||||
|
|
|
@ -192,7 +192,7 @@ verify(exception_t *e)
|
||||||
file_t *f;
|
file_t *f;
|
||||||
xmlNode *x_name = b_node->children;
|
xmlNode *x_name = b_node->children;
|
||||||
xmlNode *x_sum = x_name->next;
|
xmlNode *x_sum = x_name->next;
|
||||||
f = file_init((char*) x_name->content, e, "HOME");
|
f = file_init((char*) x_name->content, FILEPATH_ABSOLUTE, e);
|
||||||
if (strcmp(f->hash_str, (char*) x_sum->content) != 0)
|
if (strcmp(f->hash_str, (char*) x_sum->content) != 0)
|
||||||
{
|
{
|
||||||
e->type = MD5SUM_VERIFY_FAIL;
|
e->type = MD5SUM_VERIFY_FAIL;
|
||||||
|
@ -253,7 +253,7 @@ edit(exception_t *e)
|
||||||
strcat(fullpath, x_group_type);
|
strcat(fullpath, x_group_type);
|
||||||
strcat(fullpath, "/");
|
strcat(fullpath, "/");
|
||||||
strcat(fullpath, x_path);
|
strcat(fullpath, x_path);
|
||||||
f = file_init(&fullpath, e, "HOME");
|
f = file_init(&fullpath, FILEPATH_ABSOLUTE, e);
|
||||||
replace_text(f, x_before, x_after, x_type, e);
|
replace_text(f, x_before, x_after, x_type, e);
|
||||||
file_close(f);
|
file_close(f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,22 +13,22 @@ conf_verify_key(const char *f, const char *key, char *value)
|
||||||
|
|
||||||
if (!g_key_file_load_from_file (key_file, f, G_KEY_FILE_NONE, &error))
|
if (!g_key_file_load_from_file (key_file, f, G_KEY_FILE_NONE, &error))
|
||||||
{
|
{
|
||||||
if (!g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
|
if (g_error_matches (error, G_FILE_ERROR, G_FILE_ERROR_NOENT))
|
||||||
g_warning ("Error loading key file: %s\n", error->message);
|
g_warning ("Error loading key file: %s\n", error->message);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
value = g_key_file_get_string (key_file, "Global", key, &error);
|
value = g_key_file_get_string (key_file, "Global", key, &error);
|
||||||
if (value == NULL &&
|
if (value == NULL &&
|
||||||
!g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
|
g_error_matches (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND))
|
||||||
{
|
{
|
||||||
g_warning ("Error finding key in key file: %s\n", error->message);
|
g_warning ("Error finding key in key file: %s\n", error->message);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
else if (value == NULL)
|
else if (value == NULL)
|
||||||
{
|
{
|
||||||
g_warning ("Error finding game directory.\n");
|
g_warning ("Error: %s.\n", error->message);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,44 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "exception_t.h"
|
#include "exception_t.h"
|
||||||
|
|
||||||
|
exception_t*
|
||||||
|
exception_init() {
|
||||||
|
exception_t *e = (exception_t*) malloc(sizeof(exception_t));
|
||||||
|
e->type = NO_ERROR;
|
||||||
|
e->msg = malloc(CHAR_MAX);
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
exception_free(exception_t *e) {
|
||||||
|
free(e->msg);
|
||||||
|
free(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
exception_null(const exception_t *e) {
|
||||||
|
return e->type == NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
exception_prestr(const exception_t *e) {
|
||||||
|
switch(e->type) {
|
||||||
|
case NO_ERROR: return "No error\n";
|
||||||
|
case NO_FILE: return "No file found";
|
||||||
|
case XML_FILE_MISSING: return "XML file missing";
|
||||||
|
case XML_READ_FILE_FAIL: return "XML file reading failed";
|
||||||
|
case MD5SUM_GEN_FAIL: return "MD5sum generation failed";
|
||||||
|
case MD5SUM_VERIFY_FAIL: return "MD5sum verification failed";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
exception_str(const exception_t *e, char* msg) {
|
||||||
|
if (e->type != NO_ERROR) sprintf(msg, "%s: %s\n", exception_prestr(e), e->msg);
|
||||||
|
else sprintf(msg, "%s\n", exception_prestr(e));
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ typedef enum exception_type {
|
||||||
NO_FILE,
|
NO_FILE,
|
||||||
XML_FILE_MISSING,
|
XML_FILE_MISSING,
|
||||||
XML_READ_FILE_FAIL,
|
XML_READ_FILE_FAIL,
|
||||||
|
MD5SUM_GEN_FAIL,
|
||||||
MD5SUM_VERIFY_FAIL
|
MD5SUM_VERIFY_FAIL
|
||||||
} exception_type;
|
} exception_type;
|
||||||
|
|
||||||
|
@ -14,7 +15,16 @@ typedef struct exception_t {
|
||||||
char *msg;
|
char *msg;
|
||||||
} exception_t;
|
} exception_t;
|
||||||
|
|
||||||
|
exception_t*
|
||||||
|
exception_init();
|
||||||
|
|
||||||
|
void
|
||||||
|
exception_free(exception_t *e);
|
||||||
|
|
||||||
|
int
|
||||||
|
exception_null(const exception_t *e);
|
||||||
|
|
||||||
char*
|
char*
|
||||||
exception_str(exception_t *e);
|
exception_str(const exception_t *e, char* msg);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
87
src/file_t.c
87
src/file_t.c
|
@ -1,13 +1,11 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <openssl/md5.h> /* md5sum */
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
#include "file_t.h"
|
#include "file_t.h"
|
||||||
|
|
||||||
|
@ -28,49 +26,50 @@ get_size_by_fd(int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
file_t*
|
file_t*
|
||||||
file_init(const char *filename, exception_t *e, const char *env)
|
file_init(const char *filename, filepath_t FILEPATH, exception_t *e)
|
||||||
{
|
{
|
||||||
GString *abspath = g_string_new (NULL);
|
char *path = NULL;
|
||||||
if (env != NULL)
|
switch (FILEPATH) {
|
||||||
{
|
case FILEPATH_ABSOLUTE: {
|
||||||
char *envpath;
|
realpath(filename, path);
|
||||||
size_t sizehome, sizepath;
|
break;
|
||||||
envpath = getenv (env);
|
}
|
||||||
sizehome = strlen(envpath);
|
case FILEPATH_HOME: {
|
||||||
sizepath = strlen(filename);
|
char* home = getenv("HOME");
|
||||||
abspath = malloc(sizehome + sizepath + 2);
|
size_t pathlen = strlen(home) + strlen(filename);
|
||||||
strcpy (abspath, envpath);
|
path = malloc(pathlen + 1);
|
||||||
strcat (abspath, "/");
|
strcpy(home, path);
|
||||||
strcat (abspath, filename);
|
strcat(path, filename);
|
||||||
abspath[sizehome + sizepath + 2] = '\0';
|
path[pathlen] = '\0';
|
||||||
}
|
}
|
||||||
else
|
case FILEPATH_RELATIVE: path = (char*) filename; break;
|
||||||
{
|
}
|
||||||
abspath = filename;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Checks if the file path can be opened. */
|
/* Checks if the file path can be opened. */
|
||||||
if (open(abspath, O_RDONLY) < 0)
|
if (open(path, O_RDONLY) < 0)
|
||||||
{
|
{
|
||||||
e->type = NO_FILE;
|
e->type = NO_FILE;
|
||||||
e->msg = abspath;
|
e->msg = path;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
file_t *f;
|
file_t *f;
|
||||||
f = malloc(sizeof(file_t*));
|
f = malloc(sizeof(file_t));
|
||||||
f->name = (char*) abspath;
|
f->name = path;
|
||||||
f->hash = NULL;
|
|
||||||
f->hash_str = NULL;
|
f->hash_str = NULL;
|
||||||
|
f->fp = FILEPATH;
|
||||||
return f;
|
return f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
file_close(file_t *f)
|
file_close(file_t *f)
|
||||||
{
|
{
|
||||||
free(f->name);
|
switch (f->fp) {
|
||||||
free(f->hash);
|
case FILEPATH_ABSOLUTE:
|
||||||
free(f->hash_str);
|
case FILEPATH_HOME: free(f->name);
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
if (f->hash_str != NULL) free(f->hash_str);
|
||||||
free(f);
|
free(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +89,10 @@ file_md5_gen(file_t *f, exception_t *e)
|
||||||
file_buffer = (unsigned char*) mmap(0, file_size, PROT_READ, MAP_SHARED, file_descript, 0);
|
file_buffer = (unsigned char*) mmap(0, file_size, PROT_READ, MAP_SHARED, file_descript, 0);
|
||||||
|
|
||||||
/* Computes the MD5 checksum to result */
|
/* Computes the MD5 checksum to result */
|
||||||
MD5(file_buffer, file_size, f->hash);
|
if (MD5(file_buffer, file_size, f->hash) == NULL) {
|
||||||
|
e->type = MD5SUM_GEN_FAIL;
|
||||||
|
e->msg = "No hash!";
|
||||||
|
}
|
||||||
|
|
||||||
/* Removes fime_buffer and file_size */
|
/* Removes fime_buffer and file_size */
|
||||||
munmap(file_buffer, file_size);
|
munmap(file_buffer, file_size);
|
||||||
|
@ -102,14 +104,27 @@ char*
|
||||||
file_md5_str(file_t *f, exception_t *e)
|
file_md5_str(file_t *f, exception_t *e)
|
||||||
{
|
{
|
||||||
static const char digits[] = "0123456789abcdef";
|
static const char digits[] = "0123456789abcdef";
|
||||||
f->hash_str = malloc (MD5_DIGEST_LENGTH+1);
|
f->hash_str = malloc (2*MD5_DIGEST_LENGTH+1);
|
||||||
|
size_t si = 0;
|
||||||
for (size_t i = 0; i < MD5_DIGEST_LENGTH; i+=2)
|
for (size_t i = si; i < MD5_DIGEST_LENGTH; i++)
|
||||||
{
|
{
|
||||||
f->hash_str[i] += digits[f->hash[i] / MD5_DIGEST_LENGTH];
|
f->hash_str[si++] = digits[f->hash[i] / MD5_DIGEST_LENGTH];
|
||||||
f->hash_str[i+1] += digits[f->hash[i+1] % MD5_DIGEST_LENGTH];
|
f->hash_str[si++] = digits[f->hash[i] % MD5_DIGEST_LENGTH];
|
||||||
}
|
}
|
||||||
|
|
||||||
f->hash_str[MD5_DIGEST_LENGTH] = '\0';
|
f->hash_str[2*MD5_DIGEST_LENGTH] = '\0';
|
||||||
return f->hash_str;
|
return f->hash_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
file_abs(const file_t *f) {
|
||||||
|
char *path = NULL;
|
||||||
|
switch (f->fp) {
|
||||||
|
case FILEPATH_ABSOLUTE: return f->name;
|
||||||
|
case FILEPATH_RELATIVE: {
|
||||||
|
realpath(f->name, path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
16
src/file_t.h
16
src/file_t.h
|
@ -1,15 +1,24 @@
|
||||||
#ifndef FILE_T_H
|
#ifndef FILE_T_H
|
||||||
#define FILE_T_H
|
#define FILE_T_H
|
||||||
|
|
||||||
|
#include <openssl/md5.h> /* md5sum */
|
||||||
|
|
||||||
#include "exception_t.h"
|
#include "exception_t.h"
|
||||||
|
|
||||||
|
typedef enum filepath_t {
|
||||||
|
FILEPATH_ABSOLUTE,
|
||||||
|
FILEPATH_RELATIVE,
|
||||||
|
FILEPATH_HOME
|
||||||
|
} filepath_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper to file
|
* Wrapper to file
|
||||||
*/
|
*/
|
||||||
typedef struct file_t {
|
typedef struct file_t {
|
||||||
char *name; /**< Absolute path to file */
|
char *name; /**< Absolute path to file */
|
||||||
unsigned char *hash; /**< MD5sum hash */
|
unsigned char hash[MD5_DIGEST_LENGTH]; /**< MD5sum hash */
|
||||||
char *hash_str; /**< MD5sum hash as char* */
|
char *hash_str; /**< MD5sum hash as char* */
|
||||||
|
filepath_t fp;
|
||||||
} file_t;
|
} file_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +29,7 @@ typedef struct file_t {
|
||||||
* @return Pointer to file_t
|
* @return Pointer to file_t
|
||||||
*/
|
*/
|
||||||
file_t*
|
file_t*
|
||||||
file_init(const char *filename, exception_t *e, const char *env);
|
file_init(const char *filename, filepath_t FILEPATH, exception_t *e);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy file_t
|
* Destroy file_t
|
||||||
|
@ -44,4 +53,7 @@ file_md5_gen(file_t *f, exception_t *e);
|
||||||
char*
|
char*
|
||||||
file_md5_str(file_t *f, exception_t *e);
|
file_md5_str(file_t *f, exception_t *e);
|
||||||
|
|
||||||
|
char*
|
||||||
|
file_abs(const file_t *f);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
#include "install.h"
|
|
||||||
|
|
||||||
int
|
|
||||||
backup()
|
|
||||||
{
|
|
||||||
struct stat sb;
|
|
||||||
|
|
||||||
const std::string bkp = hd + _prefix + "_backup/";
|
|
||||||
|
|
||||||
struct stat stat_dir;
|
|
||||||
if (stat(bkp.c_str(), &stat_dir) != 0)
|
|
||||||
{
|
|
||||||
mkdir(bkp.c_str(), 0700);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &i : _vec)
|
|
||||||
{
|
|
||||||
const std::string source_file = hd + _prefix + "/" + i;
|
|
||||||
const std::string dest_file = bkp + i;
|
|
||||||
|
|
||||||
std::cout << "Backing up " << _prefix << "/" << i << "\n";
|
|
||||||
|
|
||||||
int source = open(source_file.c_str(), O_RDONLY, 0);
|
|
||||||
int dest = open(dest_file.c_str(), O_WRONLY | O_CREAT /*| O_TRUNC/**/, 0644);
|
|
||||||
|
|
||||||
// struct required, rationale: function stat() exists also
|
|
||||||
struct stat stat_source;
|
|
||||||
fstat(source, &stat_source);
|
|
||||||
sendfile(dest, source, 0, stat_source.st_size);
|
|
||||||
|
|
||||||
close(source);
|
|
||||||
close(dest);
|
|
||||||
|
|
||||||
if (access(dest_file.c_str(), F_OK) != 0)
|
|
||||||
{
|
|
||||||
throw ExceptionHandler(CUSTOM_ERROR, "Backing up " + dest_file + " failed!");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,15 @@
|
||||||
TESTS = check_file_t
|
TESTS = \
|
||||||
check_PROGRAMS = check_file_t
|
check_check
|
||||||
check_file_t_SOURCES = check_file_t.c $(top_builddir)/src/file_t.h
|
|
||||||
check_file_t_CFLAGS= $(CFLAGS) $(CHECK_CFLAGS)
|
noinst_PROGRAMS = \
|
||||||
check_file_t_LDADD = $(top_builddir)/src/libfile_t.la $(LDFLAGS) $(CHECK_LIBS)
|
check_check
|
||||||
|
|
||||||
|
check_check_SOURCES = \
|
||||||
|
check_check.c \
|
||||||
|
check_file_t.c \
|
||||||
|
check_exception_t.c \
|
||||||
|
check_calibrate.c
|
||||||
|
check_check_CPPFLAGS= $(CPPFLAGS)
|
||||||
|
check_check_CFLAGS= $(CFLAGS) $(CHECK_CFLAGS)
|
||||||
|
check_check_LDFLAGS= $(LDFLAGS) $(CHECK_LIBS)
|
||||||
|
check_check_LDADD = $(top_builddir)/src/libmodetw.la
|
||||||
|
|
|
@ -1,8 +1,36 @@
|
||||||
|
#include <stdlib.h>
|
||||||
#include <check.h>
|
#include <check.h>
|
||||||
|
#include "check_check.h"
|
||||||
#include "../src/calibrate.h"
|
#include "../src/calibrate.h"
|
||||||
|
#include "../src/file_t.h"
|
||||||
|
|
||||||
START_TEST(test_calibrate)
|
START_TEST(test_replace_text)
|
||||||
{
|
{
|
||||||
|
exception_t *e;
|
||||||
|
file_t *f;
|
||||||
|
e = exception_init();
|
||||||
|
f = file_init("samples/1.txt", FILEPATH_RELATIVE, e);
|
||||||
|
char *path = file_abs(f);
|
||||||
|
ck_assert(replace_text(path, "ABC", "123", "ASCII", e));
|
||||||
|
ck_assert(exception_null(e));
|
||||||
|
ck_assert(replace_text(path, "123", "ABC", "ASCII", e));
|
||||||
|
ck_assert(exception_null(e));
|
||||||
|
file_close(f);
|
||||||
|
exception_free(e);
|
||||||
|
free(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
Suite*
|
||||||
|
calibrate_suite(void)
|
||||||
|
{
|
||||||
|
Suite *s;
|
||||||
|
TCase *tc_core;
|
||||||
|
|
||||||
|
s = suite_create ("calibrate");
|
||||||
|
tc_core = tcase_create ("core");
|
||||||
|
|
||||||
|
tcase_add_test(tc_core, test_replace_text);
|
||||||
|
suite_add_tcase(s, tc_core);
|
||||||
|
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#include <check.h>
|
||||||
|
#include "check_check.h"
|
||||||
|
|
||||||
|
int
|
||||||
|
main(void)
|
||||||
|
{
|
||||||
|
int number_failed;
|
||||||
|
SRunner *sr;
|
||||||
|
|
||||||
|
sr = srunner_create(file_t_suite());
|
||||||
|
srunner_add_suite(sr, exception_t_suite());
|
||||||
|
srunner_add_suite(sr, calibrate_suite());
|
||||||
|
|
||||||
|
srunner_run_all(sr, CK_VERBOSE);
|
||||||
|
number_failed = srunner_ntests_failed(sr);
|
||||||
|
srunner_free(sr);
|
||||||
|
return number_failed;
|
||||||
|
}
|
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef CHECK_CHECK_H
|
||||||
|
#define CHECK_CHECK_H
|
||||||
|
|
||||||
|
#include <check.h>
|
||||||
|
|
||||||
|
Suite* file_t_suite(void);
|
||||||
|
Suite* exception_t_suite(void);
|
||||||
|
Suite* calibrate_suite(void);
|
||||||
|
|
||||||
|
#endif
|
|
@ -0,0 +1,27 @@
|
||||||
|
#include "check_check.h"
|
||||||
|
#include "../src/exception_t.h"
|
||||||
|
|
||||||
|
START_TEST(test_exception_init)
|
||||||
|
{
|
||||||
|
exception_t *e = NULL;
|
||||||
|
e = exception_init();
|
||||||
|
ck_assert_ptr_nonnull(e);
|
||||||
|
ck_assert_int_eq(e->type, NO_ERROR);
|
||||||
|
exception_free(e);
|
||||||
|
}
|
||||||
|
END_TEST
|
||||||
|
|
||||||
|
Suite*
|
||||||
|
exception_t_suite(void)
|
||||||
|
{
|
||||||
|
Suite *s;
|
||||||
|
TCase *tc_core;
|
||||||
|
|
||||||
|
s = suite_create ("exception_t");
|
||||||
|
tc_core = tcase_create ("core");
|
||||||
|
|
||||||
|
tcase_add_test(tc_core, test_exception_init);
|
||||||
|
suite_add_tcase(s, tc_core);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
|
@ -1,29 +1,30 @@
|
||||||
#include <check.h>
|
#include "check_check.h"
|
||||||
|
|
||||||
#include "../src/file_t.h"
|
#include "../src/file_t.h"
|
||||||
|
|
||||||
START_TEST(test_file_init)
|
START_TEST(test_file_init)
|
||||||
{
|
{
|
||||||
file_t *f;
|
file_t *f;
|
||||||
exception_t *e = NULL;
|
exception_t *e = exception_init();
|
||||||
f = file_init ("samples/1.txt", e, NULL);
|
f = file_init ("samples/1.txt", FILEPATH_RELATIVE, e);
|
||||||
ck_assert_ptr_ne (f, NULL);
|
ck_assert_ptr_nonnull (f);
|
||||||
ck_assert_ptr_eq (e, NULL);
|
ck_assert (exception_null(e));
|
||||||
file_close (f);
|
file_close (f);
|
||||||
|
exception_free(e);
|
||||||
}
|
}
|
||||||
END_TEST
|
END_TEST
|
||||||
|
|
||||||
START_TEST(test_file_md5)
|
START_TEST(test_file_md5)
|
||||||
{
|
{
|
||||||
file_t *f;
|
file_t *f;
|
||||||
exception_t *e = NULL;
|
exception_t *e = exception_init();
|
||||||
f = file_init("samples/1.txt", e, NULL);
|
f = file_init("samples/1.txt", FILEPATH_RELATIVE, e);
|
||||||
file_md5_gen (f, e);
|
file_md5_gen (f, e);
|
||||||
ck_assert_ptr_eq (e, NULL);
|
ck_assert (exception_null(e));
|
||||||
file_md5_str (f, e);
|
file_md5_str (f, e);
|
||||||
ck_assert_ptr_eq (e, NULL);
|
ck_assert (exception_null(e));
|
||||||
ck_assert_str_eq (f->hash_str, "492ff087b26577237c576e7ad409064e");
|
ck_assert_str_eq (f->hash_str, "492ff087b26577237c576e7ad409064e");
|
||||||
file_close (f);
|
file_close (f);
|
||||||
|
exception_free(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Suite*
|
Suite*
|
||||||
|
@ -41,19 +42,3 @@ file_t_suite(void)
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
|
||||||
main(void)
|
|
||||||
{
|
|
||||||
int number_failed;
|
|
||||||
Suite *s;
|
|
||||||
SRunner *sr;
|
|
||||||
|
|
||||||
s = file_t_suite();
|
|
||||||
sr = srunner_create(s);
|
|
||||||
|
|
||||||
srunner_run_all(sr, CK_VERBOSE);
|
|
||||||
number_failed = srunner_ntests_failed(sr);
|
|
||||||
srunner_free(sr);
|
|
||||||
return number_failed;
|
|
||||||
}
|
|
||||||
|
|
Reference in New Issue