Back to index

indicator-appmenu  12.10.0
test-usage-db-simple.c
Go to the documentation of this file.
00001 /*
00002 Test function to ensure we can use a simple databse
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 <glib.h>
00023 #include <glib-object.h>
00024 
00025 #include "hudsettings.h"
00026 #include "load-app-info.h"
00027 #include "usage-tracker.h"
00028 
00029 HudSettings hud_settings = {
00030   .store_usage_data = TRUE
00031 };
00032 
00033 /* Ensure the base object works */
00034 static void
00035 test_usage_db_base (void)
00036 {
00037        UsageTracker * tracker = usage_tracker_new();
00038        g_assert(tracker != NULL);
00039        g_assert(IS_USAGE_TRACKER(tracker));
00040 
00041        g_object_unref(tracker);
00042        return;
00043 }
00044 
00045 static void
00046 test_usage_db_counts (void)
00047 {
00048        UsageTracker * tracker = usage_tracker_new();
00049        g_assert(tracker != NULL);
00050        g_assert(IS_USAGE_TRACKER(tracker));
00051 
00052        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Zero") == 0);
00053        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "One") == 1);
00054        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Two") == 2);
00055        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Three") == 3);
00056        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Four") == 4);
00057 
00058        g_object_unref(tracker);
00059        return;
00060 }
00061 
00062 static void
00063 test_usage_db_insert (void)
00064 {
00065        UsageTracker * tracker = usage_tracker_new();
00066        g_assert(tracker != NULL);
00067        g_assert(IS_USAGE_TRACKER(tracker));
00068 
00069        int i = 0;
00070 
00071        for (i = 0; i < 5; i++) {
00072               usage_tracker_mark_usage(tracker, "testapp.desktop", "Five");
00073        }
00074 
00075        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Five") == 5);
00076 
00077        for (i = 0; i < 100; i++) {
00078               usage_tracker_mark_usage(tracker, "testapp.desktop", "Hundred");
00079        }
00080 
00081        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Hundred") == 100);
00082 
00083        g_object_unref(tracker);
00084        return;
00085 }
00086 
00087 /* Build the test suite */
00088 static void
00089 test_usage_db_suite (void)
00090 {
00091        g_test_add_func ("/hud/usage/simple/base",          test_usage_db_base);
00092        g_test_add_func ("/hud/usage/simple/counts",        test_usage_db_counts);
00093        g_test_add_func ("/hud/usage/simple/insert",        test_usage_db_insert);
00094        return;
00095 }
00096 
00097 gint
00098 main (gint argc, gchar * argv[])
00099 {
00100        //gtk_init(&argc, &argv);
00101        g_type_init();
00102 
00103        g_test_init(&argc, &argv, NULL);
00104 
00105        /* Test suites */
00106        test_usage_db_suite();
00107 
00108        return g_test_run ();
00109 }