File: offhook.t

package info (click to toggle)
libdevice-modem-perl 1.59-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 452 kB
  • sloc: perl: 1,910; sh: 30; makefile: 2
file content (48 lines) | stat: -rw-r--r-- 1,040 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!perl

use strict;
use Device::Modem;
use Test::More;

my %config;
parse_config();

my $port = $config{tty} || $ENV{DEV_MODEM_PORT} || $Device::Modem::DEFAULT_PORT;

unless( $port ) {
	plan skip_all => 'Environment variables: DEV_MODEM_PORT and DEV_MODEM_BAUD are necessary';
	exit;
}
diag("Testing against port $port.  Set env DEV_MODEM_PORT to change");

plan tests => 4;

my $modem = Device::Modem->new( port => $port );
isa_ok($modem, 'Device::Modem', 'new: new object instance');

my $connected;
my $error = do {
	local $@;
	eval { $connected = $modem->connect() if $modem; };
	$@;
};
is($error, undef, 'connect: no errors');
ok($connected, 'connect: successfully connected');

SKIP: {
	skip "Not connected.", 1 unless $connected;
	diag('testing offhook function...');
	$modem->attention();

	ok($modem->offhook(), 'offhook: properly set');
}

sub parse_config {
	open my $fh, '<', '../.config' or return undef;
	while (my $line = <$fh>) {
		chomp $line;
		my @t = split ' ', $line, 2;
		$config{ $t[0] } = $t[1];
	}
	return undef;
}