taskrambler  0.1.8
Web server and task management solution.
usertest.c
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <gdbm.h>
4 #include <errno.h>
5 #include <string.h>
6 
7 #include "class.h"
8 #include "commons.h"
9 #include "user.h"
10 #include "storage.h"
11 
12 #include "utils/memory.h"
13 
14 void
15 printUser(Storage users, const char * key, size_t nkey)
16 {
17  User user = new(User, NULL);
18 
19  user->email = (char *)key,
20  user->nemail = &nkey;
21 
22  if (NULL == userLoad(user, users)) {
23  fprintf(stderr, "can't find user: %s\n", key);
24  } else {
25  puts("found user:");
26  puts(user->email);
27  puts(user->firstname);
28  puts(user->surname);
29 
30  delete(user);
31  }
32 }
33 
34 void
36  Storage users,
37  const char * email, size_t nemail,
38  const char * firstname, size_t nfirstname,
39  const char * surname, size_t nsurname)
40 {
41  User insert = new(User,
42  email, nemail,
43  firstname, nfirstname,
44  surname, nsurname);
45 
46  userSave(insert, users);
47  delete(insert);
48 }
49 
50 int
51 main(int argc, char * argv[])
52 {
53  Storage users = new(Storage, CSTRA("./users.db"));
54 
55  if (NULL == users) {
56  fprintf(stderr, "%s\n", gdbm_strerror(gdbm_errno));
57  fprintf(stderr, "%s\n", strerror(errno));
58  return 1;
59  }
60 
61  insertUser(
62  users,
63  CSTRA("georg"),
64  CSTRA("Georg"),
65  CSTRA("Hopp"));
66  insertUser(
67  users,
68  CSTRA("georg@steffers.org"),
69  CSTRA("Georg"),
70  CSTRA("Hopp"));
71  insertUser(
72  users,
73  CSTRA("drachenfrau1982@gmx.net"),
74  CSTRA("Gundula"),
75  CSTRA("Hopp"));
76 
77  printUser(users, CSTRA("foo@bar.de"));
78  puts("");
79  printUser(users, CSTRA("drachenfrau1982@gmx.net"));
80  puts("");
81  printUser(users, CSTRA("georg@steffers.org"));
82 
83  delete(users);
84 
85  users = new(Storage, CSTRA("./users.db"));
86 
87  insertUser(
88  users,
89  CSTRA("drachenfrau1982@gmx.net"),
90  CSTRA("Stefanie"),
91  CSTRA("Hopp"));
92 
93  puts("");
94  printUser(users, CSTRA("foo@bar.de"));
95  puts("");
96  printUser(users, CSTRA("drachenfrau1982@gmx.net"));
97  puts("");
98  printUser(users, CSTRA("georg@steffers.org"));
99 
100  delete(users);
101 
102  memCleanup();
103 
104  return 0;
105 }
106 
107 // vim: set et ts=4 sw=4:
int main(int argc, char *argv[])
Definition: usertest.c:51
#define CSTRA(val)
Const STRing Argument.
Definition: memory.h:26
void insertUser(Storage users, const char *email, size_t nemail, const char *firstname, size_t nfirstname, const char *surname, size_t nsurname)
Definition: usertest.c:35
void printUser(Storage users, const char *key, size_t nkey)
Definition: usertest.c:15
void memCleanup()
Definition: memory.c:862