3void test_get_git_branch_CreatePipe_fails(
void **state) {
4 will_return(__wrap_CreatePipe,
false);
5 assert_null(get_git_branch(
nullptr, 0,
nullptr, 0));
8void test_get_git_branch_CreateProcess_fails(
void **state) {
9 will_return(__wrap_CreatePipe,
true);
10 will_return(__wrap_CreateProcess,
false);
11 will_return_always(__wrap_CloseHandle,
true);
12 assert_null(get_git_branch(
nullptr, 0,
nullptr, 0));
15void test_get_git_branch(
void **state) {
16 char *master_nl = malloc(8);
18 memcpy(master_nl,
"master\n", 7);
19 wchar_t *w_master = calloc(7,
sizeof(
wchar_t));
21 wmemcpy(w_master, L
"master", 6);
23 will_return(__wrap_CreatePipe,
true);
24 will_return(__wrap_CreateProcess,
true);
25 will_return_always(__wrap_CloseHandle,
true);
26 will_return(__wrap_WaitForSingleObject, WAIT_OBJECT_0);
27 will_return(__wrap_PeekNamedPipe, 8);
28 will_return(__wrap_PeekNamedPipe,
true);
29 will_return(__wrap_ReadFile, master_nl);
30 will_return(__wrap_ReadFile, 7);
31 will_return(__wrap_ReadFile,
true);
32 will_return(__wrap_PeekNamedPipe, 0);
33 will_return(__wrap_PeekNamedPipe,
true);
34 expect_value(__wrap_MultiByteToWideChar, cchWideChar, 0);
35 will_return(__wrap_MultiByteToWideChar, 0);
36 will_return(__wrap_MultiByteToWideChar, 6);
37 expect_value(__wrap_MultiByteToWideChar, cchWideChar, 6);
38 will_return(__wrap_MultiByteToWideChar, w_master);
39 will_return(__wrap_MultiByteToWideChar, 6);
41 wchar_t *ret = get_git_branch(
nullptr, 0,
nullptr, 0);
42 assert_memory_equal(ret, L
"master", 12);
49const struct CMUnitTest powershell_tests[] = {
50 cmocka_unit_test(test_get_git_branch),
51 cmocka_unit_test(test_get_git_branch_CreatePipe_fails),
52 cmocka_unit_test(test_get_git_branch_CreateProcess_fails),
55int main(
int argc,
char *argv[]) {
56 return cmocka_run_group_tests(powershell_tests,
nullptr,
nullptr);