File: echo.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 (65 lines) | stat: -rw-r--r-- 1,590 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!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 => 10;

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.", 7 unless $connected;

	my $echo = $modem->echo(1);
	ok($echo, "echo: echo turned on");
	ECHO: {
		skip "No Echo", 3 unless $echo;
		diag("Sending AT@@@ string...");
		ok($modem->atsend('AT@@@'.Device::Modem::CR), 'atsend: AT@@@ sent');
		my $ans = $modem->answer();
		like($ans, qr/AT@@@/, 'answer: contains AT@@@');
		like($ans, qr/ERROR/, 'answer: contains ERROR');
	}

	$echo = $modem->echo(0);
	ok($echo, "echo: echo turned off");
	ECHO: {
		skip "Couldn't turn off echo", 2 unless $echo;
		diag("Sending AT@@@ string");
		ok($modem->atsend('AT@@@'.Device::Modem::CR), 'atsend: AT@@@ sent');
		my $ans = $modem->answer();
		like($ans, qr/ERROR/, 'answer: contains ERROR');
	}
}

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;
}