Add packaging/libsqlfs.changes file
[platform/core/base/libsqlfs.git] / tests / test.c
1 /******************************************************************************
2 Copyright 2006 Palmsource, Inc (an ACCESS company). 
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8  
9 This library 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 GNU
12 Lesser General Public License for more details.
13  
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17
18 *****************************************************************************/
19
20 #include <assert.h>
21 #include <string.h>
22 #include "sqlfs.h"
23
24 int main(int argc, char *argv[])
25 {
26     char *data = "this is a string";
27     char *data2 = malloc(sizeof(char) * 32000);
28     char buf[200];
29     struct fuse_file_info fi = { 0 };
30     int i;
31     sqlfs_t *sqlfs = 0;
32     memset(data2, '2', 32000);
33     sqlfs_init(argv[1]);
34     sqlfs_open(argv[1], &sqlfs);
35     
36     sqlfs_proc_mkdir(sqlfs, "/test", 0666);
37     sqlfs_proc_mkdir(sqlfs, "/test/1", 0666);
38     sqlfs_proc_mkdir(sqlfs, "/test/2", 0666);
39     sqlfs_proc_mkdir(sqlfs, "/a/b/c/d/e/f/g", 0666);
40     fi.flags |= ~0;
41     sqlfs_proc_write(sqlfs, "/test/2/file", data, strlen(data), 0, &fi);
42     sqlfs_proc_rmdir(sqlfs, "/test");
43     
44     
45     i = sqlfs_proc_read(sqlfs, "/test/2/file", buf, sizeof(buf), 0, &fi);
46     buf[i] = 0;
47     assert(!strcmp(buf, data));
48     
49     sqlfs_proc_write(sqlfs, "/app/data/file", data, strlen(data), 0, &fi);
50     sqlfs_proc_write(sqlfs, "/big/a/b/c/file", data2, 32000, 0, &fi);
51
52     i = sqlfs_proc_read(sqlfs, "/big/a/b/c/file", buf, sizeof(buf), 400, &fi);
53     assert(buf[97] == '2');
54     sqlfs_close(sqlfs);
55
56 }
57