1 [CCode (returns_floating_reference
= true)]
2 Variant
get_floating_variant () {
3 return new Variant
.string ("foo");
8 string? @value
= "bar";
9 Variant? variant
= new Variant
.string (@value
) ?? new Variant
.string (@value
);
10 assert (variant
.is_of_type (VariantType
.STRING
));
11 assert (!variant
.is_floating ());
14 string? @value
= "foo";
15 Variant? variant
= @value
== null ?
null : new Variant
.string (@value
);
16 assert (variant
.is_of_type (VariantType
.STRING
));
17 assert (!variant
.is_floating ());
20 string? @value
= "foo";
25 variant
= new Variant
.string (@value
);
27 assert (variant
.is_of_type (VariantType
.STRING
));
28 assert (!variant
.is_floating ());
32 Variant? variant
= new Variant
.boolean (@value
);
33 assert (variant
.is_of_type (VariantType
.BOOLEAN
));
34 assert (!variant
.is_floating ());
37 string? @value
= "manam";
38 Variant? variant
= new Variant
.string (@value
);
39 assert (variant
.is_of_type (VariantType
.STRING
));
40 assert (!variant
.is_floating ());
41 string s
= (string) variant
;
42 assert (s
== "manam");
45 Variant? variant
= get_floating_variant ();
46 assert (!variant
.is_floating ());
50 void test_variant_builder () {
53 Variant? @value
= null;
54 var builder
= new
VariantBuilder (new
VariantType ("a{smv}"));
55 builder
.add ("{smv}", key
, @value
);
56 var variant
= new
Variant ("(s@a{smv})", name
, builder
.end ());
57 assert (!variant
.is_floating ());
62 test_variant_builder ();