resetting manifest requested domain to floor
[platform/upstream/ccache.git] / test / test_lockfile.c
1 /*
2  * Copyright (C) 2010 Joel Rosdahl
3  *
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)
7  * any later version.
8  *
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
12  * more details.
13  *
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
17  */
18
19 /*
20  * This file contains tests for functions in lockfile.c.
21  */
22
23 #include "ccache.h"
24 #include "test/framework.h"
25 #include "test/util.h"
26
27 TEST_SUITE(lockfile)
28
29 TEST(acquire_should_create_symlink)
30 {
31         lockfile_acquire("test", 1000);
32
33 #ifdef _WIN32
34         CHECK(path_exists("test.lock"));
35 #else
36         CHECK(is_symlink("test.lock"));
37 #endif
38 }
39
40 TEST(release_should_delete_file)
41 {
42         create_file("test.lock", "");
43         lockfile_release("test");
44
45         CHECK(!path_exists("test.lock"));
46 }
47
48 TEST(lock_breaking)
49 {
50         char *p;
51
52 #ifdef _WIN32
53         create_file("test.lock", "foo");
54         create_file("test.lock.lock", "foo");
55 #else
56         CHECK_INT_EQ(0, symlink("foo", "test.lock"));
57         CHECK_INT_EQ(0, symlink("foo", "test.lock.lock"));
58 #endif
59         CHECK(lockfile_acquire("test", 1000));
60
61 #ifdef _WIN32
62         p = read_text_file("test.lock");
63 #else
64         p = x_readlink("test.lock");
65 #endif
66         CHECK(p);
67         CHECK(!str_eq(p, "foo"));
68         CHECK(!path_exists("test.lock.lock"));
69
70         free(p);
71 }
72
73 #ifndef _WIN32
74 TEST(failed_lock_breaking)
75 {
76         create_file("test.lock", "");
77         CHECK(!lockfile_acquire("test", 1000));
78 }
79 #endif
80
81 TEST_SUITE_END