Developer Guide

1 Coding Conventions

Please have a look at Coding Convention document.

2 Unit Tests

To add unit tests for a module there are two steps to be follwed, first add the unit test to the module's test suite, second add the modules test suite to the main unit test suite.

We are using CuTest which is an opensource effort for unit testing.

2.1 Adding a Unit Test to a Module's Unit Test Sutie

Suppose you need to add a new test in the util module. I take for example the unit tests for axis2 stream.

There is two files called util_stream_test.c/.h added into modules/util/test folder.

#include "util_stream_test.h"

void Testaxis2_stream_ops_read(CuTest *tc)

{

char actual[10];

axis2_allocator_t *allocator = axis2_allocator_init(NULL);

axis2_env_t *env = axis2_environment_create(allocator,

NULL, NULL, NULL, NULL);

axis2_stream_read(env->stream, actual, 10);

char *expected = strdup("aaaaaaaaa");

CuAssertStrEquals(tc, expected, actual);

}

In the header file prototype of the funciton included.

Now in util_test.c file add the new function to the test suite

#include "util_test.h"

#include <axis2_allocator.h>

#include <axis2_environment.h>

CuSuite* axis2_utilGetSuite()

{

CuSuite* suite = CuSuiteNew();

SUITE_ADD_TEST(suite, Testaxis2_stream_ops_read);

SUITE_ADD_TEST(suite, Testaxis2_stream_ops_write);

SUITE_ADD_TEST(suite, Testaxis2_log_ops_write);

SUITE_ADD_TEST(suite, Testaxis2_hash_ops_get);

return suite;

}

2.2 Adding the Module test suite to the Main Unit Test Suite

Now make sure that in the main test suite this module test suite is added.

#include <CuTest.h>

#include "../../util/test/util_test.h"

#include "../../common/test/common_test.h"

void RunAllTests(void)

{

CuString *output = CuStringNew();

CuSuite* suite = CuSuiteNew();

CuSuiteAddSuite(suite, axis2_utilGetSuite());

CuSuiteAddSuite(suite, axis2_commonGetSuite());

CuSuiteRun(suite);

CuSuiteSummary(suite, output);

CuSuiteDetails(suite, output);

printf("%s\n", output->buffer);

}

int main(void)

{

RunAllTests();

return 0;

}

When compiled an executable is created in module/util/test to run the module test and in modules/test/unit

to run the main test suite.

3 System Tests

For each module system tests has to be added in modules/test/<module folder>

For example to test the OM we need to add lines in modules/test/om/test_om.c

#include <axis2_stax_ombuilder.h>

#include <axis2_om_document.h>

#include <axis2_om_node.h>

#include <axis2_om_element.h>

#include <axis2_om_text.h>

#include <apr.h>

int test_om_build()

{

READER *red = NULL;

XML_PullParser *parser = NULL;

axis2_om_element_t *ele1=NULL,*ele2=NULL,*ele3 = NULL,*ele4 = NULL;

axis2_stax_om_builder_t *builder = NULL;

axis2_om_document_t *document = NULL;

axis2_om_node_t *node1 = NULL ,*node2 = NULL ,*node3 = NULL ;

FILE

......

......

......

}

int main(void)

{

test_om_build();

test_om_serialize();

}

So for each system test you need to add a new function and call it from main method.