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