Skip to content

CFSet: add a test suite for creation, lookup and mutation#71

Open
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:test/cfset-coverage
Open

CFSet: add a test suite for creation, lookup and mutation#71
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:test/cfset-coverage

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

CFSet.c had only partial test coverage. This adds a self-contained CFSet test suite (Tests/CFSet) built on the existing CFTesting.h framework.

Immutable (create.m):

  • CFSetCreate, CFSetGetCount.
  • Lookup — CFSetContainsValue, CFSetGetCountOfValue, CFSetGetValue, CFSetGetValueIfPresent, CFSetGetValues.
  • CFSetApplyFunction (verifies every value is visited once).
  • CFSetCreateCopy, CFSetGetTypeID / CFGetTypeID, and CFEqual / CFHash.

Mutable (mutable.m):

  • CFSetCreateMutable, CFSetAddValue (including that a value already present is not duplicated), CFSetSetValue, CFSetReplaceValue (present and absent), CFSetRemoveValue, CFSetRemoveAllValues, CFSetCreateMutableCopy.

This raises CFSet.c line coverage from 40.0% to 89.5% (measured with llvm-cov). All new tests pass and no existing tests are affected. The remaining uncovered lines are the toll-free-bridge (CF_IS_OBJC) paths and the internal formatting-description helper.

@HendrikHuebner HendrikHuebner left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the implementation of the mutable set generally the same as the immutable set for read only functions?

Comment thread Tests/CFSet/create.m
CFRelease (set);

return 0;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add a brief test for empty sets.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment thread Tests/CFSet/create.m

values[0] = CFSTR("a");
values[1] = CFSTR("b");
values[2] = CFSTR("c");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also have a test for sets created from an array of values with duplicates / NULLs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding that test surfaced a bug, so I've left it out of this suite rather than assert the broken behaviour: CFSetCreate doesn't de-duplicate. From {a, b, a} it returns count 3, and CFSetGetValues then hands back a garbage third pointer (segfault). Root cause is GSHashTableCreate incrementing _count per array element with no existing-key check, so CFDictionaryCreate/CFBagCreate are affected too. I'll fix that in a separate PR and add the de-dup test (and the NULL-callbacks case) there.

Comment thread Tests/CFSet/mutable.m
copy = CFSetCreateMutableCopy (NULL, 0, set);
PASS_CF(copy != NULL, "CFSetCreateMutableCopy returns a set.");
PASS_CFEQ(copy, set, "A mutable copy is equal to the original.");
CFRelease (copy);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also test whether removing an absent value is a no op.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

CFSet.c had only partial coverage.  Add tests exercising the public
API: CFSetCreate, the count and lookup accessors (CFSetGetCount,
CFSetContainsValue, CFSetGetCountOfValue, CFSetGetValue,
CFSetGetValueIfPresent, CFSetGetValues), CFSetApplyFunction,
CFSetCreateCopy, the type ID, and CFEqual / CFHash.  The mutable path
covers CFSetCreateMutable, CFSetAddValue (including that a present
value is not duplicated), CFSetSetValue, CFSetReplaceValue,
CFSetRemoveValue, CFSetRemoveAllValues and CFSetCreateMutableCopy.
@DTW-Thalion DTW-Thalion force-pushed the test/cfset-coverage branch from 2bb9db4 to 10cdb9f Compare July 3, 2026 14:41
@DTW-Thalion

Copy link
Copy Markdown
Contributor Author

@HendrikHuebner Yes — immutable and mutable CFSets are both backed by the same GSHashTable, and the read-only functions (CFSetGetCount, CFSetContainsValue, CFSetGetValue, CFSetGetValues, CFSetGetCountOfValue, CFSetGetValueIfPresent) just cast to GSHashTableRef and call the generic GSHashTable* accessors with no mutable/immutable branching, so reads behave identically for both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants