示例#1
0
文件: test-fact.c 项目: jusa/ohm
static void test_fact_store_pattern_delete (void) {
#define FACT_NAME "com.nokia.ahoy"

	OhmFactStore     *fs;
	OhmFactStoreView *v1, *v2;
	OhmPattern       *p1, *p2;
	OhmFact          *f;

	fs = ohm_fact_store_new();
	v1 = ohm_fact_store_new_view(fs, NULL);
	v2 = ohm_fact_store_new_view(fs, NULL);
	
	p1 = ohm_pattern_new(FACT_NAME);
	p2 = ohm_pattern_new(FACT_NAME);
	
	ohm_fact_store_view_add(v1, OHM_STRUCTURE(p1));
	ohm_fact_store_view_add(v2, OHM_STRUCTURE(p2));

	g_object_unref(p1);
	g_object_unref(p2);

	f = ohm_fact_new(FACT_NAME);
	ohm_fact_store_insert(fs, f);

	ohm_fact_store_view_remove(v1, OHM_STRUCTURE(p1));
	g_object_unref(v1);
	
	f = ohm_fact_new(FACT_NAME);
	ohm_fact_store_insert(fs, f);
}
示例#2
0
文件: test-fact.c 项目: jusa/ohm
static void test_fact_store_view_two (void) {
	OhmFactStore* fs;
	OhmFactStoreView* v;
	OhmFactStoreView* v2;
	OhmPattern* _tmp0;
	OhmPattern* _tmp1;
	OhmFact* _tmp2;
	OhmFact* _tmp3;
	OhmFact* _tmp4;
	OhmFact* _tmp5;
	OhmFact* f;
	fs = ohm_fact_store_new ();
	v = ohm_fact_store_new_view (fs, NULL);
	v2 = ohm_fact_store_new_view (fs, NULL);
	_tmp0 = NULL;
	ohm_fact_store_view_add (v, OHM_STRUCTURE ((_tmp0 = ohm_pattern_new ("org.freedesktop.hello"))));
	(_tmp0 == NULL ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL)));
	_tmp1 = NULL;
	ohm_fact_store_view_add (v2, OHM_STRUCTURE ((_tmp1 = ohm_pattern_new ("org.freedesktop.hello"))));
	(_tmp1 == NULL ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL)));
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 0);
	_tmp2 = NULL;
	ohm_fact_store_insert (fs, (_tmp2 = ohm_fact_new ("org.freedesktop.match2")));
	(_tmp2 == NULL ? NULL : (_tmp2 = (g_object_unref (_tmp2), NULL)));
	_tmp3 = NULL;
	ohm_fact_store_insert (fs, (_tmp3 = ohm_fact_new ("org.freedesktop.hello")));
	(_tmp3 == NULL ? NULL : (_tmp3 = (g_object_unref (_tmp3), NULL)));
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 1);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set)) == 1);
	_tmp4 = NULL;
	ohm_fact_store_insert (fs, (_tmp4 = ohm_fact_new ("org.freedesktop.hello")));
	(_tmp4 == NULL ? NULL : (_tmp4 = (g_object_unref (_tmp4), NULL)));
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 2);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set)) == 2);
	ohm_fact_store_change_set_reset (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 0);
	_tmp5 = NULL;
	ohm_fact_store_insert (fs, (_tmp5 = ohm_fact_new ("org.freedesktop.hello")));
	(_tmp5 == NULL ? NULL : (_tmp5 = (g_object_unref (_tmp5), NULL)));
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) != 0);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set)) == 3);
	f = ohm_fact_new ("org.freedesktop.self");
	ohm_fact_store_change_set_reset (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set);
	ohm_fact_store_view_add (v, OHM_STRUCTURE (f));
	ohm_fact_store_insert (fs, f);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 2);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v2)->change_set)) == 0);
	(fs == NULL ? NULL : (fs = (g_object_unref (fs), NULL)));
	(v == NULL ? NULL : (v = (g_object_unref (v), NULL)));
	(v2 == NULL ? NULL : (v2 = (g_object_unref (v2), NULL)));
	(f == NULL ? NULL : (f = (g_object_unref (f), NULL)));
}
/********************
 * dres_store_track
 ********************/
int
dres_store_track(dres_t *dres)
{
    dres_store_t    *store = &dres->store;
    dres_variable_t *var;
    OhmPattern      *pattern;
    char            *name;
    int              id, i;
    
    store->view = ohm_fact_store_new_transparent_view(store->fs, NULL);
    if (store->view == NULL)
        return ENOMEM;
    
    for (i = 0; i < dres->nfactvar; i++) {
        var  = dres->factvars + i;
        id   = var->id;
        name = var->name;

        if (!DRES_TST_FLAG(var, VAR_PREREQ))
            continue;
        
        if ((pattern = ohm_pattern_new(name)) == NULL)
            return ENOMEM;

        ohm_fact_store_view_add(store->view, OHM_STRUCTURE(pattern));
        g_object_unref(pattern);
        g_hash_table_insert(store->ht, (gpointer)name, (gpointer)id);
    }

    return 0;
}
示例#4
0
文件: test-fact.c 项目: jusa/ohm
static void test_fact_store_transaction_push_and_commit (void) {
	OhmFactStore* fs;
	OhmFactStoreView* v;
	OhmFactStoreView* v2;
	OhmFactStoreView* tpv;
	OhmPattern* _tmp0;
	OhmPattern* _tmp1;
	OhmFact* fact;
	GValue* val;
	fs = ohm_fact_store_new ();
	v = ohm_fact_store_new_view (fs, NULL);
	v2 = ohm_fact_store_new_view (fs, NULL);
	tpv = ohm_fact_store_new_transparent_view (fs, NULL);
	_tmp0 = NULL;
	ohm_fact_store_view_add (v, OHM_STRUCTURE ((_tmp0 = ohm_pattern_new ("org.test.match"))));
	(_tmp0 == NULL ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL)));
	_tmp1 = NULL;
	ohm_fact_store_view_add (v2, OHM_STRUCTURE ((_tmp1 = ohm_pattern_new ("org.freedesktop.hello"))));
	(_tmp1 == NULL ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL)));
	_tmp1 = NULL;
	ohm_fact_store_view_add (tpv, OHM_STRUCTURE ((_tmp1 = ohm_pattern_new ("org.test.match"))));
	(_tmp1 == NULL ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL)));
	_tmp1 = NULL;
	/* insertion*/
	ohm_fact_store_transaction_push (fs);
	{
		fact = ohm_fact_new ("org.test.match");
		ohm_fact_set (fact, "field", ohm_value_from_int (42));
		ohm_fact_store_insert (fs, fact);
		g_assert (g_slist_length (ohm_fact_store_get_facts_by_name (fs, "org.test.match")) == 1);
		g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 0);
		g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 1);
	}
	ohm_fact_store_transaction_pop (fs, FALSE);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 1);
	/* and from the fact store*/
	g_assert (g_slist_length (ohm_fact_store_get_facts_by_name (fs, "org.test.match")) == 1);
	ohm_fact_set (fact, "field", ohm_value_from_int (43));
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 2);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 2);
	ohm_fact_store_transaction_push (fs);
	{
		ohm_fact_store_remove (fs, fact);
		g_assert (g_slist_length (ohm_fact_store_get_facts_by_name (fs, "org.test.match")) == 0);
		g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 2);
		g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 3);
	}
	ohm_fact_store_transaction_pop (fs, FALSE);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 3);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 3);
	g_assert (g_slist_length (ohm_fact_store_get_facts_by_name (fs, "org.test.match")) == 0);
	/* update*/
	fact = ohm_fact_new ("org.test.match");
	ohm_fact_set (fact, "field", ohm_value_from_int (41));
	ohm_fact_store_insert (fs, fact);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 4);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 4);
	ohm_fact_store_transaction_push (fs);
	{
		GValue* val;
		val = ((GValue*) ohm_fact_get (fact, "field"));
		g_assert (g_value_get_int (val) == 41);
		ohm_fact_set (fact, "field", ohm_value_from_int (42));
		val = ((GValue*) ohm_fact_get (fact, "field"));
		g_assert (g_value_get_int (val) == 42);
		g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 4);
		g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 5);
	}
	ohm_fact_store_transaction_pop (fs, FALSE);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (v)->change_set)) == 5);
	g_assert (g_slist_length (ohm_fact_store_change_set_get_matches (OHM_FACT_STORE_SIMPLE_VIEW (tpv)->change_set)) == 5);
	val = ((GValue*) ohm_fact_get (fact, "field"));
	g_assert (g_value_get_int (val) == 42);
	(fs == NULL ? NULL : (fs = (g_object_unref (fs), NULL)));
	(v == NULL ? NULL : (v = (g_object_unref (v), NULL)));
	(v2 == NULL ? NULL : (v2 = (g_object_unref (v2), NULL)));
	(fact == NULL ? NULL : (fact = (g_object_unref (fact), NULL)));
}