Debugged type-decl de-serialization

* src/abg-ir.cc (namespace_decl::~namespace_decl): Add this
	missing virtual constructor definition.
	* src/abg-reader.cc (read_context::{get_cur_decl,pop_decl}):
	Return a null pointer when the decls stack is empty.
	(update_read_context): Don't try to de-reference a NULL cur_decl.
	(read_input): Don't try to poke at file validity here.  What was I
	thinking.  Really test for advance_cursor to return 1, expressing
	success.
	* src/abg-reader.h (read_file):  Fix style.
	* Makefile.am: Add tests sub-directory.
	* configure.ac: Build with debugging-friendly options if the
	ABIGAIL_DEBUG env variable is set.  Generate tests/Makefile.
	* tests/Makefile.am: New file.
	* tests/test-read-write.cc: Likewise.
	* tests/test-utils.{h,cc}: Likewise.
	* tests/data/test-read-write/input0.xml: Likewise.
This commit is contained in:
Dodji Seketeli 2013-03-21 23:42:41 +01:00
parent a80b09f912
commit fc27d10cee
10 changed files with 127 additions and 9 deletions

View File

@ -1,4 +1,4 @@
SUBDIRS = src
SUBDIRS = src tests
ACLOCAL_AMFLAGS = -I m4 ${ACLOCAL_FLAGS}
headers = config.h

View File

@ -37,7 +37,15 @@ ABIGAIL_LIBS="$ABIGAIL_DEPS_LIBS"
AC_SUBST(ABIGAIL_CFLAGS)
AC_SUBST(ABIGAIL_LIBS)
if test x$ABIGAIL_DEVEL != x; then
DEVEL_CFLAGS="-g -Wall -Wextra -Werror"
DEVEL_CXXFLAGS="-g -Wall -Wextra -Werror"
CFLAGS=$DEVEL_CFLAGS
CXXFLAGS=$DEVEL_CXXFLAGS
fi
AC_CONFIG_FILES([Makefile
src/Makefile])
src/Makefile
tests/Makefile])
AC_OUTPUT

View File

@ -332,6 +332,11 @@ namespace_decl::namespace_decl(const std::string& name,
: scope_decl(KIND_NAMESPACE_DECL, name, context, locus)
{
}
namespace_decl::~namespace_decl()
{
}
// </namespace_decl>
}//end namespace abigail

View File

@ -82,6 +82,9 @@ public:
shared_ptr<decl_base>
get_cur_decl() const
{
if (m_decls_stack.empty())
return shared_ptr<decl_base>(static_cast<decl_base*>(0));
return m_decls_stack.top();
}
@ -94,6 +97,9 @@ public:
shared_ptr<decl_base>
pop_decl()
{
if (m_decls_stack.empty())
return shared_ptr<decl_base>(static_cast<decl_base*>(0));
shared_ptr<decl_base> t = get_cur_decl();
m_decls_stack.pop();
return t;
@ -164,7 +170,7 @@ update_read_context(read_context& ctxt)
shared_ptr<decl_base> cur_decl = ctxt.get_cur_decl();
if (dynamic_cast<scope_decl*> (cur_decl.get()))
ctxt.set_cur_scope(dynamic_pointer_cast<scope_decl>(cur_decl));
else
else if (cur_decl)
ctxt.set_cur_scope(cur_decl->get_scope());
}
@ -203,9 +209,6 @@ read_input(read_context& ctxt,
if (!reader)
return false;
if (!xmlTextReaderIsValid(reader.get()))
return false;
// The document must start with the abi-instr node.
int status = advance_cursor (ctxt);
if (status != 1 || !xmlStrEqual (XML_READER_GET_NODE_NAME(reader).get(),
@ -213,7 +216,7 @@ read_input(read_context& ctxt,
return false;
for (status = advance_cursor(ctxt);
status;
status == 1;
status = advance_cursor(ctxt))
{
xmlReaderTypes node_type = XML_READER_GET_NODE_TYPE(reader);

View File

@ -8,8 +8,8 @@ namespace abigail
{
namespace reader
{
bool read_file(const std::string& file_path,
abi_corpus& abi_corpus);
bool read_file(const std::string& file_path,
abi_corpus& abi_corpus);
}// end namespace reader
}// end namespace abigail

24
tests/Makefile.am Normal file
View File

@ -0,0 +1,24 @@
h=$(abs_srcdir)
hb=$(abs_builddir)
TESTS=runtestreadwrite
noinst_PROGRAMS= $(TESTS)
noinst_LTLIBRARIES = libtestutils.la
libtestutils_la_SOURCES=\
$(h)/test-utils.h \
$(h)/test-utils.cc
libtestutils_la_CXXFLAGS= \
-DABIGAIL_SRC_DIR=\"${top_srcdir}\" \
-DABIGAIL_BUILD_DIR=\"${top_builddir}\"
runtestreadwrite_SOURCES=$(h)/test-read-write.cc
runtestreadwrite_LDADD=$(hb)/libtestutils.la $(top_builddir)/src/libabigail.la
AM_CPPFLAGS=-I${top_srcdir}/src
EXTRA_DIST= \
$(h)/data/test-read-write/input0.xml

View File

@ -0,0 +1,3 @@
<abi-instr version='1.0'>
<type-decl name='int' size-in-bits='32' alignment-in-bits='32' id='0'/>
</abi-instr>

22
tests/test-read-write.cc Normal file
View File

@ -0,0 +1,22 @@
// -*- Mode: C++ -*-
#include <iostream>
#include "test-utils.h"
#include "abg-reader.h"
int
main()
{
string suffix("tests/data/test-read-write/input0.xml");
string path(abigail::tests::get_src_dir() + "/" + suffix);
abigail::abi_corpus corpus("test");
if (!abigail::reader::read_file(path.c_str(), corpus))
return 1;
//TODO: serialize the corpus into
//builddir/output/test-read-write/ouput0.xml, so that an other
//dedicated test diffs it.
return 0;
}

35
tests/test-utils.cc Normal file
View File

@ -0,0 +1,35 @@
// -*- Mode: C++ -*-
#include "test-utils.h"
using std::string;
namespace abigail
{
namespace tests
{
std::string&
get_src_dir()
{
#ifndef ABIGAIL_SRC_DIR
#error the macro ABIGAIL_SRC_DIR must be set at compile time
#endif
static string s(ABIGAIL_SRC_DIR);
return s;
}
std::string&
get_build_dir()
{
#ifndef ABIGAIL_BUILD_DIR
#error the macro ABIGAIL_BUILD_DIR must be set at compile time
#endif
static string s(ABIGAIL_BUILD_DIR);
return s;
}
}//end namespace tests
}//end namespace abigail

18
tests/test-utils.h Normal file
View File

@ -0,0 +1,18 @@
// -*- Mode: C++ -*-
#ifndef __TEST_UTILS_H__
#define __TEST_UTILS_H__
#include <string>
namespace abigail
{
namespace tests
{
std::string& get_src_dir();
std::string& get_build_dir();
}//end namespace tests
}//end namespace abigail
#endif //__TEST_UTILS_H__