From: "cron2 (Code Review)" Date: Sat, 2 Dec 2023 15:26:35 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <6f65f6f4798c48d5cc0e64a132182086c7af03a5-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="14Jq1fKGo0k="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Replace character_class_debug with proper unit test List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --14Jq1fKGo0k= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#2) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/464?usp=3Demail ) 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 Signed-off-by: Arne Schwabe Acked-by: Frank Lichtenheld Message-Id: <20231201112243.15541-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27= 628.html Signed-off-by: Gert Doering --- 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 diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 24f1ef2..0b94a52 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -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) !=3D 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) diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index 4cc7950..0456b27 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -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 */ diff --git a/src/openvpn/init.c b/src/openvpn/init.c index abba748..ca42c92 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -875,11 +875,6 @@ return false; #endif -#ifdef CHARACTER_CLASS_DEBUG - character_class_debug(); - return false; -#endif - #ifdef TIME_TEST time_test(); return false; diff --git a/tests/unit_tests/openvpn/test_buffer.c b/tests/unit_tests/open= vpn/test_buffer.c index 8232f92..f994812 100644 --- a/tests/unit_tests/openvpn/test_buffer.c +++ b/tests/unit_tests/openvpn/test_buffer.c @@ -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_DOUBL= E_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 .t= ree!"); +} 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=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0 Gerrit-Change-Number: 464 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --14Jq1fKGo0k= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #2 to the change originally cr= eated by plaisthos.

View Change

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

Replace character_class_debug with proper uni=
t test

Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477f56c9a6b705d0
Signe= d-off-by: Arne Schwabe <arne@...1227...>
Acked-by: Frank Lichtenhe= ld <frank@...2641...>
Message-Id: <20231201112243.15541-1-frank= @...2641...>
URL: https://www.mail-archive.com/openvpn-devel@...1466...= urceforge.net/msg27628.html
Signed-off-by: Gert Doering <gert@...1726...= ...>
---
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 chan= ged, 25 insertions(+), 32 deletions(-)

git pull ssh://gerrit.open=
vpn.net:29418/openvpn refs/changes/64/464/2
diff --git a/src/openvp=
n/buffer.c b/src/openvpn/buffer.c
index 24f1ef2..0b94a52 10= 0644
--- a/src/openvpn/buffer.c
+++ b/src/o= penvpn/buffer.c
@@ -1150,26 +1150,6 @@
= }
}

-#ifdef CHARACTER_CLASS_DEBUG
-
-#define CC_INCLUDE (CC_PRINT)
-#define CC_EXCLUDE (0)
-#define CC_REPLACE ('.')
-
-void
-chara= cter_class_debug(void)
= -{
- char buf[256];<= /span>
-
- while (fgets(buf, sizeof(buf), stdin) != =3D NULL)
- {=
- string_mod(buf, CC_I= NCLUDE, CC_EXCLUDE, CC_REPLACE);
- printf("%s", buf);
- }
-}
--#endif
-
#ifdef VERIFY_ALIGNMENT
void
valign4(const struct buffer *buf, const = char *file, const int line)
diff --git a/src/openvpn/buffer= .h b/src/openvpn/buffer.h
index 4cc7950..0456b27 100644
--- a/src/openvpn/buffer.h
+++ b/src/openvpn/b= uffer.h
@@ -896,8 +896,6 @@
*/
= const char *np(const char *str);

-/*#define CHARACTER_CLASS_DEBUG*/
-
/* charac= ter 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 ali= gned
*/
diff --git a/src/openvpn/init.c b= /src/openvpn/init.c
index abba748..ca42c92 100644--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -875,11 +875,6 @@
return false;
#endif

-#ifdef CHARACTER_CLASS_DEBUG
- character_class_debug();
- return false;
-#endif
-
#ifdef TIME_TEST
time_test= ();
return false;
diff --git a/tests/u= nit_tests/openvpn/test_buffer.c b/tests/unit_tests/openvpn/test_buffer.c
index 8232f92..f994812 100644
--- a/tests/uni= t_tests/openvpn/test_buffer.c
+++ b/tests/unit_tests/openvp= n/test_buffer.c
@@ -319,6 +319,30 @@
g= c_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!");
+ 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!");<= /span>
+ string_mod(buf, = CC_PRINT, CC_DIGIT, '@');
+ assert_string_equal(buf, "There is @ a nice @@@@ yea= r old tr@ ee!");
+
+ strcpy(buf, &= quot;There is \x01 a nice 1234 year old tr\x7f ee!");
+ string_mod(buf, CC_ALPHA, CC_DIG= IT, '.');
+ = assert_string_equal(buf, "There.is...a.nice......year.old.tr..ee.&qu= ot;);
+
+ strcpy(buf, "There is \x= 01 a 'nice' \"1234\"\n year old \ntr\x7f ee!");
+ string_mod(buf, CC_A= LPHA|CC_DIGIT|CC_NEWLINE|CC_SINGLE_QUOTE, CC_DOUBLE_QUOTE|CC_BLANK, '.&= #39;);
+ assert_st= ring_equal(buf, "There.is...a.'nice'..1234.\n.year.old.\ntr..e= e.");
++ 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 .&= #39;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 cm= ocka_run_group_tests_name("buffer", tests, NULL, NULL);

To view, visit change 464. To unsubscribe, or for hel= p writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib2aa85b9c34d0a0b8b1dfb9f477= f56c9a6b705d0
Gerrit-Change-Number: 464
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--14Jq1fKGo0k=--