Skip to content
This repository was archived by the owner on Nov 6, 2020. It is now read-only.

Commit 18eb04c

Browse files
committed
Test the C library in test.sh
1 parent 7257cfd commit 18eb04c

3 files changed

Lines changed: 58 additions & 2 deletions

File tree

parity-clib-example/CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
cmake_minimum_required(VERSION 3.11)
2+
include(ExternalProject)
3+
4+
include_directories("${CMAKE_SOURCE_DIR}/../parity-clib")
5+
6+
add_executable(parity-example main.cpp)
7+
8+
ExternalProject_Add(
9+
libparity
10+
DOWNLOAD_COMMAND ""
11+
CONFIGURE_COMMAND ""
12+
BUILD_COMMAND ""
13+
COMMAND cargo build -p parity-clib # Note: use --release in a real project
14+
BINARY_DIR "${CMAKE_SOURCE_DIR}/../target"
15+
INSTALL_COMMAND ""
16+
LOG_BUILD ON)
17+
18+
add_dependencies(parity-example libparity)
19+
target_link_libraries(parity-example "${CMAKE_SOURCE_DIR}/../target/debug/libparity.so")

parity-clib-example/main.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <cstddef>
2+
#include <unistd.h>
3+
#include <parity.h>
4+
5+
void on_restart(void*, const char*, size_t) {}
6+
7+
int main() {
8+
ParityParams cfg = { 0 };
9+
cfg.on_client_restart_cb = on_restart;
10+
11+
const char* args[] = {"--light"};
12+
size_t str_lens[] = {7};
13+
if (parity_config_from_cli(args, str_lens, 1, &cfg.configuration) != 0) {
14+
return 1;
15+
}
16+
17+
void* parity;
18+
if (parity_start(&cfg, &parity) != 0) {
19+
return 1;
20+
}
21+
22+
sleep(5);
23+
if (parity != NULL) {
24+
parity_destroy(parity);
25+
}
26+
27+
return 0;
28+
}

test.sh

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,17 @@ echo "________Validate chainspecs________"
4040
fi
4141

4242

43-
# Running test's
43+
# Running tests
4444
echo "________Running Parity Full Test Suite________"
45-
4645
cargo test -j 8 $OPTIONS --features "$FEATURES" --all $1
4746

47+
# Running the C example
48+
cd parity-clib-example && \
49+
mkdir -p build && \
50+
cd build && \
51+
cmake .. && \
52+
make && \
53+
./parity-example && \
54+
cd .. && \
55+
rm -rf build && \
56+
cd ..

0 commit comments

Comments
 (0)