Back to index

indicator-appmenu  12.10.0
test-load-app-info.c
Go to the documentation of this file.
00001 /*
00002 Make sure the app info is truly bad and we don't crash or something.
00003 
00004 Copyright 2011 Canonical Ltd.
00005 
00006 Authors:
00007     Ted Gould <ted@canonical.com>
00008 
00009 This program is free software: you can redistribute it and/or modify it 
00010 under the terms of the GNU General Public License version 3, as published 
00011 by the Free Software Foundation.
00012 
00013 This program is distributed in the hope that it will be useful, but 
00014 WITHOUT ANY WARRANTY; without even the implied warranties of 
00015 MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR 
00016 PURPOSE.  See the GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License along 
00019 with this program.  If not, see <http://www.gnu.org/licenses/>.
00020 */
00021 
00022 #include <unistd.h>
00023 #include <glib.h>
00024 #include <glib/gstdio.h>
00025 #include <glib-object.h>
00026 #include "load-app-info.h"
00027 
00028 static void
00029 build_db (sqlite3 * db)
00030 {
00031        /* Create the table */
00032        int exec_status = SQLITE_OK;
00033        gchar * failstring = NULL;
00034        exec_status = sqlite3_exec(db,
00035                                   "create table usage (application text, entry text, timestamp datetime);",
00036                                   NULL, NULL, &failstring);
00037        if (exec_status != SQLITE_OK) {
00038               g_warning("Unable to create table: %s", failstring);
00039        }
00040 
00041        /* Import data from the system */
00042 
00043        return;
00044 }
00045 
00046 int
00047 main (int argv, char * argc[])
00048 {
00049        gboolean passed = TRUE;
00050 
00051        if (argv != 3) {
00052               g_printerr("Usage: %s <db path> <app-info file path>\n", argc[0]);
00053               return 1;
00054        }
00055 
00056        g_type_init();
00057 
00058        gchar * filename = argc[1];
00059 
00060        sqlite3 * db = NULL;
00061        int open_status = sqlite3_open(filename, &db); 
00062 
00063        if (open_status != SQLITE_OK) {
00064               g_warning("Error opening usage DB: %s", filename);
00065               passed = FALSE;
00066               goto cleanup;
00067        }
00068 
00069        /* Create the table in the DB */
00070        build_db(db);
00071 
00072        passed = load_app_info(argc[2], db);
00073 
00074 cleanup:
00075        if (db != NULL) {
00076               sqlite3_close(db);
00077        }
00078 
00079        if (passed) {
00080               return 0;
00081        } else {
00082               return 1;
00083        }
00084 }