aboutsummaryrefslogtreecommitdiffstats
path: root/librecrypt_set_user_data.c
diff options
context:
space:
mode:
Diffstat (limited to 'librecrypt_set_user_data.c')
-rw-r--r--librecrypt_set_user_data.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/librecrypt_set_user_data.c b/librecrypt_set_user_data.c
new file mode 100644
index 0000000..f2abb2f
--- /dev/null
+++ b/librecrypt_set_user_data.c
@@ -0,0 +1,49 @@
+/* See LICENSE file for copyright and license details. */
+#include "common.h"
+#ifndef TEST
+
+
+void
+librecrypt_set_user_data(LIBRECRYPT_CONTEXT *ctx, void *user)
+{
+ ctx->user_data = user;
+}
+
+
+#else
+
+
+extern LIBRECRYPT_CONTEXT *volatile ctx;
+LIBRECRYPT_CONTEXT *volatile ctx;
+
+
+int
+main(void)
+{
+ char *user = &(char){0};
+
+ SET_UP_ALARM();
+ INIT_RESOURCE_TEST();
+
+ ctx = librecrypt_create_context();
+ assert(ctx != NULL);
+
+ EXPECT(librecrypt_get_user_data(ctx) == NULL);
+ EXPECT(librecrypt_get_user_data(ctx) == NULL);
+ librecrypt_set_user_data(ctx, user);
+ EXPECT(librecrypt_get_user_data(ctx) == user);
+ EXPECT(librecrypt_get_user_data(ctx) == user);
+ librecrypt_set_user_data(ctx, user);
+ librecrypt_set_user_data(ctx, NULL);
+ EXPECT(librecrypt_get_user_data(ctx) == NULL);
+ EXPECT(librecrypt_get_user_data(ctx) == NULL);
+ librecrypt_set_user_data(ctx, NULL);
+
+ librecrypt_free_context(ctx);
+
+ STOP_RESOURCE_TEST();
+ return 0;
+}
+
+
+#endif