2 * Copyright (C) 2010 Joel Rosdahl
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 3 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc., 51
16 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 * This file contains tests for functions in lockfile.c.
24 #include "test/framework.h"
25 #include "test/util.h"
29 TEST(acquire_should_create_symlink)
31 lockfile_acquire("test", 1000);
34 CHECK(path_exists("test.lock"));
36 CHECK(is_symlink("test.lock"));
40 TEST(release_should_delete_file)
42 create_file("test.lock", "");
43 lockfile_release("test");
45 CHECK(!path_exists("test.lock"));
53 create_file("test.lock", "foo");
54 create_file("test.lock.lock", "foo");
56 CHECK_INT_EQ(0, symlink("foo", "test.lock"));
57 CHECK_INT_EQ(0, symlink("foo", "test.lock.lock"));
59 CHECK(lockfile_acquire("test", 1000));
62 p = read_text_file("test.lock");
64 p = x_readlink("test.lock");
67 CHECK(!str_eq(p, "foo"));
68 CHECK(!path_exists("test.lock.lock"));
74 TEST(failed_lock_breaking)
76 create_file("test.lock", "");
77 CHECK(!lockfile_acquire("test", 1000));