File: bytes.t

package info (click to toggle)
libglib-perl 3%3A1.329-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,320 kB
  • sloc: perl: 4,938; ansic: 901; makefile: 7
file content (50 lines) | stat: -rw-r--r-- 988 bytes parent folder | download | duplicates (5)
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
#!/usr/bin/perl

#
# Test the GBytes wrappers.
#

use strict;
use warnings;
use Glib;
use Test::More;

unless (Glib -> CHECK_VERSION (2, 32, 0)) {
  plan skip_all => 'GBytes is new in 2.32';
} else {
  plan tests => 13;
}

# Basic API.
my $data = pack 'C*', 0..255;

my $bytes = Glib::Bytes->new ($data);
isa_ok ($bytes, 'Glib::Bytes');
isa_ok ($bytes, 'Glib::Boxed');

is ($bytes->get_size, length $data);
is ($bytes->get_data, $data);

ok (defined $bytes->hash);
ok ($bytes->equal ($bytes));
is ($bytes->compare ($bytes), 0);

# Overloading.
is ("$bytes", $data, '"" overloading');
ok ($bytes eq $data, 'eq overloading');
is (length $bytes, length $data, 'length overloading');

# Wide characters.
eval {
  my $wstring = "\x{2665}";
  my $bytes = Glib::Bytes->new ($wstring);
};
like ($@, qr/Wide character/);

eval {
  my $wstring = "\x{2665}";
  utf8::encode ($wstring);
  my $bytes = Glib::Bytes->new ($wstring);
  is ($bytes->get_data, pack ('C*', 0xE2,0x99,0xA5));
};
is ($@, '');