Commit e91a3940 authored by Thomas Feuvrier's avatar Thomas Feuvrier
Browse files

ENH: ADD Expat library in OTB/Utilities directory (add one testing)

OTB find expat lib on th esystem and try to compile a specific program. Il compilation no succeess, we decided to compile the expat on OTB/Utilities.
parent 3cf7661a
......@@ -291,26 +291,29 @@ LINK_DIRECTORIES( ${GDAL_LIBRARY_DIRS} )
# EXPAT Library
#-------------------------------
# FIND_PACKAGE(EXPAT)
# IF(EXPAT_FOUND)
# INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
# MESSAGE(${EXPAT_INCLUDE_DIR})
# LINK_DIRECTORIES( ${EXPAT_LIBRARY} )
# TRY_COMPILE(OTB_TYPE_COMPILE_EXPAT
# ${OTB_BINARY_DIR}/CMakeTmp
# ${OTB_SOURCE_DIR}/CMake/otbTestCompileExpat.cxx )
# IF(OTB_TYPE_COMPILE_EXPAT)
# SET(OTB_USE_EXTERNAL_EXPAT ON CACHE INTERNAL "Use an outside build of EXPAT.")
# ELSE(OTB_TYPE_COMPILE_EXPAT)
# SET(OTB_USE_EXTERNAL_EXPAT OFF CACHE INTERNAL "Use an OTB internal build of EXPAT.")
# ENDIF( OTB_TYPE_COMPILE_EXPAT)
# ELSE(EXPAT_FOUND)
# SET(OTB_USE_EXTERNAL_EXPAT OFF CACHE INTERNAL "Use an OTB internal build of EXPAT.")
# ENDIF(EXPAT_FOUND)
SET(OTB_USE_EXTERNAL_EXPAT 1)
FIND_PACKAGE(EXPAT)
IF(EXPAT_FOUND)
# Control expat compatibility
INCLUDE_DIRECTORIES(${EXPAT_INCLUDE_DIR})
MESSAGE(${EXPAT_INCLUDE_DIR})
LINK_DIRECTORIES( ${EXPAT_LIBRARY} )
TRY_COMPILE(OTB_TYPE_COMPILE_EXPAT
${OTB_BINARY_DIR}/CMakeTmp
${OTB_SOURCE_DIR}/CMake/otbTestCompileExpat.cxx )
IF(OTB_TYPE_COMPILE_EXPAT)
SET(OTB_USE_EXTERNAL_EXPAT 1)
ELSE(OTB_TYPE_COMPILE_EXPAT)
SET(OTB_USE_EXTERNAL_EXPAT 0)
ENDIF( OTB_TYPE_COMPILE_EXPAT)
ELSE(EXPAT_FOUND)
SET(OTB_USE_EXTERNAL_EXPAT 0)
ENDIF(EXPAT_FOUND)
IF(NOT OTB_USE_EXTERNAL_EXPAT)
ADD_DEFINITIONS(-DOTB_USE_INTERNAL_EXPAT)
INCLUDE_DIRECTORIES("${OTB_SOURCE_DIR}/Utilities/otbexpat")
INCLUDE_DIRECTORIES("${OTB_BINARY_DIR}/Utilities/otbexpat")
ENDIF(NOT OTB_USE_EXTERNAL_EXPAT)
#-------------------------------
# End connections whith external libraries
......
Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
and Clark Cooper
Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
......@@ -333,6 +333,12 @@ ADD_TEST(utOpenJpegDecoder ${UTILITIES_TESTS}
openJpegDecoder)
ENDIF(OTB_COMPILE_JPEG2000)
# ------- lib expat ------------------------------
IF(NOT OTB_USE_EXTERNAL_EXPAT)
ADD_TEST(utExpatRunTests ${UTILITIES_TESTS}
expatruntests
-q)
ENDIF(NOT OTB_USE_EXTERNAL_EXPAT)
# ------- lib OpenThreads ------------------------------
IF(NOT OTB_USE_EXTERNAL_OPENTHREADS)
......@@ -435,8 +441,6 @@ IF(OTB_COMPILE_JPEG2000)
SET(UtilitiesTests_SRCS ${UtilitiesTests_SRCS} openJpegEncoder.cxx openJpegDecoder.cxx)
ENDIF(OTB_COMPILE_JPEG2000)
IF(NOT OTB_USE_EXTERNAL_OPENTHREADS)
SET(UtilitiesTests_SRCS ${UtilitiesTests_SRCS}
openthreadsThreadObserver.cpp
......@@ -445,8 +449,19 @@ IF(NOT OTB_USE_EXTERNAL_OPENTHREADS)
openthreadsSimpleThreader.cpp )
ENDIF(NOT OTB_USE_EXTERNAL_OPENTHREADS)
INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
IF(NOT OTB_USE_EXTERNAL_EXPAT)
SET(UtilitiesTests_SRCS ${UtilitiesTests_SRCS}
expatchardata.cxx
expatminicheck.cxx
expatruntests.cxx )
IF(CMAKE_COMPILER_IS_GNUCXX)
SET_SOURCE_FILES_PROPERTIES( expatchardata.cxx expatminicheck.cxx expatruntests.cxx PROPERTIES COMPILE_FLAGS -w )
ENDIF(CMAKE_COMPILER_IS_GNUCXX)
ENDIF(NOT OTB_USE_EXTERNAL_EXPAT)
INCLUDE_DIRECTORIES("${OTBTesting_BINARY_DIR}")
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}")
......@@ -465,6 +480,10 @@ IF(NOT OTB_USE_EXTERNAL_OPENTHREADS)
TARGET_LINK_LIBRARIES(otbUtilitiesTests OpenThreads)
ENDIF(NOT OTB_USE_EXTERNAL_OPENTHREADS)
IF(NOT OTB_USE_EXTERNAL_EXPAT)
TARGET_LINK_LIBRARIES(otbUtilitiesTests otbexpat)
ENDIF(NOT OTB_USE_EXTERNAL_EXPAT)
IF(UNIX)
TARGET_LINK_LIBRARIES (otbUtilitiesTests m)
ENDIF(UNIX)
......
#ifdef __cplusplus
extern "C" {
#endif
/* Copyright (c) 1998-2003 Thai Open Source Software Center Ltd
See the file COPYING for copying permission.
chardata.c
*/
#ifdef HAVE_EXPAT_CONFIG_H
#include "expat_config.h"
#endif
#ifdef HAVE_CHECK_H
#include <check.h>
#else
#include "expatminicheck.h"
#endif
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include "expatchardata.h"
static int
xmlstrlen(const XML_Char *s)
{
int len = 0;
assert(s != NULL);
while (s[len] != 0)
++len;
return len;
}
void
CharData_Init(CharData *storage)
{
assert(storage != NULL);
storage->count = -1;
}
void
CharData_AppendString(CharData *storage, const char *s)
{
int maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
int len;
assert(s != NULL);
len = strlen(s);
if (storage->count < 0)
storage->count = 0;
if ((len + storage->count) > maxchars) {
len = (maxchars - storage->count);
}
if (len + storage->count < sizeof(storage->data)) {
memcpy(storage->data + storage->count, s, len);
storage->count += len;
}
}
void
CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len)
{
int maxchars;
assert(storage != NULL);
assert(s != NULL);
maxchars = sizeof(storage->data) / sizeof(storage->data[0]);
if (storage->count < 0)
storage->count = 0;
if (len < 0)
len = xmlstrlen(s);
if ((len + storage->count) > maxchars) {
len = (maxchars - storage->count);
}
if (len + storage->count < sizeof(storage->data)) {
memcpy(storage->data + storage->count, s,
len * sizeof(storage->data[0]));
storage->count += len;
}
}
int
CharData_CheckString(CharData *storage, const char *expected)
{
char buffer[1280];
int len;
int count;
assert(storage != NULL);
assert(expected != NULL);
count = (storage->count < 0) ? 0 : storage->count;
len = strlen(expected);
if (len != count) {
if (sizeof(XML_Char) == 1)
sprintf(buffer, "wrong number of data characters:"
" got %d, expected %d:\n%s", count, len, storage->data);
else
sprintf(buffer,
"wrong number of data characters: got %d, expected %d",
count, len);
fail(buffer);
return 0;
}
if (memcmp(expected, storage->data, len) != 0) {
fail("got bad data bytes");
return 0;
}
return 1;
}
int
CharData_CheckXMLChars(CharData *storage, const XML_Char *expected)
{
char buffer[1024];
int len = xmlstrlen(expected);
int count;
assert(storage != NULL);
count = (storage->count < 0) ? 0 : storage->count;
if (len != count) {
sprintf(buffer, "wrong number of data characters: got %d, expected %d",
count, len);
fail(buffer);
return 0;
}
if (memcmp(expected, storage->data, len * sizeof(storage->data[0])) != 0) {
fail("got bad data bytes");
return 0;
}
return 1;
}
#ifdef __cplusplus
}
#endif
/* chardata.h
Interface to some helper routines used to accumulate and check text
and attribute content.
*/
#ifdef __cplusplus
extern "C" {
#endif
#ifndef XML_CHARDATA_H
#define XML_CHARDATA_H 1
#ifndef XML_VERSION
#include "otb_expat.h" /* need XML_Char */
#endif
typedef struct {
int count; /* # of chars, < 0 if not set */
XML_Char data[1024];
} CharData;
void CharData_Init(CharData *storage);
void CharData_AppendString(CharData *storage, const char *s);
void CharData_AppendXMLChars(CharData *storage, const XML_Char *s, int len);
int CharData_CheckString(CharData *storage, const char *s);
int CharData_CheckXMLChars(CharData *storage, const XML_Char *s);
#endif /* XML_CHARDATA_H */
#ifdef __cplusplus
}
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* Miniature re-implementation of the "check" library.
*
* This is intended to support just enough of check to run the Expat
* tests. This interface is based entirely on the portion of the
* check library being used.
*/
#include <stdio.h>
#include <stdlib.h>
#include <setjmp.h>
#include <assert.h>
#include "expatminicheck.h"
Suite *
suite_create(char *name)
{
Suite *suite = (Suite *) calloc(1, sizeof(Suite));
if (suite != NULL) {
suite->name = name;
}
return suite;
}
TCase *
tcase_create(char *name)
{
TCase *tc = (TCase *) calloc(1, sizeof(TCase));
if (tc != NULL) {
tc->name = name;
}
return tc;
}
void
suite_add_tcase(Suite *suite, TCase *tc)
{
assert(suite != NULL);
assert(tc != NULL);
assert(tc->next_tcase == NULL);
tc->next_tcase = suite->tests;
suite->tests = tc;
}
void
tcase_add_checked_fixture(TCase *tc,
tcase_setup_function setup,
tcase_teardown_function teardown)
{
assert(tc != NULL);
tc->setup = setup;
tc->teardown = teardown;
}
void
tcase_add_test(TCase *tc, tcase_test_function test)
{
assert(tc != NULL);
if (tc->allocated == tc->ntests) {
int nalloc = tc->allocated + 100;
size_t new_size = sizeof(tcase_test_function) * nalloc;
// OTB Modifications
// tcase_test_function *new_tests = realloc(tc->tests, new_size);
tcase_test_function *new_tests = static_cast<tcase_test_function *>(realloc(tc->tests, new_size));
assert(new_tests != NULL);
if (new_tests != tc->tests) {
free(tc->tests);
tc->tests = new_tests;
}
tc->allocated = nalloc;
}
tc->tests[tc->ntests] = test;
tc->ntests++;
}
SRunner *
srunner_create(Suite *suite)
{
// OTB Modifications
// SRunner *runner = calloc(1, sizeof(SRunner));
SRunner *runner = static_cast<SRunner *>(calloc(1, sizeof(SRunner)));
if (runner != NULL) {
runner->suite = suite;
}
return runner;
}
static jmp_buf env;
static char const *_check_current_function = NULL;
static int _check_current_lineno = -1;
static char const *_check_current_filename = NULL;
void
_check_set_test_info(char const *function, char const *filename, int lineno)
{
_check_current_function = function;
_check_current_lineno = lineno;
_check_current_filename = filename;
}
static void
add_failure(SRunner *runner, int verbosity)
{
runner->nfailures++;
if (verbosity >= CK_VERBOSE) {
printf("%s:%d: %s\n", _check_current_filename,
_check_current_lineno, _check_current_function);
}
}
void
srunner_run_all(SRunner *runner, int verbosity)
{
Suite *suite;
TCase *tc;
assert(runner != NULL);
suite = runner->suite;
tc = suite->tests;
while (tc != NULL) {
int i;
for (i = 0; i < tc->ntests; ++i) {
runner->nchecks++;
if (tc->setup != NULL) {
/* setup */
if (setjmp(env)) {
add_failure(runner, verbosity);
continue;
}
tc->setup();
}
/* test */
if (setjmp(env)) {
add_failure(runner, verbosity);
continue;
}
(tc->tests[i])();
/* teardown */
if (tc->teardown != NULL) {
if (setjmp(env)) {
add_failure(runner, verbosity);
continue;
}
tc->teardown();
}
}
tc = tc->next_tcase;
}
if (verbosity) {
int passed = runner->nchecks - runner->nfailures;
double percentage = ((double) passed) / runner->nchecks;
int display = (int) (percentage * 100);
printf("%d%%: Checks: %d, Failed: %d\n",
display, runner->nchecks, runner->nfailures);
}
}
void
_fail_unless(int condition, const char *file, int line, char *msg)
{
/* Always print the error message so it isn't lost. In this case,
we have a failure, so there's no reason to be quiet about what
it is.
*/
if (msg != NULL)
printf("%s", msg);
longjmp(env, 1);
}
int
srunner_ntests_failed(SRunner *runner)
{
assert(runner != NULL);
return runner->nfailures;
}
void
srunner_free(SRunner *runner)
{
free(runner->suite);
free(runner);
}
#ifdef __cplusplus
}
#endif
/* Miniature re-implementation of the "check" library.
*
* This is intended to support just enough of check to run the Expat
* tests. This interface is based entirely on the portion of the
* check library being used.
*
* This is *source* compatible, but not necessary *link* compatible.
*/
#ifdef __cplusplus
extern "C" {
#endif
#define CK_NOFORK 0
#define CK_FORK 1
#define CK_SILENT 0
#define CK_NORMAL 1
#define CK_VERBOSE 2
/* Workaround for Tru64 Unix systems where the C compiler has a working
__func__, but the C++ compiler only has a working __FUNCTION__. This
could be fixed in configure.in, but it's not worth it right now. */
#if defined(__osf__) && defined(__cplusplus)
#define __func__ __FUNCTION__
#endif
#define START_TEST(testname) static void testname(void) { \
_check_set_test_info(__func__, __FILE__, __LINE__); \
{
#define END_TEST } }
#define fail(msg) _fail_unless(0, __FILE__, __LINE__, msg)
typedef void (*tcase_setup_function)(void);
typedef void (*tcase_teardown_function)(void);
typedef void (*tcase_test_function)(void);
typedef struct SRunner SRunner;
typedef struct Suite Suite;
typedef struct TCase TCase;
struct SRunner {
Suite *suite;
int nchecks;
int nfailures;
};
struct Suite {
char *name;
TCase *tests;
};
struct TCase {
char *name;
tcase_setup_function setup;
tcase_teardown_function teardown;
tcase_test_function *tests;
int ntests;
int allocated;
TCase *next_tcase;
};
/* Internal helper. */
void _check_set_test_info(char const *function,
char const *filename, int lineno);
/*
* Prototypes for the actual implementation.
*/
void _fail_unless(int condition, const char *file, int line, char *msg);
Suite *suite_create(char *name);
TCase *tcase_create(char *name);
void suite_add_tcase(Suite *suite, TCase *tc);
void tcase_add_checked_fixture(TCase *,
tcase_setup_function,
tcase_teardown_function);
void tcase_add_test(TCase *tc, tcase_test_function test);
SRunner *srunner_create(Suite *suite);
void srunner_run_all(SRunner *runner, int verbosity);
int srunner_ntests_failed(SRunner *runner);
void srunner_free(SRunner *runner);
#ifdef __cplusplus
}
#endif
This diff is collapsed.
......@@ -49,5 +49,8 @@ REGISTER_TEST(itk2DScaleInvariantFeatureImageFilterTest);
REGISTER_TEST(openthreadsSimpleThreader);
REGISTER_TEST(openthreadsWorkCrew);
#endif
#ifdef OTB_USE_INTERNAL_EXPAT
REGISTER_TEST(expatruntests);
#endif
}
......@@ -21,7 +21,7 @@ IF(OTB_USE_VISU_GUI)
ENDIF(OTB_USE_VISU_GUI)
IF(NOT OTB_USE_EXTERNAL_EXPAT)
#SUBDIRS( otbexpat )
SUBDIRS( otbexpat )
ENDIF(NOT OTB_USE_EXTERNAL_EXPAT)
#Supress libraries not used by the 2.2.0 version
......
......@@ -58,7 +58,7 @@ CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/cmake_expat_config.h.in
ADD_LIBRARY(otbexpat ${EXPAT_SRCS} )
TARGET_LINK_LIBRARIES (otbkml)
#TARGET_LINK_LIBRARIES (otbkml)