summaryrefslogtreecommitdiffstats
path: root/util/test/util
diff options
context:
space:
mode:
authorGravatar gmcdonald2010-02-13 01:32:03 +0000
committerGravatar gmcdonald2010-02-13 01:32:03 +0000
commit0425aadc78680e53000fd0108b540d6eca048516 (patch)
tree8ec7ab8e015d454c5ec586dfc91e05a2dce1cfc0 /util/test/util
downloadaxis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.gz
axis2c-0425aadc78680e53000fd0108b540d6eca048516.tar.bz2
Moving axis svn, part of TLP move INFRA-2441
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@909681 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'util/test/util')
-rw-r--r--util/test/util/Makefile.am20
-rw-r--r--util/test/util/create_env.c17
-rw-r--r--util/test/util/create_env.h10
-rw-r--r--util/test/util/test_log.c182
-rw-r--r--util/test/util/test_log.h47
-rw-r--r--util/test/util/test_md5.c55
-rw-r--r--util/test/util/test_md5.h27
-rw-r--r--util/test/util/test_string.c84
-rw-r--r--util/test/util/test_thread.c345
-rw-r--r--util/test/util/test_thread.h50
-rw-r--r--util/test/util/test_util.c304
11 files changed, 1141 insertions, 0 deletions
diff --git a/util/test/util/Makefile.am b/util/test/util/Makefile.am
new file mode 100644
index 0000000..4d3a701
--- /dev/null
+++ b/util/test/util/Makefile.am
@@ -0,0 +1,20 @@
+TESTS = test_thread test_util
+noinst_PROGRAMS = test_util test_thread
+noinst_HEADERS = test_log.h \
+ test_thread.h \
+ create_env.h\
+ test_md5.h
+check_PROGRAMS = test_util test_thread
+SUBDIRS =
+test_util_SOURCES = test_util.c test_log.c test_string.c test_md5.c
+test_thread_SOURCES = test_thread.c
+
+test_util_LDADD = \
+ $(top_builddir)/src/libaxutil.la \
+ -lpthread
+
+test_thread_LDADD = \
+ $(top_builddir)/src/libaxutil.la \
+ -lpthread
+
+INCLUDES = -I$(top_builddir)/include
diff --git a/util/test/util/create_env.c b/util/test/util/create_env.c
new file mode 100644
index 0000000..5a26182
--- /dev/null
+++ b/util/test/util/create_env.c
@@ -0,0 +1,17 @@
+#include "create_env.h"
+
+axutil_env_t * create_environment()
+{
+ axutil_allocator_t *allocator = NULL;
+ axutil_log_t *log = NULL;
+ axutil_error_t *error = NULL;
+ axutil_env_t *env = NULL;
+ allocator = axutil_allocator_init(NULL);
+ log = axutil_log_create(allocator, NULL, NULL);
+
+ error = axutil_error_create(allocator);
+ env = axutil_env_create_with_error_log(allocator, error, log);
+ return env;
+}
+
+
diff --git a/util/test/util/create_env.h b/util/test/util/create_env.h
new file mode 100644
index 0000000..e3ea7b8
--- /dev/null
+++ b/util/test/util/create_env.h
@@ -0,0 +1,10 @@
+#include <axutil_log_default.h>
+#include <axutil_error_default.h>
+#include <stdio.h>
+#include <axutil_env.h>
+
+axutil_env_t * create_environment();
+
+
+
+
diff --git a/util/test/util/test_log.c b/util/test/util/test_log.c
new file mode 100644
index 0000000..4539b4e
--- /dev/null
+++ b/util/test/util/test_log.c
@@ -0,0 +1,182 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 <stdio.h>
+#include <axutil_error_default.h>
+#include <axutil_log.h>
+#include <axutil_log_default.h>
+#include <axutil_allocator.h>
+#include <test_log.h>
+#include <string.h>
+const axutil_env_t *
+create_env_with_error_log(
+ )
+{
+ axutil_allocator_t *allocator = axutil_allocator_init(NULL);
+ if (!allocator)
+ {
+ printf("allocator is NULL\n");
+ return NULL;
+ }
+ axutil_error_t *error = axutil_error_create(allocator);
+ if (!error)
+ {
+ printf("cannot create error\n");
+ return NULL;
+ }
+
+ axutil_log_t *log22 = axutil_log_create(allocator, NULL, NULL);
+ if (!log22)
+ {
+ printf("cannot create log\n");
+ return NULL;
+ }
+ /*
+ * allow all types of logs
+ */
+ log22->level = AXIS2_LOG_LEVEL_DEBUG;
+ /* log22->enabled = 0; */
+ const axutil_env_t *env =
+ axutil_env_create_with_error_log(allocator, error, log22);
+ if (!env)
+ {
+ printf("cannot create env with error and log\n");
+ return NULL;
+ }
+ return env;
+}
+
+void
+test_axutil_log_write(
+ const axutil_env_t * env)
+{
+ char msg[32];
+ printf("\n####start of test_axutil_log_write\n\n");
+ strcpy(msg, "abcd test123");
+ printf("\n####end of test_axutil_log_write\n\n");
+}
+
+void
+test_axutil_log_debug(
+ const axutil_env_t * env)
+{
+ printf("\n####start of test_axutil_log_degug\n\n");
+ env->log->level = AXIS2_LOG_LEVEL_DEBUG;
+ AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "log_debug test %s %d", "foo", 1);
+ printf("\n####end of test_axutil_log_debug\n\n");
+}
+
+void
+test_axutil_log_debug_off(
+ const axutil_env_t * env)
+{
+ printf("\n####start of test_axutil_log_degug_off\n\n");
+ env->log->level = AXIS2_LOG_LEVEL_ERROR; /*log only ERROR's and CRITICAL's */
+ AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI,
+ "this should not be logged log_debug test %s %d", "foo", 1);
+ printf("\n####end of test_axutil_log_debug_off\n\n");
+}
+
+void
+test_axutil_log_info(
+ const axutil_env_t * env)
+{
+ printf("\n####start of test_axutil_log_info\n\n");
+ env->log->level = AXIS2_LOG_LEVEL_DEBUG;
+ AXIS2_LOG_INFO(env->log, "log_info test %s %d", "foo", 1);
+ printf("\n####end of test_axutil_log_info\n\n");
+}
+
+void
+test_axutil_log_info_off(
+ const axutil_env_t * env)
+{
+ printf("\n####start of test_axutil_log_info_off\n\n");
+ env->log->level = AXIS2_LOG_LEVEL_ERROR; /*log only ERROR's and CRITICAL's */
+ AXIS2_LOG_INFO(env->log, "this should not be logged log_info test %s %d",
+ "foo", 1);
+ printf("\n####end of test_axutil_log_info_off\n\n");
+}
+
+void
+test_axutil_log_warning(
+ const axutil_env_t * env)
+{
+ printf("\n####start of test_axutil_log_warning\n\n");
+ env->log->level = AXIS2_LOG_LEVEL_DEBUG;
+ AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "log_warning test %s %d", "foo",
+ 1);
+ printf("\n####end of test_axutil_log_warning\n\n");
+}
+
+void
+test_axutil_log_warning_off(
+ const axutil_env_t * env)
+{
+ printf("\n####start of test_axutil_log_warning_off\n\n");
+ env->log->level = AXIS2_LOG_LEVEL_ERROR; /*log only ERROR's and CRITICAL's */
+ AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI,
+ "this should not be logged log_warning test %s %d", "foo",
+ 1);
+ printf("\n####end of test_axutil_log_warning_off\n\n");
+}
+
+/*no need to sent log level, should always log*/
+void
+test_axutil_log_error(
+ const axutil_env_t * env)
+{
+ printf("\n####start of test_axutil_log_error\n\n");
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "log_error test %s %d", "foo", 1);
+ printf("\n####end of test_axutil_log_error\n\n");
+}
+
+/*no need to sent log level, should always log*/
+void
+test_axutil_log_critical(
+ const axutil_env_t * env)
+{
+ printf("\n####start of test_axutil_log_critical\n\n");
+ AXIS2_LOG_CRITICAL(env->log, AXIS2_LOG_SI, "log_critical test %s %d", "foo",
+ 1);
+ printf("\n####end of test_axutil_log_critical\n\n");
+}
+
+void
+run_test_log(
+ )
+{
+ printf("\n####start of run_test_log test suite\n\n");
+ const axutil_env_t *env = create_env_with_error_log();
+ if (!env)
+ return;
+ test_axutil_log_write(env);
+ test_axutil_log_debug(env);
+ test_axutil_log_debug_off(env);
+
+ test_axutil_log_info(env);
+ test_axutil_log_info_off(env);
+
+ test_axutil_log_warning(env);
+ test_axutil_log_warning_off(env);
+
+ test_axutil_log_error(env);
+
+ test_axutil_log_critical(env);
+ printf("\n####end of run_test_log test suite \n\n");
+}
diff --git a/util/test/util/test_log.h b/util/test/util/test_log.h
new file mode 100644
index 0000000..d88669e
--- /dev/null
+++ b/util/test/util/test_log.h
@@ -0,0 +1,47 @@
+
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You 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.
+*/
+
+#ifndef _TEST_LOG_H_
+#define _TEST_LOG_H_
+
+#include <axutil_env.h>
+
+void run_test_log(
+);
+const axutil_env_t *create_env_with_error_log(
+);
+void test_axutil_log_write(
+ const axutil_env_t * env);
+void test_axutil_log_debug(
+ const axutil_env_t * env);
+void test_axutil_log_debug_off(
+ const axutil_env_t * env);
+void test_axutil_log_info(
+ const axutil_env_t * env);
+void test_axutil_log_info_off(
+ const axutil_env_t * env);
+void test_axutil_log_warning(
+ const axutil_env_t * env);
+void test_axutil_log_warning_off(
+ const axutil_env_t * env);
+void test_axutil_log_error(
+ const axutil_env_t * env);
+void test_axutil_log_critical(
+ const axutil_env_t * env);
+
+#endif /* _TEST_LOG_H_ */
diff --git a/util/test/util/test_md5.c b/util/test/util/test_md5.c
new file mode 100644
index 0000000..7c360ce
--- /dev/null
+++ b/util/test/util/test_md5.c
@@ -0,0 +1,55 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 <test_md5.h>
+#include <stdio.h>
+#include <axutil_string.h>
+#include <axutil_md5.h>
+
+/* Digests a string and prints the result.
+ */
+static void MDString (char * string, const axutil_env_t * env)
+{
+ axutil_md5_ctx_t * context;
+ unsigned char digest[16];
+ unsigned int i;
+ unsigned int len = axutil_strlen(string);
+
+ context = axutil_md5_ctx_create(env);
+ axutil_md5_update(context, env, string, len);
+ axutil_md5_final(context, env, digest);
+ axutil_md5_ctx_free(context, env);
+
+ printf ("MD%d (\"%s\") = ", 5, string);
+ for (i = 0; i < 16; i++)
+ printf ("%02x", digest[i]);
+ printf ("\n");
+}
+
+void test_md5(const axutil_env_t *env)
+{
+ printf ("\nMD5 test suite:\n");
+ printf ("test confirmation: Rivest, R., \"The MD5 Message-Digest Algorithm\", RFC 1321, April 1992.\n");
+ MDString ("", env);
+ MDString ("a", env);
+ MDString ("abc", env);
+ MDString ("message digest", env);
+ MDString ("abcdefghijklmnopqrstuvwxyz", env);
+ MDString ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", env);
+ MDString ("12345678901234567890123456789012345678901234567890123456789012345678901234567890", env);
+}
diff --git a/util/test/util/test_md5.h b/util/test/util/test_md5.h
new file mode 100644
index 0000000..215a096
--- /dev/null
+++ b/util/test/util/test_md5.h
@@ -0,0 +1,27 @@
+
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You 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.
+*/
+
+#ifndef _TEST_MD5_H_
+#define _TEST_MD5_H_
+
+#include <axutil_env.h>
+
+void test_md5(
+ const axutil_env_t * env);
+
+#endif /* _TEST_MD5_H_ */
diff --git a/util/test/util/test_string.c b/util/test/util/test_string.c
new file mode 100644
index 0000000..d4d7bbc
--- /dev/null
+++ b/util/test/util/test_string.c
@@ -0,0 +1,84 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 <stdio.h>
+#include <axutil_error_default.h>
+#include <axutil_log.h>
+#include <axutil_string.h>
+
+void
+test_strltrim(
+ const axutil_env_t * env)
+{
+ axis2_char_t *s = axutil_strdup(env, " abcd efgh ");
+ axis2_char_t *trimmed = NULL;
+ trimmed = axutil_strltrim(env, s, " \t\r\n");
+ if (0 == axutil_strcmp(trimmed, "abcd efgh "))
+ printf("axutil_strltrim successful\n");
+ else
+ printf("axutil_strltrim failed [%s]\n", trimmed);
+ if (trimmed)
+ AXIS2_FREE(env->allocator, trimmed);
+ if (s)
+ AXIS2_FREE(env->allocator, s);
+}
+
+void
+test_strrtrim(
+ const axutil_env_t * env)
+{
+ axis2_char_t *s = axutil_strdup(env, "abcd efgh ");
+ axis2_char_t *trimmed = NULL;
+ trimmed = axutil_strrtrim(env, s, " \t\r\n");
+ if (0 == axutil_strcmp(trimmed, " abcd efgh"))
+ printf("axutil_strrtrim successful\n");
+ else
+ printf("axutil_strrtrim failed [%s]\n", trimmed);
+ if (trimmed)
+ AXIS2_FREE(env->allocator, trimmed);
+ if (s)
+ AXIS2_FREE(env->allocator, s);
+}
+
+void
+test_strtrim(
+ const axutil_env_t * env)
+{
+ axis2_char_t *s = axutil_strdup(env, " abcd efgh ");
+ axis2_char_t *trimmed = NULL;
+ trimmed = axutil_strtrim(env, s, " \t\r\n");
+ if (0 == axutil_strcmp(trimmed, "abcd efgh"))
+ printf("axutil_strtrim successful\n");
+ else
+ printf("axutil_strtrim failed [%s]\n", trimmed);
+ if (trimmed)
+ AXIS2_FREE(env->allocator, trimmed);
+ if (s)
+ AXIS2_FREE(env->allocator, s);
+}
+
+void
+run_test_string(
+ axutil_env_t * env)
+{
+ if (!env)
+ return;
+ test_strltrim(env);
+ test_strrtrim(env);
+ test_strtrim(env);
+}
diff --git a/util/test/util/test_thread.c b/util/test/util/test_thread.c
new file mode 100644
index 0000000..e10b5b7
--- /dev/null
+++ b/util/test/util/test_thread.c
@@ -0,0 +1,345 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 <stdio.h>
+#include <string.h>
+#include <axutil_error_default.h>
+#include <axutil_log.h>
+#include <axutil_log_default.h>
+#include <axutil_allocator.h>
+#include <axutil_utils.h>
+#include "test_thread.h"
+#include <unistd.h>
+
+const axutil_env_t *env = NULL;
+static axutil_thread_mutex_t *thread_lock = NULL;
+static axutil_thread_once_t *control = NULL;
+static int x = 0;
+static int value = 0;
+
+static axutil_thread_t *t1 = NULL;
+static axutil_thread_t *t2 = NULL;
+
+/*for detach tests*/
+static axutil_thread_t *t3 = NULL;
+static axutil_thread_t *t4 = NULL;
+
+void
+init_func(
+ void)
+{
+ value++;
+}
+
+void
+thread_init(
+ const axutil_env_t * env)
+{
+ axutil_allocator_t *allocator = NULL;
+
+ allocator = env->allocator;
+
+ control = axutil_thread_once_init(allocator);
+
+ if (control)
+ printf("success - thread_init - axutil_thread_once_init \n");
+ else
+ printf("failure - thread_init - axutil_thread_once_init \n");
+
+ thread_lock =
+ axutil_thread_mutex_create(allocator, AXIS2_THREAD_MUTEX_DEFAULT);
+
+ if (thread_lock)
+ printf("success - thread_init - axutil_thread_mutex_create \n");
+ else
+ printf("failure - thread_init - axutil_thread_mutex_create \n");
+}
+
+void *AXIS2_CALL
+test_function(
+ axutil_thread_t * td,
+ void *param)
+{
+ int i;
+ i = *((int *) param);
+ printf("thread data = %d \n", i);
+
+ axutil_thread_once(control, init_func);
+
+ axutil_thread_mutex_lock(thread_lock);
+ printf("x = %d \n", ++x);
+ axutil_thread_mutex_unlock(thread_lock);
+
+ /*axutil_thread_exit(td, env->allocator); */
+
+ return (void *) 1;
+}
+
+void
+test_axutil_thread_create(
+ const axutil_env_t * env)
+{
+ axis2_status_t rv = AXIS2_FAILURE;
+ axutil_allocator_t *allocator = NULL;
+ int *i = NULL,
+ *j = NULL;
+
+ allocator = env->allocator;
+ i = AXIS2_MALLOC(allocator, sizeof(int));
+ *i = 5;
+ t1 = axutil_thread_create(allocator, NULL, test_function, (void *) i);
+
+ if (t1)
+ printf("success - test_axutil_thread_create - axutil_thread_create \n");
+ else
+ printf("failure - test_axutil_thread_create - axutil_thread_create \n");
+
+ j = AXIS2_MALLOC(allocator, sizeof(int));
+ *j = 25;
+
+ t2 = axutil_thread_create(allocator, NULL, test_function, (void *) j);
+
+ if (t2)
+ printf("success - test_axutil_thread_create - axutil_thread_create \n");
+ else
+ printf("failure - test_axutil_thread_create - axutil_thread_create \n");
+
+ rv = axutil_thread_join(t1);
+
+ if (AXIS2_SUCCESS == rv)
+ printf("success - test_axutil_thread_create - axutil_thread_join \n");
+ else
+ printf
+ ("failure - thread_init - test_axutil_thread_create - axutil_thread_join \n");
+
+ rv = axutil_thread_join(t2);
+
+ if (AXIS2_SUCCESS == rv)
+ printf("success - test_axutil_thread_create - axutil_thread_join \n");
+ else
+ printf
+ ("failure - thread_init - test_axutil_thread_create - axutil_thread_join \n");
+
+}
+
+void *AXIS2_CALL
+test_function2(
+ axutil_thread_t * td,
+ void *param)
+{
+ printf("thread \n");
+ /*axutil_thread_exit(td, env->allocator); */
+
+ return (void *) 1;
+}
+
+void
+test_axutil_thread_detach(
+ const axutil_env_t * env)
+{
+ axutil_threadattr_t *attr = NULL;
+ axutil_allocator_t *allocator = NULL;
+ axis2_status_t rv = AXIS2_FAILURE;
+
+ allocator = env->allocator;
+ attr = axutil_threadattr_create(allocator);
+ if (!attr)
+ {
+ printf("failure - test_axutil_thread_detach\n");
+ return;
+ }
+ rv = axutil_threadattr_detach_set(attr, 1);
+
+ if (AXIS2_SUCCESS != rv)
+ {
+ printf("failure - test_axutil_thread_detach\n");
+ return;
+ }
+ t3 = axutil_thread_create(allocator, attr, test_function2, NULL);
+
+ if (!t3)
+ {
+ printf("failure - test_axutil_thread_detach\n");
+ return;
+ }
+
+ /*
+ * thread is already detached - should return AXIS2_FAILURE
+ */
+ rv = axutil_thread_detach(t3);
+
+ if (AXIS2_FAILURE != rv)
+ {
+ printf("failure - test_axutil_thread_detach\n");
+ return;
+ }
+
+ /*
+ * thread is already detached - should return AXIS2_FAILURE
+ * cannot join detached threads
+ */
+ /*rv = axutil_thread_join(t3); */
+ if (AXIS2_FAILURE != rv)
+ {
+ printf("failure - test_axutil_thread_detach\n");
+ return;
+ }
+ printf("success - test_axutil_thread_detach\n");
+}
+
+void
+test_axutil_thread_detach2(
+ const axutil_env_t * env)
+{
+ axutil_threadattr_t *attr = NULL;
+ axutil_allocator_t *allocator = NULL;
+ axis2_status_t rv = AXIS2_FAILURE;
+
+ allocator = env->allocator;
+ attr = axutil_threadattr_create(allocator);
+ if (!attr)
+ {
+ printf("failure - test_axutil_thread_detach2\n");
+ return;
+ }
+
+ t4 = axutil_thread_create(allocator, attr, test_function2, NULL);
+
+ if (!t4)
+ {
+ printf("failure - test_axutil_thread_detach2\n");
+ return;
+ }
+
+ /*
+ * thread is not detached yet - should return AXIS2_SUCCESS
+ */
+ rv = axutil_thread_detach(t4);
+
+ if (AXIS2_SUCCESS != rv)
+ {
+ printf("failure - test_axutil_thread_detach\n");
+ return;
+ }
+
+ /*
+ * thread is already detached - should return AXIS2_FAILURE
+ * cannot join detached threads
+ */
+ /*rv = axutil_thread_join(t4); */
+ if (AXIS2_FAILURE != rv)
+ {
+ printf("failure - test_axutil_thread_detach2\n");
+ return;
+ }
+ printf("success - test_axutil_thread_detach2\n");
+}
+
+void
+check_locks(
+ )
+{
+ if (2 == x)
+ printf("success - check_locks \n");
+ else
+ printf("failure - check_locks \n");
+
+}
+
+void
+check_thread_once(
+ )
+{
+ if (1 == value)
+ printf("success - check_thread_once \n");
+ else
+ printf("failure - check_thread_once \n");
+}
+
+void
+run_test_thread(
+ const axutil_env_t * env)
+{
+ thread_init(env);
+ test_axutil_thread_create(env);
+ check_locks();
+ check_thread_once();
+ test_axutil_thread_detach(env);
+ test_axutil_thread_detach2(env);
+
+#if defined (WIN32)
+ Sleep(1000); /*to give time for detached threads to execute */
+#else
+ sleep(2);
+#endif
+
+ axutil_thread_mutex_destroy(thread_lock);
+}
+
+const axutil_env_t *
+create_env_with_error_log(
+ )
+{
+ axutil_error_t *error = NULL;
+ axutil_log_t *log22 = NULL;
+ const axutil_env_t *env = NULL;
+ axutil_allocator_t *allocator = axutil_allocator_init(NULL);
+ if (!allocator)
+ {
+ printf("allocator is NULL\n");
+ return NULL;
+ }
+ error = axutil_error_create(allocator);
+ if (!error)
+ {
+ printf("cannot create error\n");
+ return NULL;
+ }
+
+ log22 = axutil_log_create(allocator, NULL, "test123.log");
+ if (!log22)
+ {
+ printf("cannot create log\n");
+ return NULL;
+ }
+ /*
+ * allow all types of logs
+ */
+ log22->level = AXIS2_LOG_LEVEL_DEBUG;
+ /* log22->enabled = 0; */
+ env = axutil_env_create_with_error_log(allocator, error, log22);
+ if (!env)
+ {
+ printf("cannot create env with error and log\n");
+ return NULL;
+ }
+ return env;
+}
+
+int
+main(
+ void)
+{
+ env = create_env_with_error_log();
+
+ if (!env)
+ return -1;
+ run_test_thread(env);
+
+ return 0;
+}
diff --git a/util/test/util/test_thread.h b/util/test/util/test_thread.h
new file mode 100644
index 0000000..b006b3f
--- /dev/null
+++ b/util/test/util/test_thread.h
@@ -0,0 +1,50 @@
+
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You 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.
+*/
+
+#ifndef TEST_LOG_H
+#define TEST_LOG_H
+
+#include <axutil_env.h>
+#include <axutil_thread.h>
+
+void init_func(
+ void);
+void thread_init(
+ const axutil_env_t * env);
+void *AXIS2_CALL
+test_function(
+ axutil_thread_t * td,
+ void *param);
+void test_axutil_thread_create(
+ const axutil_env_t * env);
+void *AXIS2_CALL
+test_function2(
+ axutil_thread_t * td,
+ void *param);
+void test_axutil_thread_detach(
+ const axutil_env_t * env);
+void test_axutil_thread_detach2(
+ const axutil_env_t * env);
+void check_locks(
+);
+
+/*call this method from main*/
+void run_test_thread(
+ const axutil_env_t * env);
+
+#endif
diff --git a/util/test/util/test_util.c b/util/test/util/test_util.c
new file mode 100644
index 0000000..dd37710
--- /dev/null
+++ b/util/test/util/test_util.c
@@ -0,0 +1,304 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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 <stdio.h>
+#include <axutil_hash.h>
+#include <axutil_string.h>
+#include <axutil_error_default.h>
+#include <axutil_array_list.h>
+#include <platforms/axutil_platform_auto_sense.h>
+#include <axutil_uuid_gen.h>
+#include <axutil_log_default.h>
+#include <axutil_log.h>
+#include <axutil_dir_handler.h>
+#include <axutil_file.h>
+#include "axutil_log.h"
+#include "test_thread.h"
+#include <test_log.h>
+
+typedef struct a
+{
+ axis2_char_t *value;
+}
+a;
+
+const axutil_env_t *
+test_init(
+ )
+{
+ axutil_allocator_t *allocator = axutil_allocator_init(NULL);
+ axutil_error_t *error = axutil_error_create(allocator);
+ const axutil_env_t *env = axutil_env_create_with_error(allocator, error);
+ return env;
+}
+
+int
+test_hash_get(
+ const axutil_env_t * env)
+{
+ axutil_hash_t *ht;
+ a *a1,
+ *a2,
+ *a3,
+ *a4;
+
+ axutil_hash_index_t *i = 0;
+ void *v = NULL;
+
+ char *key1 = "key1";
+ char *key2 = "key2";
+ char *key3 = "key3";
+ char *key4 = "key4";
+ int cnt = 0;
+ axis2_char_t ***rettt = NULL;
+ axis2_status_t stat = AXIS2_FAILURE;
+ stat = axutil_parse_rest_url_for_params(env, "ech{a}tring", "/echoString?text=Hello%20World%21", &cnt, &rettt);
+ stat = axutil_parse_rest_url_for_params(env, "{a}ny/mor/sum", "echoStringmany/mor/sum", &cnt, &rettt);
+/* rettt = axutil_parse_rest_url_for_params(env, "echoString/{a}re/{b}?", "/echoString/more/sum/?");
+ rettt = axutil_parse_rest_url_for_params(env, "/ech{c}tring{a}more/{b}/", "/echoStringma/nymore/sum?");
+ rettt = axutil_parse_rest_url_for_params(env, "echoString/{a}/more/{b}?{c}", "echoString/many/more/sum/");
+ rettt = axutil_parse_rest_url_for_params(env, "echoString/{a}/more/{b}/?", "echoString/many/more/sum/?test=");*/
+
+ a1 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ a2 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ a3 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ a4 = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+
+ a1->value = axutil_strdup(env, "value1");
+ a2->value = axutil_strdup(env, "value2");
+ a3->value = axutil_strdup(env, "value3");
+ a4->value = axutil_strdup(env, "value4");
+
+ ht = axutil_hash_make(env);
+
+ axutil_hash_set(ht, key1, AXIS2_HASH_KEY_STRING, a1);
+ axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, a2);
+ axutil_hash_set(ht, key3, AXIS2_HASH_KEY_STRING, a3);
+ axutil_hash_set(ht, key4, AXIS2_HASH_KEY_STRING, a4);
+
+ axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, NULL);
+ axutil_hash_set(ht, key2, AXIS2_HASH_KEY_STRING, a2);
+ for (i = axutil_hash_first(ht, env); i; i = axutil_hash_next(env, i))
+ {
+ axutil_hash_this(i, NULL, NULL, &v);
+ printf("\n %s \n", ((a *) v)->value);
+ }
+
+ printf("\n demo get %s ",
+ ((a *) axutil_hash_get(ht, key1, AXIS2_HASH_KEY_STRING))->value);
+
+ printf("\n demo get %s ",
+ ((a *) axutil_hash_get(ht, key2, AXIS2_HASH_KEY_STRING))->value);
+
+ printf("\n demo get %s ",
+ ((a *) axutil_hash_get(ht, key3, AXIS2_HASH_KEY_STRING))->value);
+
+ printf("\n demo get %s \n",
+ ((a *) axutil_hash_get(ht, key4, AXIS2_HASH_KEY_STRING))->value);
+
+ axutil_hash_free(ht, env);
+ AXIS2_FREE(env->allocator, a1->value);
+ AXIS2_FREE(env->allocator, a2->value);
+ AXIS2_FREE(env->allocator, a3->value);
+ AXIS2_FREE(env->allocator, a4->value);
+ AXIS2_FREE(env->allocator, a1);
+ AXIS2_FREE(env->allocator, a2);
+ AXIS2_FREE(env->allocator, a3);
+ AXIS2_FREE(env->allocator, a4);
+ return 0;
+}
+
+void
+test_axutil_dir_handler_list_service_or_module_dirs(
+ )
+{
+ int i,
+ isize;
+ axutil_file_t *file = NULL;
+ axis2_char_t *filename = NULL;
+ axutil_allocator_t *allocator = axutil_allocator_init(NULL);
+ axutil_error_t *error = axutil_error_create(allocator);
+ axutil_log_t *log = axutil_log_create(allocator, NULL, NULL);
+ const axutil_env_t *env =
+ axutil_env_create_with_error_log(allocator, error, log);
+
+ axis2_char_t *pathname = axutil_strdup(env, "/tmp/test/");
+
+ axutil_array_list_t *arr_folders =
+ axutil_dir_handler_list_service_or_module_dirs(env, pathname);
+ if (arr_folders == NULL)
+ {
+ printf("List of folders is NULL\n");
+ return;
+ }
+
+ isize = axutil_array_list_size(arr_folders, env);
+ printf("Folder array size = %d \n", isize);
+
+ for (i = 0; i < isize; ++i)
+ {
+ file = (axutil_file_t *) axutil_array_list_get(arr_folders, env, i);
+ filename = axutil_file_get_name(file, env);
+ printf("filename = %s \n", filename);
+ }
+ printf
+ ("----end of test_axutil_dir_handler_list_service_or_module_dirs----\n");
+
+}
+
+/**
+ * This test is intended to test whether given two files are equal or not.
+ * Spaces and new lines are ignored in comparing
+ */
+int
+test_file_diff(
+ const axutil_env_t * env)
+{
+ /* axis2_char_t *expected_file_name = axutil_strdup("expected", env);
+ axis2_char_t *actual_file_name = axutil_strdup("actual", env); */
+ return 0;
+}
+
+void
+test_array_list(
+ const axutil_env_t * env)
+{
+ axutil_array_list_t *al;
+ a *entry = NULL;
+ int size;
+
+ al = axutil_array_list_create(env, 1);
+ printf("list size %d\n", axutil_array_list_size(al, env));
+
+ entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ entry->value = axutil_strdup(env, "value1");
+ axutil_array_list_add(al, env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ entry->value = axutil_strdup(env, "value2");
+ axutil_array_list_add(al, env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ entry->value = axutil_strdup(env, "value3");
+ axutil_array_list_add(al, env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ entry->value = axutil_strdup(env, "value4");
+ axutil_array_list_add(al, env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ entry->value = axutil_strdup(env, "value5");
+ axutil_array_list_add(al, env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ entry->value = axutil_strdup(env, "value6");
+ axutil_array_list_add(al, env, (void *) entry);
+
+ entry = (a *) AXIS2_MALLOC(env->allocator, sizeof(a));
+ entry->value = axutil_strdup(env, "value7");
+ axutil_array_list_set(al, env, 3, (void *) entry);
+ axutil_array_list_remove(al, env, 2);
+
+ entry = (a *) axutil_array_list_get(al, env, 0);
+ printf("entry->value:%s\n", entry->value);
+
+ entry = (a *) axutil_array_list_get(al, env, 2);
+ printf("entry->value:%s\n", entry->value);
+ size = axutil_array_list_size(al, env);
+ printf("list size %d\n", axutil_array_list_size(al, env));
+
+}
+
+void
+test_uuid_gen(
+ const axutil_env_t * env)
+{
+ char *uuid = NULL;
+ printf("starting uuid_gen test...\n");
+ uuid = axutil_uuid_gen(env);
+ printf("Generated UUID 1:%s\n", uuid);
+ AXIS2_FREE(env->allocator, uuid);
+ uuid = axutil_uuid_gen(env);
+ printf("Generated UUID 2:%s\n", uuid);
+ AXIS2_FREE(env->allocator, uuid);
+ printf("finished uuid_gen test...\n");
+}
+
+void
+test_log_write(
+ )
+{
+ char msg[10];
+ printf("start of test_log_write\n\n");
+ axutil_allocator_t *allocator = axutil_allocator_init(NULL);
+ if (!allocator)
+ {
+ printf("allocator is NULL\n");
+ return;
+ }
+ axutil_error_t *error = axutil_error_create(allocator);
+ if (!error)
+ {
+ printf("cannot create error\n");
+ return;
+ }
+ axutil_log_t *log22 = axutil_log_create(allocator, NULL, NULL);
+ if (!log22)
+ {
+ printf("cannot create log\n");
+ return;
+ }
+ log22->level = AXIS2_LOG_LEVEL_DEBUG;
+
+ const axutil_env_t *env =
+ axutil_env_create_with_error_log(allocator, error, log22);
+ if (!env)
+ {
+ printf("cannot create env with error and log\n");
+ return;
+ }
+ strcpy(msg, "abcd test123");
+
+ AXIS2_LOG_CRITICAL(env->log, AXIS2_LOG_SI, "log1 %s", "test1");
+ AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "log2 %d", 2);
+ AXIS2_LOG_WARNING(env->log, AXIS2_LOG_SI, "log3 %s", "test3");
+ AXIS2_LOG_INFO(env->log, AXIS2_LOG_SI, "log4 %s %s", "info1", "info2");
+ AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "log5 %s %d", "test", 5);
+ printf("end of test_log_write \n\n");
+
+}
+
+int
+main(
+ void)
+{
+ const axutil_env_t *env = test_init();
+ test_hash_get(env);
+ test_file_diff(env);
+ test_array_list(env);
+ test_uuid_gen(env);
+ test_md5(env);
+ run_test_log();
+ run_test_string(env);
+ test_axutil_dir_handler_list_service_or_module_dirs();
+ axutil_allocator_t *allocator = env->allocator;
+
+/* axutil_env_free(env);*/
+ axutil_allocator_free(allocator);
+ return 0;
+}