1 /*
2  * Copyright (C) 2010 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 
17 package com.android.camera.unittest;
18 
19 import android.graphics.Matrix;
20 
21 import androidx.test.filters.SmallTest;
22 
23 import com.android.camera.util.CameraUtil;
24 
25 import junit.framework.TestCase;
26 
27 @SmallTest
28 public class CameraUnitTest extends TestCase {
testPrepareMatrix()29     public void testPrepareMatrix() {
30         Matrix matrix = new Matrix();
31         float[] points;
32         int[] expected;
33 
34         CameraUtil.prepareMatrix(matrix, false, 0, 800, 480);
35         points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250};
36         expected = new int[] {0, 0, 400, 240, 800, 480, 400, 480, 100, 300};
37         matrix.mapPoints(points);
38         assertEquals(expected, points);
39 
40         CameraUtil.prepareMatrix(matrix, false, 90, 800, 480);
41         points = new float[] {-1000, -1000,   0,   0, 1000, 1000, 0, 1000, -750, 250};
42         expected = new int[] {800, 0, 400, 240, 0, 480, 0, 240, 300, 60};
43         matrix.mapPoints(points);
44         assertEquals(expected, points);
45 
46         CameraUtil.prepareMatrix(matrix, false, 180, 800, 480);
47         points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250};
48         expected = new int[] {800, 480, 400, 240, 0, 0, 400, 0, 700, 180};
49         matrix.mapPoints(points);
50         assertEquals(expected, points);
51 
52         CameraUtil.prepareMatrix(matrix, true, 180, 800, 480);
53         points = new float[] {-1000, -1000, 0, 0, 1000, 1000, 0, 1000, -750, 250};
54         expected = new int[] {0, 480, 400, 240, 800, 0, 400, 0, 100, 180};
55         matrix.mapPoints(points);
56         assertEquals(expected, points);
57     }
58 
assertEquals(int expected[], float[] actual)59     private void assertEquals(int expected[], float[] actual) {
60         for (int i = 0; i < expected.length; i++) {
61             assertEquals("Array index " + i + " mismatch", expected[i], Math.round(actual[i]));
62         }
63     }
64 }
65