~ubuntu-branches/ubuntu/saucy/libusermetrics/saucy

« back to all changes in this revision

Viewing changes to tests/unit/qml/tst_Metrics.qml

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Pete Woods, Ugo Riboni, Ubuntu daily release
  • Date: 2013-09-24 22:45:08 UTC
  • mfrom: (1.1.18)
  • Revision ID: package-import@ubuntu.com-20130924224508-of7dy6421vnizx3f
Tags: 1.1.1+13.10.20130924-0ubuntu1
[ Pete Woods ]
* Add QML bindings to be able to set user metrics from declarative
  code. For now only part of the input API is supported.

[ Ugo Riboni ]
* Add QML bindings to be able to set user metrics from declarative
  code. For now only part of the input API is supported.

[ Ubuntu daily release ]
* Automatic snapshot from revision 132

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 */
 
17
 
 
18
import QtQuick 2.0
 
19
import QtTest 1.0
 
20
import UserMetrics 0.1
 
21
import UserMetricsTest 0.1
 
22
 
 
23
TestCase {
 
24
    name: "Increment"
 
25
    property string originalName: "test"
 
26
    property string originalFormat: "Test Metric"
 
27
    property string originalEmptyFormat: "Nope, no data"
 
28
    property string originalDomain: "test-domain"
 
29
 
 
30
    Metric {
 
31
        id: metric
 
32
        name: originalName
 
33
        format: originalFormat
 
34
        emptyFormat: originalEmptyFormat
 
35
        domain: originalDomain
 
36
    }
 
37
 
 
38
    function test_metric() {
 
39
        // Make sure the metric properties have been set properly
 
40
        var info = dbusQuery.queryMetricInfo(1);
 
41
        compare(info.name, originalName, "Metric name was not set properly");
 
42
        compare(info.format, originalFormat, "Metric format was not set properly");
 
43
        compare(info.emptyFormat, originalEmptyFormat, "Metric emptyFormat was not set properly");
 
44
        compare(info.domain, originalDomain, "Metric domain was not set properly");
 
45
 
 
46
        // Test update and increment with integers and floating point data
 
47
        metric.update(0);
 
48
        compare(dbusQuery.queryCurrentValue(1), 0, "Data not updated successfully")
 
49
        metric.increment();
 
50
        compare(dbusQuery.queryCurrentValue(1), 1, "Data not incremented successfully")
 
51
        metric.increment(7776);
 
52
        compare(dbusQuery.queryCurrentValue(1), 7777, "Data not incremented successfully")
 
53
        metric.increment(0.999);
 
54
        compare(dbusQuery.queryCurrentValue(1), 7777.999, "Data not incremented successfully")
 
55
        metric.update(5.5);
 
56
        compare(dbusQuery.queryCurrentValue(1), 5.5, "Data not updated successfully")
 
57
 
 
58
        // Check that when changing the metric format or emptyFormat nothing else changes and
 
59
        // no new metrics are created
 
60
        var newFormat = "Something else";
 
61
        var newEmptyFormat = "Still no data";
 
62
        var newDomain = "test-new-domain";
 
63
        metric.format = newFormat;
 
64
        metric.emptyFormat = newEmptyFormat;
 
65
        metric.domain = newDomain;
 
66
        info = dbusQuery.queryMetricInfo(1);
 
67
        compare(info.name, originalName, "Metric name was changed without requesting it");
 
68
        compare(info.format, newFormat, "Metric format was not changed properly");
 
69
        compare(info.emptyFormat, newEmptyFormat, "Metric emptyFormat was not changed properly");
 
70
        compare(info.domain, newDomain, "Metric domain was not changed properly");
 
71
        info = dbusQuery.queryMetricInfo(2);
 
72
        compare(info, null, "A new metric shouldn't have been created when just changing format");
 
73
 
 
74
        // Check that when changing the metric name a new metric is created with the new name
 
75
        var newName = "another_test";
 
76
        metric.name = newName;
 
77
        info = dbusQuery.queryMetricInfo(1);
 
78
        compare(info.name, originalName, "Metric 1 name was changed instead of creating new metric");
 
79
        info = dbusQuery.queryMetricInfo(2);
 
80
        compare(info.name, newName, "Metric 2 was not created with proper name");
 
81
        compare(info.format, newFormat, "Metric 2 was not created with proper format");
 
82
 
 
83
        // Check that now the "metric" object points to the newly created metric and changes to it don't
 
84
        // affect the old metric
 
85
        metric.update(0);
 
86
        compare(dbusQuery.queryCurrentValue(1), 5.5, "Metric 1 data was changed while metric 2 was in use");
 
87
        compare(dbusQuery.queryCurrentValue(2), 0, "Metric 2 data was not updated correctly");
 
88
        metric.increment(1.5);
 
89
        compare(dbusQuery.queryCurrentValue(1), 5.5, "Metric 1 data was changed while metric 2 was in use");
 
90
        compare(dbusQuery.queryCurrentValue(2), 1.5, "Metric 2 data was not incremented correctly");
 
91
 
 
92
        // Make sure that making the "metric" object point back to the original metric by restoring the
 
93
        // original name works fine and has no side effects.
 
94
        metric.name = originalName;
 
95
        metric.update(0);
 
96
        compare(dbusQuery.queryCurrentValue(1), 0, "Metric 1 data was not changed when pointing to it");
 
97
        compare(dbusQuery.queryCurrentValue(2), 1.5, "Metric 2 data was changed when pointing to metric 1");
 
98
        info = dbusQuery.queryMetricInfo(3);
 
99
        compare(info, null, "A new metric shouldn't have been created when pointing back to metric 1");
 
100
    }
 
101
}