Initial commit
This commit is contained in:
commit
fdfefe7d55
31 changed files with 3242 additions and 0 deletions
37
test/Makefile
Normal file
37
test/Makefile
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# Test makefile
|
||||
DEFS= -D__DEBUG__
|
||||
CC=gcc
|
||||
CFLAGS=-g
|
||||
|
||||
all :
|
||||
make rbtree
|
||||
make inotify
|
||||
make mysql
|
||||
|
||||
raw_inotify :
|
||||
$(CC) -linotifytools raw_inotify.c -o raw_inotify
|
||||
|
||||
path :
|
||||
$(CC) -D__DEBUG__ $(CFLAGS) ../src/common/path.c t_path.c -o test_path
|
||||
|
||||
rbtree :
|
||||
$(CC) -D RB_DEBUG $(CFLAGS) ../src/common/rbtree.c t_rbtree.c -o test_rbtree
|
||||
|
||||
inotify :
|
||||
$(CC) -lpthread -D INOTIFY_DEBUG -D RB_DEBUG $(CFLAGS) \
|
||||
../src/common/rbtree.c \
|
||||
../src/common/path.c \
|
||||
../src/fs/scan.c \
|
||||
../src/fs/notify_event.c \
|
||||
../src/fs/inotify.c \
|
||||
t_inotify.c -o test_inotify
|
||||
|
||||
tree :
|
||||
$(CC) $(CFLAGS) $(DEFS) ../src/common/path.c ../src/fs/tree.c t_tree.c -o test_tree
|
||||
|
||||
indexer :
|
||||
$(CC) $(CFLAGS) -D__DEBUG__ ../src/common/path.c ../src/fs/tree.c ../src/indexer.c t_indexer.c -o test_indexer
|
||||
|
||||
mysql :
|
||||
$(CC) -D DB_DEBUG $(CFLAGS) ../src/mysql_db.c -L/usr/lib64/mysql \
|
||||
-lmysqlclient -lz -lcrypt -lnsl -lm -L/usr/lib64 -lssl -lcrypto t_mysql.c -o test_mysql
|
||||
31
test/raw_inotify.c
Normal file
31
test/raw_inotify.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <inotifytools/inotifytools.h>
|
||||
#include <inotifytools/inotify.h>
|
||||
// (IN_MOVE | IN_CREATE | IN_DELETE | IN_ONLYDIR)
|
||||
#define WMASK (IN_MOVE | IN_MOVE_SELF | IN_CREATE | IN_DELETE | IN_ONLYDIR)
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
struct inotify_event *ev;
|
||||
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
|
||||
if ( !inotifytools_initialize()
|
||||
|| !inotifytools_watch_recursively(argv[1], WMASK) ) {
|
||||
fprintf(stderr, "%s\n", strerror(inotifytools_error()) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
|
||||
ev = inotifytools_next_event(-1);
|
||||
|
||||
printf("%u: ", ev->wd);
|
||||
inotifytools_printf(ev, "%w:%f %e\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
29
test/t_indexer.c
Normal file
29
test/t_indexer.c
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include "../src/indexer.h"
|
||||
|
||||
int main() {
|
||||
|
||||
indexer_register("/home/pnx/", "tmptree");
|
||||
indexer_register("/home/pnx/", "tmptree");
|
||||
indexer_register("/home/pnx/", "tmptree");
|
||||
|
||||
while(indexer_pending()) {
|
||||
indexer_run(5);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
printf("---\n");
|
||||
|
||||
indexer_register("/home/pnx/", "tmptree");
|
||||
|
||||
while(indexer_pending()) {
|
||||
indexer_run(5);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
printf("done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
40
test/t_inotify.c
Normal file
40
test/t_inotify.c
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include "../src/fs/notify.h"
|
||||
|
||||
PROT_SCAN_CALLBACK(my_callback) {
|
||||
//printf("FROM THREAD -- path: %s; is_dir = %i\n", path, dir);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
notify_event *event;
|
||||
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
|
||||
notify_init();
|
||||
|
||||
if (!notify_add_watch(argv[1]))
|
||||
return 1;
|
||||
|
||||
printf("begin watching on: %s\n", argv[1]);
|
||||
|
||||
for (;;) {
|
||||
|
||||
event = notify_read(3);
|
||||
|
||||
if (event == NULL)
|
||||
continue;
|
||||
|
||||
printf("====================\n"
|
||||
"Type: %s\n"
|
||||
"Path: %s\n"
|
||||
"Filename: %s\n"
|
||||
"Directory: %u\n"
|
||||
"====================\n"
|
||||
, notify_event_masktostr(event), event->path, event->filename, event->dir);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
33
test/t_mysql.c
Normal file
33
test/t_mysql.c
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
|
||||
#ifndef INOTIFY_DEBUG
|
||||
#define INOTIFY_DEBUG
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include "../src/notify_db.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
// Keep me safe
|
||||
printf("Run!\n");
|
||||
|
||||
// Connect
|
||||
notify_db_init("localhost", "warez", "elebobo", "filesystem", "filesystem");
|
||||
|
||||
// Truncate
|
||||
//notify_db_truncate();
|
||||
|
||||
sleep(10);
|
||||
|
||||
// Insert
|
||||
notify_db_insert("/this/is/my/path/to/", "myfile", 0);
|
||||
|
||||
// Delete
|
||||
//notify_db_delete("/this/is/my/path/to/", "myfile");
|
||||
|
||||
// Close
|
||||
notify_db_close();
|
||||
|
||||
// Kill me
|
||||
return 0;
|
||||
}
|
||||
82
test/t_path.c
Normal file
82
test/t_path.c
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include "../src/common/path.h"
|
||||
|
||||
/* test data */
|
||||
|
||||
char string[8][128] = {
|
||||
"usr/include/",
|
||||
"/usr/src/linux",
|
||||
"/segment1/segment2/segment3/",
|
||||
"//double///tripple",
|
||||
"/stuff/with/ahell/lot/of/slashes/at/the/end/////////",
|
||||
"~/myhome/",
|
||||
"/",
|
||||
"///////////////////////////////////////////////////////////"
|
||||
};
|
||||
|
||||
char split[8][2][64] = {
|
||||
{"usr/", "include/" },
|
||||
{"/usr/src/", "linux" },
|
||||
{"/segment1/segment2/", "segment3/" },
|
||||
{"//double//", "/tripple" },
|
||||
{"/stuff/with/ahell/lot/of/slashes/at/the/", "end/////////" },
|
||||
{"~/", "myhome/" },
|
||||
{"/mnt/cdrom", "keff" },
|
||||
{"//////////////////////////////", "/////////////////////////////" }
|
||||
};
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
int i;
|
||||
char *ptr = NULL;
|
||||
|
||||
for(i=0; i < 8; i++) {
|
||||
//printf("adding: %s\n", string[i]);
|
||||
ptr = fmt_path(string[i], NULL, 0);
|
||||
printf("str %i is: %s\n", i, ptr);
|
||||
|
||||
if (ptr != NULL) {
|
||||
free(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i < 8; i++) {
|
||||
//printf("adding: %s%s\n", split[i][0], split[i][1]);
|
||||
ptr = fmt_path(split[i][0], split[i][1], 0);
|
||||
printf("str %i is: %s\n", i, ptr);
|
||||
|
||||
if (ptr != NULL) {
|
||||
free(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i < 8; i++) {
|
||||
//printf("adding: %s%s\n", split[i][0], split[i][1]);
|
||||
ptr = fmt_path(split[i][0], split[i][1], 1);
|
||||
printf("str %i is: %s\n", i, ptr);
|
||||
|
||||
if (ptr != NULL) {
|
||||
free(ptr);
|
||||
ptr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if(argc < 2)
|
||||
return 0;
|
||||
else if(argc == 2)
|
||||
ptr = fmt_path(argv[1], NULL, 0);
|
||||
else if(argc > 2) {
|
||||
ptr = fmt_path(argv[1], argv[2], 0);
|
||||
}
|
||||
|
||||
printf("%s\n", ptr);
|
||||
|
||||
if (ptr != NULL)
|
||||
free(ptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
91
test/t_rbtree.c
Normal file
91
test/t_rbtree.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
#ifndef RB_DEBUG
|
||||
#define RB_DEBUG 1
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include "../src/common/rbtree.h"
|
||||
|
||||
#define MAX_VAL 12500
|
||||
#define NODES 5000
|
||||
|
||||
uint get_random_key(uint m) {
|
||||
return (uint) (rand() % m);
|
||||
}
|
||||
|
||||
void printer(rbnode *node) {
|
||||
|
||||
printf("node: %u (%p)\n", node->key, node);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
uint keyref[NODES];
|
||||
uint i, spos, search_key, ckey;
|
||||
rbtree tree;
|
||||
rbnode *snode;
|
||||
|
||||
tree.root = NULL;
|
||||
|
||||
srand(time(NULL));
|
||||
|
||||
/* rbtree should be empty */
|
||||
assert(rbtree_is_empty(&tree) == 1);
|
||||
|
||||
/* get a random node position */
|
||||
spos = get_random_key(NODES);
|
||||
|
||||
/* insert values */
|
||||
for(i=0; i < NODES; i++) {
|
||||
|
||||
ckey = get_random_key(MAX_VAL);
|
||||
|
||||
if(i == spos)
|
||||
search_key = ckey;
|
||||
|
||||
//printf("insert: %u\n", ckey);
|
||||
rbtree_insert(&tree, ckey, NULL);
|
||||
keyref[i] = ckey;
|
||||
}
|
||||
|
||||
/* validate tree */
|
||||
rb_assert(tree.root);
|
||||
|
||||
/* search the random key */
|
||||
snode = rbtree_search(&tree, search_key);
|
||||
|
||||
assert(snode->key == search_key);
|
||||
|
||||
/* remove some values */
|
||||
for(i=0; i < NODES; i++) {
|
||||
|
||||
//printf("removing: %u\n", ckey);
|
||||
|
||||
rbtree_delete(&tree, ckey);
|
||||
|
||||
ckey = get_random_key(MAX_VAL);
|
||||
}
|
||||
|
||||
/* assert again */
|
||||
rb_assert(tree.root);
|
||||
|
||||
if(argc == 1) {
|
||||
/* free the tree */
|
||||
rbtree_free(&tree, NULL);
|
||||
} else {
|
||||
printf("---\n");
|
||||
for(i=0; i < NODES; i++) {
|
||||
//printf("removing: %u\n", keyref[i]);
|
||||
rbtree_delete(&tree, keyref[i]);
|
||||
}
|
||||
}
|
||||
|
||||
rbtree_walk(&tree, printer);
|
||||
|
||||
/* tree should now be empty */
|
||||
assert(rbtree_is_empty(&tree) == 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
36
test/t_tree.c
Normal file
36
test/t_tree.c
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
|
||||
#include <stdio.h>
|
||||
#include "../src/fs/tree.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
struct entry *ent;
|
||||
struct tree *tree;
|
||||
unsigned int c_ent = 0;
|
||||
|
||||
if (argc < 2)
|
||||
return 1;
|
||||
|
||||
tree = tree_new(argv[1]);
|
||||
|
||||
if (tree == NULL) {
|
||||
printf("error\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
|
||||
ent = tree_next_ent(tree);
|
||||
|
||||
if (ent == NULL)
|
||||
break;
|
||||
|
||||
printf("%s%s\n", ent->base, ent->name);
|
||||
|
||||
c_ent++;
|
||||
}
|
||||
|
||||
printf("%i Entries\n", c_ent);
|
||||
|
||||
return 0;
|
||||
}
|
||||
16
test/unit.c
Normal file
16
test/unit.c
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
|
||||
#include "unit.h"
|
||||
|
||||
int utest_string(const char *a, const char *b) {
|
||||
|
||||
while(*a == *b) {
|
||||
|
||||
if (*a == 0)
|
||||
return 1;
|
||||
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
21
test/unit.h
Normal file
21
test/unit.h
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
|
||||
#ifndef _UNIT_H
|
||||
|
||||
#define _UNIT_H
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define utest_exit(fmt, ...) \
|
||||
fprintf(stderr, fmt, __VA_ARGS__); \
|
||||
exit(1)
|
||||
|
||||
#define utest_string(a, b) \
|
||||
(strcmp(a, b) == 0 ? \
|
||||
(void) 0 : \
|
||||
utest_exit("ASSERT: \"" #expr "\" at %s:%i\n", __FILE__, __LINE__))
|
||||
|
||||
|
||||
#endif /* _UNIT_H */
|
||||
9
test/unit_path.c
Normal file
9
test/unit_path.c
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
void unit_fmt_path() {
|
||||
|
||||
assert();
|
||||
}
|
||||
Reference in a new issue