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 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
#!/usr/bin/perl -w
use strict;
use Gnome2;
use constant TESTS => 50;
use Test::More tests => TESTS;
# $Id$
###############################################################################
SKIP: {
our $application;
do "t/TestBoilerplate";
#############################################################################
Gnome2::Config -> push_prefix("Test");
#############################################################################
Gnome2::Config -> set_string("/State/Shit", "Oh yes.");
is(Gnome2::Config -> get_string("/State/Shit"), "Oh yes.");
Gnome2::Config -> set_translated_string("/State/Shit", "Oh yes.");
is(Gnome2::Config -> get_translated_string("/State/Shit"), "Oh yes.");
is_deeply([Gnome2::Config -> get_string_with_default("/State/Whops=bla")], [1, "bla"]);
is_deeply([Gnome2::Config -> get_string_with_default("/State/Shit")], [0, "Oh yes."]);
is_deeply([Gnome2::Config -> get_translated_string_with_default("/State/Whops=bla")], [1, "bla"]);
is_deeply([Gnome2::Config -> get_translated_string_with_default("/State/Shit")], [0, "Oh yes."]);
Gnome2::Config -> set_vector("/State/Env", ["bla=blub", "blub=bla"]);
is_deeply(Gnome2::Config -> get_vector("/State/Env"), ["bla=blub", "blub=bla"]);
is_deeply([Gnome2::Config -> get_vector_with_default("/State/Whops")], [1, []]);
is_deeply([Gnome2::Config -> get_vector_with_default("/State/Env")], [0, ["bla=blub", "blub=bla"]]);
Gnome2::Config -> set_int("/Geometry/Width", 1024);
is(Gnome2::Config -> get_int("/Geometry/Width"), 1024);
is_deeply([Gnome2::Config -> get_int_with_default("/Geometry/Whops=1600")], [1, 1600]);
is_deeply([Gnome2::Config -> get_int_with_default("/Geometry/Width")], [0, 1024]);
Gnome2::Config -> set_float("/Geometry/Ratio", 1.23);
is(Gnome2::Config -> get_float("/Geometry/Ratio"), 1.23);
is_deeply([Gnome2::Config -> get_float_with_default("/Geometry/Whops=0.5")], [1, 0.5]);
is_deeply([Gnome2::Config -> get_float_with_default("/Geometry/Ratio")], [0, 1.23]);
Gnome2::Config -> set_bool("/State/Hidden", 1);
ok(Gnome2::Config -> get_bool("/State/Hidden"));
is_deeply([Gnome2::Config -> get_bool_with_default("/State/Whops=0")], [1, 0]);
is_deeply([Gnome2::Config -> get_bool_with_default("/State/Hidden")], [0, 1]);
ok(Gnome2::Config -> has_section("/State"));
ok(not Gnome2::Config -> has_section("/Whops"));
# #############################################################################
Gnome2::Config::Private -> set_string("/State/Shit", "Oh yes.");
is(Gnome2::Config::Private -> get_string("/State/Shit"), "Oh yes.");
Gnome2::Config::Private -> set_translated_string("/State/Shit", "Oh yes.");
is(Gnome2::Config::Private -> get_translated_string("/State/Shit"), "Oh yes.");
is_deeply([Gnome2::Config::Private -> get_string_with_default("/State/Whops=bla")], [1, "bla"]);
is_deeply([Gnome2::Config::Private -> get_string_with_default("/State/Shit")], [0, "Oh yes."]);
is_deeply([Gnome2::Config::Private -> get_translated_string_with_default("/State/Whops=bla")], [1, "bla"]);
is_deeply([Gnome2::Config::Private -> get_translated_string_with_default("/State/Shit")], [0, "Oh yes."]);
Gnome2::Config::Private -> set_vector("/State/Env", ["bla=blub", "blub=bla"]);
is_deeply(Gnome2::Config::Private -> get_vector("/State/Env"), ["bla=blub", "blub=bla"]);
is_deeply([Gnome2::Config::Private -> get_vector_with_default("/State/Whops")], [1, []]);
is_deeply([Gnome2::Config::Private -> get_vector_with_default("/State/Env")], [0, ["bla=blub", "blub=bla"]]);
Gnome2::Config::Private -> set_int("/Geometry/Width", 1024);
is(Gnome2::Config::Private -> get_int("/Geometry/Width"), 1024);
is_deeply([Gnome2::Config::Private -> get_int_with_default("/Geometry/Whops=1600")], [1, 1600]);
is_deeply([Gnome2::Config::Private -> get_int_with_default("/Geometry/Width")], [0, 1024]);
Gnome2::Config::Private -> set_float("/Geometry/Ratio", 1.23);
is(Gnome2::Config::Private -> get_float("/Geometry/Ratio"), 1.23);
SKIP: {
skip("get_float_with_default was broken prior to 2.6.0", 2)
unless (Gnome2 -> CHECK_VERSION(2, 6, 0));
is_deeply([Gnome2::Config::Private -> get_float_with_default("/Geometry/Whops=0.5")], [1, 0.5]);
is_deeply([Gnome2::Config::Private -> get_float_with_default("/Geometry/Ratio")], [0, 1.23]);
}
Gnome2::Config::Private -> set_bool("/State/Hidden", 1);
ok(Gnome2::Config::Private -> get_bool("/State/Hidden"));
is_deeply([Gnome2::Config::Private -> get_bool_with_default("/State/Whops=0")], [1, 0]);
is_deeply([Gnome2::Config::Private -> get_bool_with_default("/State/Hidden")], [0, 1]);
ok(Gnome2::Config::Private -> has_section("/State"));
ok(not Gnome2::Config::Private -> has_section("/Whops"));
#############################################################################
my $handle = Gnome2::Config -> init_iterator("/Geometry");
isa_ok($handle, "Gnome2::Config::Iterator");
$handle = Gnome2::Config::Private -> init_iterator("/Geometry");
isa_ok($handle, "Gnome2::Config::Iterator");
my ($key, $value);
while (@_ = $handle -> next()) {
($handle, $key, $value) = @_;
ok($key eq "Ratio" || $key eq "Width");
ok($value == 1.23 || $value == 1024);
}
#############################################################################
# FIXME: hrm, no sections?
$handle = Gnome2::Config -> init_iterator_sections("Test");
isa_ok($handle, "Gnome2::Config::Iterator");
$handle = Gnome2::Config::Private -> init_iterator_sections("Test");
isa_ok($handle, "Gnome2::Config::Iterator");
while (@_ = $handle -> next()) {
($handle, $key, $value) = @_;
warn $key, $value;
}
#############################################################################
# ok(Gnome2::Config -> sync());
# ok(Gnome2::Config -> sync_file("Test"));
# ok(Gnome2::Config::Private -> sync_file("Test"));
Gnome2::Config -> clean_key("/Geometry/Ratio");
Gnome2::Config::Private -> clean_file("/Geometry/Ratio");
Gnome2::Config -> clean_section("/Geometry");
Gnome2::Config::Private -> clean_section("/Geometry");
Gnome2::Config -> clean_file("Test");
Gnome2::Config::Private -> clean_file("Test");
Gnome2::Config -> drop_file("Test");
Gnome2::Config::Private -> drop_file("Test");
Gnome2::Config -> drop_all();
#############################################################################
Gnome2::Config -> pop_prefix();
#############################################################################
is(Gnome2::Config -> get_real_path("Test"), "$ENV{ HOME }/.gnome2/Test");
is(Gnome2::Config::Private -> get_real_path("Test"), "$ENV{ HOME }/.gnome2_private/Test");
}
|