Debian Codegraph @

src/test/dbtest.c

raw
1 #include "confmodule.h"
2 #include "configuration.h"
3 #include "frontend.h"
4 #include "database.h"
5 #include "template.h"
6 #include "question.h"
7
8 void loadtemplate(const char *filename, const char *owner,
9 struct template_db *g_templates,
10 struct question_db *g_questions);
11
12 void loadtemplate(const char *filename, const char *owner,
13 struct template_db *g_templates,
14 struct question_db *g_questions) {
15 struct template *t;
16 struct question *q;
17
18 t = template_load(filename);
19 while (t)
20 {
21 if (g_templates->methods.set(g_templates, t) != DC_OK)
22 INFO(INFO_ERROR, "Cannot add template %s", t->tag);
23
24 q = g_questions->methods.get(g_questions, t->tag);
25 if (q == NULL)
26 {
27 q = question_new(t->tag);
28 q->template = t;
29 question_ref(q);
30 }
31 question_owner_add(q, owner);
32 if (g_questions->methods.set(g_questions, q) != DC_OK)
33 INFO(INFO_ERROR, "Cannot add question %s", t->tag);
34 fprintf(stderr, "\t\t%p\n\t\t%s\n",q,q->tag);
35 question_deref(q);
36 t = t->next;
37 }
38
39 }
40
41 int main(int argc, char **argv)
42 {
43 struct configuration *config;
44 struct question_db *qdb;
45 struct template_db *tdb;
46 struct question *q;
47
48 /* parse the configuration info */
49 config = config_new();
50 if (config->read(config, "debconf.conf") == 0)
51 DIE("Error reading configuration information");
52
53 /* initialize database and frontend modules */
54 if ((tdb = template_db_new(config, NULL)) == 0)
55 DIE("Cannot initialize DebConf template database");
56
57 if ((qdb = question_db_new(config, tdb, NULL)) == 0)
58 DIE("Cannot initialize DebConf question database");
59
60 /* load templates */
61 tdb->methods.load(tdb);
62 qdb->methods.load(qdb);
63 loadtemplate("test.templates","foo", tdb, qdb);
64 q = qdb->methods.get(qdb,"test/boolean");
65
66 fprintf(stderr, "\t\t%p\n", q);
67 fprintf(stderr, "\t\t%s\n", q->tag);
68
69 /* shutting down .... sync the database and shutdown the modules */
70 qdb->methods.save(qdb);
71 tdb->methods.save(tdb);
72 template_db_delete(tdb);
73 question_db_delete(qdb);
74
75 return 0;
76 }