Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -22,10 +22,12 @@ #if defined HAVE_SEL_GET_NAME #define SEL_NAME(x) sel_get_name(x) #elif defined HAVE_SEL_GETNAME #define SEL_NAME(x) sel_getName(x) +#else +#error "You need either sel_get_name() or sel_getName!" #endif @implementation OFException + newWithObject: (id)obj { Index: tests/OFXMLFactory/OFXMLFactory.m ================================================================== --- tests/OFXMLFactory/OFXMLFactory.m +++ tests/OFXMLFactory/OFXMLFactory.m @@ -13,23 +13,34 @@ #import #import #import "OFXMLFactory.h" -/* TODO: Do not only print, but check if it's the output it should be */ +inline void +check_result(char *result, const char *should) +{ + if (!strcmp(result, should)) + printf("%s is expected result\n", result); + else { + printf("%s is NOT expected result!", result); + exit(1); + } + + free(result); +} -inline int +inline void test_concat() { const char *c1 = "", *c2 = "bar", *c3 = ""; - char *s1, *s2, *s3, *str; + char *s1, *s2, *s3; char *strs[4]; if ((s1 = malloc(strlen(c1) + 1)) == NULL || (s2 = malloc(strlen(c2) + 1)) == NULL || (s3 = malloc(strlen(c3) + 1)) == NULL) - return 1; + exit(1); strncpy(s1, c1, strlen(c1) + 1); strncpy(s2, c2, strlen(c2) + 1); strncpy(s3, c3, strlen(c3) + 1); @@ -36,100 +47,79 @@ strs[0] = s1; strs[1] = s2; strs[2] = s3; strs[3] = NULL; - puts((str = [OFXMLFactory concatAndFreeCStrings: strs])); - free(str); - - return 0; + check_result([OFXMLFactory concatAndFreeCStrings: strs], + "bar"); } -inline int +inline void test_create_stanza() { - char *xml; - - xml = [OFXMLFactory createStanza: "foo" - withCloseTag: NO - andCData: NULL, - NULL]; - puts(xml); - free(xml); - - xml = [OFXMLFactory createStanza: "foo" - withCloseTag: NO - andCData: NULL, - "bar", "baz", - "blub", "asd", - NULL]; - puts(xml); - free(xml); - - xml = [OFXMLFactory createStanza: "foo" - withCloseTag: YES - andCData: NULL, - NULL]; - puts(xml); - free(xml); - - xml = [OFXMLFactory createStanza: "foo" - withCloseTag: YES - andCData: "bar", - NULL]; - puts(xml); - free(xml); - - xml = [OFXMLFactory createStanza: "foo" - withCloseTag: YES - andCData: NULL, - "bar", "b&az", - NULL]; - puts(xml); - free(xml); - - xml = [OFXMLFactory createStanza: "foo" - withCloseTag: YES - andCData: "bar", - "bar", "b'az", - NULL]; - puts(xml); - free(xml); - - xml = [OFXMLFactory createStanza: "foo" - withCloseTag: YES - andCData: NULL, - "bar", "b&az", - "x", "asd\"", - NULL]; - puts(xml); - free(xml); - - xml = [OFXMLFactory createStanza: "foo" - withCloseTag: YES - andCData: "bar", - "bar", "b'az", - "x", "y", - "a", "b", - NULL]; - puts(xml); - free(xml); - - return 0; -} - -inline int -test_escape() -{ - char *tmp; - - tmp = [OFXMLFactory escapeCString: " &welt'\"!&"]; - puts(tmp); - free(tmp); - - return 0; + check_result([OFXMLFactory createStanza: "foo" + withCloseTag: NO + andCData: NULL, + NULL], + ""); + + check_result([OFXMLFactory createStanza: "foo" + withCloseTag: NO + andCData: NULL, + "bar", "baz", + "blub", "asd", + NULL], + ""); + check_result([OFXMLFactory createStanza: "foo" + withCloseTag: YES + andCData: NULL, + NULL], + ""); + check_result([OFXMLFactory createStanza: "foo" + withCloseTag: YES + andCData: "bar", + NULL], + "bar"); + check_result([OFXMLFactory createStanza: "foo" + withCloseTag: YES + andCData: NULL, + "bar", "b&az", + NULL], + ""); + check_result([OFXMLFactory createStanza: "foo" + withCloseTag: YES + andCData: "bar", + "bar", "b'az", + NULL], + "bar"); + check_result([OFXMLFactory createStanza: "foo" + withCloseTag: YES + andCData: NULL, + "bar", "b&az", + "x", "asd\"", + NULL], + ""); + check_result([OFXMLFactory createStanza: "foo" + withCloseTag: YES + andCData: "bar", + "bar", "b'az", + "x", "y", + "a", "b", + NULL], + "bar"); +} + +inline void +test_escape() +{ + check_result([OFXMLFactory escapeCString: " &welt'\"!&"], + "<hallo> &welt'"!&"); } int main() { - return test_escape() + test_create_stanza() + test_concat(); + test_escape(); + test_create_stanza(); + test_concat(); + + return 0; }