]> arthur.barton.de Git - netatalk.git/blob - test/afpd/test.c
35f0876a231c5a82e7f893bb3381e70b0e9ccf37
[netatalk.git] / test / afpd / test.c
1 /*
2   Copyright (c) 2010 Frank Lahm <franklahm@gmail.com>
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 2 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 #include "config.h"
17 #endif /* HAVE_CONFIG_H */
18
19 #include <string.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <errno.h>
23
24 #include <atalk/util.h>
25 #include <atalk/cnid.h>
26 #include <atalk/logger.h>
27 #include <atalk/volume.h>
28 #include <atalk/directory.h>
29 #include <atalk/queue.h>
30 #include <atalk/bstrlib.h>
31
32 #include "file.h"
33 #include "filedir.h"
34 #include "directory.h"
35 #include "dircache.h"
36 #include "hash.h"
37 #include "globals.h"
38 #include "afp_config.h"
39 #include "volume.h"
40
41 #include "test.h"
42 #include "subtests.h"
43 #include "afpfunc_helpers.h"
44
45 /* Stuff from main.c which of cource can't be added as source to testbin */
46 unsigned char nologin = 0;
47 struct afp_options default_options;
48 static AFPConfig *configs;
49
50 /* Static variables */
51
52 int main(int argc, char **argv)
53 {
54     #define ARGNUM 7
55     char *args[ARGNUM] = {"test", "-F", "test.conf", "-f", "test.default", "-s" ,"test.system"};
56     int reti;
57     uint16_t vid;
58     struct vol *vol;
59     struct dir *dir;
60     struct dir *retdir;
61     struct path *path;
62
63     /* initialize */
64     afp_version = 32;
65     printf("Initializing\n============\n");
66     TEST(setuplog("default log_note /dev/tty"));
67     TEST(afp_options_init(&default_options));
68     TEST_int(afp_options_parse( ARGNUM, args, &default_options), 1);
69     TEST_expr(configs = configinit(&default_options), configs != NULL);
70     TEST(cnid_init());
71     TEST(load_volumes(&configs->obj));
72     TEST_int(dircache_init(8192), 0);
73  
74     printf("\n");
75
76     /* now run tests */
77     printf("Running tests\n=============\n");
78
79     TEST_expr(vid = openvol(&configs->obj, "test"), vid != 0);
80     TEST_expr(vol = getvolbyvid(vid), vol != NULL);
81
82     /* test dircache.c stuff*/
83     TEST_expr(dir = dir_new("dir", "dir", vol, DIRDID_ROOT, htonl(20), bfromcstr(vol->v_path), 0),
84               dir != NULL);
85     TEST_int(dircache_add(dir), 0);
86     TEST_expr(retdir = dircache_search_by_did(vol, dir->d_did ),
87               retdir != NULL && retdir == dir && bstrcmp(retdir->d_u_name, dir->d_u_name) == 0);
88     TEST_expr(retdir = dircache_search_by_name(vol, vol->v_root, "dir", strlen("dir"), 0),
89               retdir != NULL && retdir == dir && bstrcmp(retdir->d_u_name, dir->d_u_name) == 0);
90     TEST_int(dir_remove(vol, dir), 0);
91     TEST_int(test001_add_x_dirs(vol, 100, 100000), 0);
92     TEST_int(test002_rem_x_dirs(vol, 100, 100000), 0);
93
94     /* test directory.c stuff */
95     TEST_expr(retdir = dirlookup(vol, DIRDID_ROOT_PARENT), retdir != NULL);
96     TEST_expr(retdir = dirlookup(vol, DIRDID_ROOT), retdir != NULL);
97     TEST_expr(path = cname(vol, retdir, cnamewrap("Network Trash Folder")), path != NULL);
98
99     TEST_expr(retdir = dirlookup(vol, DIRDID_ROOT), retdir != NULL);
100     TEST_int(getfiledirparms(&configs->obj, vid, DIRDID_ROOT_PARENT, "test"), 0);
101     TEST_int(getfiledirparms(&configs->obj, vid, DIRDID_ROOT, ""), 0);
102
103     TEST_expr(reti = createdir(&configs->obj, vid, DIRDID_ROOT, "dir1"),
104               reti == 0 || reti == AFPERR_EXIST);
105
106     TEST_int(getfiledirparms(&configs->obj, vid, DIRDID_ROOT, "dir1"), 0);
107 /*
108   FIXME: this doesn't work although it should. "//" get translated to \000 \000 at means ".."
109   ie this should getfiledirparms for DIRDID_ROOT_PARENT -- at least afair!
110     TEST_int(getfiledirparms(&configs->obj, vid, DIRDID_ROOT, "//"), 0);
111 */
112     TEST_int(createfile(&configs->obj, vid, DIRDID_ROOT, "dir1/file1"), 0);
113     TEST_int(delete(&configs->obj, vid, DIRDID_ROOT, "dir1/file1"), 0);
114     TEST_int(delete(&configs->obj, vid, DIRDID_ROOT, "dir1"), 0);
115
116     TEST_int(createfile(&configs->obj, vid, DIRDID_ROOT, "file1"), 0);
117     TEST_int(getfiledirparms(&configs->obj, vid, DIRDID_ROOT, "file1"), 0);
118     TEST_int(delete(&configs->obj, vid, DIRDID_ROOT, "file1"), 0);
119
120
121     /* test enumerate.c stuff */
122     TEST_int(enumerate(&configs->obj, vid, DIRDID_ROOT), 0);
123 }