From: "flichtenheld (Code Review)"
Date: Wed, 1 Oct 2025 15:00:32 +0000
In-Reply-To:
References:
Reply-To: frank@...2641..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net
Message-ID:
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="980rDd7Gnsc="; charset=UTF-8
Subject: [Openvpn-devel] [M] Change in openvpn[master]: test_options_parse:
Start new UT for options_parse.c
List-Id:
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
To: plaisthos
Cc: openvpn-devel
--980rDd7Gnsc=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: plaisthos.
Hello plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/1244?usp=3Demail
to look at the new patch set (#3).
Change subject: test_options_parse: Start new UT for options_parse.c
......................................................................
test_options_parse: Start new UT for options_parse.c
For now contains one test case for parse_line.
Change-Id: I95032d2539d994abf69fc17319ed1a429c3bb948
Signed-off-by: Frank Lichtenheld
---
M CMakeLists.txt
M tests/unit_tests/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_options_parse.c
3 files changed, 227 insertions(+), 0 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/44/1244/3
diff --git a/CMakeLists.txt b/CMakeLists.txt
index aeef480..37bfc03 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -685,6 +685,7 @@
# Clang-cl (which is also MSVC) is wrongly detected to support wrap
if (NOT MSVC AND "${LD_SUPPORTS_WRAP}")
list(APPEND unit_tests
+ "test_options_parse"
"test_tls_crypt"
)
endif ()
@@ -826,6 +827,20 @@
src/compat/compat-strsep.c
)
+ if (TARGET test_options_parse)
+ target_link_options(test_options_parse PRIVATE
+ -Wl,--wrap=3Dadd_option
+ -Wl,--wrap=3Dremove_option
+ -Wl,--wrap=3Dupdate_option
+ -Wl,--wrap=3Dusage
+ )
+ target_sources(test_options_parse PRIVATE
+ tests/unit_tests/openvpn/mock_get_random.c
+ src/openvpn/options_parse.c
+ src/openvpn/options_util.c
+ )
+ endif ()
+
target_sources(test_packet_id PRIVATE
tests/unit_tests/openvpn/mock_get_random.c
src/openvpn/otime.c
diff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/unit_tests/openvp=
n/Makefile.am
index f7b1bc8..8e94665 100644
--- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_tests/openvpn/Makefile.am
@@ -9,6 +9,7 @@
user_pass_testdriver push_update_msg_testdriver provider_testdriver socke=
t_testdriver
if HAVE_LD_WRAP_SUPPORT
+test_binaries +=3D options_parse_testdriver
if !WIN32
test_binaries +=3D tls_crypt_testdriver
endif
@@ -190,6 +191,21 @@
$(top_srcdir)/src/openvpn/platform.c
endif
+options_parse_testdriver_CFLAGS =3D -I$(top_srcdir)/src/openvpn -I$(top_s=
rcdir)/src/compat @TEST_CFLAGS@
+options_parse_testdriver_LDFLAGS =3D @TEST_LDFLAGS@ -L$(top_srcdir)/src/op=
envpn \
+ -Wl,--wrap=3Dadd_option \
+ -Wl,--wrap=3Dupdate_option \
+ -Wl,--wrap=3Dremove_option \
+ -Wl,--wrap=3Dusage
+options_parse_testdriver_SOURCES =3D test_options_parse.c \
+ mock_msg.c mock_msg.h test_common.h \
+ mock_get_random.c \
+ $(top_srcdir)/src/openvpn/options_parse.c \
+ $(top_srcdir)/src/openvpn/options_util.c \
+ $(top_srcdir)/src/openvpn/buffer.c \
+ $(top_srcdir)/src/openvpn/win32-util.c \
+ $(top_srcdir)/src/openvpn/platform.c
+
provider_testdriver_CFLAGS =3D \
-I$(top_srcdir)/include -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/op=
envpn \
@TEST_CFLAGS@ $(OPTIONAL_CRYPTO_CFLAGS)
diff --git a/tests/unit_tests/openvpn/test_options_parse.c b/tests/unit_tes=
ts/openvpn/test_options_parse.c
new file mode 100644
index 0000000..9472c78
--- /dev/null
+++ b/tests/unit_tests/openvpn/test_options_parse.c
@@ -0,0 +1,196 @@
+/*
+ * OpenVPN -- An application to securely tunnel IP networks
+ * over a single UDP port, with support for SSL/TLS-based
+ * session authentication and key exchange,
+ * packet encryption, packet authentication, and
+ * packet compression.
+ *
+ * Copyright (C) 2025 OpenVPN Inc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see .
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include "options.h"
+#include "test_common.h"
+#include "mock_msg.h"
+
+void
+__wrap_add_option(struct options *options, char *p[], bool is_inline, cons=
t char *file,
+ int line, const int level, const msglvl_t msglevel,
+ const unsigned int permission_mask, unsigned int *option=
_types_found,
+ struct env_set *es)
+{
+}
+
+void
+__wrap_remove_option(struct context *c, struct options *options, char *p[]=
, bool is_inline,
+ const char *file, int line, const msglvl_t msglevel,
+ const unsigned int permission_mask, unsigned int *opt=
ion_types_found,
+ struct env_set *es)
+{
+}
+
+void
+__wrap_update_option(struct context *c, struct options *options, char *p[]=
, bool is_inline,
+ const char *file, int line, const int level, const ms=
glvl_t msglevel,
+ const unsigned int permission_mask, unsigned int *opt=
ion_types_found,
+ struct env_set *es, unsigned int *update_options_foun=
d)
+{
+}
+
+void
+__wrap_usage(void)
+{
+}
+
+/* for building long texts */
+#define A_TIMES_256 "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAO"
+
+static void
+test_parse_line(void **state)
+{
+ char *p[MAX_PARMS + 1] =3D { 0 };
+ struct gc_arena gc =3D gc_new();
+ int res =3D 0;
+
+#define PARSE_LINE_TST(string) =
\
+ do =
\
+ { =
\
+ CLEAR(p); =
\
+ res =3D parse_line(string, p, SIZE(p) - 1, "test_options_parse", 1=
, M_INFO, &gc); \
+ } while (0);
+
+ /* basic example */
+ PARSE_LINE_TST("some-opt firstparm second-parm");
+ assert_int_equal(res, 3);
+ assert_string_equal(p[0], "some-opt");
+ assert_string_equal(p[1], "firstparm");
+ assert_string_equal(p[2], "second-parm");
+ assert_null(p[res]);
+
+ /* basic quoting, -- is not handled special */
+ PARSE_LINE_TST("--some-opt 'first parm' \"second' 'parm\"");
+ assert_int_equal(res, 3);
+ assert_string_equal(p[0], "--some-opt");
+ assert_string_equal(p[1], "first parm");
+ assert_string_equal(p[2], "second' 'parm");
+ assert_null(p[res]);
+
+ /* escaped quotes */
+ PARSE_LINE_TST("\"some opt\" 'first\" \"parm' \"second\\\" \\\"parm\""=
);
+ assert_int_equal(res, 3);
+ assert_string_equal(p[0], "some opt");
+ assert_string_equal(p[1], "first\" \"parm");
+ assert_string_equal(p[2], "second\" \"parm");
+ assert_null(p[res]);
+
+ /* missing closing quote */
+ PARSE_LINE_TST("--some-opt 'first parm \"second parm\"");
+ assert_int_equal(res, 0);
+
+ /* escaped backslash */
+ PARSE_LINE_TST("some\\\\opt C:\\\\directory\\\\file");
+ assert_int_equal(res, 2);
+ assert_string_equal(p[0], "some\\opt");
+ assert_string_equal(p[1], "C:\\directory\\file");
+ assert_null(p[res]);
+
+ /* comment chars are not special inside parameter */
+ PARSE_LINE_TST("some-opt firstparm; second#parm");
+ assert_int_equal(res, 3);
+ assert_string_equal(p[0], "some-opt");
+ assert_string_equal(p[1], "firstparm;");
+ assert_string_equal(p[2], "second#parm");
+ assert_null(p[res]);
+
+ /* comment */
+ PARSE_LINE_TST("some-opt firstparm # secondparm");
+ assert_int_equal(res, 2);
+ assert_string_equal(p[0], "some-opt");
+ assert_string_equal(p[1], "firstparm");
+ assert_null(p[res]);
+
+ /* parameter just long enough */
+ PARSE_LINE_TST("opt " A_TIMES_256);
+ assert_int_equal(res, 2);
+ assert_string_equal(p[0], "opt");
+ assert_string_equal(p[1], A_TIMES_256);
+ assert_null(p[res]);
+
+ /* quoting doesn't count for parameter length */
+ PARSE_LINE_TST("opt \"" A_TIMES_256 "\"");
+ assert_int_equal(res, 2);
+ assert_string_equal(p[0], "opt");
+ assert_string_equal(p[1], A_TIMES_256);
+ assert_null(p[res]);
+
+ /* very long line */
+ PARSE_LINE_TST("opt " A_TIMES_256 " " A_TIMES_256 " " A_TIMES_256 " " =
A_TIMES_256);
+ assert_int_equal(res, 5);
+ assert_string_equal(p[0], "opt");
+ assert_string_equal(p[1], A_TIMES_256);
+ assert_string_equal(p[2], A_TIMES_256);
+ assert_string_equal(p[3], A_TIMES_256);
+ assert_string_equal(p[4], A_TIMES_256);
+ assert_null(p[res]);
+
+ /* parameter too long */
+ PARSE_LINE_TST("opt " A_TIMES_256 "B");
+ assert_int_equal(res, 0);
+
+ /* max parameters */
+ PARSE_LINE_TST("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15");
+ assert_int_equal(res, MAX_PARMS);
+ char num[3];
+ for (int i =3D 0; i < MAX_PARMS; i++)
+ {
+ assert_true(snprintf(num, 3, "%d", i) < 3);
+ assert_string_equal(p[i], num);
+ }
+ assert_null(p[res]);
+
+ /* too many parameters, overflow is ignored */
+ PARSE_LINE_TST("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16");
+ assert_int_equal(res, MAX_PARMS);
+ for (int i =3D 0; i < MAX_PARMS; i++)
+ {
+ assert_true(snprintf(num, 3, "%d", i) < 3);
+ assert_string_equal(p[i], num);
+ }
+ assert_null(p[res]);
+
+ gc_free(&gc);
+}
+
+int
+main(void)
+{
+ const struct CMUnitTest tests[] =3D {
+ cmocka_unit_test(test_parse_line),
+ };
+
+ return cmocka_run_group_tests_name("options_parse", tests, NULL, NULL);
+}
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1244?usp=3Demail
To unsubscribe, or for help writing mail filters, visit http://gerrit.openv=
pn.net/settings?usp=3Demail
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I95032d2539d994abf69fc17319ed1a429c3bb948
Gerrit-Change-Number: 1244
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-Attention: plaisthos
--980rDd7Gnsc=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is cur=
rently required from: plaisthos.
flichtenheld uploaded patch set #3 to this change.
<=
p>View C=
hange
test_options_parse: Start new UT for options_par=
se.c
For now contains one test case for parse_line.
Change-Id=
: I95032d2539d994abf69fc17319ed1a429c3bb948
Signed-off-by: Frank Lichten=
held <frank@...2641...>
---
M CMakeLists.txt
M tests/unit_te=
sts/openvpn/Makefile.am
A tests/unit_tests/openvpn/test_options_parse.c<=
br>3 files changed, 227 insertions(+), 0 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/44/1244/=
3
diff --git a/CMakeLists.txt b/CMakeLists.txt
inde=
x aeef480..37bfc03 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -685,6 +685,7 @@
# Clang-cl (which is also MSVC) is wrongly detected to support wrap<=
/span>
if (NOT MSVC AND "${LD_SUPPORTS_WRAP}")
list(APPEND unit_tests
+ "test_options_parse" "test_tls_crypt"
=
)
endif ()
@@ -826,6 +827,20 @@
src/compat/compat-strsep.c
)<=
/span>
+ =
if (TARGET test_options_parse)
+ target_link_options(test_options_parse PRIVATE<=
br>+ -Wl,--wrap=3Dad=
d_option
+ =
-Wl,--wrap=3Dremove_option
+ -Wl,--wrap=3Dupdate_option
+ -Wl,--wrap=3Dusage
+ )
+ target_sources(test_options_parse PRIVATE
+ tests/unit_t=
ests/openvpn/mock_get_random.c
+ src/openvpn/options_parse.c
+ src/openvpn/options_util.c
+ )
+ endif ()
+
target_sources(test=
_packet_id PRIVATE
tests/unit_tests/openvpn/mock_g=
et_random.c
src/openvpn/otime.c
di=
ff --git a/tests/unit_tests/openvpn/Makefile.am b/tests/unit_tests/openvpn/=
Makefile.am
index f7b1bc8..8e94665 100644
-=
-- a/tests/unit_tests/openvpn/Makefile.am
+++ b/tests/unit_=
tests/openvpn/Makefile.am
@@ -9,6 +9,7 @@
=
user_pass_testdriver push_update_msg_testdriver provider_testdriver socket=
_testdriver
if HAVE_LD_WRAP_SUPPORT
+test_binaries +=3D optio=
ns_parse_testdriver
if !WIN32
test_binari=
es +=3D tls_crypt_testdriver
endif
@@ -190=
,6 +191,21 @@
$(top_srcdir)/src/openvpn/platform.c=
endif
+options_parse_testdriver_CFLAGS =3D -I$(top_srcdir)/src/ope=
nvpn -I$(top_srcdir)/src/compat @TEST_CFLAGS@
+options_parse_testdriver_LDFLAGS =3D @TEST_LDFLAG=
S@ -L$(top_srcdir)/src/openvpn \
+ -Wl,--wrap=3Dadd_option \
+ -Wl,--wrap=3Dupdate_option \
+ -Wl,--wrap=3Dremove_option \
+ -Wl,--wrap=3Dusage
+options_parse_testdriver_SOURCES =
=3D test_options_parse.c \
+ mock_msg.c mock_msg.h test_common.h \
+ mock_get_random.c \
+ $(top_srcdir)/src/openvpn/options_parse.c \
+ $(top_srcdir)/src/open=
vpn/options_util.c \
=
+ $(top_srcdir)/src/openvpn/buffer.c \
+ $(top_srcdir)/src/openvpn/win32-util.c \
+ $(top_srcdir)/src/openvpn/platfor=
m.c
+
provider_testdriver_CFLAGS =3D \
-I$(top_srcdir)/inclu=
de -I$(top_srcdir)/src/compat -I$(top_srcdir)/src/openvpn \
@TEST_CFLAGS@ $(OPTIONAL_CRYPTO_CFLAGS)
diff --git a/tes=
ts/unit_tests/openvpn/test_options_parse.c b/tests/unit_tests/openvpn/test_=
options_parse.c
new file mode 100644
index =
0000000..9472c78
--- /dev/null
+++ b/tests/=
unit_tests/openvpn/test_options_parse.c
@@ -0,0 +1,196 @@=
span>
+/*
+ * OpenVPN -- An application to secur=
ely tunnel IP networks
+ * over a single UDP port, with support for SSL/TLS-based
+ * session=
authentication and key exchange,
+ * packet encryption, packet authentication, and<=
/span>
+ * packe=
t compression.
+ *
+ * Copyright (C) 2025=
OpenVPN Inc <sales@...515...>
+ *
+=
* This program is free software; you can redistribute it and/or modify
+ * it under the terms=
of the GNU General Public License version 2
+ * as published by the Free Software Foundation.<=
/span>
+ *
+ * This program is distributed in th=
e hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty =
of
+ * MERCHANTABILI=
TY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more detail=
s.
+ *
+ * You should have received a cop=
y of the GNU General Public License along
+ * with this program; if not, see <https://www.gn=
u.org/licenses/>.
=
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "syshead.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <setjmp.h>
+#include <cmocka.h>+
+#include "options.h"
+#include "test_common.h"=
span>
+#include "mock_m=
sg.h"
++void
+__wrap_add_option(struct options *options=
, char *p[], bool is_inline, const char *file,
+ int line, const int level, con=
st msglvl_t msglevel,
+ const unsigned int permission_mask, unsigned int *optio=
n_types_found,
+ =
struct env_set *es)
+{
+}
+
+void
+__wrap_remove_option(struct context *c, struct options *=
options, char *p[], bool is_inline,
+ const char *file, int line, const msgl=
vl_t msglevel,
+ =
const unsigned int permission_mask, unsigned int *option_ty=
pes_found,
+ =
struct env_set *es)
+{
+}
+
+void
+__wrap_update_option(struct context *c, struct options *=
options, char *p[], bool is_inline,
+ const char *file, int line, const int =
level, const msglvl_t msglevel,
+ const unsigned int permission_mask, unsign=
ed int *option_types_found,
+ struct env_set *es, unsigned int *update_optio=
ns_found)
+{+}
+
+void
+__wra=
p_usage(void)
+{
+}
+
+/* for building long texts */
+#define A_TIMES_256 "AAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
AAAAAAO"
+
+static void
+test_parse_line(void **state)
+{
+ char *p[MAX_PARMS + 1] =3D { 0 };
+ struct gc_arena gc =
=3D gc_new();
+ in=
t res =3D 0;
+=
+#define PARSE_LINE_TST(str=
ing) \
<=
span style=3D"color: hsl(120, 100%, 40%);">+ do =
\
+ { =
\
+ CLEAR(p); =
\
+ res =3D parse_line(string, p, SIZE(p) =
- 1, "test_options_parse", 1, M_INFO, &gc); \
+ } while (0);
+
+ /* basic example */
+ PARSE_LINE_TST("some-opt firstparm second-pa=
rm");
+ asser=
t_int_equal(res, 3);
=
+ assert_string_equal(p[0], "some-opt");
+ assert_string_equal(p[1], "first=
parm");
+ ass=
ert_string_equal(p[2], "second-parm");
+ assert_null(p[res]);
+
+ /* basic quoting, -- is not handled special */
+ PARSE_LINE_TST("--so=
me-opt 'first parm' \"second' 'parm\"");
+ assert_int_equal(re=
s, 3);
+ assert_st=
ring_equal(p[0], "--some-opt");
+ assert_string_equal(p[1], "first parm")=
;
+ assert_string_=
equal(p[2], "second' 'parm");
+ assert_null(p[res]);
+
+ /* escaped quotes */
+ PARSE_LINE_TST("\"some opt\" 'fi=
rst\" \"parm' \"second\\\" \\\"parm\"&quo=
t;);
+ assert_int_=
equal(res, 3);
+ a=
ssert_string_equal(p[0], "some opt");
+ assert_string_equal(p[1], "first\"=
; \"parm");
+ assert_string_equal(p[2], "second\" \"parm");
+ assert_null(p[res])=
;
+
+ /* missing closing quote */
+ PARSE_LINE_TST("=
--some-opt 'first parm \"second parm\"");
+ assert_int_equal(res, 0);
+
+ /* escaped backslash */
+ PARSE_LINE_TST("some\\\\=
opt C:\\\\directory\\\\file");
+ assert_int_equal(res, 2);
+ assert_string_equal(p[0], "some\\opt&quo=
t;);
+ assert_stri=
ng_equal(p[1], "C:\\directory\\file");
+ assert_null(p[res]);
+
+ /* comment chars are not special inside parameter */
+ PARSE_LINE_TST(&quo=
t;some-opt firstparm; second#parm");
+ assert_int_equal(res, 3);
+ assert_string_equal(p[0], "some-=
opt");
+ asse=
rt_string_equal(p[1], "firstparm;");
+ assert_string_equal(p[2], "second#parm&=
quot;);
+ assert_n=
ull(p[res]);
+=
+ /* comment */+ PARSE_LINE_TST("som=
e-opt firstparm # secondparm");
+ assert_int_equal(res, 2);
+ assert_string_equal(p[0], "some-opt&quo=
t;);
+ assert_stri=
ng_equal(p[1], "firstparm");
+ assert_null(p[res]);
+
+ /* parameter just long enough */
+ PARSE_LINE_TST("opt " A_TIMES_256);
+ assert_int_equal(re=
s, 2);
+ assert_st=
ring_equal(p[0], "opt");
+ assert_string_equal(p[1], A_TIMES_256);
+ assert_null(p[res]);
<=
span style=3D"color: hsl(120, 100%, 40%);">+
+ /* quoting doesn't count for parameter len=
gth */
+ PARSE_LIN=
E_TST("opt \"" A_TIMES_256 "\"");
<=
span style=3D"color: hsl(120, 100%, 40%);">+ assert_int_equal(res, 2);=
span>
+ assert_string_equ=
al(p[0], "opt");
+ assert_string_equal(p[1], A_TIMES_256);
+ assert_null(p[res]);
+
+ /* very long line */
+ PARSE_LINE_TST("opt " A_TIMES_256 "=
; " A_TIMES_256 " " A_TIMES_256 " " A_TIMES_256);<=
/span>
+ assert_int_equal=
(res, 5);
+ assert=
_string_equal(p[0], "opt");
+ assert_string_equal(p[1], A_TIMES_256);
+ assert_string_equal(p[2], A_T=
IMES_256);
+ asser=
t_string_equal(p[3], A_TIMES_256);
+ assert_string_equal(p[4], A_TIMES_256);
+ assert_null(p[res]);
<=
span style=3D"color: hsl(120, 100%, 40%);">+
+ /* parameter too long */
+ PARSE_LINE_TST("opt " A_TIM=
ES_256 "B");
+ assert_int_equal(res, 0);
+
+ /*=
max parameters */
+ =
PARSE_LINE_TST("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15");
+ assert_int_equal(res,=
MAX_PARMS);
+ cha=
r num[3];
+ for (i=
nt i =3D 0; i < MAX_PARMS; i++)
+ {
=
+ assert_true(snprintf(num, 3, "%d", i) < 3);
+ assert_string_equal(p=
[i], num);
+ }
+ assert_null(p[res])=
;
+
+ /* too many parameters, overflow =
is ignored */
+ PA=
RSE_LINE_TST("0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16");<=
br>+ assert_int_equal(res, M=
AX_PARMS);
+ for (=
int i =3D 0; i < MAX_PARMS; i++)
+ {
+ assert_true(snprintf(num, 3, "%d", i) < 3);+ assert_string_equal(=
p[i], num);
+ }
+ assert_null(p[res]=
);
+
+ gc_free(&gc);
+}
+
+int
+main(void)=
span>
+{
+ const struct CMUnitTest tests[] =3D=
{
+ cmocka_un=
it_test(test_parse_line),
+ };
+=
+ return cmocka_run_grou=
p_tests_name("options_parse", tests, NULL, NULL);
+}
=
To view, visit change 1244. To unsubscribe, or for help writing mail filters=
, visit settings=
.
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I95032d2539d994abf69fc17319e=
d1a429c3bb948
Gerrit-Change-Number: 1244
Gerrit-PatchSet: 3
Gerrit-Owner: flichtenheld <frank@...2723...=
.>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
=
--980rDd7Gnsc=--