]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Replace character_class_debug with proper unit test
authorArne Schwabe <arne@rfc2549.org>
Fri, 1 Dec 2023 11:22:43 +0000 (12:22 +0100)
committerGert Doering <gert@greenie.muc.de>
Sat, 2 Dec 2023 15:23:22 +0000 (16:23 +0100)
Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Message-Id: <20231201112243.15541-1-frank@lichtenheld.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27628.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/buffer.c
src/openvpn/buffer.h
src/openvpn/init.c
tests/unit_tests/openvpn/test_buffer.c

index 24f1ef262f2acca91ac8246808407461d239933a..0b94a5289762a20710af544ceb4a4f07d95d8845 100644 (file)
@@ -1150,26 +1150,6 @@ string_replace_leading(char *str, const char match, const char replace)
     }
 }
 
-#ifdef CHARACTER_CLASS_DEBUG
-
-#define CC_INCLUDE    (CC_PRINT)
-#define CC_EXCLUDE    (0)
-#define CC_REPLACE    ('.')
-
-void
-character_class_debug(void)
-{
-    char buf[256];
-
-    while (fgets(buf, sizeof(buf), stdin) != NULL)
-    {
-        string_mod(buf, CC_INCLUDE, CC_EXCLUDE, CC_REPLACE);
-        printf("%s", buf);
-    }
-}
-
-#endif
-
 #ifdef VERIFY_ALIGNMENT
 void
 valign4(const struct buffer *buf, const char *file, const int line)
index 4cc79507e10684b9355788958dd4dd4d32e3e3e7..0456b2766bba93be33bcb8c8bd4438c8f99d9342 100644 (file)
@@ -896,8 +896,6 @@ int buf_substring_len(const struct buffer *buf, int delim);
  */
 const char *np(const char *str);
 
-/*#define CHARACTER_CLASS_DEBUG*/
-
 /* character classes */
 
 #define CC_ANY                (1<<0)
@@ -961,11 +959,6 @@ strprefix(const char *str, const char *prefix)
 }
 
 
-#ifdef CHARACTER_CLASS_DEBUG
-void character_class_debug(void);
-
-#endif
-
 /*
  * Verify that a pointer is correctly aligned
  */
index abba74816e428d55b7e77f3a89f1b61141aa6a59..ca42c92656760c32a4595dbae6c56f243dffac10 100644 (file)
@@ -875,11 +875,6 @@ init_static(void)
     return false;
 #endif
 
-#ifdef CHARACTER_CLASS_DEBUG
-    character_class_debug();
-    return false;
-#endif
-
 #ifdef TIME_TEST
     time_test();
     return false;
index 8232f927c293826731cd39130845433d56b145f8..f9948125b2b3fda8b766717e852eda1b1f08fd9a 100644 (file)
@@ -319,6 +319,30 @@ test_buffer_gc_realloc(void **state)
     gc_free(&gc);
 }
 
+static void
+test_character_class(void **state)
+{
+    char buf[256];
+    strcpy(buf, "There is \x01 a nice 1234 year old tr\x7f ee!");
+    string_mod(buf, CC_PRINT, 0, '@');
+    assert_string_equal(buf, "There is @ a nice 1234 year old tr@ ee!");
+
+    strcpy(buf, "There is \x01 a nice 1234 year old tr\x7f ee!");
+    string_mod(buf, CC_PRINT, CC_DIGIT, '@');
+    assert_string_equal(buf, "There is @ a nice @@@@ year old tr@ ee!");
+
+    strcpy(buf, "There is \x01 a nice 1234 year old tr\x7f ee!");
+    string_mod(buf, CC_ALPHA, CC_DIGIT, '.');
+    assert_string_equal(buf, "There.is...a.nice......year.old.tr..ee.");
+
+    strcpy(buf, "There is \x01 a 'nice' \"1234\"\n year old \ntr\x7f ee!");
+    string_mod(buf, CC_ALPHA|CC_DIGIT|CC_NEWLINE|CC_SINGLE_QUOTE, CC_DOUBLE_QUOTE|CC_BLANK, '.');
+    assert_string_equal(buf, "There.is...a.'nice'..1234.\n.year.old.\ntr..ee.");
+
+    strcpy(buf, "There is a \\'nice\\' \"1234\" [*] year old \ntree!");
+    string_mod(buf, CC_PRINT, CC_BACKSLASH|CC_ASTERISK, '.');
+    assert_string_equal(buf, "There is a .'nice.' \"1234\" [.] year old .tree!");
+}
 
 int
 main(void)
@@ -351,6 +375,7 @@ main(void)
         cmocka_unit_test(test_buffer_free_gc_one),
         cmocka_unit_test(test_buffer_free_gc_two),
         cmocka_unit_test(test_buffer_gc_realloc),
+        cmocka_unit_test(test_character_class),
     };
 
     return cmocka_run_group_tests_name("buffer", tests, NULL, NULL);