1#
2#  Module for simulated extreme situations, useful for testing.
3#
4package Prima::Stress;
5use strict;
6no warnings;
7use Prima;
8
9our %stress = (
10	fs  => undef,
11	dpi => undef,
12	scr => undef,
13);
14
15sub import
16{
17	shift;
18
19	for my $p ( @_ ) {
20		if ( $p =~ /^(\w+)=(\d+)$/ && exists $stress{$1}) {
21			$stress{$1} = $2;
22		} else {
23			warn "bad command: '$p'\n";
24		}
25	}
26
27	unless ( @_ ) {
28		$stress{fs}  = ( 5, 7, 14, 18) [ int(rand(4)) ] ;
29		$stress{scr}  = ( 7, 14, 30, 40) [ int(rand(4)) ] ;
30		$stress{dpi} = ( 48, 96, 192, 288 ) [int(rand(4)) ];
31		warn "** Prima::Stress: fs=$stress{fs} dpi=$stress{dpi} scr=$stress{scr}\n";
32	}
33
34	Prima::Application::add_startup_notification( sub {
35		if ( $stress{dpi}) {
36			$::application->sys_action("resolution $stress{dpi} $stress{dpi}");
37			$::application->uiScaling(0);
38			$::application->font( $::application-> get_default_font );
39			$::application->HintWidget->font( $::application-> get_default_font );
40		}
41		if ($stress{fs}) {
42			$::application->font->size( $stress{fs});
43		}
44	});
45
46	if ( $stress{fs}) {
47		*Prima::Widget::get_default_font = sub {
48			Prima::Drawable-> font_match( { size => $Prima::Stress::stress{fs} }, {});
49		};
50		*Prima::Application::get_default_font = sub {
51			Prima::Drawable-> font_match( { size => $Prima::Stress::stress{fs} }, {});
52		};
53	}
54
55	if ( $stress{scr}) {
56		my $gsv = \&Prima::Application::get_system_value;
57		*Prima::Application::get_system_value = sub {
58			my ( undef, $val ) = @_;
59			return $stress{scr} if $val == sv::XScrollbar || $val == sv::YScrollbar;
60			goto $gsv;
61		};
62		*Prima::Application::get_default_scrollbar_metrics = sub { $stress{scr}, $stress{scr} };
63	}
64}
65
661;
67
68=pod
69
70=head1 NAME
71
72Prima::Stress - stress test module
73
74=head1 DESCRIPTION
75
76The module is intended for use in test purposes, to check the functionality of
77a program or a module under particular conditions that
78might be overlooked during the design. Currently, the only stress factor implemented
79is change of the default font size, which is set to different value every time
80the module is invoked.
81
82To use the module functionality it is enough to include a typical
83
84	use Prima::Stress;
85
86code, or, if the program is invoked by calling perl, by using
87
88	perl -MPrima::Stress program
89
90syntax. The module does not provide any methods, however one may address individual aspects
91of UI defaults.
92
93=head1 API
94
95=head2 Font size
96
97   use Prima::Stress q(fs=18);
98   perl -MPrima::Stress=fs=18 program
99
100This syntax changes the default font size to 18 points.
101
102=head2 Display resolution
103
104   use Prima::Stress q(dpi=192);
105   perl -MPrima::Stress=dpi=192 program
106
107This syntax changes the display resolution to 192 pixels per inch.
108
109=head1 AUTHOR
110
111Dmitry Karasik E<lt>dmitry@karasik.eu.orgkE<gt>,
112
113=cut
114