[messaging] Fix bugs occurring when filtering by strings or value ranges 65/211865/4
authorPawel Wasowski <p.wasowski2@samsung.com>
Wed, 27 Feb 2019 19:14:19 +0000 (20:14 +0100)
committerPiotr Kosko <p.kosko@samsung.com>
Thu, 24 Oct 2019 04:56:38 +0000 (04:56 +0000)
The following bugs have been fixed:
- daylight saving time was not taken into account when filtering by
  timestamp attribute with AttributeRangeFilter
- AttributeRangeFilter did not work with null/undefined range limits
- isBetweenTimeRange did not work properly with lower limit close to the
  minimal value of time_t type variables
- filter with an empty string matchValue never matched other strings

[Verification] Subtestcases from TCT tests added in
https://review.tizen.org/gerrit/#/c/test/tct/web/api/+/199159/
that used to fail due to the described bugs now pass.

tct-messaging-sms-tizen-tests pass rate: 100%

This commit has already been reviewed:
https://review.tizen.org/gerrit/#/c/platform/core/api/webapi-plugins/+/200662/
Change-Id of the original change was:
Ia6c2074408e8f4fadd10605d6986b5a2d2d4c93b

Change-Id: I6d28a8d153a34cf54084dae5585cbd7d0e771e4a
Signed-off-by: Pawel Wasowski <p.wasowski2@samsung.com>
packaging/webapi-plugins.pc.in
src/messaging/MsgCommon/AbstractFilter.cpp
src/messaging/MsgCommon/AbstractFilter.h

index e9cade2..747a966 100644 (file)
@@ -1,6 +1,6 @@
 project_name=webapi-plugins
-libdir=__LIB_DIR__
-includedir=__INCLUDE_DIR__
+libdir=/usr/lib/tizen-extensions-crosswalk
+includedir=/usr/include/webapi-plugins/src
 
 Name: ${project_name}
 Description: ${project_name}
index 1eb527a..123128e 100644 (file)
@@ -60,6 +60,10 @@ bool isMatchingString(const std::string& match_value, const std::string& value,
                       AttributeMatchFlag flag) {
   ScopeLogger();
 
+  if (match_value.empty() && value.empty()) {
+    return true;
+  }
+
   switch (flag) {
     case AttributeMatchFlag::kEndsWith: {
       if (match_value.empty()) {
@@ -189,24 +193,18 @@ bool FilterUtils::isAnyStringMatching(const std::string& key,
 bool FilterUtils::isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& initial_value,
                                      tizen::AnyPtr& end_value) {
   ScopeLogger();
-  time_t from_time = 0;
 
-  if (initial_value && !initial_value->isNullOrUndefined()) {
-    struct tm ftime = *initial_value->toDateTm();
-    from_time = mktime(&ftime);
-  } else {
-    LoggerE("initialValue is not Time!");
+  if (!initial_value || !end_value) {
+    LoggerD("initial_value is %snull. end_value is %snull",
+            initial_value ? "NOT " : "", end_value ? "NOT " : "");
     return false;
   }
 
-  time_t to_time = 0;
-  if (end_value && !end_value->isNullOrUndefined()) {
-    struct tm ttime = *end_value->toDateTm();
-    to_time = mktime(&ttime);
-  } else {
-    LoggerE("endValue is not Time!");
-    return false;
-  }
+  time_t from_time = initial_value->isNullOrUndefined() ?
+                      std::numeric_limits<time_t>::min() : initial_value->toTimeT();
+
+  time_t to_time = end_value->isNullOrUndefined() ?
+                    std::numeric_limits<time_t>::max() : end_value->toTimeT();
 
   bool is_in_range = FilterUtils::isBetweenTimeRange(time_stamp, from_time, to_time);
 
index c4eea0e..2d0bd37 100644 (file)
@@ -20,6 +20,7 @@
 #include <memory>
 #include <sstream>
 #include <vector>
+#include <time.h>
 //#include <JSArray.h>
 
 #include "Any.h"
@@ -94,8 +95,8 @@ bool isTimeStampInRange(const time_t& time_stamp, tizen::AnyPtr& initial_value,
                         tizen::AnyPtr& end_value);
 bool isInRange(const unsigned long messageCount, const unsigned long initial_value,
                const unsigned long end_value);
-inline bool isBetweenTimeRange(const time_t current, const time_t from, const time_t to) {
-  return ((current - from) >= 0) && ((to - current) >= 0);
+inline bool isBetweenTimeRange(const time_t timestamp, const time_t from, const time_t to) {
+  return (difftime(timestamp, from) >= 0.0) && (difftime(to, timestamp) >= 0.0);
 }
 
 /*