forked from libgeos/geos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for registering interruption-checking callback.
This is to enhance flexibility of the interruption request model. git-svn-id: http://svn.osgeo.org/geos/trunk@3666 5242fede-7e19-0410-aef8-94bd7d2200fb
- Loading branch information
Sandro Santilli
committed
Jun 7, 2012
1 parent
e4d258c
commit 6819ea6
Showing
7 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
// | ||
// Test Suite for C-API custom allocators | ||
|
||
#include <tut.hpp> | ||
// geos | ||
#include <geos_c.h> | ||
// std | ||
#include <cstdarg> | ||
#include <cstdio> | ||
#include <cstdlib> | ||
#include <memory> | ||
|
||
namespace tut | ||
{ | ||
// | ||
// Test Group | ||
// | ||
|
||
// Common data used in test cases. | ||
struct test_capiinterrupt_data | ||
{ | ||
static int alloc_count; | ||
static int dealloc_count; | ||
|
||
static void notice(const char *fmt, ...) | ||
{ | ||
std::fprintf( stdout, "NOTICE: "); | ||
|
||
va_list ap; | ||
va_start(ap, fmt); | ||
std::vfprintf(stdout, fmt, ap); | ||
va_end(ap); | ||
|
||
std::fprintf(stdout, "\n"); | ||
} | ||
|
||
test_capiinterrupt_data() | ||
{ | ||
} | ||
|
||
~test_capiinterrupt_data() | ||
{ | ||
} | ||
|
||
static void interruptNow(void *) | ||
{ | ||
GEOS_interruptRequest(); | ||
} | ||
|
||
static void countCalls(void *arg) | ||
{ | ||
int* numcalls = reinterpret_cast<int*>(arg); | ||
++(*numcalls); | ||
} | ||
|
||
}; | ||
|
||
int test_capiinterrupt_data::alloc_count = 0; | ||
int test_capiinterrupt_data::dealloc_count = 0; | ||
|
||
typedef test_group<test_capiinterrupt_data> group; | ||
typedef group::object object; | ||
|
||
group test_capiinterrupt_group("capi::GEOSInterrupt"); | ||
|
||
// | ||
// Test Cases | ||
// | ||
|
||
/// Test interrupt callback being called | ||
template<> | ||
template<> | ||
void object::test<1>() | ||
{ | ||
int numcalls = 0; | ||
GEOS_interruptRegisterCallback(countCalls, &numcalls); | ||
|
||
initGEOS(notice, notice); | ||
|
||
ensure_equals(numcalls, 0); | ||
|
||
GEOSGeometry *geom1 = GEOSGeomFromWKT("LINESTRING(0 0, 1 0)"); | ||
|
||
ensure("GEOSGeomFromWKT failed", 0 != geom1); | ||
|
||
GEOSGeometry *geom2 = GEOSBuffer(geom1, 1, 8); | ||
|
||
ensure("GEOSBufferWithStyle failed", 0 != geom2); | ||
|
||
ensure("interrupt callback never called", numcalls > 0); | ||
|
||
GEOSGeom_destroy(geom1); | ||
GEOSGeom_destroy(geom2); | ||
|
||
finishGEOS(); | ||
} | ||
|
||
/// Test interrupting from callback | ||
template<> | ||
template<> | ||
void object::test<2>() | ||
{ | ||
initGEOS(notice, notice); | ||
|
||
GEOS_interruptRegisterCallback(0, 0); /* unregister */ | ||
|
||
GEOSGeometry *geom1 = GEOSGeomFromWKT("LINESTRING(0 0, 1 0)"); | ||
|
||
ensure("GEOSGeomFromWKT failed", 0 != geom1); | ||
|
||
GEOS_interruptRegisterCallback(interruptNow, 0); | ||
bool interrupted = false; | ||
GEOSGeometry *geom2 = GEOSBuffer(geom1, 1, 8); | ||
ensure("GEOSBuffer wasn't interrupted", 0 == geom2); | ||
|
||
// TODO: check the actual exception ? (sent to notice() callback) | ||
|
||
GEOSGeom_destroy(geom1); | ||
|
||
finishGEOS(); | ||
} | ||
|
||
|
||
} // namespace tut | ||
|