From: Michael Stapelberg Date: Wed, 19 Oct 2011 18:57:39 +0000 (+0100) Subject: Create different IDs for each bar (+test) X-Git-Tag: 4.1~92^2~36 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=15bface10d2ebaac3f0a7b01da2c7be285a61807;p=i3%2Fi3 Create different IDs for each bar (+test) --- diff --git a/src/cfgparse.y b/src/cfgparse.y index 6e59c87c..2c796af1 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -934,7 +934,14 @@ bar: { printf("\t new bar configuration finished, saving.\n"); /* 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 * one, then cleanup our static one. */ diff --git a/src/main.c b/src/main.c index ffdc1fd3..832d7f1b 100644 --- a/src/main.c +++ b/src/main.c @@ -217,6 +217,8 @@ int main(int argc, char *argv[]) { if (!isatty(fileno(stdout))) setbuf(stdout, NULL); + srand(time(NULL)); + init_logging(); start_argv = argv; diff --git a/testcases/t/177-bar-config.t b/testcases/t/177-bar-config.t index 98eb4edd..c7cf2843 100644 --- a/testcases/t/177-bar-config.t +++ b/testcases/t/177-bar-config.t @@ -99,9 +99,9 @@ $i3 = i3(get_socket_path(0)); $bars = $i3->get_bar_config()->recv; 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'); ok($bar_config->{verbose}, 'verbose on'); ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled'); @@ -127,4 +127,39 @@ is_deeply($bar_config->{colors}, exit_gracefully($pid); +##################################################################### +# ensure that multiple bars get different IDs +##################################################################### + +$config = <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;