From: jihoi kim Date: Wed, 24 Jul 2024 01:35:04 +0000 (+0900) Subject: Add bundle equal comparision operator X-Git-Tag: accepted/tizen/unified/20240727.112750~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F63%2F314963%2F5;p=platform%2Fcore%2Fbase%2Fbundle.git Add bundle equal comparision operator - 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 --- diff --git a/src/bundle/bundle_cpp.cc b/src/bundle/bundle_cpp.cc index c45f405..bc85d6d 100644 --- a/src/bundle/bundle_cpp.cc +++ b/src/bundle/bundle_cpp.cc @@ -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::GetKeys() { diff --git a/src/bundle/include/bundle_cpp.h b/src/bundle/include/bundle_cpp.h index 997da06..a407e45 100644 --- a/src/bundle/include/bundle_cpp.h +++ b/src/bundle/include/bundle_cpp.h @@ -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 diff --git a/src/bundle/include/bundle_internal.h b/src/bundle/include/bundle_internal.h index b489adb..3bde4b2 100644 --- a/src/bundle/include/bundle_internal.h +++ b/src/bundle/include/bundle_internal.h @@ -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 diff --git a/tests/bundle_unittests/src/test_bundle_cpp.cc b/tests/bundle_unittests/src/test_bundle_cpp.cc index 4e82b1e..ad69876 100644 --- a/tests/bundle_unittests/src/test_bundle_cpp.cc +++ b/tests/bundle_unittests/src/test_bundle_cpp.cc @@ -224,3 +224,21 @@ TEST(Bundle, CopyAndExport) { std::vector 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"}})); +}