6 * This test tests a blob of this form...
26 static char const array_a
[] = "array_a";
27 static char const array_b
[] = "array_b";
29 static const struct blobmsg_policy pol_a
[] = {
32 .type
= BLOBMSG_TYPE_ARRAY
36 static const struct blobmsg_policy pol_b
[] = {
39 .type
= BLOBMSG_TYPE_ARRAY
44 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
48 check_table_a_entries(struct blob_attr
*attr
)
50 struct blob_attr
*cur
;
54 blobmsg_for_each_attr(cur
, attr
, rem
) {
57 fprintf(stderr
, "Process %s: entry %d\n", array_a
, entry_number
);
59 struct blob_attr
*tb
[ARRAY_SIZE(pol_b
)];
61 if (blobmsg_parse(pol_b
, ARRAY_SIZE(pol_b
), tb
,
62 blobmsg_data(cur
), blobmsg_data_len(cur
)) != 0) {
63 fprintf(stderr
, "Policy %s parse failed\n", array_b
);
67 if (tb
[ARRAY_B
] == NULL
) {
68 fprintf(stderr
, "%s not found\n", array_b
);
73 * This is the test that fails when blobmsg_check_array() passes the
74 * length obtained by blob_len(attr).
75 * It succeeds when blobmsg_check_array() uses blob_len(attr), which is
76 * equivalent to the origianl code, pre the length check changes.
78 if (blobmsg_check_array(tb
[ARRAY_B
], BLOBMSG_TYPE_STRING
) < 0) {
79 fprintf(stderr
, "Failed blobmsg_check_array() (STRING) on %s\n",
85 * Continue outputting the strings even though the test above might
87 * This will show that the array does actually contain the expected
91 struct blob_attr
*cur2
;
94 blobmsg_for_each_attr(cur2
, tb
[ARRAY_B
], rem2
) {
95 fprintf(stderr
, "%s contains string: %s\n",
96 array_b
, blobmsg_get_string(cur2
));
110 check_message(struct blob_buf
*buf
)
112 struct blob_attr
*tb
[ARRAY_SIZE(pol_a
)];
114 if (blobmsg_parse(pol_a
, ARRAY_SIZE(pol_a
), tb
,
115 blob_data(buf
->head
), blobmsg_data_len(buf
->head
)) != 0) {
116 fprintf(stderr
, "Policy %s parse failed\n", array_a
);
120 if (tb
[ARRAY_A
] == NULL
) {
121 fprintf(stderr
, "%s not found\n", array_a
);
125 int const result
= blobmsg_check_array(tb
[ARRAY_A
], BLOBMSG_TYPE_TABLE
);
128 fprintf(stderr
, "Failed blobmsg_check_array() (TABLE) on %s (%d)\n",
133 return check_table_a_entries(tb
[ARRAY_A
]);
137 fill_message(struct blob_buf
* const buf
)
139 void * const tbl_a
= blobmsg_open_array(buf
, "array_a");
140 void * const obj
= blobmsg_open_table(buf
, NULL
);
142 void * const tbl_b
= blobmsg_open_array(buf
, "array_b");
144 blobmsg_add_string(buf
, NULL
, "1");
146 blobmsg_close_array(buf
, tbl_b
);
148 blobmsg_close_table(buf
, obj
);
150 blobmsg_close_array(buf
, tbl_a
);
153 int main(int argc
, char **argv
)
156 static struct blob_buf buf
;
158 blobmsg_buf_init(&buf
);
161 result
= check_message(&buf
);
163 fprintf(stderr
, "blobmsg_check_array() test passed\n");
168 return result
? EXIT_FAILURE
: EXIT_SUCCESS
;