@@ -1,292 +0,0 @@
2− * Copyright 2013 Canonical Ltd.
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.
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.
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/>.
19−import "../../../qml/Components/"
20−import "../../../qml/Components/carousel.js" as Carousel
21−import Unity.Test 0.1 as UT
31− property int createdDelegates: 0
32− property int destroyedDelegates: 0
34− itemComponent: BaseCarouselDelegate {
35− objectName: "carouselDelegate" + index
39− border.color: "black"
41− Component.onCompleted: carousel.createdDelegates++
42− Component.onDestruction: carousel.destroyedDelegates++
56− property real carouselWidth
57− property int itemCount
58− property real tileWidth
60− property Item listView: findChild(carousel, "listView")
62− property real contentWidth: itemCount * tileWidth
63− // following variables are copied from Carousel.qml
64− // I'm not using the variables directly from there, as then tileWidth and others would be affected as well
65− property real gapToMiddlePhase: Math.min(carouselWidth / 2 - tileWidth / 2, (contentWidth - carouselWidth) / 2)
66− property real gapToEndPhase: contentWidth - carouselWidth - gapToMiddlePhase
67− property real kMiddleIndex: (carouselWidth / 2) / tileWidth - 0.5
68− property real kGapEnd: kMiddleIndex * (1 - gapToEndPhase / gapToMiddlePhase)
69− property real kXBeginningEnd: 1 / tileWidth + kMiddleIndex / gapToMiddlePhase
73− waitForRendering(carousel)
74− listView.positionViewAtBeginning();
79− carousel.createdDelegates = 0;
80− carousel.destroyedDelegates = 0;
85− // This test needs to run first since it tests a corner case condition
86− // to where the carousel is just being created
87− // That is why it has a 1 in the name
88− function test_1onlyNeededItemsCreated() {
89− tryCompare(carousel, "createdDelegates", 9);
90− compare(carousel.destroyedDelegates, 0);
93− // test for the getContinuousIndex() function
94− function test_getContinuousIndex_data() {
95− // testing for 10 items of size 100 pixel
96− return [ {tag:"at start",
97− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, result: 0},
99− x: 100, carouselWidth:400, tileWidth:100, itemCount:10, result: 2},
100− {tag:"in the middle",
101− x: 350, carouselWidth:400, tileWidth:100, itemCount:10, result: 5},
103− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, result: 9},
107− function test_getContinuousIndex(data) {
108− root.carouselWidth = data.carouselWidth
109− root.tileWidth = data.tileWidth
110− root.itemCount = data.itemCount
112− var index = Carousel.getContinuousIndex(data.x,
119− compare(index, data.result)
122− // test for the getXFromContinuousIndex() function
123− function test_getXFromContinuousIndex_data() {
124− return [ {tag:"at start",
125− index: 0, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 0},
127− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 100},
128− {tag:"in startup with drawBuffer",
129− index: 2, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 0},
130− {tag:"in the middle",
131− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 350},
132− {tag:"in the middle with drawBuffer",
133− index: 5, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 250},
135− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:0, result: 600},
136− {tag:"at end with drawBuffer",
137− index: 9, carouselWidth:400, tileWidth:100, itemCount:10, drawBuffer:100, result: 500},
141− function test_getXFromContinuousIndex(data) {
142− root.carouselWidth = data.carouselWidth
143− root.tileWidth = data.tileWidth
144− root.itemCount = data.itemCount
146− var x = Carousel.getXFromContinuousIndex(data.index,
153− compare(x, data.result)
156− // test for the getViewTranslation() function
157− function test_getViewTranslation_data() {
158− return [ {tag:"at start - viewfactor 1",
159− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 150},
160− {tag:"at start - viewfactor 2",
161− x: 0, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:2, result: 300},
163− x: 100, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 50},
164− {tag:"in the middle",
165− x: 350, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: 0},
167− x: 600, carouselWidth:400, tileWidth:100, itemCount:10, translationXViewFactor:1, result: -150},
171− function test_getViewTranslation(data) {
172− root.carouselWidth = data.carouselWidth
173− root.tileWidth = data.tileWidth
174− root.itemCount = data.itemCount
176− var x = Carousel.getViewTranslation(data.x,
178− root.gapToMiddlePhase,
180− data.translationXViewFactor)
181− compare(x, data.result)
184− // test for the getItemScale() function
185− function test_getItemScale_data() {
186− return [ // tests for distance
187− {distance: 0, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 1},
188− {distance: 9, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
189− {distance: 999, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.01},
190− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
191− {distance: 3, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.688230855}, // = 1 - (3^2.5 / 50)
192− // tests for continuousIndex
193− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
194− {distance: 1, continuousIndex: 97, numberOfItems: 100, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
195− // tests for numberOfItems
196− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
197− {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
198− // tests for scaleFactor
199− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 1, result: 0.98}, // = 1 - (1 / 50)
200− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 2, result: 0.99}, // = 1 - (1 / 100)
201− {distance: 1, continuousIndex: 50, numberOfItems: 100, scaleFactor: 0.5, result: 0.96}, // = 1 - (1 / 25)
202− {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 1, result: 0.99}, // = 1 - (1 / 100) - distanceToBounds is used
203− {distance: 1, continuousIndex: 50, numberOfItems: 53, scaleFactor: 2, result: 0.996666666}, // = 1 - (1 / 300) - distanceToBounds is used
207− function test_getItemScale(data) {
208− var scale = Carousel.getItemScale(data.distance,
209− data.continuousIndex,
212− compare(scale, data.result)
215− // test for the getItemTranslation() function
216− function test_getItemTranslation_data() {
217− return [ // tests for index and selectedIndex
218− {index: 1, selectedIndex: 1, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
219− // tests if distance only affects the sign
220− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
221− {index: 1, selectedIndex: 2, distance: 99, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
222− {index: 1, selectedIndex: 2, distance: -1, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
223− {index: 1, selectedIndex: 2, distance: -99, scale: 0, maxScale: 1, maxTranslation: 10, result: -10},
224− // tests for the scale
225− {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 10, result: 0},
226− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
227− {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 1, maxTranslation: 10, result: 5},
228− // tests for maxScale
229− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 0.98, maxTranslation: 10, result: 9.8},
230− {index: 1, selectedIndex: 2, distance: 1, scale: 0.5, maxScale: 0.95, maxTranslation: 10, result: 4.5},
231− {index: 1, selectedIndex: 2, distance: 1, scale: 0.8, maxScale: 0.93, maxTranslation: 10, result: 1.3},
232− // test for maxTranslation
233− {index: 1, selectedIndex: 2, distance: 1, scale: 1, maxScale: 1, maxTranslation: 1, result: 0},
234− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 1, result: 1},
235− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 10, result: 10},
236− {index: 1, selectedIndex: 2, distance: 1, scale: 0, maxScale: 1, maxTranslation: 0, result: 0},
240− function test_getItemTranslation(data) {
241− var scale = Carousel.getItemTranslation(data.index,
246− data.maxTranslation)
247− compare(scale, data.result)
250− function test_lastItemXPosition() {
251− var carouselList = findChild(carousel, "listView");
252− var stepAnimation = findInvisibleChild(carouselList, "stepAnimation");
254− stepAnimation.onRunningChanged.connect(function() { if (stepAnimation.running) stepDiff = Math.abs(carouselList.contentX - stepAnimation.to); })
255− var overshootOnce = false;
256− while (!overshootOnce) {
257− overshootOnce = carouselList.realContentX > carouselList.realContentWidth - carouselList.realWidth;
258− mouseFlick(carousel, carousel.width - units.gu(1),
259− carousel.height / 2,
261− carousel.height / 2);
262− tryCompare(carouselList, "moving", false);
264− verify(stepDiff < 1);
265− var x = carouselList.getXFromContinuousIndex(carousel.model - 1);
266− verify(Math.abs(x - carouselList.contentX) < 1);
269− function test_activate() {
270− var carouselList = findChild(carousel, "listView");
271− var carouselItem = findChild(carousel, "carouselDelegate3")
272− verify(carouselItem, "Could not find delegate");
274− spy.signalName = "clicked";
275− spy.target = carouselItem;
276− mouseClick(carouselItem);
277− tryCompare(carouselList, "moving", false);
278− tryCompare(carouselItem, "explicitlyScaled", true);
279− mouseClick(carouselItem);
282− spy.signalName = "pressAndHold";
283− spy.target = carouselItem;
284− mouseClick(carouselItem);
285− tryCompare(carouselList, "moving", false);
286− tryCompare(carouselItem, "explicitlyScaled", true);
287− mousePress(carouselItem);
289− mouseRelease(carouselItem);