summaryrefslogtreecommitdiff
path: root/regress/dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'regress/dev.c')
-rw-r--r--regress/dev.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/regress/dev.c b/regress/dev.c
new file mode 100644
index 0000000..39b3584
--- /dev/null
+++ b/regress/dev.c
@@ -0,0 +1,77 @@
1/*
2 * Copyright (c) 2019 Yubico AB. All rights reserved.
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file.
5 */
6
7#include <assert.h>
8#include <fido.h>
9
10#define FAKE_DEV_HANDLE ((void *)0xdeadbeef)
11#define REPORT_LEN (64 + 1)
12
13static void *
14dummy_open(const char *path)
15{
16 (void)path;
17
18 return (FAKE_DEV_HANDLE);
19}
20
21static void
22dummy_close(void *handle)
23{
24 assert(handle == FAKE_DEV_HANDLE);
25}
26
27static int
28dummy_read(void *handle, unsigned char *ptr, size_t len, int ms)
29{
30 (void)ptr;
31 (void)len;
32 (void)ms;
33
34 assert(handle == FAKE_DEV_HANDLE);
35
36 return (-1);
37}
38
39static int
40dummy_write(void *handle, const unsigned char *ptr, size_t len)
41{
42 assert(handle == FAKE_DEV_HANDLE);
43 assert(ptr != NULL);
44 assert(len == REPORT_LEN);
45
46 return ((int)len);
47}
48
49/* gh#56 */
50static void
51open_iff_ok(void)
52{
53 fido_dev_t *dev = NULL;
54 fido_dev_io_t io;
55
56 io.open = dummy_open;
57 io.close = dummy_close;
58 io.read = dummy_read;
59 io.write = dummy_write;
60
61 assert((dev = fido_dev_new()) != NULL);
62 assert(fido_dev_set_io_functions(dev, &io) == FIDO_OK);
63 assert(fido_dev_open(dev, "dummy") == FIDO_ERR_RX);
64 assert(fido_dev_close(dev) == FIDO_ERR_INVALID_ARGUMENT);
65
66 fido_dev_free(&dev);
67}
68
69int
70main(void)
71{
72 fido_init(0);
73
74 open_iff_ok();
75
76 exit(0);
77}