From 1961ae06e96f1111f9c4316d9d08fc485008935f Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Fri, 28 Nov 2014 15:36:19 +0100 Subject: Test that libcmark can be used by C++ code --- api_test/CMakeLists.txt | 1 + api_test/cplusplus.cpp | 15 +++++++++++++++ api_test/harness.h | 8 ++++++++ api_test/main.c | 4 ++++ 4 files changed, 28 insertions(+) create mode 100644 api_test/cplusplus.cpp (limited to 'api_test') diff --git a/api_test/CMakeLists.txt b/api_test/CMakeLists.txt index c25b6c1..f64961f 100644 --- a/api_test/CMakeLists.txt +++ b/api_test/CMakeLists.txt @@ -1,4 +1,5 @@ add_executable(api_test + cplusplus.cpp harness.c harness.h main.c diff --git a/api_test/cplusplus.cpp b/api_test/cplusplus.cpp new file mode 100644 index 0000000..ea64b06 --- /dev/null +++ b/api_test/cplusplus.cpp @@ -0,0 +1,15 @@ +#include + +#include "cmark.h" + +#include "harness.h" + +extern "C" void +test_cplusplus(test_batch_runner *runner) +{ + static const char md[] = "paragraph\n"; + char *html = cmark_markdown_to_html(md, sizeof(md) - 1); + STR_EQ(runner, html, "

paragraph

\n", "libcmark works with C++"); + free(html); +} + diff --git a/api_test/harness.h b/api_test/harness.h index 5fdc7ae..55a6232 100644 --- a/api_test/harness.h +++ b/api_test/harness.h @@ -1,6 +1,10 @@ #ifndef CMARK_API_TEST_HARNESS_H #define CMARK_API_TEST_HARNESS_H +#ifdef __cplusplus +extern "C" { +#endif + typedef struct { int test_num; int num_passed; @@ -30,5 +34,9 @@ test_ok(test_batch_runner *runner); void test_print_summary(test_batch_runner *runner); +#ifdef __cplusplus +} +#endif + #endif diff --git a/api_test/main.c b/api_test/main.c index 709b8d3..6e54ea1 100644 --- a/api_test/main.c +++ b/api_test/main.c @@ -10,6 +10,9 @@ #define UTF8_REPL "\xEF\xBF\xBD" +void +test_cplusplus(test_batch_runner *runner); + static const cmark_node_type node_types[] = { CMARK_NODE_DOCUMENT, CMARK_NODE_BLOCK_QUOTE, @@ -608,6 +611,7 @@ int main() { parser(runner); render_html(runner); utf8(runner); + test_cplusplus(runner); test_print_summary(runner); retval = test_ok(runner) ? 0 : 1; -- cgit v1.2.3