Просмотр исходного кода

libdpkg: Add missing test cases for the command and varbuf modules

Guillem Jover лет назад: 15
Родитель
Сommit
7e26acd008
2 измененных файлов с 45 добавлено и 1 удалено
  1. 21 1
      lib/dpkg/test/t-command.c
  2. 24 0
      lib/dpkg/test/t-varbuf.c

+ 21 - 1
lib/dpkg/test/t-command.c

@@ -2,7 +2,7 @@
  * libdpkg - Debian packaging suite library routines
  * t-command.c - test command implementation
  *
- * Copyright © 2010 Guillem Jover <guillem@debian.org>
+ * Copyright © 2010-2011 Guillem Jover <guillem@debian.org>
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -152,6 +152,25 @@ test_command_exec(void)
 	subproc_wait_check(pid, "command exec test", 0);
 }
 
+static void
+test_command_shell(void)
+{
+	pid_t pid;
+	int ret;
+
+	pid = subproc_fork();
+	if (pid == 0)
+		command_shell("true", "command shell pass test");
+	ret = subproc_wait_check(pid, "command shell pass test", 0);
+	test_pass(ret == 0);
+
+	pid = subproc_fork();
+	if (pid == 0)
+		command_shell("false", "command shell fail test");
+	ret = subproc_wait_check(pid, "command shell fail test", PROCNOERR);
+	test_fail(ret == 0);
+}
+
 static void
 test(void)
 {
@@ -160,4 +179,5 @@ test(void)
 	test_command_add_argl();
 	test_command_add_args();
 	test_command_exec();
+	test_command_shell();
 }

+ 24 - 0
lib/dpkg/test/t-varbuf.c

@@ -199,6 +199,29 @@ test_varbuf_map_char(void)
 	varbuf_destroy(&vb);
 }
 
+static void
+test_varbuf_end_str(void)
+{
+	struct varbuf vb;
+
+	varbuf_init(&vb, 10);
+
+	varbuf_add_buf(&vb, "1234567890X", 11);
+	test_pass(vb.used == 11);
+	test_pass(vb.size >= vb.used);
+	test_mem(vb.buf, ==, "1234567890X", 11);
+
+	varbuf_trunc(&vb, 10);
+
+	varbuf_end_str(&vb);
+	test_pass(vb.used == 10);
+	test_pass(vb.size >= vb.used + 1);
+	test_pass(vb.buf[10] == '\0');
+	test_str(vb.buf, ==, "1234567890");
+
+	varbuf_destroy(&vb);
+}
+
 static void
 test_varbuf_printf(void)
 {
@@ -276,6 +299,7 @@ test(void)
 	test_varbuf_add_char();
 	test_varbuf_dup_char();
 	test_varbuf_map_char();
+	test_varbuf_end_str();
 	test_varbuf_printf();
 	test_varbuf_reset();
 	test_varbuf_detach();