Rework some code in tvbtest to fix an issue when testing composite tvbs.

tvbtest now completes all the tvb tests successfully (including those for composite tvbs) !!

In addition, running tvbtest under valgrind shows no memory leaks.


svn path=/trunk/; revision=40269
This commit is contained in:
Bill Meier 2011-12-21 23:42:17 +00:00
parent a15064f02f
commit 9708878fa3
1 changed files with 89 additions and 55 deletions

View File

@ -39,9 +39,10 @@ gboolean failed = FALSE;
* Returns TRUE if all tests succeeed, FALSE if any test fails */
gboolean
test(tvbuff_t *tvb, gchar* name,
guint8* expected_data, guint expected_length)
guint8* expected_data, guint expected_length, guint expected_reported_length)
{
guint length;
guint reported_length;
guint8 *ptr;
volatile gboolean ex_thrown;
volatile guint32 val32;
@ -57,6 +58,15 @@ test(tvbuff_t *tvb, gchar* name,
return FALSE;
}
reported_length = tvb_reported_length(tvb);
if (reported_length != expected_reported_length) {
printf("01: Failed TVB=%s Reported length of tvb=%u while expected reported length=%u\n",
name, reported_length, expected_reported_length);
failed = TRUE;
return FALSE;
}
/* Test boundary case. A BoundsError exception should be thrown. */
ex_thrown = FALSE;
TRY {
@ -77,11 +87,11 @@ test(tvbuff_t *tvb, gchar* name,
return FALSE;
}
/* Test boundary case with one more byte. A ReportedBoundsError
/* Test boundary case with reported_length+1. A ReportedBoundsError
exception should be thrown. */
ex_thrown = FALSE;
TRY {
tvb_get_ptr(tvb, 0, length + 2);
tvb_get_ptr(tvb, 0, reported_length + 1);
}
CATCH(BoundsError) {
printf("03: Caught wrong exception: BoundsError\n");
@ -93,7 +103,7 @@ test(tvbuff_t *tvb, gchar* name,
if (!ex_thrown) {
printf("03: Failed TVB=%s No ReportedBoundsError when retrieving %u bytes\n",
name, length + 2);
name, reported_length + 1);
failed = TRUE;
return FALSE;
}
@ -266,13 +276,19 @@ run_tests(void)
tvbuff_t *tvb_large[3];
tvbuff_t *tvb_subset[6];
guint8 *small[3];
guint small_length[3];
guint small_reported_length[3];
guint8 *large[3];
guint large_length[3];
guint large_reported_length[3];
guint8 *subset[6];
guint subset_length[6];
guint subset_reported_length[6];
guint8 temp;
guint8 *comp[6];
tvbuff_t *tvb_comp[6];
guint comp_length[6];
guint comp_reported_length[6];
int len;
tvb_parent = tvb_new_real_data("", 0, 0);
@ -283,7 +299,8 @@ run_tests(void)
for (j = 0; j < 16; j++) {
small[i][j] = temp + j;
}
small_length[i] = 16;
small_reported_length[i] = 17;
tvb_small[i] = tvb_new_child_real_data(tvb_parent, small[i], 16, 17);
tvb_set_free_cb(tvb_small[i], g_free);
}
@ -296,50 +313,58 @@ run_tests(void)
large[i][j] = temp + j;
}
large_length[i] = 19;
large_reported_length[i] = 20;
tvb_large[i] = tvb_new_child_real_data(tvb_parent, large[i], 19, 20);
tvb_set_free_cb(tvb_large[i], g_free);
}
/* Test the TVBUFF_REAL_DATA objects. */
test(tvb_small[0], "Small 0", small[0], 16);
test(tvb_small[1], "Small 1", small[1], 16);
test(tvb_small[2], "Small 2", small[2], 16);
test(tvb_small[0], "Small 0", small[0], small_length[0], small_reported_length[0]);
test(tvb_small[1], "Small 1", small[1], small_length[1], small_reported_length[1]);
test(tvb_small[2], "Small 2", small[2], small_length[2], small_reported_length[2]);
test(tvb_large[0], "Large 0", large[0], 19);
test(tvb_large[1], "Large 1", large[1], 19);
test(tvb_large[2], "Large 2", large[2], 19);
test(tvb_large[0], "Large 0", large[0], large_length[0], large_reported_length[0]);
test(tvb_large[1], "Large 1", large[1], large_length[1], large_reported_length[1]);
test(tvb_large[2], "Large 2", large[2], large_length[2], large_reported_length[2]);
tvb_subset[0] = tvb_new_subset(tvb_small[0], 0, 8, 9);
subset[0] = &small[0][0];
subset_length[0] = 8;
subset_length[0] = 8;
subset_reported_length[0] = 9;
tvb_subset[0] = tvb_new_subset(tvb_small[0], 0, 8, 9);
subset[0] = &small[0][0];
tvb_subset[1] = tvb_new_subset(tvb_large[0], -10, 10, 11);
subset[1] = &large[0][9];
subset_length[1] = 10;
subset_length[1] = 10;
subset_reported_length[1] = 11;
tvb_subset[1] = tvb_new_subset(tvb_large[0], -10, 10, 11);
subset[1] = &large[0][9];
tvb_subset[2] = tvb_new_subset(tvb_small[1], -16, -1, 17);
subset[2] = &small[1][0];
subset_length[2] = 16;
subset_length[2] = 16;
subset_reported_length[2] = 17;
tvb_subset[2] = tvb_new_subset(tvb_small[1], -16, -1, 17);
subset[2] = &small[1][0];
tvb_subset[3] = tvb_new_subset(tvb_subset[0], 0, 3, 4);
subset[3] = &small[0][0];
subset_length[3] = 3;
subset_length[3] = 3;
subset_reported_length[3] = 4;
tvb_subset[3] = tvb_new_subset(tvb_subset[0], 0, 3, 4);
subset[3] = &small[0][0];
tvb_subset[4] = tvb_new_subset(tvb_subset[1], -5, 5, 6);
subset[4] = &large[0][14];
subset_length[4] = 5;
subset_length[4] = 5;
subset_reported_length[4] = 6;
tvb_subset[4] = tvb_new_subset(tvb_subset[1], -5, 5, 6);
subset[4] = &large[0][14];
tvb_subset[5] = tvb_new_subset(tvb_subset[2], 4, 8, 9);
subset[5] = &small[1][4];
subset_length[5] = 8;
subset_length[5] = 8;
subset_reported_length[5] = 9;
tvb_subset[5] = tvb_new_subset(tvb_subset[2], 4, 8, 9);
subset[5] = &small[1][4];
/* Test the TVBUFF_SUBSET objects. */
test(tvb_subset[0], "Subset 0", subset[0], subset_length[0]);
test(tvb_subset[1], "Subset 1", subset[1], subset_length[1]);
test(tvb_subset[2], "Subset 2", subset[2], subset_length[2]);
test(tvb_subset[3], "Subset 3", subset[3], subset_length[3]);
test(tvb_subset[4], "Subset 4", subset[4], subset_length[4]);
test(tvb_subset[5], "Subset 5", subset[5], subset_length[5]);
test(tvb_subset[0], "Subset 0", subset[0], subset_length[0], subset_reported_length[0]);
test(tvb_subset[1], "Subset 1", subset[1], subset_length[1], subset_reported_length[1]);
test(tvb_subset[2], "Subset 2", subset[2], subset_length[2], subset_reported_length[2]);
test(tvb_subset[3], "Subset 3", subset[3], subset_length[3], subset_reported_length[3]);
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. */
@ -347,18 +372,20 @@ run_tests(void)
/* One Real */
printf("Making Composite 0\n");
tvb_comp[0] = tvb_new_composite();
comp_length[0] = small_length[0];
comp_reported_length[0] = small_reported_length[0];
comp[0] = small[0];
comp_length[0] = 16;
tvb_composite_append(tvb_comp[0], tvb_small[0]);
tvb_composite_finalize(tvb_comp[0]);
/* Two Reals */
printf("Making Composite 1\n");
tvb_comp[1] = tvb_new_composite();
comp[1] = g_malloc(32);
comp_length[1] = 32;
memcpy(comp[1], small[0], 16);
memcpy(&comp[1][16], small[1], 16);
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]);
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]);
tvb_composite_append(tvb_comp[1], tvb_small[1]);
tvb_composite_finalize(tvb_comp[1]);
@ -366,18 +393,20 @@ run_tests(void)
/* One subset */
printf("Making Composite 2\n");
tvb_comp[2] = tvb_new_composite();
comp[2] = subset[1];
comp_length[2] = subset_length[1];
comp_reported_length[2] = subset_reported_length[1];
comp[2] = subset[1];
tvb_composite_append(tvb_comp[2], tvb_subset[1]);
tvb_composite_finalize(tvb_comp[2]);
/* Two subsets */
printf("Making Composite 3\n");
tvb_comp[3] = tvb_new_composite();
comp[3] = g_malloc(13);
comp_length[3] = 13;
memcpy(comp[3], &large[0][14], 5);
memcpy(&comp[3][5], &small[1][4], 8);
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]);
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]);
tvb_composite_append(tvb_comp[3], tvb_subset[5]);
tvb_composite_finalize(tvb_comp[3]);
@ -385,10 +414,11 @@ run_tests(void)
/* One real, one subset */
printf("Making Composite 4\n");
tvb_comp[4] = tvb_new_composite();
comp[4] = g_malloc(16 + subset_length[1]);
comp_length[4] = 16 + subset_length[1];
memcpy(comp[4], small[0], 16);
memcpy(&comp[4][16], subset[1], subset_length[1]);
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]);
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]);
tvb_composite_append(tvb_comp[4], tvb_subset[1]);
tvb_composite_finalize(tvb_comp[4]);
@ -400,6 +430,10 @@ run_tests(void)
comp_length[1] +
comp_length[2] +
comp_length[3];
comp_reported_length[5] = comp_reported_length[0] +
comp_reported_length[1] +
comp_reported_length[2] +
comp_reported_length[3];
comp[5] = g_malloc(comp_length[5]);
len = 0;
@ -418,12 +452,12 @@ run_tests(void)
tvb_composite_finalize(tvb_comp[5]);
/* Test the TVBUFF_COMPOSITE objects. */
test(tvb_comp[0], "Composite 0", comp[0], comp_length[0]);
skip(tvb_comp[1], "Composite 1", comp[1], comp_length[1]);
test(tvb_comp[2], "Composite 2", comp[2], comp_length[2]);
skip(tvb_comp[3], "Composite 3", comp[3], comp_length[3]);
skip(tvb_comp[4], "Composite 4", comp[4], comp_length[4]);
skip(tvb_comp[5], "Composite 5", comp[5], comp_length[5]);
test(tvb_comp[0], "Composite 0", comp[0], comp_length[0], comp_reported_length[0]);
test(tvb_comp[1], "Composite 1", comp[1], comp_length[1], comp_reported_length[1]);
test(tvb_comp[2], "Composite 2", comp[2], comp_length[2], comp_reported_length[2]);
test(tvb_comp[3], "Composite 3", comp[3], comp_length[3], comp_reported_length[3]);
test(tvb_comp[4], "Composite 4", comp[4], comp_length[4], comp_reported_length[4]);
test(tvb_comp[5], "Composite 5", comp[5], comp_length[5], comp_reported_length[5]);
/* free memory. */
/* Don't free: comp[0] */