This is an automated email from the ASF dual-hosted git repository.

pengzheng pushed a commit to branch feature/error_injector_ergonomics
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 38539edda1a8e70d092f50d88b25b8362f4f9392
Author: PengZheng <[email protected]>
AuthorDate: Fri May 5 16:57:30 2023 +0800

    Use a separate cut(code under test) library for unit test.
---
 bundles/pubsub/pubsub_spi/CMakeLists.txt           |  2 +-
 libs/framework/CMakeLists.txt                      | 56 +++++++++++-----------
 libs/framework/gtest/CMakeLists.txt                |  5 +-
 .../CelixBundleContextBundlesWithErrorTestSuite.cc |  2 +-
 libs/framework/src/bundle_archive_private.h        |  3 +-
 libs/framework/src/bundle_private.h                |  5 +-
 libs/framework/src/bundle_revision_private.h       |  4 +-
 libs/framework/src/celix_framework_utils_private.h | 13 ++---
 8 files changed, 38 insertions(+), 52 deletions(-)

diff --git a/bundles/pubsub/pubsub_spi/CMakeLists.txt 
b/bundles/pubsub/pubsub_spi/CMakeLists.txt
index 8b9dc526..e3934409 100644
--- a/bundles/pubsub/pubsub_spi/CMakeLists.txt
+++ b/bundles/pubsub/pubsub_spi/CMakeLists.txt
@@ -28,7 +28,7 @@ target_include_directories(pubsub_spi PUBLIC
         $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>)
 
 target_link_libraries(pubsub_spi PUBLIC Celix::framework Celix::pubsub_api)
-target_link_libraries(pubsub_spi PUBLIC Celix::pubsub_utils )
+target_link_libraries(pubsub_spi PUBLIC Celix::pubsub_utils libuuid::libuuid)
 celix_deprecated_utils_headers(pubsub_spi)
 celix_deprecated_framework_headers(pubsub_spi)
 add_library(Celix::pubsub_spi ALIAS pubsub_spi)
diff --git a/libs/framework/CMakeLists.txt b/libs/framework/CMakeLists.txt
index f9b9701e..e6a727f1 100644
--- a/libs/framework/CMakeLists.txt
+++ b/libs/framework/CMakeLists.txt
@@ -19,7 +19,7 @@ find_package(ZLIB REQUIRED)
 find_package(libuuid REQUIRED)
 find_package(CURL REQUIRED)
 
-set(SOURCES
+set(FRAMEWORK_SRC
         src/attribute.c src/bundle.c src/bundle_archive.c 
src/celix_bundle_cache.c
         src/bundle_context.c src/bundle_revision.c src/celix_errorcodes.c
         src/framework.c src/manifest.c
@@ -35,41 +35,31 @@ set(SOURCES
         src/celix_bundle_state.c
         src/celix_framework_utils.c
         src/celix_module_private.h)
-add_library(framework_obj OBJECT ${SOURCES})
+add_library(framework SHARED ${FRAMEWORK_SRC})
+set(FRAMEWORK_DEPS libuuid::libuuid CURL::libcurl ZLIB::ZLIB ${CMAKE_DL_LIBS})
 
-target_include_directories(framework_obj PUBLIC
-    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
-)
-target_include_directories(framework_obj PRIVATE 
${CMAKE_CURRENT_LIST_DIR}/include_deprecated)
-target_compile_options(framework_obj PRIVATE -DUSE_FILE32API)
-target_compile_options(framework_obj PRIVATE -Wno-deprecated-declarations) 
#note part of the api is deprecated, ignore this warning on own api
-target_link_libraries(framework_obj PUBLIC Celix::utils 
${CELIX_OPTIONAL_EXTRA_LIBS})
-target_link_libraries(framework_obj PUBLIC libuuid::libuuid CURL::libcurl 
ZLIB::ZLIB)
-target_link_libraries(framework_obj PRIVATE ${CMAKE_DL_LIBS})
-#Note visibility preset is also needed on OBJECT libraries, to work correctly
-set_target_properties(framework_obj PROPERTIES C_VISIBILITY_PRESET hidden)
-celix_deprecated_utils_headers(framework_obj)
-
-add_library(framework SHARED)
-generate_export_header(framework
-        BASE_NAME "CELIX_FRAMEWORK"
-        EXPORT_FILE_NAME 
"${CMAKE_BINARY_DIR}/celix/gen/includes/framework/celix_framework_export.h")
-target_include_directories(framework_obj PUBLIC 
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/celix/gen/includes/framework>)
-# We are building this library
-target_compile_definitions(framework_obj PRIVATE framework_EXPORTS)
-
-target_link_libraries(framework PUBLIC framework_obj)
 set_target_properties(framework
-    PROPERTIES
+        PROPERTIES
         C_VISIBILITY_PRESET hidden
         "VERSION" "${CELIX_MAJOR}.${CELIX_MINOR}.${CELIX_MICRO}"
         "SOVERSION" ${CELIX_MAJOR}
         OUTPUT_NAME "celix_framework")
+target_include_directories(framework PUBLIC
+    $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
+)
+target_include_directories(framework PRIVATE 
${CMAKE_CURRENT_LIST_DIR}/include_deprecated)
+target_compile_options(framework PRIVATE -DUSE_FILE32API)
+target_compile_options(framework PRIVATE -Wno-deprecated-declarations) #note 
part of the api is deprecated, ignore this warning on own api
+target_link_libraries(framework PUBLIC Celix::utils 
${CELIX_OPTIONAL_EXTRA_LIBS})
+target_link_libraries(framework PRIVATE ${FRAMEWORK_DEPS})
 
+generate_export_header(framework
+        BASE_NAME "CELIX_FRAMEWORK"
+        EXPORT_FILE_NAME 
"${CMAKE_BINARY_DIR}/celix/gen/includes/framework/celix_framework_export.h")
+target_include_directories(framework PUBLIC 
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/celix/gen/includes/framework>)
 celix_deprecated_utils_headers(framework)
 
-# By omitting OBJECTS DESTINATION, object files will NOT be installed.
-install(TARGETS framework framework_obj EXPORT celix LIBRARY DESTINATION 
${CMAKE_INSTALL_LIBDIR} COMPONENT framework
+install(TARGETS framework EXPORT celix LIBRARY DESTINATION 
${CMAKE_INSTALL_LIBDIR} COMPONENT framework
         INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/celix/framework)
 install(DIRECTORY include/ DESTINATION 
${CMAKE_INSTALL_INCLUDEDIR}/celix/framework COMPONENT framework)
 install(DIRECTORY include_deprecated/ DESTINATION 
${CMAKE_INSTALL_INCLUDEDIR}/celix/framework COMPONENT framework)
@@ -77,9 +67,19 @@ install(DIRECTORY 
${CMAKE_BINARY_DIR}/celix/gen/includes/framework/ DESTINATION
 
 #Alias setup to match external usage
 add_library(Celix::framework ALIAS framework)
-add_library(Celix::framework_obj ALIAS framework_obj)
 
 if (ENABLE_TESTING AND CELIX_CXX17) #framework tests are C++17
+    add_library(framework_cut STATIC ${FRAMEWORK_SRC})
+    target_include_directories(framework_cut PUBLIC
+            ${CMAKE_CURRENT_LIST_DIR}/src
+            ${CMAKE_CURRENT_LIST_DIR}/include
+            ${CMAKE_BINARY_DIR}/celix/gen/includes/framework
+            ${CMAKE_CURRENT_LIST_DIR}/include_deprecated
+            )
+    target_compile_options(framework_cut PRIVATE -DUSE_FILE32API)
+    target_compile_options(framework_cut PRIVATE -Wno-deprecated-declarations) 
#note part of the api is deprecated, ignore this warning on own api
+    target_link_libraries(framework_cut PUBLIC Celix::utils 
${CELIX_OPTIONAL_EXTRA_LIBS} ${FRAMEWORK_DEPS})
+    celix_deprecated_utils_headers(framework_cut)
     add_subdirectory(gtest)
 endif()
 
diff --git a/libs/framework/gtest/CMakeLists.txt 
b/libs/framework/gtest/CMakeLists.txt
index 98db4391..eca5c583 100644
--- a/libs/framework/gtest/CMakeLists.txt
+++ b/libs/framework/gtest/CMakeLists.txt
@@ -59,7 +59,7 @@ set(CELIX_FRAMEWORK_TEST_SOURCES
 )
 
 add_executable(test_framework ${CELIX_FRAMEWORK_TEST_SOURCES})
-target_link_libraries(test_framework PRIVATE Celix::framework CURL::libcurl 
GTest::gtest GTest::gtest_main)
+target_link_libraries(test_framework PRIVATE framework_cut CURL::libcurl 
GTest::gtest GTest::gtest_main)
 celix_deprecated_framework_headers(test_framework)
 
 
@@ -130,12 +130,11 @@ if (LINKER_WRAP_SUPPORTED)
             SIMPLE_TEST_BUNDLE1_LOCATION="${SIMPLE_TEST_BUNDLE1}"
             SIMPLE_CXX_BUNDLE_LOC="${SIMPLE_CXX_BUNDLE_LOC}"
     )
-    target_include_directories(test_framework_with_ei PRIVATE ../src 
../include_deprecated)
     add_celix_bundle_dependencies(test_framework_with_ei simple_test_bundle1 
simple_cxx_bundle)
     celix_target_embedded_bundles(test_framework_with_ei simple_test_bundle1)
     celix_deprecated_utils_headers(test_framework_with_ei)
     target_link_libraries(test_framework_with_ei PRIVATE
-            Celix::framework_obj
+            framework_cut
             Celix::malloc_ei
             Celix::utils_ei
             Celix::asprintf_ei
diff --git 
a/libs/framework/gtest/src/CelixBundleContextBundlesWithErrorTestSuite.cc 
b/libs/framework/gtest/src/CelixBundleContextBundlesWithErrorTestSuite.cc
index c1b533d3..89fa3326 100644
--- a/libs/framework/gtest/src/CelixBundleContextBundlesWithErrorTestSuite.cc
+++ b/libs/framework/gtest/src/CelixBundleContextBundlesWithErrorTestSuite.cc
@@ -82,7 +82,7 @@ TEST_F(CelixBundleContextBundlesWithErrorTestSuite, 
privateLibraryLoadErrorAbort
 }
 
 TEST_F(CelixBundleContextBundlesWithErrorTestSuite, failedToGetLibraryPath) {
-    celix_ei_expect_celix_utils_writeOrCreateString((void 
*)celix_framework_installBundle, 8, nullptr, 2);
+    celix_ei_expect_celix_utils_writeOrCreateString((void 
*)celix_module_loadLibraries, 2, nullptr);
     long bndId = celix_bundleContext_installBundle(ctx, SIMPLE_CXX_BUNDLE_LOC, 
true);
     ASSERT_TRUE(bndId > 0); //bundle is installed, but not started
 
diff --git a/libs/framework/src/bundle_archive_private.h 
b/libs/framework/src/bundle_archive_private.h
index f4974cf5..29e65102 100644
--- a/libs/framework/src/bundle_archive_private.h
+++ b/libs/framework/src/bundle_archive_private.h
@@ -41,9 +41,8 @@ extern "C" {
 
 /**
  * @brief Create bundle archive.
- * @note Symbol exported for testing purposes.
  */
-CELIX_FRAMEWORK_EXPORT celix_status_t 
celix_bundleArchive_create(celix_framework_t* fw, const char *archiveRoot, long 
id, const char *location, bundle_archive_pt *bundle_archive);
+celix_status_t celix_bundleArchive_create(celix_framework_t* fw, const char 
*archiveRoot, long id, const char *location, bundle_archive_pt *bundle_archive);
 
 celix_status_t bundleArchive_destroy(bundle_archive_pt archive);
 
diff --git a/libs/framework/src/bundle_private.h 
b/libs/framework/src/bundle_private.h
index b17df02a..1b3471cf 100644
--- a/libs/framework/src/bundle_private.h
+++ b/libs/framework/src/bundle_private.h
@@ -22,7 +22,6 @@
 
 #include "bundle.h"
 #include "celix_bundle.h"
-#include "celix_framework_export.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -56,12 +55,10 @@ celix_bundle_createFromArchive(celix_framework_t 
*framework, bundle_archive_pt a
 /**
  * @brief Get the bundle archive.
  *
- * @note Symbol export is needed for unit tests.
- *
  * @param[in] bundle The bundle.
  * @return The bundle archive.
  */
-CELIX_FRAMEWORK_EXPORT bundle_archive_t *celix_bundle_getArchive(const 
celix_bundle_t *bundle);
+bundle_archive_t *celix_bundle_getArchive(const celix_bundle_t *bundle);
 
 /**
  * Destroys the bundle.
diff --git a/libs/framework/src/bundle_revision_private.h 
b/libs/framework/src/bundle_revision_private.h
index 7a165339..0eb2106a 100644
--- a/libs/framework/src/bundle_revision_private.h
+++ b/libs/framework/src/bundle_revision_private.h
@@ -50,8 +50,6 @@ struct bundleRevision {
  * Creates a new revision for the given inputFile or location.
  * The location parameter is used to identify the bundle.
  *
- * @note Symbol exported for testing purposes.
- *
  * @param fw The Celix framework where to create the bundle revision.
  * @param root The root for this revision in which the bundle is extracted and 
state is stored.
  * @param location The location associated with the revision.
@@ -62,7 +60,7 @@ struct bundleRevision {
  *             - CELIX_SUCCESS when no errors are encountered.
  *             - CELIX_ENOMEM If allocating memory for 
<code>bundle_revision</code> failed.
  */
-CELIX_FRAMEWORK_EXPORT celix_status_t 
celix_bundleRevision_create(celix_framework_t* fw, const char *root, const char 
*location, manifest_pt manifest, bundle_revision_pt *bundle_revision);
+celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char 
*root, const char *location, manifest_pt manifest, bundle_revision_pt 
*bundle_revision);
 
 bundle_revision_t* bundleRevision_revise(const bundle_revision_t* revision, 
const char* updatedBundleUrl);
 
diff --git a/libs/framework/src/celix_framework_utils_private.h 
b/libs/framework/src/celix_framework_utils_private.h
index 5b123952..f6201929 100644
--- a/libs/framework/src/celix_framework_utils_private.h
+++ b/libs/framework/src/celix_framework_utils_private.h
@@ -23,7 +23,6 @@
 #include <time.h>
 
 #include "celix_framework_utils.h"
-#include "celix_framework_export.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -32,8 +31,6 @@ extern "C" {
 /**
  * @brief Checks whether the provided bundle url is newer than the provided 
time.
  *
- * @note Symbol export is required for unit testing.
- *
  * @param fw Celix framework (used for logging).
  * @param bundleURL The bundle url. Which must be the following:
  * - prefixed with file:// -> url is a file path.
@@ -44,13 +41,11 @@ extern "C" {
  * @return Whether the bundle url is newer than the provided time. Will also 
be true if time is NULL or if the bundleUrl
  *         is an embedded:// url.
  */
-CELIX_FRAMEWORK_EXPORT bool 
celix_framework_utils_isBundleUrlNewerThan(celix_framework_t* fw, const char* 
bundleURL, const struct timespec* time);
+bool celix_framework_utils_isBundleUrlNewerThan(celix_framework_t* fw, const 
char* bundleURL, const struct timespec* time);
 
 /**
  * @brief extracts a bundle for the given cache.
  *
- * @note Symbol export is required for unit testing.
- *
  * @param fw Optional Celix framework (used for logging).
  *           If NULL the result of celix_frameworkLogger_globalLogger() will 
be used for logging.
  * @param extractPath The path to extract the bundle to.
@@ -61,7 +56,7 @@ CELIX_FRAMEWORK_EXPORT bool 
celix_framework_utils_isBundleUrlNewerThan(celix_fra
  *  - no :// -> assuming that the url is a file path (same as with a file:// 
prefix)
  * @return CELIX_SUCCESS is the bundle was correctly extracted.
  */
-CELIX_FRAMEWORK_EXPORT celix_status_t 
celix_framework_utils_extractBundle(celix_framework_t *fw, const char 
*bundleURL,  const char* extractPath);
+celix_status_t celix_framework_utils_extractBundle(celix_framework_t *fw, 
const char *bundleURL,  const char* extractPath);
 
 /**
  * @brief Checks whether the provided bundle url is valid.
@@ -73,15 +68,13 @@ CELIX_FRAMEWORK_EXPORT celix_status_t 
celix_framework_utils_extractBundle(celix_
  *
  *  If a bundle url is invalid, this function will print - on error level - 
why the url is invalid.
  *
- *  @note Symbol export is required for unit testing.
- *
  * @param fw Optional Celix framework (used for logging).
  *           If NULL the result of celix_frameworkLogger_globalLogger() will 
be used for logging.
  * @param bundleURL A bundle url to check.
  * @param silent If true, this function will not write error logs when the 
bundle url is not valid.
  * @return Whether the bundle url is valid.
  */
-CELIX_FRAMEWORK_EXPORT bool 
celix_framework_utils_isBundleUrlValid(celix_framework_t *fw, const char 
*bundleURL, bool silent);
+bool celix_framework_utils_isBundleUrlValid(celix_framework_t *fw, const char 
*bundleURL, bool silent);
 
 #ifdef __cplusplus
 }

Reply via email to