This is an automated email from the ASF dual-hosted git repository. pengzheng pushed a commit to branch feature/556-osgi-uninstall in repository https://gitbox.apache.org/repos/asf/celix.git
commit be8461b71dbc1473335d47d136e970a337d38188 Author: PengZheng <[email protected]> AuthorDate: Tue May 30 19:37:54 2023 +0800 Add more tests for bundle archive. --- .../BundleArchiveWithErrorInjectionTestSuite.cc | 29 +++++++++++++++++++++- libs/framework/src/bundle_revision.c | 4 ++- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc index 86bc39d3..6fc2118f 100644 --- a/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc +++ b/libs/framework/gtest/src/BundleArchiveWithErrorInjectionTestSuite.cc @@ -19,9 +19,11 @@ #include <gtest/gtest.h> +#include <unistd.h> + #include "celix_constants.h" #include "celix_file_utils.h" -#include "celix_framework_utils.h" +#include "celix_framework_utils_private.h" #include "celix_log.h" #include "celix_properties_ei.h" #include "celix_utils_ei.h" @@ -33,6 +35,7 @@ #include "bundle_revision_private.h" #include "framework_private.h" #include "malloc_ei.h" +#include "manifest.h" class BundleArchiveWithErrorInjectionTestSuite : public ::testing::Test { public: @@ -177,6 +180,7 @@ class CelixBundleArchiveErrorInjectionTestSuite : public ::testing::Test { celix_ei_expect_celix_utils_deleteDirectory(nullptr, 0, CELIX_SUCCESS); celix_ei_expect_celix_utils_writeOrCreateString(nullptr, 0, nullptr); celix_ei_expect_celix_utils_extractZipData(nullptr, 0, CELIX_SUCCESS); + celix_ei_expect_celix_utils_extractZipFile(nullptr, 0, CELIX_SUCCESS); } struct celix_framework fw {}; }; @@ -240,6 +244,29 @@ TEST_F(CelixBundleArchiveErrorInjectionTestSuite, ArchiveReviseErrorTest) { EXPECT_EQ(CELIX_ENOMEM, bundleArchive_revise(archive, SIMPLE_TEST_BUNDLE1_LOCATION, nullptr)); EXPECT_EQ(CELIX_SUCCESS, bundleArchive_destroy(archive)); EXPECT_EQ(CELIX_SUCCESS, celix_utils_deleteDirectory(TEST_ARCHIVE_ROOT, nullptr)); + teardownErrorInjectors(); + + // manifest clone failure + EXPECT_EQ(CELIX_SUCCESS, + celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive)); + EXPECT_NE(nullptr, archive); + celix_ei_expect_malloc((void*)manifest_clone, 1, nullptr); + EXPECT_EQ(CELIX_ENOMEM, bundleArchive_revise(archive, SIMPLE_TEST_BUNDLE1_LOCATION, nullptr)); + EXPECT_EQ(CELIX_SUCCESS, bundleArchive_destroy(archive)); + EXPECT_EQ(CELIX_SUCCESS, celix_utils_deleteDirectory(TEST_ARCHIVE_ROOT, nullptr)); + teardownErrorInjectors(); + + // extract zip data failure + EXPECT_EQ(CELIX_SUCCESS, + celix_bundleArchive_create(&fw, TEST_ARCHIVE_ROOT, 1, SIMPLE_TEST_BUNDLE1_LOCATION, &archive)); + EXPECT_NE(nullptr, archive); + celix_ei_expect_celix_utils_extractZipFile((void*)celix_framework_utils_extractBundle, 1, CELIX_FILE_IO_EXCEPTION); + usleep(10000); // sleep to ensure that the last modified time is different (otherwise the revision is not updated + celix_utils_touch(SIMPLE_TEST_BUNDLE1_LOCATION); + EXPECT_EQ(CELIX_FILE_IO_EXCEPTION, bundleArchive_revise(archive, SIMPLE_TEST_BUNDLE1_LOCATION, nullptr)); + EXPECT_EQ(CELIX_SUCCESS, bundleArchive_destroy(archive)); + EXPECT_EQ(CELIX_SUCCESS, celix_utils_deleteDirectory(TEST_ARCHIVE_ROOT, nullptr)); + teardownErrorInjectors(); EXPECT_EQ(CELIX_SUCCESS, celix_bundleCache_destroy(cache)); } diff --git a/libs/framework/src/bundle_revision.c b/libs/framework/src/bundle_revision.c index febbeb41..b0bdbbde 100644 --- a/libs/framework/src/bundle_revision.c +++ b/libs/framework/src/bundle_revision.c @@ -55,7 +55,9 @@ celix_status_t celix_bundleRevision_create(celix_framework_t* fw, const char *ro bundle_revision_t* bundleRevision_revise(const bundle_revision_t* rev, const char* updatedBundleUrl) { bundle_revision_pt newRev = NULL; manifest_pt clonedManifest = manifest_clone(rev->manifest); - celix_bundleRevision_create(rev->fw, rev->root, updatedBundleUrl, clonedManifest, &newRev); + if (clonedManifest) { + celix_bundleRevision_create(rev->fw, rev->root, updatedBundleUrl, clonedManifest, &newRev); + } return newRev; }
