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); }
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))); }
static void test_fact_pattern_match (void) { OhmPattern* p; OhmFact* match; OhmFact* match2; OhmFact* nomatch; OhmPatternMatch* _tmp0; OhmPatternMatch* _tmp1; OhmPatternMatch* _tmp2; p = ohm_pattern_new ("org.test.match"); match = ohm_fact_new ("org.test.match"); match2 = ohm_fact_new ("org.test.match"); nomatch = ohm_fact_new ("org.test.nomatch"); _tmp0 = NULL; g_assert ((_tmp0 = ohm_pattern_match (p, match, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp0 == NULL ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL))); _tmp1 = NULL; g_assert ((_tmp1 = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp1 == NULL ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL))); _tmp2 = NULL; g_assert ((_tmp2 = ohm_pattern_match (p, nomatch, OHM_FACT_STORE_EVENT_LOOKUP)) == NULL); (_tmp2 == NULL ? NULL : (_tmp2 = (g_object_unref (_tmp2), NULL))); (p == NULL ? NULL : (p = (g_object_unref (p), NULL))); (match == NULL ? NULL : (match = (g_object_unref (match), NULL))); (match2 == NULL ? NULL : (match2 = (g_object_unref (match2), NULL))); (nomatch == NULL ? NULL : (nomatch = (g_object_unref (nomatch), 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; }
static void test_fact_pattern_new (void) { void* p; p = NULL; { OhmPattern* s; s = ohm_pattern_new ("org.freedesktop.ohm.test"); p = s; g_object_add_weak_pointer (G_OBJECT (s), &p); g_assert (ohm_pattern_get_view (s) == NULL); g_assert (ohm_pattern_get_fact (s) == NULL); (s == NULL ? NULL : (s = (g_object_unref (s), NULL))); } g_assert (p == NULL); }
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))); }
static void test_fact_pattern_match_fields (void) { OhmPattern* p; OhmFact* match; OhmFact* match2; OhmFact* nomatch; OhmPatternMatch* _tmp0; OhmPatternMatch* _tmp1; OhmPatternMatch* _tmp2; OhmPatternMatch* _tmp3; OhmPatternMatch* m; OhmPatternMatch* _tmp4; OhmPatternMatch* _tmp5; OhmPatternMatch* _tmp6; OhmPatternMatch* _tmp7; p = ohm_pattern_new ("org.test.match"); match = ohm_fact_new ("org.test.match"); match2 = ohm_fact_new ("org.test.match"); nomatch = ohm_fact_new ("org.test.nomatch"); ohm_fact_set (match, "field1", ohm_value_from_string ("test1")); ohm_fact_set (match, "field2", ohm_value_from_int (42)); ohm_fact_set (match2, "field2", ohm_value_from_int (42)); _tmp0 = NULL; g_assert ((_tmp0 = ohm_pattern_match (p, match, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp0 == NULL ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL))); _tmp1 = NULL; g_assert ((_tmp1 = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp1 == NULL ? NULL : (_tmp1 = (g_object_unref (_tmp1), NULL))); ohm_structure_set (OHM_STRUCTURE (p), "field2", ohm_value_from_int (42)); _tmp2 = NULL; g_assert ((_tmp2 = ohm_pattern_match (p, match, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp2 == NULL ? NULL : (_tmp2 = (g_object_unref (_tmp2), NULL))); _tmp3 = NULL; g_assert ((_tmp3 = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp3 == NULL ? NULL : (_tmp3 = (g_object_unref (_tmp3), NULL))); m = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP); g_assert (ohm_pattern_match_get_fact (m) == match2); g_assert (ohm_pattern_match_get_pattern (m) == p); g_assert (ohm_pattern_match_get_event (m) == OHM_FACT_STORE_EVENT_LOOKUP); ohm_structure_set (OHM_STRUCTURE (p), "field1", ohm_value_from_string ("test1")); _tmp4 = NULL; g_assert ((_tmp4 = ohm_pattern_match (p, match, OHM_FACT_STORE_EVENT_LOOKUP)) != NULL); (_tmp4 == NULL ? NULL : (_tmp4 = (g_object_unref (_tmp4), NULL))); _tmp5 = NULL; g_assert ((_tmp5 = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP)) == NULL); (_tmp5 == NULL ? NULL : (_tmp5 = (g_object_unref (_tmp5), NULL))); ohm_structure_set (OHM_STRUCTURE (p), "field1", ohm_value_from_string ("notest1")); _tmp6 = NULL; g_assert ((_tmp6 = ohm_pattern_match (p, match, OHM_FACT_STORE_EVENT_LOOKUP)) == NULL); (_tmp6 == NULL ? NULL : (_tmp6 = (g_object_unref (_tmp6), NULL))); _tmp7 = NULL; g_assert ((_tmp7 = ohm_pattern_match (p, match2, OHM_FACT_STORE_EVENT_LOOKUP)) == NULL); (_tmp7 == NULL ? NULL : (_tmp7 = (g_object_unref (_tmp7), NULL))); (p == NULL ? NULL : (p = (g_object_unref (p), NULL))); (match == NULL ? NULL : (match = (g_object_unref (match), NULL))); (match2 == NULL ? NULL : (match2 = (g_object_unref (match2), NULL))); (nomatch == NULL ? NULL : (nomatch = (g_object_unref (nomatch), NULL))); (m == NULL ? NULL : (m = (g_object_unref (m), NULL))); return; (void)test_fact_pattern_match_instance; }
static void test_fact_pattern_set_get (void) { OhmPattern* f; f = ohm_pattern_new ("org.freedesktop.ohm.test"); _structure_set_get (OHM_STRUCTURE (f)); (f == NULL ? NULL : (f = (g_object_unref (f), NULL))); }