test: Add tests for isd_get_commercial_credit()
[libisds.git] / test / offline / prepare_environment.c
blobf1913030efb89f2d574efc1e1dd51642670912d5
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 #ifdef _WIN32
12 #define mkdir(x,y) mkdir(x)
13 #endif
15 static int test_setup_gnupg(void) {
16 char *home, *path = NULL;
17 char tmpfile[] = "XXXXXX";
18 int tmpfd;
20 home = getenv("HOME");
21 if (!home)
22 FAIL_TEST("Could not get HOME variable");
24 if (!*home)
25 FAIL_TEST("HOME environment variable is empty");
27 if (0 > test_asprintf(&path, "%s/%s", home, GNUPG_DIR))
28 FAIL_TEST("Could not build $HOME/.gnupg string");
30 if (mkdir(path, S_IRWXU) && errno != EEXIST) {
31 FAILURE_REASON("Could not create `%s' directory: %s", path,
32 strerror(errno));
33 free(path);
34 return 1;
37 if (chdir(path)) {
38 FAILURE_REASON("Could not change CWD to `%s': %s", path,
39 strerror(errno));
40 free(path);
41 return 1;
44 #ifndef _WIN32
45 if (-1 == (tmpfd = mkstemp(tmpfile))) {
46 FAILURE_REASON("Directory `%s' is not writable: %s", path,
47 strerror(errno));
48 free(path);
49 return 1;
52 close(tmpfd);
53 unlink(tmpfile);
54 #endif
56 free(path);
57 PASS_TEST;
60 int main(int argc, char **argv) {
62 INIT_TEST("prepare_environment");
64 TEST("set up gnupg", test_setup_gnupg);
66 SUM_TEST();