@@ -1150,26 +1150,6 @@
}
}
-#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)
@@ -896,8 +896,6 @@
*/
const char *np(const char *str);
-/*#define CHARACTER_CLASS_DEBUG*/
-
/* character classes */
#define CC_ANY (1<<0)
@@ -961,11 +959,6 @@
}
-#ifdef CHARACTER_CLASS_DEBUG
-void character_class_debug(void);
-
-#endif
-
/*
* Verify that a pointer is correctly aligned
*/
@@ -875,11 +875,6 @@
return false;
#endif
-#ifdef CHARACTER_CLASS_DEBUG
- character_class_debug();
- return false;
-#endif
-
#ifdef TIME_TEST
time_test();
return false;
@@ -319,6 +319,30 @@
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 @@
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);