Release 0.41.92
[vala-gnome.git] / tests / semantic / floating-reference.vala
blobf690d690ddc7504a91661e5fb0d2b45b4a903d3f
1 [CCode (returns_floating_reference = true)]
2 Variant get_floating_variant () {
3 return new Variant.string ("foo");
6 void test_variant () {
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";
21 Variant? variant;
22 if (@value == null) {
23 variant = null;
24 } else {
25 variant = new Variant.string (@value);
27 assert (variant.is_of_type (VariantType.STRING));
28 assert (!variant.is_floating ());
31 bool @value = true;
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 () {
51 string name = "foo";
52 string key = "bar";
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 ());
60 void main () {
61 test_variant ();
62 test_variant_builder ();