From 51498f27fd9b493ad34558325f7d38bf651014da Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Thu, 5 Nov 2020 12:49:47 +0900 Subject: [PATCH] Add a new method for exporting bundle to argv Adds: - Export() Change-Id: If76969aca0d3cb2cae63326109c6802d4ad9c4f3 Signed-off-by: Hwankyu Jhun --- include/bundle_cpp.h | 7 +++++++ src/bundle_cpp.cc | 16 ++++++++++++++++ unit_tests/src/test_bundle_cpp.cc | 7 +++++++ 3 files changed, 30 insertions(+) diff --git a/include/bundle_cpp.h b/include/bundle_cpp.h index 3b71501..86c8af9 100644 --- a/include/bundle_cpp.h +++ b/include/bundle_cpp.h @@ -318,6 +318,13 @@ class EXPORT_API Bundle final { */ bundle* Detach(); + /** + * @brief Exports bundle to an argument vector. + * @since_tizen 6.5 + * @return The argument vector + */ + std::vector Export() const; + private: class Impl; std::unique_ptr impl_; diff --git a/src/bundle_cpp.cc b/src/bundle_cpp.cc index 4cc9808..a9233dd 100644 --- a/src/bundle_cpp.cc +++ b/src/bundle_cpp.cc @@ -320,4 +320,20 @@ bundle* Bundle::Detach() { return h; } +std::vector Bundle::Export() const { + char** argv = nullptr; + int argc = bundle_export_to_argv(impl_->handle_, &argv); + if (argc < 0) { + LOGE("bundle_export_to_argv() is failed"); + return {}; + } + + std::vector args(1); + for (int i = 1; i < argc; ++i) + args.push_back(argv[i]); + + bundle_free_exported_argv(argc, &argv); + return args; +} + } // namespace tizen_base diff --git a/unit_tests/src/test_bundle_cpp.cc b/unit_tests/src/test_bundle_cpp.cc index 46fca50..54261d1 100644 --- a/unit_tests/src/test_bundle_cpp.cc +++ b/unit_tests/src/test_bundle_cpp.cc @@ -165,3 +165,10 @@ TEST(Bundle, IsEmpty) { bundle.Add("TestKey1", "TestVal"); EXPECT_FALSE(bundle.IsEmpty()); } + +TEST(Bundle, Export) { + Bundle bundle; + bundle.Add("TestKey1", "TestVal1"); + std::vector argv = bundle.Export(); + EXPECT_NE(argv.size(), 0); +} -- 2.7.4