Skip to content

When enum is not accessible, it shouldn't be created by fuzzer (#1660) #1752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ class EnumValueProvider(
description: FuzzedDescription,
type: FuzzedType
) = sequence<Seed<FuzzedType, FuzzedValue>> {
type.classId.jClass.enumConstants.filterIsInstance<Enum<*>>().forEach { enum ->
val id = idGenerator.getOrCreateIdForValue(enum)
yield(Seed.Simple(UtEnumConstantModel(id, type.classId, enum).fuzzed {
summary = "%var% = $enum"
}))
val jClass = type.classId.jClass
if (isAccessible(jClass, description.description.packageName)) {
jClass.enumConstants.filterIsInstance<Enum<*>>().forEach { enum ->
val id = idGenerator.getOrCreateIdForValue(enum)
yield(Seed.Simple(UtEnumConstantModel(id, type.classId, enum).fuzzed {
summary = "%var% = $enum"
}))
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,18 @@ public Node() {
}
}
}

public int ordinal(InnEn val) {
switch (val) {
case ONE:
return 0;
case TWO:
return 1;
}
return -1;
}

private enum InnEn {
ONE, TWO
}
}
17 changes: 17 additions & 0 deletions utbot-fuzzers/src/test/kotlin/org/utbot/fuzzing/JavaFuzzingTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,23 @@ class JavaFuzzingTest {
assertEquals(0, exec) { "Fuzzer should not create any values of private classes" }
}

@Test
fun `fuzzing should not generate values of private enums`() {
var exec = 0
runBlockingWithContext {
runJavaFuzzing(
TestIdentityPreservingIdGenerator,
methodUnderTest = AccessibleObjects::class.java.declaredMethods.first { it.name == "ordinal" }.executableId,
constants = emptyList(),
names = emptyList(),
) { _, _, _ ->
exec += 1
BaseFeedback(Trie.emptyNode(), Control.STOP)
}
}
assertEquals(0, exec) { "Fuzzer should not create any values of private classes" }
}

@Test
fun `fuzzing generate single test in case of collection with fail-to-generate generic type`() {
val size = 100
Expand Down