#!/usr/bin/env perl
our
$VERSION
=
'0.03'
;
use
lib (
$FindBin::Bin
,
'blib/lib'
);
my
$VERBOSITY
= 0;
my
$curdir
=
$FindBin::Bin
;
my
$configfile
= File::Spec->catfile(
$curdir
,
'..'
,
'..'
,
't'
,
't-config'
,
'myapp.conf'
);
ok(-f
$configfile
,
"config file exists ($configfile)."
) or BAIL_OUT;
my
$mother
= Android::ElectricSheep::Automator->new({
'configfile'
=>
$configfile
,
'device-is-connected'
=> 1,
});
ok(
defined
(
$mother
),
'Android::ElectricSheep::Automator->new()'
.
" : called and got defined result."
) or BAIL_OUT;
my
$aregex
=
qr/^com\.google\.android\.calendar$/
i;
my
$res
=
$mother
->open_app({
'package'
=>
$aregex
});
ok(
defined
(
$res
),
'Android::ElectricSheep::Automator->open_app()'
.
" : called and got good result."
) or BAIL_OUT;
is(
ref
(
$res
),
'HASH'
,
'Android::ElectricSheep::Automator->open_app()'
.
" : called and got good result which is a HASHref."
) or BAIL_OUT(
"no it is '"
.
ref
(
$res
).
"'"
);
for
my
$k
(
keys
%$res
){
is(
ref
(
$res
->{
$k
}),
'Android::ElectricSheep::Automator::AppProperties'
,
'Android::ElectricSheep::Automator->open_app()'
.
" : called and got good result which is of type 'Android::ElectricSheep::Automator::AppProperties'."
) or BAIL_OUT(
"no it is '"
.
ref
(
$res
->{
$k
}).
"'"
);
}
my
$instantiated_apps
= 0;
my
@instantiated_apps
= ();
my
$apps
=
$mother
->apps;
for
my
$appname
(
sort
keys
%$apps
){
if
(
defined
$apps
->{
$appname
} ){
$instantiated_apps
++;
push
@instantiated_apps
,
$appname
;
}
if
(
$appname
=~
$aregex
){
ok(
defined
(
$apps
->{
$appname
}),
'open_app()'
.
" : app '$appname' has AppProperties."
) or BAIL_OUT;
for
my
$k
(
qw/
declaredPermissions requestedPermissions
installPermissions runtimePermissions enabledComponents
usesLibraryFiles usesOptionalLibraries
activities MainActivities MainActivity
/
){
diag
"$k:"
.perl2dump(
$apps
->{
$appname
}->get(
$k
));
}
}
}
is(
$instantiated_apps
, 1,
'open_app()'
.
" : called for regex '$aregex' and result contains one item with AppProperties."
) or BAIL_OUT(
"no it contains ${instantiated_apps} items: "
.
join
(
', '
,
@instantiated_apps
));
my
$num_apps_total
=
scalar
keys
%{
$mother
->apps };
sleep
(1);
$aregex
=
qr/^com\.google\.android\.deskclock$/
i;
$res
=
$mother
->open_app({
'package'
=>
$aregex
});
ok(
defined
(
$res
),
'Android::ElectricSheep::Automator->open_app()'
.
" : called and got good result."
) or BAIL_OUT;
is(
ref
(
$res
),
'HASH'
,
'Android::ElectricSheep::Automator->open_app()'
.
" : called and got good result which is a HASHref."
) or BAIL_OUT(
"no it is '"
.
ref
(
$res
).
"'"
);
for
my
$k
(
keys
%$res
){
is(
ref
(
$res
->{
$k
}),
'Android::ElectricSheep::Automator::AppProperties'
,
'Android::ElectricSheep::Automator->open_app()'
.
" : called and got good result which is of type 'Android::ElectricSheep::Automator::AppProperties'."
) or BAIL_OUT(
"no it is '"
.
ref
(
$res
->{
$k
}).
"'"
);
}
$instantiated_apps
= 0;
my
@instantiated_apps
= ();
$apps
=
$mother
->apps;
for
my
$appname
(
sort
keys
%$apps
){
if
(
defined
$apps
->{
$appname
} ){
$instantiated_apps
++;
push
@instantiated_apps
,
$appname
;
}
if
(
$appname
=~
$aregex
){
ok(
defined
(
$apps
->{
$appname
}),
'open_app()'
.
" : app '$appname' has AppProperties."
) or BAIL_OUT;
for
my
$k
(
qw/
declaredPermissions requestedPermissions
installPermissions runtimePermissions enabledComponents
usesLibraryFiles usesOptionalLibraries
activities MainActivities MainActivity
/
){
diag
"$k:"
.perl2dump(
$apps
->{
$appname
}->get(
$k
));
}
}
}
is(
$instantiated_apps
, 2,
'open_app()'
.
" : called for regex '$aregex' and result contains one item with AppProperties."
) or BAIL_OUT(
"no it contains ${instantiated_apps} items: "
.
join
(
', '
,
@instantiated_apps
));
sleep
(1);
for
$aregex
(
qr/^com\.android\.settings$/
i,
qr/^com\.google\.android\.deskclock$/
i,
){
$res
=
$mother
->close_app({
'package'
=>
$aregex
});
ok(
defined
(
$res
),
'Android::ElectricSheep::Automator->close_app()'
.
" : called and got good result."
) or BAIL_OUT;
is(
ref
(
$res
),
'HASH'
,
'Android::ElectricSheep::Automator->close_app()'
.
" : called and got good result which is a HASHref."
) or BAIL_OUT(
"no it is '"
.
ref
(
$res
).
"'"
);
for
my
$k
(
keys
%$res
){
is(
ref
(
$res
->{
$k
}),
'Android::ElectricSheep::Automator::AppProperties'
,
'Android::ElectricSheep::Automator->close_app()'
.
" : called and got good result which is of type 'Android::ElectricSheep::Automator::AppProperties'."
) or BAIL_OUT(
"no it is '"
.
ref
(
$res
->{
$k
}).
"'"
);
}
sleep
(2);
}
done_testing();
sleep
(1);