File: boxed.t

package info (click to toggle)
libglib-object-introspection-perl 0.051-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 584 kB
  • sloc: ansic: 3,543; perl: 2,809; makefile: 9; sh: 3
file content (126 lines) | stat: -rw-r--r-- 3,284 bytes parent folder | download | duplicates (6)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env perl

BEGIN { require './t/inc/setup.pl' };

use strict;
use warnings;
use Scalar::Util qw/weaken/;

plan tests => 47;

# Use the provided constructor.
{
  my $boxed = GI::BoxedStruct->new;
  isa_ok ($boxed, 'GI::BoxedStruct');
  is ($boxed->long_, 0);
  is ($boxed->g_strv, undef);
  is ($boxed->long_ (42), 0);
  $boxed->inv;
  weaken $boxed;
  is ($boxed, undef);
}

# Use our generic constructor.
{
  my $boxed = Glib::Boxed::new ('GI::BoxedStruct', {long_ => 42});
  isa_ok ($boxed, 'GI::BoxedStruct');
  is ($boxed->long_, 42);
  is ($boxed->g_strv, undef);
  $boxed->inv;

  $boxed = Glib::Boxed::new ('GI::BoxedStruct', long_ => 42);
  isa_ok ($boxed, 'GI::BoxedStruct');
  is ($boxed->long_, 42);
  is ($boxed->g_strv, undef);
  $boxed->inv;
}

SKIP: {
  skip 'new stuff', 6
    unless check_gi_version (0, 12, 0);
  my $boxed = GI::BoxedStruct::returnv ();
  isa_ok ($boxed, 'GI::BoxedStruct');
  is ($boxed->long_, 42);
  is_deeply ($boxed->g_strv, [qw/0 1 2/]);
  $boxed->inv;
  weaken $boxed;
  is ($boxed, undef);
  # make sure we haven't destroyed the static object
  isa_ok (GI::BoxedStruct::returnv (), 'GI::BoxedStruct');
  isa_ok (GI::BoxedStruct::returnv ()->copy, 'GI::BoxedStruct');
}

SKIP: {
  skip 'new stuff', 5
    unless check_gi_version (0, 12, 0);
  my $boxed = GI::BoxedStruct::out ();
  isa_ok ($boxed, 'GI::BoxedStruct');
  is ($boxed->long_, 42);
  # $boxed->g_strv contains garbage
  weaken $boxed;
  is ($boxed, undef);
  # make sure we haven't destroyed the static object
  isa_ok (GI::BoxedStruct::out (), 'GI::BoxedStruct');
  isa_ok (GI::BoxedStruct::out ()->copy, 'GI::BoxedStruct');
}

SKIP: {
  skip 'new stuff', 4
    unless check_gi_version (0, 12, 0);
  my $boxed_out = GI::BoxedStruct::out ();
  my $boxed = GI::BoxedStruct::inout ($boxed_out);
  isa_ok ($boxed, 'GI::BoxedStruct');
  is ($boxed->long_, 0);
  is ($boxed_out->long_, 42);
  # $boxed->g_strv contains garbage
  weaken $boxed;
  is ($boxed, undef);
}

# --------------------------------------------------------------------------- #

SKIP: {
  skip 'new stuff', 5
    unless check_gi_version (0, 12, 0);
  my $boxed = Regress::TestSimpleBoxedA::const_return ();
  isa_ok ($boxed, 'Regress::TestSimpleBoxedA');
  isa_ok ($boxed, 'Glib::Boxed');
  my $copy = $boxed->copy;
  ok ($boxed->equals ($copy));
  weaken $boxed;
  is ($boxed, undef);
  weaken $copy;
  is ($copy, undef);
}

{
  my $boxed = Regress::TestBoxed->new;
  isa_ok ($boxed, 'Regress::TestBoxed');
  isa_ok ($boxed, 'Glib::Boxed');
  my $copy = $boxed->copy;
  isa_ok ($boxed, 'Regress::TestBoxed');
  isa_ok ($boxed, 'Glib::Boxed');
  ok ($boxed->equals ($copy));
  weaken $boxed;
  is ($boxed, undef);
  weaken $copy;
  is ($copy, undef);

  $boxed = Regress::TestBoxed->new_alternative_constructor1 (23);
  isa_ok ($boxed, 'Regress::TestBoxed');
  isa_ok ($boxed, 'Glib::Boxed');
  weaken $boxed;
  is ($boxed, undef);

  $boxed = Regress::TestBoxed->new_alternative_constructor2 (23, 42);
  isa_ok ($boxed, 'Regress::TestBoxed');
  isa_ok ($boxed, 'Glib::Boxed');
  weaken $boxed;
  is ($boxed, undef);

  $boxed = Regress::TestBoxed->new_alternative_constructor3 ("perl");
  isa_ok ($boxed, 'Regress::TestBoxed');
  isa_ok ($boxed, 'Glib::Boxed');
  weaken $boxed;
  is ($boxed, undef);
}