tests CHANGE add test for sharing client context in multiple threads
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index ddb5eec..26ce14c 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 2.6)
# list of all the tests
-set(tests test_io test_fd_comm test_init_destroy_client test_init_destroy_server test_time)
+set(tests test_io test_fd_comm test_init_destroy_client test_init_destroy_server test_time test_client_thread)
if (ENABLE_SSH OR ENABLE_TLS)
list(APPEND tests test_server_thread)
diff --git a/tests/test_client_thread.c b/tests/test_client_thread.c
new file mode 100644
index 0000000..52ce016
--- /dev/null
+++ b/tests/test_client_thread.c
@@ -0,0 +1,77 @@
+/**
+ * \file test_client_thread.c
+ * \author Radek Krejci <rkrejci@cesnet.cz>
+ * \brief libnetconf2 tests - threads functions in client
+ *
+ * Copyright (c) 2017 CESNET, z.s.p.o.
+ *
+ * This source code is licensed under BSD 3-Clause License (the "License").
+ * You may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://opensource.org/licenses/BSD-3-Clause
+ */
+
+#include <pthread.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+#include <libyang/libyang.h>
+
+#include <session_client.h>
+#include "config.h"
+
+#define nc_assert(cond) if (!(cond)) { fprintf(stderr, "assert failed (%s:%d)\n", __FILE__, __LINE__); exit(1); }
+
+static void *
+thread(void *arg)
+{
+ /* default search path is NULL */
+ nc_assert(nc_client_get_schema_searchpath() == NULL);
+
+ /* use the context shared from the main thread */
+ nc_client_set_thread_context(arg);
+
+ /* check that we have now the search path set in main thread */
+ nc_assert(strcmp(nc_client_get_schema_searchpath(), "/tmp") == 0);
+ /* and change it to check it later in main thread */
+ nc_assert(nc_client_set_schema_searchpath("/etc") == 0)
+
+ return NULL;
+}
+
+int
+main(void)
+{
+ void *arg;
+ pthread_t t;
+ int r;
+
+ nc_client_init();
+
+ /*
+ * TEST sharing the thread context
+ */
+ nc_assert(nc_client_set_schema_searchpath("/tmp") == 0)
+
+ /* get the context for sharing */
+ arg = nc_client_get_thread_context();
+
+ /* create new thread and provide the context */
+ r = pthread_create(&t, NULL, &thread, arg);
+ nc_assert(r == 0);
+
+ pthread_join(t, NULL);
+
+ /* check the changed search path value from the thread */
+ nc_assert(strcmp(nc_client_get_schema_searchpath(), "/etc") == 0);
+
+ /* cleanup */
+ nc_client_destroy();
+
+ return EXIT_SUCCESS;
+}