Create different IDs for each bar (+test)

This commit is contained in:
Michael Stapelberg 2011-10-19 19:57:39 +01:00
parent 063b124e35
commit 15bface10d
3 changed files with 47 additions and 3 deletions

View File

@ -934,7 +934,14 @@ bar:
{ {
printf("\t new bar configuration finished, saving.\n"); printf("\t new bar configuration finished, saving.\n");
/* Generate a unique ID for this bar */ /* Generate a unique ID for this bar */
current_bar.id = sstrdup("foo"); /* TODO */ current_bar.id = sstrdup("bar-XXXXXX");
/* This works similar to mktemp in that it replaces the last six X with
* random letters, but without the restriction that the given buffer
* has to contain a valid path name. */
char *x = current_bar.id + strlen("bar-");
while (*x != '\0') {
*(x++) = (rand() % 26) + 'a';
}
/* Copy the current (static) structure into a dynamically allocated /* Copy the current (static) structure into a dynamically allocated
* one, then cleanup our static one. */ * one, then cleanup our static one. */

View File

@ -217,6 +217,8 @@ int main(int argc, char *argv[]) {
if (!isatty(fileno(stdout))) if (!isatty(fileno(stdout)))
setbuf(stdout, NULL); setbuf(stdout, NULL);
srand(time(NULL));
init_logging(); init_logging();
start_argv = argv; start_argv = argv;

View File

@ -99,9 +99,9 @@ $i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv; $bars = $i3->get_bar_config()->recv;
is(@$bars, 1, 'one bar configured'); is(@$bars, 1, 'one bar configured');
my $bar_id = shift @$bars; $bar_id = shift @$bars;
my $bar_config = $i3->get_bar_config($bar_id)->recv; $bar_config = $i3->get_bar_config($bar_id)->recv;
is($bar_config->{status_command}, 'i3status --bar', 'status_command correct'); is($bar_config->{status_command}, 'i3status --bar', 'status_command correct');
ok($bar_config->{verbose}, 'verbose on'); ok($bar_config->{verbose}, 'verbose on');
ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled'); ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled');
@ -127,4 +127,39 @@ is_deeply($bar_config->{colors},
exit_gracefully($pid); exit_gracefully($pid);
#####################################################################
# ensure that multiple bars get different IDs
#####################################################################
$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
bar {
# Start a default instance of i3bar which provides workspace buttons.
# Additionally, i3status will provide a statusline.
status_command i3status --bar
output HDMI1
}
bar {
output VGA1
}
EOT
$pid = launch_with_config($config);
$i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv;
is(@$bars, 2, 'two bars configured');
isnt($bars->[0], $bars->[1], 'bar IDs are different');
my $bar1_config = $i3->get_bar_config($bars->[0])->recv;
my $bar2_config = $i3->get_bar_config($bars->[1])->recv;
isnt($bar1_config->{outputs}, $bar2_config->{outputs}, 'outputs different');
exit_gracefully($pid);
done_testing; done_testing;