/******************** * dres_store_check ********************/ int dres_store_check(dres_t *dres) { dres_store_t *store = &dres->store; dres_variable_t *var; const char *name; int id, idx, updated; GSList *changes, *l; OhmFact *fact; OhmPatternMatch *match; if (store->view == NULL) return ENOENT; updated = FALSE; if ((changes = ohm_view_get_changes(store->view)) != NULL) { for (l = changes; l != NULL; l = g_slist_next(l)) { if (!OHM_PATTERN_IS_MATCH(l->data)) { DRES_ERROR("%s: invalid data from view", __FUNCTION__); continue; } match = OHM_PATTERN_MATCH(l->data); fact = ohm_pattern_match_get_fact(match); name = ohm_structure_get_name(OHM_STRUCTURE(fact)); id = (int)g_hash_table_lookup(store->ht, name); #if 0 DRES_INFO("variable '%s' has changed", name); #endif if (!id) { DRES_ERROR("%s: unkown variable %s", __FUNCTION__, name); continue; } if (DRES_ID_TYPE(id) != DRES_TYPE_FACTVAR) { DRES_ERROR("%s: got invalid type for variable %s (0x%x)", __FUNCTION__, name, id); continue; } if ((idx = DRES_INDEX(id)) >= dres->nfactvar) { DRES_ERROR("%s: invalid index %d for variable %s", __FUNCTION__, idx, name); continue; } var = dres->factvars + idx; dres_update_var_stamp(dres, var); updated = TRUE; } ohm_view_reset_changes(store->view); } return updated; }
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; }