void Schema_Spec_Field_IMP(Schema *self, String *field, FieldType *type) { FieldType *existing = Schema_Fetch_Type(self, field); // If the field already has an association, verify pairing and return. if (existing) { if (FType_Equals(type, (Obj*)existing)) { return; } else { THROW(ERR, "'%o' assigned conflicting FieldType", field); } } if (FType_is_a(type, FULLTEXTTYPE)) { S_add_text_field(self, field, type); } else if (FType_is_a(type, STRINGTYPE)) { S_add_string_field(self, field, type); } else if (FType_is_a(type, BLOBTYPE)) { S_add_blob_field(self, field, type); } else if (FType_is_a(type, NUMERICTYPE)) { S_add_numeric_field(self, field, type); } else { THROW(ERR, "Unrecognized field type: '%o'", type); } }
static void test_Dump_Load_and_Equals(TestBatchRunner *runner) { FieldType *type = (FieldType*)DummyFieldType_new(); FieldType *other = (FieldType*)DummyFieldType_new(); FieldType *class_differs = S_alt_field_type(); FieldType *boost_differs = (FieldType*)DummyFieldType_new(); FieldType *indexed = (FieldType*)DummyFieldType_new(); FieldType *stored = (FieldType*)DummyFieldType_new(); FType_Set_Boost(other, 1.0); FType_Set_Indexed(indexed, false); FType_Set_Stored(stored, false); FType_Set_Boost(boost_differs, 1.5); FType_Set_Indexed(indexed, true); FType_Set_Stored(stored, true); TEST_TRUE(runner, FType_Equals(type, (Obj*)other), "Equals() true with identical stats"); TEST_FALSE(runner, FType_Equals(type, (Obj*)class_differs), "Equals() false with subclass"); TEST_FALSE(runner, FType_Equals(type, (Obj*)class_differs), "Equals() false with super class"); TEST_FALSE(runner, FType_Equals(type, (Obj*)boost_differs), "Equals() false with different boost"); TEST_FALSE(runner, FType_Equals(type, (Obj*)indexed), "Equals() false with indexed => true"); TEST_FALSE(runner, FType_Equals(type, (Obj*)stored), "Equals() false with stored => true"); DECREF(stored); DECREF(indexed); DECREF(boost_differs); DECREF(class_differs); DECREF(other); DECREF(type); }