]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lwip.git/commitdiff
Added unit test that pbuf_copy returns a correct error code for pbuf queues ending...
authorgoldsimon <goldsimon@gmx.de>
Thu, 3 May 2012 18:11:23 +0000 (20:11 +0200)
committergoldsimon <goldsimon@gmx.de>
Thu, 3 May 2012 18:11:23 +0000 (20:11 +0200)
test/unit/core/test_pbuf.c [new file with mode: 0644]
test/unit/core/test_pbuf.h [new file with mode: 0644]
test/unit/lwip_unittests.c

diff --git a/test/unit/core/test_pbuf.c b/test/unit/core/test_pbuf.c
new file mode 100644 (file)
index 0000000..2911078
--- /dev/null
@@ -0,0 +1,73 @@
+#include "test_pbuf.h"
+
+#include "lwip/pbuf.h"
+#include "lwip/stats.h"
+
+#if !LWIP_STATS || !MEM_STATS ||!MEMP_STATS
+#error "This tests needs MEM- and MEMP-statistics enabled"
+#endif
+#if LWIP_DNS
+#error "This test needs DNS turned off (as it mallocs on init)"
+#endif
+
+/* Setups/teardown functions */
+
+static void
+pbuf_setup(void)
+{
+}
+
+static void
+pbuf_teardown(void)
+{
+}
+
+
+/* Test functions */
+
+/** Call pbuf_copy on a pbuf with zero length */
+START_TEST(test_pbuf_copy_zero_pbuf)
+{
+  struct pbuf *p1, *p2, *p3;
+  err_t err;
+  LWIP_UNUSED_ARG(_i);
+
+  fail_unless(lwip_stats.mem.used == 0);
+  fail_unless(lwip_stats.memp[MEMP_PBUF_POOL].used == 0);
+
+  p1 = pbuf_alloc(PBUF_RAW, 1024, PBUF_RAM);
+  fail_unless(p1 != NULL);
+  fail_unless(p1->ref == 1);
+
+  p2 = pbuf_alloc(PBUF_RAW, 2, PBUF_POOL);
+  fail_unless(p2 != NULL);
+  fail_unless(p2->ref == 1);
+  p2->len = p2->tot_len = 0;
+
+  pbuf_cat(p1, p2);
+  fail_unless(p1->ref == 1);
+  fail_unless(p2->ref == 1);
+
+  p3 = pbuf_alloc(PBUF_RAW, p1->tot_len, PBUF_POOL);
+  err = pbuf_copy(p3, p1);
+  fail_unless(err == ERR_VAL);
+
+  pbuf_free(p1);
+  pbuf_free(p3);
+  fail_unless(lwip_stats.mem.used == 0);
+
+  fail_unless(lwip_stats.mem.used == 0);
+  fail_unless(lwip_stats.memp[MEMP_PBUF_POOL].used == 0);
+}
+END_TEST
+
+
+/** Create the suite including all tests for this module */
+Suite *
+pbuf_suite(void)
+{
+  TFun tests[] = {
+    test_pbuf_copy_zero_pbuf
+  };
+  return create_suite("PBUF", tests, sizeof(tests)/sizeof(TFun), pbuf_setup, pbuf_teardown);
+}
diff --git a/test/unit/core/test_pbuf.h b/test/unit/core/test_pbuf.h
new file mode 100644 (file)
index 0000000..b2715ad
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef __TEST_PBUF_H__
+#define __TEST_PBUF_H__
+
+#include "../lwip_check.h"
+
+Suite *pbuf_suite(void);
+
+#endif
index 01023c1472e703623b327436eeac6cad46b3c236..41d1f3612f666ae57f9d57d6fe297da4a8206dc5 100644 (file)
@@ -4,6 +4,7 @@
 #include "tcp/test_tcp.h"
 #include "tcp/test_tcp_oos.h"
 #include "core/test_mem.h"
+#include "core/test_pbuf.h"
 #include "etharp/test_etharp.h"
 #include "dhcp/test_dhcp.h"
 
@@ -20,6 +21,7 @@ int main()
     tcp_suite,
     tcp_oos_suite,
     mem_suite,
+    pbuf_suite,
     etharp_suite,
     dhcp_suite
   };