File: util.cpp

package info (click to toggle)
polybar 3.7.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,108 kB
  • sloc: cpp: 30,424; python: 3,750; sh: 284; makefile: 83
file content (22 lines) | stat: -rw-r--r-- 641 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include "ipc/util.hpp"

#include "common/test.hpp"
#include "ipc/msg.hpp"

using namespace polybar;
using namespace ipc;

TEST(GetSocketPath, RoundTrip) {
  EXPECT_EQ(123, get_pid_from_socket(get_socket_path(123)));
  EXPECT_EQ(1, get_pid_from_socket(get_socket_path(1)));

  EXPECT_EQ(-1, get_pid_from_socket(get_glob_socket_path()));
}

TEST(PidFromSocket, EdgeCases) {
  EXPECT_EQ(-1, get_pid_from_socket(""));
  EXPECT_EQ(-1, get_pid_from_socket("/tmp/foo.txt"));
  EXPECT_EQ(-1, get_pid_from_socket("/tmp/foo.sock"));
  EXPECT_EQ(-1, get_pid_from_socket("/tmp/foo..sock"));
  EXPECT_EQ(-1, get_pid_from_socket("/tmp/foo.bar.sock"));
}