Update library version
[libisds.git] / test / offline / prepare_environment.c
bloba843f0d29c3f6dbc8029d08dbdf91bdfd68747aa
1 #include "../test.h"
2 #include <stdlib.h>
3 #include <string.h>
4 #include <sys/stat.h>
5 #include <sys/types.h>
6 #include <errno.h>
7 #include <unistd.h>
9 #define GNUPG_DIR ".gnupg"
11 static int test_setup_gnupg(void) {
12 char *home, *path = NULL;
13 char tmpfile[] = "XXXXXX";
14 int tmpfd;
16 home = getenv("HOME");
17 if (!home)
18 FAIL_TEST("Could not get HOME variable");
20 if (!*home)
21 FAIL_TEST("HOME environment variable is empty");
23 if (0 > test_asprintf(&path, "%s/%s", home, GNUPG_DIR))
24 FAIL_TEST("Could not build $HOME/.gnupg string");
26 if (mkdir(path, S_IRWXU) && errno != EEXIST) {
27 FAILURE_REASON("Could not create `%s' directory: %s", path,
28 strerror(errno));
29 free(path);
30 return 1;
33 if (chdir(path)) {
34 FAILURE_REASON("Could not change CWD to `%s': %s", path,
35 strerror(errno));
36 free(path);
37 return 1;
40 if (-1 == (tmpfd = mkstemp(tmpfile))) {
41 FAILURE_REASON("Directory `%s' is not writable: %s", path,
42 strerror(errno));
43 free(path);
44 return 1;
47 close(tmpfd);
48 unlink(tmpfile);
50 free(path);
51 PASS_TEST;
54 int main(int argc, char **argv) {
56 INIT_TEST("prepare_environment");
58 TEST("set up gnupg", test_setup_gnupg);
60 SUM_TEST();