diff mbox series

[4/6] unit: Add unit tests for language list parsers

Message ID 20240213153524.1085649-4-denkenz@gmail.com (mailing list archive)
State Accepted
Commit 43989a59566a46ff8837a64e36f15e133ab26b33
Headers show
Series [1/6] sim: Drop glib use from sim_efli_format | expand

Commit Message

Denis Kenzior Feb. 13, 2024, 3:35 p.m. UTC
Add unit tests for the newly moved sim_parse_language_list and
sim_parse_eflp functions.
---
 unit/test-simutil.c | 57 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
diff mbox series

Patch

diff --git a/unit/test-simutil.c b/unit/test-simutil.c
index 8364f200c665..4199991a4d2a 100644
--- a/unit/test-simutil.c
+++ b/unit/test-simutil.c
@@ -695,6 +695,59 @@  static void test_auth_build_parse(void)
 	g_assert(!memcmp(kc_b.data, kc, sizeof(kc)));
 }
 
+static void test_parse_language_list(void)
+{
+	static const unsigned char empty[] = {
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+	};
+	static const unsigned char efpl[] = {
+		'e', 'n', 0xff, 0xff, 'd', 'e', 'f', 'r', 0xff, 0xff, 'n', 'l'
+	};
+
+	char **parsed;
+	char *joined;
+
+	parsed = sim_parse_language_list(empty, sizeof(empty));
+	assert(!parsed);
+
+	parsed = sim_parse_language_list(efpl, sizeof(efpl));
+	assert(parsed);
+	joined = l_strjoinv(parsed, ':');
+	assert(!strcmp(joined, "en:de:fr:nl"));
+	l_strfreev(parsed);
+	l_free(joined);
+
+	parsed = sim_parse_language_list(efpl, sizeof(efpl) - 1);
+	assert(parsed);
+	joined = l_strjoinv(parsed, ':');
+	assert(!strcmp(joined, "en:de:fr"));
+	l_strfreev(parsed);
+	l_free(joined);
+}
+
+static void test_parse_eflp(void)
+{
+	static const unsigned char empty[] = {
+		0xff, 0xff, 0xff, 0xff, 0xff, 0xff
+	};
+	static const unsigned char eflp[] = {
+		0x00, 0x01, 0x02, 0x03, 0x04, 0x05
+	};
+
+	char **parsed;
+	char *joined;
+
+	parsed = sim_parse_eflp(empty, sizeof(empty));
+	assert(!parsed);
+
+	parsed = sim_parse_eflp(eflp, sizeof(eflp));
+	assert(parsed);
+	joined = l_strjoinv(parsed, ':');
+	assert(!strcmp(joined, "de:en:it:fr:es:nl"));
+	l_strfreev(parsed);
+	l_free(joined);
+}
+
 int main(int argc, char **argv)
 {
 	g_test_init(&argc, &argv, NULL);
@@ -716,5 +769,9 @@  int main(int argc, char **argv)
 	g_test_add_func("/testsimutil/2G path", test_get_2g_path);
 	g_test_add_func("/testsimutil/auth build parse", test_auth_build_parse);
 
+	g_test_add_func("/testsimutil/parse_language_list",
+						test_parse_language_list);
+	g_test_add_func("/testsimutil/parse_efpl", test_parse_eflp);
+
 	return g_test_run();
 }