• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.graphics.cts;
17 
18 import android.graphics.Matrix;
19 import android.graphics.RectF;
20 import android.graphics.Matrix.ScaleToFit;
21 import android.test.AndroidTestCase;
22 import dalvik.annotation.TestTargets;
23 import dalvik.annotation.TestLevel;
24 import dalvik.annotation.TestTargetNew;
25 import dalvik.annotation.TestTargetClass;
26 
27 @TestTargetClass(Matrix.class)
28 public class MatrixTest extends AndroidTestCase {
29     private Matrix mMatrix;
30     private float[] mValues;
31 
32     @Override
setUp()33     protected void setUp() throws Exception {
34         super.setUp();
35         mMatrix = new Matrix();
36         mValues = new float[9];
37     }
38 
39     @TestTargets({
40         @TestTargetNew(
41             level = TestLevel.COMPLETE,
42             method = "Matrix",
43             args = {}
44         ),
45         @TestTargetNew(
46             level = TestLevel.COMPLETE,
47             method = "Matrix",
48             args = {android.graphics.Matrix.class}
49         ),
50         @TestTargetNew(
51             level = TestLevel.COMPLETE,
52             method = "finalize",
53             args = {}
54         )
55     })
testConstractor()56     public void testConstractor() {
57         new Matrix();
58         new Matrix(mMatrix);
59     }
60 
61     @TestTargetNew(
62         level = TestLevel.COMPLETE,
63         method = "isIdentity",
64         args = {}
65     )
testIsIdentity()66     public void testIsIdentity() {
67         assertTrue(mMatrix.isIdentity());
68         mMatrix.setScale(0f, 0f);
69         assertFalse(mMatrix.isIdentity());
70     }
71 
72     @TestTargetNew(
73         level = TestLevel.COMPLETE,
74         method = "rectStaysRect",
75         args = {}
76     )
testRectStaysRect()77     public void testRectStaysRect() {
78         assertTrue(mMatrix.rectStaysRect());
79         mMatrix.postRotate(80);
80         assertFalse(mMatrix.rectStaysRect());
81     }
82 
83     @TestTargetNew(
84         level = TestLevel.COMPLETE,
85         method = "set",
86         args = {android.graphics.Matrix.class}
87     )
testSet()88     public void testSet() {
89         mValues[0] = 1000;
90         mMatrix.getValues(mValues);
91         Matrix matrix = new Matrix();
92         matrix.set(mMatrix);
93         mValues = new float[9];
94         mValues[0] = 2000;
95         matrix.getValues(mValues);
96         assertEquals(1f, mValues[0]);
97     }
98 
99     @TestTargetNew(
100         level = TestLevel.COMPLETE,
101         method = "equals",
102         args = {java.lang.Object.class}
103     )
testEquals()104     public void testEquals() {
105         mMatrix.setScale(1f, 2f);
106         Matrix matrix = new Matrix();
107         matrix.set(mMatrix);
108         assertFalse(mMatrix.equals(null));
109         assertFalse(mMatrix.equals(new String()));
110         assertTrue(mMatrix.equals(matrix));
111     }
112 
113     @TestTargetNew(
114         level = TestLevel.COMPLETE,
115         method = "reset",
116         args = {}
117     )
testReset()118     public void testReset() {
119         mMatrix.setScale(1f, 2f, 3f, 4f);
120         String expect = "[1.0, 0.0, 0.0][0.0, 2.0, -4.0][0.0, 0.0, 1.0]";
121         assertEquals(expect, mMatrix.toShortString());
122         mMatrix.reset();
123         expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
124         assertEquals(expect, mMatrix.toShortString());
125     }
126 
127     @TestTargetNew(
128         level = TestLevel.COMPLETE,
129         method = "setScale",
130         args = {float.class, float.class}
131     )
testSetScale()132     public void testSetScale() {
133         String expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
134         assertEquals(expect, mMatrix.toShortString());
135         mMatrix.setScale(1f, 2f);
136         expect = "[1.0, 0.0, 0.0][0.0, 2.0, 0.0][0.0, 0.0, 1.0]";
137         assertEquals(expect, mMatrix.toShortString());
138     }
139 
140     @TestTargetNew(
141         level = TestLevel.COMPLETE,
142         method = "setScale",
143         args = {float.class, float.class, float.class, float.class}
144     )
testSetScale2()145     public void testSetScale2() {
146         String expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
147         assertEquals(expect, mMatrix.toShortString());
148 
149         mMatrix.setScale(1f, 2f, 3f, 4f);
150         expect = "[1.0, 0.0, 0.0][0.0, 2.0, -4.0][0.0, 0.0, 1.0]";
151         assertEquals(expect, mMatrix.toShortString());
152     }
153 
154     @TestTargetNew(
155         level = TestLevel.COMPLETE,
156         method = "setRotate",
157         args = {float.class}
158     )
testSetRotate()159     public void testSetRotate() {
160         mMatrix.setRotate(1f);
161         String expect = "[0.9998477, -0.017452406, 0.0]"
162                 + "[0.017452406, 0.9998477, 0.0][0.0, 0.0, 1.0]";
163         assertEquals(expect, mMatrix.toShortString());
164     }
165 
166     @TestTargetNew(
167         level = TestLevel.COMPLETE,
168         method = "setRotate",
169         args = {float.class, float.class, float.class}
170     )
testSetRotate2()171     public void testSetRotate2() {
172         mMatrix.setRotate(1f, 2f, 3f);
173         String expect = "[0.9998477, -0.017452406, 0.0526618]"
174                 + "[0.017452406, 0.9998477, -0.034447942][0.0, 0.0, 1.0]";
175         assertEquals(expect, mMatrix.toShortString());
176     }
177 
178     @TestTargetNew(
179         level = TestLevel.COMPLETE,
180         method = "setSinCos",
181         args = {float.class, float.class}
182     )
testSetSinCos()183     public void testSetSinCos() {
184         mMatrix.setSinCos(1f, 2f);
185         String expect = "[2.0, -1.0, 0.0][1.0, 2.0, 0.0][0.0, 0.0, 1.0]";
186         assertEquals(expect, mMatrix.toShortString());
187     }
188 
189     @TestTargetNew(
190         level = TestLevel.COMPLETE,
191         method = "setSinCos",
192         args = {float.class, float.class, float.class, float.class}
193     )
testSetSinCos2()194     public void testSetSinCos2() {
195         mMatrix.setSinCos(1f, 2f, 3f, 4f);
196         String expect = "[2.0, -1.0, 1.0][1.0, 2.0, -7.0][0.0, 0.0, 1.0]";
197         assertEquals(expect, mMatrix.toShortString());
198     }
199 
200     @TestTargetNew(
201         level = TestLevel.COMPLETE,
202         method = "setSkew",
203         args = {float.class, float.class}
204     )
testSetSkew()205     public void testSetSkew() {
206         mMatrix.setSkew(1f, 2f);
207         String expect = "[1.0, 1.0, 0.0][2.0, 1.0, 0.0][0.0, 0.0, 1.0]";
208         assertEquals(expect, mMatrix.toShortString());
209     }
210 
211     @TestTargetNew(
212         level = TestLevel.COMPLETE,
213         method = "setSkew",
214         args = {float.class, float.class, float.class, float.class}
215     )
testSetSkew2()216     public void testSetSkew2() {
217         mMatrix.setSkew(1f, 2f, 3f, 4f);
218         String expect = "[1.0, 1.0, -4.0][2.0, 1.0, -6.0][0.0, 0.0, 1.0]";
219         assertEquals(expect, mMatrix.toShortString());
220     }
221 
222     @TestTargetNew(
223         level = TestLevel.COMPLETE,
224         method = "setConcat",
225         args = {android.graphics.Matrix.class, android.graphics.Matrix.class}
226     )
testSetConcat()227     public void testSetConcat() {
228         Matrix a = new Matrix();
229         Matrix b = new Matrix();
230         mMatrix.setConcat(a, b);
231         String expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
232         assertEquals(expect, mMatrix.toShortString());
233         mMatrix = new Matrix();
234         mMatrix.setConcat(mMatrix, b);
235         mMatrix.setConcat(a, b);
236         expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
237         assertEquals(expect, mMatrix.toShortString());
238         mMatrix = new Matrix();
239         mValues = new float[9];
240         mMatrix.setConcat(a, mMatrix);
241         mMatrix.getValues(mValues);
242         expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
243         assertEquals(expect, mMatrix.toShortString());
244     }
245 
246     @TestTargetNew(
247         level = TestLevel.COMPLETE,
248         method = "preTranslate",
249         args = {float.class, float.class}
250     )
testPreTranslate()251     public void testPreTranslate() {
252         assertTrue(mMatrix.preTranslate(1f, 2f));
253         String expect = "[1.0, 0.0, 1.0][0.0, 1.0, 2.0][0.0, 0.0, 1.0]";
254         assertEquals(expect, mMatrix.toShortString());
255     }
256 
257     @TestTargetNew(
258         level = TestLevel.COMPLETE,
259         method = "preScale",
260         args = {float.class, float.class}
261     )
testPreScale()262     public void testPreScale() {
263         assertTrue(mMatrix.preScale(1f, 2f));
264         String expect = "[1.0, 0.0, 0.0][0.0, 2.0, 0.0][0.0, 0.0, 1.0]";
265         assertEquals(expect, mMatrix.toShortString());
266     }
267 
268     @TestTargetNew(
269         level = TestLevel.COMPLETE,
270         method = "preScale",
271         args = {float.class, float.class, float.class, float.class}
272     )
testPreScale2()273     public void testPreScale2() {
274         assertTrue(mMatrix.preScale(1f, 2f, 3f, 4f));
275         String expect = "[1.0, 0.0, 0.0][0.0, 2.0, -4.0][0.0, 0.0, 1.0]";
276         assertEquals(expect, mMatrix.toShortString());
277     }
278 
279     @TestTargetNew(
280         level = TestLevel.COMPLETE,
281         method = "preRotate",
282         args = {float.class}
283     )
testPreRotate()284     public void testPreRotate() {
285         assertTrue(mMatrix.preRotate(1f));
286         String expect = "[0.9998477, -0.017452406, 0.0][0.017452406, 0.9998477, "
287                 + "0.0][0.0, 0.0, 1.0]";
288         assertEquals(expect, mMatrix.toShortString());
289     }
290 
291     @TestTargetNew(
292         level = TestLevel.COMPLETE,
293         method = "preRotate",
294         args = {float.class, float.class, float.class}
295     )
testPreRotate2()296     public void testPreRotate2() {
297         assertTrue(mMatrix.preRotate(1f, 2f, 3f));
298         float[] values = new float[9];
299         mMatrix.getValues(values);
300         String expect = "[0.9998477, -0.017452406, 0.0526618][0.017452406, 0.9998477,"
301                 + " -0.034447942][0.0, 0.0, 1.0]";
302         assertEquals(expect, mMatrix.toShortString());
303     }
304 
305     @TestTargetNew(
306         level = TestLevel.COMPLETE,
307         method = "preSkew",
308         args = {float.class, float.class}
309     )
testPreSkew()310     public void testPreSkew() {
311         assertTrue(mMatrix.preSkew(1f, 2f));
312         String expect = "[1.0, 1.0, 0.0][2.0, 1.0, 0.0][0.0, 0.0, 1.0]";
313         assertEquals(expect, mMatrix.toShortString());
314     }
315 
316     @TestTargetNew(
317         level = TestLevel.COMPLETE,
318         method = "preSkew",
319         args = {float.class, float.class, float.class, float.class}
320     )
testPreSkew2()321     public void testPreSkew2() {
322         assertTrue(mMatrix.preSkew(1f, 2f, 3f, 4f));
323         String expect = "[1.0, 1.0, -4.0][2.0, 1.0, -6.0][0.0, 0.0, 1.0]";
324         assertEquals(expect, mMatrix.toShortString());
325     }
326 
327     @TestTargetNew(
328         level = TestLevel.COMPLETE,
329         method = "preConcat",
330         args = {android.graphics.Matrix.class}
331     )
testPreConcat()332     public void testPreConcat() {
333         float[] values = new float[9];
334         values[0] = 1000;
335         Matrix matrix = new Matrix();
336         matrix.setValues(values);
337         assertTrue(mMatrix.preConcat(matrix));
338         String expect = "[1000.0, 0.0, 0.0][0.0, 0.0, 0.0][0.0, 0.0, 0.0]";
339         assertEquals(expect, mMatrix.toShortString());
340     }
341 
342     @TestTargetNew(
343         level = TestLevel.COMPLETE,
344         method = "postTranslate",
345         args = {float.class, float.class}
346     )
testPostTranslate()347     public void testPostTranslate() {
348         assertTrue(mMatrix.postTranslate(1f, 2f));
349         String expect = "[1.0, 0.0, 1.0][0.0, 1.0, 2.0][0.0, 0.0, 1.0]";
350         assertEquals(expect, mMatrix.toShortString());
351     }
352 
353     @TestTargetNew(
354         level = TestLevel.COMPLETE,
355         method = "postScale",
356         args = {float.class, float.class}
357     )
testPostScale()358     public void testPostScale() {
359         assertTrue(mMatrix.postScale(1f, 2f));
360         String expect = "[1.0, 0.0, 0.0][0.0, 2.0, 0.0][0.0, 0.0, 1.0]";
361         assertEquals(expect, mMatrix.toShortString());
362     }
363 
364     @TestTargetNew(
365         level = TestLevel.COMPLETE,
366         method = "postScale",
367         args = {float.class, float.class, float.class, float.class}
368     )
testPostScale2()369     public void testPostScale2() {
370         assertTrue(mMatrix.postScale(1f, 2f, 3f, 4f));
371         String expect = "[1.0, 0.0, 0.0][0.0, 2.0, -4.0][0.0, 0.0, 1.0]";
372         assertEquals(expect, mMatrix.toShortString());
373     }
374 
375     @TestTargetNew(
376         level = TestLevel.COMPLETE,
377         method = "postRotate",
378         args = {float.class}
379     )
testPostRotate()380     public void testPostRotate() {
381         assertTrue(mMatrix.postRotate(1f));
382         String expect = "[0.9998477, -0.017452406, 0.0]" +
383          "[0.017452406, 0.9998477, 0.0][0.0, 0.0, 1.0]";
384         assertEquals(expect, mMatrix.toShortString());
385     }
386 
387     @TestTargetNew(
388         level = TestLevel.COMPLETE,
389         method = "postRotate",
390         args = {float.class, float.class, float.class}
391     )
testPostRotate2()392     public void testPostRotate2() {
393         assertTrue(mMatrix.postRotate(1f, 2f, 3f));
394         String expect = "[0.9998477, -0.017452406, 0.0526618]" +
395         "[0.017452406, 0.9998477, -0.034447942][0.0, 0.0, 1.0]";
396         assertEquals(expect, mMatrix.toShortString());
397     }
398 
399     @TestTargetNew(
400         level = TestLevel.COMPLETE,
401         method = "postSkew",
402         args = {float.class, float.class}
403     )
testPostSkew()404     public void testPostSkew() {
405         assertTrue(mMatrix.postSkew(1f, 2f));
406         String expect = "[1.0, 1.0, 0.0][2.0, 1.0, 0.0][0.0, 0.0, 1.0]";
407         assertEquals(expect, mMatrix.toShortString());
408     }
409 
410     @TestTargetNew(
411         level = TestLevel.COMPLETE,
412         method = "postSkew",
413         args = {float.class, float.class, float.class, float.class}
414     )
testPostSkew2()415     public void testPostSkew2() {
416         assertTrue(mMatrix.postSkew(1f, 2f, 3f, 4f));
417         String expect = "[1.0, 1.0, -4.0][2.0, 1.0, -6.0][0.0, 0.0, 1.0]";
418         assertEquals(expect, mMatrix.toShortString());
419     }
420 
421     @TestTargetNew(
422         level = TestLevel.COMPLETE,
423         method = "postConcat",
424         args = {android.graphics.Matrix.class}
425     )
testPostConcat()426     public void testPostConcat() {
427         Matrix matrix = new Matrix();
428         float[] values = new float[9];
429         values[0] = 1000;
430         matrix.setValues(values);
431         assertTrue(mMatrix.postConcat(matrix));
432 
433         String expect = "[1000.0, 0.0, 0.0][0.0, 0.0, 0.0][0.0, 0.0, 0.0]";
434         assertEquals(expect, mMatrix.toShortString());
435     }
436 
437     @TestTargetNew(
438         level = TestLevel.COMPLETE,
439         method = "setRectToRect",
440         args = {android.graphics.RectF.class, android.graphics.RectF.class,
441                 android.graphics.Matrix.ScaleToFit.class}
442     )
testSetRectToRect()443     public void testSetRectToRect() {
444         RectF r1 = new RectF();
445         r1.set(1f, 2f, 3f, 3f);
446         RectF r2 = new RectF();
447         r1.set(10f, 20f, 30f, 30f);
448         assertTrue(mMatrix.setRectToRect(r1, r2, ScaleToFit.CENTER));
449         String expect = "[0.0, 0.0, 0.0][0.0, 0.0, 0.0][0.0, 0.0, 1.0]";
450         assertEquals(expect, mMatrix.toShortString());
451         mMatrix.setRectToRect(r1, r2, ScaleToFit.END);
452 
453         assertEquals(expect, mMatrix.toShortString());
454         mMatrix.setRectToRect(r1, r2, ScaleToFit.FILL);
455         assertEquals(expect, mMatrix.toShortString());
456         mMatrix.setRectToRect(r1, r2, ScaleToFit.START);
457         assertEquals(expect, mMatrix.toShortString());
458 
459         assertFalse(mMatrix.setRectToRect(r2, r1, ScaleToFit.CENTER));
460 
461         expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
462         assertEquals(expect, mMatrix.toShortString());
463         assertFalse(mMatrix.setRectToRect(r2, r1, ScaleToFit.FILL));
464         assertEquals(expect, mMatrix.toShortString());
465         assertFalse(mMatrix.setRectToRect(r2, r1, ScaleToFit.START));
466         assertEquals(expect, mMatrix.toShortString());
467         assertFalse(mMatrix.setRectToRect(r2, r1, ScaleToFit.END));
468         assertEquals(expect, mMatrix.toShortString());
469 
470         try {
471             mMatrix.setRectToRect(null, null, ScaleToFit.CENTER);
472             fail("should throw exception");
473         } catch (Exception e) {
474         }
475     }
476 
477     @TestTargetNew(
478         level = TestLevel.COMPLETE,
479         method = "invert",
480         args = {android.graphics.Matrix.class}
481     )
testInvert()482     public void testInvert() {
483         Matrix matrix = new Matrix();
484         float[] values = new float[9];
485         values[0] = 1000f;
486         matrix.setValues(values);
487         assertTrue(mMatrix.invert(matrix));
488         String expect = "[1.0, -0.0, 0.0][-0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
489         assertEquals(expect, matrix.toShortString());
490         expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
491         assertEquals(expect, mMatrix.toShortString());
492         boolean result = false;
493         try {
494             result = mMatrix.invert(null);
495             fail("should throw exception");
496         } catch (Exception e) {
497         }
498         assertFalse(result);
499     }
500 
501     @TestTargetNew(
502         level = TestLevel.COMPLETE,
503         method = "setPolyToPoly",
504         args = {float[].class, int.class, float[].class, int.class, int.class}
505     )
testSetPolyToPoly()506     public void testSetPolyToPoly() {
507         float[] src = new float[9];
508         src[0] = 100f;
509         float[] dst = new float[9];
510         dst[0] = 200f;
511         dst[1] = 300f;
512         assertTrue(mMatrix.setPolyToPoly(src, 0, dst, 0, 1));
513         String expect = "[1.0, 0.0, 100.0][0.0, 1.0, 300.0][0.0, 0.0, 1.0]";
514         assertEquals(expect, mMatrix.toShortString());
515         try {
516             mMatrix.setPolyToPoly(src, 0, dst, 0, 5);
517             fail("should throw exception");
518         } catch (Exception e) {
519         }
520     }
521 
522     @TestTargetNew(
523         level = TestLevel.COMPLETE,
524         method = "mapPoints",
525         args = {float[].class}
526     )
testMapPoints()527     public void testMapPoints() {
528         float[] value = new float[9];
529         value[0] = 100f;
530         mMatrix.mapPoints(value);
531         assertEquals(value[0], 100f);
532         try {
533             mMatrix.mapPoints(null);
534             fail("should throw exception");
535         } catch (Exception e) {
536         }
537     }
538 
539     @TestTargetNew(
540         level = TestLevel.COMPLETE,
541         method = "mapPoints",
542         args = {float[].class, float[].class}
543     )
testMapPoints2()544     public void testMapPoints2() {
545         float[] dst = new float[9];
546         dst[0] = 100f;
547         float[] src = new float[9];
548         src[0] = 200f;
549         mMatrix.mapPoints(dst, src);
550         assertEquals(dst[0], 200f);
551         try {
552             mMatrix.mapPoints(new float[8], new float[9]);
553             fail("should throw exception");
554         } catch (Exception e) {
555         }
556     }
557 
558     @TestTargetNew(
559         level = TestLevel.COMPLETE,
560         method = "mapPoints",
561         args = {float[].class, int.class, float[].class, int.class, int.class}
562     )
testMapPoints3()563     public void testMapPoints3() {
564         float[] dst = new float[9];
565         dst[0] = 100f;
566         float[] src = new float[9];
567         src[0] = 200f;
568         mMatrix.mapPoints(dst, 0, src, 0, 9 >> 1);
569         assertEquals(dst[0], 200f);
570         try {
571             mMatrix.mapPoints(null, 0, new float[9], 0, 1);
572             fail("should throw exception");
573         } catch (Exception e) {
574         }
575     }
576 
577     @TestTargetNew(
578         level = TestLevel.COMPLETE,
579         method = "mapVectors",
580         args = {float[].class}
581     )
testMapVectors()582     public void testMapVectors() {
583         float[] values = new float[9];
584         values = new float[9];
585         values[0] = 100f;
586         mMatrix.mapVectors(values);
587         assertEquals(values[0], 100f);
588         try {
589             mMatrix.mapVectors(null);
590             fail("should throw exception");
591         } catch (Exception e) {
592         }
593     }
594 
595     @TestTargetNew(
596         level = TestLevel.COMPLETE,
597         method = "mapVectors",
598         args = {float[].class, float[].class}
599     )
testMapVectors2()600     public void testMapVectors2() {
601         float[] src = new float[9];
602         src[0] = 100f;
603         float[] dst = new float[9];
604         dst[0] = 200f;
605         mMatrix.mapVectors(dst, src);
606         assertEquals(dst[0], 100f);
607 
608         try {
609             mMatrix.mapVectors(new float[9], new float[8]);
610             fail("should throw exception");
611         } catch (Exception e) {
612         }
613     }
614 
615     @TestTargetNew(
616         level = TestLevel.COMPLETE,
617         method = "mapVectors",
618         args = {float[].class, int.class, float[].class, int.class, int.class}
619     )
testMapVectors3()620     public void testMapVectors3() {
621         float[] src = new float[9];
622         src[0] = 100f;
623         float[] dst = new float[9];
624         dst[0] = 200f;
625         mMatrix.mapVectors(dst, 0, src, 0, 1);
626         assertEquals(dst[0], 100f);
627         try {
628             mMatrix.mapVectors(dst, 0, src, 0, 10);
629             fail("should throw exception");
630         } catch (Exception e) {
631         }
632     }
633 
634     @TestTargetNew(
635         level = TestLevel.COMPLETE,
636         method = "mapRadius",
637         args = {float.class}
638     )
testMapRadius()639     public void testMapRadius() {
640         assertEquals(mMatrix.mapRadius(100f), 100f);
641         assertEquals(mMatrix.mapRadius(Float.MAX_VALUE),
642                 Float.POSITIVE_INFINITY);
643         assertEquals(mMatrix.mapRadius(Float.MIN_VALUE), 0f);
644     }
645 
646     @TestTargetNew(
647         level = TestLevel.COMPLETE,
648         method = "mapRect",
649         args = {android.graphics.RectF.class}
650     )
testMapRect()651     public void testMapRect() {
652         RectF r = new RectF();
653         r.set(1f, 2f, 3f, 4f);
654         assertTrue(mMatrix.mapRect(r));
655         assertEquals(1f, r.left);
656         assertEquals(2f, r.top);
657         assertEquals(3f, r.right);
658         assertEquals(4f, r.bottom);
659 
660         try {
661             mMatrix.mapRect(null);
662             fail("should throw exception");
663         } catch (Exception e) {
664         }
665     }
666 
667     @TestTargetNew(
668         level = TestLevel.COMPLETE,
669         method = "mapRect",
670         args = {android.graphics.RectF.class, android.graphics.RectF.class}
671     )
testMapRect2()672     public void testMapRect2() {
673         RectF dst = new RectF();
674         dst.set(100f, 100f, 200f, 200f);
675         RectF src = new RectF();
676         dst.set(10f, 10f, 20f, 20f);
677         assertTrue(mMatrix.mapRect(dst, src));
678         assertEquals(0f, dst.left);
679         assertEquals(0f, dst.top);
680         assertEquals(0f, dst.right);
681         assertEquals(0f, dst.bottom);
682 
683         assertEquals(0f, src.left);
684         assertEquals(0f, src.top);
685         assertEquals(0f, src.right);
686         assertEquals(0f, src.bottom);
687 
688         try {
689             mMatrix.mapRect(null, null);
690             fail("should throw exception");
691         } catch (Exception e) {
692         }
693     }
694 
695     @TestTargets({
696         @TestTargetNew(
697             level = TestLevel.COMPLETE,
698             method = "setValues",
699             args = {float[].class}
700         ),
701         @TestTargetNew(
702             level = TestLevel.COMPLETE,
703             method = "getValues",
704             args = {float[].class}
705         )
706     })
testAccessValues()707     public void testAccessValues() {
708         Matrix matrix = new Matrix();
709         mMatrix.invert(matrix);
710         float[] values = new float[9];
711         values[0] = 9f;
712         values[1] = 100f;
713         mMatrix.setValues(values);
714         values = new float[9];
715         mMatrix.getValues(values);
716         String expect = "[9.0, 100.0, 0.0][0.0, 0.0, 0.0][0.0, 0.0, 0.0]";
717         assertEquals(expect, toShortString(values));
718     }
719 
toShortString(float[] values)720     private String toShortString(float[] values) {
721         return "[" + values[0] + ", " + values[1] + ", " + values[2] + "]["
722                 + values[3] + ", " + values[4] + ", " + values[5] + "]["
723                 + values[6] + ", " + values[7] + ", " + values[8] + "]";
724     }
725 
726     @TestTargetNew(
727         level = TestLevel.COMPLETE,
728         method = "toString",
729         args = {}
730     )
testToString()731     public void testToString() {
732         assertNotNull(mMatrix.toString());
733     }
734 
735     @TestTargetNew(
736         level = TestLevel.COMPLETE,
737         method = "toShortString",
738         args = {}
739     )
testToShortString()740     public void testToShortString() {
741         String expect = "[1.0, 0.0, 0.0][0.0, 1.0, 0.0][0.0, 0.0, 1.0]";
742         assertEquals(expect, mMatrix.toShortString());
743     }
744 
745     @TestTargetNew(
746         level = TestLevel.COMPLETE,
747         method = "setTranslate",
748         args = {float.class, float.class}
749     )
testSetTranslate()750     public void testSetTranslate() {
751         mMatrix.setTranslate(2f, 3f);
752         String expect = "[1.0, 0.0, 2.0][0.0, 1.0, 3.0][0.0, 0.0, 1.0]";
753         assertEquals(expect, mMatrix.toShortString());
754     }
755 
756 }
757