Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ commands:
-DCMAKE_BUILD_TYPE=Release \
.
- run: make -j 16 VERBOSE=1
run-linkage-tests:
steps:
- run:
name: Linkage test (static)
command: |
BUILD=$(mktemp -d) INST=$(mktemp -d) LB=$(mktemp -d)
cmake -S . -B "$BUILD" -DCMAKE_BUILD_TYPE=Debug -DSANITIZE=OFF -DBUILD_SHARED_LIBS=OFF -DCMAKE_INSTALL_PREFIX="$INST"
cmake --build "$BUILD" --parallel
cmake --install "$BUILD"
cmake -S test/linkage -B "$LB" -DCMAKE_PREFIX_PATH="$INST"
cmake --build "$LB"
ctest --test-dir "$LB" -VV
- run:
name: Linkage test (shared)
command: |
BUILD=$(mktemp -d) INST=$(mktemp -d) LB=$(mktemp -d)
cmake -S . -B "$BUILD" -DCMAKE_BUILD_TYPE=Debug -DSANITIZE=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX="$INST"
cmake --build "$BUILD" --parallel
cmake --install "$BUILD"
cmake -S test/linkage -B "$LB" -DCMAKE_PREFIX_PATH="$INST"
cmake --build "$LB"
LD_LIBRARY_PATH="$INST/lib" ctest --test-dir "$LB" -VV
test:
steps:
- run: ctest -VV --output-junit ctest_out.xml
Expand Down Expand Up @@ -109,6 +131,7 @@ jobs:
cat Testing/Temporary/MemoryChecker*
exit 1
fi;
- run-linkage-tests

build-and-test-clang:
machine:
Expand All @@ -122,6 +145,7 @@ jobs:
- linux-setup
- build
- test
- run-linkage-tests

build-and-test-sanitized:
machine:
Expand Down
10 changes: 10 additions & 0 deletions test/linkage/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.5)
project(libcbor_linkage_test C)

find_package(libcbor REQUIRED)

add_executable(linkage_test main.c)
target_link_libraries(linkage_test libcbor::libcbor)

enable_testing()
add_test(NAME linkage_test COMMAND linkage_test)
38 changes: 38 additions & 0 deletions test/linkage/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
*
* libcbor is free software; you can redistribute it and/or modify
* it under the terms of the MIT license. See LICENSE for details.
*/

/*
* Standalone linkage test: verifies that libcbor can be found via
* find_package and linked against from an external project, for both
* static and shared library builds.
*/

#include <assert.h>
#include <stdio.h>
#include "cbor.h"

int main(void) {
/* Encode an integer and decode it back */
cbor_item_t* item = cbor_build_uint8(42);
assert(item != NULL);

unsigned char buf[16];
size_t len = cbor_serialize(item, buf, sizeof(buf));
assert(len > 0);

struct cbor_load_result result;
cbor_item_t* decoded = cbor_load(buf, len, &result);
assert(decoded != NULL);
assert(result.error.code == CBOR_ERR_NONE);
assert(cbor_get_uint8(decoded) == 42);

cbor_decref(&item);
cbor_decref(&decoded);

printf("libcbor linkage test passed (version %s)\n", CBOR_VERSION);
return 0;
}