2016-02-09 06:43:19 +01:00
|
|
|
#include <platform.h>
|
|
|
|
#include "key.h"
|
|
|
|
|
|
|
|
#include <util/attrib.h>
|
|
|
|
#include <CuTest.h>
|
|
|
|
|
|
|
|
static void test_get_set_keys(CuTest *tc) {
|
|
|
|
attrib *a = 0;
|
|
|
|
key_set(&a, 42);
|
2016-02-09 06:45:28 +01:00
|
|
|
key_set(&a, 43);
|
|
|
|
key_set(&a, 44);
|
2016-02-09 06:43:19 +01:00
|
|
|
CuAssertTrue(tc, key_get(a, 42));
|
2016-02-09 06:45:28 +01:00
|
|
|
CuAssertTrue(tc, key_get(a, 43));
|
|
|
|
CuAssertTrue(tc, key_get(a, 44));
|
2016-02-09 06:43:19 +01:00
|
|
|
key_unset(&a, 42);
|
|
|
|
CuAssertTrue(tc, !key_get(a, 42));
|
2016-02-09 06:45:28 +01:00
|
|
|
CuAssertTrue(tc, key_get(a, 43));
|
|
|
|
CuAssertTrue(tc, key_get(a, 44));
|
|
|
|
a_removeall(&a, NULL);
|
2016-02-09 06:43:19 +01:00
|
|
|
}
|
|
|
|
|
2016-02-13 21:38:42 +01:00
|
|
|
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));
|
2016-03-11 09:47:13 +01:00
|
|
|
a_removeall(&alist, NULL);
|
2016-02-13 21:38:42 +01:00
|
|
|
}
|
|
|
|
|
2016-02-09 06:43:19 +01:00
|
|
|
CuSuite *get_key_suite(void)
|
|
|
|
{
|
|
|
|
CuSuite *suite = CuSuiteNew();
|
|
|
|
SUITE_ADD_TEST(suite, test_get_set_keys);
|
2016-02-13 21:38:42 +01:00
|
|
|
SUITE_ADD_TEST(suite, test_upgrade);
|
2016-02-09 06:43:19 +01:00
|
|
|
return suite;
|
|
|
|
}
|