1 // Copyright (C) 2010-2018 Joel Rosdahl
3 // This program is free software; you can redistribute it and/or modify it
4 // under the terms of the GNU General Public License as published by the Free
5 // Software Foundation; either version 3 of the License, or (at your option)
8 // This program is distributed in the hope that it will be useful, but WITHOUT
9 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 // You should have received a copy of the GNU General Public License along with
14 // this program; if not, write to the Free Software Foundation, Inc., 51
15 // Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 // This file contains tests for functions in lockfile.c.
19 #include "../src/ccache.h"
20 #include "framework.h"
25 TEST(acquire_should_create_symlink)
27 lockfile_acquire("test", 1000);
30 CHECK(path_exists("test.lock"));
32 CHECK(is_symlink("test.lock"));
36 TEST(release_should_delete_file)
38 create_file("test.lock", "");
39 lockfile_release("test");
41 CHECK(!path_exists("test.lock"));
49 create_file("test.lock", "foo");
50 create_file("test.lock.lock", "foo");
52 CHECK_INT_EQ(0, symlink("foo", "test.lock"));
53 CHECK_INT_EQ(0, symlink("foo", "test.lock.lock"));
55 CHECK(lockfile_acquire("test", 1000));
58 p = read_text_file("test.lock", 0);
60 p = x_readlink("test.lock");
63 CHECK(!str_eq(p, "foo"));
64 CHECK(!path_exists("test.lock.lock"));
70 TEST(failed_lock_breaking)
72 create_file("test.lock", "");
73 CHECK(!lockfile_acquire("test", 1000));