@@ -0,0 +1,121 @@
1+/*
2+ * Copyright 2014 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+import QtQuick 2.0
18+import QtTest 1.0
19+import Unity.Test 0.1 as UT
20+import QMenuModel 0.1
21+import Unity.Indicators 0.1 as Indicators
22+
23+Item {
24+ id: root
25+ width: units.gu(40)
26+ height: units.gu(70)
27+
28+ Component {
29+ id: model
30+ Indicators.CachedUnityMenuModel {}
31+ }
32+
33+ UT.UnityTestCase {
34+ name: "CachedUnityMenuModel"
35+ when: windowShown
36+
37+ function test_createDifferent() {
38+ var cachedObject = model.createObject(root,
39+ {
40+ "busName": "com.canonical.test1",
41+ "menuObjectPath": "com/canonical/test1",
42+ "actionsObjectPath": "com/canonical/test1/actions"
43+ });
44+
45+ var cachedObject2 = model.createObject(root,
46+ {
47+ "busName": "com.canonical.test2",
48+ "menuObjectPath": "com/canonical/test2",
49+ "actionsObjectPath": "com/canonical/test2/actions"
50+ });
51+
52+ verify(cachedObject.model !== cachedObject2.model);
53+
54+ cachedObject.destroy();
55+ cachedObject2.destroy();
56+ }
57+
58+ function test_createSame() {
59+ var cachedObject = model.createObject(root,
60+ {
61+ "busName": "com.canonical.test1",
62+ "menuObjectPath": "com/canonical/test1",
63+ "actionsObjectPath": "com/canonical/test1/actions"
64+ });
65+
66+ var cachedObject2 = model.createObject(root,
67+ {
68+ "busName": "com.canonical.test1",
69+ "menuObjectPath": "com/canonical/test1",
70+ "actionsObjectPath": "com/canonical/test1/actions"
71+ });
72+
73+ verify(cachedObject.model === cachedObject2.model);
74+
75+ cachedObject.destroy();
76+ cachedObject2.destroy();
77+ }
78+
79+ function test_destroyAllDeletesModel() {
80+ var cachedObject = model.createObject(root,
81+ {
82+ "busName": "com.canonical.test1",
83+ "menuObjectPath": "com/canonical/test1",
84+ "actionsObjectPath": "com/canonical/test1/actions"
85+ });
86+
87+ var cachedObject2 = model.createObject(root,
88+ {
89+ "busName": "com.canonical.test1",
90+ "menuObjectPath": "com/canonical/test1",
91+ "actionsObjectPath": "com/canonical/test1/actions"
92+ });
93+
94+ var menuModel = cachedObject.model;
95+ cachedObject.destroy();
96+ cachedObject2.destroy();
97+ tryCompareFunction(function() { return Indicators.UnityMenuModelCache.contains(menuModel) }, false);
98+ }
99+
100+ function test_destroyPartialKeepsModel() {
101+ var cachedObject = model.createObject(root,
102+ {
103+ "busName": "com.canonical.test1",
104+ "menuObjectPath": "com/canonical/test1",
105+ "actionsObjectPath": "com/canonical/test1/actions"
106+ });
107+
108+ var cachedObject2 = model.createObject(root,
109+ {
110+ "busName": "com.canonical.test1",
111+ "menuObjectPath": "com/canonical/test1",
112+ "actionsObjectPath": "com/canonical/test1/actions"
113+ });
114+
115+ var menuModel = cachedObject.model;
116+ cachedObject.destroy();
117+ wait(1);
118+ compare(Indicators.UnityMenuModelCache.contains(menuModel), true);
119+ }
120+ }
121+}