• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.cts.verifier.sensors.sixdof.Utils.TestPhase;
18 
19 import com.android.cts.verifier.sensors.sixdof.Dialogs.BaseResultsDialog;
20 import com.android.cts.verifier.sensors.sixdof.Utils.Manager;
21 import com.android.cts.verifier.sensors.sixdof.Utils.TestReport;
22 import com.android.cts.verifier.sensors.sixdof.Utils.Path.ComplexMovementPath;
23 import com.android.cts.verifier.sensors.sixdof.Utils.Path.ReferencePath;
24 import com.android.cts.verifier.sensors.sixdof.Utils.Path.PathUtilityClasses.Ring;
25 
26 import android.util.Log;
27 
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 
31 /**
32  * Handles all the ComplexMovement test related features.
33  */
34 public class ComplexMovementTest extends Test {
35     private boolean mResultsGiven = false;
36 
37     /**
38      * Created a new ComplexMovement path which is to be used in this test.
39      *
40      * @param referencePath Reference the the reference path.
41      * @param testReport    The test report object to record the tests.
42      * @param manager       The manager to call when the test is done.
43      */
ComplexMovementTest(ReferencePath referencePath, TestReport testReport, Manager manager)44     public ComplexMovementTest(ReferencePath referencePath, TestReport testReport, Manager manager) {
45         super(referencePath, testReport, manager, "Complex Movement Test");
46         mTestPath = new ComplexMovementPath(mReferencePathDistances, mReferencePath.getCurrentPath());
47     }
48 
49     /**
50      * Implementation of the abstract method which check whether the test is complete.
51      */
52     @Override
runAdditionalMethods()53     protected void runAdditionalMethods() {
54         if (mTestPath.getPathMarkersSize() == MAX_MARKER_NUMBER && !mResultsGiven) {
55             mResultsGiven = true;
56             executeComplexMovementTests();
57         }
58     }
59 
60     /**
61      * Starts the ComplexMovement tests.
62      */
executeComplexMovementTests()63     private void executeComplexMovementTests() {
64         HashMap<BaseResultsDialog.ResultType, Boolean> complexMovementTestResults;
65         complexMovementTestResults = executeTests(true, false);
66         complexMovementTestResults.put(BaseResultsDialog.ResultType.RINGS, testRings());
67         mManager.onComplexMovementTestCompleted(complexMovementTestResults);
68     }
69 
70     /**
71      * Tests whether the current location enters a ring.
72      *
73      * @param location the current location of the user
74      */
checkIfARingHasBeenPassed(float[] location)75     public void checkIfARingHasBeenPassed(float[] location) {
76         Ring ring = ((ComplexMovementPath) mTestPath).hasRingBeenEntered(location);
77         if (ring != null && !ring.isEntered()) {
78             // If ring has not already been entered.
79             mManager.ringEntered(ring);
80             ring.setEntered(true);
81         }
82     }
83 
84     /**
85      * Finds the rings that have not been entered.
86      *
87      * @return true if all rings are entered and false if there is at least one ring not entered
88      */
testRings()89     public boolean testRings() {
90         ArrayList<Ring> testArray = ((ComplexMovementPath) mTestPath).getRings();
91         boolean state = true;
92         for (int i = 0; i < testArray.size(); i++) {
93             if (!testArray.get(i).isEntered()) {
94                 recordRingTestResults(i);
95                 state = false;
96             }
97         }
98         return state;
99     }
100 
101     /**
102      * Forms a string for the failed ring and updates the test report with the string.
103      *
104      * @param ringIndex the index of the array the ring is in
105      */
recordRingTestResults(int ringIndex)106     private void recordRingTestResults(int ringIndex) {
107         Ring ring = ((ComplexMovementPath) mTestPath).getRings().get(ringIndex);
108         String testDetails =
109                 "Ring Test: Ring was not entered. Path number: " + ring.getPathNumber() +
110                         "Ring number:" + ((ringIndex % ComplexMovementPath.RINGS_PER_PATH) + 1) + "\n";
111         Log.e("Ring Result", testDetails);
112         mTestReport.setFailDetails(testDetails);
113 
114     }
115 
116     /**
117      * Returns the rings in the path.
118      */
getRings()119     public ArrayList<Ring> getRings() {
120         return ((ComplexMovementPath) mTestPath).getRings();
121     }
122 }
123