|
| 1 | +#include <assert.h> |
| 2 | + |
| 3 | +// Add some string constants to confuse the value sets. |
| 4 | +const char *x1 = "This is a short string constant"; |
| 5 | +const char *x2 = "This is a loooooooooooooonger string constant"; |
| 6 | +const char *x3 = "And yet another string constant"; |
| 7 | + |
| 8 | +int main() |
| 9 | +{ |
| 10 | + __CPROVER_field_decl_local("field1", (_Bool)0); |
| 11 | + __CPROVER_field_decl_global("field1", (_Bool)0); |
| 12 | + |
| 13 | + // Add some string constants to confuse the value sets. |
| 14 | + const char *y1 = "Yes, this is a short string constant"; |
| 15 | + const char *y2 = "Yes, this is a loooooooooooooonger string constant"; |
| 16 | + const char *y3 = "Yes, and yet another string constant"; |
| 17 | + |
| 18 | + char *a; |
| 19 | + assert(__CPROVER_get_field(a, "field1") == 0); |
| 20 | + assert(__CPROVER_get_field(&a, "field1") == 0); |
| 21 | + // Cannot set because a doesn't point anywhere. |
| 22 | + __CPROVER_set_field(a, "field1", 1); |
| 23 | + // Hence, the value is still 0. |
| 24 | + assert(__CPROVER_get_field(a, "field1") == 0); |
| 25 | + assert(__CPROVER_get_field(&a, "field1") == 0); |
| 26 | + |
| 27 | + __CPROVER_set_field(a, "field1", 0); |
| 28 | + __CPROVER_set_field(&a, "field1", 1); |
| 29 | + assert(__CPROVER_get_field(a, "field1") == 0); |
| 30 | + assert(__CPROVER_get_field(&a, "field1") == 1); |
| 31 | + |
| 32 | + char *b = (char *)0; |
| 33 | + assert(__CPROVER_get_field(b, "field1") == 0); |
| 34 | + assert(__CPROVER_get_field(&b, "field1") == 0); |
| 35 | + // Cannot set because b points to NULL. |
| 36 | + __CPROVER_set_field(b, "field1", 1); |
| 37 | + // Hence, the value is still 0. |
| 38 | + assert(__CPROVER_get_field(b, "field1") == 0); |
| 39 | + assert(__CPROVER_get_field(&b, "field1") == 0); |
| 40 | + |
| 41 | + __CPROVER_set_field(b, "field1", 0); |
| 42 | + __CPROVER_set_field(&b, "field1", 1); |
| 43 | + assert(__CPROVER_get_field(b, "field1") == 0); |
| 44 | + assert(__CPROVER_get_field(&b, "field1") == 1); |
| 45 | + |
| 46 | + static char *c; |
| 47 | + assert(__CPROVER_get_field(c, "field1") == 0); |
| 48 | + assert(__CPROVER_get_field(&c, "field1") == 0); |
| 49 | + // Cannot set because c doesn't point anywhere. |
| 50 | + __CPROVER_set_field(c, "field1", 1); |
| 51 | + // Hence, the value is still 0. |
| 52 | + assert(__CPROVER_get_field(c, "field1") == 0); |
| 53 | + assert(__CPROVER_get_field(&c, "field1") == 0); |
| 54 | + |
| 55 | + __CPROVER_set_field(c, "field1", 0); |
| 56 | + __CPROVER_set_field(&c, "field1", 1); |
| 57 | + assert(__CPROVER_get_field(c, "field1") == 0); |
| 58 | + assert(__CPROVER_get_field(&c, "field1") == 1); |
| 59 | +} |
0 commit comments