static void S_set_prereqs(CFCParcel *self, CFCJson *node, const char *path) { size_t num_prereqs = CFCJson_get_num_children(node) / 2; CFCJson **children = CFCJson_get_children(node); CFCPrereq **prereqs = (CFCPrereq**)MALLOCATE((num_prereqs + 1) * sizeof(CFCPrereq*)); for (size_t i = 0; i < num_prereqs; ++i) { const char *name = CFCJson_get_string(children[2*i]); CFCJson *value = children[2*i+1]; int value_type = CFCJson_get_type(value); CFCVersion *version = NULL; if (value_type == CFCJSON_STRING) { version = CFCVersion_new(CFCJson_get_string(value)); } else if (value_type != CFCJSON_NULL) { CFCUtil_die("Invalid prereq value (filepath '%s')", path); } prereqs[i] = CFCPrereq_new(name, version); CFCBase_decref((CFCBase*)version); } prereqs[num_prereqs] = NULL; // Assume that prereqs are empty. FREEMEM(self->prereqs); self->prereqs = prereqs; self->num_prereqs = num_prereqs; }
static void S_run_prereq_tests(CFCTest *test) { { CFCVersion *v77_66_55 = CFCVersion_new("v77.66.55"); CFCPrereq *prereq = CFCPrereq_new("Flour", v77_66_55); const char *name = CFCPrereq_get_name(prereq); STR_EQ(test, name, "Flour", "prereq get_name"); CFCVersion *version = CFCPrereq_get_version(prereq); INT_EQ(test, CFCVersion_compare_to(version, v77_66_55), 0, "prereq get_version"); CFCBase_decref((CFCBase*)prereq); CFCBase_decref((CFCBase*)v77_66_55); } { CFCVersion *v0 = CFCVersion_new("v0"); CFCPrereq *prereq = CFCPrereq_new("Sugar", NULL); CFCVersion *version = CFCPrereq_get_version(prereq); INT_EQ(test, CFCVersion_compare_to(version, v0), 0, "prereq with default version"); CFCBase_decref((CFCBase*)prereq); CFCBase_decref((CFCBase*)v0); } }