diff options
Diffstat (limited to 'meta-selftest/recipes-test/cpp/files')
7 files changed, 0 insertions, 200 deletions
diff --git a/meta-selftest/recipes-test/cpp/files/CMakeLists.txt b/meta-selftest/recipes-test/cpp/files/CMakeLists.txt deleted file mode 100644 index 6fa6917d89..0000000000 --- a/meta-selftest/recipes-test/cpp/files/CMakeLists.txt +++ /dev/null | |||
| @@ -1,61 +0,0 @@ | |||
| 1 | # | ||
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: MIT | ||
| 5 | # | ||
| 6 | |||
| 7 | cmake_minimum_required(VERSION 3.22) | ||
| 8 | |||
| 9 | project(cmake-example | ||
| 10 | VERSION 1.0.0 | ||
| 11 | LANGUAGES CXX | ||
| 12 | ) | ||
| 13 | |||
| 14 | option(BUILD_SHARED_LIBS "Build using shared libraries" ON) | ||
| 15 | option(FAILING_TEST "Compile a failing unit test to test the test infrastructure" OFF) | ||
| 16 | |||
| 17 | set(CMAKE_CXX_STANDARD 17) | ||
| 18 | set(CMAKE_CXX_STANDARD_REQUIRED On) | ||
| 19 | set(CMAKE_CXX_EXTENSIONS Off) | ||
| 20 | |||
| 21 | include(GNUInstallDirs) | ||
| 22 | |||
| 23 | # Linking a small library makes the example more useful for testing. | ||
| 24 | find_package(json-c) | ||
| 25 | |||
| 26 | # A simple library linking json-c library found by pkgconfig | ||
| 27 | add_library(cmake-example-lib cpp-example-lib.cpp cpp-example-lib.hpp) | ||
| 28 | set_target_properties(cmake-example-lib PROPERTIES | ||
| 29 | VERSION ${PROJECT_VERSION} | ||
| 30 | SOVERSION ${PROJECT_VERSION_MAJOR} | ||
| 31 | ) | ||
| 32 | target_link_libraries(cmake-example-lib PRIVATE json-c::json-c) | ||
| 33 | |||
| 34 | install(TARGETS cmake-example-lib | ||
| 35 | INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} | ||
| 36 | ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| 37 | LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} | ||
| 38 | ) | ||
| 39 | |||
| 40 | # A simple executable linking the library | ||
| 41 | add_executable(cmake-example cpp-example.cpp) | ||
| 42 | target_link_libraries(cmake-example PRIVATE cmake-example-lib) | ||
| 43 | |||
| 44 | install(TARGETS cmake-example | ||
| 45 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| 46 | ) | ||
| 47 | |||
| 48 | # A simple test executable for testing the library | ||
| 49 | add_executable(test-cmake-example test-cpp-example.cpp) | ||
| 50 | target_link_libraries(test-cmake-example PRIVATE cmake-example-lib) | ||
| 51 | |||
| 52 | if (FAILING_TEST) | ||
| 53 | target_compile_definitions(test-cmake-example PRIVATE FAIL_COMPARISON_STR="foo") | ||
| 54 | endif(FAILING_TEST) | ||
| 55 | |||
| 56 | install(TARGETS test-cmake-example | ||
| 57 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | ||
| 58 | ) | ||
| 59 | |||
| 60 | include(CTest) | ||
| 61 | add_test(NAME test-cmake-example COMMAND test-cmake-example) | ||
diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp deleted file mode 100644 index d3dc976864..0000000000 --- a/meta-selftest/recipes-test/cpp/files/cpp-example-lib.cpp +++ /dev/null | |||
| @@ -1,33 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright OpenEmbedded Contributors | ||
| 3 | * | ||
| 4 | * SPDX-License-Identifier: MIT | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <iostream> | ||
| 8 | #include <string> | ||
| 9 | #include <json-c/json.h> | ||
| 10 | #include "cpp-example-lib.hpp" | ||
| 11 | |||
| 12 | const std::string &CppExample::get_string() | ||
| 13 | { | ||
| 14 | return test_string; | ||
| 15 | } | ||
| 16 | |||
| 17 | const char *CppExample::get_json_c_version() | ||
| 18 | { | ||
| 19 | return json_c_version(); | ||
| 20 | } | ||
| 21 | |||
| 22 | void CppExample::print_json() | ||
| 23 | { | ||
| 24 | struct json_object *jobj; | ||
| 25 | const int flag = JSON_C_TO_STRING_SPACED | JSON_C_TO_STRING_PRETTY; | ||
| 26 | |||
| 27 | jobj = json_object_new_object(); | ||
| 28 | json_object_object_add(jobj, "test_string", json_object_new_string(test_string.c_str())); | ||
| 29 | |||
| 30 | std::cout << json_object_to_json_string_ext(jobj, flag) << std::endl; | ||
| 31 | |||
| 32 | json_object_put(jobj); // Delete the json object | ||
| 33 | } | ||
diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp b/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp deleted file mode 100644 index 0ad9e7b7b2..0000000000 --- a/meta-selftest/recipes-test/cpp/files/cpp-example-lib.hpp +++ /dev/null | |||
| @@ -1,21 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright OpenEmbedded Contributors | ||
| 3 | * | ||
| 4 | * SPDX-License-Identifier: MIT | ||
| 5 | */ | ||
| 6 | |||
| 7 | #pragma once | ||
| 8 | |||
| 9 | #include <string> | ||
| 10 | |||
| 11 | struct CppExample | ||
| 12 | { | ||
| 13 | inline static const std::string test_string = "cpp-example-lib Magic: 123456789"; | ||
| 14 | |||
| 15 | /* Retrieve a constant string */ | ||
| 16 | const std::string &get_string(); | ||
| 17 | /* Retrieve a constant string from a library */ | ||
| 18 | const char *get_json_c_version(); | ||
| 19 | /* Call a more advanced function from a library */ | ||
| 20 | void print_json(); | ||
| 21 | }; | ||
diff --git a/meta-selftest/recipes-test/cpp/files/cpp-example.cpp b/meta-selftest/recipes-test/cpp/files/cpp-example.cpp deleted file mode 100644 index 9889554e0c..0000000000 --- a/meta-selftest/recipes-test/cpp/files/cpp-example.cpp +++ /dev/null | |||
| @@ -1,18 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright OpenEmbedded Contributors | ||
| 3 | * | ||
| 4 | * SPDX-License-Identifier: MIT | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "cpp-example-lib.hpp" | ||
| 8 | |||
| 9 | #include <iostream> | ||
| 10 | |||
| 11 | int main() | ||
| 12 | { | ||
| 13 | auto cpp_example = CppExample(); | ||
| 14 | std::cout << "C++ example linking " << cpp_example.get_string() << std::endl; | ||
| 15 | std::cout << "Linking json-c version " << cpp_example.get_json_c_version() << std::endl; | ||
| 16 | cpp_example.print_json(); | ||
| 17 | return 0; | ||
| 18 | } | ||
diff --git a/meta-selftest/recipes-test/cpp/files/meson.build b/meta-selftest/recipes-test/cpp/files/meson.build deleted file mode 100644 index 74a0e0173c..0000000000 --- a/meta-selftest/recipes-test/cpp/files/meson.build +++ /dev/null | |||
| @@ -1,39 +0,0 @@ | |||
| 1 | # | ||
| 2 | # Copyright OpenEmbedded Contributors | ||
| 3 | # | ||
| 4 | # SPDX-License-Identifier: MIT | ||
| 5 | # | ||
| 6 | |||
| 7 | project('meson-example', 'cpp', | ||
| 8 | version: '1.0.0', | ||
| 9 | default_options: ['cpp_std=c++17'], | ||
| 10 | meson_version: '>=1.1.0' | ||
| 11 | ) | ||
| 12 | |||
| 13 | jsoncdep = dependency('json-c') | ||
| 14 | |||
| 15 | if get_option('FAILING_TEST').enabled() | ||
| 16 | add_project_arguments('-DFAIL_COMPARISON_STR=foo', language: 'cpp') | ||
| 17 | endif | ||
| 18 | |||
| 19 | mesonexlib = shared_library('mesonexlib', | ||
| 20 | 'cpp-example-lib.cpp', 'cpp-example-lib.hpp', | ||
| 21 | version: meson.project_version(), | ||
| 22 | soversion: meson.project_version().split('.')[0], | ||
| 23 | dependencies : jsoncdep, | ||
| 24 | install : true | ||
| 25 | ) | ||
| 26 | |||
| 27 | executable('mesonex', | ||
| 28 | 'cpp-example.cpp', | ||
| 29 | link_with : mesonexlib, | ||
| 30 | install : true | ||
| 31 | ) | ||
| 32 | |||
| 33 | test_mesonex = executable('test-mesonex', | ||
| 34 | 'test-cpp-example.cpp', | ||
| 35 | link_with : mesonexlib, | ||
| 36 | install : true | ||
| 37 | ) | ||
| 38 | |||
| 39 | test('meson example test', test_mesonex) | ||
diff --git a/meta-selftest/recipes-test/cpp/files/meson.options b/meta-selftest/recipes-test/cpp/files/meson.options deleted file mode 100644 index 58a0bf9e61..0000000000 --- a/meta-selftest/recipes-test/cpp/files/meson.options +++ /dev/null | |||
| @@ -1,3 +0,0 @@ | |||
| 1 | |||
| 2 | option('FAILING_TEST', type : 'feature', value : 'disabled', | ||
| 3 | description : 'Compile a failing unit test to test the test infrastructure') | ||
diff --git a/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp b/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp deleted file mode 100644 index 83c9bfa844..0000000000 --- a/meta-selftest/recipes-test/cpp/files/test-cpp-example.cpp +++ /dev/null | |||
| @@ -1,25 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * Copyright OpenEmbedded Contributors | ||
| 3 | * | ||
| 4 | * SPDX-License-Identifier: MIT | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "cpp-example-lib.hpp" | ||
| 8 | |||
| 9 | #include <iostream> | ||
| 10 | |||
| 11 | /* This is for creating a failing test for testing the test infrastructure */ | ||
| 12 | #ifndef FAIL_COMPARISON_STR | ||
| 13 | #define FAIL_COMPARISON_STR "" | ||
| 14 | #endif | ||
| 15 | |||
| 16 | int main() { | ||
| 17 | auto cpp_example = CppExample(); | ||
| 18 | auto ret_string = cpp_example.get_string(); | ||
| 19 | if(0 == ret_string.compare(CppExample::test_string + FAIL_COMPARISON_STR)) { | ||
| 20 | std::cout << "PASS: " << ret_string << " = " << CppExample::test_string << std::endl; | ||
| 21 | } else { | ||
| 22 | std::cout << "FAIL: " << ret_string << " != " << CppExample::test_string << std::endl; | ||
| 23 | return 1; | ||
| 24 | } | ||
| 25 | } | ||
