Fix CMake checks of PCap functions, along with AirPCap
[metze/wireshark/wip.git] / epan / tvbtest.c
index 9f4879bd39836eb4060b8a882f0ac867ff3bfdae..2877e59d1ed6a11719790a9da729ff4f5569b90d 100644 (file)
@@ -2,8 +2,6 @@
  *
  * tvbtest : tvbtest.o tvbuff.o except.o
  *
- * $Id$
- *
  * Copyright (c) 2000 by Gilbert Ramirez <gram@alumni.rice.edu>
  *
  * This program is free software; you can redistribute it and/or
 #include <string.h>
 
 #include "tvbuff.h"
-#include "pint.h"
+#include "exceptions.h"
+#include "wsutil/pint.h"
 
 gboolean failed = FALSE;
 
 /* Tests a tvbuff against the expected pattern/length.
  * Returns TRUE if all tests succeeed, FALSE if any test fails */
 gboolean
-test(tvbuff_t *tvb, gchar* name,
+test(tvbuff_t *tvb, const gchar* name,
      guint8* expected_data, guint expected_length, guint expected_reported_length)
 {
        guint                   length;
@@ -73,9 +72,15 @@ test(tvbuff_t *tvb, gchar* name,
        CATCH(BoundsError) {
                ex_thrown = TRUE;
        }
+       CATCH(FragmentBoundsError) {
+               printf("02: Caught wrong exception: FragmentBoundsError\n");
+       }
        CATCH(ReportedBoundsError) {
                printf("02: Caught wrong exception: ReportedBoundsError\n");
        }
+       CATCH_ALL {
+               printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
+       }
        ENDTRY;
 
        if (!ex_thrown) {
@@ -94,9 +99,15 @@ test(tvbuff_t *tvb, gchar* name,
        CATCH(BoundsError) {
                printf("03: Caught wrong exception: BoundsError\n");
        }
+       CATCH(FragmentBoundsError) {
+               printf("03: Caught wrong exception: FragmentBoundsError\n");
+       }
        CATCH(ReportedBoundsError) {
                ex_thrown = TRUE;
        }
+       CATCH_ALL {
+               printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
+       }
        ENDTRY;
 
        if (!ex_thrown) {
@@ -114,9 +125,15 @@ test(tvbuff_t *tvb, gchar* name,
        CATCH(BoundsError) {
                ex_thrown = TRUE;
        }
+       CATCH(FragmentBoundsError) {
+               printf("04: Caught wrong exception: FragmentBoundsError\n");
+       }
        CATCH(ReportedBoundsError) {
                printf("04: Caught wrong exception: ReportedBoundsError\n");
        }
+       CATCH_ALL {
+               printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
+       }
        ENDTRY;
 
        if (!ex_thrown) {
@@ -134,9 +151,15 @@ test(tvbuff_t *tvb, gchar* name,
        CATCH(BoundsError) {
                ex_thrown = TRUE;
        }
+       CATCH(FragmentBoundsError) {
+               printf("05: Caught wrong exception: FragmentBoundsError\n");
+       }
        CATCH(ReportedBoundsError) {
                printf("05: Caught wrong exception: ReportedBoundsError\n");
        }
+       CATCH_ALL {
+               printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
+       }
        ENDTRY;
 
        if (ex_thrown) {
@@ -154,9 +177,15 @@ test(tvbuff_t *tvb, gchar* name,
        CATCH(BoundsError) {
                ex_thrown = TRUE;
        }
+       CATCH(FragmentBoundsError) {
+               printf("06: Caught wrong exception: FragmentBoundsError\n");
+       }
        CATCH(ReportedBoundsError) {
                printf("06: Caught wrong exception: ReportedBoundsError\n");
        }
+       CATCH_ALL {
+               printf("02: Caught wrong exception: %lu\n", exc->except_id.except_code);
+       }
        ENDTRY;
 
        if (ex_thrown) {
@@ -185,7 +214,7 @@ test(tvbuff_t *tvb, gchar* name,
                        return FALSE;
                }
 
-               expected32 = pntohl(expected_data);
+               expected32 = pntoh32(expected_data);
                if (val32 != expected32) {
                        printf("08: Failed TVB=%s  guint32 @ 0 %u != expected %u\n",
                                        name, val32, expected32);
@@ -212,7 +241,7 @@ test(tvbuff_t *tvb, gchar* name,
                        return FALSE;
                }
 
-               expected32 = pntohl(&expected_data[length-4]);
+               expected32 = pntoh32(&expected_data[length-4]);
                if (val32 != expected32) {
                        printf("10: Failed TVB=%s guint32 @ -4 %u != expected %u\n",
                                        name, val32, expected32);
@@ -225,29 +254,29 @@ test(tvbuff_t *tvb, gchar* name,
         * tvb_memdup() */
        for (incr = 1; incr < length; incr++) {
                for (i = 0; i < length - incr; i += incr) {
-                       ptr = tvb_memdup(tvb, i, incr);
+                       ptr = (guint8*)tvb_memdup(NULL, tvb, i, incr);
                        if (memcmp(ptr, &expected_data[i], incr) != 0) {
                                printf("11: Failed TVB=%s Offset=%d Length=%d "
                                                "Bad memdup\n",
                                                name, i, incr);
                                failed = TRUE;
-                               g_free(ptr);
+                               wmem_free(NULL, ptr);
                                return FALSE;
                        }
-                       g_free(ptr);
+                       wmem_free(NULL, ptr);
                }
        }
 
        /* One big memdup */
-       ptr = tvb_memdup(tvb, 0, -1);
+       ptr = (guint8*)tvb_memdup(NULL, tvb, 0, -1);
        if (memcmp(ptr, expected_data, length) != 0) {
                printf("12: Failed TVB=%s Offset=0 Length=-1 "
                                "Bad memdup\n", name);
                failed = TRUE;
-               g_free(ptr);
+               wmem_free(NULL, ptr);
                return FALSE;
        }
-       g_free(ptr);
+       wmem_free(NULL, ptr);
 
 
        printf("Passed TVB=%s\n", name);
@@ -364,9 +393,6 @@ run_tests(void)
        test(tvb_subset[4], "Subset 4", subset[4], subset_length[4], subset_reported_length[4]);
        test(tvb_subset[5], "Subset 5", subset[5], subset_length[5], subset_reported_length[5]);
 
-       /* Composite tvbuffs don't work at the moment -- tests commented out until
-        * they do. */
-
        /* One Real */
        printf("Making Composite 0\n");
        tvb_comp[0]             = tvb_new_composite();
@@ -381,7 +407,7 @@ run_tests(void)
        tvb_comp[1]             = tvb_new_composite();
        comp_length[1]          = small_length[0] + small_length[1];
        comp_reported_length[1] = small_reported_length[0] + small_reported_length[1];
-       comp[1]                 = g_malloc(comp_length[1]);
+       comp[1]                 = (guint8*)g_malloc(comp_length[1]);
        memcpy(comp[1], small[0], small_length[0]);
        memcpy(&comp[1][small_length[0]], small[1], small_length[1]);
        tvb_composite_append(tvb_comp[1], tvb_small[0]);
@@ -402,7 +428,7 @@ run_tests(void)
        tvb_comp[3]             = tvb_new_composite();
        comp_length[3]          = subset_length[4] + subset_length[5];
        comp_reported_length[3] = subset_reported_length[4] + subset_reported_length[5];
-       comp[3]                 = g_malloc(comp_length[3]);
+       comp[3]                 = (guint8*)g_malloc(comp_length[3]);
        memcpy(comp[3], subset[4], subset_length[4]);
        memcpy(&comp[3][subset_length[4]], subset[5], subset_length[5]);
        tvb_composite_append(tvb_comp[3], tvb_subset[4]);
@@ -414,7 +440,7 @@ run_tests(void)
        tvb_comp[4]             = tvb_new_composite();
        comp_length[4]          = small_length[0] + subset_length[1];
        comp_reported_length[4] = small_reported_length[0] + subset_reported_length[1];
-       comp[4]                 = g_malloc(comp_length[4]);
+       comp[4]                 = (guint8*)g_malloc(comp_length[4]);
        memcpy(&comp[4][0], small[0], small_length[0]);
        memcpy(&comp[4][small_length[0]], subset[1], subset_length[1]);
        tvb_composite_append(tvb_comp[4], tvb_small[0]);
@@ -432,7 +458,7 @@ run_tests(void)
                                        comp_reported_length[1] +
                                        comp_reported_length[2] +
                                        comp_reported_length[3];
-       comp[5]                 = g_malloc(comp_length[5]);
+       comp[5]                 = (guint8*)g_malloc(comp_length[5]);
 
        len = 0;
        memcpy(&comp[5][len], comp[0], comp_length[0]);