6 #include "../libgammu/device/devfunc.h"
10 #define lock_path "/var/lock/LCK.."
11 #define TEST_DEVICE "/dev/foo/bar"
12 #define TEST_LOCK lock_path "bar"
14 void create_lock(const char *name
, const void *lock_data
, const size_t lock_data_len
)
17 fd
= fopen(name
, "w");
18 test_result(fd
!= NULL
);
19 test_result(fwrite(lock_data
, 1, lock_data_len
, fd
) == lock_data_len
);
20 test_result(fclose(fd
) == 0);
23 int main(int argc UNUSED
, char **argv UNUSED
)
25 GSM_Debug_Info
*debug_info
;
31 sprintf(pids
, "%d", pid
);
33 debug_info
= GSM_GetGlobalDebug();
34 GSM_SetDebugFileDescriptor(stderr
, FALSE
, debug_info
);
35 GSM_SetDebugLevel("textall", debug_info
);
37 /* Non existing PID, ASCII */
38 create_lock(TEST_LOCK
, "1234567890", 10);
39 test_result(lock_device(NULL
, TEST_DEVICE
, &lock
) == ERR_NONE
);
40 test_result(lock
!= NULL
);
41 test_result(unlock_device(NULL
, &lock
) == TRUE
);
45 /* Existing PID, ASCII */
46 create_lock(TEST_LOCK
, pids
, strlen(pids
));
47 test_result(lock_device(NULL
, TEST_DEVICE
, &lock
) == ERR_DEVICELOCKED
);
48 test_result(lock
== NULL
);
49 test_result(unlock_device(NULL
, &lock
) == FALSE
);
53 /* Existing PID, binary */
54 create_lock(TEST_LOCK
, &pid
, sizeof(int));
55 test_result(lock_device(NULL
, TEST_DEVICE
, &lock
) == ERR_DEVICELOCKED
);
56 test_result(lock
== NULL
);
57 test_result(unlock_device(NULL
, &lock
) == FALSE
);
61 /* Existing PID, binary */
63 create_lock(TEST_LOCK
, &pid
, sizeof(int));
64 test_result(lock_device(NULL
, TEST_DEVICE
, &lock
) == ERR_NONE
);
65 test_result(lock
!= NULL
);
66 test_result(unlock_device(NULL
, &lock
) == TRUE
);
70 /* No existing lock */
71 test_result(lock_device(NULL
, TEST_DEVICE
, &lock
) == ERR_NONE
);
72 test_result(lock
!= NULL
);
73 test_result(unlock_device(NULL
, &lock
) == TRUE
);
78 /* Editor configuration
79 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: