YACA: Add helper types/functions for pointer management 73/73573/11
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 13 Jun 2016 12:49:38 +0000 (14:49 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 14 Jun 2016 11:25:09 +0000 (13:25 +0200)
Change-Id: Iecdd6e8bfc36477a7c20c081a7788073fff66c60

src/yaca/yaca-test-common.cpp
src/yaca/yaca-test-common.h

index eee4c27..edfb971 100644 (file)
@@ -49,3 +49,18 @@ const char *yaca_error(int error)
 {
     return yaca_debug_translate_error(static_cast<yaca_error_e>(error));
 }
+
+KeyPtr wrap_ptr(yaca_key_h key)
+{
+    return KeyPtr(key, yaca_key_destroy);
+}
+
+CtxPtr wrap_ptr(yaca_context_h ctx)
+{
+    return CtxPtr(ctx, yaca_context_destroy);
+}
+
+BufPtr wrap_ptr(char* buffer)
+{
+    return BufPtr(buffer, yaca_free);
+}
index 9b6663d..f05db57 100644 (file)
 #include <string>
 #include <iostream>
 #include <sstream>
+#include <memory>
 
 #include <yaca_crypto.h>
 #include <yaca_error.h>
+#include <yaca_key.h>
 
 #include <dpl/gdbbacktrace.h>
 #include <dpl/test/test_failed.h>
@@ -94,3 +96,11 @@ do {                                                                           \
 #define YACA_SUCCESS(func) YACA_RESULT(YACA_ERROR_NONE, func);
 
 #define YACA_INVALID_PARAM(func) YACA_RESULT(YACA_ERROR_INVALID_PARAMETER, func);
+
+typedef std::unique_ptr<yaca_key_s, int (*)(yaca_key_h)> KeyPtr;
+typedef std::unique_ptr<yaca_context_s, int (*)(yaca_context_h)> CtxPtr;
+typedef std::unique_ptr<char, int (*)(void*)> BufPtr;
+
+KeyPtr wrap_ptr(yaca_key_h key);
+CtxPtr wrap_ptr(yaca_context_h ctx);
+BufPtr wrap_ptr(char* buffer);