From 949385ec35280773cd15c4f4dc99bfe0b508f5e5 Mon Sep 17 00:00:00 2001 From: Jason Stephenson Date: Mon, 9 May 2022 15:08:21 -0400 Subject: [PATCH] LP1970667: Add Installation Support for Ubuntu 22.04 (Jammy Jellyfish) Update the prerequisite installation, C unit tests, and README for Ubuntu 22.04 LTS (Jammy Jellyfish). Update configure.ac for recent autoconf/libtool changes Suggest disabling apparmor for ejabberd in README Signed-off-by: Jason Stephenson Signed-off-by: Bill Erickson --- README | 16 +++++++++++++- configure.ac | 5 +---- src/extras/Makefile.install | 3 +++ tests/check_osrf_json_object.c | 46 +++++++++++++++++++++++++++++++++++++++++ tests/check_osrf_list.c | 38 ++++++++++++++++++++++++++++++++++ tests/check_osrf_message.c | 12 +++++++++++ tests/check_osrf_stack.c | 2 ++ tests/check_osrf_utils.c | 2 ++ tests/check_transport_client.c | 18 ++++++++++++++++ tests/check_transport_message.c | 26 +++++++++++++++++++++++ 10 files changed, 163 insertions(+), 5 deletions(-) diff --git a/README b/README index a1af0ef..6f6acdc 100644 --- a/README +++ b/README @@ -69,6 +69,7 @@ Well-tested values for include: * `debian-stretch` for Debian 9 * `ubuntu-bionic` for Ubuntu 18.04 * `ubuntu-focal` for Ubuntu 20.04 + * `ubuntu-jammy` for Ubuntu 22.04 Patches and suggestions for improvement from users of these distributions, or others, are welcome! @@ -197,6 +198,19 @@ create a file within the `/etc/ld.so.conf.d/` directory, and then run Configure the ejabberd server ----------------------------- +[TIP] +===== +It is recommended to disable the apparmor profile for ejabberd on *Ubuntu* before +continuing. If you are installing on any version of *Ubuntu*, run the following +commands as the *root* Linux account: + +[source,bash] +--------------------------------------------------------------------------- +ln -s /etc/apparmor.d/usr.sbin.ejabberdctl /etc/apparmor.d/disable/ +apparmor_parser -R /etc/apparmor.d/usr.sbin.ejabberdctl +--------------------------------------------------------------------------- +===== + OpenSRF requires an XMPP (Jabber) server. For performance reasons, ejabberd is the Jabber server of choice for the OpenSRF project. In most cases, you only have to make a few changes to the default configuration file to make ejabberd @@ -268,7 +282,7 @@ hosts: mod_legacy_auth: {} ----------------------- + -(Debian Bullseye) Ejabberd 21.x:: +(Debian Bullseye / Ubuntu Jammy) Ejabberd 21.x:: Open `/etc/ejabberd/ejabberd.yml` and make the following changes: a. Define your public and private domains in the `hosts` directive. For diff --git a/configure.ac b/configure.ac index 21963b0..c037c21 100644 --- a/configure.ac +++ b/configure.ac @@ -99,7 +99,7 @@ AM_CONDITIONAL(DEBUG, test x$debug = xtrue) # Checks for programs. #-------------------------------- -AC_PROG_LIBTOOL +LT_INIT AC_PROG_AWK AC_PROG_CC AC_PROG_INSTALL @@ -283,7 +283,6 @@ if test "x$OSRF_INSTALL_CORE" = "xtrue"; then # Checks for header files. #----------------------------- - AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([arpa/inet.h fcntl.h limits.h malloc.h netdb.h netinet/in.h stdlib.h string.h strings.h sys/socket.h sys/time.h sys/timeb.h syslog.h unistd.h]) @@ -295,7 +294,6 @@ if test "x$OSRF_INSTALL_CORE" = "xtrue"; then AC_C_INLINE AC_TYPE_PID_T AC_TYPE_SIZE_T - AC_HEADER_TIME AC_STRUCT_TM AM_PROG_CC_C_O @@ -306,7 +304,6 @@ if test "x$OSRF_INSTALL_CORE" = "xtrue"; then AC_FUNC_FORK AC_FUNC_MALLOC AC_FUNC_SELECT_ARGTYPES - AC_TYPE_SIGNAL AC_FUNC_STRFTIME AC_FUNC_STRTOD AC_FUNC_VPRINTF diff --git a/src/extras/Makefile.install b/src/extras/Makefile.install index 993b90f..3a8df8b 100644 --- a/src/extras/Makefile.install +++ b/src/extras/Makefile.install @@ -20,6 +20,8 @@ # - or - # make -f Makefile.install ubuntu-focal # - or - +# make -f Makefile.install ubuntu-jammy +# - or - # make -f Makefile.install fedora # # --------------------------------------------------------------------- @@ -158,6 +160,7 @@ generic_debian: install_debs debian_sys_config apache_mpm_prefork_mods apache_pe ubuntu-bionic: generic_ubuntu ubuntu-focal: generic_ubuntu +ubuntu-jammy: generic_ubuntu generic_ubuntu: install_debs debian_sys_config apache_mpm_prefork_mods apache_perl_mod diff --git a/tests/check_osrf_json_object.c b/tests/check_osrf_json_object.c index bd0bd37..966b8b9 100644 --- a/tests/check_osrf_json_object.c +++ b/tests/check_osrf_json_object.c @@ -28,10 +28,13 @@ void teardown (void) { //Tests START_TEST(test_osrf_json_object_jsonNewObject) +{ fail_if(jsonObj == NULL, "jsonObject not created"); +} END_TEST START_TEST(test_osrf_json_object_jsonNewObjectFmt) +{ jsonObject *fmtObj; jsonObject *nullObj; fmtObj = jsonNewObjectFmt("string %d %d", 10, 20); @@ -46,9 +49,11 @@ START_TEST(test_osrf_json_object_jsonNewObjectFmt) "jsonNewObjectFmt should set jsonObject->value.s to NULL if passed a NULL arg"); fail_unless(nullObj->type == JSON_NULL, "jsonNewObjectFmt should set jsonObject->type to JSON_NULL if passed a NULL arg"); +} END_TEST START_TEST(test_osrf_json_object_jsonNewNumberObject) +{ jsonObject *numObj; numObj = jsonNewNumberObject(123); @@ -57,9 +62,11 @@ START_TEST(test_osrf_json_object_jsonNewNumberObject) "jsonNewNumberObject should set jsonObject->value.s to the string value of the num arg"); fail_unless(numObj->type == JSON_NUMBER, "jsonNewNumberObject should set jsonObject->type to JSON_NUMBER"); +} END_TEST START_TEST(test_osrf_json_object_jsonNewNumberStringObject) +{ jsonObject *nullobj = jsonNewNumberStringObject(NULL); fail_unless(strcmp(nullobj->value.s, "0") == 0, "jsonNewNumberStringObject should return a jsonObject with a value of 0 if passed a NULL numstr arg"); @@ -73,54 +80,70 @@ START_TEST(test_osrf_json_object_jsonNewNumberStringObject) "jsonNewNumberStringObject should return a jsonObject with value.s = the value of the numstr arg"); fail_unless(numstrobj->type == JSON_NUMBER, "jsonNewNumberStringObject should return a jsonObject of type JSON_NUMBER"); +} END_TEST START_TEST(test_osrf_json_object_jsonNewBoolObject) +{ fail_unless(jsonBool->type == JSON_BOOL, "jsonNewBoolObject should return a jsonObject of type JSON_BOOL"); fail_unless(jsonBool->value.b == 0, "jsonNewBoolObject should return an object with a value of the val arg"); +} END_TEST START_TEST(test_osrf_json_object_jsonSetBool) +{ jsonSetBool(jsonBool, -1); fail_unless(jsonBool->value.b == -1, "jsonSetBool should set jsonObject->value.b to the value of the val arg"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectSetKey) +{ fail_unless(jsonObjectSetKey(NULL, "key1", NULL) == -1); fail_unless(jsonObjectSetKey(jsonHash, "key1", NULL) == 1); fail_unless(jsonObjectSetKey(jsonHash, "key2", jsonNewObject("test2")) == 2); fail_unless(jsonObjectGetKey(jsonHash, "key1")->value.s == NULL); fail_unless(strcmp(jsonObjectGetKey(jsonHash, "key2")->value.s, "test2") == 0); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectRemoveKey) +{ jsonObjectSetKey(jsonHash, "key1", jsonNewObject("value")); fail_unless(jsonObjectRemoveKey(jsonHash, NULL) == -1); fail_unless(jsonObjectRemoveKey(jsonHash, "key1") == 1); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectGetKey) +{ jsonObjectSetKey(jsonHash, "key1", jsonNewObject("value")); fail_unless(strcmp(jsonObjectGetKey(jsonHash, "key1")->value.s, "value") == 0); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectSetClass) +{ jsonObjectSetClass(jsonObj, NULL); fail_unless(jsonObj->classname == NULL); jsonObjectSetClass(jsonObj, "aClass"); fail_unless(strcmp(jsonObj->classname, "aClass") == 0); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectGetClass) +{ fail_unless(jsonObjectGetClass(NULL) == NULL); jsonObjectSetClass(jsonObj, "aClass"); fail_unless(strcmp(jsonObjectGetClass(jsonObj), "aClass") == 0); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectSetIndex) +{ jsonObject *jsonArrayValue = jsonNewObject("value"); fail_unless(jsonObjectSetIndex(NULL, 0, jsonArrayValue) == -1, "jsonObjectSetIndex should return -1 if dest arg is NULL"); @@ -133,9 +156,11 @@ START_TEST(test_osrf_json_object_jsonObjectSetIndex) "the value inserted into the jsonArray should be the value of the newObj arg"); fail_unless(jsonArrayResult->parent == jsonArray, "the parent of the element inserted should be equal to the newObj arg"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectGetIndex) +{ jsonObject *jsonArrayValue = jsonNewObject("value"); jsonObjectSetIndex(jsonArray, 0, jsonArrayValue); fail_unless(jsonObjectGetIndex(NULL, 0) == NULL, @@ -147,9 +172,11 @@ START_TEST(test_osrf_json_object_jsonObjectGetIndex) jsonObject *getIndexValue = jsonObjectGetIndex(jsonArray, 0); fail_unless(strcmp(getIndexValue->value.s, "value") == 0, "jsonObjectGetIndex should return the jsonObject at the index given"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectToJSONRaw) +{ fail_unless(jsonObjectToJSONRaw(NULL) == NULL, "when passed NULL, jsonObjectToJSONRaw should return NULL"); @@ -164,9 +191,11 @@ START_TEST(test_osrf_json_object_jsonObjectToJSONRaw) "{\"key1\":\"value1\",\"key2\":\"value2\"}") == 0, "jsonObjectToJSONRaw should return a string of raw JSON, without expanding\ class names, built from the obj arg"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectToJSON) +{ fail_unless(jsonObjectToJSON(NULL) == NULL, "jsonObjectToJSON should return NULL if passed a NULL obj arg"); jsonObject *val1 = jsonNewObject("value1"); @@ -179,15 +208,19 @@ START_TEST(test_osrf_json_object_jsonObjectToJSON) fail_unless(strcmp(jsonObjectToJSON(jsonHash), "{\"key1\":{\"__c\":\"class1\",\"__p\":\"value1\"},\"key2\":{\"__c\":\"class2\",\"__p\":\"value2\"}}") == 0, "jsonObjectToJSON should return the obj arg as raw json, expanding class names"); +} END_TEST START_TEST(test_osrf_json_object_doubleToString) +{ fail_unless(strcmp(doubleToString(123.456), "123.456000000000003069544618484") == 0, "doubleToString should return a string version of the given double, with a precision of 30 digits"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectGetString) +{ fail_unless(strcmp(jsonObjectGetString(jsonObj), "test") == 0, "jsonObjectGetString should return the value of the given object, if it is of type JSON_STRING"); fail_unless(strcmp(jsonObjectGetString(jsonNumber), @@ -201,9 +234,11 @@ START_TEST(test_osrf_json_object_jsonObjectGetString) "jsonObjectGetString should return NULL if the given arg is not of type JSON_NUMBER or JSON_STRING"); fail_unless(jsonObjectGetString(NULL) == NULL, "jsonObjectGetString should return NULL if the given arg is NULL"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectGetNumber) +{ fail_unless(jsonObjectGetNumber(NULL) == 0, "jsonObjectGetNumber should return 0 if given arg is NULL"); fail_unless(jsonObjectGetNumber(jsonHash) == 0, @@ -214,18 +249,22 @@ START_TEST(test_osrf_json_object_jsonObjectGetNumber) "jsonObjectGetNumber should return 0 if given args value is NULL"); fail_unless(jsonObjectGetNumber(jsonNumber) == 123.456000000000003069544618484, "jsonObjectGetNumber should return the value of the given obj in double form"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectSetString) +{ jsonObjectSetString(jsonObj, NULL); fail_unless(strcmp(jsonObj->value.s, "test") == 0, "jsonObjectSetString should not change the value of the dest arg if passed a NULL string arg"); jsonObjectSetString(jsonObj, "changed"); fail_unless(strcmp(jsonObj->value.s, "changed") == 0, "jsonObjectSetString should change the value of the dest arg to the value of the string arg"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectSetNumberString) +{ fail_unless(jsonObjectSetNumberString(NULL, "asdf") == -1, "jsonObjectSetNumberString should return -1 when dest arg is NULL"); fail_unless(jsonObjectSetNumberString(jsonNumber, NULL) == -1, @@ -238,15 +277,19 @@ START_TEST(test_osrf_json_object_jsonObjectSetNumberString) "jsonObjectSetNumber should return -1 if the string arg is not numeric"); fail_unless(jsonNumber->value.s == NULL, "when the string arg is not numeric, dest->value.s should be set to NULL"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectSetNumber) +{ jsonObjectSetNumber(jsonNumber, 999.999); fail_unless(strcmp(jsonNumber->value.s, "999.999000000000023646862246096") == 0, "jsonObjectSetNumber should set dest->value.s to the stringified version of the num arg"); +} END_TEST START_TEST(test_osrf_json_object_jsonObjectClone) +{ jsonObject *nullClone = jsonObjectClone(NULL); fail_unless(nullClone->type == JSON_NULL && nullClone->value.s == NULL, "when passed a NULL arg, jsonObjectClone should return a jsonObject of type JSON_NULL with a value of NULL "); @@ -288,9 +331,11 @@ START_TEST(test_osrf_json_object_jsonObjectClone) jsonObject *hashClone = jsonObjectClone(jsonHash); fail_unless(strcmp(jsonObjectToJSON(hashClone), jsonObjectToJSON(jsonHash)) == 0, "jsonObjectClone should return a clone of a JSON_HASH object"); +} END_TEST START_TEST(test_osrf_json_object_jsonBoolIsTrue) +{ fail_unless(jsonBoolIsTrue(NULL) == 0, "jsonBoolIsTrue should return 0 if a NULL arg is passed"); fail_unless(jsonBoolIsTrue(jsonObj) == 0, @@ -300,6 +345,7 @@ START_TEST(test_osrf_json_object_jsonBoolIsTrue) jsonObject *newBool = jsonNewBoolObject(123); fail_unless(jsonBoolIsTrue(newBool) == 1, "jsonBoolIsTrue should return 1 if the value of boolObj is not 0"); +} END_TEST //END Tests diff --git a/tests/check_osrf_list.c b/tests/check_osrf_list.c index 8dfa32e..1e820bc 100644 --- a/tests/check_osrf_list.c +++ b/tests/check_osrf_list.c @@ -33,12 +33,15 @@ void teardown(void) { // BEGIN TESTS START_TEST(test_osrf_list_osrfNewList) +{ osrfList *newList = osrfNewList(); fail_if(newList == NULL, "osrfList object not successfully created"); fail_unless(newList->arrsize == 48, "the osrfList is not the default size of 48"); +} END_TEST START_TEST(test_osrf_list_osrfNewListSize) +{ osrfList *smallList = osrfNewListSize(5); fail_if(smallList == NULL, "smallList not successfully created"); fail_unless(smallList->arrsize == 5, "smallList wasn't created with the size 5"); @@ -52,9 +55,11 @@ START_TEST(test_osrf_list_osrfNewListSize) osrfList *sizelessList = osrfNewListSize(0); fail_unless(sizelessList->arrsize == 16, "osrfNewListSize called with a size of 0 or less should have an array size of 16"); +} END_TEST START_TEST(test_osrf_list_osrfListPush) +{ fail_unless(osrfListPush(NULL, NULL) == -1, "Passing a null list to osrfListPush should return -1"); int listItem = 111; @@ -64,9 +69,11 @@ START_TEST(test_osrf_list_osrfListPush) "testOsrfList->size did not update correctly, should be 4"); fail_unless(osrfListGetIndex(testOsrfList, 3) == &listItem, "listItem did not add to the end of testOsrfList"); +} END_TEST START_TEST(test_osrf_list_osrfListPushFirst) +{ fail_unless(osrfListPushFirst(NULL, NULL) == -1, "Passing a null list to osrfListPushFirst should return -1"); int listItem = 123; @@ -74,9 +81,11 @@ START_TEST(test_osrf_list_osrfListPushFirst) "osrfListPushFirst should return a size of 3"); fail_unless(osrfListGetIndex(testOsrfList, 1) == &listItem, "listItem should be in index 1 because it is the first that is null"); +} END_TEST START_TEST(test_osrf_list_osrfListSet) +{ //Null argument check fail_unless(osrfListSet(NULL, NULL, 1) == NULL, "Given a null list arg, osrfListSet should return null"); @@ -129,9 +138,11 @@ START_TEST(test_osrf_list_osrfListSet) "List should have a size value of 19"); fail_unless(osrfListGetIndex(testOsrfList, 18) == &listItem4, "Value not added to correct index of list"); +} END_TEST START_TEST(test_osrf_list_osrfListGetIndex) +{ fail_unless(osrfListGetIndex(NULL, 1) == NULL, "Calling osrfListGetIndex with a null list should return null"); fail_unless(osrfListGetIndex(testOsrfList, 8) == NULL, @@ -139,9 +150,11 @@ START_TEST(test_osrf_list_osrfListGetIndex) occupied indexes should return NULL"); fail_unless(osrfListGetIndex(testOsrfList, 2) == &globalItem3, "osrfListGetIndex should return the value of the list at the given index"); +} END_TEST START_TEST(test_osrf_list_osrfListFree) +{ //Set up a new list to be freed osrfList *myList = osrfNewList(); myList->freeItem = (void(*)(void*)) osrfCustomListFree; @@ -155,9 +168,11 @@ START_TEST(test_osrf_list_osrfListFree) fail_unless(freedItemsSize == 2, "osrfListFree should free each item in the list if there is a custom \ freeing function defined"); +} END_TEST START_TEST(test_osrf_list_osrfListClear) +{ //Set up a new list with items to be freed osrfList *myList = osrfNewList(); myList->freeItem = (void(*)(void*)) osrfCustomListFree; @@ -176,9 +191,11 @@ START_TEST(test_osrf_list_osrfListClear) "osrfListClear should make all previously used slots in the list NULL"); fail_unless(myList->size == 0, "osrfListClear should set the list's size to 0"); +} END_TEST START_TEST(test_osrf_list_osrfListSwap) +{ //Prepare a second list to swap osrfList *secondOsrfList = osrfNewListSize(7); int* secondListItem2 = malloc(sizeof(int)); @@ -204,9 +221,11 @@ START_TEST(test_osrf_list_osrfListSwap) "After osrfListSwap, second list should now contain \ the contents of the first list" ); +} END_TEST START_TEST(test_osrf_list_osrfListRemove) +{ fail_unless(osrfListRemove(NULL, 2) == NULL, "osrfListRemove should return NULL when not given a list"); fail_unless(osrfListRemove(testOsrfList, 1000) == NULL, @@ -233,9 +252,11 @@ START_TEST(test_osrf_list_osrfListRemove) fail_unless(testOsrfList->size == 2, "osrfListRemove should not touch \ the size of the list if it isn't removing the last element in the \ list"); +} END_TEST START_TEST(test_osrf_list_osrfListExtract) +{ fail_unless(osrfListExtract(NULL, 2) == NULL, "osrfListExtract should return NULL when not given a list"); fail_unless(osrfListExtract(testOsrfList, 1000) == NULL, @@ -259,9 +280,11 @@ START_TEST(test_osrf_list_osrfListExtract) fail_unless(testOsrfList->size == 2, "osrfListExtract should not touch the size of the list if it \ isn't removing the last element in the list"); +} END_TEST START_TEST(test_osrf_list_osrfListFind) +{ int* notInList1 = malloc(sizeof(int)); int* notInList2 = malloc(sizeof(int)); fail_unless(osrfListFind(NULL, ¬InList1) == -1, @@ -274,16 +297,20 @@ START_TEST(test_osrf_list_osrfListFind) fail_unless(osrfListFind(testOsrfList, ¬InList2) == -1, "osrfListFind should return -1 when the addr does not exist in \ the list"); +} END_TEST START_TEST(test_osrf_list_osrfListGetCount) +{ fail_unless(osrfListGetCount(NULL) == -1, "osrfListGetCount should return -1 when no list is given"); fail_unless(osrfListGetCount(testOsrfList) == 3, "osrfListGetCount should return list->size when given a list"); +} END_TEST START_TEST(test_osrf_list_osrfListPop) +{ fail_unless(osrfListPop(NULL) == NULL, "osrfListPop should return NULL when no list is given"); fail_unless(osrfListPop(testOsrfList) == NULL, @@ -299,9 +326,11 @@ START_TEST(test_osrf_list_osrfListPop) "osrfListPop should return the last item from the list"); fail_unless(testOsrfList->arrlist[2] == NULL, "osrfListPop should remove the last item from the list"); +} END_TEST START_TEST(test_osrf_list_osrfNewListIterator) +{ fail_unless(osrfNewListIterator(NULL) == NULL, "osrfNewListIterator should return NULL when no list is given"); osrfListIterator *testListItr = osrfNewListIterator(testOsrfList); @@ -313,9 +342,11 @@ START_TEST(test_osrf_list_osrfNewListIterator) fail_unless(testListItr->current == 0, "osrfNewListIterator should set its current position to 0 by \ default"); +} END_TEST START_TEST(test_osrf_list_osrfListIteratorNext) +{ fail_unless(osrfListIteratorNext(NULL) == NULL, "osrfListIteratorNext should return NULL when no list given"); osrfListIterator *testListItr = osrfNewListIterator(testOsrfList); @@ -335,20 +366,27 @@ START_TEST(test_osrf_list_osrfListIteratorNext) fail_unless(osrfListIteratorNext(testListItr) == NULL, "osrfListIteratorNext should return NULL if osrfListIterator->list \ is NULL"); +} END_TEST START_TEST(test_osrf_list_osrfListIteratorFree) +{ +} END_TEST START_TEST(test_osrf_list_osrfListIteratorReset) +{ osrfListIterator *testListItr = osrfNewListIterator(testOsrfList); osrfListIteratorNext(testListItr); osrfListIteratorReset(testListItr); fail_unless(testListItr->current == 0, "osrfListIteratorReset should reset the iterator's current position to 0"); +} END_TEST START_TEST(test_osrf_list_osrfListSetDefaultFree) +{ +} END_TEST //END TESTS diff --git a/tests/check_osrf_message.c b/tests/check_osrf_message.c index 10a7706..d327abc 100644 --- a/tests/check_osrf_message.c +++ b/tests/check_osrf_message.c @@ -17,15 +17,20 @@ void teardown(void) { //Tests START_TEST(test_osrf_message_init) +{ fail_if (o == NULL, "osrfMessage not created"); +} END_TEST START_TEST(test_osrf_message_get_last_locale) +{ fail_unless(osrf_message_get_last_locale() == NULL, "osrf_message_get_last_locale should return the value of current_locale"); +} END_TEST START_TEST(test_osrf_message_set_locale) +{ const char* new_locale = "en-CA"; fail_unless(osrf_message_set_locale(o, NULL) == NULL, "osrf_message_set_locale should return NULL if locale is NULL"); @@ -36,9 +41,11 @@ START_TEST(test_osrf_message_set_locale) "osrf_message_set_locale should return the new locale"); fail_unless(strcmp(o->sender_locale, "en-CA") == 0, "osrf_message_set_locale should set osrfMessage->sender_locale to the new locale"); +} END_TEST START_TEST(test_osrf_message_set_default_locale) +{ fail_unless(osrf_message_set_default_locale(NULL) == NULL, "osrf_message_set_default_locale should return NULL if given a NULL arg"); fail_unless(osrf_message_set_default_locale("This string is \ @@ -47,18 +54,22 @@ START_TEST(test_osrf_message_set_default_locale) fail_unless(strcmp(osrf_message_set_default_locale("fr-CA"), "fr-CA") == 0, "osrf_message_set_default_locale should return the new default locale if successful"); +} END_TEST START_TEST(test_osrf_message_set_method) +{ osrf_message_set_method(o, NULL); fail_unless(o->method_name == NULL, "osrf_message_set_method should return NULL if given a NULL method_name arg"); osrf_message_set_method(o, "add"); fail_unless(strcmp(o->method_name, "add") == 0, "osrf_message_set_method should set osrfMessage->method_name if successful"); +} END_TEST START_TEST(test_osrf_message_set_params) +{ osrf_message_set_params(o, NULL); fail_unless(o->_params == NULL, "osrf_message_set_params should set msg->_params to NULL when passed a NULL o arg"); @@ -69,6 +80,7 @@ START_TEST(test_osrf_message_set_params) "osrf_message_set_params should set msg->_params to an array containing the\ jsonObject passed"); jsonObjectFree(testJSONObject); +} END_TEST //END Tests diff --git a/tests/check_osrf_stack.c b/tests/check_osrf_stack.c index 3657488..3c7b6b0 100644 --- a/tests/check_osrf_stack.c +++ b/tests/check_osrf_stack.c @@ -14,9 +14,11 @@ void teardown(void){ // BEGIN TESTS START_TEST(test_osrf_stack_process) +{ int *mr = 0; fail_unless(osrf_stack_process(NULL, 10, mr) == -1, "osrf_stack_process should return -1 if client arg is NULL"); +} END_TEST //END TESTS diff --git a/tests/check_osrf_utils.c b/tests/check_osrf_utils.c index b0a3a6d..1b3462b 100644 --- a/tests/check_osrf_utils.c +++ b/tests/check_osrf_utils.c @@ -14,11 +14,13 @@ void teardown(void){ // BEGIN TESTS START_TEST(test_osrfXmlEscapingLength) +{ const char* ordinary = "12345"; fail_unless(osrfXmlEscapingLength(ordinary) == 0, "osrfXmlEscapingLength should return 0 if string has no special characters"); const char* special = "a & b"; ck_assert_int_eq(osrfXmlEscapingLength(special), 38); +} END_TEST //END TESTS diff --git a/tests/check_transport_client.c b/tests/check_transport_client.c index 0373290..7595e34 100644 --- a/tests/check_transport_client.c +++ b/tests/check_transport_client.c @@ -81,6 +81,7 @@ int session_wait(transport_session* session, int timeout) { // BEGIN TESTS START_TEST(test_transport_client_init) +{ fail_unless(client_init(NULL, 1234, "some_path", 123) == NULL, "When given a NULL client arg, client_init should return NULL"); transport_client *test_client = client_init("server", 1234, "unixpath", 123); @@ -95,32 +96,40 @@ START_TEST(test_transport_client_init) fail_unless(test_client->error == 0, "client->error should be false on new client creation"); fail_unless(strcmp(test_client->host, "server") == 0, "client->host should be set to the host arg"); fail_unless(test_client->xmpp_id == NULL, "xmpp_id should be NULL on new client creation"); +} END_TEST START_TEST(test_transport_client_connect) +{ fail_unless(client_connect(NULL, "user", "password", "resource", 10, AUTH_PLAIN) == 0, "Passing a NULL client to client_connect should return a failure"); fail_unless(client_connect(a_client, "user", "password", "resource", 10, AUTH_PLAIN) == 1, "A successful call to client_connect should return a 1, provided session_connect is successful"); fail_unless(strcmp(a_client->xmpp_id, "user@server/resource") == 0, "A successful call to client_connect should set the correct xmpp_id in the client"); +} END_TEST START_TEST(test_transport_client_disconnect) +{ fail_unless(client_disconnect(NULL) == 0, "client_disconnect should return 0 if no client arg is passed"); fail_unless(client_disconnect(a_client) == 1, "client_disconnect should return 1 if successful"); +} END_TEST START_TEST(test_transport_client_connected) +{ fail_unless(client_connected(NULL) == 0, "client_connected should return 0 if no client arg is passed"); fail_unless(client_connected(a_client) == 1, "client_connected should return 1 if successful"); +} END_TEST START_TEST(test_transport_client_send_message) +{ fail_unless(client_send_message(NULL, a_message) == -1, "client_send_message should return -1 if client arg is NULL"); a_client->error = 1; @@ -131,9 +140,11 @@ START_TEST(test_transport_client_send_message) //"client_send_message should return 0 on success"); //fail_unless(strcmp(a_message->sender, "user") == 0, //"client_send_message shoud set msg->sender to the value of client->xmpp_id"); +} END_TEST START_TEST(test_transport_client_recv) +{ //NULL client case fail_unless(client_recv(NULL, 10) == NULL, "client_recv should return NULL if the client arg is NULL"); @@ -188,30 +199,37 @@ START_TEST(test_transport_client_recv) transport_message *msg5 = client_recv(other_client, 1); //only 1 sec again... fail_unless(msg5 == NULL, "client_recv should return NULL if there is an error"); +} END_TEST START_TEST(test_transport_client_free) +{ fail_unless(client_free(NULL) == 0, "client_free should retun 0 if passed a NULL arg"); transport_client* client1 = client_init("server", 1234, "unixpath", 123); fail_unless(client_free(client1) == 1, "client_free should return 0 if successful"); +} END_TEST START_TEST(test_transport_client_discard) +{ fail_unless(client_discard(NULL) == 0, "client_discard should return 0 if passed a NULL arg"); transport_client* client1 = client_init("server", 1234, "unixpath", 123); fail_unless(client_discard(client1) == 1, "client_discard should return 1 if successful"); +} END_TEST START_TEST(test_transport_client_sock_fd) +{ fail_unless(client_sock_fd(NULL) == 0, "client_sock_fd should return 0 if passed a NULL arg"); a_client->session->sock_id = 1; fail_unless(client_sock_fd(a_client) == 1, "client_sock_fd should return client->session->sock_id"); +} END_TEST //END TESTS diff --git a/tests/check_transport_message.c b/tests/check_transport_message.c index 4ecbfd3..ebea8cc 100644 --- a/tests/check_transport_message.c +++ b/tests/check_transport_message.c @@ -16,6 +16,7 @@ void teardown(void) { //BEGIN TESTS START_TEST(test_transport_message_init_empty) +{ transport_message* empty_message = message_init(NULL, NULL, NULL, NULL, NULL); fail_if(empty_message == NULL, "transport_message wasn't created"); fail_unless(strcmp(empty_message->body, "") == 0, @@ -50,9 +51,11 @@ START_TEST(test_transport_message_init_empty) "message_init should set the msg_xml field to NULL"); fail_unless(empty_message->next == NULL, "message_init should set the next field to NULL"); +} END_TEST START_TEST(test_transport_message_init_populated) +{ fail_if(a_message == NULL, "transport_message wasn't created"); fail_unless(strcmp(a_message->body, "body") == 0, "When calling message_init, an body arg should be stored in the body field"); @@ -64,9 +67,11 @@ START_TEST(test_transport_message_init_populated) "When calling message_init, a recipient arg should be stored in the recipient field"); fail_unless(strcmp(a_message->sender, "sender") == 0, "When calling message_init, a sender arg should be stored in the sender field"); +} END_TEST START_TEST(test_transport_message_new_message_from_xml_empty) +{ fail_unless(new_message_from_xml(NULL) == NULL, "Passing NULL to new_message_from_xml should return NULL"); fail_unless(new_message_from_xml("\0") == NULL, @@ -107,9 +112,11 @@ START_TEST(test_transport_message_new_message_from_xml_empty) fail_unless(strcmp(t_msg->msg_xml, "") == 0, "msg->msg_xml should contain the contents of the original xml message"); fail_unless(t_msg->next == NULL, "msg->next should be set to NULL"); +} END_TEST START_TEST(test_transport_message_new_message_from_xml_populated) +{ const char* xml_jabber_msg = "thread_valuesubject_valuebody_value"; @@ -135,18 +142,22 @@ START_TEST(test_transport_message_new_message_from_xml_populated) "new_message_from_xml should populate the broadcast field"); fail_unless(strcmp(my_msg->msg_xml, xml_jabber_msg) == 0, "new_message_from_xml should store the original xml msg in msg_xml"); +} END_TEST START_TEST(test_transport_message_set_osrf_xid) +{ message_set_osrf_xid(a_message, "abcd"); fail_unless(strcmp(a_message->osrf_xid, "abcd") == 0, "message_set_osrf_xid should set msg->osrf_xid to the value of the osrf_xid arg"); message_set_osrf_xid(a_message, NULL); fail_unless(strcmp(a_message->osrf_xid, "") == 0, "message_set_osrf_xid should set msg->osrf_xid to an empty string if osrf_xid arg is NULL"); +} END_TEST START_TEST(test_transport_message_set_router_info_empty) +{ message_set_router_info(a_message, NULL, NULL, NULL, NULL, 0); fail_unless(strcmp(a_message->router_from, "") == 0, "message_set_router_info should set msg->router_from to empty string if NULL router_from arg is passed"); @@ -158,9 +169,11 @@ START_TEST(test_transport_message_set_router_info_empty) "message_set_router_info should set msg->router_command to empty string if NULL router_command arg is passed"); fail_unless(a_message->broadcast == 0, "message_set_router_info should set msg->broadcast to the content of the broadcast_enabled arg"); +} END_TEST START_TEST(test_transport_message_set_router_info_populated) +{ message_set_router_info(a_message, "routerfrom", "routerto", "routerclass", "routercmd", 1); fail_unless(strcmp(a_message->router_from, "routerfrom") == 0, "message_set_router_info should set msg->router_from to the value of the router_from arg"); @@ -172,17 +185,21 @@ START_TEST(test_transport_message_set_router_info_populated) "message_set_router_info should set msg->router_command to the value of the router_command arg"); fail_unless(a_message->broadcast == 1, "message_set_router_info should set msg->broadcast to the value of the broadcast_enabled arg"); +} END_TEST START_TEST(test_transport_message_free) +{ fail_unless(message_free(NULL) == 0, "message_free should return 0 if passed a NULL msg arg"); transport_message *msg = message_init("one", "two", "three", "four", "five"); fail_unless(message_free(msg) == 1, "message_free should return 1 if successful"); +} END_TEST START_TEST(test_transport_message_prepare_xml) +{ fail_unless(message_prepare_xml(NULL) == 0, "Passing a NULL msg arg to message_prepare_xml should return 0"); @@ -202,17 +219,21 @@ START_TEST(test_transport_message_prepare_xml) fail_unless(strcmp(a_message->msg_xml, "threadsubjectbody") == 0, "message_prepare_xml should store the correct xml in msg->msg_xml"); +} END_TEST START_TEST(test_transport_message_jid_get_username) +{ int buf_size = 15; char buffer[buf_size]; jid_get_username("testuser@domain.com/stuff", buffer, buf_size); fail_unless(strcmp(buffer, "testuser") == 0, "jid_get_username should set the buffer to the username extracted from the jid arg"); +} END_TEST START_TEST(test_transport_message_jid_get_resource) +{ char buf_size = 15; char buffer[buf_size]; jid_get_resource("testuser@domain.com/stuff", buffer, buf_size); @@ -221,9 +242,11 @@ START_TEST(test_transport_message_jid_get_resource) jid_get_resource("testuser@domain.com", buffer, buf_size); fail_unless(strcmp(buffer, "") == 0, "jid_get_resource should set the buffer to an empty string if there is no resource"); +} END_TEST START_TEST(test_transport_message_jid_get_domain) +{ char buf_size = 15; char buffer[buf_size]; jid_get_domain("testuser@domain.com/stuff", buffer, buf_size); @@ -232,9 +255,11 @@ START_TEST(test_transport_message_jid_get_domain) jid_get_domain("ksdljflksd", buffer, buf_size); fail_unless(strcmp(buffer, "") == 0, "jid_get_domain should set the buffer to an empty string if the jid is malformed"); +} END_TEST START_TEST(test_transport_message_set_msg_error) +{ set_msg_error(a_message, NULL, 111); fail_unless(a_message->is_error == 1, "set_msg_error called with a NULL error type should only set msg->is_error to 1"); @@ -245,6 +270,7 @@ START_TEST(test_transport_message_set_msg_error) "set_msg_error should set msg->error_type if error_type arg is passed"); fail_unless(a_message->error_code == 123, "set_msg_error should set msg->error_code to the value of the err_code arg"); +} END_TEST //END TESTS -- 2.11.0