--- /dev/null
+/*
+ * libhusb-test.c
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <cmocka.h>
+
+#include "libhusb.h"
+#include "libhusb_internal.h"
+#include <libusb-1.0/libusb.h>
+
+/* assertions and checks */
+
+/**
+ * @brief Initialize library context and check results
+ */
+static int setup_libhusb_context(void **state)
+{
+ int ret;
+ libhusb_context *ctx;
+ libusb_context *lusb_ctx;
+
+ expect_any(libusb_init, ctx);
+ will_return(libusb_init, lusb_ctx);
+ will_return(libusb_init, LIBUSB_SUCCESS);
+
+ ret = libhusb_init(&ctx);
+
+ assert_return_code(ret, 0);
+ assert_ptr_equal(ctx->lusb_ctx, lusb_ctx);
+
+ *state = (void *)ctx;
+
+ return 0;
+}
+
+static int teardown_libhusb_context(void **state)
+{
+ libhusb_context *ctx;
+
+ ctx = (libhusb_context *)(*state);
+ expect_any(libusb_exit, ctx);
+ libhusb_exit(ctx);
+
+ return 0;
+}
+
+/**
+ * @brief Test if initialization works fine
+ */
+static void test_init(void **state)
+{
+ libhusb_context *ctx;
+
+ ctx = (libhusb_context *)(*state);
+ assert_non_null(ctx);
+}
+
+/* Custom macro for defining test with given name and fixed teardown function */
+#define HUSB_TEST_CTX(func) \
+ cmocka_unit_test_setup_teardown(func, setup_libhusb_context, teardown_libhusb_context)
+
+static struct CMUnitTest tests[] = {
+
+ /**
+ * @some_test
+ * TODO: documentation
+ */
+ HUSB_TEST_CTX(test_init),
+};
+
+
+int main(int argc, char **argv)
+{
+ return cmocka_run_group_tests(tests, NULL, NULL);
+}