/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtSensors module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

//include("Device.qtx")
//include("extrafunctions.qtt")

//TESTED_COMPONENT=src/sensors

testcase = {

/*
init: function() {
    qtuitest.checkActiveWindow = false;
    qtuitest.autoTerminate = false;
    wait(500);
    unlock();
    wait(500);
},


cleanup: function() {
    print("Cleanup test function");
    unlock();
    wait(500);
    Gesture.swipe(Screen.leftCenter(), Screen.rightCenter()); //close applicatin
    wait(500);
},
*/

// As a QML Application developer I need information about the position of the device (rotation angles from X and Y Axis)
    Device_Rotational_Position: function()
    {
        // Test meta data
        testTitle = "device position (rotation angles from X and Y Axis)";
        testBinary = "QML QtSensors";
        testSource = "$QTDIR/qtsensors/examples/QtSensors/QtSensors_qmlqtsensors";
        testGoal = "Verify that the values of the X and Y axis are returned from the application and match those of the actual phone";
        testPreconditions = "Nil.";
        testGroups = "BAT, 5.0";
        testRequirements = "";

      // Test steps
//        mouseClick(findByProperty("label", testBinary)); wait(500);
        prompt(twiki("---+++ " + testTitle + "<br><br>
            *Goal:* " + testGoal + "<br>
            *Pre-Requisites:* " + testPreconditions + "<br>
            *Tested Binary:* " + testBinary + "<br>

            | *Step* | *Verification* |
            | Launch " + testBinary + " | App launches normally |
            | Press the *Start* button for the accelerometer | The button now displays *running* and numeric values are displayed for X and Y Rotation |
            | Hold the device with the screen facing up in portrait | Verfy the x, y rotation values are approximatly 0,0 |
            | Rotate the device toward you along the x axis | Verify that the x rotation values increase from zero as the device is rotated and the y values remain at approximatly 0 |
            | Return the device to the screen facing up in portrait position | Verfy the x, y rotation values are approximatly 0,0 |
            | Rotate the device away from you along the x axis | Verify that the x rotation values decrease from zero (become negitive) as the device is rotated and the y values remain at approximatly 0 |
            | Return the device to the screen facing up in portrait position | Verfy the x, y rotation values are approximatly 0,0 |
            | Rotate the device to the right along the y axis | Verify that the y rotation values increase from zero as the device is rotated and the x values remain at approximatly 0 |
            | Return the device to the screen facing up in portrait position | Verfy the x, y rotation values are approximatly 0,0 |
            | Rotate the device to the left along the y axis | Verify that the y rotation values decrease from zero (become negitive) as the device is rotated and the x values remain at approximatly 0 |
        "));
    },

// As a QML Application developer I want to calibrate the current device position
    Calibrate_Current_Device_Position: function()
    {
        // Test meta data
        testTitle = "Accelerometer Calibration";
        testBinary = "QML QtSensors";
        testSource = "$QTDIR/qtsensors/examples/QtSensors/QtSensors_qmlqtsensors"
        testGoal = "Verify that the application can be set to read an X and Y value of zero for the current phone position";
        testPreconditions = "Nil.";
        testGroups = "BAT, 5.0";
        testRequirements = "";

        // Test steps
//        mouseClick(findByProperty("label", testBinary)); wait(500);
        prompt(twiki("---+++ " + testTitle + "<br><br>
           *Goal:* " + testGoal + "<br>
           *Pre-Requisites:* " + testPreconditions + "<br>
           *Tested Binary:* " + testBinary + "<br>

           | *Step* | *Verification* |
           | Launch " + testBinary + " | App launches normally |
           | Press the *Start* button for the accelerometer | The button now displays *running* and numeric values are displayed for X and Y Rotation |
           | Hold the device with the screen facing up in portrait | Verfy the x, y rotation values are approximatly 0,0 |
           | Rotate the device toward you along the x axis until the device is at 90 degrees| Verify that the x rotation values show approximatly 90 degrees and the y values remain at approximatly 0 |
           | While holding the device in this position select the calibrate button | Verify that the x, y values now show approximatly 0,0 |
           | Return the device to the face up position | Verify that the accelerometer x, y rotation shows approximatly -90,0 |
           | While holding the device in this position select the calibrate button | Verify that the x, y values now show approximatly 0,0 |
           | Rotate the device toward the right along the y axis until the device is at 90 degrees| Verify that the x rotation values remain at approximatly 0 degrees and the y value show approximatly 90 degrees |
           | While holding the device in this position select the calibrate button | Verify that the x, y values now show approximatly 0,0 |
           | Return the device to the face up position | Verify that the accelerometer x, y rotation shows approximatly 0,-90 |
           | Select the calibrate button | Verify that the x, y values now show approximatly 0,0 |
       "));
    },

    // As a QML Application developer I want to find the device orientation
        Show_Device_Orientation: function()
     {
        // Test meta data
        testTitle = "Phone Orientation";
        testBinary = "sensor explorer";
        testSource = "$QTDIR/qtsensors/examples/QtSensors/QtSensors_sensor_explorer"
        testGoal = "Verify that the application can show the orientation of the phone";
        testPreconditions = "Nil.";
        testGroups = "BAT, 5.0";
        testRequirements = "";

            // Test steps
//            mouseClick(findByProperty("label", testBinary)); wait(500);
            prompt(twiki("---+++ " + testTitle + "<br><br>
               *Goal:* " + testGoal + "<br>
               *Pre-Requisites:* " + testPreconditions + "<br>
               *Tested Binary:* " + testBinary + "<br>

               | *Step* | *Verification* |
               | Launch " + testBinary + " | App launches normally |
               | Select orientation from the sensor list and press start | *Orientation* is highlighted and orientation type shows the current orientation |
               | Orient the device with the screen facing up | Verify that the orientation type shows *FaceUp* |
               | Orient the device with the left side facing up | Verify that the orientation type shows *LeftUp* |
               | Orient the device with the top down | Verify that the orientation type shows *TopDown* |
               | Orient the device with the face down | Verify that the orientation type shows *FaceDown* |
               | Orient the device with the right side facing up | Verify that the orientation type shows *FaceUp* |
               | Orient the device with the top facing up | Verify that the orientation type shows *TopUp* |
           "));
        },

// As a QML Application developer I would like to have one QML element per sensor type
// MTMW-427 QML System Test - Using only Proximity sensor does not start the sensor hardware
    Display_All_Sensor_Types: function()
    {
        // Test meta data
        testTitle = "List Sensor Types";
        testBinary = "sensor explorer";
        testSource = "$QTDIR/qtsensors/examples/QtSensors/QtSensors_sensor_explorer"
        testGoal = "Verify that all sensor types are shown by the application";
        testPreconditions = "Nil.";
        testGroups = "BAT, 5.0";
        testRequirements = "";

          // Test steps
//          mouseClick(findByProperty("label", testBinary)); wait(500);
          prompt(twiki("---+++ " + testTitle + "<br><br>
              *Goal:* " + testGoal + "<br>
              *Pre-Requisites:* " + testPreconditions + "<br>
              *Tested Binary:* " + testBinary + "<br>

              | *Step* | *Verification* |
              | Launch " + testBinary + " | App launches normally |
              | Ensure that none of the sensors are in a *running* state | Press any buttons that display *Running* to place that sensor in a *Stopped* state |
              | Each sensor button will display *start* or *Stopped*, press the accelerometer *Start* button | Verify that the accelerometer button displays *running* and operates as expected |
              | Press the accelerometer button again to stop the accelerometer | Verify the button reads *Stopped* and the X, Y Rotation values do not repond to movement |
              | Press the Ambient Light *Start* button | Verify that the Ambient Light sensor button displays *running* and operates as expected |
              | Press the Ambient Light button again to stop the Ambient Light sensor | Verify the button reads *Stopped* and the Ambient Light sensor does not respond when a shadow falls on it |
              | Press the Proximity sensor *Start* button | Verify that the Proximity sensor button displays *running* and operates as expected |
              | Press the Proximity sensor button again to stop the Proximity sensor | Verify the button reads *Stopped* and the Proximity sensor does not respond when when your palm is brought within 1 cm of the Proximity sensor |
              | Press all sensor buttons again to start all sensors | Verify all buttons read *Running* and all sensors operate as expected |
        "));
    },

// As a QML Application developer I would like to receive the rotation angles in Radian or Degree
    Display_Angles_Radian_Degrees: function()
    {
        // Test meta data
        testTitle = "Rotation Units";
        testBinary = "QML QtSensors";
        testSource = "$QTDIR/qtsensors/examples/QtSensors/QtSensors_qmlqtsensors"
        testGoal = "Verify that the read values for the X and Y axis can be displayed in radians or degrees";
        testPreconditions = "Nil.";
        testGroups = "BAT, 5.0";
        testRequirements = "";

          // Test steps
//          mouseClick(findByProperty("label", testBinary)); wait(500);
          prompt(twiki("---+++ " + testTitle + "<br><br>
              *Goal:* " + testGoal + "<br>
              *Pre-Requisites:* " + testPreconditions + "<br>
              *Tested Binary:* " + testBinary + "<br>

              | *Step* | *Verification* |
              | Launch " + testBinary + " | App launches normally |
              | Press the *Start* button for the accelerometer | The button now displays *running* and numeric values are displayed for X and Y Rotation |
              | Hold the device in portrait face up horizontal | Verify the x, y rotation values display 0,0 |
              | While holding the device in this position press the button marked *degree* | Verify the button now reads *radian* and the x, y rotation values display approximatly 0,0 |
              | Still holding the device in portrait tilt the device at right angles toward you (screen facing you) | Verify the x, y rotation values display approximatly 1.57,0|
              | While holding the device in this position press the button marked *radian* | Verify the button now reads *radian* and the x, y rotation values display approximatly 90,0 |
        "));
    },

// As a QML Application developer I would like to change my UI dependent of the ambient light
    Ambient_Light_Detection: function()
    {
        // Test meta data
        testTitle = "Ambient Light Sensor";
        testBinary = "QML QtSensors";
        testSource = "$QTDIR/qtsensors/examples/QtSensors/QtSensors_qmlqtsensors";
        testGoal = "Verify that the ambient light values can be read";
        testPreconditions = "Nil.";
        testGroups = "BAT, 5.0";
        testRequirements = "A bright light source such as a desk lamp";


          // Test steps
//          mouseClick(findByProperty("label", testBinary)); wait(500);
          prompt(twiki("---+++ " + testTitle + "<br><br>
              *Goal:* " + testGoal + "<br>
              *Pre-Requisites:* " + testPreconditions + "<br>
              *Tested Binary:* " + testBinary + "<br>

              | *Step* | *Verification* |
              | Launch " + testBinary + " | App launches normally |
              | Press the *Start* button for the ambient light sensor | The button now displays *running* and a value is displayed for *Ambient Light* |
              | Place the device close under a bright light | Verify that the Ambient Light is reported as *Sunny* |
              | Move the device a bit futher away from the light source | Verify that the Ambient Light is reported as *Bright* |
              | Move the device even futher away from the light source | Verify that the Ambient Light is reported as *Light* |
              | Place the light sensor element under a partial shadow, i.e. by holding your hand above the device | Verify that the Ambient Light is reported as *Twilight*, note that the amount of shadow may need to be adjusted by moving your hand to achieve this |
              | Place your finger over the sensor element | Verify that the Ambient Light now reads as *Dark* |
        "));
    },

// As a QML Application developer I would like to deactivate the touchscreen as soon the proximity of the user is close - no need for test app to lock screen, testing that the proximity is detected is sufficient
    Proximity_Detection: function()
    {
        // Test meta data
        testTitle = "Proximity";
        testBinary = "QML QtSensors";
        testSource = "$QTDIR/qtsensors/examples/QtSensors/QtSensors_qmlqtsensors";
        testGoal = "Verify that close proximity can be detected";
        testPreconditions = "Nil.";
        testGroups = "BAT, 5.0";
        testRequirements = "";

          // Test steps
//          mouseClick(findByProperty("label", testBinary)); wait(500);
          prompt(twiki("---+++ " + testTitle + "<br><br>
              *Goal:* " + testGoal + "<br>
              *Pre-Requisites:* " + testPreconditions + "<br>
              *Tested Binary:* " + testBinary + "<br>
              | *Step* | *Verification* |
              | Launch " + testBinary + " | App launches normally |
              | Press the *Start* button for the *Proximity* | The button now displays *running* and a value is displayed for *Proximity* |
              | Confirm that nothing is close to the proximity detector | Verify that the Proximity reads *far* |
              | Bring your hand to within 1 cm of the proximity sensor | Verify that the Proximity now reads *near* |
              | Move your hand away from the proximity sensor | Verify that the Proximity now reads *far* |
        "));
    },

// MTMW-426   Handle service errors gracefully
    Service_Errors: function()
    {
        // Test meta data
        testTitle = "Error Handling";
        testBinary = "QML QtSensors";
        testSource = "$QTDIR/qtsensors/examples/QtSensors/QtSensors_qmlqtsensors";
        testGoal = "Verify that service errors are handled so as to prevent baldr crashes if the sensor daemon stops unexpectedly";
        testPreconditions = "Nil.";
        testGroups = "BAT, 5.0";
        testRequirements = "";

          // Test steps
//          mouseClick(findByProperty("label", testBinary)); wait(500);
          prompt(twiki("---+++ " + testTitle + "<br><br>
              *Goal:* " + testGoal + "<br>
              *Pre-Requisites:* " + testPreconditions + "<br>
              *Tested Binary:* " + testBinary + "<br>
              | *Step* | *Verification* |
              | Launch " + testBinary + " | App launches normally |
              | Press start on the three sensors | Verify that the sensors are operating |
              | Log into the device using a console and enter the following commands: ps -A &#124; grep sensorq | Verify that the process ID number for sensorq is displayed |
              | Using the process ID from the previous step stop sensorq by typing kill processID at the console |  |
              | Check the sensors on " + testBinary + " | Verify that the sensors are still operating |
              | Repeat the previous steps to find the process ID and kill sensorq a second time | Verify the sensors are still operating and sensorq still has a process ID |
        "));
    },
}
