summaryrefslogtreecommitdiff
path: root/app/bin/unittest/shortentest.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-22 14:05:41 +0200
committerJörg Frings-Fürst <debian@jff-webhosting.net>2020-08-22 14:05:41 +0200
commitb55285a77da0e0b829e4ce8d7e09debaabc68e15 (patch)
treef622559ef65bbdd3e1c5bdb06098a8f89eec0563 /app/bin/unittest/shortentest.c
parentd3897ce090dbeb220ed2c782f095597e417cf3cc (diff)
parentd1ae75703e1ed81d65ea16946dcdb77e7a13adc9 (diff)
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'app/bin/unittest/shortentest.c')
-rw-r--r--app/bin/unittest/shortentest.c152
1 files changed, 152 insertions, 0 deletions
diff --git a/app/bin/unittest/shortentest.c b/app/bin/unittest/shortentest.c
new file mode 100644
index 0000000..4d24b84
--- /dev/null
+++ b/app/bin/unittest/shortentest.c
@@ -0,0 +1,152 @@
+/** \file stringutiltest.c
+* Unit tests for the dxfformat module
+*/
+
+#include <malloc.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <string.h>
+#include <stdio.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <shortentext.h>
+
+#define RESULTSTRING "This is a test!"
+
+
+static void NoRemoveBlanks(void **state)
+{
+ char *result = malloc(strlen(RESULTSTRING) + 20);
+ (void)state;
+
+ RemoveFormatChars(RESULTSTRING, result);
+ assert_string_equal(result, RESULTSTRING);
+
+ RemoveFormatChars(" " RESULTSTRING, result);
+ assert_string_equal(result, " " RESULTSTRING);
+}
+
+static void RemoveMultipleBlanks(void **state)
+{
+ char *result = malloc(strlen(RESULTSTRING) + 20);
+ (void)state;
+
+ RemoveFormatChars("This is a test!", result);
+ assert_string_equal(result, RESULTSTRING);
+
+ RemoveFormatChars("This is a test!", result);
+ assert_string_equal(result, RESULTSTRING);
+}
+
+
+static void RemoveTabs(void **state)
+{
+ char *result = malloc(strlen(RESULTSTRING) + 20);
+ (void)state;
+
+ RemoveFormatChars("This \tis\ta test!", result);
+ assert_string_equal(result, RESULTSTRING);
+
+ RemoveFormatChars("This\t\tis a\ttest!", result);
+ assert_string_equal(result, RESULTSTRING);
+
+ RemoveFormatChars("\tThis is a test!", result);
+ assert_string_equal(result, " " RESULTSTRING);
+}
+
+static void RemoveCRs(void **state)
+{
+ char *result = malloc(strlen(RESULTSTRING) + 20);
+ (void)state;
+
+ RemoveFormatChars("This\r is a test!", result);
+ assert_string_equal(result, RESULTSTRING);
+
+ RemoveFormatChars("This\ris a test!", result);
+ assert_string_equal(result, RESULTSTRING);
+
+ RemoveFormatChars("This is a test!\r", result);
+ assert_string_equal(result, RESULTSTRING);
+}
+
+static void RemoveLFs(void **state)
+{
+ char *result = malloc(strlen(RESULTSTRING) + 20);
+ (void)state;
+
+ RemoveFormatChars("This\n is a test!", result);
+ assert_string_equal(result, RESULTSTRING);
+
+ RemoveFormatChars("This\nis a test!", result);
+ assert_string_equal(result, RESULTSTRING);
+
+ RemoveFormatChars("\nThis is a test!", result);
+ assert_string_equal(result, " " RESULTSTRING);
+
+ RemoveFormatChars("This is a test!\r\n", result);
+ assert_string_equal(result, RESULTSTRING);
+}
+
+#define LONGSTRING "The strrchr() function in C/C++ locates the last occurrence of a character in a string. It returns a pointer to the last occurrence in the string. The terminating null character is considered part of the C string. ... str : specifies the pointer to the null terminated string to be searched for."
+
+static void NoEllipsizeText(void **state)
+{
+ char *result = malloc(strlen(RESULTSTRING) + 20);
+
+ (void)state;
+
+ EllipsizeString(RESULTSTRING, result, strlen(RESULTSTRING) + 10);
+ assert_string_equal(result, RESULTSTRING);
+
+ EllipsizeString(RESULTSTRING, NULL, strlen(RESULTSTRING) + 10);
+ assert_string_equal(result, RESULTSTRING);
+}
+
+static void EllipsizeText(void **state)
+{
+ char *result = malloc(sizeof(LONGSTRING));
+ (void)state;
+
+ EllipsizeString(LONGSTRING, result, strlen(LONGSTRING));
+ assert_string_equal(result, LONGSTRING);
+
+ EllipsizeString(LONGSTRING, result, 40);
+ assert_string_equal(result, "The strrchr() function in C/C++...");
+
+ EllipsizeString(LONGSTRING, result, 23);
+ assert_string_equal(result, "The strrchr()...");
+
+ strcpy(result, LONGSTRING);
+ EllipsizeString(result, NULL, 23);
+ assert_string_equal(result, "The strrchr()...");
+
+}
+
+static void LongText(void **state)
+{
+ char *result = malloc(sizeof(LONGSTRING));
+ (void)state;
+
+ strcpy(result, "abcdefghijklmnopqrstuvwxyz");
+ EllipsizeString(result, NULL, 23);
+ assert_string_equal(result, "abcdefghijklmnopqrst...");
+
+ EllipsizeString("abcdefghijklmnopqrstuvwxyz", result, 10);
+ assert_string_equal(result, "abcdefg...");
+}
+
+int main(void)
+{
+ const struct CMUnitTest tests[] = {
+ cmocka_unit_test(NoRemoveBlanks),
+ cmocka_unit_test(RemoveMultipleBlanks),
+ cmocka_unit_test(RemoveTabs),
+ cmocka_unit_test(RemoveCRs),
+ cmocka_unit_test(RemoveLFs),
+ cmocka_unit_test(NoEllipsizeText),
+ cmocka_unit_test(EllipsizeText),
+ cmocka_unit_test(LongText),
+ };
+ return cmocka_run_group_tests(tests, NULL, NULL);
+} \ No newline at end of file