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

pnoltes pushed a commit to branch feature/685-refactor-manifest-format
in repository https://gitbox.apache.org/repos/asf/celix.git

commit 7b4b0cc56d0198935e848b0e2de6e46146d3e847
Author: Pepijn Noltes <[email protected]>
AuthorDate: Fri Jul 26 16:19:43 2024 +0200

    gh-685: Add additional manifest tests
---
 .../gtest/src/ManifestErrorInjectionTestSuite.cc   | 15 +++++++++-
 libs/framework/gtest/src/ManifestTestSuite.cc      | 32 ++++++++++++++++++++++
 libs/framework/src/celix_bundle_manifest.c         | 16 +++++------
 libs/utils/include/celix_err.h                     |  8 +++---
 4 files changed, 58 insertions(+), 13 deletions(-)

diff --git a/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc 
b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc
index ab7114e08..7813efe63 100644
--- a/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc
+++ b/libs/framework/gtest/src/ManifestErrorInjectionTestSuite.cc
@@ -46,5 +46,18 @@ TEST_F(ManifestErrorInjectionTestSuite, 
NoMemoryForManifestCreateTest) {
     celix_status_t status = celix_bundleManifest_create(attributes, &manifest);
     EXPECT_EQ(CELIX_ENOMEM, status);
     EXPECT_EQ(nullptr, manifest);
-    celix_err_printErrors(stdout, "Errors are expected[", "]\n");
+    celix_err_printErrors(stdout, "Errors are expected [", "]\n");
+}
+
+TEST_F(ManifestErrorInjectionTestSuite, 
NoMemoryForFrameworkManifestCreateTest) {
+    celix_bundle_manifest_t* manifest = nullptr;
+    
celix_ei_expect_celix_properties_create((void*)celix_bundleManifest_createFrameworkManifest,
 0, nullptr);
+    auto status = celix_bundleManifest_createFrameworkManifest(&manifest);
+    EXPECT_EQ(CELIX_ENOMEM, status);
+
+    
celix_ei_expect_celix_properties_set((void*)celix_bundleManifest_createFrameworkManifest,
 0, CELIX_ENOMEM, 3);
+    status = celix_bundleManifest_createFrameworkManifest(&manifest);
+    EXPECT_EQ(CELIX_ENOMEM, status);
+
+    celix_err_printErrors(stdout, "Errors are expected [", "]\n");
 }
diff --git a/libs/framework/gtest/src/ManifestTestSuite.cc 
b/libs/framework/gtest/src/ManifestTestSuite.cc
index 8f10dfa16..73fe5f9eb 100644
--- a/libs/framework/gtest/src/ManifestTestSuite.cc
+++ b/libs/framework/gtest/src/ManifestTestSuite.cc
@@ -24,6 +24,7 @@
 #include "celix_err.h"
 #include "celix_properties.h"
 #include "celix_stdlib_cleanup.h"
+#include "celix_framework_version.h"
 
 class ManifestTestSuite : public ::testing::Test {
   public:
@@ -60,6 +61,15 @@ TEST_F(ManifestTestSuite, CreateManifestTest) {
     EXPECT_EQ(4, 
celix_properties_size(celix_bundleManifest_getAttributes(manifest)));
 }
 
+TEST_F(ManifestTestSuite, InvalidArgumentTest) {
+    celix_bundle_manifest_t* man = nullptr;
+    auto status = celix_bundleManifest_create(nullptr, &man);
+    EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status);
+
+    status = celix_bundleManifest_createFromFile("invalid-file", &man);
+    EXPECT_EQ(CELIX_FILE_IO_EXCEPTION, status);
+}
+
 TEST_F(ManifestTestSuite, MissingOrInvalidMandatoryManifestAttributesTest) {
     //Given an empty properties set
     celix_properties_t *properties = celix_properties_create();
@@ -196,3 +206,25 @@ TEST_F(ManifestTestSuite, GetBuiltinAttributes) {
         EXPECT_STREQ("my_group", 
celix_bundleManifest_getBundleGroup(manifest2));
         EXPECT_STREQ("my_description", 
celix_bundleManifest_getBundleDescription(manifest2));
 }
+
+TEST_F(ManifestTestSuite, CreateFrameworkManifestTest) {
+    //When creating a framework manifest
+        celix_autoptr(celix_bundle_manifest_t) manifest = nullptr;
+        celix_status_t status = 
celix_bundleManifest_createFrameworkManifest(&manifest);
+
+        //When the creation is successful
+        ASSERT_EQ(CELIX_SUCCESS, status);
+
+        //And the manifest contains at least the mandatory attributes for a 
framework bundle
+        
EXPECT_GE(celix_properties_size(celix_bundleManifest_getAttributes(manifest)), 
4);
+        auto manifestVersion = 
celix_bundleManifest_getManifestVersion(manifest);
+        ASSERT_NE(nullptr, manifestVersion);
+        auto bundleVersion = celix_bundleManifest_getBundleVersion(manifest);
+        ASSERT_NE(nullptr, bundleVersion);
+        celix_autofree char* mv = celix_version_toString(manifestVersion);
+        celix_autofree char* bv = celix_version_toString(bundleVersion);
+        EXPECT_STREQ("2.0.0", mv);
+        EXPECT_STREQ(CELIX_FRAMEWORK_VERSION, bv);
+        EXPECT_STREQ("Apache Celix Framework", 
celix_bundleManifest_getBundleName(manifest));
+        EXPECT_STREQ("apache_celix_framework", 
celix_bundleManifest_getBundleSymbolicName(manifest));
+}
diff --git a/libs/framework/src/celix_bundle_manifest.c 
b/libs/framework/src/celix_bundle_manifest.c
index 38330e578..91eee7334 100644
--- a/libs/framework/src/celix_bundle_manifest.c
+++ b/libs/framework/src/celix_bundle_manifest.c
@@ -149,11 +149,11 @@ static celix_status_t 
celix_bundleManifest_setMandatoryAttributes(celix_bundle_m
     celix_autoptr(celix_version_t) manifestVersion = NULL;
     celix_status_t getVersionStatus =
         celix_properties_getAsVersion(manifest->attributes, 
CELIX_BUNDLE_MANIFEST_VERSION, NULL, &manifestVersion);
-    CELIX_ERR_RET_IF_ENOMEM(getVersionStatus);
+    CELIX_RETURN_IF_ENOMEM(getVersionStatus);
 
     celix_autoptr(celix_version_t) bundleVersion = NULL;
     getVersionStatus = celix_properties_getAsVersion(manifest->attributes, 
CELIX_BUNDLE_VERSION, NULL, &bundleVersion);
-    CELIX_ERR_RET_IF_ENOMEM(getVersionStatus);
+    CELIX_RETURN_IF_ENOMEM(getVersionStatus);
 
     celix_status_t status = CELIX_SUCCESS;
     if (!bundleName) {
@@ -191,9 +191,9 @@ static celix_status_t 
celix_bundleManifest_setMandatoryAttributes(celix_bundle_m
 
     if (status == CELIX_SUCCESS) {
         manifest->symbolicName = celix_utils_strdup(symbolicName);
-        CELIX_ERR_RET_IF_NULL(manifest->symbolicName);
+        CELIX_RETURN_IF_NULL(manifest->symbolicName);
         manifest->bundleName = celix_utils_strdup(bundleName);
-        CELIX_ERR_RET_IF_NULL(manifest->bundleName);
+        CELIX_RETURN_IF_NULL(manifest->bundleName);
         manifest->manifestVersion = celix_steal_ptr(manifestVersion);
         manifest->bundleVersion = celix_steal_ptr(bundleVersion);
     }
@@ -208,27 +208,27 @@ static celix_status_t 
celix_bundleManifest_setOptionalAttributes(celix_bundle_ma
     celix_autofree char* activatorLib = NULL;
     if (lib) {
         activatorLib = celix_utils_strdup(lib);
-        CELIX_ERR_RET_IF_NULL(activatorLib);
+        CELIX_RETURN_IF_NULL(activatorLib);
     }
 
     const char* group = celix_properties_getAsString(manifest->attributes, 
CELIX_BUNDLE_GROUP, NULL);
     celix_autofree char* bundleGroup = NULL;
     if (group) {
         bundleGroup = celix_utils_strdup(group);
-        CELIX_ERR_RET_IF_NULL(bundleGroup);
+        CELIX_RETURN_IF_NULL(bundleGroup);
     }
 
     const char* desc = celix_properties_getAsString(manifest->attributes, 
CELIX_BUNDLE_DESCRIPTION, NULL);
     celix_autofree char* description = NULL;
     if (desc) {
         description = celix_utils_strdup(desc);
-        CELIX_ERR_RET_IF_NULL(description);
+        CELIX_RETURN_IF_NULL(description);
     }
 
     celix_autoptr(celix_array_list_t) privateLibraries = NULL;
     celix_status_t getStatus = celix_properties_getAsStringArrayList(
         manifest->attributes, CELIX_BUNDLE_PRIVATE_LIBRARIES, NULL, 
&privateLibraries);
-    CELIX_ERR_RET_IF_ENOMEM(getStatus);
+    CELIX_RETURN_IF_ENOMEM(getStatus);
     if (celix_properties_hasKey(manifest->attributes, 
CELIX_BUNDLE_PRIVATE_LIBRARIES) && !privateLibraries) {
         celix_err_pushf(CELIX_BUNDLE_PRIVATE_LIBRARIES " is not a string 
array. Got: '%s'",
                         celix_properties_get(manifest->attributes, 
CELIX_BUNDLE_PRIVATE_LIBRARIES, NULL));
diff --git a/libs/utils/include/celix_err.h b/libs/utils/include/celix_err.h
index d617dcec0..51f30f435 100644
--- a/libs/utils/include/celix_err.h
+++ b/libs/utils/include/celix_err.h
@@ -95,9 +95,9 @@ CELIX_UTILS_EXPORT void celix_err_printErrors(FILE* stream, 
const char* prefix,
 CELIX_UTILS_EXPORT int celix_err_dump(char* buf, size_t size, const char* 
prefix, const char* postfix);
 
 /*!
- * Helper macro that return with ENOMEM if the status is ENOMEM and logs an 
"<func>: Out of memory" error to celix_err.
+ * Helper macro that returns with ENOMEM if the status is ENOMEM and logs an 
"<func>: Out of memory" error to celix_err.
  */
-#define CELIX_ERR_RET_IF_ENOMEM(status)                                        
                                        \
+#define CELIX_RETURN_IF_ENOMEM(status)                                         
                                        \
     do {                                                                       
                                        \
         if ((status) == ENOMEM) {                                              
                                        \
             celix_err_pushf("%s: Out of memory", __func__);                    
                                        \
@@ -106,9 +106,9 @@ CELIX_UTILS_EXPORT int celix_err_dump(char* buf, size_t 
size, const char* prefix
     } while (0)
 
 /*!
- * Helper macro that return with ENOMEM if the arg is NULL and logs an 
"<func>: Out of memory" error to celix_err.
+ * Helper macro that returns with ENOMEM if the arg is NULL and logs an 
"<func>: Out of memory" error to celix_err.
  */
-#define CELIX_ERR_RET_IF_NULL(arg)                                             
                                        \
+#define CELIX_RETURN_IF_NULL(arg)                                              
                                        \
     do {                                                                       
                                        \
         if ((arg) == NULL) {                                                   
                                        \
             celix_err_pushf("%s: Out of memory", __func__);                    
                                        \

Reply via email to