~jbicha/hud/build-depend-on-valac-not-gir

« back to all changes in this revision

Viewing changes to tests/test-load-app-info.c

Merging the HUD into indicator-appmenu

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Make sure the app info is truly bad and we don't crash or something.
 
3
 
 
4
Copyright 2011 Canonical Ltd.
 
5
 
 
6
Authors:
 
7
    Ted Gould <ted@canonical.com>
 
8
 
 
9
This program is free software: you can redistribute it and/or modify it 
 
10
under the terms of the GNU General Public License version 3, as published 
 
11
by the Free Software Foundation.
 
12
 
 
13
This program is distributed in the hope that it will be useful, but 
 
14
WITHOUT ANY WARRANTY; without even the implied warranties of 
 
15
MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
 
16
PURPOSE.  See the GNU General Public License for more details.
 
17
 
 
18
You should have received a copy of the GNU General Public License along 
 
19
with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
*/
 
21
 
 
22
#include <unistd.h>
 
23
#include <glib.h>
 
24
#include <glib/gstdio.h>
 
25
#include <glib-object.h>
 
26
#include "load-app-info.h"
 
27
#include "load-app-info.c"
 
28
 
 
29
static void
 
30
build_db (sqlite3 * db)
 
31
{
 
32
        /* Create the table */
 
33
        int exec_status = SQLITE_OK;
 
34
        gchar * failstring = NULL;
 
35
        exec_status = sqlite3_exec(db,
 
36
                                   "create table usage (application text, entry text, timestamp datetime);",
 
37
                                   NULL, NULL, &failstring);
 
38
        if (exec_status != SQLITE_OK) {
 
39
                g_warning("Unable to create table: %s", failstring);
 
40
        }
 
41
 
 
42
        /* Import data from the system */
 
43
 
 
44
        return;
 
45
}
 
46
 
 
47
int
 
48
main (int argv, char * argc[])
 
49
{
 
50
        gboolean passed = TRUE;
 
51
 
 
52
        if (argv != 3) {
 
53
                g_printerr("Usage: %s <db path> <app-info file path>\n", argc[0]);
 
54
                return 1;
 
55
        }
 
56
 
 
57
        g_type_init();
 
58
 
 
59
        gchar * filename = argc[1];
 
60
 
 
61
        sqlite3 * db = NULL;
 
62
        int open_status = sqlite3_open(filename, &db); 
 
63
 
 
64
        if (open_status != SQLITE_OK) {
 
65
                g_warning("Error opening usage DB: %s", filename);
 
66
                passed = FALSE;
 
67
                goto cleanup;
 
68
        }
 
69
 
 
70
        /* Create the table in the DB */
 
71
        build_db(db);
 
72
 
 
73
        passed = load_app_info(argc[2], db);
 
74
 
 
75
cleanup:
 
76
        if (db != NULL) {
 
77
                sqlite3_close(db);
 
78
        }
 
79
 
 
80
        if (passed) {
 
81
                return 0;
 
82
        } else {
 
83
                return 1;
 
84
        }
 
85
}