Skip to contentSkip to conversation

Change in openvpn[master]: Replace character_class_debug with proper unit test

Openvpn-devel In review plaisthos (Code Review) 3 participants 6 messages Nov 30, 2023 – Dec 2, 2023 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1701361470000.Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0@...2715...

#1 lore raw

Attention is currently required from: flichtenheld.

Hello flichtenheld,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/464?usp=email

to review the following change.

Change subject: Replace character_class_debug with proper unit test
......................................................................

Replace character_class_debug with proper unit test

Change-Id Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0

---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/init.c
M tests/unit_tests/openvpn/test_buffer.c

4 files changed, 25 insertions(+), 32 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/464/1

src/openvpn/buffer.c +0 -20
index 24f1ef2..0b94a52 100644
@@ -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)
src/openvpn/buffer.h +0 -7
index 4cc7950..0456b27 100644
@@ -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
  */
src/openvpn/init.c +0 -5
index fdab26b..9972ed7 100644
@@ -875,11 +875,6 @@
     return false;
 #endif
 
-#ifdef CHARACTER_CLASS_DEBUG
-    character_class_debug();
-    return false;
-#endif
-
 #ifdef TIME_TEST
     time_test();
     return false;
tests/unit_tests/openvpn/test_buffer.c +25 -0
index 8232f92..f994812 100644
@@ -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);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/464?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0
Gerrit-Change-Number: 464
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: plaisthos.

flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/464?usp=email )

Change subject: Replace character_class_debug with proper unit test
......................................................................

Patch Set 1: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/464?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0
Gerrit-Change-Number: 464
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Comment-Date: Fri, 01 Dec 2023 10:34:46 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment

#3 lore raw

PATCH 1/1 Replace character_class_debug with proper unit test

In reply to a message not in the archive

From: Arne Schwabe <[email protected]...>

Change-Id Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0

---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/464
This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>

Note: this requires "Remove dead remains of extract_x509_field_test"
(https://gerrit.openvpn.net/c/openvpn/+/462) to be applied first.

src/openvpn/buffer.c +0 -20
index 24f1ef2..0b94a52 100644
@@ -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)
src/openvpn/buffer.h +0 -7
index 4cc7950..0456b27 100644
@@ -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
  */
src/openvpn/init.c +0 -5
index fdab26b..9972ed7 100644
@@ -875,11 +875,6 @@
     return false;
 #endif
 
-#ifdef CHARACTER_CLASS_DEBUG
-    character_class_debug();
-    return false;
-#endif
-
 #ifdef TIME_TEST
     time_test();
     return false;
tests/unit_tests/openvpn/test_buffer.c +25 -0
index 8232f92..f994812 100644
@@ -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);
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: Replace character_class_debug with proper unit test

This is definitely more useful than having conditional tests that nobody ever runs... done a quick test on FreeBSD, passes...

[ RUN ] test_character_class
[ OK ] test_character_class
[==========] 14 test(s) run.
[ PASSED ] 14 test(s).
PASS: buffer_testdriver

Your patch has been applied to the master branch.

commit 0a27c98a61ae103d29065610abe1e4e0b61f3375

Author: Arne Schwabe
Date:   Fri Dec 1 12:22:43 2023 +0100
     Replace character_class_debug with proper unit test

     Signed-off-by: Arne Schwabe <[email protected]...>
     Acked-by: Frank Lichtenheld <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg27628.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#2) to the change originally created by plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/464?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld

Change subject: Replace character_class_debug with proper unit test
......................................................................

Replace character_class_debug with proper unit test

Change-Id Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg27628.html

---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/init.c
M tests/unit_tests/openvpn/test_buffer.c

4 files changed, 25 insertions(+), 32 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/64/464/2

src/openvpn/buffer.c +0 -20
index 24f1ef2..0b94a52 100644
@@ -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)
src/openvpn/buffer.h +0 -7
index 4cc7950..0456b27 100644
@@ -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
  */
src/openvpn/init.c +0 -5
index abba748..ca42c92 100644
@@ -875,11 +875,6 @@
     return false;
 #endif
 
-#ifdef CHARACTER_CLASS_DEBUG
-    character_class_debug();
-    return false;
-#endif
-
 #ifdef TIME_TEST
     time_test();
     return false;
tests/unit_tests/openvpn/test_buffer.c +25 -0
index 8232f92..f994812 100644
@@ -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);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/464?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0
Gerrit-Change-Number: 464
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/464?usp=email )

Change subject: Replace character_class_debug with proper unit test
......................................................................

Replace character_class_debug with proper unit test

Change-Id Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0

Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg27628.html

---
M src/openvpn/buffer.c
M src/openvpn/buffer.h
M src/openvpn/init.c
M tests/unit_tests/openvpn/test_buffer.c

4 files changed, 25 insertions(+), 32 deletions(-)
src/openvpn/buffer.c +0 -20
index 24f1ef2..0b94a52 100644
@@ -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)
src/openvpn/buffer.h +0 -7
index 4cc7950..0456b27 100644
@@ -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
  */
src/openvpn/init.c +0 -5
index abba748..ca42c92 100644
@@ -875,11 +875,6 @@
     return false;
 #endif
 
-#ifdef CHARACTER_CLASS_DEBUG
-    character_class_debug();
-    return false;
-#endif
-
 #ifdef TIME_TEST
     time_test();
     return false;
tests/unit_tests/openvpn/test_buffer.c +25 -0
index 8232f92..f994812 100644
@@ -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);

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/464?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0
Gerrit-Change-Number: 464
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged