forked from github/server
fix key upgrade.
should have had a test to begin with. github issue #481
This commit is contained in:
parent
9c10cc6b16
commit
5317c029d5
|
@ -77,6 +77,7 @@ void a_upgradekeys(attrib **alist, attrib *abegin) {
|
|||
keys = realloc(keys, sizeof(int) * (n + i + 1));
|
||||
memcpy(keys + n + 1, val, sizeof(int)*i);
|
||||
n += i;
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
if (i > 0) {
|
||||
|
@ -84,6 +85,7 @@ void a_upgradekeys(attrib **alist, attrib *abegin) {
|
|||
memcpy(keys + n + 1, val, sizeof(int)*i);
|
||||
}
|
||||
keys[0] = n + i;
|
||||
a->data.v = keys;
|
||||
}
|
||||
|
||||
attrib_type at_key = {
|
||||
|
|
|
@ -19,9 +19,32 @@ static void test_get_set_keys(CuTest *tc) {
|
|||
a_removeall(&a, NULL);
|
||||
}
|
||||
|
||||
static attrib *key_set_orig(attrib **alist, int key) {
|
||||
attrib * a = a_add(alist, a_new(&at_key));
|
||||
a->data.i = key;
|
||||
return a;
|
||||
}
|
||||
|
||||
static void test_upgrade(CuTest *tc) {
|
||||
attrib *alist = 0;
|
||||
key_set_orig(&alist, 40);
|
||||
key_set_orig(&alist, 41);
|
||||
key_set_orig(&alist, 42);
|
||||
key_set_orig(&alist, 43);
|
||||
key_set_orig(&alist, 44);
|
||||
CuAssertPtrNotNull(tc, alist->type->upgrade);
|
||||
alist->type->upgrade(&alist, alist);
|
||||
CuAssertTrue(tc, key_get(alist, 40));
|
||||
CuAssertTrue(tc, key_get(alist, 41));
|
||||
CuAssertTrue(tc, key_get(alist, 42));
|
||||
CuAssertTrue(tc, key_get(alist, 43));
|
||||
CuAssertTrue(tc, key_get(alist, 44));
|
||||
}
|
||||
|
||||
CuSuite *get_key_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_get_set_keys);
|
||||
SUITE_ADD_TEST(suite, test_upgrade);
|
||||
return suite;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue