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-318: Added some negative dfi unit tests
Date Mon, 14 Dec 2015 14:28:45 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 8d4d3e9de -> 53bc7bd83


CELIX-318: Added some negative dfi unit tests


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

Branch: refs/heads/develop
Commit: 53bc7bd830e50531a89319da483ef959ca0eab33
Parents: 8d4d3e9
Author: Bjoern Petri <bpetri@apache.org>
Authored: Mon Dec 14 15:27:47 2015 +0100
Committer: Bjoern Petri <bpetri@apache.org>
Committed: Mon Dec 14 15:27:47 2015 +0100

----------------------------------------------------------------------
 dfi/private/src/dyn_common.c             | 12 +++---
 dfi/private/test/dyn_function_tests.cpp  | 21 ++++++++++
 dfi/private/test/dyn_interface_tests.cpp | 58 +++++++++++++++++++++++++++
 dfi/private/test/dyn_message_tests.cpp   | 39 ++++++++++++++++++
 4 files changed, 124 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/53bc7bd8/dfi/private/src/dyn_common.c
----------------------------------------------------------------------
diff --git a/dfi/private/src/dyn_common.c b/dfi/private/src/dyn_common.c
index 6934e17..00c3d3a 100644
--- a/dfi/private/src/dyn_common.c
+++ b/dfi/private/src/dyn_common.c
@@ -80,16 +80,17 @@ int dynCommon_parseNameAlsoAccept(FILE *stream, const char *acceptedChars,
char
 }
 
 int dynCommon_parseNameValue(FILE *stream, char **outName, char **outValue) {
-    int status = OK;
+    int status;
     char *name = NULL;
     char *value = NULL;
-    const char *valueAcceptedChars = ".<>{}[]?;:~!@#$%^&*()_+-=,./\\'\"";
 
     status = dynCommon_parseName(stream, &name);
     if (status == OK) {
         status = dynCommon_eatChar(stream, '=');
     }
     if (status == OK) {
+        const char *valueAcceptedChars = ".<>{}[]?;:~!@#$%^&*()_+-=,./\\'\"";
+
         status = dynCommon_parseNameAlsoAccept(stream, valueAcceptedChars, &value); //NOTE
use different more lenient function e.g. only stop at '\n' ?
     }
 
@@ -113,7 +114,7 @@ int dynCommon_eatChar(FILE *stream, int expected) {
     int c = fgetc(stream);
     if (c != expected) {
         status = ERROR;
-        LOG_ERROR("Error parsing, expected token '%c' got '%c' at position %li", expected,
loc);
+        LOG_ERROR("Error parsing, expected token '%c' got '%c' at position %li", expected,
c, loc);
     }
     return status;
 }
@@ -134,10 +135,9 @@ static bool dynCommon_charIn(int c, const char *acceptedChars) {
 }
 
 void dynCommon_clearNamValHead(struct namvals_head *head) {
-    struct namval_entry *tmp = NULL;
     struct namval_entry *entry = TAILQ_FIRST(head);
     while (entry != NULL) {
-        tmp = entry;
+        struct namval_entry *tmp = entry;
 
         if (entry->name != NULL) {
             free(entry->name);
@@ -148,4 +148,4 @@ void dynCommon_clearNamValHead(struct namvals_head *head) {
         entry = TAILQ_NEXT(entry, entries);
         free(tmp);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/53bc7bd8/dfi/private/test/dyn_function_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_function_tests.cpp b/dfi/private/test/dyn_function_tests.cpp
index 2279331..1b65be8 100644
--- a/dfi/private/test/dyn_function_tests.cpp
+++ b/dfi/private/test/dyn_function_tests.cpp
@@ -220,6 +220,22 @@ extern "C" {
 
         dynFunction_destroy(dynFunc);
     }
+
+    #define INVALID_FUNC_DESCRIPTOR "example$[D)V"//$ is an invalid symbol, missing (
+
+    static void test_invalidDynFunc(void) {
+        dyn_function_type *dynFunc = NULL;
+        int rc = dynFunction_parseWithStr(INVALID_FUNC_DESCRIPTOR, NULL, &dynFunc);
+        CHECK_EQUAL(2, rc); //Mem error
+    }
+
+    #define INVALID_FUNC_TYPE_DESCRIPTOR "example(H)A"//H and A are invalid types
+
+    static void test_invalidDynFuncType(void) {
+        dyn_function_type *dynFunc = NULL;
+        int rc = dynFunction_parseWithStr(INVALID_FUNC_TYPE_DESCRIPTOR, NULL, &dynFunc);
+        CHECK_EQUAL(3, rc); //Parse Error
+    }
 }
 
 TEST_GROUP(DynFunctionTests) {
@@ -250,3 +266,8 @@ TEST(DynFunctionTests, DynFuncTest3) {
 TEST(DynFunctionTests, DynFuncTest4) {
     test_example4();
 }
+
+TEST(DynFunctionTests, InvalidDynFuncTest) {
+    test_invalidDynFunc();
+    test_invalidDynFuncType();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/53bc7bd8/dfi/private/test/dyn_interface_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_interface_tests.cpp b/dfi/private/test/dyn_interface_tests.cpp
index 83afb9b..08eb6f5 100644
--- a/dfi/private/test/dyn_interface_tests.cpp
+++ b/dfi/private/test/dyn_interface_tests.cpp
@@ -96,6 +96,60 @@ extern "C" {
         dynInterface_destroy(dynIntf);
     }
 
+    static void testInvalid(void) {
+        int status = 0;
+
+        /* Invalid field */
+        dyn_interface_type *dynIntf = NULL;
+        FILE *desc = fopen("descriptors/invalids/invalid.descriptor", "r");
+        assert(desc != NULL);
+        status = dynInterface_parse(desc, &dynIntf);
+        CHECK_EQUAL(1, status); //Test fails because of a space at the end of the name
+        fclose(desc);
+        dynInterface_destroy(dynIntf);
+
+        /* Header without Version */
+        desc = fopen("descriptors/invalids/noVersion.descriptor", "r");
+        status = dynInterface_parse(desc, &dynIntf);
+        CHECK_EQUAL(1, status); //Test fails because of missing version field in header section
+        fclose(desc);
+        dynInterface_destroy(dynIntf);
+
+        /* Invalid section */
+        desc = fopen("descriptors/invalids/invalidSection.descriptor", "r");
+        status = dynInterface_parse(desc, &dynIntf);
+        CHECK_EQUAL(1, status); //Test fails because of unknown section type
+        fclose(desc);
+        dynInterface_destroy(dynIntf);
+
+        /* Invalid return type */
+        desc = fopen("descriptors/invalids/invalidMethodReturnType.descriptor", "r");
+        status = dynInterface_parse(desc, &dynIntf);
+        CHECK_EQUAL(1, status); //Test fails because of invalid return type (D instead of
N)
+        fclose(desc);
+        dynInterface_destroy(dynIntf);
+
+        /* Invalid  method section */
+        desc = fopen("descriptors/invalids/invalidMethod.descriptor", "r");
+        status = dynInterface_parse(desc, &dynIntf);
+        CHECK_EQUAL(1, status); //Test fails because of space at the end of the method
+        fclose(desc);
+        dynInterface_destroy(dynIntf);
+
+        /* Invalid  method section */
+        desc = fopen("descriptors/invalids/invalidType.descriptor", "r");
+        status = dynInterface_parse(desc, &dynIntf);
+        CHECK_EQUAL(1, status); //Test fails because of space at the end of the type
+        fclose(desc);
+        dynInterface_destroy(dynIntf);
+
+        /* Invalid  method section */
+        desc = fopen("descriptors/invalids/invalidMetaType.descriptor", "r");
+        status = dynInterface_parse(desc, &dynIntf);
+        CHECK_EQUAL(0, status); //Invalid meta type doesn't generate errors, just warnings
+        fclose(desc);
+        dynInterface_destroy(dynIntf);
+    }
 }
 
 
@@ -116,3 +170,7 @@ TEST(DynInterfaceTests, test1) {
 TEST(DynInterfaceTests, test2) {
     test2();
 }
+
+TEST(DynInterfaceTests, testInvalid) {
+    testInvalid();
+}

http://git-wip-us.apache.org/repos/asf/celix/blob/53bc7bd8/dfi/private/test/dyn_message_tests.cpp
----------------------------------------------------------------------
diff --git a/dfi/private/test/dyn_message_tests.cpp b/dfi/private/test/dyn_message_tests.cpp
index e30d16e..acaddf8 100644
--- a/dfi/private/test/dyn_message_tests.cpp
+++ b/dfi/private/test/dyn_message_tests.cpp
@@ -158,6 +158,41 @@ static void msg_test3(void) {
 	dynMessage_destroy(dynMsg);
 }
 
+static void msg_invalid(void) {
+	int status = 0;
+	dyn_message_type *dynMsg = NULL;
+	FILE *desc = fopen("descriptors/invalids/invalidMsgHdr.descriptor", "r");
+	assert(desc != NULL);
+	status = dynMessage_parse(desc, &dynMsg);
+	CHECK_EQUAL(1, status);
+	fclose(desc);
+
+	desc = fopen("descriptors/invalids/invalidMsgMissingVersion.descriptor", "r");
+	assert(desc != NULL);
+	status = dynMessage_parse(desc, &dynMsg);
+	CHECK_EQUAL(1, status);
+	fclose(desc);
+
+	desc = fopen("descriptors/invalids/invalidMsgInvalidSection.descriptor", "r");
+	assert(desc != NULL);
+	status = dynMessage_parse(desc, &dynMsg);
+	CHECK_EQUAL(1, status);
+	fclose(desc);
+
+	desc = fopen("descriptors/invalids/invalidMsgInvalidName.descriptor", "r");
+	assert(desc != NULL);
+	status = dynMessage_parse(desc, &dynMsg);
+	CHECK_EQUAL(1, status);
+	fclose(desc);
+
+	desc = fopen("descriptors/invalids/invalidMsgInvalidType.descriptor", "r");
+	assert(desc != NULL);
+	status = dynMessage_parse(desc, &dynMsg);
+	CHECK_EQUAL(1, status);
+	fclose(desc);
+
+}
+
 }
 
 
@@ -182,3 +217,7 @@ TEST(DynMessageTests, msg_test2) {
 TEST(DynMessageTests, msg_test3) {
 	msg_test3();
 }
+
+TEST(DynMessageTests, msg_invalid) {
+	msg_invalid();
+}


Mime
View raw message