summaryrefslogtreecommitdiffstats
path: root/util/test/allocator
diff options
context:
space:
mode:
authorGravatar damitha2010-07-08 06:38:10 +0000
committerGravatar damitha2010-07-08 06:38:10 +0000
commitc8d5aeb5d3048e8a037f1884b59cef8adf7e25b2 (patch)
tree6edd50a5f63708b4c916614809082d9c1090b262 /util/test/allocator
parent4a01960cba446e046d5687279c024fa60b576d85 (diff)
downloadaxis2c-c8d5aeb5d3048e8a037f1884b59cef8adf7e25b2.tar.gz
axis2c-c8d5aeb5d3048e8a037f1884b59cef8adf7e25b2.tar.bz2
Added the simple test suite suggested in AXIS2C-1412
git-svn-id: http://svn.apache.org/repos/asf/axis/axis2/c/core/trunk@961590 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'util/test/allocator')
-rw-r--r--util/test/allocator/Makefile.am3
-rw-r--r--util/test/allocator/allocator_test.c161
2 files changed, 54 insertions, 110 deletions
diff --git a/util/test/allocator/Makefile.am b/util/test/allocator/Makefile.am
index 02dfa27..6c1aaca 100644
--- a/util/test/allocator/Makefile.am
+++ b/util/test/allocator/Makefile.am
@@ -8,6 +8,7 @@ allocator_test_LDADD = \
INCLUDES = -I$(top_builddir)/include \
-I ../../../axiom/include \
- -I ../../../include
+ -I ../../../include \
+ -I ../../../cutest/include
diff --git a/util/test/allocator/allocator_test.c b/util/test/allocator/allocator_test.c
index 70e0bad..a2369d7 100644
--- a/util/test/allocator/allocator_test.c
+++ b/util/test/allocator/allocator_test.c
@@ -2,139 +2,82 @@
#include <axutil_error_default.h>
#include <axiom_node.h>
#include <stdio.h>
+#include <cut_defs.h>
#include "../util/create_env.h"
-int plain_binary_len;
-unsigned char *plain_binary ;
+unsigned char buffer[1024];
-/** @brief read binary
- * read the binary file
- */
-
-int read_binary()
-{
- unsigned char buffer[1024];
- FILE *in = fopen("test","rb");
- FILE *out = fopen("test.doc","w");
- int fwrite_result = 0;
-
- if (!(in && out))
- {
- fprintf (stderr, "unable to open streams\n");
- return -1;
- }
-
- while((plain_binary_len = fread(buffer,1,sizeof(buffer),in)) > 0)
- {
- fwrite_result = fwrite(buffer,1,plain_binary_len,out);
- }
-
- fclose(in);
- fclose(out);
- plain_binary = buffer;
- printf("%s",buffer);
- return plain_binary_len;
-}
-
-/** @brief test base64
- * create duration from values and retrieve values
- */
-axis2_status_t test_base64(axutil_env_t *env)
+void test_base64(axutil_env_t *env)
{
axis2_status_t status = AXIS2_FAILURE;
axutil_base64_binary_t *base64_binary;
axutil_base64_binary_t *plain_base64_binary;
const char *encoded_binary;
- char * get_binary = NULL;
- int binary_len;
+ unsigned char * get_binary = NULL;
+ int plain_binary_len, b_len;
unsigned char * plain_binary = NULL;
- read_binary();
-
+ FILE *in = fopen("test","rb");
+ CUT_ASSERT(in != NULL);
+ if (!in) return;
+
+ plain_binary_len = fread(buffer,1,sizeof(buffer),in);
+ fclose(in);
+ plain_binary = buffer;
+ CUT_ASSERT(plain_binary_len != 0);
+ if (plain_binary_len == 0 ) return;
+
base64_binary = axutil_base64_binary_create(env);
- if(!base64_binary)
- {
- printf("The test axutil_base64_binary_create is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- return AXIS2_FAILURE;
- }
- else
- printf("The test axutil_base64_binary_create is successfull\n");
+ CUT_ASSERT(base64_binary != NULL);
plain_base64_binary = axutil_base64_binary_create_with_plain_binary(env,
plain_binary,
plain_binary_len);
- if(!plain_base64_binary)
- {
- printf("The test axutil_base64_binary_create_with_plain_binary is failed\n");
- axutil_base64_binary_free(plain_base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_create_with_plain_binary is successfull\n");
+ CUT_ASSERT(plain_base64_binary != NULL);
- encoded_binary = axutil_base64_binary_get_encoded_binary(base64_binary,env);
- if(!encoded_binary)
- {
- printf("The test axutil_base64_binary_get_encoded_binary is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_get_encoded_binary is successfull\n");
+ encoded_binary = axutil_base64_binary_get_encoded_binary(plain_base64_binary,env);
+ CUT_ASSERT(encoded_binary != NULL);
status = axutil_base64_binary_set_plain_binary(base64_binary,env,plain_binary,
plain_binary_len);
- if (status == AXIS2_SUCCESS)
- printf("The test axutil_base64_binary_set_plain_binary is successful\n");
- else
- printf("The test axutil_base64_binary_set_plain_binary failed\n") ;
-
- plain_binary = axutil_base64_binary_get_plain_binary(base64_binary,env,&plain_binary_len);
- if(!plain_binary)
- {
- printf("The test axutil_base64_binary_get_plain_binary is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_get_plain_binary is successfull\n" );
-
+ CUT_ASSERT(status == AXIS2_SUCCESS);
+ plain_binary = axutil_base64_binary_get_plain_binary(base64_binary,env,&b_len);
+ CUT_ASSERT(plain_binary != NULL);
status = axutil_base64_binary_set_encoded_binary(base64_binary,env,encoded_binary);
- if (status == AXIS2_SUCCESS)
- printf("The test axutil_base64_binary_set_encoded_binary is successful\n");
- else
- printf("The test axutil_base64_binary_set_encoded_binary failed\n");
-
- get_binary = axutil_base64_binary_get_encoded_binary(base64_binary,env);
- if(!get_binary)
- {
- printf("The test axutil_base64_binary_get_encoded_binary is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_get_encoded_binary is successfull\n");
-
- binary_len = axutil_base64_binary_get_encoded_binary_len(base64_binary,env);
- if(!binary_len)
- {
- printf("The test axutil_base64_binary_get_encoded_binary_len is failed\n");
- axutil_base64_binary_free(base64_binary,env);
- }
- else
- printf("The test axutil_base64_binary_get_encoded_binary_len is successfull\n");
-
- return AXIS2_SUCCESS;
+ CUT_ASSERT(status == AXIS2_SUCCESS);
+ get_binary = (unsigned char *) axutil_base64_binary_get_encoded_binary(base64_binary,env);
+ CUT_ASSERT(get_binary != NULL);
+ b_len = axutil_base64_binary_get_encoded_binary_len(base64_binary,env);
+ CUT_ASSERT(b_len != 0);
+
+ axutil_base64_binary_free(base64_binary, env);
+ base64_binary = axutil_base64_binary_create_with_encoded_binary(env, encoded_binary);
+ CUT_ASSERT(base64_binary != NULL);
+ if (base64_binary != NULL)
+ {
+ int binary_len;
+ get_binary = axutil_base64_binary_get_plain_binary(base64_binary,env, &binary_len);
+ CUT_ASSERT(binary_len == plain_binary_len);
+ CUT_ASSERT(memcmp(get_binary, plain_binary, plain_binary_len) == 0);
+ axutil_base64_binary_free(base64_binary, env);
+ }
+
+ /* To avoid warning of not using cut_ptr_equal */
+ CUT_ASSERT_PTR_EQUAL(NULL, NULL, 0);
+ /* To avoid warning of not using cut_int_equal */
+ CUT_ASSERT_INT_EQUAL(0, 0, 0);
+ /* To avoid warning of not using cut_str_equal */
+ CUT_ASSERT_STR_EQUAL("", "", 0);
+
+ axutil_base64_binary_free(plain_base64_binary, env);
}
int main()
{
- int status = AXIS2_SUCCESS;
- axutil_env_t *env = NULL;
- env = create_environment();
- status = test_base64(env);
-
- if(status == AXIS2_FAILURE)
- {
- printf("build failed");
- }
+ axutil_env_t *env = cut_setup_env("Base64");
+ CUT_ASSERT(env != NULL);
+ test_base64(env);
axutil_env_free(env);
+ CUT_RETURN_ON_FAILURE(-1);
return 0;
}