]>
git.proxmox.com Git - libgit2.git/blob - tests-clar/core/env.c
1 #include "clar_libgit2.h"
7 #include "win32/utf-conv.h"
9 static char *cl_getenv(const char *name
)
11 wchar_t *name_utf16
= gitwin_to_utf16(name
);
12 DWORD value_len
, alloc_len
;
16 cl_assert(name_utf16
);
17 alloc_len
= GetEnvironmentVariableW(name_utf16
, NULL
, 0);
21 cl_assert(value_utf16
= git__calloc(alloc_len
, sizeof(wchar_t)));
23 value_len
= GetEnvironmentVariableW(name_utf16
, value_utf16
, alloc_len
);
24 cl_assert_equal_i(value_len
, alloc_len
- 1);
26 cl_assert(value_utf8
= gitwin_from_utf16(value_utf16
));
28 git__free(value_utf16
);
33 static int cl_setenv(const char *name
, const char *value
)
35 wchar_t *name_utf16
= gitwin_to_utf16(name
);
36 wchar_t *value_utf16
= value
? gitwin_to_utf16(value
) : NULL
;
38 cl_assert(name_utf16
);
39 cl_assert(SetEnvironmentVariableW(name_utf16
, value_utf16
));
41 git__free(name_utf16
);
42 git__free(value_utf16
);
50 #define cl_getenv(n) getenv(n)
51 #define cl_setenv(n,v) (v) ? setenv((n),(v),1) : unsetenv(n)
55 static char *env_home
= NULL
;
56 static char *env_userprofile
= NULL
;
58 void test_core_env__initialize(void)
61 env_userprofile
= cl_getenv("USERPROFILE");
63 env_home
= cl_getenv("HOME");
67 void test_core_env__cleanup(void)
70 cl_setenv("USERPROFILE", env_userprofile
);
71 git__free(env_userprofile
);
73 cl_setenv("HOME", env_home
);
77 void test_core_env__0(void)
79 static char *home_values
[] = {
81 "fáke_hõme", /* all in latin-1 supplement */
82 "fĀke_Ĥome", /* latin extended */
83 "fακε_hοmέ", /* having fun with greek */
84 "faงe_นome", /* now I have no idea, but thai characters */
85 "f\xe1\x9cx80ke_\xe1\x9c\x91ome", /* tagalog characters */
86 "\xe1\xb8\x9fẢke_hoṁe", /* latin extended additional */
87 "\xf0\x9f\x98\x98\xf0\x9f\x98\x82", /* emoticons */
90 git_buf path
= GIT_BUF_INIT
, found
= GIT_BUF_INIT
;
94 for (val
= home_values
; *val
!= NULL
; val
++) {
96 if (p_mkdir(*val
, 0777) == 0) {
97 /* if we can't make the directory, let's just assume
98 * we are on a filesystem that doesn't support the
99 * characters in question and skip this test...
101 cl_git_pass(git_path_prettify(&path
, *val
, NULL
));
104 cl_git_pass(cl_setenv("USERPROFILE", path
.ptr
));
106 /* do a quick check that it was set correctly */
107 check
= cl_getenv("USERPROFILE");
108 cl_assert_equal_s(path
.ptr
, check
);
111 cl_git_pass(cl_setenv("HOME", path
.ptr
));
113 /* do a quick check that it was set correctly */
114 check
= cl_getenv("HOME");
115 cl_assert_equal_s(path
.ptr
, check
);
118 cl_git_pass(git_buf_puts(&path
, "/testfile"));
119 cl_git_mkfile(path
.ptr
, "find me");
121 cl_git_pass(git_futils_find_global_file(&found
, "testfile"));
126 git_buf_free(&found
);