]> git.sur5r.net Git - i3/i3/blob - testcases/t/159-socketpaths.t
30460fa94569332c3395f6fc3c5d01db41b137d5
[i3/i3] / testcases / t / 159-socketpaths.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Tests if the various ipc_socket_path options are correctly handled
5 #
6 use i3test i3_autostart => 0;
7 use File::Temp qw(tempfile tempdir);
8 use POSIX qw(getuid);
9 use v5.10;
10
11 #####################################################################
12 # default case: socket will be created in /tmp/i3-<username>/ipc-socket.<pid>
13 #####################################################################
14
15 my $config = <<EOT;
16 # i3 config file (v4)
17 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
18 EOT
19
20 # ensure XDG_RUNTIME_DIR is not set
21 delete $ENV{XDG_RUNTIME_DIR};
22 my $pid = launch_with_config($config, dont_add_socket_path => 1);
23
24 my $folder = "/tmp/i3-" . getpwuid(getuid());
25 ok(-d $folder, "folder $folder exists");
26 my $socketpath = "$folder/ipc-socket." . $pid;
27 ok(-S $socketpath, "file $socketpath exists and is a socket");
28
29 exit_gracefully($pid);
30
31 #####################################################################
32 # XDG_RUNTIME_DIR case: socket gets created in $XDG_RUNTIME_DIR/i3/ipc-socket.<pid>
33 #####################################################################
34
35 my $rtdir = tempdir(CLEANUP => 1);
36
37 ok(! -e "$rtdir/i3", "$rtdir/i3 does not exist yet");
38
39 $ENV{XDG_RUNTIME_DIR} = $rtdir;
40
41 $pid = launch_with_config($config, dont_add_socket_path => 1);
42
43 ok(-d "$rtdir/i3", "$rtdir/i3 exists and is a directory");
44 $socketpath = "$rtdir/i3/ipc-socket." . $pid;
45 ok(-S $socketpath, "file $socketpath exists and is a socket");
46
47 exit_gracefully($pid);
48
49 #####################################################################
50 # configuration file case: socket gets placed whereever we specify
51 #####################################################################
52
53 my $tmpdir = tempdir(CLEANUP => 1);
54 $socketpath = $tmpdir . "/config.sock";
55 ok(! -e $socketpath, "$socketpath does not exist yet");
56
57 $config = <<EOT;
58 # i3 config file (v4)
59 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
60 ipc-socket $socketpath
61 EOT
62
63 $pid = launch_with_config($config, dont_add_socket_path => 1);
64
65 ok(-S $socketpath, "file $socketpath exists and is a socket");
66
67 exit_gracefully($pid);
68
69 done_testing;