~cyphermox/indicator-appmenu/version

« back to all changes in this revision

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

  • Committer: Tarmac
  • Author(s): Ted Gould
  • Date: 2013-02-19 17:55:05 UTC
  • mfrom: (216.1.15 hudectomy)
  • Revision ID: tarmac-20130219175505-jjynbyonwdf8ui8p
Remove the HUD files from indicator-appmenu.

Approved by PS Jenkins bot, Mathieu Trudel-Lapierre, Charles Kerr.

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
 
 
28
 
static void
29
 
build_db (sqlite3 * db)
30
 
{
31
 
        /* Create the table */
32
 
        int exec_status = SQLITE_OK;
33
 
        gchar * failstring = NULL;
34
 
        exec_status = sqlite3_exec(db,
35
 
                                   "create table usage (application text, entry text, timestamp datetime);",
36
 
                                   NULL, NULL, &failstring);
37
 
        if (exec_status != SQLITE_OK) {
38
 
                g_warning("Unable to create table: %s", failstring);
39
 
        }
40
 
 
41
 
        /* Import data from the system */
42
 
 
43
 
        return;
44
 
}
45
 
 
46
 
int
47
 
main (int argv, char * argc[])
48
 
{
49
 
        gboolean passed = TRUE;
50
 
 
51
 
        if (argv != 2) {
52
 
                g_printerr("Usage: %s <app-info file path>\n", argc[0]);
53
 
                return 1;
54
 
        }
55
 
 
56
 
        gchar * filename = NULL;
57
 
        gint tmpfile = g_file_open_tmp("hud-test-bad-app-info-temp-db-XXXXXX", &filename, NULL);
58
 
 
59
 
        if (tmpfile < 0) {
60
 
                passed = FALSE;
61
 
        } else {
62
 
 
63
 
                close(tmpfile);
64
 
                /* NOTE: there is a small security bug here in that we're closing the
65
 
                   file and reopening it, so the temp isn't really gauranteed to be
66
 
                   safe.  But, I don't think we're really worried about security in this
67
 
                   utility. */
68
 
 
69
 
                sqlite3 * db = NULL;
70
 
                int open_status = sqlite3_open(filename, &db); 
71
 
 
72
 
                if (open_status != SQLITE_OK) {
73
 
                        g_warning("Error opening usage DB: %s", filename);
74
 
                        passed = FALSE;
75
 
                } else {
76
 
 
77
 
                        /* Create the table in the DB */
78
 
                        build_db(db);
79
 
 
80
 
                        passed = !load_app_info(argc[1], db);
81
 
 
82
 
                        sqlite3_close(db);
83
 
                }
84
 
        }
85
 
 
86
 
        if (filename != NULL) {
87
 
                if (g_getenv("HUD_VERIFY_NO_UNLINK") == NULL) {
88
 
                        g_unlink(filename);
89
 
                } else {
90
 
                        g_print("Temp db '%s' not deleted\n", filename);
91
 
                }
92
 
                g_free(filename);
93
 
        }
94
 
 
95
 
        if (passed) {
96
 
                return 0;
97
 
        } else {
98
 
                return 1;
99
 
        }
100
 
}