~sil2100/indicator-appmenu/indicator-appmenu-qt5

« back to all changes in this revision

Viewing changes to tests/test-usage-db-simple.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
 
Test function to ensure we can use a simple databse
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 <glib.h>
23
 
#include <glib-object.h>
24
 
 
25
 
#include "hudsettings.h"
26
 
#include "load-app-info.h"
27
 
#include "usage-tracker.h"
28
 
 
29
 
HudSettings hud_settings = {
30
 
  .store_usage_data = TRUE
31
 
};
32
 
 
33
 
/* Ensure the base object works */
34
 
static void
35
 
test_usage_db_base (void)
36
 
{
37
 
        UsageTracker * tracker = usage_tracker_new();
38
 
        g_assert(tracker != NULL);
39
 
        g_assert(IS_USAGE_TRACKER(tracker));
40
 
 
41
 
        g_object_unref(tracker);
42
 
        return;
43
 
}
44
 
 
45
 
static void
46
 
test_usage_db_counts (void)
47
 
{
48
 
        UsageTracker * tracker = usage_tracker_new();
49
 
        g_assert(tracker != NULL);
50
 
        g_assert(IS_USAGE_TRACKER(tracker));
51
 
 
52
 
        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Zero") == 0);
53
 
        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "One") == 1);
54
 
        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Two") == 2);
55
 
        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Three") == 3);
56
 
        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Four") == 4);
57
 
 
58
 
        g_object_unref(tracker);
59
 
        return;
60
 
}
61
 
 
62
 
static void
63
 
test_usage_db_insert (void)
64
 
{
65
 
        UsageTracker * tracker = usage_tracker_new();
66
 
        g_assert(tracker != NULL);
67
 
        g_assert(IS_USAGE_TRACKER(tracker));
68
 
 
69
 
        int i = 0;
70
 
 
71
 
        for (i = 0; i < 5; i++) {
72
 
                usage_tracker_mark_usage(tracker, "testapp.desktop", "Five");
73
 
        }
74
 
 
75
 
        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Five") == 5);
76
 
 
77
 
        for (i = 0; i < 100; i++) {
78
 
                usage_tracker_mark_usage(tracker, "testapp.desktop", "Hundred");
79
 
        }
80
 
 
81
 
        g_assert(usage_tracker_get_usage(tracker, "testapp.desktop", "Hundred") == 100);
82
 
 
83
 
        g_object_unref(tracker);
84
 
        return;
85
 
}
86
 
 
87
 
/* Build the test suite */
88
 
static void
89
 
test_usage_db_suite (void)
90
 
{
91
 
        g_test_add_func ("/hud/usage/simple/base",          test_usage_db_base);
92
 
        g_test_add_func ("/hud/usage/simple/counts",        test_usage_db_counts);
93
 
        g_test_add_func ("/hud/usage/simple/insert",        test_usage_db_insert);
94
 
        return;
95
 
}
96
 
 
97
 
gint
98
 
main (gint argc, gchar * argv[])
99
 
{
100
 
        g_test_init(&argc, &argv, NULL);
101
 
 
102
 
        /* Test suites */
103
 
        test_usage_db_suite();
104
 
 
105
 
        return g_test_run ();
106
 
}