Add bundle equal comparision operator 63/314963/5
authorjihoi kim <jihoi.kim@samsung.com>
Wed, 24 Jul 2024 01:35:04 +0000 (10:35 +0900)
committerjihoi kim <jihoi.kim@samsung.com>
Wed, 24 Jul 2024 08:15:40 +0000 (17:15 +0900)
- Create 'Bundle::operator ==' and 'Bundle::opeator !='
- Create TEST(Bundle, EqualOp) for unittest
- Remove unnecessary ternary operator
- Fix typo in 'bundle_internal.h'

Change-Id: Id00b08d91b4c3cf91f5d2abf0e2e596cbf6badd2
Signed-off-by: jihoi kim <jihoi.kim@samsung.com>
src/bundle/bundle_cpp.cc
src/bundle/include/bundle_cpp.h
src/bundle/include/bundle_internal.h
tests/bundle_unittests/src/test_bundle_cpp.cc

index c45f405..bc85d6d 100644 (file)
@@ -210,8 +210,16 @@ Bundle& Bundle::operator = (Bundle&& b) noexcept {
   return *this;
 }
 
+bool Bundle::operator == (const Bundle& b) const {
+  return (bundle_compare(impl_->handle_, b.impl_->handle_) == 0);
+}
+
+bool Bundle::operator != (const Bundle& b) const {
+  return !(*this == b);
+}
+
 bool Bundle::IsEmpty() const noexcept {
-  return (bundle_get_count(impl_->handle_) == 0) ? true : false;
+  return (bundle_get_count(impl_->handle_) == 0);
 }
 
 std::vector<Bundle::KeyInfo> Bundle::GetKeys() {
index 997da06..a407e45 100644 (file)
@@ -203,6 +203,22 @@ class EXPORT_API Bundle final {
   Bundle& operator = (Bundle&& b) noexcept;
 
   /**
+   * @brief Equal comparision.
+   * @since_tizen 9.0
+   * @param[in] b The object to compare
+   * @return true if lhs and rhs are identical
+   */
+  bool operator == (const Bundle& b) const;
+
+  /**
+   * @brief Unequal comparision.
+   * @since_tizen 9.0
+   * @param[in] b The object to compare
+   * @return true if lhs and rhs are not identical
+   */
+  bool operator != (const Bundle& b) const;
+
+  /**
    * @brief Check the bundle is empty or not.
    * @since_tizen 6.0
    * @return true if the bundle is empty
index b489adb..3bde4b2 100644 (file)
@@ -371,7 +371,7 @@ int bundle_set_str_array_element(bundle *b, const char *key, const unsigned int
 int bundle_to_json(bundle *b, char **json);
 
 /**
- * @breif Creates a bundle object from json.
+ * @brief Creates a bundle object from json.
  * @since_tizen 3.0
  * @remarks This function only supports the string type and the string array type.
  * @param[in] json The json data
@@ -395,7 +395,7 @@ int bundle_to_json(bundle *b, char **json);
 int bundle_from_json(const char *json, bundle **b);
 
 /**
- * @breif Compares the bundle 1, 2.
+ * @brief Compares the bundle 1, 2.
  * @since_tizen 3.0
  * @param[in] b1 The bundle object
  * @param[in] b2 The bundle object
index 4e82b1e..ad69876 100644 (file)
@@ -224,3 +224,21 @@ TEST(Bundle, CopyAndExport) {
   std::vector<std::string> argv2 = copy_bundle.Export();
   EXPECT_EQ(argv, argv2);
 }
+
+TEST(Bundle, EqualOp) {
+  Bundle b1;
+  Bundle b2;
+  EXPECT_EQ(b1, b2);
+
+  b1.Add("TestKey1", "TestVal1");
+  b2.Add("TestKey1", "TestVal1");
+  EXPECT_EQ(b1, b2);
+
+  b1.Add("TestKey2", "TestVal2");
+  EXPECT_NE(b1, b2);
+
+  b2.Add("TestKey2", "DiffVal2");
+  EXPECT_NE(b1, b2);
+
+  EXPECT_EQ(b1, (Bundle{{"TestKey1", "TestVal1"},{"TestKey2", "TestVal2"}}));
+}