Changeset e428a36


Ignore:
Timestamp:
Jun 14, 2013, 7:39:41 PM (11 years ago)
Author:
David Benjamin <davidben@mit.edu>
Parents:
80c0fc7 (diff), 9d4dfdc (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:
Merge 9d4dfdcd2d49dbcc22eb7c50544376042b61a6ba into 80c0fc7442dbbcdb248b6b588246470d35b6f8ec
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • t/variable.t

    r4953c44 r5d8c9a7  
    1717BarnOwl::unset("-q", "intvar");
    1818is(BarnOwl::getvar("intvar"), "24", "intvar unset bogus");
     19BarnOwl::new_variable_int("intvar", { default => 7 });
     20isnt(BarnOwl::getvar("intvar"), "7", "intvar reinit shouldn't override preexisting value");
    1921
    2022BarnOwl::new_variable_bool("boolvar", { default => 1 });
     
    2830BarnOwl::unset("-q", "boolvar");
    2931is(BarnOwl::getvar("boolvar"), "off", "boolvar unset");
     32BarnOwl::new_variable_bool("boolvar", { default => 1 });
     33isnt(BarnOwl::getvar("boolvar"), "on", "boolvar reinit shouldn't override preexisting value");
    3034
    3135BarnOwl::new_variable_string("strvar", { default => "monkey" });
     
    3741BarnOwl::unset("-q", "strvar");
    3842is(BarnOwl::getvar("strvar"), "cuttlefish", "strvar unset bogus");
     43BarnOwl::new_variable_string("strvar", { default => "monkey" });
     44isnt(BarnOwl::getvar("strvar"), "monkey", "strvar reinit shouldn't override value");
    3945
    4046BarnOwl::new_variable_enum("enumvar", { validsettings => [qw/foo bar baz/], default => "bar" });
     
    4652BarnOwl::unset("-q", "enumvar");
    4753is(BarnOwl::getvar("enumvar"), "baz", "enumvar unset bogus");
     54BarnOwl::new_variable_enum("enumvar", { validsettings => [qw/foo bar baz/], default => "bar" });
     55isnt(BarnOwl::getvar("enumvar"), "bar", "enumvar reinit shouldn't override value");
    4856
    4957BarnOwl::new_variable_int("intvar2");
     
    6068BarnOwl::new_variable_full("fullvar", {
    6169    validsettings => '<short-words>',
    62     get_tostring => sub { "value is " . $value },
     70    get_tostring => sub { $value },
    6371    set_fromstring => sub {
    64         die "Too long" unless $_[0] =~ /^...?$/;
    65         $value = $_[0];
     72        die "Too long" unless $_[0] =~ /^...?$/;
     73        $value = lc($_[0]);
    6674    },
    6775    takes_on_off => 1
    6876});
    69 is(BarnOwl::getvar("fullvar"), "value is foo", "fullvar get");
    70 BarnOwl::set("-q", "fullvar", "bar");
    71 is(BarnOwl::getvar("fullvar"), "value is bar", "fullvar set");
     77is(BarnOwl::getvar("fullvar"), "foo", "fullvar get");
     78BarnOwl::set("-q", "fullvar", "Bar");
     79is(BarnOwl::getvar("fullvar"), "bar", "fullvar set");
    7280BarnOwl::set("-q", "fullvar");
    73 is(BarnOwl::getvar("fullvar"), "value is on", "fullvar set2");
     81is(BarnOwl::getvar("fullvar"), "on", "fullvar set2");
    7482BarnOwl::unset("-q", "fullvar");
    75 is(BarnOwl::getvar("fullvar"), "value is off", "fullvar unset");
     83is(BarnOwl::getvar("fullvar"), "off", "fullvar unset");
    7684BarnOwl::set("-q", "fullvar", "bogus");
    77 is(BarnOwl::getvar("fullvar"), "value is off", "fullvar set bogus");
    78 $value = "something really long";
    79 is(BarnOwl::getvar("fullvar"), "value is something really long", "fullvar set out-of-band");
     85is(BarnOwl::getvar("fullvar"), "off", "fullvar set bogus");
     86$value = "xyz";
     87is(BarnOwl::getvar("fullvar"), "xyz", "fullvar set out-of-band");
     88# Kinda verbose, but better to test all forms
     89my $newvalue = "foo";
     90BarnOwl::new_variable_full("fullvar", {
     91    validsettings => '<short-words>',
     92    get_tostring => sub { $newvalue },
     93    set_fromstring => sub {
     94        die "Too long" unless $_[0] =~ /^...?$/;
     95        $newvalue = lc($_[0]);
     96    },
     97    takes_on_off => 1
     98});
     99is(BarnOwl::getvar("fullvar"), "xyz", "fullvar reinit doesn't override value");
     100$newvalue = "abc";
     101is(BarnOwl::getvar("fullvar"), "abc", "fullvar reinit changed setters");
    80102
    811031;
  • variable.c

    r6a8b519 r9d4dfdc  
    612612void owl_variable_dict_add_variable(owl_vardict * vardict,
    613613                                    owl_variable * var) {
     614  char *oldvalue = NULL;
     615  owl_variable *oldvar = owl_variable_get_var(vardict, var->name);
     616  /* Save the old value as a string. */
     617  if (oldvar) {
     618    oldvalue = owl_variable_get_tostring(oldvar);
     619  }
    614620  owl_dict_insert_element(vardict, var->name, var, (void (*)(void *))owl_variable_delete);
     621  /* Restore the old value. */
     622  if (oldvalue) {
     623    owl_variable_set_fromstring(var, oldvalue, 0);
     624    g_free(oldvalue);
     625  }
    615626}
    616627
     
    777788  g_free(v->default_str);
    778789  g_free(v->validsettings);
    779   g_value_unset(&(v->val));
     790  if (v->type != OWL_VARIABLE_OTHER)
     791    g_value_unset(&(v->val));
    780792  g_closure_unref(v->get_tostring_fn);
    781793  g_closure_unref(v->set_fromstring_fn);
Note: See TracChangeset for help on using the changeset viewer.