Ejemplo n.º 1
0
def check_size(arguments):
    global VERDICT
    global OUTPUT

    events_structure = touch_util.poll_touchscreen(events=1000,
                                                   timeout=10,
                                                   stop_finger_up=True)
    if not events_structure:
        VERDICT = FAILURE
        OUTPUT = "Failure. No touch events are retrieved"
        return

    size_values = []
    for index, fingers_nr in enumerate(events_structure.fingers_number):
        for finger in range(0, fingers_nr):
            if len(size_values) <= finger:
                size_values.append([])
            size_values[finger].append(events_structure.size[index][finger])
    if MULTIPLE_FINGERS == "False":
        if are_values_ordered(size_values[0]):
            print_to_console_and_logcat("Success")
            VERDICT = SUCCESS
            OUTPUT = "Success"
        else:
            print_to_console_and_logcat(
                "Failure. Finger size should increase.")
            VERDICT = FAILURE
            OUTPUT = "Failure. Finger size didn't increase."
    else:
        fingers_nr = len(size_values)
        if fingers_nr < 5:
            print_to_console_and_logcat(
                "Failure. Touch should be pressed with at least 5 fingers")
            print_to_console_and_logcat("Failure. There were recorded only " + str(fingers_nr) + \
                                        " fingers")
            VERDICT = FAILURE
            OUTPUT = "Failure. There were recorded only " + str(fingers_nr) + \
                                        " fingers"
        else:
            passed = True
            for finger in range(0, fingers_nr):
                if not are_values_ordered(size_values[finger]):
                    passed = False
                    print_to_console_and_logcat(
                        "Failure. Fingers size should increase")
                    VERDICT = FAILURE
                    OUTPUT = "Failure. Finger size didn't increase."
                    break
            if passed:
                print_to_console_and_logcat("Success")
                VERDICT = SUCCESS
                OUTPUT = "Success"
def check_acc_values_are_increasing(args):
    global VERDICT, OUTPUT
    values = []
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 15, timeout, poll_time)
            if len(events) > 0:
                break
            else:
                OUTPUT = "No data results from sensor poll"
                print_test_result(False, OUTPUT)
                VERDICT = FAILURE
                return
    for event in events:
        values.append(event['data'][axis])
    maxim = max(values)
    max_position = get_value_position(maxim, values)
    if max_position > 3 and are_values_ordered(values[:max_position + 1]) and \
        maxim - values[0] > 0.5 * G:
        message = "Accelerometer values on {} axis were increasing".format(axis)
        print_test_result(True, message)
        VERDICT = SUCCESS
    else:
        values = eliminate_succesive_duplicates(values)
        message = "It was expected an increasing of the values on the {} axis with at least 0.5 * G.".format(axis)
        message += " Returned values were: {}".format(values)
        print_test_result(False, message)
        VERDICT = FAILURE
    OUTPUT = message
def check_temperature_values_are_ordered(args):
    global VERDICT, OUTPUT
    values = []
    poll_time = 5
    timeout = poll_time * 2 + 5
    p = 0.95
    if order == -1:
        p = 1.05
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 0, timeout, poll_time)
            break
    for event in events:
        values.append(event['data']['temperature'])
    if are_values_ordered(values, order):
        message = "Temperature value " + order_s + "d"
        print_test_result(True, message)
        VERDICT = SUCCESS
    else:
        message = "Sensor values were not ordered"
        print_test_result(False, message)
        VERDICT = FAILURE
    OUTPUT = message
 def check_values(self):
     maxim = max(self.values)
     max_position = self.values.index(maxim)
     if max_position > 3 and are_values_ordered(self.values[:max_position + 1]) and \
         maxim - self.values[0] > 1:
         message = "Gyroscope values on {} axis were increasing".format(
             self.axes)
         return True, message
     else:
         values = eliminate_succesive_duplicates(self.values)
         message = "It was expected an increasing of the values on the {} axis with at least 1.".format(
             self.axes)
         message += " Returned values were: {}".format(values)
         return False, message
Ejemplo n.º 5
0
def are_values_on_the_edge(x_coords, y_coords):
    if EDGE == 'left':
        const_axis, ordered_axis = (x_coords, y_coords)
        const_axis_name, ordered_axis_name = ("x axis", "y axis")
        edge_val = x_min
        min_ordered, max_ordered = (y_min, y_max)
    elif EDGE == "right":
        const_axis, ordered_axis = (x_coords, y_coords)
        const_axis_name, ordered_axis_name = ("x axis", "y axis")
        edge_val = x_max
        min_ordered, max_ordered = (y_min, y_max)
    elif EDGE == "top":
        const_axis, ordered_axis = (y_coords, x_coords)
        const_axis_name, ordered_axis_name = ("y axis", "x axis")
        edge_val = y_min
        min_ordered, max_ordered = (x_min, x_max)
    elif EDGE == "bottom":
        const_axis, ordered_axis = (y_coords, x_coords)
        const_axis_name, ordered_axis_name = ("y axis", "x axis")
        edge_val = y_max
        min_ordered, max_ordered = (x_min, x_max)

    pixel_margin = 50
    for const_coord in const_axis:
        if abs(const_coord - edge_val) > pixel_margin:
            print_to_console_and_logcat(
                "Found value {} for {} that is too far from the touchscreen edge ({})"
                .format(const_coord, const_axis_name, edge_val))
            return False
    if abs(ordered_axis[0] - min_ordered) > pixel_margin:
        print_to_console_and_logcat(
            "Swipe did not start near the expected corner. Found {} coordinate '{}' "
            "which is too far from the corner value ({})".format(
                ordered_axis_name, ordered_axis[0], min_ordered))
        return False
    if abs(ordered_axis[-1] - max_ordered) > pixel_margin:
        print_to_console_and_logcat(
            "Swipe did not end near the expected corner. Found {} coordinate '{}' "
            "which is too far from the corner value ({})".format(
                ordered_axis_name, ordered_axis[-1], max_ordered))
        return False
    if not are_values_ordered(ordered_axis):
        return False
    return True
Ejemplo n.º 6
0
def check_light_values_are_ordered(args):
    global VERDICT, OUTPUT
    values = []
    print "Press ENTER to start the record"
    while (True):
        input_line = raw_input("")
        if input_line == "":
            events = poll_for_events(sensor_id, 0, timeout, poll_time)
            break
    for event in events:
        values.append(event['data']['light'])
    if are_values_ordered(values, order):
        OUTPUT = "Light value " + order_s + "d"
        print_test_result(True, OUTPUT)
        VERDICT = SUCCESS
    else:
        OUTPUT = "Sensor values were not ordered"
        print_test_result(False, OUTPUT)
        VERDICT = FAILURE
Ejemplo n.º 7
0
def check_multiple_swipe(arguments):
    global VERDICT
    global OUTPUT

    events_structure = touch_util.poll_touchscreen(events=1000,
                                                   timeout=10,
                                                   stop_finger_up=True)
    if not events_structure:
        VERDICT = FAILURE
        OUTPUT = "Failure. No touch events are retrieved"
        return

    x_coords = []
    y_coords = []
    for index, fingers_nr in enumerate(events_structure.fingers_number):
        # when at least one finger is lifted we won't take into consideration other events
        if events_structure.action[index] == "pointer up":
            break
        for finger in range(0, fingers_nr):
            if len(x_coords) <= finger:
                x_coords.append([])
            x_coords[finger].append(events_structure.x[index][finger])
            if len(y_coords) <= finger:
                y_coords.append([])
            y_coords[finger].append(events_structure.y[index][finger])

    # x_coords and y_coords are the same length
    fingers_nr = len(x_coords)
    if fingers_nr < 5:
        print_to_console_and_logcat(
            "Failure. Touch should be pressed with at least 5 fingers")
        print_to_console_and_logcat("Failure. There were recorded only " +
                                    str(fingers_nr) + " fingers")
        VERDICT = FAILURE
        OUTPUT = "Failure. Only " + str(fingers_nr) + " fingers detected"

    else:
        passed = True
        for finger in range(0, fingers_nr):
            if swipe_direction == "down":
                constant = "x coords"
                ordered = "y coords"
                order = 1
            elif swipe_direction == "up":
                constant = "x coords"
                ordered = "y coords"
                order = -1
            elif swipe_direction == "right":
                constant = "y coords"
                ordered = "x coords"
                order = 1
            elif swipe_direction == "left":
                constant = "y coords"
                ordered = "x coords"
                order = -1

            if constant == "x coords":
                constant_vals = x_coords[finger]
            else:
                constant_vals = y_coords[finger]

            if ordered == "x coords":
                ordered_vals = x_coords[finger]
            else:
                ordered_vals = y_coords[finger]

            if not are_values_ordered(ordered_vals, order, 0.99):
                passed = False
                fail_message = "Failure. For at least one finger, values for {} did not increase " \
                               "as they should.".format(ordered)
                print_to_console_and_logcat(fail_message)
                VERDICT = FAILURE
                OUTPUT = fail_message
                break
            elif not are_values_constant(constant_vals, 0.2):
                passed = False
                fail_message = "Failure. For at least one finger, values for {} are not relative constant " \
                               "as they should be.".format(finger+1, constant)
                print_to_console_and_logcat(fail_message)
                VERDICT = FAILURE
                OUTPUT = fail_message
                break
        if passed:
            print_to_console_and_logcat("Success")
            VERDICT = SUCCESS
            OUTPUT = "Success"
Ejemplo n.º 8
0
def check_axis(arguments):
    global VERDICT
    global OUTPUT

    events_structure = touch_util.poll_touchscreen(events=1000,
                                                   timeout=10,
                                                   stop_finger_up=True)
    if not events_structure:
        VERDICT = FAILURE
        OUTPUT = "Failure. No touch events are retrieved"
        return

    x_coords = []
    y_coords = []
    for x_event in events_structure.x:
        x_coords.append(x_event[0])
    for y_event in events_structure.y:
        y_coords.append(y_event[0])

    if DIAGONAL == "primary":
        if not (touch_util.is_coord_in_corner(x_coords[0], y_coords[0],
                                              "upper-left")
                and touch_util.is_coord_in_corner(x_coords[-1], y_coords[-1],
                                                  "bottom-right")):
            print_to_console_and_logcat(
                "Failure. Swipe should start from the top left corner "
                "and end in the bottom right corner")
            VERDICT = FAILURE
            OUTPUT = "Failure. Swipe start coordinate " + str(x_coords[0]) +" "+ str(y_coords[0]) + " and end cooridnates " + \
                     str(x_coords[-1]) +" "+ str(y_coords[-1]) + " don't match the intended swipe gesture"
            return

        for coords, coords_name, axis in zip([x_coords, y_coords],
                                             ["x_coords", "y_coords"],
                                             ["X", "Y"]):
            if not are_values_ordered(coords):
                print_to_console_and_logcat(
                    "Failure. Events coordinates should increase on {} axis.".
                    format(axis))
                VERDICT = FAILURE
                OUTPUT = "Failure. Events coordinates should increase on {} axis.".format(
                    axis)
                return

        print_to_console_and_logcat("Success")
        VERDICT = SUCCESS
        OUTPUT = "Success"

    if DIAGONAL == "secondary":
        if not (touch_util.is_coord_in_corner(x_coords[0], y_coords[0],
                                              "upper-right")
                and touch_util.is_coord_in_corner(x_coords[-1], y_coords[-1],
                                                  "bottom-left")):
            print_to_console_and_logcat(
                "Failure. Swipe should start from the top right corner "
                "and end in the bottom left corner")
            VERDICT = FAILURE
            OUTPUT = "Failure. Swipe start coordinate " + str(x_coords[0]) +" "+ str(y_coords[0]) + " and end cooridnates " + \
                     str(x_coords[-1]) +" "+ str(y_coords[-1]) + " don't match the intended swipe gesture"
            return
        if not are_values_ordered(x_coords, -1):
            print_to_console_and_logcat(
                "Failure. Events coordinates should decrease on X axis.")
            VERDICT = FAILURE
            OUTPUT = "Failure. Events along x axis are not in decrease order"
            return
        if not are_values_ordered(y_coords):
            print_to_console_and_logcat(
                "Failure. Events coordinates should increase on Y axis.")
            VERDICT = FAILURE
            OUTPUT = "Failure. Events along y axis are not in decrease order"
            return
        print_to_console_and_logcat("Success")
        VERDICT = SUCCESS
        OUTPUT = "Success"