]>
git.saurik.com Git - apple/libc.git/blob - tests/readpassphrase.c
1 #include <darwintest.h>
4 #include <readpassphrase.h>
6 T_DECL(readpassphrase_stdin
, "readpassphrase_stdin")
8 int stdin_pipe
[2] = { 0 };
9 char pwd
[] = "ishouldnotbedoingthis\n";
12 T_ASSERT_POSIX_ZERO(pipe(stdin_pipe
),
13 "must be able to create a pipe");
14 T_ASSERT_EQ(STDIN_FILENO
, dup2(stdin_pipe
[0], STDIN_FILENO
),
15 "must be able to re-register the read end of the pipe with STDIN_FILENO");
16 T_ASSERT_EQ((ssize_t
) sizeof(pwd
), write(stdin_pipe
[1], pwd
, sizeof(pwd
)),
17 "must be able to write into the pipe");
18 T_ASSERT_EQ((void *) buff
, (void *) readpassphrase("", buff
, sizeof(buff
), RPP_STDIN
),
19 "readpassphrase must return its buffer argument on success");
20 // readpassphrase eats newlines
21 pwd
[sizeof(pwd
) - 2] = 0;
22 T_ASSERT_EQ_STR(buff
, pwd
,
23 "readpassphrase with RPP_STDIN must capture stdin");