Convert neethi test to use gtest
diff --git a/neethi/test/Makefile.am b/neethi/test/Makefile.am
index 4a2f4e0..837504d 100644
--- a/neethi/test/Makefile.am
+++ b/neethi/test/Makefile.am
@@ -12,18 +12,23 @@
# 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.
-TESTS =
+TESTS = test
noinst_PROGRAMS = test
+check_PROGRAMS = test
+SUBDIRS =
-test_SOURCES = test.c
+test_SOURCES = test.cc
-INCLUDES = -I$(top_builddir)/include \
- -I ../../util/include \
- -I ../../axiom/include \
- -I ../../include
+AM_CPPFLAGS = -I$(top_builddir)/include \
+ -I ../../util/include \
+ -I ../../axiom/include \
+ -I ../../include \
+ -I $(GTEST_DIR)/include
test_LDADD = $(top_builddir)/src/libneethi.la \
../../axiom/src/om/libaxis2_axiom.la \
../../axiom/src/parser/$(WRAPPER_DIR)/libaxis2_parser.la \
../../util/src/libaxutil.la \
- ../src/libneethi.la
+ ../src/libneethi.la \
+ $(top_builddir)/$(GTEST)/libgtest.a \
+ $(top_builddir)/$(GTEST)/libgtest_main.a
diff --git a/neethi/test/test.c b/neethi/test/test.cc
similarity index 75%
rename from neethi/test/test.c
rename to neethi/test/test.cc
index 2654693..25ffb70 100644
--- a/neethi/test/test.c
+++ b/neethi/test/test.cc
@@ -15,6 +15,8 @@
* limitations under the License.
*/
+#include <gtest/gtest.h>
+
#include <axiom.h>
#include <axutil_utils.h>
#include <axutil_env.h>
@@ -29,88 +31,87 @@
axiom_node_t * node,
const axutil_env_t * env);
-int
-main(
- int argc,
- char **argv)
+class TestNeethi: public ::testing::Test
{
- /*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);*/
- const axutil_env_t *env = NULL;
+
+ protected:
+ void SetUp()
+ {
+ m_allocator = axutil_allocator_init(NULL);
+
+ m_axis_log = axutil_log_create(m_allocator, NULL, NULL);
+ m_error = axutil_error_create(m_allocator);
+
+ m_environment = axutil_env_create_with_error_log(m_allocator, m_error, m_axis_log);
+
+ }
+
+ void TearDown()
+ {
+ axutil_env_free(m_environment);
+ }
+
+
+ axutil_allocator_t *m_allocator = NULL;
+ axutil_env_t *m_environment = NULL;
+ axutil_error_t *m_error = NULL;
+ axutil_log_t *m_axis_log = NULL;
+
+};
+
+
+TEST_F(TestNeethi, test_get_policy)
+{
+
axiom_xml_reader_t *reader = NULL;
axiom_stax_builder_t *builder = NULL;
axiom_document_t *document = NULL;
axiom_node_t *root = NULL;
axiom_element_t *root_ele = NULL;
- env = axutil_env_create_all("test.log", AXIS2_LOG_LEVEL_TRACE);
+ char *filename = "policies/symmetric_binding_policy.xml";
- reader = axiom_xml_reader_create_for_file(env, argv[1], NULL);
+ reader = axiom_xml_reader_create_for_file(m_environment, filename, NULL);
+ ASSERT_NE(reader, nullptr);
- if (!reader)
- {
- AXIS2_ERROR_SET(env->error, AXIS2_ERROR_CREATING_XML_STREAM_READER,
- AXIS2_FAILURE);
- printf("xml reader creation failed\n");
- return 0;
- }
+ builder = axiom_stax_builder_create(m_environment, reader);
+ ASSERT_NE(builder, nullptr);
- builder = axiom_stax_builder_create(env, reader);
- if (!builder)
- {
- axiom_xml_reader_free(reader, env);
- printf("Builder creation failed\n");
- return 0;
- }
- document = axiom_stax_builder_get_document(builder, env);
- if (!document)
- {
- axiom_stax_builder_free(builder, env);
- printf("Document creation failed\n");
- return 0;
- }
+ document = axiom_stax_builder_get_document(builder, m_environment);
+ ASSERT_NE(document, nullptr);
- /*root = axiom_document_get_root_element(document, env); */
- root = axiom_document_build_all(document, env);
- if (!root)
- {
- axiom_stax_builder_free(builder, env);
- return 0;
- }
+ root = axiom_document_get_root_element(document, m_environment);
+ /*root = axiom_document_build_all(document, m_environment); */
+ ASSERT_NE(root, nullptr);
if (root)
{
- if (axiom_node_get_node_type(root, env) == AXIOM_ELEMENT)
+ if (axiom_node_get_node_type(root, m_environment) == AXIOM_ELEMENT)
{
root_ele =
- (axiom_element_t *) axiom_node_get_data_element(root, env);
+ (axiom_element_t *) axiom_node_get_data_element(root, m_environment);
if (root_ele)
{
neethi_policy_t *neethi_policy = NULL;
- neethi_policy = neethi_engine_get_policy(env, root, root_ele);
- if (!neethi_policy)
- {
- printf("Policy Creation fails\n");
- return 0;
- }
+ neethi_policy = neethi_engine_get_policy(m_environment, root, root_ele);
+ ASSERT_NE(neethi_policy, nullptr);
if(neethi_policy)
{
axis2_char_t *id = NULL;
axis2_char_t *name = NULL;
- id = neethi_policy_get_id(neethi_policy, env);
+ id = neethi_policy_get_id(neethi_policy, m_environment);
if(id)
{
printf("Id is : %s\n", id);
}
- name = neethi_policy_get_name(neethi_policy, env);
+ name = neethi_policy_get_name(neethi_policy, m_environment);
if(name)
{
printf("Name is : %s\n", name);
}
- neethi_policy_free(neethi_policy, env);
+ neethi_policy_free(neethi_policy, m_environment);
neethi_policy = NULL;
printf("Successful \n");
@@ -134,16 +135,10 @@
if(builder)
{
- axiom_stax_builder_free(builder, env);
+ axiom_stax_builder_free(builder, m_environment);
builder = NULL;
}
- axutil_env_free((axutil_env_t *)env);
- env = NULL;
-
- printf("Successful\n");
- return 0;
-
}
axis2_status_t AXIS2_CALL