Add a new method for exporting bundle to argv 92/246892/3
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 5 Nov 2020 03:49:47 +0000 (12:49 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Thu, 5 Nov 2020 06:06:29 +0000 (15:06 +0900)
Adds:
 - Export()

Change-Id: If76969aca0d3cb2cae63326109c6802d4ad9c4f3
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/bundle_cpp.h
src/bundle_cpp.cc
unit_tests/src/test_bundle_cpp.cc

index 3b71501..86c8af9 100644 (file)
@@ -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<std::string> Export() const;
+
  private:
   class Impl;
   std::unique_ptr<Impl> impl_;
index 4cc9808..a9233dd 100644 (file)
@@ -320,4 +320,20 @@ bundle* Bundle::Detach() {
   return h;
 }
 
+std::vector<std::string> 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<std::string> 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
index 46fca50..54261d1 100644 (file)
@@ -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<std::string> argv = bundle.Export();
+  EXPECT_NE(argv.size(), 0);
+}