celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject celix git commit: CELIX-327: add support for greather-than and lesser-than operators in filter implementation
Date Tue, 15 Dec 2015 14:09:45 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 67a7170d7 -> 135ea22a9


CELIX-327: add support for greather-than and lesser-than operators in filter implementation


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/135ea22a
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/135ea22a
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/135ea22a

Branch: refs/heads/develop
Commit: 135ea22a97c129afad8bd10ddfa772ce31446128
Parents: 67a7170
Author: Bjoern Petri <bpetri@apache.org>
Authored: Tue Dec 15 15:09:07 2015 +0100
Committer: Bjoern Petri <bpetri@apache.org>
Committed: Tue Dec 15 15:09:07 2015 +0100

----------------------------------------------------------------------
 framework/private/include/filter_private.h |  2 ++
 framework/private/src/filter.c             | 34 ++++++++++++++++++++++---
 framework/private/test/filter_test.cpp     | 29 +++++++++++++++++++++
 3 files changed, 61 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/135ea22a/framework/private/include/filter_private.h
----------------------------------------------------------------------
diff --git a/framework/private/include/filter_private.h b/framework/private/include/filter_private.h
index bf3139f..548a6d2 100644
--- a/framework/private/include/filter_private.h
+++ b/framework/private/include/filter_private.h
@@ -36,7 +36,9 @@ typedef enum operand
 	EQUAL,
 	APPROX,
 	GREATER,
+    GREATEREQUAL,
 	LESS,
+	LESSEQUAL,
 	PRESENT,
 	SUBSTRING,
 	AND,

http://git-wip-us.apache.org/repos/asf/celix/blob/135ea22a/framework/private/src/filter.c
----------------------------------------------------------------------
diff --git a/framework/private/src/filter.c b/framework/private/src/filter.c
index 834280d..bf632ff 100644
--- a/framework/private/src/filter.c
+++ b/framework/private/src/filter.c
@@ -228,22 +228,38 @@ filter_pt filter_parseItem(char * filterString, int * pos) {
 			if (filterString[*pos + 1] == '=') {
 				filter_pt filter = (filter_pt) malloc(sizeof(*filter));
 				*pos += 2;
-				filter->operand = GREATER;
+				filter->operand = GREATEREQUAL;
 				filter->attribute = attr;
 				filter->value = filter_parseValue(filterString, pos);
 				return filter;
 			}
+			else {
+                filter_pt filter = (filter_pt) malloc(sizeof(*filter));
+                *pos += 1;
+                filter->operand = GREATER;
+                filter->attribute = attr;
+                filter->value = filter_parseValue(filterString, pos);
+                return filter;
+			}
 			break;
 		}
 		case '<': {
 			if (filterString[*pos + 1] == '=') {
 				filter_pt filter = (filter_pt) malloc(sizeof(*filter));
 				*pos += 2;
-				filter->operand = LESS;
+				filter->operand = LESSEQUAL;
 				filter->attribute = attr;
 				filter->value = filter_parseValue(filterString, pos);
 				return filter;
 			}
+			else {
+                filter_pt filter = (filter_pt) malloc(sizeof(*filter));
+                *pos += 1;
+                filter->operand = LESS;
+                filter->attribute = attr;
+                filter->value = filter_parseValue(filterString, pos);
+                return filter;
+			}
 			break;
 		}
 		case '=': {
@@ -459,7 +475,9 @@ celix_status_t filter_match(filter_pt filter, properties_pt properties,
bool *re
 		case SUBSTRING :
 		case EQUAL :
 		case GREATER :
+        case GREATEREQUAL :
 		case LESS :
+        case LESSEQUAL :
 		case APPROX : {
 			char * value = (properties == NULL) ? NULL: properties_get(properties, filter->attribute);
 
@@ -548,13 +566,21 @@ celix_status_t filter_compareString(OPERAND operand, char * string,
void * value
 			return CELIX_SUCCESS;
 		}
 		case GREATER: {
-			*result = (strcmp(string, (char *) value2) >= 0);
+			*result = (strcmp(string, (char *) value2) > 0);
 			return CELIX_SUCCESS;
 		}
+        case GREATEREQUAL: {
+            *result = (strcmp(string, (char *) value2) >= 0);
+            return CELIX_SUCCESS;
+        }
 		case LESS: {
-			*result = (strcmp(string, (char *) value2) <= 0);
+			*result = (strcmp(string, (char *) value2) < 0);
 			return CELIX_SUCCESS;
 		}
+        case LESSEQUAL: {
+            *result = (strcmp(string, (char *) value2) <= 0);
+            return CELIX_SUCCESS;
+        }
 		case AND:
 		case NOT:
 		case OR:

http://git-wip-us.apache.org/repos/asf/celix/blob/135ea22a/framework/private/test/filter_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/filter_test.cpp b/framework/private/test/filter_test.cpp
index e6a6930..2ed7485 100644
--- a/framework/private/test/filter_test.cpp
+++ b/framework/private/test/filter_test.cpp
@@ -51,6 +51,8 @@ TEST_GROUP(filter) {
 	void teardown() {
 		mock().checkExpectations();
 		mock().clear();
+
+		free(logger);
 	}
 };
 
@@ -62,5 +64,32 @@ TEST(filter, create) {
 }
 
 
+TEST(filter, create1) {
+    char filterStr[] = "(key<value)";
+    filter_pt filter = filter_create(filterStr);
+
+    STRCMP_EQUAL(filterStr, filter->filterStr);
+}
+
+TEST(filter, create2) {
+    char filterStr[] = "(key>value)";
+    filter_pt filter = filter_create(filterStr);
+
+    STRCMP_EQUAL(filterStr, filter->filterStr);
+}
+
+TEST(filter, create3) {
+    char filterStr[] = "(key<=value)";
+    filter_pt filter = filter_create(filterStr);
+
+    STRCMP_EQUAL(filterStr, filter->filterStr);
+}
+
+TEST(filter, create4) {
+    char filterStr[] = "(key>=value)";
+    filter_pt filter = filter_create(filterStr);
+
+    STRCMP_EQUAL(filterStr, filter->filterStr);
+}
 
 


Mime
View raw message