Branch data Line data Source code
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 : 1 : TEST_SUITE(lockfile)
28 : :
29 [ + - ]: 1 : TEST(acquire_should_create_symlink)
30 : : {
31 : 1 : lockfile_acquire("test", 1000);
32 : :
33 : : #ifdef _WIN32
34 : : CHECK(path_exists("test.lock"));
35 : : #else
36 [ + - ]: 1 : CHECK(is_symlink("test.lock"));
37 : : #endif
38 : : }
39 : :
40 [ + - ]: 1 : TEST(release_should_delete_file)
41 : : {
42 : 1 : create_file("test.lock", "");
43 : 1 : lockfile_release("test");
44 : :
45 [ + - ]: 1 : CHECK(!path_exists("test.lock"));
46 : : }
47 : :
48 [ + - ]: 1 : 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 [ - + ]: 1 : CHECK_INT_EQ(0, symlink("foo", "test.lock"));
57 [ - + ]: 1 : CHECK_INT_EQ(0, symlink("foo", "test.lock.lock"));
58 : : #endif
59 [ + - ]: 1 : CHECK(lockfile_acquire("test", 1000));
60 : :
61 : : #ifdef _WIN32
62 : : p = read_text_file("test.lock", 0);
63 : : #else
64 : 1 : p = x_readlink("test.lock");
65 : : #endif
66 [ + - ]: 1 : CHECK(p);
67 [ + - ]: 1 : CHECK(!str_eq(p, "foo"));
68 [ + - ]: 1 : CHECK(!path_exists("test.lock.lock"));
69 : :
70 : 1 : free(p);
71 : : }
72 : :
73 : : #ifndef _WIN32
74 [ + - ]: 1 : TEST(failed_lock_breaking)
75 : : {
76 : 1 : create_file("test.lock", "");
77 [ + - ]: 1 : CHECK(!lockfile_acquire("test", 1000));
78 : : }
79 : : #endif
80 : :
81 : 1 : TEST_SUITE_END
|