示例#1
0
void
create_instance(struct tesla_class *tclass, struct tesla_instance **instance,
                int32_t key0, int32_t key1, int32_t key2)
{
	struct tesla_key key;
	key.tk_mask = 0x07;
	key.tk_keys[0] = key0;
	key.tk_keys[1] = key1;
	key.tk_keys[2] = key2;

	check(tesla_instance_new(tclass, &key, 0, instance));

	assert(instance != NULL);
}
示例#2
0
static void
check_store(struct tesla_store *store)
{
	assert(store != NULL);

	struct tesla_class *classes[CLASSES];
	for (unsigned int i = 0; i < CLASSES; i++) {
		check(tesla_class_get(store, i, classes + i, name(i), desc(i)));

		struct tesla_instance *instance;
		struct tesla_key key;
		key.tk_mask = 1;
		key.tk_keys[0] = 42 + i;

		register_t state = 2 * i + 42;

		check(tesla_instance_new(classes[i], &key, state, &instance));
		assert(instance != NULL);
		assert(tesla_instance_active(instance));
		assert(instance->ti_state == 2 * i + 42);
		assert(instance->ti_key.tk_mask == 1);
		assert(instance->ti_key.tk_keys[0] == 42 + i);

		tesla_class_put(classes[i]);
	}

	void *JUNK = (void*) 0xF00BA5;
	struct tesla_class *junk = JUNK;
	int err = tesla_class_get(store, CLASSES, &junk, "foo", "bar");
	if (err != TESLA_ERROR_EINVAL)
		errx(1, "tesla_class_get() did not report EINVAL: %s",
		     tesla_strerror(err));

	if (junk != JUNK)
		errx(1, "tesla_class_get() clobbered output variable when"
		        " returning an error");
}