From 31aed3c877af1cc23afce3bf75dd7344784170d0 Mon Sep 17 00:00:00 2001 From: Lukas Ruzicka Date: Tue, 12 Nov 2024 14:43:27 +0100 Subject: [PATCH] Create a test for KDE KCalc. --- tests/applications/kcalc/aaa_setup.pm | 26 +++++++ tests/applications/kcalc/about.pm | 31 +++++++++ tests/applications/kcalc/help.pm | 30 +++++++++ tests/applications/kcalc/kcalc.pm | 97 +++++++++++++++++++++++++++ 4 files changed, 184 insertions(+) create mode 100644 tests/applications/kcalc/aaa_setup.pm create mode 100644 tests/applications/kcalc/about.pm create mode 100644 tests/applications/kcalc/help.pm create mode 100644 tests/applications/kcalc/kcalc.pm diff --git a/tests/applications/kcalc/aaa_setup.pm b/tests/applications/kcalc/aaa_setup.pm new file mode 100644 index 00000000..b55244d2 --- /dev/null +++ b/tests/applications/kcalc/aaa_setup.pm @@ -0,0 +1,26 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# This script starts the KCalc application +# and saves the milestone for the consequtive +# tests. + +sub run { + my $self = shift; + # Run the application + menu_launch_type("kcalc"); + assert_screen("kcalc_runs"); + # wait for system to settle before snapshotting + sleep 10; +} + +sub test_flags { + return {fatal => 1, milestone => 1}; +} + +1; + +# vim: set sw=4 et: + diff --git a/tests/applications/kcalc/about.pm b/tests/applications/kcalc/about.pm new file mode 100644 index 00000000..850595b5 --- /dev/null +++ b/tests/applications/kcalc/about.pm @@ -0,0 +1,31 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# This script checks that Gnome Calculator shows About. + +sub run { + my $self = shift; + # Let's wait until everything settles down properly + # before we start testing. + sleep 5; + # Open the menu and click on the About item. + assert_and_click("kde_mainmenu_help"); + wait_still_screen(2); + assert_and_click("kcalc_submenu_about"); + # Check that it is shown. + assert_screen("kcalc_about_shown"); + # Click on the Credits button and check that it shows. + assert_and_click("kcalc_authors"); + assert_screen("kcalc_authors_shown"); +} + +sub test_flags { + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: + diff --git a/tests/applications/kcalc/help.pm b/tests/applications/kcalc/help.pm new file mode 100644 index 00000000..8a3f83a2 --- /dev/null +++ b/tests/applications/kcalc/help.pm @@ -0,0 +1,30 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# This script checks that Gnome Calculator shows help. + +sub run { + my $self = shift; + # Wait until everything settles. + sleep 5; + # Open Help + send_key("f1"); + wait_still_screen(2); + + # Check that Help opens. + assert_screen("kcalc_help_shown"); + + # Rest of the documentation is currently + # unavailable. +} + +sub test_flags { + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: + diff --git a/tests/applications/kcalc/kcalc.pm b/tests/applications/kcalc/kcalc.pm new file mode 100644 index 00000000..6a9680b8 --- /dev/null +++ b/tests/applications/kcalc/kcalc.pm @@ -0,0 +1,97 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# This script checks that KCalc works in Basic mode. + +# This subroutine rewrites the number into a word. +sub rewrite { + my $number = shift; + my %numbers = ( + 0 => 'zero', + 1 => 'one', + 2 => 'two', + 3 => 'three', + 4 => 'four', + 5 => 'five', + 6 => 'six', + 7 => 'seven', + 8 => 'eight', + 9 => 'nine', + "." => 'divider', + "%" => 'percent', + ); + my $rewritten = $numbers{$number}; + return $rewritten; +} + +# This subroutine performs the clicking of simple operations +# in the KCalc. +sub calculate { + my ($a, $b, $operation) = @_; + # Create lists of the numbers. + my @first = split('', $a); + my @second = split('', $b); + + # For each digit of the first number, click on + # the corresponding button. + foreach (@first) { + my $word = rewrite($_); + assert_and_click("kcalc_button_$word"); + } + # Click the operation button. + assert_and_click("kcalc_button_$operation"); + # For each digit of the second number, click on + # the corresponding button. + foreach (@second) { + my $word = rewrite($_); + assert_and_click("kcalc_button_$word"); + } + # Click on the Equals button + assert_and_click("kcalc_button_equals"); + # Assert the result has appeared on the screen. + my $identifier = hashed_string("$a-$operation-$b"); + assert_screen("kcalc_result_$identifier"); + # Clear the display. + send_key("esc"); +} + +sub run { + my $self = shift; + # Wait until everything settles. + sleep 5; + # Check that two numbers can be added. + calculate("10", "23", "add"); + # Check that two numbers can be subtracted. + calculate("67", "45", "sub"); + # Check that two numbers can be multiplied. + calculate("9", "0.8", "multi"); + # Check that two numbers can be divided. + calculate("77", "7", "div"); + # Check that you can use percents + calculate("33%", "90", "multi"); + + # Check that you can use brackets + assert_and_click("kcalc_button_three"); + assert_and_click("kcalc_button_multi"); + assert_and_click("kcalc_button_bopen"); + assert_and_click("kcalc_button_two"); + assert_and_click("kcalc_button_add"); + assert_and_click("kcalc_button_three"); + assert_and_click("kcalc_button_bclose"); + assert_and_click("kcalc_button_equals"); + my $identifier = hashed_string("3*(3+2)"); + assert_screen("kcalc_result_$identifier"); + send_key("esc"); + +} + +sub test_flags { + return {fatal => 1}; +} + +1; + +# vim: set sw=4 et: +