#!/usr/bin/env python3
#
# Copyright (c) 2024 Stormux
# Copyright (c) 2010-2012 The Orca Team
# Copyright (c) 2012 Igalia, S.L.
# Copyright (c) 2005-2010 Sun Microsystems Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., Franklin Street, Fifth Floor,
# Boston MA  02110-1301 USA.
#
# Fork of Orca Screen Reader (GNOME)
# Original source: https://gitlab.gnome.org/GNOME/orca

"""Test of learn mode."""

from macaroon.playback import *
import utils

sequence = MacroSequence()

sequence.append(KeyPressAction(0, None, "KP_Insert"))
sequence.append(TypeAction("h"))
sequence.append(KeyReleaseAction(0, None, "KP_Insert"))

sequence.append(KeyComboAction("F1"))
sequence.append(PauseAction(2000))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("k"))
sequence.append(utils.AssertPresentationAction(
    "1. k for next link",
    ["BRAILLE LINE:  ' Welcome to Cthulhu'",
     "     VISIBLE:  ' Welcome to Cthulhu', cursor=2",
     "BRAILLE LINE:  ' Welcome to Cthulhu'",
     "     VISIBLE:  ' Welcome to Cthulhu', cursor=2",
     "SPEECH OUTPUT: 'Welcome to Cthulhu",
     "Introducing the Cthulhu screen reader",
     " link'"]))

sequence.append(KeyComboAction("Return"))
sequence.append(PauseAction(2000))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("p"))
sequence.append(utils.AssertPresentationAction(
    "2. p for next paragraph",
    ["BRAILLE LINE:  ' Cthulhu is a free, open source, flexible, and extensible screen reader that provides access to the graphical desktop via speech and refreshable braille.'",
     "     VISIBLE:  'Cthulhu is a free, open source, fle', cursor=1",
     "BRAILLE LINE:  ' Cthulhu is a free, open source, flexible, and extensible screen reader that provides access to the graphical desktop via speech and refreshable braille.'",
     "     VISIBLE:  'Cthulhu is a free, open source, fle', cursor=1",
     "SPEECH OUTPUT: 'Cthulhu is a free, open source, flexible, and extensible screen reader that provides access to the graphical desktop via speech and refreshable braille.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("p"))
sequence.append(utils.AssertPresentationAction(
    "3. p for next paragraph",
    ["BRAILLE LINE:  ' Cthulhu works with applications and toolkits that support the Assistive Technology Service Provider Interface (AT-SPI), which is the primary assistive technology infrastructure for Linux and Solaris. Applications and toolkits supporting the AT-SPI include the GNOME Gtk+ toolkit, the Java platform's Swing toolkit, LibreOffice, Gecko, and WebKitGtk. AT-SPI support for the KDE Qt toolkit is being pursued.'",
     "     VISIBLE:  'Cthulhu works with applications and', cursor=1",
     "BRAILLE LINE:  ' Cthulhu works with applications and toolkits that support the Assistive Technology Service Provider Interface (AT-SPI), which is the primary assistive technology infrastructure for Linux and Solaris. Applications and toolkits supporting the AT-SPI include the GNOME Gtk+ toolkit, the Java platform's Swing toolkit, LibreOffice, Gecko, and WebKitGtk. AT-SPI support for the KDE Qt toolkit is being pursued.'",
     "     VISIBLE:  'Cthulhu works with applications and', cursor=1",
     "SPEECH OUTPUT: 'Cthulhu works with applications and toolkits that support the Assistive Technology Service Provider Interface (AT-SPI), which is the primary assistive technology infrastructure for Linux and Solaris. Applications and toolkits supporting the AT-SPI include the GNOME Gtk+ toolkit, the Java platform's Swing toolkit, LibreOffice, Gecko, and WebKitGtk. AT-SPI support for the KDE Qt toolkit is being pursued.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("p"))
sequence.append(utils.AssertPresentationAction(
    "4. p for next paragraph",
    ["BRAILLE LINE:  ' To launch Cthulhu:'",
     "     VISIBLE:  ' To launch Cthulhu:', cursor=2",
     "BRAILLE LINE:  ' To launch Cthulhu:'",
     "     VISIBLE:  ' To launch Cthulhu:', cursor=2",
     "SPEECH OUTPUT: 'To launch Cthulhu:'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("p"))
sequence.append(utils.AssertPresentationAction(
    "5. p for next paragraph",
    ["BRAILLE LINE:  ' The method for configuring Cthulhu to be launched automatically as your preferred screen reader will depend upon which desktop environment you use. For instance, in GNOME 3.x this option can be found in the Universal Access Control Center panel on the Seeing page.'",
     "     VISIBLE:  'The method for configuring Cthulhu ', cursor=1",
     "BRAILLE LINE:  ' The method for configuring Cthulhu to be launched automatically as your preferred screen reader will depend upon which desktop environment you use. For instance, in GNOME 3.x this option can be found in the Universal Access Control Center panel on the Seeing page.'",
     "     VISIBLE:  'The method for configuring Cthulhu ', cursor=1",
     "SPEECH OUTPUT: 'The method for configuring Cthulhu to be launched automatically as your preferred screen reader will depend upon which desktop environment you use. For instance, in GNOME 3.x this option can be found in the Universal Access Control Center panel on the Seeing page.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("p"))
sequence.append(utils.AssertPresentationAction(
    "6. p for next paragraph",
    ["BRAILLE LINE:  ' To toggle Cthulhu on and off in GNOME, press Super+Alt+S.'",
     "     VISIBLE:  'To toggle Cthulhu on and off in GNO', cursor=1",
     "BRAILLE LINE:  ' To toggle Cthulhu on and off in GNOME, press Super+Alt+S.'",
     "     VISIBLE:  'To toggle Cthulhu on and off in GNO', cursor=1",
     "SPEECH OUTPUT: 'To toggle Cthulhu on and off in GNOME, press Super+Alt+S.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("p"))
sequence.append(utils.AssertPresentationAction(
    "7. p for next paragraph",
    ["BRAILLE LINE:  ' Type cthulhu, along with any optional parameters, in a terminal window or within the Run dialog and then press Return.'",
     "     VISIBLE:  'Type cthulhu, along with any option', cursor=1",
     "BRAILLE LINE:  ' Type cthulhu, along with any optional parameters, in a terminal window or within the Run dialog and then press Return.'",
     "     VISIBLE:  'Type cthulhu, along with any option', cursor=1",
     "SPEECH OUTPUT: 'Type cthulhu, along with any optional parameters, in a terminal window or within the Run dialog and then press Return.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Shift>p"))
sequence.append(utils.AssertPresentationAction(
    "8. shift+p for previous paragraph",
    ["BRAILLE LINE:  ' To toggle Cthulhu on and off in GNOME, press Super+Alt+S.'",
     "     VISIBLE:  'To toggle Cthulhu on and off in GNO', cursor=1",
     "BRAILLE LINE:  ' To toggle Cthulhu on and off in GNOME, press Super+Alt+S.'",
     "     VISIBLE:  'To toggle Cthulhu on and off in GNO', cursor=1",
     "SPEECH OUTPUT: 'To toggle Cthulhu on and off in GNOME, press Super+Alt+S.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Shift>p"))
sequence.append(utils.AssertPresentationAction(
    "9. shift+p for previous paragraph",
    ["BRAILLE LINE:  ' The method for configuring Cthulhu to be launched automatically as your preferred screen reader will depend upon which desktop environment you use. For instance, in GNOME 3.x this option can be found in the Universal Access Control Center panel on the Seeing page.'",
     "     VISIBLE:  'The method for configuring Cthulhu ', cursor=1",
     "BRAILLE LINE:  ' The method for configuring Cthulhu to be launched automatically as your preferred screen reader will depend upon which desktop environment you use. For instance, in GNOME 3.x this option can be found in the Universal Access Control Center panel on the Seeing page.'",
     "     VISIBLE:  'The method for configuring Cthulhu ', cursor=1",
     "SPEECH OUTPUT: 'The method for configuring Cthulhu to be launched automatically as your preferred screen reader will depend upon which desktop environment you use. For instance, in GNOME 3.x this option can be found in the Universal Access Control Center panel on the Seeing page.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Shift>p"))
sequence.append(utils.AssertPresentationAction(
    "10. shift+p for previous paragraph",
    ["BRAILLE LINE:  ' To launch Cthulhu:'",
     "     VISIBLE:  ' To launch Cthulhu:', cursor=2",
     "BRAILLE LINE:  ' To launch Cthulhu:'",
     "     VISIBLE:  ' To launch Cthulhu:', cursor=2",
     "SPEECH OUTPUT: 'To launch Cthulhu:'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Shift>p"))
sequence.append(utils.AssertPresentationAction(
    "11. shift+p for previous paragraph",
    ["BRAILLE LINE:  ' Cthulhu works with applications and toolkits that support the Assistive Technology Service Provider Interface (AT-SPI), which is the primary assistive technology infrastructure for Linux and Solaris. Applications and toolkits supporting the AT-SPI include the GNOME Gtk+ toolkit, the Java platform's Swing toolkit, LibreOffice, Gecko, and WebKitGtk. AT-SPI support for the KDE Qt toolkit is being pursued.'",
     "     VISIBLE:  'Cthulhu works with applications and', cursor=1",
     "BRAILLE LINE:  ' Cthulhu works with applications and toolkits that support the Assistive Technology Service Provider Interface (AT-SPI), which is the primary assistive technology infrastructure for Linux and Solaris. Applications and toolkits supporting the AT-SPI include the GNOME Gtk+ toolkit, the Java platform's Swing toolkit, LibreOffice, Gecko, and WebKitGtk. AT-SPI support for the KDE Qt toolkit is being pursued.'",
     "     VISIBLE:  'Cthulhu works with applications and', cursor=1",
     "SPEECH OUTPUT: 'Cthulhu works with applications and toolkits that support the Assistive Technology Service Provider Interface (AT-SPI), which is the primary assistive technology infrastructure for Linux and Solaris. Applications and toolkits supporting the AT-SPI include the GNOME Gtk+ toolkit, the Java platform's Swing toolkit, LibreOffice, Gecko, and WebKitGtk. AT-SPI support for the KDE Qt toolkit is being pursued.'"]))

sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("<Shift>p"))
sequence.append(utils.AssertPresentationAction(
    "12. shift+p for previous paragraph",
    ["BRAILLE LINE:  ' Cthulhu is a free, open source, flexible, and extensible screen reader that provides access to the graphical desktop via speech and refreshable braille.'",
     "     VISIBLE:  'Cthulhu is a free, open source, fle', cursor=1",
     "BRAILLE LINE:  ' Cthulhu is a free, open source, flexible, and extensible screen reader that provides access to the graphical desktop via speech and refreshable braille.'",
     "     VISIBLE:  'Cthulhu is a free, open source, fle', cursor=1",
     "SPEECH OUTPUT: 'Cthulhu is a free, open source, flexible, and extensible screen reader that provides access to the graphical desktop via speech and refreshable braille.'"]))

sequence.append(KeyComboAction("<Alt>F4"))
sequence.append(utils.AssertionSummaryAction())
sequence.start()
