From 4da08785e48f0a5e3c2607f7fe37b37870d273e8 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Wed, 9 Nov 2022 20:11:50 +0300 Subject: [PATCH 01/30] merge --- .../utbot/cli/GenerateTestsAbstractCommand.kt | 19 +- .../main/kotlin/org/utbot/common/FileUtil.kt | 5 +- .../kotlin/org/utbot/framework/UtSettings.kt | 7 +- .../org/utbot/framework/plugin/api/Api.kt | 5 +- .../framework/plugin/api/UtExecutionResult.kt | 12 + .../api/util/constructor/ValueConstructor.kt | 3 + utbot-framework/build.gradle | 4 + .../main/java/org/utbot/quickcheck/From.java | 65 +++ .../quickcheck/MinimalCounterexampleHook.java | 46 ++ .../main/java/org/utbot/quickcheck/Mode.java | 63 +++ .../NonTrackingGenerationStatus.java | 81 +++ .../main/java/org/utbot/quickcheck/Pair.java | 70 +++ .../java/org/utbot/quickcheck/Produced.java | 55 ++ .../java/org/utbot/quickcheck/Property.java | 97 ++++ .../main/java/org/utbot/quickcheck/When.java | 68 +++ .../conversion/StringConversion.java | 40 ++ .../org/utbot/quickcheck/generator/Also.java | 69 +++ .../generator/ComponentizedGenerator.java | 120 ++++ .../org/utbot/quickcheck/generator/Ctor.java | 152 +++++ .../generator/DecimalGenerator.java | 155 ++++++ .../utbot/quickcheck/generator/Distinct.java | 52 ++ .../utbot/quickcheck/generator/Fields.java | 123 +++++ .../org/utbot/quickcheck/generator/Gen.java | 248 +++++++++ .../generator/GenerationStatus.java | 123 +++++ .../utbot/quickcheck/generator/Generator.java | 396 +++++++++++++ .../generator/GeneratorConfiguration.java | 53 ++ .../GeneratorConfigurationException.java | 46 ++ .../quickcheck/generator/Generators.java | 188 +++++++ .../utbot/quickcheck/generator/InRange.java | 138 +++++ .../generator/IntegralGenerator.java | 133 +++++ .../utbot/quickcheck/generator/Lambdas.java | 167 ++++++ .../quickcheck/generator/NullAllowed.java | 21 + .../org/utbot/quickcheck/generator/Only.java | 79 +++ .../utbot/quickcheck/generator/Precision.java | 50 ++ .../utbot/quickcheck/generator/Shrink.java | 47 ++ .../org/utbot/quickcheck/generator/Size.java | 52 ++ .../quickcheck/generator/VoidGenerator.java | 57 ++ .../java/lang/AbstractStringGenerator.java | 123 +++++ .../generator/java/lang/BooleanGenerator.java | 69 +++ .../generator/java/lang/ByteGenerator.java | 107 ++++ .../java/lang/CharacterGenerator.java | 96 ++++ .../generator/java/lang/CodePointShrink.java | 83 +++ .../generator/java/lang/DoubleGenerator.java | 117 ++++ .../generator/java/lang/Encoded.java | 83 +++ .../generator/java/lang/FloatGenerator.java | 109 ++++ .../generator/java/lang/IntegerGenerator.java | 111 ++++ .../generator/java/lang/LongGenerator.java | 112 ++++ .../java/lang/PrimitiveBooleanGenerator.java | 69 +++ .../java/lang/PrimitiveByteGenerator.java | 107 ++++ .../java/lang/PrimitiveCharGenerator.java | 96 ++++ .../java/lang/PrimitiveDoubleGenerator.java | 117 ++++ .../java/lang/PrimitiveFloatGenerator.java | 110 ++++ .../java/lang/PrimitiveIntGenerator.java | 111 ++++ .../java/lang/PrimitiveLongGenerator.java | 112 ++++ .../java/lang/PrimitiveShortGenerator.java | 107 ++++ .../generator/java/lang/ShortGenerator.java | 107 ++++ .../generator/java/lang/StringGenerator.java | 43 ++ .../java/lang/strings/CodePoints.java | 190 +++++++ .../java/math/BigDecimalGenerator.java | 190 +++++++ .../java/math/BigIntegerGenerator.java | 127 +++++ .../java/nio/charset/CharsetGenerator.java | 85 +++ .../generator/java/time/ClockGenerator.java | 123 +++++ .../java/time/DurationGenerator.java | 84 +++ .../generator/java/time/InstantGenerator.java | 84 +++ .../java/time/LocalDateGenerator.java | 89 +++ .../java/time/LocalDateTimeGenerator.java | 98 ++++ .../java/time/LocalTimeGenerator.java | 90 +++ .../java/time/MonthDayGenerator.java | 96 ++++ .../java/time/OffsetDateTimeGenerator.java | 95 ++++ .../java/time/OffsetTimeGenerator.java | 101 ++++ .../generator/java/time/PeriodGenerator.java | 112 ++++ .../generator/java/time/YearGenerator.java | 88 +++ .../java/time/YearMonthGenerator.java | 96 ++++ .../generator/java/time/ZoneIdGenerator.java | 53 ++ .../java/time/ZoneOffsetGenerator.java | 93 ++++ .../java/time/ZonedDateTimeGenerator.java | 106 ++++ .../java/util/ArrayListGenerator.java | 41 ++ .../generator/java/util/BitSetGenerator.java | 93 ++++ .../java/util/CollectionGenerator.java | 231 ++++++++ .../generator/java/util/DateGenerator.java | 119 ++++ .../generator/java/util/HashMapGenerator.java | 40 ++ .../generator/java/util/HashSetGenerator.java | 40 ++ .../java/util/HashtableGenerator.java | 44 ++ .../java/util/LinkedHashMapGenerator.java | 40 ++ .../java/util/LinkedHashSetGenerator.java | 40 ++ .../java/util/LinkedListGenerator.java | 40 ++ .../generator/java/util/ListGenerator.java | 44 ++ .../generator/java/util/LocaleGenerator.java | 55 ++ .../generator/java/util/MapGenerator.java | 261 +++++++++ .../java/util/OptionalDoubleGenerator.java | 107 ++++ .../java/util/OptionalGenerator.java | 109 ++++ .../java/util/OptionalIntGenerator.java | 107 ++++ .../java/util/OptionalLongGenerator.java | 104 ++++ .../java/util/PropertiesGenerator.java | 129 +++++ .../generator/java/util/RFC4122.java | 235 ++++++++ .../generator/java/util/SetGenerator.java | 51 ++ .../generator/java/util/StackGenerator.java | 40 ++ .../java/util/TimeZoneGenerator.java | 56 ++ .../generator/java/util/VectorGenerator.java | 40 ++ .../util/concurrent/CallableGenerator.java | 63 +++ .../util/function/BiFunctionGenerator.java | 67 +++ .../util/function/BiPredicateGenerator.java | 73 +++ .../function/BinaryOperatorGenerator.java | 65 +++ .../function/DoubleFunctionGenerator.java | 65 +++ .../java/util/function/FunctionGenerator.java | 64 +++ .../util/function/IntFunctionGenerator.java | 66 +++ .../util/function/LongFunctionGenerator.java | 65 +++ .../util/function/PredicateGenerator.java | 70 +++ .../java/util/function/SupplierGenerator.java | 63 +++ .../function/ToDoubleBiFunctionGenerator.java | 73 +++ .../function/ToDoubleFunctionGenerator.java | 72 +++ .../function/ToIntBiFunctionGenerator.java | 74 +++ .../util/function/ToIntFunctionGenerator.java | 72 +++ .../function/ToLongBiFunctionGenerator.java | 74 +++ .../function/ToLongFunctionGenerator.java | 74 +++ .../util/function/UnaryOperatorGenerator.java | 65 +++ .../hook/NilMinimalCounterexampleHook.java | 39 ++ .../internal/CartesianIterator.java | 96 ++++ .../quickcheck/internal/Comparables.java | 75 +++ .../internal/DefaultMethodHandleMaker.java | 55 ++ .../internal/FakeAnnotatedTypeFactory.java | 113 ++++ .../internal/GeometricDistribution.java | 63 +++ .../org/utbot/quickcheck/internal/Items.java | 83 +++ .../org/utbot/quickcheck/internal/Lists.java | 111 ++++ .../quickcheck/internal/ParameterSampler.java | 49 ++ .../internal/ParameterTypeContext.java | 508 +++++++++++++++++ .../internal/PropertyParameterContext.java | 110 ++++ .../org/utbot/quickcheck/internal/Ranges.java | 127 +++++ .../utbot/quickcheck/internal/Reflection.java | 332 +++++++++++ .../internal/ReflectionException.java | 38 ++ .../quickcheck/internal/SeededValue.java | 59 ++ .../utbot/quickcheck/internal/Sequences.java | 152 +++++ .../quickcheck/internal/ShrinkControl.java | 68 +++ .../utbot/quickcheck/internal/Weighted.java | 41 ++ .../org/utbot/quickcheck/internal/Zilch.java | 34 ++ .../constraint/ConstraintEvaluator.java | 84 +++ .../ConstructorInvokingStringConversion.java | 48 ++ .../MethodInvokingStringConversion.java | 48 ++ .../conversion/StringConversions.java | 97 ++++ .../generator/AbstractGenerationStatus.java | 65 +++ .../internal/generator/ArrayGenerator.java | 229 ++++++++ .../generator/CompositeGenerator.java | 175 ++++++ .../internal/generator/EnumGenerator.java | 57 ++ .../generator/ExhaustiveDomainGenerator.java | 66 +++ .../generator/GeneratorRepository.java | 443 +++++++++++++++ .../generator/GuaranteeValuesGenerator.java | 58 ++ .../internal/generator/LambdaGenerator.java | 54 ++ .../generator/MarkerInterfaceGenerator.java | 118 ++++ .../internal/generator/NullableGenerator.java | 124 +++++ .../PropertyParameterGenerationContext.java | 182 ++++++ .../generator/SamplingDomainGenerator.java | 55 ++ .../ServiceLoaderGeneratorSource.java | 57 ++ .../generator/SimpleGenerationStatus.java | 46 ++ .../internal/generator/ZilchGenerator.java | 48 ++ .../sampling/ExhaustiveParameterSampler.java | 139 +++++ .../sampling/TupleParameterSampler.java | 96 ++++ .../quickcheck/random/SourceOfRandomness.java | 402 ++++++++++++++ .../quickcheck/runner/JUnitQuickcheck.java | 110 ++++ .../runner/JUnitQuickcheckTestClass.java | 107 ++++ .../NoValuesSatisfiedPropertyAssumptions.java | 17 + .../quickcheck/runner/PropertyFalsified.java | 101 ++++ .../quickcheck/runner/PropertyStatement.java | 197 +++++++ .../quickcheck/runner/PropertyVerifier.java | 122 ++++ .../utbot/quickcheck/runner/ShrinkNode.java | 223 ++++++++ .../org/utbot/quickcheck/runner/Shrinker.java | 111 ++++ .../org/utbot/engine/UtBotSymbolicEngine.kt | 26 +- .../engine/greyboxfuzzer/GreyBoxFuzzer.kt | 253 +++++++++ .../greyboxfuzzer/generator/DataGenerator.kt | 236 ++++++++ .../engine/greyboxfuzzer/generator/FField.kt | 74 +++ .../greyboxfuzzer/generator/FParameter.kt | 59 ++ .../generator/FakeAnnotatedTypeFactory.kt | 74 +++ .../generator/GeneratorConfigurator.kt | 97 ++++ .../generator/GreyBoxFuzzerGenerators.kt | 79 +++ .../generator/QuickCheckExtensions.kt | 273 +++++++++ .../generator/ThisInstanceGenerator.kt | 18 + .../generator/UTGeneratorRepository.kt | 28 + .../generator/map/HashMapGenerator.kt | 9 + .../generator/map/HashtableGenerator.kt | 9 + .../generator/map/LinkedHashMapGenerator.kt | 7 + .../generator/map/MapGenerator.kt | 60 ++ .../generator/set/HashSetGenerator.kt | 5 + .../generator/set/LinkedHashSetGenerator.kt | 3 + .../generator/set/SetGenerator.kt | 43 ++ .../userclasses/InstancesGenerator.kt | 521 ++++++++++++++++++ .../userclasses/UserClassGenerator.kt | 79 +++ .../generator/ClassesInstanceGenerator.kt | 50 ++ .../ConstructorBasedInstanceGenerator.kt | 77 +++ .../generator/ExecutableInvoker.kt | 42 ++ .../userclasses/generator/GenerationMethod.kt | 5 + .../generator/InstanceGenerator.kt | 7 + ...terfaceImplementationsInstanceGenerator.kt | 88 +++ .../userclasses/generator/ObjectGenerator.kt | 20 + .../generator/ReflectionClassGenerator.kt | 15 + .../StaticsBasedInstanceGenerator.kt | 28 + .../StaticsFieldBasedInstanceGenerator.kt | 78 +++ .../StaticsMethodBasedInstanceGenerator.kt | 56 ++ .../engine/greyboxfuzzer/mutator/Mutator.kt | 164 ++++++ .../greyboxfuzzer/mutator/ObjectMerger.kt | 14 + .../engine/greyboxfuzzer/mutator/Seed.kt | 10 + .../greyboxfuzzer/mutator/SeedCollector.kt | 55 ++ .../greyboxfuzzer/util/CoverageCollector.kt | 9 + .../greyboxfuzzer/util/CustomClassLoader.kt | 7 + .../greyboxfuzzer/util/GenericsReplacer.kt | 55 ++ .../util/GreyBoxFuzzingStatisticPrinter.kt | 54 ++ .../engine/greyboxfuzzer/util/KotlinUtils.kt | 43 ++ .../greyboxfuzzer/util/ReflectionUtils.kt | 381 +++++++++++++ .../engine/greyboxfuzzer/util/SootUtils.kt | 148 +++++ .../engine/greyboxfuzzer/util/UtBotUtils.kt | 77 +++ .../greyboxfuzzer/util/UtModelGenerator.kt | 16 + .../greyboxfuzzer/util/kcheck/Common.kt | 77 +++ .../greyboxfuzzer/util/kcheck/RandomEx.kt | 83 +++ .../org/utbot/external/api/UtBotJavaApi.kt | 9 +- .../framework/plugin/api/TestCaseGenerator.kt | 4 + .../utbot/framework/plugin/api/TestFlow.kt | 3 + .../org/utbot/framework/util/SootUtils.kt | 31 +- .../utbot/instrumentation/ConcreteExecutor.kt | 4 +- .../execution/BigNumberConstructor.kt | 32 ++ .../execution/BitSetConstructor.kt | 37 ++ .../execution/DateTimeConstructors.kt | 433 +++++++++++++++ .../execution/LocaleConstructor.kt | 37 ++ .../execution/UUIDConstructor.kt | 35 ++ .../execution/UtExecutionInstrumentation.kt | 9 + .../UtFuzzingExecutionInstrumentation.kt | 196 +++++++ .../UtAssembleModelConstructors.kt | 25 + .../constructors/UtModelConstructor.kt | 2 +- .../main/kotlin/org/utbot/contest/Contest.kt | 1 + .../kotlin/org/utbot/summary/TagGenerator.kt | 2 + 227 files changed, 20618 insertions(+), 15 deletions(-) create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/From.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/MinimalCounterexampleHook.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/Mode.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/Pair.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/Produced.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/Property.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/When.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/conversion/StringConversion.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Also.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Ctor.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Fields.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/NullAllowed.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Only.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Shrink.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CodePointShrink.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/hook/NilMinimalCounterexampleHook.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/CartesianIterator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Lists.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterSampler.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/PropertyParameterContext.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/SeededValue.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Sequences.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/ShrinkControl.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/constraint/ConstraintEvaluator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/ConstructorInvokingStringConversion.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/MethodInvokingStringConversion.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/StringConversions.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ExhaustiveDomainGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GuaranteeValuesGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/PropertyParameterGenerationContext.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SamplingDomainGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ServiceLoaderGeneratorSource.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/ExhaustiveParameterSampler.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/TupleParameterSampler.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheck.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheckTestClass.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/NoValuesSatisfiedPropertyAssumptions.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyFalsified.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyStatement.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyVerifier.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/ShrinkNode.java create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/Shrinker.java create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FakeAnnotatedTypeFactory.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/ThisInstanceGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashMapGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashtableGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/LinkedHashMapGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/MapGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/LinkedHashSetGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/SetGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/InstancesGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/ObjectMerger.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GenericsReplacer.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/Common.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/RandomEx.kt create mode 100644 utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BigNumberConstructor.kt create mode 100644 utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BitSetConstructor.kt create mode 100644 utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/DateTimeConstructors.kt create mode 100644 utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/LocaleConstructor.kt create mode 100644 utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UUIDConstructor.kt create mode 100644 utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt diff --git a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt index 3b789d25a8..1cd2cf42fb 100644 --- a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt +++ b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt @@ -40,6 +40,7 @@ import java.nio.file.Path import java.nio.file.Paths import java.time.LocalDateTime import java.time.temporal.ChronoUnit +import org.utbot.engine.greyboxfuzzer.util.CustomClassLoader private const val LONG_GENERATION_TIMEOUT = 1_200_000L @@ -144,8 +145,16 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : protected fun getWorkingDirectory(classFqn: String): Path? { val classRelativePath = classFqnToPath(classFqn) + ".class" val classAbsoluteURL = classLoader.getResource(classRelativePath) ?: return null - val classAbsolutePath = replaceSeparator(classAbsoluteURL.toPath().toString()) - .removeSuffix(classRelativePath) + val classAbsolutePath = + if (classAbsoluteURL.toURI().scheme == "jar") { + replaceSeparator(classAbsoluteURL.file.removePrefix("file:")) + .removeSuffix(classRelativePath) + .removeSuffix("/") + .removeSuffix("!") + } else { + replaceSeparator(classAbsoluteURL.toPath().toString()) + .removeSuffix(classRelativePath) + } return Paths.get(classAbsolutePath) } @@ -155,8 +164,9 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : sourceCodeFile: Path? = null, searchDirectory: Path, chosenClassesToMockAlways: Set - ): List = - testCaseGenerator.generate( + ): List { + CustomClassLoader.classLoader = classLoader + return testCaseGenerator.generate( targetMethods, mockStrategy, chosenClassesToMockAlways, @@ -164,6 +174,7 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : ).map { if (sourceCodeFile != null) it.summarize(searchDirectory, sourceCodeFile.toFile()) else it } + } protected fun withLogger(targetClassFqn: String, block: Runnable) { diff --git a/utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt b/utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt index 6cc649f37f..d0f6a3ab0a 100644 --- a/utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt +++ b/utbot-core/src/main/kotlin/org/utbot/common/FileUtil.kt @@ -90,7 +90,10 @@ object FileUtil { for (clazz in classes) { val path = clazz.toClassFilePath() - val resource = clazz.classLoader.getResource(path) ?: error("No such file: $path") + val resource = + clazz.classLoader.getResource(path) + ?: ClassLoader.getSystemClassLoader().getResource(path) + ?: error("No such file: $path") if (resource.toURI().scheme == "jar") { val jarLocation = resource.toURI().extractJarName() diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt index 02bf1bc3f3..d5d73e208f 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt @@ -240,7 +240,12 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS /** * Set to true to start fuzzing if symbolic execution haven't return anything */ - var useFuzzing: Boolean by getBooleanProperty(true) + var useFuzzing: Boolean by getBooleanProperty(false) + + /** + * Set to true to start grey-box fuzzing + */ + var useGreyBoxFuzzing: Boolean by getBooleanProperty(true) /** * Set the total attempts to improve coverage by fuzzer. diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 1813769347..639305b29a 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -480,12 +480,13 @@ data class UtArrayModel( * @param instantiationCall is an [UtExecutableCallModel] to instantiate represented object. It **must** not return `null`. * @param modificationsChain is a chain of [UtStatementModel] to construct object state. */ -data class UtAssembleModel private constructor( +data class UtAssembleModel constructor( override val id: Int?, override val classId: ClassId, override val modelName: String, val instantiationCall: UtExecutableCallModel, - val modificationsChain: List, + //TODO: get rid of var + var modificationsChain: List, val origin: UtCompositeModel? ) : UtReferenceModel(id, classId, modelName) { diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt index 20748404fa..260d905359 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt @@ -1,5 +1,6 @@ package org.utbot.framework.plugin.api +import org.utbot.framework.plugin.api.util.objectClassId import org.utbot.framework.plugin.api.visible.UtStreamConsumingException import java.io.File import java.util.LinkedList @@ -21,6 +22,10 @@ sealed class UtExecutionFailure : UtExecutionResult() { get() = exception } +data class UtExecutionSuccessConcrete(val result: Any?) : UtExecutionResult() { + override fun toString() = "$result" +} + data class UtOverflowFailure( override val exception: Throwable, ) : UtExecutionFailure() @@ -102,7 +107,14 @@ inline fun UtExecutionResult.onFailure(action: (exception: Throwable) -> Unit): return this } +fun UtExecutionResult.getOrThrow(): UtModel = when (this) { + is UtExecutionSuccess -> model + is UtExecutionFailure -> throw exception + is UtExecutionSuccessConcrete -> UtNullModel(objectClassId) +} + fun UtExecutionResult.exceptionOrNull(): Throwable? = when (this) { is UtExecutionFailure -> rootCauseException is UtExecutionSuccess -> null + is UtExecutionSuccessConcrete -> null } diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/constructor/ValueConstructor.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/constructor/ValueConstructor.kt index 962fd54446..b3df2a59ea 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/constructor/ValueConstructor.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/constructor/ValueConstructor.kt @@ -26,6 +26,7 @@ import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtExecutionFailure import org.utbot.framework.plugin.api.UtExecutionResult import org.utbot.framework.plugin.api.UtExecutionSuccess +import org.utbot.framework.plugin.api.UtExecutionSuccessConcrete import org.utbot.framework.plugin.api.UtLambdaModel import org.utbot.framework.plugin.api.UtMockValue import org.utbot.framework.plugin.api.UtModel @@ -42,6 +43,7 @@ import org.utbot.framework.plugin.api.util.anyInstance import org.utbot.framework.plugin.api.util.constructLambda import org.utbot.framework.plugin.api.util.constructStaticLambda import org.utbot.framework.plugin.api.util.constructor +import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.isStatic import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.jField @@ -492,6 +494,7 @@ class ValueConstructor { private fun UtExecutionResult.map(transform: (model: UtModel) -> R): Result = when (this) { is UtExecutionSuccess -> Result.success(transform(model)) is UtExecutionFailure -> Result.failure(exception) + is UtExecutionSuccessConcrete -> Result.success(transform(UtNullModel(Any::class.java.id))) } /** diff --git a/utbot-framework/build.gradle b/utbot-framework/build.gradle index a46be75524..7401500d4e 100644 --- a/utbot-framework/build.gradle +++ b/utbot-framework/build.gradle @@ -34,6 +34,10 @@ dependencies { implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion implementation group: 'org.jacoco', name: 'org.jacoco.report', version: jacocoVersion implementation group: 'org.apache.commons', name: 'commons-text', version: apacheCommonsTextVersion + implementation "org.javaruntype:javaruntype:1.3" + implementation "ru.vyarus:generics-resolver:3.0.3" + implementation "ognl:ognl:3.3.2" + // we need this for construction mocks from composite models implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0' diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/From.java b/utbot-framework/src/main/java/org/utbot/quickcheck/From.java new file mode 100644 index 0000000000..9456b496b0 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/From.java @@ -0,0 +1,65 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck; + +import org.utbot.quickcheck.Produced; +import org.utbot.quickcheck.Property; +import org.utbot.quickcheck.generator.Generator; + +import java.lang.annotation.Repeatable; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a parameter of a {@link Property} method with this annotation to + * have random values supplied to it via the specified + * {@link Generator}.

+ * + *

You may specify as many of these annotations as as you wish on a given + * parameter. On a given generation, one of the specified generators will be + * chosen at random with probability in proportion to {@link #frequency()}.

+ * + *

If any such generator produces values of a type incompatible with the + * type of the marked parameter, {@link IllegalArgumentException} is + * raised.

+ */ +@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) +@Retention(RUNTIME) +@Repeatable(Produced.class) +public @interface From { + /** + * @return the generator to be used for the annotated property parameter + */ + Class value(); + + /** + * @return a weight to influence how often the generator is chosen + */ + int frequency() default 1; +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/MinimalCounterexampleHook.java b/utbot-framework/src/main/java/org/utbot/quickcheck/MinimalCounterexampleHook.java new file mode 100644 index 0000000000..54da339a4f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/MinimalCounterexampleHook.java @@ -0,0 +1,46 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck; + +import org.utbot.quickcheck.Property; + +/** + *

Allows access to an actual failing example.

+ * + *

This may be useful if any of the objects' {@link Object#toString()} + * representations is difficult to understand.

+ * + * @see Property#onMinimalCounterexample() + */ +public interface MinimalCounterexampleHook { + /** + * @param counterexample the minimal counterexample (after shrinking) + * @param action work to perform with the minimal counterexample; + * for example, this could repeat the test using the same inputs. + * This action should be safely callable multiple times. + */ + void handle(Object[] counterexample, Runnable action); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/Mode.java b/utbot-framework/src/main/java/org/utbot/quickcheck/Mode.java new file mode 100644 index 0000000000..4d8ac52c6d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/Mode.java @@ -0,0 +1,63 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck; + +import org.utbot.quickcheck.Property; +import org.utbot.quickcheck.internal.ParameterSampler; +import org.utbot.quickcheck.internal.sampling.ExhaustiveParameterSampler; +import org.utbot.quickcheck.internal.sampling.TupleParameterSampler; + +/** + * Represents different modes of execution of property-based tests. + * + * @see org.utbot.quickcheck.generator.Only + * @see org.utbot.quickcheck.generator.Also + */ +public enum Mode { + /** + * Verify {@link org.utbot.quickcheck.Property#trials()} tuples of arguments for a property's + * parameters. + */ + SAMPLING { + @Override ParameterSampler sampler(int defaultSampleSize) { + return new TupleParameterSampler(defaultSampleSize); + } + }, + + /** + * Generate {@link Property#trials()} arguments for each parameter + * property, and verify the cross-products of those sets of arguments. + * This behavior mirrors that of the JUnit + * {@link org.junit.experimental.theories.Theories} runner. + */ + EXHAUSTIVE { + @Override ParameterSampler sampler(int defaultSampleSize) { + return new ExhaustiveParameterSampler(defaultSampleSize); + } + }; + + abstract ParameterSampler sampler(int defaultSampleSize); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java b/utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java new file mode 100644 index 0000000000..8d107083ca --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2017-2018 The Regents of the University of California + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.utbot.quickcheck; + +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.internal.GeometricDistribution; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + + +/** + * Provides a generation status that does not track the number of trials + * generated so far. This is useful for guided fuzzing where the burden + * of making choices is on the guidance system rather than on quickcheck. + * + * @author Rohan Padhye + */ +public class NonTrackingGenerationStatus implements GenerationStatus { + + public static final int MEAN_SIZE = 10; + + private final SourceOfRandomness random; + private final Map, Object> contextValues = new HashMap<>(); + private final GeometricDistribution geometric = new GeometricDistribution(); + + + public NonTrackingGenerationStatus(SourceOfRandomness random) { + this.random = random; + } + + @Override + public int size() { + return geometric.sampleWithMean(MEAN_SIZE, random); + } + + @Override + public int attempts() { + throw new UnsupportedOperationException("attempts() and @ValueOf" + + " is not supported in guided mode."); + } + + @Override + public GenerationStatus setValue(Key key, T value) { + contextValues.put(key, value); + return this; + } + + @Override + public Optional valueOf(Key key) { + return Optional.ofNullable(key.cast(contextValues.get(key))); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/Pair.java b/utbot-framework/src/main/java/org/utbot/quickcheck/Pair.java new file mode 100644 index 0000000000..d641703a84 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/Pair.java @@ -0,0 +1,70 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck; + +import java.util.Objects; + +/** + * Typed pair of elements. + * + * @param type of first element of pair + * @param type of second element of pair + * @see org.utbot.quickcheck.generator.Gen#frequency(Pair, Pair[]) + */ +public final class Pair { + public final F first; + public final S second; + + /** + * Makes a pair. + * + * @param first first element of the pair + * @param second second element of the pair + */ + public Pair(F first, S second) { + this.first = first; + this.second = second; + } + + @Override public int hashCode() { + return Objects.hash(first, second); + } + + @Override public boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof Pair)) + return false; + + Pair other = (Pair) o; + return Objects.equals(first, other.first) + && Objects.equals(second, other.second); + } + + @Override public String toString() { + return String.format("[%s = %s]", first, second); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/Produced.java b/utbot-framework/src/main/java/org/utbot/quickcheck/Produced.java new file mode 100644 index 0000000000..ce137809b8 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/Produced.java @@ -0,0 +1,55 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck; + +import org.utbot.quickcheck.From; +import org.utbot.quickcheck.Property; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a parameter of a {@link Property} method with this annotation to + * have random values supplied to it via one of the + * {@link org.utbot.quickcheck.generator.Generator}s specified by the + * aggregated {@link From} annotations.

+ * + *

Alternatively, you can specify many generators via many repetitions of + * {@link From}, without using this container annotation.

+ * + *

On a given generation, one of the specified generators will be chosen at + * random with probability in proportion to {@link From#frequency()}.

+ * + * @see From + */ +@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) +@Retention(RUNTIME) +public @interface Produced { + From[] value(); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/Property.java b/utbot-framework/src/main/java/org/utbot/quickcheck/Property.java new file mode 100644 index 0000000000..513686b46e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/Property.java @@ -0,0 +1,97 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck; + +import org.utbot.quickcheck.MinimalCounterexampleHook; +import org.utbot.quickcheck.Mode; +import org.utbot.quickcheck.hook.NilMinimalCounterexampleHook; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static org.utbot.quickcheck.Mode.SAMPLING; +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a method on a class that is {@linkplain org.junit.runner.RunWith + * run with} the {@link org.utbot.quickcheck.runner.JUnitQuickcheck} + * runner with this annotation to have it run as a property-based test.

+ * + *

A method marked with this annotation should be an instance method + * declared as {@code public} with a return type of {@code void}.

+ */ +@Target(METHOD) +@Retention(RUNTIME) +public @interface Property { + /** + * @return the verification mode for the property + */ + Mode mode() default SAMPLING; + + /** + * @return how many sets of parameters to verify the property with, in + * {@link Mode#SAMPLING} mode; in {@link Mode#EXHAUSTIVE} mode, how many + * values to generate for each property parameter + */ + int trials() default 100; + + /** + * @return whether or not to attempt to {@linkplain + * org.utbot.quickcheck.generator.Shrink shrink} a failing set + * of parameters + */ + boolean shrink() default true; + + /** + * @return the maximum number of {@linkplain + * org.utbot.quickcheck.generator.Shrink shrink} attempts to make + * on a failing set of parameters; in effect only when {@link #shrink()} + * is {@code true} + */ + int maxShrinks() default 100; + + /** + * @return the maximum depth of {@linkplain + * org.utbot.quickcheck.generator.Shrink shrink} tree to make on + * a failing set of parameters; in effect only when {@link #shrink()} is + * {@code true} + */ + int maxShrinkDepth() default 20; + + /** + * @return the maximum elapsed time for the shrinking process in + * milliseconds; in effect only when {@link #shrink()} is {@code true} + */ + int maxShrinkTime() default 60_000; + + /** + * @return callback that it is executed if a minimal counterexample + * is found (after shrinking) + */ + Class onMinimalCounterexample() + default NilMinimalCounterexampleHook.class; +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/When.java b/utbot-framework/src/main/java/org/utbot/quickcheck/When.java new file mode 100644 index 0000000000..992b304054 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/When.java @@ -0,0 +1,68 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck; + +import org.utbot.quickcheck.Property; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.PARAMETER; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Mark a parameter of a {@link Property} method with this annotation to + * specify metadata about values generated for that parameter. + */ +@Target(PARAMETER) +@Retention(RUNTIME) +public @interface When { + /** + * @return the ratio of discarded generated values to successful generated + * values above which values for the annotated property parameter will + * no longer be generated. For a non-positive value, an + * {@link IllegalArgumentException} is raised. The default value is 10, + * to curtail generation for {@link #satisfies()} expressions that are + * difficult to satisfy or can never be satisfied (inadvertently or + * otherwise). + */ + int discardRatio() default 10; + + /** + * @return an OGNL expression + * used to constrain the values fed to the annotated property parameter. + * The expression should evaluate to a {@code boolean} value. Within the + * expression, {@code "_"} refers to the property parameter. + */ + String satisfies() default ""; + + /** + * @return a value to be used as the initial seed for the random value + * generator. Not specifying a value causes the seed to be chosen + * randomly. + */ + long seed() default 0; +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/conversion/StringConversion.java b/utbot-framework/src/main/java/org/utbot/quickcheck/conversion/StringConversion.java new file mode 100644 index 0000000000..150a57b10f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/conversion/StringConversion.java @@ -0,0 +1,40 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.conversion; + +/** + * Describes ways of transforming string input into objects of another type. + */ +@FunctionalInterface +public interface StringConversion { + /** + * Transform the given "raw" string" into an object of another type. + * + * @param raw the string to convert + * @return the result of the conversion + */ + Object convert(String raw); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Also.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Also.java new file mode 100644 index 0000000000..0bc1c56191 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Also.java @@ -0,0 +1,69 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.Property; +import org.utbot.quickcheck.conversion.StringConversion; +import org.utbot.quickcheck.generator.Only; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a parameter of a {@link Property} method with this annotation to + * ensure that a limited set of values are guaranteed to be used as the value + * of that parameter to test the property.

+ * + *

In {@linkplain org.utbot.quickcheck.Mode#SAMPLING sampling} + * mode, on each trial junit-quickcheck ensures that the first n + * values are the given set, and generates the remaining (trials - n) + * values in the usual way. + * + *

In {@linkplain org.utbot.quickcheck.Mode#EXHAUSTIVE exhaustive} + * mode, junit-quickcheck uses the values in the limited set for the property + * parameter, and generates the remaining (trials - n) values in the + * usual way.

+ * + *

Note: You will still need a generator defined for the + * property parameter's type when this annotation is used.

+ */ +@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) +@Retention(RUNTIME) +public @interface Also { + /** + * @return the values to which the property parameter will certainly be + * assigned during property verification + */ + String[] value(); + + /** + * @see Only#by() + */ + Class by() default StringConversion.class; +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java new file mode 100644 index 0000000000..17343c0ed1 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java @@ -0,0 +1,120 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.javaruntype.type.TypeParameter; + +import java.lang.reflect.AnnotatedType; +import java.util.ArrayList; +import java.util.List; + +import static org.utbot.quickcheck.internal.Reflection.annotatedComponentTypes; +import static java.util.Collections.unmodifiableList; + +/** + * Produces values for property parameters of types that have parameterizations + * that would also need generation, such as collections, maps, and predicates. + * + * @param type of property parameter to apply this generator's values to + */ +public abstract class ComponentizedGenerator extends Generator { + + private final List> components = new ArrayList<>(); + + /** + * @param type class token for type of property parameter this generator + * is applicable to + */ + protected ComponentizedGenerator(Class type) { + super(type); + } + + /** + * {@inheritDoc} + * + *

Generators of this type do not get called upon to generate values + * for parameters of type {@link Object}.

+ */ + @Override public boolean canRegisterAsType(Class type) { + return !Object.class.equals(type); + } + + @Override public final boolean hasComponents() { + return true; + } + + @Override public void addComponentGenerators( + List> newComponents) { + + if (newComponents.size() != numberOfNeededComponents()) { + throw new IllegalArgumentException( + String.format( + "Needed %d components for %s, but got %d", + numberOfNeededComponents(), + getClass(), + newComponents.size())); + } + + components.clear(); + components.addAll(newComponents); + } + + @Override public boolean canGenerateForParametersOfTypes( + List> typeParameters) { + + return numberOfNeededComponents() == typeParameters.size(); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + for (org.utbot.quickcheck.generator.Generator each : components) { + each.provide(provided); + } + } + + @Override public void configure(AnnotatedType annotatedType) { + super.configure(annotatedType); + + List annotatedComponentTypes = + annotatedComponentTypes(annotatedType); + + if (annotatedComponentTypes.size() == components.size()) { + for (int i = 0; i < components.size(); ++i) { + components.get(i).configure(annotatedComponentTypes.get(i)); + } + } + } + + /** + * @return this generator's component generators + */ + public List> componentGenerators() { + return unmodifiableList(components); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Ctor.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Ctor.java new file mode 100644 index 0000000000..65636aa75a --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Ctor.java @@ -0,0 +1,152 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.external.api.UtModelFactoryKt; +import org.utbot.framework.concrete.UtModelConstructor; +import org.utbot.framework.plugin.api.*; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Constructor; +import java.lang.reflect.Parameter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.instantiate; +import static org.utbot.quickcheck.internal.Reflection.singleAccessibleConstructor; + +/** + *

Produces instances of a class by generating values for the parameters of + * one of the constructors on the class, and invoking the constructor.

+ * + *

If a constructor parameter is marked with an annotation that influences + * the generation of a given kind of value, that annotation will be applied to + * the generation of values for that parameter.

+ * + *

This generator is intended to be used with + * {@link org.utbot.quickcheck.From}, and not to be available via the + * {@link java.util.ServiceLoader} mechanism.

+ * + * @param the type of objects generated + */ +public class Ctor extends Generator { + private final Constructor ctor; + private final Parameter[] parameters; + private final List> parameterGenerators = new ArrayList<>(); + + /** + * Reflects the given type for a single accessible constructor to be used + * to generate values of that type. + * + * @param type the type of objects to be generated + */ + public Ctor(Class type) { + this(singleAccessibleConstructor(type)); + } + + /** + * Uses the given constructor to generate values of the declaring type. + * + * @param ctor the constructor to reflect on to generate constructor + * parameter values + */ + public Ctor(Constructor ctor) { + super(ctor.getDeclaringClass()); + + this.ctor = ctor; + this.parameters = ctor.getParameters(); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); + + final ClassId classId = classIdForType(ctor.getDeclaringClass()); + final List argumentTypes = Arrays.stream(ctor.getParameterTypes()) + .map(UtModelFactoryKt::classIdForType) + .collect(Collectors.toList()); + + final ExecutableId constructorId = new ConstructorId(classId, argumentTypes); + + final int generatedModelId = modelConstructor.computeUnusedIdAndUpdate(); + + final List args = arguments(random, status); + final UtAssembleModel generatedModel = new UtAssembleModel( + generatedModelId, + classId, + constructorId.getName() + "#" + generatedModelId, + new UtExecutableCallModel(null, constructorId, args), + null, + (a) -> List.of() + ); + + return generatedModel; + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + parameterGenerators.clear(); + for (Parameter each : parameters) { + parameterGenerators.add(gen().parameter(each)); + } + } + + @Override public void configure(AnnotatedType annotatedType) { + super.configure(annotatedType); + + for (int i = 0; i < parameters.length; ++i) { + parameterGenerators.get(i) + .configure(parameters[i].getAnnotatedType()); + } + } + + @Override public Ctor copy() { + return new Ctor<>(ctor); + } + + private List arguments( + SourceOfRandomness random, + GenerationStatus status) { + + UtModel[] args = new UtModel[parameters.length]; + + for (int i = 0; i < args.length; ++i) { + args[i] = parameterGenerators.get(i).generate(random, status); + } + + return List.of(args); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java new file mode 100644 index 0000000000..71ff1e4f5b --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java @@ -0,0 +1,155 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Stream; + +import static org.utbot.quickcheck.internal.Sequences.halvingDecimal; +import static org.utbot.quickcheck.internal.Sequences.halvingIntegral; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; + +/** + * Base class for generators of decimal types, such as {@code double} and + * {@link BigDecimal}. All numbers are converted to/from BigDecimal for + * processing. + * + * @param type of values this generator produces + */ +public abstract class DecimalGenerator extends Generator { + protected DecimalGenerator(Class type) { + super(singletonList(type)); + } + + protected DecimalGenerator(List> types) { + super(types); + } + + @Override public List doShrink( + SourceOfRandomness random, + T largestGeneric) { + + if (largestGeneric.equals(leastMagnitude())) + return emptyList(); + + // We work with BigDecimal, so convert all inputs + BigDecimal largest = widen().apply(largestGeneric); + BigDecimal least = widen().apply(leastMagnitude()); + + List results = new ArrayList<>(); + + // Positive numbers are considered easier than negative ones + if (negative(largestGeneric)) + results.add(negate(largestGeneric)); + + // Try your luck by testing the smallest possible value + results.add(leastMagnitude()); + + // Try values between smallest and largest, with smaller and smaller + // increments as we approach the largest + + // Integrals are considered easier than decimals + results.addAll(shrunkenIntegrals(largest, least)); + results.addAll(shrunkenDecimals(largest, least)); + + return results; + } + + private List shrunkenIntegrals(BigDecimal largest, BigDecimal least) { + return decimalsFrom( + stream( + halvingIntegral( + largest.toBigInteger(), + least.toBigInteger()) + .spliterator(), + false) + .map(BigDecimal::new)); + } + + private List shrunkenDecimals(BigDecimal largest, BigDecimal least) { + return decimalsFrom( + stream( + halvingDecimal(largest, least).spliterator(), + false)); + } + + private List decimalsFrom(Stream stream) { + return stream.limit(15) + .map(narrow()) + .filter(inRange()) + .distinct() + .collect(toList()); + } + + /** + * @return a function converting a value of the base type into a + * {@link BigDecimal} + */ + protected abstract Function widen(); + + /** + * @return a function converting a {@link BigDecimal} into the equivalent + * value in the base type + */ + protected abstract Function narrow(); + + /** + * @return a predicate checking whether its input is in the configured + * range + */ + protected abstract Predicate inRange(); + + /** + * @return the lowest magnitude number, respecting the configured range. + * The ideal shrink value is always this value (i.e. this value cannot + * be shrunk any further). + */ + protected abstract T leastMagnitude(); + + /** + * @return whether the given number is negative or not + */ + protected abstract boolean negative(T target); + + /** + * Used when shrinking negative numbers to add the positive equivalent + * value at the top of shrinks list. + * + * @param target always a negative number + * @return the positive equivalent to target + */ + protected abstract T negate(T target); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java new file mode 100644 index 0000000000..f64a7e1e8b --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java @@ -0,0 +1,52 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.GeneratorConfiguration; +import org.utbot.quickcheck.generator.Size; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + * method with this annotation to make values generated for the parameter + * distinct from each other.

+ * + *

This annotation is recognized on array parameters and parameters of type + * {@link java.util.Collection} and {@link java.util.Map}.

+ * + *

Using this annotation with {@link Size} on {@link java.util.Set} or + * {@link java.util.Map} leads to strict size constraint.

+ */ +@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) +@Retention(RUNTIME) +@GeneratorConfiguration +public @interface Distinct { +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Fields.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Fields.java new file mode 100644 index 0000000000..f4e32289b4 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Fields.java @@ -0,0 +1,123 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.framework.plugin.api.UtNullModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Field; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.*; +import static java.util.stream.Collectors.toList; + +/** + *

Produces instances of a class by reflecting the class's fields and + * generating random values for them.

+ * + *

All fields of the class and its class hierarchy are auto-generated.

+ * + *

In order for this generator to work, the type it is given must have an + * accessible zero-arg constructor.

+ * + *

If a field is marked with an annotation that influences the generation of + * a given kind of value, that annotation will be applied to the generation of + * values for that field.

+ * + *

This generator is intended to be used with + * {@link org.utbot.quickcheck.From}, and not to be available via the + * {@link java.util.ServiceLoader} mechanism.

+ * + * @param the type of objects generated + */ +public class Fields extends org.utbot.quickcheck.generator.Generator { + private final List fields; + private final List> fieldGenerators = new ArrayList<>(); + + /** + * @param type the type of objects to be generated + */ + public Fields(Class type) { + super(type); + + this.fields = + allDeclaredFieldsOf(type).stream() + .filter(f -> !Modifier.isFinal(f.getModifiers())) + .collect(toList()); + + instantiate(type); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + Class type = types().get(0); + Object generated = instantiate(type); + + for (int i = 0; i < fields.size(); i++) { + setField( + fields.get(i), + generated, + fieldGenerators.get(i).generate(random, status), + true); + } + + //return UtModelGenerator.getUtModelConstructor().construct(type.cast(generated),); + return new UtNullModel(classIdForType(type)); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + fieldGenerators.clear(); + for (Field each : fields) { + fieldGenerators.add(gen().field(each)); + } + } + + @Override public void configure(AnnotatedType annotatedType) { + super.configure(annotatedType); + + for (int i = 0; i < fields.size(); ++i) { + fieldGenerators.get(i).configure( + fields.get(i).getAnnotatedType()); + } + } + + @Override public Generator copy() { + return new Fields<>(types().get(0)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java new file mode 100644 index 0000000000..1ac1ae84d0 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java @@ -0,0 +1,248 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.random.SourceOfRandomness; + +/** + * Represents a strategy for generating random values. + * + * @param type of values generated + */ +@FunctionalInterface +public interface Gen { + /** + * Generates a value, possibly influenced by a source of randomness and + * metadata about the generation. + * + * @param random source of randomness to be used when generating the value + * @param status an object that can be used to influence the generated + * value. For example, generating lists can use the {@link + * GenerationStatus#size() size} method to generate lists with a given + * number of elements. + * @return the generated value + */ + UtModel generate(SourceOfRandomness random, GenerationStatus status); + +// /** +// * Gives a generation strategy that produces a random value by having this +// * strategy produce a random value, then applying the given function to +// * that value, and returning the result. +// * +// * @param type of values produced by the mapped generation strategy +// * @param mapper function that converts receiver's random values to +// * result's values +// * @return a new generation strategy +// */ +// default Gen map(Function mapper) { +// return (random, status) -> mapper.apply(_gen(random, status)); +// } +// +// /** +// * Gives a generation strategy that produces a random value by having this +// * strategy produce a random value, then applying the given function to +// * that value, and asking the result to produce a value. +// * +// * @param type of values produced by the mapped generation strategy +// * @param mapper function that converts receiver's random values to +// * another kind of generation strategy +// * @return a new generation strategy +// */ +// default Gen flatMap( +// Function> mapper) { +// +// return (random, status) -> +// mapper.apply(_gen(random, status))._gen(random, status); +// } +// +// /** +// * Gives a generation strategy that produces a random value by having this +// * strategy produce random values until one satisfies the given condition, +// * then using that value as the result. +// * +// * @param condition a condition the generated value is to meet +// * @return a new generation strategy +// */ +// default Gen filter(Predicate condition) { +// return (random, status) -> { +// T next = _gen(random, status); +// while (!condition.test(next)) { +// next = _gen(random, status); +// } +// return next; +// }; +// } +// +// /** +// *

Gives a generation strategy that produces a random value by having +// * this strategy produce a random value and wrapping it in an +// * {@link Optional}; if the value meets the given condition, the wrapping +// * optional will be {@linkplain Optional#isPresent() present}.

+// * +// *

If the value meets the condition but is {@code null}, the wrapping +// * optional will not be considered +// * {@linkplain Optional#isPresent() present}.

+// * +// * @param condition a condition the generated value is to meet +// * @return a new generation strategy +// */ +// default Gen> filterOptional(Predicate condition) { +// return (random, status) -> { +// T next = _gen(random, status); +// return condition.test(next) +// ? Optional.ofNullable(next) +// : Optional.empty(); +// }; +// } +// +// default Gen> times(int times) { +// if (times < 0) +// throw new IllegalArgumentException("negative times: " + times); +// +// return (random, status) -> { +// List values = new ArrayList<>(); +// for (int i = 0; i < times; ++i) { +// values.add(_gen(random, status)); +// } +// return values; +// }; +// } +// +// /** +// * Gives a generation strategy that produces the given value, always. +// * +// * @param type of values produced by the resulting strategy +// * @param constant the value to be returned by the resulting strategy +// * @return a new generation strategy +// */ +// static Gen pure(U constant) { +// return (random, status) -> constant; +// } +// +// /** +// * Gives a generation strategy that produces a random value by choosing +// * one of the given values at random with (approximately) equal +// * probability. +// * +// * @param type of values produced by the resulting strategy +// * @param first first possible choice +// * @param rest the other possible choices +// * @return a new generation strategy +// */ +// @SafeVarargs static Gen oneOf(U first, U... rest) { +// List choices = new ArrayList<>(); +// choices.add(first); +// Collections.addAll(choices, rest); +// +// return (random, status) -> Items.choose(choices, random); +// } +// +// /** +// * Gives a generation strategy that produces a random value by choosing +// * one of the given generators at random with (approximately) equal +// * probability, and having it generate a value. +// * +// * @param type of values produced by the resulting strategy +// * @param first first possible generator choice +// * @param rest the other possible generator choices +// * @return a new generation strategy +// */ +// @SafeVarargs static Gen oneOf( +// Gen first, +// Gen... rest) { +// +// List> choices = new ArrayList<>(); +// choices.add(first); +// Collections.addAll(choices, rest); +// +// return (random, status) -> +// Items.choose(choices, random)._gen(random, status); +// } +// +// /** +// * Gives a generation strategy that produces a random value by choosing +// * one of the given generators at random with probability in proportion +// * to their given weights, and having it generate a value. +// * +// * @param type of values produced by the resulting strategy +// * @param first first possible (weighted) generator choice +// * @param rest the other possible (weighted) generator choices +// * @return a new generation strategy +// */ +// @SafeVarargs static Gen frequency( +// Pair> first, +// Pair>... rest) { +// +// List>> pairs = new ArrayList<>(); +// pairs.add(first); +// Collections.addAll(pairs, rest); +// +// List>> weighted = +// pairs.stream() +// .map(p -> new Weighted>(p.second, p.first)) +// .collect(toList()); +// +// return (random, status) -> +// Items.chooseWeighted(weighted, random)._gen(random, status); +// } +// +// /** +// * Helper for making a weighted generator indicator for +// * {@link #frequency(Pair, Pair[])}. +// * +// * @param type of values produced by the given generation strategy +// * @param weight an integer weight +// * @param generator a generator +// * @return a weight-generator pair +// */ +// static Pair> freq( +// int weight, +// Gen generator) { +// +// return new Pair<>(weight, generator); +// } +// +// /** +// * @deprecated For use by junit-quickcheck only -- when we migrate to Java +// * 9 or better, this method will likely become {@code private}. +// * +// * @param random source of randomness to be used when generating the value +// * @param status an object that can be used to influence the generated +// * value. For example, generating lists can use the {@link +// * GenerationStatus#size() size} method to generate lists with a given +// * number of elements. +// * @return the generated value +// */ +// @Deprecated +// default T _gen(SourceOfRandomness random, GenerationStatus status) { +// T result = generate(random, status); +// +// status.semiAttempt(); +// +// return result; +// } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java new file mode 100644 index 0000000000..4668fff487 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java @@ -0,0 +1,123 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.Generator; + +import java.util.Objects; +import java.util.Optional; + +/** + * {@link Generator}s are fed instances of this interface on each generation + * so that, if they choose, they can use these instances to influence the + * results of a generation for a particular property parameter. + */ +public interface GenerationStatus { + /** + * @return an arbitrary "size" parameter; this value (probabilistically) + * increases for every successful generation + */ + int size(); + + /** + * @return how many attempts have been made to generate a value for a + * property parameter + */ + int attempts(); + + /** + *

Signals part of an attempt to generate a value.

+ * + *

Mostly for use by junit-quickcheck itself; generators can call this + * to convince the framework that it's doing work to generate a complex + * value, but doing so is not strictly necessary.

+ */ + default void semiAttempt() { + } + + /** + * Associates the given value with the given key for the duration of the + * generation of a value for a property parameter, or until overwritten. + * + * @param type of the value + * @param key a key to associate with a value + * @param value the associated value + * @return self, so that calls to this method can be chained + */ + GenerationStatus setValue(Key key, T value); + + /** + * Retrieves the value associated with the given key. + * + * @param type of the value associated with the key + * @param key key to look up + * @return the (optional) associated value + */ + Optional valueOf(Key key); + + /** + * Type-safe keys for {@link GenerationStatus#setValue(Key, Object) + * setValue} and {@link GenerationStatus#valueOf(Key) valueOf}. + * + * @param type of value that can be associated with the key + */ + final class Key { + private final String name; + private final Class type; + + public Key(String name, Class type) { + if (name == null) + throw new NullPointerException("name must not be null"); + if (type == null) + throw new NullPointerException("type must not be null"); + + this.name = name; + this.type = type; + } + + public T cast(Object o) { + return type.cast(o); + } + + @Override public boolean equals(Object o) { + if (o == this) + return true; + if (!(o instanceof Key)) + return false; + + Key other = (Key) o; + return name.equals(other.name) && type.equals(other.type); + } + + @Override public int hashCode() { + return Objects.hash(name, type); + } + + @Override public String toString() { + return name + ": " + type; + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java new file mode 100644 index 0000000000..f612425d5f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java @@ -0,0 +1,396 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.javaruntype.type.TypeParameter; +import org.javaruntype.type.Types; +import org.javaruntype.type.WildcardTypeParameter; +import org.utbot.quickcheck.internal.ReflectionException; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Method; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; + +import static java.math.BigDecimal.ONE; +import static java.util.Collections.*; +import static java.util.stream.Collectors.toList; +import static org.utbot.quickcheck.internal.Reflection.*; + +/** + * Produces values for property parameters. + * + * @param type of property parameter to apply this generator's values to + */ +public abstract class Generator implements Gen, Shrink { + private final List> types = new ArrayList<>(); + + private Generators repo; + + /** + * @param type class token for type of property parameter this generator is + * applicable to + */ + protected Generator(Class type) { + this(singletonList(type)); + } + + /** + * Used for generators of primitives and their wrappers. For example, a + * {@code Generator} can be used for property parameters of type + * {@code Integer} or {@code int}. + * + * @param types class tokens for type of property parameter this generator + * is applicable to + */ + protected Generator(List> types) { + this.types.addAll(types); + } + + /** + * @return class tokens for the types of property parameters this generator + * is applicable to + */ + public List> types() { + return unmodifiableList(types); + } + + /** + * Tells whether this generator is allowed to be used for property + * parameters of the given type. + * + * @param type type against which to test this generator + * @return {@code true} if the generator is allowed to participate in + * generating values for property parameters of {@code type} + */ + public boolean canRegisterAsType(Class type) { + return true; + } + + /** + * {@inheritDoc} + * + *

Generators first ensure that they {@linkplain #canShrink(Object) can + * participate} in shrinking the given value, and if so, they + * {@linkplain #doShrink(SourceOfRandomness, Object) produce shrinks}.

+ */ + @Override public final List shrink(SourceOfRandomness random, Object larger) { + if (!canShrink(larger)) { + throw new IllegalStateException( + getClass() + " not capable of shrinking " + larger); + } + + return doShrink(random, narrow(larger)); + } + + /** + *

Tells whether this generator is allowed to participate in the + * {@link Shrink} process for the given "larger" value.

+ * + *

Unless overridden, the only criterion for whether a generator is + * allowed to participate in shrinking a value is if the value can be + * safely cast to the type of values the generator produces.

+ * + * @param larger the "larger" value + * @return whether this generator can participate in "shrinking" the larger + * value + */ + public boolean canShrink(Object larger) { + return types().get(0).isInstance(larger); + } + + /** + *

Gives some objects that are "smaller" than a given "larger" + * object.

+ * + *

Unless overridden, a generator will produce an empty list of + * "smaller" values.

+ * + * @param random source of randomness to use in shrinking, if desired + * @param larger the larger object + * @return objects that are "smaller" than the larger object. Smaller objects should be provided before bigger objects to make shrinking process faster. + */ + public List doShrink(SourceOfRandomness random, T larger) { + return emptyList(); + } + + /** + *

Gives a hint to the shrinking process as to the magnitude of the given + * value. The shrinking process will prefer trying values of greater + * magnitude before values of lesser magnitude. If not overridden, this + * implementation returns "one".

+ * + *

Note to generator writers: Do not worry about normalizing + * a magnitude to a positive value; the shrinking mechanism will take care + * of it.

+ * + * @see #narrow(Object) + * @param value the value to assess + * @return a measure of the given value's magnitude + */ + public BigDecimal magnitude(Object value) { + return ONE; + } + + /** + *

Attempts to "narrow" the given object to the type this generator + * produces.

+ * + *

This is intended for use only by junit-quickcheck itself, and not by + * creators of custom generators.

+ * + * @param wider target of the narrowing + * @return narrowed the result of the narrowing + * @throws ClassCastException if the narrowing cannot be performed + */ + protected final T narrow(Object wider) { + return types().get(0).cast(wider); + } + + /** + *

This is intended for use only by junit-quickcheck itself, and not by + * creators of custom generators.

+ * + * @return whether this generator has component generators, such as for + * those generators that produce lists or maps + * @see #addComponentGenerators(List) + */ + public boolean hasComponents() { + return false; + } + + /** + *

This is intended for use only by junit-quickcheck itself, and not by + * creators of custom generators.

+ * + * @return how many component generators this generator needs + * @see #addComponentGenerators(List) + */ + public int numberOfNeededComponents() { + return 0; + } + + /** + *

Adds component generators to this generator.

+ * + *

Some generators need component generators to create proper values. + * For example, list generators require a single component generator in + * order to generate elements that have the type of the list parameter's + * type argument.

+ * + *

This is intended for use only by junit-quickcheck itself, and not by + * creators of custom generators.

+ * + * @param newComponents component generators to add + */ + public void addComponentGenerators(List> newComponents) { + // do nothing by default + } + + /** + * @param typeParameters a list of generic type parameters + * @return whether this generator can be considered for generating values + * for property parameters that have the given type parameters in their + * signatures + */ + public boolean canGenerateForParametersOfTypes(List> typeParameters) { + return true; + } + + /** + *

Configures this generator using annotations from a given annotated + * type.

+ * + *

This method considers only annotations that are themselves marked + * with {@link GeneratorConfiguration}.

+ * + *

By default, the generator will configure itself using this + * procedure:

+ *
    + *
  • For each of the given annotations: + *
      + *
    • Find a {@code public} method on the generator named + * {@code configure}, that accepts a single parameter of the + * annotation type
    • + *
    • Invoke the {@code configure} method reflectively, passing the + * annotation as the argument
    • + *
    + *
  • + *
+ * + * @param annotatedType a type usage + * @throws GeneratorConfigurationException if the generator does not + * "understand" one of the generation configuration annotations on + * the annotated type + */ + public void configure(AnnotatedType annotatedType) { + configureStrict(collectConfigurationAnnotations(annotatedType)); + } + + /** + * @param element an annotated program element + */ + public void configure(AnnotatedElement element) { + configureLenient(collectConfigurationAnnotations(element)); + } + + /** + *

Supplies the available generators to this one.

+ * + *

This is intended for use only by junit-quickcheck itself, and not by + * creators of custom generators.

+ + * @param provided repository of available generators + */ + public void provide(Generators provided) { + repo = provided; + } + + /** + * Used by the framework to make a copy of the receiver. + * + * @return a copy of the receiver + */ + @SuppressWarnings("unchecked") + public Generator copy() { + return (Generator) instantiate(getClass()); + } + + /** + * @param parameter a generic type parameter + * @param clazz a type + * @return whether the type is compatible with the generic type parameter + * @see #canGenerateForParametersOfTypes(List) + */ + protected static boolean compatibleWithTypeParameter( + TypeParameter parameter, + Class clazz) { + + return parameter instanceof WildcardTypeParameter + || parameter.getType().isAssignableFrom(Types.forJavaLangReflectType(clazz)); + } + + /** + * @return an access point for the available generators + */ + protected Generators gen() { + return repo; + } + + /** + * @param random a source of randomness used when locating other + * generators + * @return an access point for the available generators + */ + protected Generators gen(SourceOfRandomness random) { + return repo.withRandom(random); + } + + /** + * Gives a list of the {@link GeneratorConfiguration} annotations present + * on the given program element. + * + * @param element an annotated program element + * @return what configuration annotations are present on that element + */ + protected static List configurationAnnotationsOn(AnnotatedElement element) { + return allAnnotations(element).stream() + .filter(a -> a.annotationType().isAnnotationPresent(GeneratorConfiguration.class)) + .collect(toList()); + } + + private Map, Annotation> collectConfigurationAnnotations( + AnnotatedElement element) { + + if (element == null) + return emptyMap(); + + List configs = configurationAnnotationsOn(element); + + Map, Annotation> byType = new HashMap<>(); + for (Annotation each : configs) + byType.put(each.annotationType(), each); + return byType; + } + + private void configureStrict(Map, Annotation> byType) { + for (Map.Entry, Annotation> each : byType.entrySet()) + configureStrict(each.getKey(), each.getValue()); + } + + private void configureStrict( + Class annotationType, + Annotation configuration) { + + configure( + annotationType, + configuration, + ex -> { + throw new GeneratorConfigurationException( + String.format( + "Generator %s does not understand configuration annotation %s", + getClass().getName(), + annotationType.getName()), + ex); + }); + } + + private void configureLenient(Map, Annotation> byType) { + for (Map.Entry, Annotation> each : byType.entrySet()) + configureLenient(each.getKey(), each.getValue()); + } + + private void configureLenient( + Class annotationType, + Annotation configuration) { + + configure(annotationType, configuration, ex -> {}); + } + + private void configure( + Class annotationType, + Annotation configuration, + Consumer exceptionHandler) { + + Method configurer = null; + + try { + configurer = findMethod(getClass(), "configure", annotationType); + } catch (ReflectionException ex) { + exceptionHandler.accept(ex); + } + + if (configurer != null) + invoke(configurer, this, configuration); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java new file mode 100644 index 0000000000..1e311ec3a5 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java @@ -0,0 +1,53 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.Generator; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.ANNOTATION_TYPE; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Apply this annotation to an annotation that marks property parameters, + * in order that the marked annotation can be used to configure + * {@linkplain Generator generators} for values of the parameter's type.

+ * + *

If a generator has a public instance method named {@code configure}, + * with a single parameter whose type is an annotation that has this annotation + * applied, then when a property that has a parameter marked with method that + * annotation is verified, the generator that generates the value for that + * parameter will have its {@code configure} method called with the annotation + * as the argument.

+ */ +@Target(ANNOTATION_TYPE) +@Retention(RUNTIME) +@Documented +public @interface GeneratorConfiguration { +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java new file mode 100644 index 0000000000..f03ba5d629 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java @@ -0,0 +1,46 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.Generator; + +/** + * Raised if a problem arises when attempting to configure a generator with + * annotations from a property parameter. + * + * @see Generator#configure(java.lang.reflect.AnnotatedType) + */ +public class GeneratorConfigurationException extends RuntimeException { + private static final long serialVersionUID = 1L; + + public GeneratorConfigurationException(String message) { + super(message); + } + + public GeneratorConfigurationException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java new file mode 100644 index 0000000000..965e566d5d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java @@ -0,0 +1,188 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.reflect.Field; +import java.lang.reflect.Parameter; + +/** + * An access point for available generators. + */ +public interface Generators { + /** + *

Gives a generator that can produce instances of one of a given set of + * related types on every generation.

+ * + *

On each generation, one of the available generators that can produce + * one of the named types will be chosen with (approximately) equal + * probability.

+ * + * @param type of objects produced by the resulting generator + * @param first first type of generated value + * @param rest other (related) types of generated values + * @return generator that can produce values of the given types + */ + Generator oneOf( + Class first, + Class... rest); + + /** + *

Gives a generator that can produce instances of one of a given set of + * related types on every generation.

+ * + *

On each generation, one of the given generators will be called upon + * with (approximately) equal probability.

+ * + * @param type of objects produced by the resulting generator + * @param first first generator + * @param rest other generators + * @return generator that can produce values using the given generators + */ + Generator oneOf( + Generator first, + Generator... rest); + + /** + *

Gives a generator that can produce an instance of the type described + * by the field with the given name and containing type.

+ * + *

If the field is marked with an annotation that influences the + * generation of a given kind of value, that annotation will be applied to + * the resulting generator's values.

+ * + * @param type containing type for a field + * @param fieldName name of a field + * @return generator that can produce values of the field's type + */ + Generator field(Class type, String fieldName); + + /** + *

Gives a generator that can produce an instance of the type described + * by a constructor of a given type that accepts the given types of + * arguments. It will generate values for the parameters of the given + * constructor, and then invoke the constructor.

+ * + *

If the constructor's parameters are marked with annotations that + * influence the generation of a given kind of value, those annotations + * will be applied to the generators that will produce values to be used + * as arguments to the constructor.

+ * + * @param type of objects produced by the resulting generator + * @param type containing type for a constructor + * @param argumentTypes types of arguments to the constructor + * @return generator that can produce values using the constructor + */ + Generator constructor(Class type, Class... argumentTypes); + + /** + *

Gives a generator that can produce an instance of the given type + * by reflecting the class's fields on up its class hierarchy and + * generating random values for them.

+ * + *

The given type must have an accessible zero-arg constructor.

+ * + *

If a field of the given type is marked with an annotation that + * influences the generation of a given kind of value, that annotation + * will be applied to the generation of values for that field.

+ * + * @param type of objects produced by the resulting generator + * @param type a type + * @return generator that can produce values of that type + */ + Generator fieldsOf(Class type); + + /** + *

Gives a generator that can produce values of the given type, + * parameterized by the given "component" types.

+ * + * @param type of objects produced by the resulting generator + * @param type a type + * @param componentTypes types for the "components" of the type, if any + * @return generator that can produce values of that type + * @see ComponentizedGenerator + */ + Generator type(Class type, Class... componentTypes); + + /** + *

Gives a generator that can produce instances of the type of the + * given reflected method parameter.

+ * + *

If the parameter is marked with an annotation that influences the + * generation of its value, that annotation will be applied to the + * generation of values for that parameter's type.

+ * + * @param parameter a reflected method parameter + * @return generator that can produce values of the parameter's type + */ + Generator parameter(Parameter parameter); + + /** + *

Gives a generator that can produce instances of the type of the + * given reflected field.

+ * + *

If the field is marked with an annotation that influences the + * generation of its value, that annotation will be applied to the + * generation of values for that field's type.

+ * + * @param field a reflected field + * @return generator that can produce values of the field's type + */ + Generator field(Field field); + + /** + *

Makes a new generator of the given type, provides it with access to + * other available generators, + * {@linkplain Generator#configure(java.lang.reflect.AnnotatedType) + * configures} it with any configuration annotations present on the + * generator type, and supplies it any + * {@linkplain Generator#hasComponents() component generators} it needs. + * + * @param type of objects produced by the resulting generator + * @param genType type of generator to create + * @param componentGenerators any generators for components of the type + * @return a generator for producing values + * @see ComponentizedGenerator + */ + > T make( + Class genType, + Generator... componentGenerators); + + /** + *

Makes a generator access point just like the receiver, but which + * uses the given source of randomness for making random choices.

+ * + *

Intended for use by junit-quickcheck.

+ * + * @param random a source of randomness + * @return a generator access point that has the source of randomness + * available to it + */ + Generators withRandom(SourceOfRandomness random); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java new file mode 100644 index 0000000000..b503f2c074 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java @@ -0,0 +1,138 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.GeneratorConfiguration; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + * method with this annotation to constrain the values generated for the + * parameter to a given range.

+ * + *

Different generators may use different min/max attribute pairs. + * Generators that produce primitive values or values of their wrapper types + * will likely want to use the attribute pairs of corresponding type. + * Otherwise, a generator can use {@link #min()} and {@link #max()}, and + * take on the responsibility of converting their string values to values of + * the desired type.

+ */ +@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) +@Retention(RUNTIME) +@GeneratorConfiguration +public @interface InRange { + /** + * @return a minimum {@code byte} value + */ + byte minByte() default Byte.MIN_VALUE; + + /** + * @return a maximum {@code byte} value + */ + byte maxByte() default Byte.MAX_VALUE; + + /** + * @return a minimum {@code short} value + */ + short minShort() default Short.MIN_VALUE; + + /** + * @return a maximum {@code short} value + */ + short maxShort() default Short.MAX_VALUE; + + /** + * @return a minimum {@code char} value + */ + char minChar() default Character.MIN_VALUE; + + /** + * @return a maximum {@code char} value + */ + char maxChar() default Character.MAX_VALUE; + + /** + * @return a minimum {@code int} value + */ + int minInt() default Integer.MIN_VALUE; + + /** + * @return a maximum {@code int} value + */ + int maxInt() default Integer.MAX_VALUE; + + /** + * @return a minimum {@code long} value + */ + long minLong() default Long.MIN_VALUE; + + /** + * @return a maximum {@code long} value + */ + long maxLong() default Long.MAX_VALUE; + + /** + * @return a minimum {@code float} value + */ + float minFloat() default 0F; + + /** + * @return a maximum {@code float} value + */ + float maxFloat() default 1F; + + /** + * @return a minimum {@code double} value + */ + double minDouble() default 0D; + + /** + * @return a maximum {@code double} value + */ + double maxDouble() default 1D; + + /** + * @return a minimum value, represented in string form + */ + String min() default ""; + + /** + * @return a maximum value, represented in string form + */ + String max() default ""; + + /** + * @return a formatting hint, such as a + * {@linkplain java.text.SimpleDateFormat date format string}, that + * generators can use when converting values from strings + */ + String format() default ""; +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java new file mode 100644 index 0000000000..b4767edd72 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java @@ -0,0 +1,133 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigInteger; +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.quickcheck.internal.Sequences.halvingIntegral; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; + +/** + * Base class for generators of integral types, such as {@code int} and + * {@link BigInteger}. All numbers are converted to/from BigInteger for + * processing. + * + * @param type of values this generator produces + */ +public abstract class IntegralGenerator + extends Generator { + + protected IntegralGenerator(Class type) { + super(singletonList(type)); + } + + protected IntegralGenerator(List> types) { + super(types); + } + + @Override public List doShrink(SourceOfRandomness random, T larger) { + if (larger.equals(leastMagnitude())) + return emptyList(); + + List results =new ArrayList<>(); + + // Positive numbers are considered easier than negative ones + if (negative(larger)) + results.add(negate(larger)); + + // Try your luck by testing the smallest possible value + results.add(leastMagnitude()); + + // Try values between smallest and largest, with smaller and smaller + // increments as we approach the largest + results.addAll( + stream( + halvingIntegral( + // We work with BigInteger, so convert all inputs + widen().apply(larger), + widen().apply(leastMagnitude()) + ).spliterator(), + false) + .limit(15) + .map(narrow()) + .filter(inRange()) + .distinct() + .collect(toList())); + + return results; + } + + /** + * @return a function converting a value of the base type into a + * {@link BigInteger} + */ + protected Function widen() { + return n -> BigInteger.valueOf(n.longValue()); + } + + /** + * @return a function converting a {@link BigInteger} into the equivalent + * value in the base type + */ + protected abstract Function narrow(); + + /** + * @return a predicate checking whether its input is in the configured + * range + */ + protected abstract Predicate inRange(); + + /** + * @return the lowest magnitude number, respecting the configured range. + * The ideal shrink value is always this value (i.e. this value cannot + * be shrunk any further). + */ + protected abstract T leastMagnitude(); + + /** + * @return whether the given number is negative or not + */ + protected abstract boolean negative(T target); + + /** + * Used when shrinking negative numbers to add the positive equivalent + * value at the top of shrinks list. + * + * @param target always a negative number + * @return the positive equivalent to target + */ + protected abstract T negate(T target); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java new file mode 100644 index 0000000000..cfe86c946c --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java @@ -0,0 +1,167 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.internal.DefaultMethodHandleMaker; +import org.utbot.quickcheck.internal.GeometricDistribution; +import org.utbot.quickcheck.internal.generator.SimpleGenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.invoke.MethodHandle; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.Random; + +import static org.utbot.quickcheck.internal.Reflection.singleAbstractMethodOf; +import static java.lang.System.identityHashCode; +import static java.lang.reflect.Proxy.newProxyInstance; + +/** + * Helper class for creating instances of "functional interfaces". + */ +public final class Lambdas { + private Lambdas() { + throw new UnsupportedOperationException(); + } + + /** + *

Creates an instance of a given "functional interface" type, whose + * single abstract method returns values of the type produced by the given + * generator. The arguments to the lambda's single method will be used to + * seed a random generator that will be used to generate the return value + * of that method.

+ * + *

junit-quickcheck uses this to create random values for property + * parameters whose type is determined to be a + * {@linkplain FunctionalInterface functional interface}. Custom generators + * for functional interface types can use this also.

+ * + * @param lambdaType a functional interface type token + * @param returnValueGenerator a generator for the return type of the + * functional interface's single method + * @param status an object to be passed along to the generator that will + * produce the functional interface's method return value + * @param the functional interface type token + * @param the type of the generated return value of the functional + * interface method + * @return an instance of the functional interface type, whose single + * method will return a generated value + * @throws IllegalArgumentException if {@code lambdaType} is not a + * functional interface type + */ + public static T makeLambda( + Class lambdaType, + org.utbot.quickcheck.generator.Generator returnValueGenerator, + GenerationStatus status) { + + if (singleAbstractMethodOf(lambdaType) == null) { + throw new IllegalArgumentException( + lambdaType + " is not a functional interface type"); + } + + return lambdaType.cast( + newProxyInstance( + lambdaType.getClassLoader(), + new Class[] { lambdaType }, + new LambdaInvocationHandler<>( + lambdaType, + returnValueGenerator, + status.attempts()))); + } + + private static class LambdaInvocationHandler + implements InvocationHandler { + + private final Class lambdaType; + private final org.utbot.quickcheck.generator.Generator returnValueGenerator; + private final int attempts; + private final DefaultMethodHandleMaker methodHandleMaker = + new DefaultMethodHandleMaker(); + + LambdaInvocationHandler( + Class lambdaType, + Generator returnValueGenerator, + Integer attempts) { + + this.lambdaType = lambdaType; + this.returnValueGenerator = returnValueGenerator; + this.attempts = attempts; + } + + @Override public Object invoke( + Object proxy, + Method method, + Object[] args) + throws Throwable { + + if (Object.class.equals(method.getDeclaringClass())) + return handleObjectMethod(proxy, method, args); + if (method.isDefault()) + return handleDefaultMethod(proxy, method, args); + + SourceOfRandomness source = new SourceOfRandomness(new Random()); + source.setSeed(Arrays.hashCode(args)); + GenerationStatus status = + new SimpleGenerationStatus( + new GeometricDistribution(), + source, + attempts); + return returnValueGenerator.generate(source, status); + } + + private Object handleObjectMethod( + Object proxy, + Method method, + Object[] args) { + + if ("equals".equals(method.getName())) + return proxy == args[0]; + + if ("hashCode".equals(method.getName())) + return identityHashCode(proxy); + + return handleToString(); + } + + private String handleToString() { + return "a randomly generated instance of " + lambdaType; + } + + private Object handleDefaultMethod( + Object proxy, + Method method, + Object[] args) + throws Throwable { + + MethodHandle handle = + methodHandleMaker.handleForSpecialMethod(method); + return handle.bindTo(proxy).invokeWithArguments(args); + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/NullAllowed.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/NullAllowed.java new file mode 100644 index 0000000000..6ee0e12c2c --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/NullAllowed.java @@ -0,0 +1,21 @@ +package org.utbot.quickcheck.generator; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + * method with this annotation to indicate that the parameter is nullable, and + * to optionally configure the probability of generating a null value.

+ */ +@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) +@Retention(RUNTIME) +public @interface NullAllowed { + /** + * @return probability of generating {@code null}, in the range [0,1] + */ + double probability() default 0.2; +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Only.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Only.java new file mode 100644 index 0000000000..c9bf61dabe --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Only.java @@ -0,0 +1,79 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.Property; +import org.utbot.quickcheck.conversion.StringConversion; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a parameter of a {@link Property} method with this annotation to + * limit the set of values of that parameter used to test the property.

+ * + *

In {@linkplain org.utbot.quickcheck.Mode#SAMPLING sampling} + * mode, on each trial junit-quickcheck chooses a value from the limited set + * at random with equal probability. + * + *

In {@linkplain org.utbot.quickcheck.Mode#EXHAUSTIVE exhaustive} + * mode, junit-quickcheck will use the values in the limited set for the + * property parameter, and no others.

+ * + *

Note: When a parameter is marked with this annotation, + * junit-quickcheck doesn't call upon any generators. Thus, it ignores any + * generator configuration annotations present on the parameter.

+ */ +@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) +@Retention(RUNTIME) +public @interface Only { + /** + * @return the values to which the property parameter should be limited + */ + String[] value(); + + /** + *

How to convert the values in {@link #value()} into instances of the + * property parameter's type.

+ * + *

If not specified, junit-quickcheck employs the following strategies + * for value conversion for the marked parameter:

+ *
    + *
  • If present, use a {@code public static} method on the property + * parameter type called {@code valueOf} which accepts a single + * {@code String} argument and whose return type is the type itself.
  • + *
  • Otherwise, if present, use a {@code public} constructor on the + * property parameter type which accepts a single {@code String} + * argument.
  • + *
+ * + * @return a type for a value conversion strategy + */ + Class by() default StringConversion.class; +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java new file mode 100644 index 0000000000..0ebb4f74a1 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java @@ -0,0 +1,50 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.GeneratorConfiguration; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + * method with this annotation to constrain the values generated for the + * parameter to a given precision.

+ */ +@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) +@Retention(RUNTIME) +@GeneratorConfiguration +public @interface Precision { + /** + * @return desired {@linkplain java.math.BigDecimal#scale() scale} of the + * generated values + */ + int scale(); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Shrink.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Shrink.java new file mode 100644 index 0000000000..c6b783b38c --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Shrink.java @@ -0,0 +1,47 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.List; + +/** + * Represents a strategy for producing objects "smaller than" a given object. + * + * @param type of shrunken objects produced + */ +@FunctionalInterface +public interface Shrink { + /** + * Gives some objects that are "smaller" than a given object. + * + * @param random source of randomness to use in shrinking, if desired + * @param larger the larger object + * @return objects that are "smaller" than the larger object + */ + List shrink(SourceOfRandomness random, Object larger); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java new file mode 100644 index 0000000000..fced0b8e00 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java @@ -0,0 +1,52 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.quickcheck.generator.GeneratorConfiguration; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + * method with this annotation to constrain the size of values generated for + * the parameter.

+ * + *

This annotation is recognized on array parameters and parameters of type + * {@link java.util.Collection#size() Collection} and {@link + * java.util.Map#size() Map}.

+ */ +@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) +@Retention(RUNTIME) +@GeneratorConfiguration +public @interface Size { + int min() default 0; + + int max(); +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java new file mode 100644 index 0000000000..b26b3f0d47 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java @@ -0,0 +1,57 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator; + +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.framework.plugin.api.UtNullModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import static java.util.Arrays.asList; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +/** + * Produces values for property parameters of type {@code void} or + * {@link Void}. + */ +public class VoidGenerator extends Generator { + public VoidGenerator() { + super(asList(Void.class, void.class)); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return new UtNullModel(classIdForType(Void.class)); + } + + @Override + public boolean canRegisterAsType(Class type) { + return !Object.class.equals(type); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java new file mode 100644 index 0000000000..bc0511c0e6 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java @@ -0,0 +1,123 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.internal.Lists; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getStringClassId; +import static org.utbot.quickcheck.internal.Lists.shrinksOfOneItem; +import static org.utbot.quickcheck.internal.Sequences.halving; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; + +/** + *

Base class for generators of values of type {@link String}.

+ * + *

The generated values will have {@linkplain String#length()} decided by + * {@link GenerationStatus#size()}.

+ */ +public abstract class AbstractStringGenerator extends Generator { + protected AbstractStringGenerator() { + super(String.class); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getStringClassId()); + } + + public String generateValue( SourceOfRandomness random, + GenerationStatus status){ + int[] codePoints = new int[status.size()]; + + for (int i = 0; i < codePoints.length; ++i) + codePoints[i] = nextCodePoint(random); + return new String(codePoints, 0, codePoints.length); + } + + @Override public boolean canShrink(Object larger) { + return super.canShrink(larger) && codePointsInRange((String) larger); + } + + @Override public List doShrink( + SourceOfRandomness random, + String larger) { + + List codePoints = + larger.codePoints().boxed().collect(toList()); + List shrinks = new ArrayList<>(removals(codePoints)); + + List> oneItemShrinks = + shrinksOfOneItem( + random, + codePoints, + new org.utbot.quickcheck.generator.java.lang.CodePointShrink(this::codePointInRange)); + shrinks.addAll( + oneItemShrinks.stream() + .map(this::convert) + .filter(this::codePointsInRange) + .collect(toList())); + + return shrinks; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value).length()); + } + + protected abstract int nextCodePoint(SourceOfRandomness random); + + protected abstract boolean codePointInRange(int codePoint); + + private boolean codePointsInRange(String s) { + return s.codePoints().allMatch(this::codePointInRange); + } + + private List removals(List codePoints) { + return stream(halving(codePoints.size()).spliterator(), false) + .map(i -> Lists.removeFrom(codePoints, i)) + .flatMap(Collection::stream) + .map(this::convert) + .collect(toList()); + } + + private String convert(List codePoints) { + StringBuilder s = new StringBuilder(); + codePoints.forEach(s::appendCodePoint); + return s.toString(); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java new file mode 100644 index 0000000000..6232d5233e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java @@ -0,0 +1,69 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.List; + +import static java.math.BigDecimal.ONE; +import static java.math.BigDecimal.ZERO; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; +import static org.utbot.framework.plugin.api.util.IdUtilKt.getBooleanWrapperClassId; + +/** + * Produces values of type {@code boolean} or {@link Boolean}. + */ +public class BooleanGenerator extends Generator { + public BooleanGenerator() { + super(singletonList(Boolean.class)); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextBoolean(), getBooleanWrapperClassId()); + } + + @Override public List doShrink( + SourceOfRandomness random, + Boolean larger) { + + return larger ? singletonList(false) : emptyList(); + } + + @Override public BigDecimal magnitude(Object value) { + return narrow(value) ? ONE : ZERO; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java new file mode 100644 index 0000000000..bf3bbe8f0f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java @@ -0,0 +1,107 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.IntegralGenerator; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code byte} or {@link Byte}. + */ +public class ByteGenerator extends IntegralGenerator { + private byte min = (Byte) defaultValueOf(InRange.class, "minByte"); + private byte max = (Byte) defaultValueOf(InRange.class, "maxByte"); + + public ByteGenerator() { + super(Collections.singletonList(Byte.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minByte()} and {@link InRange#maxByte()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minByte() + : Byte.parseByte(range.min()); + max = + range.max().isEmpty() + ? range.maxByte() + : Byte.parseByte(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextByte(min, max), classIdForType(Byte.class)); + } + + @Override protected Function narrow() { + return BigInteger::byteValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Byte leastMagnitude() { + return Comparables.leastMagnitude(min, max, (byte) 0); + } + + @Override protected boolean negative(Byte target) { + return target < 0; + } + + @Override protected Byte negate(Byte target) { + return (byte) -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java new file mode 100644 index 0000000000..9af11c314d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java @@ -0,0 +1,96 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getCharWrapperClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; +import static java.util.stream.Collectors.toList; + +/** + * Produces values of type {@code char} or {@link Character}. + */ +public class CharacterGenerator extends Generator { + private char min = (Character) defaultValueOf(InRange.class, "minChar"); + private char max = (Character) defaultValueOf(InRange.class, "maxChar"); + + public CharacterGenerator() { + super(Collections.singletonList(Character.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minChar()} and {@link InRange#maxChar()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = range.min().isEmpty() ? range.minChar() : range.min().charAt(0); + max = range.max().isEmpty() ? range.maxChar() : range.max().charAt(0); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextChar(min, max), getCharWrapperClassId()); + } + + @Override public List doShrink( + SourceOfRandomness random, + Character larger) { + + return new org.utbot.quickcheck.generator.java.lang.CodePointShrink(cp -> cp >= min && cp <= max) + .shrink(random, (int) larger) + .stream() + .map((Integer cp) -> (char) cp.intValue()) + .filter(this::inRange) + .collect(toList()); + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } + + private boolean inRange(Character value) { + return Comparables.inRange(min, max).test(value); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CodePointShrink.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CodePointShrink.java new file mode 100644 index 0000000000..af8df1237f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CodePointShrink.java @@ -0,0 +1,83 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.quickcheck.generator.Shrink; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; + +import static java.lang.Character.isUpperCase; +import static java.util.Collections.addAll; +import static java.util.Collections.reverse; +import static java.util.Comparator.comparing; +import static java.util.Comparator.naturalOrder; +import static java.util.stream.Collectors.toList; + +class CodePointShrink implements Shrink { + private final Predicate filter; + + CodePointShrink(Predicate filter) { + this.filter = filter; + } + + @Override public List shrink( + SourceOfRandomness random, + Object larger) { + + int codePoint = (Integer) larger; + + List shrinks = new ArrayList<>(); + addAll(shrinks, (int) 'a', (int) 'b', (int) 'c'); + if (isUpperCase(codePoint)) + shrinks.add(Character.toLowerCase(codePoint)); + addAll( + shrinks, + (int) 'A', (int) 'B', (int) 'C', (int) '1', (int) '2', (int) '3', + (int) ' ', (int) '\n'); + reverse(shrinks); + + Comparator comparator = + comparing((Function) Character::isLowerCase) + .thenComparing( + (Function) Character::isUpperCase) + .thenComparing( + (Function) Character::isDigit) + .thenComparing(cp -> Integer.valueOf(' ').equals(cp)) + .thenComparing( + (Function) Character::isSpaceChar) + .thenComparing(naturalOrder()); + return shrinks.stream() + .filter(filter) + .filter(cp -> comparator.compare(cp, codePoint) < 0) + .distinct() + .collect(toList()); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java new file mode 100644 index 0000000000..193a5748b6 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java @@ -0,0 +1,117 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.DecimalGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getDoubleWrapperClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values for property parameters of type {@code double} or + * {@link Double}. + */ +public class DoubleGenerator extends DecimalGenerator { + private double min = (Double) defaultValueOf(InRange.class, "minDouble"); + private double max = (Double) defaultValueOf(InRange.class, "maxDouble"); + + public DoubleGenerator() { + super(Collections.singletonList(Double.class)); + } + + /** + * Tells this generator to produce values within a specified minimum + * (inclusive) and/or maximum (exclusive) with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minDouble()} and {@link InRange#maxDouble()}, + * if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minDouble() + : Double.parseDouble(range.min()); + max = + range.max().isEmpty() + ? range.maxDouble() + : Double.parseDouble(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getDoubleWrapperClassId()); + } + + public double generateValue(SourceOfRandomness random, + GenerationStatus status) { + return random.nextDouble(min, max); + } + + @Override protected Function widen() { + return BigDecimal::valueOf; + } + + @Override protected Function narrow() { + return BigDecimal::doubleValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Double leastMagnitude() { + return Comparables.leastMagnitude(min, max, 0D); + } + + @Override protected boolean negative(Double target) { + return target < 0; + } + + @Override protected Double negate(Double target) { + return -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java new file mode 100644 index 0000000000..de4ea749b3 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java @@ -0,0 +1,83 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.quickcheck.generator.GeneratorConfiguration; +import org.utbot.quickcheck.generator.java.lang.AbstractStringGenerator; +import org.utbot.quickcheck.generator.java.lang.strings.CodePoints; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import java.nio.charset.Charset; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + *

Produces {@link String}s whose code points correspond to code points in + * a given {@link Charset} + * ({@link Charset#defaultCharset() by default}).

+ */ +public class Encoded extends AbstractStringGenerator { + private CodePoints charsetPoints; + + public Encoded() { + initialize(Charset.defaultCharset()); + } + + /** + * Tells this generator to emit strings in the given charset. + * + * @param charset a charset to use as the source for characters of + * generated strings + */ + public void configure(InCharset charset) { + initialize(Charset.forName(charset.value())); + } + + private void initialize(Charset charset) { + charsetPoints = CodePoints.forCharset(charset); + } + + @Override protected int nextCodePoint(SourceOfRandomness random) { + return charsetPoints.at(random.nextInt(0, charsetPoints.size() - 1)); + } + + @Override protected boolean codePointInRange(int codePoint) { + return charsetPoints.contains(codePoint); + } + + /** + * Names a {@link Charset}. + */ + @Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) + @Retention(RUNTIME) + @GeneratorConfiguration + public @interface InCharset { + String value(); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java new file mode 100644 index 0000000000..5bdf96bd4b --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java @@ -0,0 +1,109 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.DecimalGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getFloatWrapperClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code float} or {@link Float}. + */ +public class FloatGenerator extends DecimalGenerator { + private float min = (Float) defaultValueOf(InRange.class, "minFloat"); + private float max = (Float) defaultValueOf(InRange.class, "maxFloat"); + + public FloatGenerator() { + super(asList(Float.class)); + } + + /** + * Tells this generator to produce values within a specified minimum + * (inclusive) and/or maximum (exclusive) with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minFloat()} and {@link InRange#maxFloat()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minFloat() + : Float.parseFloat(range.min()); + max = + range.max().isEmpty() + ? range.maxFloat() + : Float.parseFloat(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextFloat(min, max), getFloatWrapperClassId()); + } + + @Override protected Function widen() { + return BigDecimal::valueOf; + } + + @Override protected Function narrow() { + return BigDecimal::floatValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Float leastMagnitude() { + return Comparables.leastMagnitude(min, max, 0F); + } + + @Override protected boolean negative(Float target) { + return target < 0; + } + + @Override protected Float negate(Float target) { + return -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java new file mode 100644 index 0000000000..a52daeb769 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java @@ -0,0 +1,111 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.IntegralGenerator; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getIntWrapperClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code int} or {@link Integer}. + */ +public class IntegerGenerator extends IntegralGenerator { + private int min = (Integer) defaultValueOf(InRange.class, "minInt"); + private int max = (Integer) defaultValueOf(InRange.class, "maxInt"); + + public IntegerGenerator() { + super(Collections.singletonList(Integer.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minInt()} and {@link InRange#maxInt()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minInt() + : Integer.parseInt(range.min()); + max = + range.max().isEmpty() + ? range.maxInt() + : Integer.parseInt(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getIntWrapperClassId()); + } + + public int generateValue(SourceOfRandomness random, + GenerationStatus status) { + return random.nextInt(min, max); + } + + @Override protected Function narrow() { + return BigInteger::intValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Integer leastMagnitude() { + return Comparables.leastMagnitude(min, max, 0); + } + + @Override protected boolean negative(Integer target) { + return target < 0; + } + + @Override protected Integer negate(Integer target) { + return -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java new file mode 100644 index 0000000000..f3cbeab966 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java @@ -0,0 +1,112 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.IntegralGenerator; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getLongWrapperClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code long} or {@link Long}. + */ +public class LongGenerator extends IntegralGenerator { + private long min = (Long) defaultValueOf(InRange.class, "minLong"); + private long max = (Long) defaultValueOf(InRange.class, "maxLong"); + + public LongGenerator() { + super(Collections.singletonList(Long.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minLong()} and {@link InRange#maxLong()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minLong() + : Long.parseLong(range.min()); + max = + range.max().isEmpty() + ? range.maxLong() + : Long.parseLong(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getLongWrapperClassId()); + } + + public long generateValue(SourceOfRandomness random, + GenerationStatus status) { + return random.nextLong(min, max); + } + + @Override protected Function narrow() { + return BigInteger::longValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Long leastMagnitude() { + return Comparables.leastMagnitude(min, max, 0L); + } + + @Override protected boolean negative(Long target) { + return target < 0; + } + + @Override protected Long negate(Long target) { + return -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java new file mode 100644 index 0000000000..8841df9bf0 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java @@ -0,0 +1,69 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.List; + +import static java.math.BigDecimal.ONE; +import static java.math.BigDecimal.ZERO; +import static java.util.Arrays.asList; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; +import static org.utbot.framework.plugin.api.util.IdUtilKt.getBooleanClassId; + +/** + * Produces values of type {@code boolean} or {@link Boolean}. + */ +public class PrimitiveBooleanGenerator extends Generator { + public PrimitiveBooleanGenerator() { + super(singletonList(boolean.class)); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextBoolean(), getBooleanClassId()); + } + + @Override public List doShrink( + SourceOfRandomness random, + Boolean larger) { + + return larger ? singletonList(false) : emptyList(); + } + + @Override public BigDecimal magnitude(Object value) { + return narrow(value) ? ONE : ZERO; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java new file mode 100644 index 0000000000..f6c6dda6f2 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java @@ -0,0 +1,107 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.IntegralGenerator; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getByteClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code byte} or {@link Byte}. + */ +public class PrimitiveByteGenerator extends IntegralGenerator { + private byte min = (Byte) defaultValueOf(InRange.class, "minByte"); + private byte max = (Byte) defaultValueOf(InRange.class, "maxByte"); + + public PrimitiveByteGenerator() { + super(Collections.singletonList(byte.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minByte()} and {@link InRange#maxByte()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minByte() + : Byte.parseByte(range.min()); + max = + range.max().isEmpty() + ? range.maxByte() + : Byte.parseByte(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextByte(min, max), getByteClassId()); + } + + @Override protected Function narrow() { + return BigInteger::byteValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Byte leastMagnitude() { + return Comparables.leastMagnitude(min, max, (byte) 0); + } + + @Override protected boolean negative(Byte target) { + return target < 0; + } + + @Override protected Byte negate(Byte target) { + return (byte) -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java new file mode 100644 index 0000000000..98cc15a85a --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java @@ -0,0 +1,96 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.List; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getCharClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; +import static java.util.stream.Collectors.toList; + +/** + * Produces values of type {@code char} or {@link Character}. + */ +public class PrimitiveCharGenerator extends Generator { + private char min = (Character) defaultValueOf(InRange.class, "minChar"); + private char max = (Character) defaultValueOf(InRange.class, "maxChar"); + + public PrimitiveCharGenerator() { + super(Collections.singletonList(char.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minChar()} and {@link InRange#maxChar()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = range.min().isEmpty() ? range.minChar() : range.min().charAt(0); + max = range.max().isEmpty() ? range.maxChar() : range.max().charAt(0); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextChar(min, max), getCharClassId()); + } + + @Override public List doShrink( + SourceOfRandomness random, + Character larger) { + + return new org.utbot.quickcheck.generator.java.lang.CodePointShrink(cp -> cp >= min && cp <= max) + .shrink(random, (int) larger) + .stream() + .map((Integer cp) -> (char) cp.intValue()) + .filter(this::inRange) + .collect(toList()); + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } + + private boolean inRange(Character value) { + return Comparables.inRange(min, max).test(value); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java new file mode 100644 index 0000000000..9b1deec5c9 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java @@ -0,0 +1,117 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.DecimalGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getDoubleClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values for property parameters of type {@code double} or + * {@link Double}. + */ +public class PrimitiveDoubleGenerator extends DecimalGenerator { + private double min = (Double) defaultValueOf(InRange.class, "minDouble"); + private double max = (Double) defaultValueOf(InRange.class, "maxDouble"); + + public PrimitiveDoubleGenerator() { + super(Collections.singletonList(double.class)); + } + + /** + * Tells this generator to produce values within a specified minimum + * (inclusive) and/or maximum (exclusive) with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minDouble()} and {@link InRange#maxDouble()}, + * if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minDouble() + : Double.parseDouble(range.min()); + max = + range.max().isEmpty() + ? range.maxDouble() + : Double.parseDouble(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getDoubleClassId()); + } + + public double generateValue(SourceOfRandomness random, + GenerationStatus status) { + return random.nextDouble(min, max); + } + + @Override protected Function widen() { + return BigDecimal::valueOf; + } + + @Override protected Function narrow() { + return BigDecimal::doubleValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Double leastMagnitude() { + return Comparables.leastMagnitude(min, max, 0D); + } + + @Override protected boolean negative(Double target) { + return target < 0; + } + + @Override protected Double negate(Double target) { + return -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java new file mode 100644 index 0000000000..9462188547 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java @@ -0,0 +1,110 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.DecimalGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getFloatClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code float} or {@link Float}. + */ +public class PrimitiveFloatGenerator extends DecimalGenerator { + private float min = (Float) defaultValueOf(InRange.class, "minFloat"); + private float max = (Float) defaultValueOf(InRange.class, "maxFloat"); + + public PrimitiveFloatGenerator() { + super(Collections.singletonList(float.class)); + } + + /** + * Tells this generator to produce values within a specified minimum + * (inclusive) and/or maximum (exclusive) with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minFloat()} and {@link InRange#maxFloat()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minFloat() + : Float.parseFloat(range.min()); + max = + range.max().isEmpty() + ? range.maxFloat() + : Float.parseFloat(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextFloat(min, max), getFloatClassId()); + } + + @Override protected Function widen() { + return BigDecimal::valueOf; + } + + @Override protected Function narrow() { + return BigDecimal::floatValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Float leastMagnitude() { + return Comparables.leastMagnitude(min, max, 0F); + } + + @Override protected boolean negative(Float target) { + return target < 0; + } + + @Override protected Float negate(Float target) { + return -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java new file mode 100644 index 0000000000..2e36e77eeb --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java @@ -0,0 +1,111 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.IntegralGenerator; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getIntClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code int} or {@link Integer}. + */ +public class PrimitiveIntGenerator extends IntegralGenerator { + private int min = (Integer) defaultValueOf(InRange.class, "minInt"); + private int max = (Integer) defaultValueOf(InRange.class, "maxInt"); + + public PrimitiveIntGenerator() { + super(Collections.singletonList(int.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minInt()} and {@link InRange#maxInt()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minInt() + : Integer.parseInt(range.min()); + max = + range.max().isEmpty() + ? range.maxInt() + : Integer.parseInt(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getIntClassId()); + } + + public int generateValue(SourceOfRandomness random, + GenerationStatus status) { + return random.nextInt(min, max); + } + + @Override protected Function narrow() { + return BigInteger::intValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Integer leastMagnitude() { + return Comparables.leastMagnitude(min, max, 0); + } + + @Override protected boolean negative(Integer target) { + return target < 0; + } + + @Override protected Integer negate(Integer target) { + return -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java new file mode 100644 index 0000000000..026a717ea4 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java @@ -0,0 +1,112 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.IntegralGenerator; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getLongClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code long} or {@link Long}. + */ +public class PrimitiveLongGenerator extends IntegralGenerator { + private long min = (Long) defaultValueOf(InRange.class, "minLong"); + private long max = (Long) defaultValueOf(InRange.class, "maxLong"); + + public PrimitiveLongGenerator() { + super(Collections.singletonList(long.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minLong()} and {@link InRange#maxLong()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minLong() + : Long.parseLong(range.min()); + max = + range.max().isEmpty() + ? range.maxLong() + : Long.parseLong(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getLongClassId()); + } + + public long generateValue(SourceOfRandomness random, + GenerationStatus status) { + return random.nextLong(min, max); + } + + @Override protected Function narrow() { + return BigInteger::longValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Long leastMagnitude() { + return Comparables.leastMagnitude(min, max, 0L); + } + + @Override protected boolean negative(Long target) { + return target < 0; + } + + @Override protected Long negate(Long target) { + return -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java new file mode 100644 index 0000000000..e886a03e06 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java @@ -0,0 +1,107 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.IntegralGenerator; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getShortClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code short} or {@link Short}. + */ +public class PrimitiveShortGenerator extends IntegralGenerator { + private short min = (Short) defaultValueOf(InRange.class, "minShort"); + private short max = (Short) defaultValueOf(InRange.class, "maxShort"); + + public PrimitiveShortGenerator() { + super(Collections.singletonList(short.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minShort()} and {@link InRange#maxShort()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minShort() + : Short.parseShort(range.min()); + max = + range.max().isEmpty() + ? range.maxShort() + : Short.parseShort(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextShort(min, max), getShortClassId()); + } + + @Override protected Function narrow() { + return BigInteger::shortValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Short leastMagnitude() { + return Comparables.leastMagnitude(min, max, (short) 0); + } + + @Override protected boolean negative(Short target) { + return target < 0; + } + + @Override protected Short negate(Short target) { + return (short) -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java new file mode 100644 index 0000000000..e47c69a2a8 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java @@ -0,0 +1,107 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.IntegralGenerator; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Collections; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getShortWrapperClassId; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.util.Arrays.asList; + +/** + * Produces values of type {@code short} or {@link Short}. + */ +public class ShortGenerator extends IntegralGenerator { + private short min = (Short) defaultValueOf(InRange.class, "minShort"); + private short max = (Short) defaultValueOf(InRange.class, "maxShort"); + + public ShortGenerator() { + super(Collections.singletonList(Short.class)); + } + + /** + * Tells this generator to produce values within a specified minimum and/or + * maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minShort()} and {@link InRange#maxShort()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + min = + range.min().isEmpty() + ? range.minShort() + : Short.parseShort(range.min()); + max = + range.max().isEmpty() + ? range.maxShort() + : Short.parseShort(range.max()); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextShort(min, max), getShortWrapperClassId()); + } + + @Override protected Function narrow() { + return BigInteger::shortValue; + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected Short leastMagnitude() { + return Comparables.leastMagnitude(min, max, (short) 0); + } + + @Override protected boolean negative(Short target) { + return target < 0; + } + + @Override protected Short negate(Short target) { + return (short) -target; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java new file mode 100644 index 0000000000..a71d01dd2d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java @@ -0,0 +1,43 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang; + +import org.utbot.quickcheck.generator.java.lang.AbstractStringGenerator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +/** + *

Produces {@link String}s whose characters are in the interval + * {@code [0x0000, 0xD7FF]}.

+ */ +public class StringGenerator extends AbstractStringGenerator { + @Override protected int nextCodePoint(SourceOfRandomness random) { + return random.nextInt(0, Character.MIN_SURROGATE - 1); + } + + @Override protected boolean codePointInRange(int codePoint) { + return codePoint >= 0 && codePoint < Character.MIN_SURROGATE; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java new file mode 100644 index 0000000000..e1e87c6674 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java @@ -0,0 +1,190 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.lang.strings; + +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static java.lang.String.format; + +/** + * Maps ordinal values to corresponding Unicode code points in a + * {@link Charset}. + */ +public class CodePoints { + private static final Map ENCODABLES = + new HashMap<>(); + + private final List ranges; + + CodePoints() { + ranges = new ArrayList<>(); + } + + /** + * @param index index to look up + * @return this code point set's {@code index}'th code point + * @throws IndexOutOfBoundsException if there is no such code point + */ + public int at(int index) { + if (index < 0) { + throw new IndexOutOfBoundsException( + "illegal negative index: " + index); + } + + int min = 0; + int max = ranges.size() - 1; + + while (min <= max) { + int midpoint = min + ((max - min) / 2); + CodePointRange current = ranges.get(midpoint); + + if (index >= current.previousCount + && index < current.previousCount + current.size()) { + + return current.low + index - current.previousCount; + } else if (index < current.previousCount) { + max = midpoint - 1; + } else { + min = midpoint + 1; + } + } + + throw new IndexOutOfBoundsException(String.valueOf(index)); + } + + /** + * @return how many code points are in this code point set + */ + public int size() { + if (ranges.isEmpty()) + return 0; + + CodePointRange last = ranges.get(ranges.size() - 1); + return last.previousCount + last.size(); + } + + /** + * @param codePoint a code point + * @return whether this code point set contains the given code point + */ + public boolean contains(int codePoint) { + return ranges.stream().anyMatch(r -> r.contains(codePoint)); + } + + /** + * Gives a set of the code points in the given charset. + * + * @param c a charset + * @return the set of code points in the charset + */ + public static CodePoints forCharset(Charset c) { + if (ENCODABLES.containsKey(c)) + return ENCODABLES.get(c); + + CodePoints points = load(c); + ENCODABLES.put(c, points); + return points; + } + + private static CodePoints load(Charset c) { + if (!c.canEncode()) { + throw new IllegalArgumentException( + "Charset " + c.name() + " does not support encoding"); + } + + return encodableCodePoints(c.newEncoder()); + } + + void add(CodePointRange range) { + ranges.add(range); + } + + private static CodePoints encodableCodePoints(CharsetEncoder encoder) { + CodePoints points = new CodePoints(); + + int start = 0; + boolean inRange = false; + int current = 0; + int previousCount = 0; + int[] buffer = new int[1]; + + for (; current <= Character.MAX_CODE_POINT; ++current) { + encoder.reset(); + buffer[0] = current; + + String s = new String(buffer, 0, 1); + if (encoder.canEncode(s)) { + if (!inRange) { + inRange = true; + start = current; + } + } else if (inRange) { + inRange = false; + CodePointRange range = + new CodePointRange(start, current - 1, previousCount); + points.add(range); + previousCount += range.size(); + } + } + + if (inRange) { + points.add( + new CodePointRange(start, current - 1, previousCount)); + } + + return points; + } + + static class CodePointRange { + final int low; + final int high; + final int previousCount; + + CodePointRange(int low, int high, int previousCount) { + if (low > high) { + throw new IllegalArgumentException( + format("%d > %d", low, high)); + } + + this.low = low; + this.high = high; + this.previousCount = previousCount; + } + + boolean contains(int codePoint) { + return codePoint >= low && codePoint <= high; + } + + int size() { + return high - low + 1; + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java new file mode 100644 index 0000000000..038652e846 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java @@ -0,0 +1,190 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.math; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.DecimalGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.Precision; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.internal.Ranges; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Ranges.checkRange; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.lang.Math.max; +import static java.math.BigDecimal.TEN; +import static java.math.BigDecimal.ZERO; +import static java.util.function.Function.identity; + +/** + *

Produces values of type {@link BigDecimal}.

+ * + *

With no additional configuration, the generated values are chosen from + * a range with a magnitude decided by + * {@link GenerationStatus#size()}.

+ */ +public class BigDecimalGenerator extends DecimalGenerator { + private BigDecimal min; + private BigDecimal max; + private Precision precision; + + public BigDecimalGenerator() { + super(BigDecimal.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} (inclusive) and/or + * {@linkplain InRange#max() maximum} (exclusive), with uniform + * distribution.

+ * + *

If an endpoint of the range is not specified, its value takes on + * a magnitude influenced by + * {@link GenerationStatus#size()}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = new BigDecimal(range.min()); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = new BigDecimal(range.max()); + + if (min != null && max != null) + checkRange(Ranges.Type.FLOAT, min, max); + } + + /** + *

Tells this generator to produce values that have a specified + * {@linkplain Precision#scale() scale}.

+ * + *

With no precision constraint and no {@linkplain #configure(InRange) + * min/max constraint}, the scale of the generated values is + * unspecified.

+ * + *

Otherwise, the scale of the generated values is set as + * {@code max(0, precision.scale, range.min.scale, range.max.scale)}.

+ * + * @param configuration annotation that gives the desired scale of the + * generated values + */ + public void configure(Precision configuration) { + precision = configuration; + } + + @Override + public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + BigDecimal minToUse = min; + BigDecimal maxToUse = max; + int power = status.size() + 1; + + if (minToUse == null && maxToUse == null) { + maxToUse = TEN.pow(power); + minToUse = maxToUse.negate(); + } + + if (minToUse == null) + minToUse = maxToUse.subtract(TEN.pow(power)); + else if (maxToUse == null) + maxToUse = minToUse.add(TEN.pow(power)); + + int scale = decideScale(); + + BigDecimal minShifted = minToUse.movePointRight(scale); + BigDecimal maxShifted = maxToUse.movePointRight(scale); + BigInteger range = + maxShifted.toBigInteger().subtract(minShifted.toBigInteger()); + + BigInteger generated; + do { + generated = random.nextBigInteger(range.bitLength()); + } while (generated.compareTo(range) >= 0); + + + return UtModelGenerator.getUtModelConstructor().construct(minShifted.add(new BigDecimal(generated)) + .movePointLeft(scale), classIdForType(BigDecimal.class)); + } + + private int decideScale() { + int scale = Integer.MIN_VALUE; + + if (min != null) + scale = max(scale, min.scale()); + if (max != null) + scale = max(scale, max.scale()); + if (precision != null) + scale = max(scale, precision.scale()); + + return max(scale, 0); + } + + @Override + protected Function widen() { + return identity(); + } + + @Override + protected Function narrow() { + return identity(); + } + + @Override + protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override + protected BigDecimal leastMagnitude() { + return Comparables.leastMagnitude(min, max, ZERO); + } + + @Override + protected boolean negative(BigDecimal target) { + return target.signum() < 0; + } + + @Override + protected BigDecimal negate(BigDecimal target) { + return target.negate(); + } + + @Override + public BigDecimal magnitude(Object value) { + return narrow(value); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java new file mode 100644 index 0000000000..b9ad104f8c --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java @@ -0,0 +1,127 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.math; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.IntegralGenerator; +import org.utbot.quickcheck.internal.Comparables; +import org.utbot.quickcheck.internal.Ranges; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.function.Function; +import java.util.function.Predicate; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Ranges.checkRange; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import static java.math.BigInteger.TEN; +import static java.math.BigInteger.ZERO; +import static java.util.function.Function.identity; + +/** + *

Produces values of type {@link BigInteger}.

+ * + *

With no additional configuration, the generated values are chosen from + * a range with a magnitude decided by + * {@link GenerationStatus#size()}.

+ */ +public class BigIntegerGenerator extends IntegralGenerator { + private BigInteger min; + private BigInteger max; + + public BigIntegerGenerator() { + super(BigInteger.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or + * {@linkplain InRange#max() maximum} inclusive, with uniform + * distribution.

+ * + *

If an endpoint of the range is not specified, its value takes on + * a magnitude influenced by + * {@link GenerationStatus#size()}.

+ + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = new BigInteger(range.min()); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = new BigInteger(range.max()); + if (min != null && max != null) + checkRange(Ranges.Type.INTEGRAL, min, max); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + int numberOfBits = status.size() + 1; + + if (min == null && max == null) + return UtModelGenerator.getUtModelConstructor().construct(random.nextBigInteger(numberOfBits), classIdForType(BigInteger.class)); + + BigInteger minToUse = min; + BigInteger maxToUse = max; + if (minToUse == null) + minToUse = maxToUse.subtract(TEN.pow(numberOfBits)); + else if (maxToUse == null) + maxToUse = minToUse.add(TEN.pow(numberOfBits)); + + return UtModelGenerator.getUtModelConstructor().construct(Ranges.choose(random, minToUse, maxToUse), classIdForType(BigInteger.class)); + } + + @Override protected Function narrow() { + return identity(); + } + + @Override protected Predicate inRange() { + return Comparables.inRange(min, max); + } + + @Override protected BigInteger leastMagnitude() { + return Comparables.leastMagnitude(min, max, ZERO); + } + + @Override protected boolean negative(BigInteger target) { + return target.signum() < 0; + } + + @Override protected BigInteger negate(BigInteger target) { + return target.negate(); + } + + @Override public BigDecimal magnitude(Object value) { + return new BigDecimal(narrow(value)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java new file mode 100644 index 0000000000..8525796a48 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java @@ -0,0 +1,85 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.nio.charset; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.concrete.UtModelConstructor; +import org.utbot.framework.plugin.api.*; +import org.utbot.framework.plugin.api.util.IdUtilKt; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.reflect.Method; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import static java.nio.charset.Charset.availableCharsets; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.framework.plugin.api.util.IdUtilKt.getStringClassId; + +/** + * Produces values of type {@link Charset}. + */ +public class CharsetGenerator extends Generator { + public CharsetGenerator() { + super(Charset.class); + } + + @Override + public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); + + final String charsetName = random.choose(availableCharsets().keySet()); + final UtModel charsetNameModel = modelConstructor.construct(charsetName, getStringClassId()); + + final Method charsetForName; + try { + charsetForName = Charset.class.getMethod("forName", String.class); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + final ClassId charsetClassId = classIdForType(Charset.class); + final ExecutableId charsetForNameId = IdUtilKt.getExecutableId(charsetForName); + + final int modelId = modelConstructor.computeUnusedIdAndUpdate(); + + return new UtAssembleModel( + modelId, + charsetClassId, + charsetForNameId.getName() + "#" + modelId, + new UtExecutableCallModel(null, charsetForNameId, List.of(charsetNameModel)), + null, + (a) -> List.of() + ); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java new file mode 100644 index 0000000000..404548d412 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java @@ -0,0 +1,123 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.concrete.UtModelConstructor; +import org.utbot.framework.plugin.api.*; +import org.utbot.framework.plugin.api.util.IdUtilKt; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.reflect.Method; +import java.time.Clock; +import java.time.Instant; +import java.time.ZoneId; +import java.util.ArrayList; +import java.util.List; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link Clock}. + */ +public class ClockGenerator extends Generator { + private static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); + + private Instant min = Instant.MIN; + private Instant max = Instant.MAX; + + public ClockGenerator() { + super(Clock.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution, down to the + * nanosecond.

+ * + *

Instances of this class are configured using {@link Instant} + * strings.

+ * + *

If an endpoint of the range is not specified, the generator will use + * instants with values of either {@link Instant#MIN} or + * {@link Instant#MAX} as appropriate.

+ * + *

{@linkplain InRange#format()} is ignored. Instants are always + * parsed using {@link java.time.format.DateTimeFormatter#ISO_INSTANT}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = Instant.parse(range.min()); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = Instant.parse(range.max()); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override + public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + final Instant instant = random.nextInstant(min, max); + final ZoneId zoneId = UTC_ZONE_ID; + + final Method clockFixed; + try { + clockFixed = Clock.class.getMethod("fixed", Instant.class, ZoneId.class); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + + final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); + final UtModel instantModel = modelConstructor.construct(instant, classIdForType(Instant.class)); + final UtModel zoneIdModel = modelConstructor.construct(zoneId, classIdForType(ZoneId.class)); + + final ClassId classId = classIdForType(Clock.class); + final ExecutableId constructorId = IdUtilKt.getExecutableId(clockFixed); + + final int modelId = modelConstructor.computeUnusedIdAndUpdate(); + + return new UtAssembleModel( + modelId, + classId, + constructorId.getName() + "#" + modelId, + new UtExecutableCallModel(null, constructorId, List.of(instantModel, zoneIdModel)), + null, + (a) -> List.of() + ); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java new file mode 100644 index 0000000000..93c861126c --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java @@ -0,0 +1,84 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.Duration; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link Duration}. + */ +public class DurationGenerator extends Generator { + private Duration min = Duration.ofSeconds(Long.MIN_VALUE, 0); + private Duration max = Duration.ofSeconds(Long.MAX_VALUE, 999_999_999); + + public DurationGenerator() { + super(Duration.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution, down to the + * nanosecond.

+ * + *

If an endpoint of the range is not specified, the generator will use + * durations with second values of either {@link Long#MIN_VALUE} or + * {@link Long#MAX_VALUE} (with nanoseconds set to 999,999,999) as + * appropriate.

+ * + *

{@linkplain InRange#format()} is ignored. Durations are always + * parsed using formats based on the ISO-8601 duration format + * {@code PnDTnHnMn.nS} with days considered to be exactly 24 hours. + * + * @see Duration#parse(CharSequence) + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = Duration.parse(range.min()); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = Duration.parse(range.max()); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate(SourceOfRandomness random, GenerationStatus status) { + return UtModelGenerator.getUtModelConstructor().construct(random.nextDuration(min, max), classIdForType(Duration.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java new file mode 100644 index 0000000000..1bc4285643 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java @@ -0,0 +1,84 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.Instant; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link Instant}. + */ +public class InstantGenerator extends Generator { + private Instant min = Instant.MIN; + private Instant max = Instant.MAX; + + public InstantGenerator() { + super(Instant.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution, down to the + * nanosecond.

+ * + *

If an endpoint of the range is not specified, the generator will use + * instants with values of either {@link Instant#MIN} or + * {@link Instant#MAX} as appropriate.

+ * + *

{@linkplain InRange#format()} is ignored. Instants are always + * parsed using {@link java.time.format.DateTimeFormatter#ISO_INSTANT}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = Instant.parse(range.min()); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = Instant.parse(range.max()); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.nextInstant(min, max), classIdForType(Instant.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java new file mode 100644 index 0000000000..bd03487e1d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java @@ -0,0 +1,89 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.LocalDate; +import java.time.format.DateTimeFormatter; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link LocalDate}. + */ +public class LocalDateGenerator extends Generator { + private LocalDate min = LocalDate.MIN; + private LocalDate max = LocalDate.MAX; + + public LocalDateGenerator() { + super(LocalDate.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution.

+ * + *

If an endpoint of the range is not specified, the generator will use + * dates with values of either {@link LocalDate#MIN} or + * {@link LocalDate#MAX} as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern(range.format()); + + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = LocalDate.parse(range.min(), formatter); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = LocalDate.parse(range.max(), formatter); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(LocalDate.ofEpochDay( + random.nextLong(min.toEpochDay(), max.toEpochDay())), classIdForType(LocalDate.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java new file mode 100644 index 0000000000..f41d4e03f9 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java @@ -0,0 +1,98 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link LocalDateTime}. + */ +public class LocalDateTimeGenerator extends Generator { + private static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); + + private LocalDateTime min = LocalDateTime.MIN; + private LocalDateTime max = LocalDateTime.MAX; + + public LocalDateTimeGenerator() { + super(LocalDateTime.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution, down to the + * nanosecond.

+ * + *

If an endpoint of the range is not specified, the generator will use + * dates with values of either {@link LocalDateTime#MIN} or + * {@link LocalDateTime#MAX} as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern(range.format()); + + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = LocalDateTime.parse(range.min(), formatter); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = LocalDateTime.parse(range.max(), formatter); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + /* Project the LocalDateTime to an Instant for easy long-based generation. + Any zone id will do as long as we use the same one throughout. */ + return UtModelGenerator.getUtModelConstructor().construct(LocalDateTime.ofInstant( + random.nextInstant( + min.atZone(UTC_ZONE_ID).toInstant(), + max.atZone(UTC_ZONE_ID).toInstant()), + UTC_ZONE_ID), classIdForType(LocalDateTime.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java new file mode 100644 index 0000000000..85f9e561eb --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java @@ -0,0 +1,90 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.LocalTime; +import java.time.format.DateTimeFormatter; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link LocalTime}. + */ +public class LocalTimeGenerator extends Generator { + private LocalTime min = LocalTime.MIN; + private LocalTime max = LocalTime.MAX; + + public LocalTimeGenerator() { + super(LocalTime.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution, down to the + * nanosecond.

+ * + *

If an endpoint of the range is not specified, the generator will use + * times with values of either {@link LocalTime#MIN} or + * {@link LocalTime#MAX} as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern(range.format()); + + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = LocalTime.parse(range.min(), formatter); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = LocalTime.parse(range.max(), formatter); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(LocalTime.ofNanoOfDay( + random.nextLong(min.toNanoOfDay(), max.toNanoOfDay())), classIdForType(LocalTime.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java new file mode 100644 index 0000000000..c906345170 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java @@ -0,0 +1,96 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.LocalDate; +import java.time.MonthDay; +import java.time.format.DateTimeFormatter; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link MonthDay}. + */ +public class MonthDayGenerator extends Generator { + private MonthDay min = MonthDay.of(1, 1); + private MonthDay max = MonthDay.of(12, 31); + + public MonthDayGenerator() { + super(MonthDay.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution.

+ * + *

If an endpoint of the range is not specified, the generator will use + * dates with values of either {@code MonthDay(1, 1)} or + * {@code MonthDay(12, 31)} as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern(range.format()); + + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = MonthDay.parse(range.min(), formatter); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = MonthDay.parse(range.max(), formatter); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + /* Project the MonthDay to a LocalDate for easy long-based generation. + Any leap year will do here. */ + long minEpochDay = min.atYear(2000).toEpochDay(); + long maxEpochDay = max.atYear(2000).toEpochDay(); + LocalDate date = + LocalDate.ofEpochDay(random.nextLong(minEpochDay, maxEpochDay)); + + return UtModelGenerator.getUtModelConstructor().construct(MonthDay.of(date.getMonthValue(), date.getDayOfMonth()), classIdForType(MonthDay.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java new file mode 100644 index 0000000000..aa2fef9393 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java @@ -0,0 +1,95 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.OffsetDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link OffsetDateTime}. + */ +public class OffsetDateTimeGenerator extends Generator { + private static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); + + private OffsetDateTime min = OffsetDateTime.MIN; + private OffsetDateTime max = OffsetDateTime.MAX; + + public OffsetDateTimeGenerator() { + super(OffsetDateTime.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution, down to the + * nanosecond.

+ * + *

If an endpoint of the range is not specified, the generator will use + * dates with values of either {@link OffsetDateTime#MIN} or + * {@link OffsetDateTime#MAX} as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern(range.format()); + + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = OffsetDateTime.parse(range.min(), formatter); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = OffsetDateTime.parse(range.max(), formatter); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + // Project the OffsetDateTime to an Instant for easy long-based generation. + return UtModelGenerator.getUtModelConstructor().construct(OffsetDateTime.ofInstant( + random.nextInstant(min.toInstant(), max.toInstant()), + UTC_ZONE_ID), classIdForType(OffsetDateTime.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java new file mode 100644 index 0000000000..8768ec4da1 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java @@ -0,0 +1,101 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.LocalTime; +import java.time.OffsetTime; +import java.time.ZoneOffset; +import java.time.format.DateTimeFormatter; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link OffsetTime}. + */ +public class OffsetTimeGenerator extends Generator { + private OffsetTime min = OffsetTime.MIN; + private OffsetTime max = OffsetTime.MAX; + + public OffsetTimeGenerator() { + super(OffsetTime.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution, down to the + * nanosecond.

+ * + *

If an endpoint of the range is not specified, the generator will use + * times with values of either {@link OffsetTime#MIN} or + * {@link OffsetTime#MAX} as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern(range.format()); + + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = OffsetTime.parse(range.min(), formatter); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = OffsetTime.parse(range.max(), formatter); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + LocalTime time = + LocalTime.ofNanoOfDay( + random.nextLong( + min.withOffsetSameInstant(ZoneOffset.UTC) + .toLocalTime() + .toNanoOfDay(), + max.withOffsetSameInstant(ZoneOffset.UTC) + .toLocalTime() + .toNanoOfDay())); + + return UtModelGenerator.getUtModelConstructor().construct(OffsetTime.of(time, ZoneOffset.UTC), classIdForType(OffsetTime.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java new file mode 100644 index 0000000000..70b741bd55 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java @@ -0,0 +1,112 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.internal.Ranges; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigInteger; +import java.time.Period; +import java.time.Year; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link Period}. + */ +public class PeriodGenerator extends Generator { + private static final BigInteger TWELVE = BigInteger.valueOf(12); + private static final BigInteger THIRTY_ONE = BigInteger.valueOf(31); + + private Period min = Period.of(Year.MIN_VALUE, -12, -31); + private Period max = Period.of(Year.MAX_VALUE, 12, 31); + + public PeriodGenerator() { + super(Period.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution.

+ * + *

If an endpoint of the range is not specified, the generator will use + * Periods with values of either {@code Period(Year#MIN_VALUE, -12, -31)} + * or {@code Period(Year#MAX_VALUE, 12, 31)} as appropriate.

+ * + *

{@linkplain InRange#format()} is ignored. Periods are always parsed + * using formats based on the ISO-8601 period formats {@code PnYnMnD} and + * {@code PnW}.

+ * + * @see Period#parse(CharSequence) + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = Period.parse(range.min()); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = Period.parse(range.max()); + + if (toBigInteger(min).compareTo(toBigInteger(max)) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(fromBigInteger( + Ranges.choose(random, toBigInteger(min), toBigInteger(max))), classIdForType(Period.class)); + } + + private BigInteger toBigInteger(Period period) { + return BigInteger.valueOf(period.getYears()) + .multiply(TWELVE) + .add(BigInteger.valueOf(period.getMonths())) + .multiply(THIRTY_ONE) + .add(BigInteger.valueOf(period.getDays())); + } + + private Period fromBigInteger(BigInteger period) { + BigInteger[] monthsAndDays = + period.divideAndRemainder(THIRTY_ONE); + BigInteger[] yearsAndMonths = + monthsAndDays[0].divideAndRemainder(TWELVE); + + return Period.of( + yearsAndMonths[0].intValueExact(), + yearsAndMonths[1].intValueExact(), + monthsAndDays[1].intValueExact()); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java new file mode 100644 index 0000000000..7b8a043475 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java @@ -0,0 +1,88 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.Year; +import java.time.format.DateTimeFormatter; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link Year}. + */ +public class YearGenerator extends Generator { + private Year min = Year.of(Year.MIN_VALUE); + private Year max = Year.of(Year.MAX_VALUE); + + public YearGenerator() { + super(Year.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution.

+ * + *

If an endpoint of the range is not specified, the generator will use + * Years with values of either {@code Year#MIN_VALUE} or + * {@code Year#MAX_VALUE} as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern(range.format()); + + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = Year.parse(range.min(), formatter); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = Year.parse(range.max(), formatter); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(Year.of(random.nextInt(min.getValue(), max.getValue())), classIdForType(Year.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java new file mode 100644 index 0000000000..8ae4870667 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java @@ -0,0 +1,96 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.Year; +import java.time.YearMonth; +import java.time.format.DateTimeFormatter; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link YearMonth}. + */ +public class YearMonthGenerator extends Generator { + private YearMonth min = YearMonth.of(Year.MIN_VALUE, 1); + private YearMonth max = YearMonth.of(Year.MAX_VALUE, 12); + + public YearMonthGenerator() { + super(YearMonth.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution.

+ * + *

If an endpoint of the range is not specified, the generator will use + * dates with values of either {@code YearMonth(Year#MIN_VALUE, 1)} or + * {@code YearMonth(Year#MAX_VALUE, 12)} as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern(range.format()); + + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = YearMonth.parse(range.min(), formatter); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = YearMonth.parse(range.max(), formatter); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + long generated = + random.nextLong( + min.getYear() * 12L + min.getMonthValue() - 1, + max.getYear() * 12L + max.getMonthValue() - 1); + + return UtModelGenerator.getUtModelConstructor().construct(YearMonth.of( + (int) (generated / 12), + (int) Math.abs(generated % 12) + 1), classIdForType(YearMonth.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java new file mode 100644 index 0000000000..eba2bfcd9e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java @@ -0,0 +1,53 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.ZoneId; + +import static java.time.ZoneId.getAvailableZoneIds; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +/** + * Produces values of type {@link ZoneId}. + */ +public class ZoneIdGenerator extends Generator { + public ZoneIdGenerator() { + super(ZoneId.class); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(ZoneId.of(random.choose(getAvailableZoneIds())), classIdForType(ZoneId.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java new file mode 100644 index 0000000000..12f8172272 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java @@ -0,0 +1,93 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.ZoneOffset; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link ZoneOffset}. + */ +public class ZoneOffsetGenerator extends Generator { + /* The way ZoneOffsets work, ZoneOffset.MAX (-18:00) is actually + the lower end of the seconds range, whereas ZoneOffset.MIN (+18:00) + is the upper end. */ + private ZoneOffset min = ZoneOffset.MAX; + private ZoneOffset max = ZoneOffset.MIN; + + public ZoneOffsetGenerator() { + super(ZoneOffset.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution.

+ * + *

If an endpoint of the range is not specified, the generator will use + * ZoneOffsets with values of either {@code ZoneOffset#MIN} or + * {@code ZoneOffset#MAX} as appropriate.

+ * + *

{@linkplain InRange#format()} is ignored. ZoneOffsets are always + * parsed using their zone id.

+ * + * @see ZoneOffset#of(String) + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = ZoneOffset.of(range.min()); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = ZoneOffset.of(range.max()); + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + int minSeconds = min.getTotalSeconds(); + int maxSeconds = max.getTotalSeconds(); + + return UtModelGenerator.getUtModelConstructor().construct(ZoneOffset.ofTotalSeconds( + (minSeconds <= maxSeconds) + ? random.nextInt(minSeconds, maxSeconds) + : random.nextInt(maxSeconds, minSeconds)), classIdForType(ZoneOffset.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java new file mode 100644 index 0000000000..2033f8a3bc --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java @@ -0,0 +1,106 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.time; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.time.Year; +import java.time.ZoneId; +import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link ZonedDateTime}. + */ +public class ZonedDateTimeGenerator extends Generator { + private static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); + + private ZonedDateTime min = + ZonedDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, UTC_ZONE_ID); + private ZonedDateTime max = + ZonedDateTime.of( + Year.MAX_VALUE, 12, 31, 23, 59, 59, 999_999_999, UTC_ZONE_ID); + + public ZonedDateTimeGenerator() { + super(ZonedDateTime.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution, down to the + * nanosecond.

+ * + *

If an endpoint of the range is not specified, the generator will use + * dates with values of either {@link java.time.Instant#MIN} or + * {@link java.time.Instant#MAX} and UTC zone as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + DateTimeFormatter formatter = + DateTimeFormatter.ofPattern(range.format()); + + if (!defaultValueOf(InRange.class, "min").equals(range.min())) { + min = + ZonedDateTime.parse(range.min(), formatter) + .withZoneSameInstant(UTC_ZONE_ID); + } + if (!defaultValueOf(InRange.class, "max").equals(range.max())) { + max = + ZonedDateTime.parse(range.max(), formatter) + .withZoneSameInstant(UTC_ZONE_ID); + } + + if (min.compareTo(max) > 0) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + // Project the ZonedDateTime to an Instant for easy long-based + // generation. + return UtModelGenerator.getUtModelConstructor().construct(ZonedDateTime.ofInstant( + random.nextInstant(min.toInstant(), max.toInstant()), + UTC_ZONE_ID), classIdForType(ZonedDateTime.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java new file mode 100644 index 0000000000..7b946bead3 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java @@ -0,0 +1,41 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.ListGenerator; + +import java.util.ArrayList; + +/** + * Produces values of type {@link ArrayList}. + */ +public class ArrayListGenerator extends ListGenerator { + public ArrayListGenerator() { + super(ArrayList.class); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java new file mode 100644 index 0000000000..38d981273f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java @@ -0,0 +1,93 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.BitSet; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.stream.Collectors.toList; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +/** + * Produces values of type {@link BitSet}. + */ +public class BitSetGenerator extends Generator { + public BitSetGenerator() { + super(BitSet.class); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + int size = status.size(); + + BitSet bits = new BitSet(size); + for (int i = 0; i < size; ++i) { + bits.set(i, random.nextBoolean()); + } + + return UtModelGenerator.getUtModelConstructor().construct(bits, classIdForType(BitSet.class)); + } + + @Override public List doShrink( + SourceOfRandomness random, + BitSet larger) { + + if (larger.length() == 0) + return emptyList(); + + List shrinks = new ArrayList<>(); + shrinks.addAll( + larger.stream() + .mapToObj(i -> larger.get(0, i)) + .collect(toList())); + shrinks.addAll( + larger.stream() + .mapToObj(i -> { + BitSet smaller = (BitSet) larger.clone(); + smaller.clear(i); + return smaller; + }) + .collect(toList())); + + return shrinks; + } + + @Override public BigDecimal magnitude(Object value) { + return BigDecimal.valueOf(narrow(value).size()); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java new file mode 100644 index 0000000000..fe5375f810 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java @@ -0,0 +1,231 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.concrete.UtModelConstructor; +import org.utbot.framework.plugin.api.*; + +import org.utbot.framework.plugin.api.util.IdUtilKt; +import org.utbot.quickcheck.generator.*; +import org.utbot.quickcheck.internal.Lists; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Stream; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; +import static org.utbot.quickcheck.internal.Lists.removeFrom; +import static org.utbot.quickcheck.internal.Lists.shrinksOfOneItem; +import static org.utbot.quickcheck.internal.Ranges.Type.INTEGRAL; +import static org.utbot.quickcheck.internal.Ranges.checkRange; +import static org.utbot.quickcheck.internal.Reflection.findConstructor; +import static org.utbot.quickcheck.internal.Reflection.instantiate; +import static org.utbot.quickcheck.internal.Sequences.halving; +import static java.math.BigDecimal.ZERO; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; + +/** + *

Base class for generators of {@link Collection}s.

+ * + *

The generated collection has a number of elements limited by + * {@link GenerationStatus#size()}, or else by the attributes of a {@link Size} + * marking. The individual elements will have a type corresponding to the + * collection's type argument.

+ * + * @param the type of collection generated + */ +public abstract class CollectionGenerator + extends ComponentizedGenerator { + + private Size sizeRange; + private boolean distinct; + + protected CollectionGenerator(Class type) { + super(type); + } + + /** + *

Tells this generator to add elements to the generated collection + * a number of times within a specified minimum and/or maximum, inclusive, + * chosen with uniform distribution.

+ * + *

Note that some kinds of collections disallow duplicates, so the + * number of elements added may not be equal to the collection's + * {@link Collection#size()}.

+ * + * @param size annotation that gives the size constraints + */ + public void configure(Size size) { + this.sizeRange = size; + checkRange(INTEGRAL, size.min(), size.max()); + } + + /** + * Tells this generator to add elements which are distinct from each other. + * + * @param distinct Generated elements will be distinct if this param is + * not null + */ + public void configure(Distinct distinct) { + setDistinct(distinct != null); + } + + protected final void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + @SuppressWarnings("unchecked") + @Override + public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + +// UtCompositeModel res = new UtCompositeModel( +// +// ) + UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); + Class collectionType = types().get(0); + ClassId collectionClassId = classIdForType(collectionType); + ExecutableId collectionConstructorId = new ConstructorId(collectionClassId, new ArrayList<>()); + int genId = modelConstructor.computeUnusedIdAndUpdate(); + + + UtAssembleModel collectionAssembleModel = new UtAssembleModel( + genId, + collectionClassId, + collectionConstructorId.getName() + "#" + genId, + new UtExecutableCallModel(null, collectionConstructorId, List.of()), + null, + (a) -> { + ArrayList modificationChain = new ArrayList<>(); + int size = size(random, status); + + Generator generator = componentGenerators().get(0); + Method m; + try { + m = Collection.class.getMethod("add", Object.class); + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + MethodId methodId = IdUtilKt.getExecutableId(m); + + //java.util.Collections::class.java.methodCall + for (int i = 0; i < size; ++i) { + UtModel item = generator.generate(random, status); + modificationChain.add(new UtExecutableCallModel(a, methodId, List.of(item))); + } + return modificationChain; + } + ); + + return collectionAssembleModel; + } + + @Override + public List doShrink(SourceOfRandomness random, T larger) { + @SuppressWarnings("unchecked") + List asList = new ArrayList<>(larger); + + List shrinks = new ArrayList<>(removals(asList)); + + @SuppressWarnings("unchecked") + Shrink generator = + (Shrink) componentGenerators().get(0); + + Stream> oneItemShrinks = + shrinksOfOneItem(random, asList, generator) + .stream(); + if (distinct) + oneItemShrinks = oneItemShrinks.filter(Lists::isDistinct); + + shrinks.addAll( + oneItemShrinks + .map(this::convert) + .filter(this::inSizeRange) + .collect(toList())); + + return shrinks; + } + + @Override + public int numberOfNeededComponents() { + return 1; + } + + @Override + public BigDecimal magnitude(Object value) { + Collection narrowed = narrow(value); + + if (narrowed.isEmpty()) + return ZERO; + + BigDecimal elementsMagnitude = + narrowed.stream() + .map(e -> componentGenerators().get(0).magnitude(e)) + .reduce(ZERO, BigDecimal::add); + return BigDecimal.valueOf(narrowed.size()).multiply(elementsMagnitude); + } + + protected final T empty() { + return instantiate(findConstructor(types().get(0))); + } + + private boolean inSizeRange(T items) { + return sizeRange == null + || (items.size() >= sizeRange.min() + && items.size() <= sizeRange.max()); + } + + private int size(SourceOfRandomness random, GenerationStatus status) { + return sizeRange != null + ? random.nextInt(sizeRange.min(), sizeRange.max()) + : status.size(); + } + + private List removals(List items) { + return stream(halving(items.size()).spliterator(), false) + .map(i -> removeFrom(items, i)) + .flatMap(Collection::stream) + .map(this::convert) + .filter(this::inSizeRange) + .collect(toList()); + } + + @SuppressWarnings("unchecked") + private T convert(List items) { + T converted = empty(); + converted.addAll(items); + return converted; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java new file mode 100644 index 0000000000..830c00bb0f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java @@ -0,0 +1,119 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +/** + * Produces values of type {@link Date}. + */ +public class DateGenerator extends Generator { + private Date min = new Date(Integer.MIN_VALUE); + private Date max = new Date(Long.MAX_VALUE); + + public DateGenerator() { + super(Date.class); + } + + /** + *

Tells this generator to produce values within a specified + * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() + * maximum}, inclusive, with uniform distribution, down to the + * millisecond.

+ * + *

If an endpoint of the range is not specified, the generator will use + * dates with milliseconds-since-the-epoch values of either + * {@link Integer#MIN_VALUE} or {@link Long#MAX_VALUE} as appropriate.

+ * + *

{@link InRange#format()} describes + * {@linkplain SimpleDateFormat#parse(String) how the generator is to + * interpret the range's endpoints}.

+ * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + SimpleDateFormat formatter = new SimpleDateFormat(range.format()); + formatter.setLenient(false); + + try { + if (!defaultValueOf(InRange.class, "min").equals(range.min())) + min = formatter.parse(range.min()); + if (!defaultValueOf(InRange.class, "max").equals(range.max())) + max = formatter.parse(range.max()); + } catch (ParseException e) { + throw new IllegalArgumentException(e); + } + + if (min.getTime() > max.getTime()) { + throw new IllegalArgumentException( + String.format("bad range, %s > %s", min, max)); + } + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(new Date(random.nextLong(min.getTime(), max.getTime())), classIdForType(Date.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java new file mode 100644 index 0000000000..8b7ecc873b --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java @@ -0,0 +1,40 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.MapGenerator; + +import java.util.HashMap; + +/** + * Produces values of type {@link HashMap}. + */ +public class HashMapGenerator extends MapGenerator { + public HashMapGenerator() { + super(HashMap.class); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java new file mode 100644 index 0000000000..62c045407c --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java @@ -0,0 +1,40 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.SetGenerator; + +import java.util.HashSet; + +/** + * Produces values of type {@link HashSet}. + */ +public class HashSetGenerator extends SetGenerator { + public HashSetGenerator() { + super(HashSet.class); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java new file mode 100644 index 0000000000..b8d1852167 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java @@ -0,0 +1,44 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.MapGenerator; + +import java.util.Hashtable; + +/** + * Produces values of type {@link Hashtable}. + */ +public class HashtableGenerator extends MapGenerator { + public HashtableGenerator() { + super(Hashtable.class); + } + + @Override protected boolean okToAdd(Object key, Object value) { + return key != null && value != null; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java new file mode 100644 index 0000000000..182881ecca --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java @@ -0,0 +1,40 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.MapGenerator; + +import java.util.LinkedHashMap; + +/** + * Produces values of type {@link LinkedHashMap}. + */ +public class LinkedHashMapGenerator extends MapGenerator { + public LinkedHashMapGenerator() { + super(LinkedHashMap.class); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java new file mode 100644 index 0000000000..3d829c1c21 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java @@ -0,0 +1,40 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.SetGenerator; + +import java.util.LinkedHashSet; + +/** + * Produces values of type {@link LinkedHashSet}. + */ +public class LinkedHashSetGenerator extends SetGenerator { + public LinkedHashSetGenerator() { + super(LinkedHashSet.class); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java new file mode 100644 index 0000000000..c15c30064d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java @@ -0,0 +1,40 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.ListGenerator; + +import java.util.LinkedList; + +/** + * Produces values of type {@link LinkedList}. + */ +public class LinkedListGenerator extends ListGenerator { + public LinkedListGenerator() { + super(LinkedList.class); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java new file mode 100644 index 0000000000..05a96d9f17 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java @@ -0,0 +1,44 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.CollectionGenerator; + +import java.util.List; + +/** + * Base class for generators of {@link List}s. + * + * @param the type of list generated + */ +public abstract class ListGenerator + extends CollectionGenerator { + + protected ListGenerator(Class type) { + super(type); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java new file mode 100644 index 0000000000..edf7114257 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java @@ -0,0 +1,55 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.Locale; + +import static java.util.Locale.getAvailableLocales; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +/** + * Produces values of type {@link Locale}. + */ +public class LocaleGenerator extends Generator { + private static final Locale[] AVAILABLE_LOCALES = getAvailableLocales(); + + public LocaleGenerator() { + super(Locale.class); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.choose(AVAILABLE_LOCALES), classIdForType(Locale.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java new file mode 100644 index 0000000000..84964abcc8 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java @@ -0,0 +1,261 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.concrete.UtModelConstructor; +import org.utbot.framework.plugin.api.*; +import org.utbot.quickcheck.generator.*; +import org.utbot.quickcheck.internal.Lists; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.AbstractMap.SimpleEntry; +import java.util.*; +import java.util.Map.Entry; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; +import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; +import static org.utbot.quickcheck.internal.Lists.removeFrom; +import static org.utbot.quickcheck.internal.Lists.shrinksOfOneItem; +import static org.utbot.quickcheck.internal.Ranges.Type.INTEGRAL; +import static org.utbot.quickcheck.internal.Ranges.checkRange; +import static org.utbot.quickcheck.internal.Reflection.findConstructor; +import static org.utbot.quickcheck.internal.Reflection.instantiate; +import static org.utbot.quickcheck.internal.Sequences.halving; + +/** + *

Base class for generators of {@link Map}s.

+ * + *

The generated map has a number of entries limited by + * {@link GenerationStatus#size()}, or else by the attributes of a {@link Size} + * marking. The individual keys and values will have types corresponding to the + * property parameter's type arguments.

+ * + * @param the type of map generated + */ +public abstract class MapGenerator + extends ComponentizedGenerator { + + private Size sizeRange; + private boolean distinct; + + protected MapGenerator(Class type) { + super(type); + } + + /** + *

Tells this generator to add key-value pairs to the generated map a + * number of times within a specified minimum and/or maximum, inclusive, + * chosen with uniform distribution.

+ * + *

Note that maps disallow duplicate keys, so the number of pairs added + * may not be equal to the map's {@link Map#size()}.

+ * + * @param size annotation that gives the size constraints + */ + public void configure(Size size) { + this.sizeRange = size; + checkRange(INTEGRAL, size.min(), size.max()); + } + + /** + * Tells this generator to add entries whose keys are distinct from + * each other. + * + * @param distinct Keys of generated entries will be distinct if this + * param is not null + */ + public void configure(Distinct distinct) { + this.distinct = distinct != null; + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + int size = size(random, status); + + final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); + final ClassId classId = classIdForType(types().get(0)); + final Generator keyGenerator = componentGenerators().get(0); + final Generator valueGenerator = componentGenerators().get(1); + + final ExecutableId constructorId = new ConstructorId(classId, List.of()); + final int generatedModelId = modelConstructor.computeUnusedIdAndUpdate(); + + final UtAssembleModel generatedModel = new UtAssembleModel( + generatedModelId, + classId, + constructorId.getName() + "#" + generatedModelId, + new UtExecutableCallModel(null, constructorId, List.of()), + null, + (a) -> { + final List modificationChain = new ArrayList<>(); + final ExecutableId putMethodId = methodId(classId, "put", getObjectClassId(), getObjectClassId(), getObjectClassId()); + + int i = 0; + while (i < size) { + final UtModel key = keyGenerator.generate(random, status); + final UtModel value = valueGenerator.generate(random, status); + if (!okToAdd(key, value)) continue; + i++; + modificationChain.add(new UtExecutableCallModel(a, putMethodId, List.of(key, value))); + } + return modificationChain; + } + ); + + + + return generatedModel; + } + + @Override public List doShrink(SourceOfRandomness random, T larger) { + @SuppressWarnings("unchecked") + List> entries = new ArrayList<>(larger.entrySet()); + + List shrinks = new ArrayList<>(removals(entries)); + + @SuppressWarnings("unchecked") + Shrink> entryShrink = entryShrinker( + (Shrink) componentGenerators().get(0), + (Shrink) componentGenerators().get(1)); + + Stream>> oneEntryShrinks = + shrinksOfOneItem(random, entries, entryShrink) + .stream(); + if (distinct) + oneEntryShrinks = oneEntryShrinks.filter(MapGenerator::isKeyDistinct); + + shrinks.addAll( + oneEntryShrinks + .map(this::convert) + .filter(this::inSizeRange) + .collect(toList())); + + return shrinks; + } + + @Override public int numberOfNeededComponents() { + return 2; + } + + @Override public BigDecimal magnitude(Object value) { + Map narrowed = narrow(value); + + if (narrowed.isEmpty()) + return BigDecimal.ZERO; + + BigDecimal keysMagnitude = + narrowed.keySet().stream() + .map(e -> componentGenerators().get(0).magnitude(e)) + .reduce(BigDecimal.ZERO, BigDecimal::add); + BigDecimal valuesMagnitude = + narrowed.values().stream() + .map(e -> componentGenerators().get(1).magnitude(e)) + .reduce(BigDecimal.ZERO, BigDecimal::add); + return BigDecimal.valueOf(narrowed.size()) + .multiply(keysMagnitude) + .add(valuesMagnitude); + } + + protected final T empty() { + return instantiate(findConstructor(types().get(0))); + } + + protected boolean okToAdd(Object key, Object value) { + return true; + } + + private boolean inSizeRange(T target) { + return sizeRange == null + || (target.size() >= sizeRange.min() && target.size() <= sizeRange.max()); + } + + private int size(SourceOfRandomness random, GenerationStatus status) { + return sizeRange != null + ? random.nextInt(sizeRange.min(), sizeRange.max()) + : status.size(); + } + + private List removals(List> items) { + return stream(halving(items.size()).spliterator(), false) + .map(i -> removeFrom(items, i)) + .flatMap(Collection::stream) + .map(this::convert) + .filter(this::inSizeRange) + .collect(toList()); + } + + @SuppressWarnings("unchecked") + private T convert(List entries) { + T converted = empty(); + + for (Object each : entries) { + Entry entry = (Entry) each; + converted.put(entry.getKey(), entry.getValue()); + } + + return converted; + } + + private Shrink> entryShrinker( + Shrink keyShrinker, + Shrink valueShrinker) { + + return (r, e) -> { + @SuppressWarnings("unchecked") + Entry entry = (Entry) e; + + List keyShrinks = keyShrinker.shrink(r, entry.getKey()); + List valueShrinks = valueShrinker.shrink(r, entry.getValue()); + List> shrinks = new ArrayList<>(); + shrinks.addAll( + keyShrinks.stream() + .map(k -> new SimpleEntry<>(k, entry.getValue())) + .collect(toList())); + shrinks.addAll( + valueShrinks.stream() + .map(v -> new SimpleEntry<>(entry.getKey(), v)) + .collect(toList())); + + return shrinks; + }; + } + + private static boolean isKeyDistinct(List> entries) { + return Lists.isDistinct( + entries.stream() + .map(Entry::getKey) + .collect(toList())); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java new file mode 100644 index 0000000000..0f9488ea9d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java @@ -0,0 +1,107 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.framework.plugin.api.UtNullModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.java.lang.DoubleGenerator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.OptionalDouble; + +import static java.math.BigDecimal.ZERO; +import static java.util.stream.Collectors.toList; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +/** + * Produces values of type {@link OptionalDouble}. + */ +public class OptionalDoubleGenerator extends Generator { + private final DoubleGenerator doubles = new DoubleGenerator(); + + public OptionalDoubleGenerator() { + super(OptionalDouble.class); + } + + /** + * Tells this generator to produce values, when + * {@link OptionalDouble#isPresent() present}, within a specified minimum + * (inclusive) and/or maximum (exclusive) with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minDouble()} and {@link InRange#maxDouble()}, + * if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + doubles.configure(range); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + double trial = random.nextDouble(); + final OptionalDouble generated = trial < 0.25 ? + OptionalDouble.empty() + : OptionalDouble.of(doubles.generateValue(random, status)); + + return UtModelGenerator.getUtModelConstructor().construct(generated, classIdForType(OptionalDouble.class)); + } + + @Override public List doShrink( + SourceOfRandomness random, + OptionalDouble larger) { + + if (!larger.isPresent()) + return new ArrayList<>(); + + List shrinks = new ArrayList<>(); + shrinks.add(OptionalDouble.empty()); + shrinks.addAll( + doubles.shrink(random, larger.getAsDouble()) + .stream() + .map(OptionalDouble::of) + .collect(toList())); + return shrinks; + } + + @Override public BigDecimal magnitude(Object value) { + OptionalDouble narrowed = narrow(value); + + return narrowed.isPresent() + ? doubles.magnitude(narrowed.getAsDouble()) + : ZERO; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java new file mode 100644 index 0000000000..3b1729cc8e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java @@ -0,0 +1,109 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.concrete.UtModelConstructor; +import org.utbot.framework.plugin.api.*; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static java.math.BigDecimal.ZERO; +import static java.util.stream.Collectors.toList; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; +import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; + +/** + * Produces values of type {@link Optional}. + */ +public class OptionalGenerator extends ComponentizedGenerator { + public OptionalGenerator() { + super(Optional.class); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + double trial = random.nextDouble(); + if (trial < 0.25) { + return UtModelGenerator.getUtModelConstructor().construct(Optional.empty(), classIdForType(Optional.class)); + } + + final UtModel value = componentGenerators().get(0).generate(random, status); + + final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); + final ClassId classId = classIdForType(Optional.class); + final ExecutableId constructorId = methodId(classId, "of", classId, getObjectClassId()); + + final int generatedModelId = modelConstructor.computeUnusedIdAndUpdate(); + return new UtAssembleModel( + generatedModelId, + classId, + constructorId.getName() + "#" + generatedModelId, + new UtExecutableCallModel(null, constructorId, List.of(value)), + null, + (a) -> List.of() + ); + } + + @Override public List doShrink( + SourceOfRandomness random, + Optional larger) { + + if (!larger.isPresent()) + return new ArrayList<>(); + + List shrinks = new ArrayList<>(); + shrinks.add(Optional.empty()); + shrinks.addAll( + componentGenerators().get(0) + .shrink(random, larger.get()) + .stream() + .map(Optional::of) + .collect(toList())); + return shrinks; + } + + @Override public int numberOfNeededComponents() { + return 1; + } + + @Override public BigDecimal magnitude(Object value) { + Optional narrowed = narrow(value); + + return narrowed.map(componentGenerators().get(0)::magnitude) + .orElse(ZERO); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java new file mode 100644 index 0000000000..77ce377a3c --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java @@ -0,0 +1,107 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.framework.plugin.api.UtNullModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.java.lang.IntegerGenerator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; +import java.util.OptionalDouble; +import java.util.OptionalInt; + +import static java.math.BigDecimal.ZERO; +import static java.util.stream.Collectors.toList; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +/** + * Produces values of type {@link OptionalInt}. + */ +public class OptionalIntGenerator extends Generator { + private final IntegerGenerator integers = new IntegerGenerator(); + + public OptionalIntGenerator() { + super(OptionalInt.class); + } + + /** + * Tells this generator to produce values, when + * {@link OptionalInt#isPresent() present}, within a specified minimum + * and/or maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minInt()} and {@link InRange#maxInt()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + integers.configure(range); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + double trial = random.nextDouble(); + final OptionalInt generated = trial < 0.25 ? + OptionalInt.empty() + : OptionalInt.of(integers.generateValue(random, status)); + + return UtModelGenerator.getUtModelConstructor().construct(generated, classIdForType(OptionalInt.class)); + } + + @Override public List doShrink( + SourceOfRandomness random, + OptionalInt larger) { + + if (!larger.isPresent()) + return new ArrayList<>(); + + List shrinks = new ArrayList<>(); + shrinks.add(OptionalInt.empty()); + shrinks.addAll( + integers.shrink(random, larger.getAsInt()) + .stream() + .map(OptionalInt::of) + .collect(toList())); + return shrinks; + } + + @Override public BigDecimal magnitude(Object value) { + OptionalInt narrowed = narrow(value); + + return narrowed.isPresent() + ? BigDecimal.valueOf(narrowed.getAsInt()) + : ZERO; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java new file mode 100644 index 0000000000..69f8b62448 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java @@ -0,0 +1,104 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.framework.plugin.api.UtNullModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.InRange; +import org.utbot.quickcheck.generator.java.lang.LongGenerator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.*; + +import static java.math.BigDecimal.ZERO; +import static java.util.stream.Collectors.toList; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +/** + * Produces values of type {@link OptionalLong}. + */ +public class OptionalLongGenerator extends Generator { + private final LongGenerator longs = new LongGenerator(); + + public OptionalLongGenerator() { + super(OptionalLong.class); + } + + /** + * Tells this generator to produce values, when + * {@link OptionalLong#isPresent() present}, within a specified minimum + * and/or maximum, inclusive, with uniform distribution. + * + * {@link InRange#min} and {@link InRange#max} take precedence over + * {@link InRange#minLong()} and {@link InRange#maxLong()}, if non-empty. + * + * @param range annotation that gives the range's constraints + */ + public void configure(InRange range) { + longs.configure(range); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + double trial = random.nextDouble(); + final OptionalLong generated = trial < 0.25 ? + OptionalLong.empty() + : OptionalLong.of(longs.generateValue(random, status)); + + return UtModelGenerator.getUtModelConstructor().construct(generated, classIdForType(OptionalLong.class)); + } + + @Override public List doShrink( + SourceOfRandomness random, + OptionalLong larger) { + + if (!larger.isPresent()) + return new ArrayList<>(); + + List shrinks = new ArrayList<>(); + shrinks.add(OptionalLong.empty()); + shrinks.addAll( + longs.shrink(random, larger.getAsLong()) + .stream() + .map(OptionalLong::of) + .collect(toList())); + return shrinks; + } + + @Override public BigDecimal magnitude(Object value) { + OptionalLong narrowed = narrow(value); + + return narrowed.isPresent() + ? BigDecimal.valueOf(narrowed.getAsLong()) + : ZERO; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java new file mode 100644 index 0000000000..96d777c7b2 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java @@ -0,0 +1,129 @@ +package org.utbot.quickcheck.generator.java.util; + +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.concrete.UtModelConstructor; +import org.utbot.framework.plugin.api.*; + +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.java.lang.AbstractStringGenerator; +import org.utbot.quickcheck.generator.java.lang.Encoded; +import org.utbot.quickcheck.generator.java.lang.StringGenerator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.*; + +import static java.math.BigDecimal.ZERO; +import static java.util.Arrays.asList; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; +import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; + +/** + * Produces values of type {@link Properties}. + */ +public class PropertiesGenerator extends Generator { + private AbstractStringGenerator stringGenerator = new StringGenerator(); + + public PropertiesGenerator() { + super(Properties.class); + } + + public void configure(Encoded.InCharset charset) { + Encoded encoded = new Encoded(); + encoded.configure(charset); + stringGenerator = encoded; + } + + @Override + public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + int size = status.size(); + + final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); + final ClassId classId = classIdForType(Properties.class); + + final ExecutableId constructorId = new ConstructorId(classId, List.of()); + final int generatedModelId = modelConstructor.computeUnusedIdAndUpdate(); + + final UtAssembleModel generatedModel = new UtAssembleModel( + generatedModelId, + classId, + constructorId.getName() + "#" + generatedModelId, + new UtExecutableCallModel(null, constructorId, List.of()), + null, + (a) -> { + final List modificationChain = new ArrayList<>(); + final ExecutableId setPropertyMethodId = methodId(classId, "setProperty", getObjectClassId(), getObjectClassId(), getObjectClassId()); + + for (int i = 0; i < size; i++) { + final UtModel key = stringGenerator.generate(random, status); + final UtModel value = stringGenerator.generate(random, status); + modificationChain.add(new UtExecutableCallModel(a, setPropertyMethodId, List.of(key, value))); + } + return modificationChain; + } + ); + + return generatedModel; + } + + @Override public boolean canRegisterAsType(Class type) { + Set> exclusions = + new HashSet<>( + asList( + Object.class, + Hashtable.class, + Map.class, + Dictionary.class)); + return !exclusions.contains(type); + } + + @Override public BigDecimal magnitude(Object value) { + Properties narrowed = narrow(value); + + if (narrowed.isEmpty()) + return ZERO; + + BigDecimal keysMagnitude = + narrowed.keySet().stream() + .map(e -> stringGenerator.magnitude(e)) + .reduce(ZERO, BigDecimal::add); + BigDecimal valuesMagnitude = + narrowed.values().stream() + .map(e -> stringGenerator.magnitude(e)) + .reduce(ZERO, BigDecimal::add); + return BigDecimal.valueOf(narrowed.size()) + .multiply(keysMagnitude) + .add(valuesMagnitude); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java new file mode 100644 index 0000000000..1e43b04f55 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java @@ -0,0 +1,235 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.framework.plugin.api.UtNullModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.GeneratorConfiguration; +import org.utbot.quickcheck.generator.java.lang.StringGenerator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; +import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Properties; +import java.util.UUID; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +/** + * Home for machinery to produce {@link UUID}s according to + * RFC 4122. + */ +public final class RFC4122 { + private RFC4122() { + throw new UnsupportedOperationException(); + } + + private abstract static class AbstractUUIDGenerator + extends Generator { + + protected AbstractUUIDGenerator() { + super(UUID.class); + } + + protected final void setVersion(byte[] bytes, byte mask) { + bytes[6] &= 0x0F; + bytes[6] |= mask; + } + + protected final void setVariant(byte[] bytes) { + bytes[8] &= 0x3F; + bytes[8] |= 0x80; + } + + protected final UUID newUUID(byte[] bytes) { + ByteBuffer bytesIn = ByteBuffer.wrap(bytes); + return new UUID(bytesIn.getLong(), bytesIn.getLong()); + } + } + + private abstract static class NameBasedUUIDGenerator + extends AbstractUUIDGenerator { + + private final StringGenerator strings = new StringGenerator(); + private final int versionMask; + private final MessageDigest digest; + private Namespace namespace; + + protected NameBasedUUIDGenerator( + String hashAlgorithmName, + int versionMask) { + + this.versionMask = versionMask; + digest = MessageDigests.get(hashAlgorithmName); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + digest.reset(); + + Namespaces namespaces = + namespace == null ? Namespaces.URL : namespace.value(); + digest.update(namespaces.bytes); + digest.update( + strings.generateValue(random, status) + .getBytes(StandardCharsets.UTF_8)); + + byte[] hash = digest.digest(); + setVersion(hash, (byte) versionMask); + setVariant(hash); + final UUID generatedUUID = newUUID(hash); + return UtModelGenerator.getUtModelConstructor().construct(generatedUUID, classIdForType(UUID.class)); + } + + protected void setNamespace(Namespace namespace) { + this.namespace = namespace; + } + } + + static final class MessageDigests { + private MessageDigests() { + throw new UnsupportedOperationException(); + } + + static MessageDigest get(String algorithmName) { + try { + return MessageDigest.getInstance(algorithmName); + } catch (NoSuchAlgorithmException shouldNeverHappen) { + throw new IllegalStateException(shouldNeverHappen); + } + } + } + + /** + * Produces values of type {@link UUID} that are RFC 4122 Version 3 + * identifiers. + */ + public static class Version3 extends NameBasedUUIDGenerator { + public Version3() { + super("MD5", 0x30); + } + + /** + * Tells this generator to prepend the given "namespace" UUID to the + * names it generates for UUID production. + * + * @param namespace a handle for a "namespace" UUID + */ + public void configure(Namespace namespace) { + setNamespace(namespace); + } + } + + /** + * Produces values of type {@link UUID} that are RFC 4122 Version 4 + * identifiers. + */ + public static class Version4 extends AbstractUUIDGenerator { + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + byte[] bytes = random.nextBytes(16); + setVersion(bytes, (byte) 0x40); + setVariant(bytes); + //return newUUID(bytes); + return new UtNullModel(classIdForType(UUID.class)); + } + } + + /** + * Produces values of type {@link UUID} that are RFC 4122 Version 5 + * identifiers. + */ + public static class Version5 extends NameBasedUUIDGenerator { + public Version5() { + super("SHA-1", 0x50); + } + + /** + * Tells this generator to prepend the given "namespace" UUID to the + * names it generates for UUID production. + * + * @param namespace a handle for a "namespace" UUID + */ + public void configure(Namespace namespace) { + setNamespace(namespace); + } + } + + /** + * Used in version 3 and version 5 UUID generation to specify a + * "namespace" UUID for use in generation. + */ + @Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) + @Retention(RUNTIME) + @GeneratorConfiguration + public @interface Namespace { + /** + * @return a handle on a "namespace" UUID to use in generation + */ + Namespaces value() default Namespaces.URL; + } + + /** + * Well-known "namespace" UUIDs. + */ + public enum Namespaces { + /** Fully-qualified DNS name. */ + DNS(0x10), + + /** URL. */ + URL(0x11), + + /** ISO object identifier. */ + ISO_OID(0x12), + + /** X.500 distinguished name. */ + X500_DN(0x14); + + final byte[] bytes; + + Namespaces(int difference) { + this.bytes = new byte[] { + 0x6B, (byte) 0xA7, (byte) 0xB8, (byte) difference, + (byte) 0x9D, (byte) 0xAD, + 0x11, (byte) 0xD1, + (byte) 0x80, (byte) 0xB4, + 0x00, (byte) 0xC0, 0x4F, (byte) 0xD4, 0x30, (byte) 0xC8 }; + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java new file mode 100644 index 0000000000..e82e4f1212 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java @@ -0,0 +1,51 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.Size; +import org.utbot.quickcheck.generator.java.util.CollectionGenerator; + +import java.util.Set; + +/** + * Base class for generators of {@link Set}s. + * + * @param the type of set generated + */ +public abstract class SetGenerator + extends CollectionGenerator { + + protected SetGenerator(Class type) { + super(type); + } + + @Override public void configure(Size size) { + super.configure(size); + + setDistinct(true); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java new file mode 100644 index 0000000000..53c82828c7 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java @@ -0,0 +1,40 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.ListGenerator; + +import java.util.Stack; + +/** + * Produces values of type {@link Stack}. + */ +public class StackGenerator extends ListGenerator { + public StackGenerator() { + super(Stack.class); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java new file mode 100644 index 0000000000..f0e67f5ddb --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java @@ -0,0 +1,56 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.TimeZone; + +import static java.util.TimeZone.getAvailableIDs; +import static java.util.TimeZone.getTimeZone; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +/** + * Produces values of type {@link TimeZone}. + */ +public class TimeZoneGenerator extends Generator { + private static final String[] AVAILABLE_IDS = getAvailableIDs(); + + public TimeZoneGenerator() { + super(TimeZone.class); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(getTimeZone(random.choose(AVAILABLE_IDS)), classIdForType(TimeZone.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java new file mode 100644 index 0000000000..e530987906 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java @@ -0,0 +1,40 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.java.util.ListGenerator; + +import java.util.Vector; + +/** + * Produces values of type {@link Vector}. + */ +public class VectorGenerator extends ListGenerator { + public VectorGenerator() { + super(Vector.class); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java new file mode 100644 index 0000000000..677a618ecc --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java @@ -0,0 +1,63 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.concurrent; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.concurrent.Callable; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@code Callable}. + * + * @param the type of the values produced by the generated instances + */ +public class CallableGenerator extends ComponentizedGenerator { + public CallableGenerator() { + super(Callable.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda( + Callable.class, + componentGenerators().get(0), + status), classIdForType(CallableGenerator.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java new file mode 100644 index 0000000000..38c61da0db --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java @@ -0,0 +1,67 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.BiFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link BiFunction}. + * + * @param type of first parameter of produced function + * @param type of second parameter of produced function + * @param return type of produced function + */ +public class BiFunctionGenerator + extends ComponentizedGenerator { + + public BiFunctionGenerator() { + super(BiFunction.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda( + BiFunction.class, + componentGenerators().get(2), + status), classIdForType(BiFunction.class)); + } + + @Override public int numberOfNeededComponents() { + return 3; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java new file mode 100644 index 0000000000..ea10fca834 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java @@ -0,0 +1,73 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.BiPredicate; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link BiPredicate}. + * + * @param type of first parameter of produced predicate + * @param type of second parameter of produced predicate + */ +public class BiPredicateGenerator + extends ComponentizedGenerator { + + private Generator generator; + + public BiPredicateGenerator() { + super(BiPredicate.class); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + generator = gen().type(boolean.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda(BiPredicate.class, generator, status), classIdForType(BiPredicateGenerator.class)); + } + + @Override public int numberOfNeededComponents() { + return 2; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java new file mode 100644 index 0000000000..0ea1e3f7b6 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java @@ -0,0 +1,65 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.BinaryOperator; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link BinaryOperator}. + * + * @param parameters type and return type of produced operator + */ +public class BinaryOperatorGenerator + extends ComponentizedGenerator { + + public BinaryOperatorGenerator() { + super(BinaryOperator.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda( + BinaryOperator.class, + componentGenerators().get(0), + status), classIdForType(BinaryOperator.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java new file mode 100644 index 0000000000..2539e6c237 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java @@ -0,0 +1,65 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.DoubleFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link DoubleFunction}. + * + * @param return type of produced function + */ +public class DoubleFunctionGenerator + extends ComponentizedGenerator { + + public DoubleFunctionGenerator() { + super(DoubleFunction.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda( + DoubleFunction.class, + componentGenerators().get(0), + status), classIdForType(DoubleFunction.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java new file mode 100644 index 0000000000..17ef355d7d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java @@ -0,0 +1,64 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.Function; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link Function}. + * + * @param type of parameter of produced function + * @param return type of produced function + */ +public class FunctionGenerator extends ComponentizedGenerator { + public FunctionGenerator() { + super(Function.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda( + Function.class, + componentGenerators().get(1), + status), classIdForType(Function.class)); + } + + @Override public int numberOfNeededComponents() { + return 2; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java new file mode 100644 index 0000000000..202199d58d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java @@ -0,0 +1,66 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.IntFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link IntFunction}. + * + * @param return type of produced function + */ +public class IntFunctionGenerator + extends ComponentizedGenerator { + + public IntFunctionGenerator() { + super(IntFunction.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda( + IntFunction.class, + componentGenerators().get(0), + status), classIdForType(IntFunction.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java new file mode 100644 index 0000000000..2dc3b9c815 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java @@ -0,0 +1,65 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.LongFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link LongFunction}. + * + * @param return type of produced function + */ +public class LongFunctionGenerator + extends ComponentizedGenerator { + + public LongFunctionGenerator() { + super(LongFunction.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda( + LongFunction.class, + componentGenerators().get(0), + status), classIdForType(LongFunction.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java new file mode 100644 index 0000000000..2c7e747467 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java @@ -0,0 +1,70 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.Predicate; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link Predicate}. + * + * @param type of parameter of produced predicate + */ +public class PredicateGenerator extends ComponentizedGenerator { + private Generator generator; + + public PredicateGenerator() { + super(Predicate.class); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + generator = gen().type(boolean.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda(Predicate.class, generator, status), classIdForType(Predicate.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java new file mode 100644 index 0000000000..ce0809f2bd --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java @@ -0,0 +1,63 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.Supplier; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@code Supplier}. + * + * @param the type of the values produced by the generated instances + */ +public class SupplierGenerator extends ComponentizedGenerator { + public SupplierGenerator() { + super(Supplier.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda( + Supplier.class, + componentGenerators().get(0), + status), classIdForType(Supplier.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java new file mode 100644 index 0000000000..ddeffe0bea --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java @@ -0,0 +1,73 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.ToDoubleBiFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link ToDoubleBiFunction}. + * + * @param type of first parameter of produced function + * @param type of second parameter of produced function + */ +public class ToDoubleBiFunctionGenerator + extends ComponentizedGenerator { + + private Generator generator; + + public ToDoubleBiFunctionGenerator() { + super(ToDoubleBiFunction.class); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + generator = gen().type(double.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToDoubleBiFunction.class, generator, status), classIdForType(ToDoubleBiFunction.class)); + } + + @Override public int numberOfNeededComponents() { + return 2; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java new file mode 100644 index 0000000000..e742ef755e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java @@ -0,0 +1,72 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.ToDoubleFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link ToDoubleFunction}. + * + * @param type of parameter of produced function + */ +public class ToDoubleFunctionGenerator + extends ComponentizedGenerator { + + private Generator generator; + + public ToDoubleFunctionGenerator() { + super(ToDoubleFunction.class); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + generator = gen().type(double.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToDoubleFunction.class, generator, status), classIdForType(ToDoubleFunction.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java new file mode 100644 index 0000000000..97accf0e3e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java @@ -0,0 +1,74 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.ToIntBiFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link ToIntBiFunction}. + * + * @param type of first parameter of produced function + * @param type of second parameter of produced function + */ +public class ToIntBiFunctionGenerator + extends ComponentizedGenerator { + + private Generator generator; + + public ToIntBiFunctionGenerator() { + super(ToIntBiFunction.class); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + generator = gen().type(int.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToIntBiFunction.class, generator, status), classIdForType(ToIntBiFunctionGenerator.class)); + } + + @Override public int numberOfNeededComponents() { + return 2; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java new file mode 100644 index 0000000000..7605a9b149 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java @@ -0,0 +1,72 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.ToIntFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link ToIntFunction}. + * + * @param type of parameter of produced function + */ +public class ToIntFunctionGenerator + extends ComponentizedGenerator { + + private Generator generator; + + public ToIntFunctionGenerator() { + super(ToIntFunction.class); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + generator = gen().type(int.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToIntFunction.class, generator, status), classIdForType(ToIntFunction.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java new file mode 100644 index 0000000000..3958edf8d4 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java @@ -0,0 +1,74 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.ToLongBiFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link ToLongBiFunction}. + * + * @param type of first parameter of produced function + * @param type of second parameter of produced function + */ +public class ToLongBiFunctionGenerator + extends ComponentizedGenerator { + + private Generator generator; + + public ToLongBiFunctionGenerator() { + super(ToLongBiFunction.class); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + generator = gen().type(long.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToLongBiFunction.class, generator, status), classIdForType(ToLongBiFunction.class)); + } + + @Override public int numberOfNeededComponents() { + return 2; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java new file mode 100644 index 0000000000..5e81c40094 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java @@ -0,0 +1,74 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.ToLongBiFunction; +import java.util.function.ToLongFunction; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link ToLongFunction}. + * + * @param type of parameter of produced function + */ +public class ToLongFunctionGenerator + extends ComponentizedGenerator { + + private Generator generator; + + public ToLongFunctionGenerator() { + super(ToLongFunction.class); + } + + @Override + public void provide(Generators provided) { + super.provide(provided); + + generator = gen().type(long.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToLongFunction.class, generator, status), classIdForType(ToLongFunction.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java new file mode 100644 index 0000000000..1c8a4a0191 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java @@ -0,0 +1,65 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.generator.java.util.function; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; + +import org.utbot.quickcheck.generator.ComponentizedGenerator; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.function.UnaryOperator; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +/** + * Produces values of type {@link UnaryOperator}. + * + * @param type of parameter and return type of produced operator + */ +public class UnaryOperatorGenerator + extends ComponentizedGenerator { + + public UnaryOperatorGenerator() { + super(UnaryOperator.class); + } + + @SuppressWarnings("unchecked") + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(makeLambda( + UnaryOperator.class, + componentGenerators().get(0), + status), classIdForType(UnaryOperator.class)); + } + + @Override public int numberOfNeededComponents() { + return 1; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/hook/NilMinimalCounterexampleHook.java b/utbot-framework/src/main/java/org/utbot/quickcheck/hook/NilMinimalCounterexampleHook.java new file mode 100644 index 0000000000..9a17b5946e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/hook/NilMinimalCounterexampleHook.java @@ -0,0 +1,39 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.hook; + +import org.utbot.quickcheck.MinimalCounterexampleHook; + +/** + * Counterexample hook that does nothing. + */ +public class NilMinimalCounterexampleHook + implements MinimalCounterexampleHook { + + @Override public void handle(Object[] counterexample, Runnable action) { + // do nothing purposely + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/CartesianIterator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/CartesianIterator.java new file mode 100644 index 0000000000..d6e91c087f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/CartesianIterator.java @@ -0,0 +1,96 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import static java.util.stream.Collectors.toList; + +public class CartesianIterator implements Iterator> { + private final List> buffers; + private final boolean allStartedAvailable; + + private int count; + + public CartesianIterator(List> sources) { + this.buffers = + sources.stream() + .map(s -> new Buffer<>(s, new ArrayList<>())) + .collect(toList()); + allStartedAvailable = sources.stream().allMatch(Iterator::hasNext); + } + + @Override public boolean hasNext() { + return allStartedAvailable + && buffers.stream().anyMatch(Buffer::available); + } + + @Override public List next() { + List result = new ArrayList<>(); + int n = count; + + for (Buffer each : buffers) { + int divisor = each.divisor(); + + result.add(each.get(n)); + + n /= divisor; + } + + ++count; + return result; + } + + private static class Buffer { + private final Iterator source; + private final List consumed; + private int index; + + Buffer(Iterator source, List consumed) { + this.source = source; + this.consumed = consumed; + } + + boolean available() { + return source.hasNext() || index < consumed.size() - 1; + } + + int divisor() { + return source.hasNext() ? consumed.size() + 1 : consumed.size(); + } + + T get(int n) { + index = n % divisor(); + if (index == consumed.size()) { + consumed.add(source.next()); + } + + return consumed.get(index); + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java new file mode 100644 index 0000000000..6ce54c7eaa --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java @@ -0,0 +1,75 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import java.util.function.Predicate; + +public final class Comparables { + private Comparables() { + throw new UnsupportedOperationException(); + } + + public static > + Predicate inRange(T min, T max) { + return c -> { + if (min == null && max == null) + return true; + if (min == null) + return c.compareTo(max) <= 0; + if (max == null) + return c.compareTo(min) >= 0; + return c.compareTo(min) >= 0 && c.compareTo(max) <= 0; + }; + } + + /** + * @return the value with the lowest magnitude between the min, max and zero. + *
    + *
  • [-10, 5] = 0
  • + *
  • [-10, -5] = -5
  • + *
  • [5, 10] = 5
  • + *
  • [-5, 0] = 0
  • + *
  • [0, 5] = 0
  • + *
+ */ + public static > + T leastMagnitude(T min, T max, T zero) { + if (min == null && max == null) + return zero; + + if (min == null) + return max.compareTo(zero) <= 0 ? max : zero; + if (max == null) + return min.compareTo(zero) >= 0 ? min : zero; + + if (min.compareTo(zero) > 0) + return min; + if (max.compareTo(zero) < 0) + return max; + + return zero; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.java new file mode 100644 index 0000000000..55c64bc53c --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.java @@ -0,0 +1,55 @@ +package org.utbot.quickcheck.internal; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodHandles.Lookup; +import java.lang.invoke.MethodType; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; + +import static org.utbot.quickcheck.internal.Reflection.findDeclaredConstructor; +import static org.utbot.quickcheck.internal.Reflection.jdk9OrBetter; + +public final class DefaultMethodHandleMaker { + private static volatile Constructor methodLookupCtorJDK8; + + private static Constructor methodLookupCtorJDK8() { + if (methodLookupCtorJDK8 == null) { + methodLookupCtorJDK8 = + findDeclaredConstructor(Lookup.class, Class.class, int.class); + } + + return methodLookupCtorJDK8; + } + + public MethodHandle handleForSpecialMethod(Method method) + throws Exception { + + return jdk9OrBetter() + ? jdk9OrBetterMethodHandle(method) + : jdk8MethodHandleForDefault(method); + } + + private MethodHandle jdk9OrBetterMethodHandle(Method method) + throws Exception { + + return MethodHandles.lookup() + .findSpecial( + method.getDeclaringClass(), + method.getName(), + MethodType.methodType( + method.getReturnType(), + method.getParameterTypes()), + method.getDeclaringClass()); + } + + private MethodHandle jdk8MethodHandleForDefault(Method method) + throws Exception { + + Lookup lookup = + methodLookupCtorJDK8().newInstance( + method.getDeclaringClass(), + Lookup.PRIVATE); + return lookup.unreflectSpecial(method, method.getDeclaringClass()); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java new file mode 100644 index 0000000000..5acfa88ef6 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java @@ -0,0 +1,113 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedArrayType; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Type; + +final class FakeAnnotatedTypeFactory { + private FakeAnnotatedTypeFactory() { + throw new UnsupportedOperationException(); + } + + static AnnotatedType makeFrom(Class clazz) { + return clazz.isArray() ? makeArrayType(clazz) : makePlainType(clazz); + } + + private static AnnotatedArrayType makeArrayType(Class type) { + return new FakeAnnotatedArrayType(type); + } + + private static AnnotatedType makePlainType(Class type) { + return new FakeAnnotatedType(type); + } + + private static final class FakeAnnotatedArrayType + implements AnnotatedArrayType { + + private final Class type; + + FakeAnnotatedArrayType(Class type) { + this.type = type; + } + + @Override public AnnotatedType getAnnotatedGenericComponentType() { + return makeFrom(type.getComponentType()); + } + + // Not introduced until JDK 9 -- not marking as... + // @Override + public AnnotatedType getAnnotatedOwnerType() { + return null; + } + + @Override public Type getType() { + return type; + } + + @Override public T getAnnotation( + Class annotationClass) { + + return null; + } + + @Override public Annotation[] getAnnotations() { + return new Annotation[0]; + } + + @Override public Annotation[] getDeclaredAnnotations() { + return new Annotation[0]; + } + } + + private static final class FakeAnnotatedType implements AnnotatedType { + private final Class type; + + FakeAnnotatedType(Class type) { + this.type = type; + } + + @Override public Type getType() { + return type; + } + + @Override public T getAnnotation( + Class annotationClass) { + + return null; + } + + @Override public Annotation[] getAnnotations() { + return new Annotation[0]; + } + + @Override public Annotation[] getDeclaredAnnotations() { + return new Annotation[0]; + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java new file mode 100644 index 0000000000..1184d6ab7d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java @@ -0,0 +1,63 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.random.SourceOfRandomness; + +import static java.lang.Math.ceil; +import static java.lang.Math.log; + +public class GeometricDistribution { + public int sampleWithMean(double mean, SourceOfRandomness random) { + return sample(probabilityOfMean(mean), random); + } + + int sample(double p, SourceOfRandomness random) { + ensureProbability(p); + + if (p == 1) + return 0; + + double uniform = random.nextDouble(); + return (int) ceil(log(1 - uniform) / log(1 - p)); + } + + double probabilityOfMean(double mean) { + if (mean <= 0) { + throw new IllegalArgumentException( + "Need a positive mean, got " + mean); + } + + return 1 / mean; + } + + private void ensureProbability(double p) { + if (p <= 0 || p > 1) { + throw new IllegalArgumentException( + "Need a probability in (0, 1], got " + p); + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java new file mode 100644 index 0000000000..b7a3d0b214 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java @@ -0,0 +1,83 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.internal.Weighted; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.Collection; +import java.util.List; +import java.util.RandomAccess; + +public final class Items { + private Items() { + throw new UnsupportedOperationException(); + } + + @SuppressWarnings("unchecked") + public static T choose(Collection items, SourceOfRandomness random) { + int size = items.size(); + if (size == 0) { + throw new IllegalArgumentException( + "Collection is empty, can't pick an element from it"); + } + + if (items instanceof RandomAccess && items instanceof List) { + List list = (List) items; + return size == 1 + ? list.get(0) + : list.get(random.nextInt(size)); + } + + if (size == 1) { + return items.iterator().next(); + } + + Object[] array = items.toArray(new Object[0]); + return (T) array[random.nextInt(array.length)]; + } + + public static T chooseWeighted( + Collection> items, + SourceOfRandomness random) { + + if (items.size() == 1) + return items.iterator().next().item; + + int range = items.stream().mapToInt(i -> i.weight).sum(); + int sample = random.nextInt(range); + + int threshold = 0; + for (Weighted each : items) { + threshold += each.weight; + if (sample < threshold) + return each.item; + } + + throw new AssertionError( + String.format("sample = %d, range = %d", sample, range)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Lists.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Lists.java new file mode 100644 index 0000000000..f684b3150f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Lists.java @@ -0,0 +1,111 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.generator.Shrink; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.toList; + +public final class Lists { + private Lists() { + throw new UnsupportedOperationException(); + } + + public static List> removeFrom(List target, int howMany) { + if (howMany < 0) { + throw new IllegalArgumentException( + "Can't remove " + howMany + " elements from a list"); + } + if (howMany == 0) + return singletonList(target); + if (howMany > target.size()) + return emptyList(); + + List left = target.subList(0, howMany); + List right = target.subList(howMany, target.size()); + if (right.isEmpty()) + return singletonList(emptyList()); + + List> removals = new ArrayList<>(); + removals.add(right); + removals.addAll(removeFrom(right, howMany) + .stream() + .map(r -> { + List items = new ArrayList<>(left); + items.addAll(r); + return items; + }) + .collect(toList())); + return removals; + } + + public static List> shrinksOfOneItem( + SourceOfRandomness random, + List target, + Shrink shrink) { + + if (target.isEmpty()) + return new ArrayList<>(); + + T head = target.get(0); + List tail = target.subList(1, target.size()); + + List> shrinks = new ArrayList<>(); + shrinks.addAll( + shrink.shrink(random, head) + .stream() + .map(i -> { + List items = new ArrayList<>(); + items.add(i); + items.addAll(tail); + return items; + }) + .collect(toList())); + shrinks.addAll( + shrinksOfOneItem(random, tail, shrink) + .stream() + .map(s -> { + List items = new ArrayList<>(); + items.add(head); + items.addAll(s); + return items; + }) + .collect(toList())); + + return shrinks; + } + + public static boolean isDistinct(List target) { + return new HashSet<>(target).size() == target.size(); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterSampler.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterSampler.java new file mode 100644 index 0000000000..ad2735ae6e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterSampler.java @@ -0,0 +1,49 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.internal.ParameterTypeContext; +import org.utbot.quickcheck.internal.SeededValue; +import org.utbot.quickcheck.internal.generator.GeneratorRepository; +import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; + +import java.util.List; +import java.util.stream.Stream; + +public interface ParameterSampler { + int sizeFactor(org.utbot.quickcheck.internal.ParameterTypeContext p); + + Stream> sample( + List parameters); + + default Generator decideGenerator( + GeneratorRepository repository, + ParameterTypeContext p) { + + return repository.produceGenerator(p); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java new file mode 100644 index 0000000000..6b4388534e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java @@ -0,0 +1,508 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.From; +import org.utbot.quickcheck.Produced; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.internal.ReflectionException; +import org.utbot.quickcheck.internal.Weighted; +import org.utbot.quickcheck.internal.Zilch; +import org.utbot.quickcheck.random.SourceOfRandomness; +import org.javaruntype.type.*; +import ru.vyarus.java.generics.resolver.GenericsResolver; +import ru.vyarus.java.generics.resolver.context.ConstructorGenericsContext; +import ru.vyarus.java.generics.resolver.context.GenericsContext; +import ru.vyarus.java.generics.resolver.context.MethodGenericsContext; + +import java.lang.reflect.Type; +import java.lang.reflect.*; +import java.util.*; + +import static org.utbot.quickcheck.internal.Items.choose; +import static org.utbot.quickcheck.internal.Reflection.*; +import static java.lang.String.format; +import static java.util.Collections.unmodifiableList; +import static org.javaruntype.type.Types.arrayComponentOf; + +public class ParameterTypeContext { + private static final String EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE = + "The generator %s named in @%s on parameter %s does not produce a type-compatible object"; + private static org.utbot.quickcheck.internal.Zilch zilch; + + private final String parameterName; + private final AnnotatedType parameterType; + private final String declarerName; + private final org.javaruntype.type.Type resolved; + private final List>> explicits = new ArrayList<>(); + private final GenericsContext generics; + private final int parameterIndex; + + private AnnotatedElement annotatedElement; + private boolean allowMixedTypes; + + public GenericsContext getGenerics() { + return generics; + } + public org.javaruntype.type.Type getResolved() { + return resolved; + } + public static ParameterTypeContext forClass(Class clazz) { + return new ParameterTypeContext( + clazz.getTypeName(), + org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(clazz), + clazz.getTypeName(), + Types.forJavaLangReflectType(clazz), + GenericsResolver.resolve(clazz)); + } + + public static ParameterTypeContext forField(Field field) { + GenericsContext generics = + GenericsResolver.resolve(field.getDeclaringClass()); + + return new ParameterTypeContext( + field.getName(), + field.getAnnotatedType(), + field.getDeclaringClass().getName(), + Types.forJavaLangReflectType(generics.resolveFieldType(field)), + generics); + } + + public static ParameterTypeContext forParameter(Parameter parameter) { + Executable exec = parameter.getDeclaringExecutable(); + Class clazz = exec.getDeclaringClass(); + String declarerName = clazz.getName() + '.' + exec.getName(); + int parameterIndex = parameterIndex(exec, parameter); + + GenericsContext generics; + org.javaruntype.type.Type resolved; + + if (exec instanceof Method) { + Method method = (Method) exec; + MethodGenericsContext methodGenerics = + GenericsResolver.resolve(clazz).method(method); + resolved = + Types.forJavaLangReflectType( + methodGenerics.resolveParameterType(parameterIndex)); + generics = methodGenerics; + } else if (exec instanceof Constructor) { + Constructor ctor = (Constructor) exec; + ConstructorGenericsContext constructorGenerics = + GenericsResolver.resolve(clazz).constructor(ctor); + resolved = + Types.forJavaLangReflectType( + constructorGenerics.resolveParameterType(parameterIndex)); + generics = constructorGenerics; + } else { + throw new IllegalStateException("Unrecognized subtype of Executable"); + } + + return new ParameterTypeContext( + parameter.getName(), + parameter.getAnnotatedType(), + declarerName, + resolved, + generics, + parameterIndex); + } + + public static ParameterTypeContext forParameter( + Parameter parameter, + MethodGenericsContext generics) { + + Executable exec = parameter.getDeclaringExecutable(); + Class clazz = exec.getDeclaringClass(); + String declarerName = clazz.getName() + '.' + exec.getName(); + int parameterIndex = parameterIndex(exec, parameter); + + return new ParameterTypeContext( + parameter.getName(), + parameter.getAnnotatedType(), + declarerName, + Types.forJavaLangReflectType( + generics.resolveParameterType(parameterIndex)), + generics, + parameterIndex); + } + + private static int parameterIndex(Executable exec, Parameter parameter) { + Parameter[] parameters = exec.getParameters(); + for (int i = 0; i < parameters.length; ++i) { + if (parameters[i].equals(parameter)) + return i; + } + + throw new IllegalStateException( + "Cannot find parameter " + parameter + " on " + exec); + } + + public ParameterTypeContext( + String parameterName, + AnnotatedType parameterType, + String declarerName, + org.javaruntype.type.Type resolvedType, + GenericsContext generics) { + + this( + parameterName, + parameterType, + declarerName, + resolvedType, + generics, + -1); + } + + public ParameterTypeContext( + String parameterName, + AnnotatedType parameterType, + String declarerName, + org.javaruntype.type.Type resolvedType, + GenericsContext generics, + int parameterIndex) { + + this.parameterName = parameterName; + this.parameterType = parameterType; + this.declarerName = declarerName; + this.resolved = resolvedType; + this.generics = generics; + this.parameterIndex = parameterIndex; + } + + public ParameterTypeContext annotate(AnnotatedElement element) { + this.annotatedElement = element; + + List producedGenerators = + allAnnotationsByType(element, Produced.class); + + List generators; + if (producedGenerators.size() == 1) { + generators = Arrays.asList(producedGenerators.get(0).value()); + } else { + generators = allAnnotationsByType(element, From.class); + if (!generators.isEmpty() + && element instanceof AnnotatedWildcardType) { + + throw new IllegalArgumentException( + "Wildcards cannot be marked with @From"); + } + } + + addGenerators(generators); + return this; + } + + public ParameterTypeContext allowMixedTypes(boolean value) { + this.allowMixedTypes = value; + return this; + } + + public boolean allowMixedTypes() { + return allowMixedTypes; + } + + /** + * Gives a context for generation of the return type of a lambda method. + * + * @param method method whose return type we want to resolve + * @return an associated parameter context + */ + public ParameterTypeContext methodReturnTypeContext(Method method) { + if (!(generics instanceof MethodGenericsContext)) { + throw new IllegalStateException( + "invoking methodReturnTypeContext in present of " + generics); + } + + MethodGenericsContext testMethodGenerics = + (MethodGenericsContext) generics; + MethodGenericsContext argMethodGenerics = + testMethodGenerics.parameterType(parameterIndex).method(method); + + return new ParameterTypeContext( + "return value", + method.getAnnotatedReturnType(), + method.getName(), + Types.forJavaLangReflectType(argMethodGenerics.resolveReturnType()), + argMethodGenerics); + } + + private void addGenerators(List generators) { + for (From each : generators) { + Generator generator = makeGenerator(each.value()); + ensureCorrectType(generator); + explicits.add(new org.utbot.quickcheck.internal.Weighted<>(generator, each.frequency())); + } + } + + private Generator makeGenerator( + Class generatorType) { + + Constructor ctor; + + try { + // for Ctor/Fields + ctor = findConstructor(generatorType, Class.class); + } catch (ReflectionException ex) { + return instantiate(generatorType); + } + + return instantiate(ctor, rawParameterType()); + } + + private Class rawParameterType() { + if (type() instanceof ParameterizedType) + return resolved.getRawClass(); + if (type() instanceof TypeVariable) + return resolved.getRawClass(); + + return (Class) type(); + } + + private void ensureCorrectType(Generator generator) { + for (Class each : generator.types()) { + if (!maybeWrap(resolved.getRawClass()) + .isAssignableFrom(maybeWrap(each))) { + + throw new IllegalArgumentException( + format( + EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE, + each, + From.class.getName(), + parameterName)); + } + } + } + + public String name() { + return declarerName + ':' + parameterName; + } + + public AnnotatedType annotatedType() { + return parameterType; + } + + public Type type() { + return parameterType.getType(); + } + + /** + * @deprecated This will likely go away when languages whose compilers + * and interpreters produce class files that support annotations on type + * uses. + * @see + * this issue + * @return the annotated program element this context represents + */ + @Deprecated + public AnnotatedElement annotatedElement() { + return annotatedElement; + } + + /** + * @deprecated This will likely go away when languages whose compilers + * and interpreters produce class files that support annotations on type + * uses. + * @see + * this issue + * @return the annotated program element this context represents + */ + @Deprecated + public boolean topLevel() { + return annotatedElement instanceof Parameter + || annotatedElement instanceof Field; + } + + public List>> explicitGenerators() { + return unmodifiableList(explicits); + } + + private void addParameterTypeContextToDeque(ArrayDeque deque, ParameterTypeContext ptx) { + if (ptx.resolved.getName().equals(Zilch.class.getName())) return; + deque.add(ptx); + } + public List getAllSubParameterTypeContexts(SourceOfRandomness sourceOfRandomness) { + ArrayList res = new ArrayList<>(); + res.add(this); + ArrayDeque deque = new ArrayDeque<>(); + if (isArray()) { + addParameterTypeContextToDeque(deque, arrayComponentContext()); + deque.add(arrayComponentContext()); + } + typeParameterContexts(sourceOfRandomness).forEach(ptx -> addParameterTypeContextToDeque(deque, ptx)); + while (!deque.isEmpty()) { + ParameterTypeContext ptx = deque.removeFirst(); + res.add(ptx); + if (ptx.isArray()) { + addParameterTypeContextToDeque(deque, ptx.arrayComponentContext()); + } + ptx.typeParameterContexts(sourceOfRandomness).forEach(ptxNested -> addParameterTypeContextToDeque(deque, ptxNested)); + } + return res; + } + public ParameterTypeContext arrayComponentContext() { + @SuppressWarnings("unchecked") + org.javaruntype.type.Type component = + arrayComponentOf((org.javaruntype.type.Type) resolved); + AnnotatedType annotatedComponent = annotatedArrayComponent(component); + return new ParameterTypeContext( + annotatedComponent.getType().getTypeName(), + annotatedComponent, + parameterType.getType().getTypeName(), + component, + generics) + .annotate(annotatedComponent) + .allowMixedTypes(true); + } + + private AnnotatedType annotatedArrayComponent( + org.javaruntype.type.Type component) { + + return parameterType instanceof AnnotatedArrayType + ? ((AnnotatedArrayType) parameterType).getAnnotatedGenericComponentType() + : org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(component.getComponentClass()); + } + + public boolean isArray() { + return resolved.isArray(); + } + + public Class getRawClass() { + return resolved.getRawClass(); + } + + public boolean isEnum() { + return getRawClass().isEnum(); + } + + public List> getTypeParameters() { + return resolved.getTypeParameters(); + } + + public List typeParameterContexts( + SourceOfRandomness random) { + + List typeParamContexts = new ArrayList<>(); + List> typeParameters = getTypeParameters(); + List annotatedTypeParameters = + annotatedComponentTypes(annotatedType()); + + for (int i = 0; i < typeParameters.size(); ++i) { + TypeParameter p = typeParameters.get(i); + AnnotatedType a = + annotatedTypeParameters.size() > i + ? annotatedTypeParameters.get(i) + : zilch(); + + if (p instanceof StandardTypeParameter) + addStandardTypeParameterContext(typeParamContexts, p, a); + else if (p instanceof WildcardTypeParameter) + addWildcardTypeParameterContext(typeParamContexts, a); + else if (p instanceof ExtendsTypeParameter) + addExtendsTypeParameterContext(typeParamContexts, p, a); + else { + // must be "? super X" + addSuperTypeParameterContext(random, typeParamContexts, p, a); + } + } + + return typeParamContexts; + } + + private void addStandardTypeParameterContext( + List typeParameterContexts, + TypeParameter p, + AnnotatedType a) { + + typeParameterContexts.add( + new ParameterTypeContext( + p.getType().getName(), + a, + annotatedType().getType().getTypeName(), + p.getType(), + generics) + .allowMixedTypes(!(a instanceof TypeVariable)) + .annotate(a)); + } + + private void addWildcardTypeParameterContext( + List typeParameterContexts, + AnnotatedType a) { + + typeParameterContexts.add( + new ParameterTypeContext( + "Zilch", + a, + annotatedType().getType().getTypeName(), + Types.forJavaLangReflectType(org.utbot.quickcheck.internal.Zilch.class), + GenericsResolver.resolve(Zilch.class)) + .allowMixedTypes(true) + .annotate(a)); + } + + private void addExtendsTypeParameterContext( + List typeParameterContexts, + TypeParameter p, + AnnotatedType a) { + + typeParameterContexts.add( + new ParameterTypeContext( + p.getType().getName(), + annotatedComponentTypes(a).get(0), + annotatedType().getType().getTypeName(), + p.getType(), + generics) + .allowMixedTypes(false) + .annotate(a)); + } + + private void addSuperTypeParameterContext( + SourceOfRandomness random, + List typeParameterContexts, + TypeParameter p, + AnnotatedType a) { + + Set> supertypes = supertypes(p.getType()); + org.javaruntype.type.Type choice = choose(supertypes, random); + + typeParameterContexts.add( + new ParameterTypeContext( + p.getType().getName(), + annotatedComponentTypes(a).get(0), + annotatedType().getType().getTypeName(), + choice, + generics) + .allowMixedTypes(false) + .annotate(a)); + } + + private static AnnotatedType zilch() { + try { + return ParameterTypeContext.class.getDeclaredField("zilch") + .getAnnotatedType(); + } catch (NoSuchFieldException e) { + throw new AssertionError(e); + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/PropertyParameterContext.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/PropertyParameterContext.java new file mode 100644 index 0000000000..d9d89f0be7 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/PropertyParameterContext.java @@ -0,0 +1,110 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.When; +import org.utbot.quickcheck.internal.ParameterTypeContext; + + +import java.lang.reflect.AnnotatedElement; + +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +public class PropertyParameterContext { + private static final long DEFAULT_SEED = + (long) defaultValueOf(When.class, "seed"); + + private final ParameterTypeContext typeContext; + + private int discardRatio; + private String constraint; + private long seed = DEFAULT_SEED; + + + public PropertyParameterContext(ParameterTypeContext typeContext) { + this.typeContext = typeContext; + } + + public PropertyParameterContext annotate(AnnotatedElement element) { + When quantifier = element.getAnnotation(When.class); + addQuantifier(quantifier); + addConstraint(quantifier); + typeContext.annotate(element); + + return this; + } + + public PropertyParameterContext addQuantifier(When quantifier) { + if (quantifier != null) { + this.discardRatio = ensurePositiveDiscardRatio(quantifier); + this.seed = quantifier.seed(); + } + + return this; + } + + public PropertyParameterContext addConstraint(When quantifier) { + if (quantifier != null + && !defaultValueOf(When.class, "satisfies") + .equals(quantifier.satisfies())) { + + constraint = quantifier.satisfies(); + } + + return this; + } + + + public ParameterTypeContext typeContext() { + return typeContext; + } + + public int discardRatio() { + return discardRatio; + } + + public String constraint() { + return constraint; + } + + public boolean fixedSeed() { + return seed != DEFAULT_SEED; + } + + public long seed() { + return seed; + } + + private int ensurePositiveDiscardRatio(When quantifier) { + if (quantifier.discardRatio() <= 0) { + throw new IllegalArgumentException( + "Non-positive discard ratio for parameter " + typeContext.name() + + " of type " + typeContext.type().getTypeName()); + } + + return quantifier.discardRatio(); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java new file mode 100644 index 0000000000..cd74806c38 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java @@ -0,0 +1,127 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigInteger; + +import static java.lang.String.format; + +public final class Ranges { + public enum Type { + CHARACTER("c"), + INTEGRAL("d"), + FLOAT("f"), + STRING("s"); + + private final String pattern; + + Type(String pattern) { + this.pattern = pattern; + } + } + + private Ranges() { + throw new UnsupportedOperationException(); + } + + public static > + int checkRange(Type type, T min, T max) { + int comparison = min.compareTo(max); + if (comparison > 0) { + throw new IllegalArgumentException( + format( + "bad range, %" + type.pattern + " > %" + type.pattern, + min, + max)); + } + + return comparison; + } + + public static BigInteger choose( + SourceOfRandomness random, + BigInteger min, + BigInteger max) { + + BigInteger range = max.subtract(min).add(BigInteger.ONE); + BigInteger generated; + + do { + generated = random.nextBigInteger(range.bitLength()); + } while (generated.compareTo(range) >= 0); + + return generated.add(min); + } + + public static long choose(SourceOfRandomness random, long min, long max) { + checkRange(Type.INTEGRAL, min, max); + + /* There are some edges cases with integer overflows, for instance, + when (max - min) exceeds Long.MAX_VALUE. These cases should be + relatively rare under the assumption that choosing + [Long.MIN_VALUE, Long.MAX_VALUE] can be simplified to choosing any + random long. Thus, the optimization here only deals with the common + situation that no overflows are possible (maybe the heuristic to + detect that could be improved). + */ + boolean noOverflowIssues = + max < ((long) 1 << 62) && min > -(((long) 1) << 62); + + if (noOverflowIssues) { + // fast path: use long computations + long range = (max - min) + 1; + long mask = findNextPowerOfTwoLong(range) - 1; + + // loop to avoid distribution bias (as would be the case + // with modulo division) + long generated; + do { + generated = Math.abs(random.nextLong()) & mask; + } while (generated >= range); + + return generated + min; + } else { + // slow path: fall back to BigInteger to avoid any surprises + return choose( + random, + BigInteger.valueOf(min), + BigInteger.valueOf(max)) + .longValue(); + } + } + + static long findNextPowerOfTwoLong(long positiveLong) { + return isPowerOfTwoLong(positiveLong) + ? positiveLong + : ((long) 1) << (64 - Long.numberOfLeadingZeros(positiveLong)); + } + + private static boolean isPowerOfTwoLong(long positiveLong) { + return (positiveLong & (positiveLong - 1)) == 0; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java new file mode 100644 index 0000000000..661531db5b --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java @@ -0,0 +1,332 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.internal.ReflectionException; + +import org.javaruntype.type.Type; + +import java.lang.annotation.Annotation; +import java.lang.reflect.*; +import java.security.PrivilegedAction; +import java.util.*; + +import static java.lang.reflect.Modifier.isAbstract; +import static java.security.AccessController.doPrivileged; +import static java.util.Arrays.asList; +import static java.util.Arrays.stream; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; +import static java.util.stream.Collectors.toList; + +public final class Reflection { + private static final Map, Class> PRIMITIVES = + new HashMap<>(16); + + static { + PRIMITIVES.put(Boolean.TYPE, Boolean.class); + PRIMITIVES.put(Byte.TYPE, Byte.class); + PRIMITIVES.put(Character.TYPE, Character.class); + PRIMITIVES.put(Double.TYPE, Double.class); + PRIMITIVES.put(Float.TYPE, Float.class); + PRIMITIVES.put(Integer.TYPE, Integer.class); + PRIMITIVES.put(Long.TYPE, Long.class); + PRIMITIVES.put(Short.TYPE, Short.class); + } + + private Reflection() { + throw new UnsupportedOperationException(); + } + + public static Class maybeWrap(Class clazz) { + Class wrapped = PRIMITIVES.get(clazz); + return wrapped == null ? clazz : wrapped; + } + + public static Constructor findConstructor( + Class type, + Class... parameterTypes) { + + try { + return type.getConstructor(parameterTypes); + } catch (Exception ex) { + throw reflectionException(ex); + } + } + + static Constructor findDeclaredConstructor( + Class type, + Class... parameterTypes) { + + try { + Constructor ctor = type.getDeclaredConstructor(parameterTypes); + ctor.setAccessible(true); + return ctor; + } catch (Exception ex) { + throw reflectionException(ex); + } + } + + @SuppressWarnings("unchecked") + public static Constructor singleAccessibleConstructor( + Class type) { + + Constructor[] constructors = type.getConstructors(); + if (constructors.length != 1) { + throw new org.utbot.quickcheck.internal.ReflectionException( + type + " needs a single accessible constructor"); + } + + return (Constructor) constructors[0]; + } + + + public static T instantiate(Class clazz) { + try { + return clazz.newInstance(); + } catch (Exception ex) { + throw reflectionException(ex); + } + } + + public static T instantiate(Constructor ctor, Object... args) { + try { + return ctor.newInstance(args); + } catch (Exception ex) { + throw reflectionException(ex); + } + } + + public static Set> supertypes(Type bottom) { + Set> supertypes = new HashSet<>(); + supertypes.add(bottom); + supertypes.addAll(bottom.getAllTypesAssignableFromThis()); + return supertypes; + } + + public static Object defaultValueOf( + Class annotationType, + String attribute) { + + try { + return annotationType.getMethod(attribute).getDefaultValue(); + } catch (Exception ex) { + throw reflectionException(ex); + } + } + + public static List allAnnotations(AnnotatedElement e) { + List thisAnnotations = nonSystemAnnotations(e); + + List annotations = new ArrayList<>(); + for (Annotation each : thisAnnotations) { + annotations.add(each); + annotations.addAll(allAnnotations(each.annotationType())); + } + + return annotations; + } + + static List allAnnotationsByType( + AnnotatedElement e, + Class type) { + + List annotations = new ArrayList<>(); + Collections.addAll(annotations, e.getAnnotationsByType(type)); + + List thisAnnotations = nonSystemAnnotations(e); + + for (Annotation each : thisAnnotations) { + annotations.addAll( + allAnnotationsByType(each.annotationType(), type)); + } + + return annotations; + } + + public static Method findMethod( + Class target, + String methodName, + Class... argTypes) { + + try { + return target.getMethod(methodName, argTypes); + } catch (Exception ex) { + throw reflectionException(ex); + } + } + + public static Object invoke(Method method, Object target, Object... args) { + try { + return method.invoke(target, args); + } catch (Exception ex) { + throw reflectionException(ex); + } + } + + public static Field findField(Class type, String fieldName) { + try { + return type.getDeclaredField(fieldName); + } catch (NoSuchFieldException ex) { + throw reflectionException(ex); + } + } + + public static List allDeclaredFieldsOf(Class type) { + List allFields = new ArrayList<>(); + + for (Class c = type; c != null; c = c.getSuperclass()) { + Collections.addAll(allFields, c.getDeclaredFields()); + } + + List results = + allFields.stream() + .filter(f -> !f.isSynthetic()) + .collect(toList()); + results.forEach(f -> f.setAccessible(true)); + + return results; + } + + public static void setField( + Field field, + Object target, + Object value, + boolean suppressProtection) { + + doPrivileged((PrivilegedAction) () -> { + field.setAccessible(suppressProtection); + return null; + }); + + try { + field.set(target, value); + } catch (Exception ex) { + throw reflectionException(ex); + } + } + + static boolean jdk9OrBetter() { + try { + Runtime.class.getMethod("version"); + return true; + } catch (NoSuchMethodException e) { + return false; + } + } + + public static Method singleAbstractMethodOf(Class rawClass) { + if (!rawClass.isInterface()) + return null; + + int abstractCount = 0; + Method singleAbstractMethod = null; + for (Method each : rawClass.getMethods()) { + if (isAbstract(each.getModifiers()) + && !overridesJavaLangObjectMethod(each)) { + + singleAbstractMethod = each; + ++abstractCount; + } + } + + return abstractCount == 1 ? singleAbstractMethod : null; + } + + public static boolean isMarkerInterface(Class clazz) { + if (!clazz.isInterface()) + return false; + + return Arrays.stream(clazz.getMethods()) + .filter(m -> !m.isDefault()) + .allMatch(Reflection::overridesJavaLangObjectMethod); + } + + private static boolean overridesJavaLangObjectMethod(Method method) { + return isEquals(method) || isHashCode(method) || isToString(method); + } + + private static boolean isEquals(Method method) { + return "equals".equals(method.getName()) + && method.getParameterTypes().length == 1 + && Object.class.equals(method.getParameterTypes()[0]); + } + + private static boolean isHashCode(Method method) { + return "hashCode".equals(method.getName()) + && method.getParameterTypes().length == 0; + } + + private static boolean isToString(Method method) { + return "toString".equals(method.getName()) + && method.getParameterTypes().length == 0; + } + + public static RuntimeException reflectionException(Exception ex) { + if (ex instanceof InvocationTargetException) { + return new org.utbot.quickcheck.internal.ReflectionException( + ((InvocationTargetException) ex).getTargetException()); + } + if (ex instanceof RuntimeException) + return (RuntimeException) ex; + + return new ReflectionException(ex); + } + + private static List nonSystemAnnotations(AnnotatedElement e) { + return stream(e.getAnnotations()) + .filter(a -> + !a.annotationType().getName().startsWith( + "java.lang.annotation.")) + .filter(a -> !a.annotationType().getName().startsWith("kotlin.")) + .collect(toList()); + } + + public static List annotatedComponentTypes( + AnnotatedType annotatedType) { + + if (annotatedType instanceof AnnotatedParameterizedType) { + return asList( + ((AnnotatedParameterizedType) annotatedType) + .getAnnotatedActualTypeArguments()); + } + if (annotatedType instanceof AnnotatedArrayType) { + return singletonList( + ((AnnotatedArrayType) annotatedType) + .getAnnotatedGenericComponentType()); + } + if (annotatedType instanceof AnnotatedWildcardType) { + AnnotatedWildcardType wildcard = + (AnnotatedWildcardType) annotatedType; + if (wildcard.getAnnotatedLowerBounds().length > 0) + return singletonList(wildcard.getAnnotatedLowerBounds()[0]); + + return asList(wildcard.getAnnotatedUpperBounds()); + } + + return emptyList(); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java new file mode 100644 index 0000000000..aedce2b0d1 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java @@ -0,0 +1,38 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +public class ReflectionException extends RuntimeException { + private static final long serialVersionUID = Long.MIN_VALUE; + + public ReflectionException(String message) { + super(message); + } + + public ReflectionException(Throwable cause) { + super(cause.toString()); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/SeededValue.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/SeededValue.java new file mode 100644 index 0000000000..5e5363f9cc --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/SeededValue.java @@ -0,0 +1,59 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; + + +public final class SeededValue { + private final PropertyParameterGenerationContext p; + private final Object value; + private final long seed; + + + public SeededValue(PropertyParameterGenerationContext p) { + this.p = p; + this.value = p.generate(); + this.seed = p.effectiveSeed(); + } + + + public PropertyParameterGenerationContext parameter() { + return p; + } + + public Object value() { + return value; + } + + public long seed() { + return seed; + } + + @Override public String toString() { + return String.format("%s = [%s], seed = %d", p.name(), value, seed); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Sequences.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Sequences.java new file mode 100644 index 0000000000..348cc72c7d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Sequences.java @@ -0,0 +1,152 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.Iterator; +import java.util.NoSuchElementException; + +import static java.math.RoundingMode.HALF_UP; + +public final class Sequences { + private Sequences() { + throw new UnsupportedOperationException(); + } + + public static Iterable halvingIntegral( + BigInteger max, + BigInteger start) { + + return () -> new BigIntegerHalvingIterator(start, max); + } + + public static Iterable halvingDecimal( + BigDecimal max, + BigDecimal start) { + + return () -> new BigDecimalHalvingIterator(start, max); + } + + public static Iterable halving(int start) { + return () -> new IntegerHalvingIterator(start); + } + + private static final class BigIntegerHalvingIterator + implements Iterator { + + private final BigInteger max; + + private boolean done; + private BigInteger next; + + BigIntegerHalvingIterator(BigInteger start, BigInteger max) { + this.max = max; + next = start; + } + + @Override public boolean hasNext() { + return !done; + } + + @Override public BigInteger next() { + if (!hasNext()) + throw new NoSuchElementException(); + + next = peek(); + done = next.equals(peek()); + return next; + } + + private BigInteger peek() { + return next.add( + max.subtract(next) + .divide(BigInteger.valueOf(2))); + } + } + + private static final class BigDecimalHalvingIterator + implements Iterator { + + private final BigDecimal max; + + private boolean done; + private BigDecimal next; + + BigDecimalHalvingIterator(BigDecimal start, BigDecimal max) { + this.max = max; + next = start; + } + + @Override public boolean hasNext() { + return !done; + } + + @Override public BigDecimal next() { + if (!hasNext()) + throw new NoSuchElementException(); + + next = peek(); + done = next.equals(peek()); + return next; + } + + private BigDecimal peek() { + return next.add( + max.subtract(next) + .divide(BigDecimal.valueOf(2), HALF_UP)); + } + } + + private static final class IntegerHalvingIterator + implements Iterator { + + private boolean done; + private int next; + + IntegerHalvingIterator(int start) { + next = start; + } + + @Override public boolean hasNext() { + return !done; + } + + @Override public Integer next() { + if (!hasNext()) + throw new NoSuchElementException(); + + int result = next; + next = peek(); + done = next == 0; + return result; + } + + private int peek() { + return next / 2; + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ShrinkControl.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ShrinkControl.java new file mode 100644 index 0000000000..b93fb2191a --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ShrinkControl.java @@ -0,0 +1,68 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import org.utbot.quickcheck.MinimalCounterexampleHook; +import org.utbot.quickcheck.Property; + +public class ShrinkControl { + private final boolean shouldShrink; + private final int maxShrinks; + private final int maxShrinkDepth; + private final int maxShrinkTime; + private final MinimalCounterexampleHook onMinimalCounterexample; + + public ShrinkControl(Property marker) + throws IllegalAccessException, InstantiationException { + + this.shouldShrink = marker.shrink(); + this.maxShrinks = marker.maxShrinks(); + this.maxShrinkDepth = marker.maxShrinkDepth(); + this.maxShrinkTime = marker.maxShrinkTime(); + this.onMinimalCounterexample = + marker.onMinimalCounterexample().newInstance(); + } + + public boolean shouldShrink() { + return shouldShrink; + } + + public int maxShrinks() { + return maxShrinks; + } + + public int maxShrinkDepth() { + return maxShrinkDepth; + } + + public int maxShrinkTime() { + return maxShrinkTime; + } + + public MinimalCounterexampleHook onMinimalCounterexample() { + return onMinimalCounterexample; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java new file mode 100644 index 0000000000..e07dd2cd4e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java @@ -0,0 +1,41 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +public final class Weighted { + public final T item; + public final int weight; + + public Weighted(T item, int weight) { + if (weight <= 0) { + throw new IllegalArgumentException( + "non-positive weight: " + weight); + } + + this.item = item; + this.weight = weight; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java new file mode 100644 index 0000000000..87a4f60958 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java @@ -0,0 +1,34 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +public final class Zilch { + public static final Zilch INSTANCE = new Zilch(); + + private Zilch() { + // nothing to do here + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/constraint/ConstraintEvaluator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/constraint/ConstraintEvaluator.java new file mode 100644 index 0000000000..5f735e7cf9 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/constraint/ConstraintEvaluator.java @@ -0,0 +1,84 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.utbot.quickcheck.internal.constraint; + +import ognl.Ognl; +import ognl.OgnlException; + +import java.util.HashMap; +import java.util.Map; + +public class ConstraintEvaluator { + private final Object constraint; + private final Map bindings; + + public ConstraintEvaluator(String expression) { + try { + constraint = + expression == null ? null : Ognl.parseExpression(expression); + bindings = new EvalMap(); + } catch (OgnlException ex) { + throw new EvaluationException(ex); + } + } + + public boolean evaluate() { + try { + return constraint == null + || (Boolean) Ognl.getValue(constraint, bindings, (Object) null); + } catch (OgnlException ex) { + throw new EvaluationException(ex); + } + } + + public void bind(Object value) { + bindings.put("_", value); + } + + public static class EvaluationException extends RuntimeException { + private static final long serialVersionUID = Integer.MIN_VALUE; + + EvaluationException(String message) { + super(message); + } + + EvaluationException(Throwable cause) { + super(cause); + } + } + + private static class EvalMap extends HashMap { + private static final long serialVersionUID = Long.MIN_VALUE; + + @Override public Object get(Object key) { + if (!containsKey(key)) { + throw new EvaluationException( + "Referring to undefined variable '" + key + "']"); + } + return super.get(key); + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/ConstructorInvokingStringConversion.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/ConstructorInvokingStringConversion.java new file mode 100644 index 0000000000..644d19f3be --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/ConstructorInvokingStringConversion.java @@ -0,0 +1,48 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.conversion; + +import org.utbot.quickcheck.conversion.StringConversion; + +import java.lang.reflect.Constructor; + +import static org.utbot.quickcheck.internal.Reflection.reflectionException; + +public class ConstructorInvokingStringConversion implements StringConversion { + private final Constructor ctor; + + ConstructorInvokingStringConversion(Constructor ctor) { + this.ctor = ctor; + } + + @Override public Object convert(String raw) { + try { + return ctor.newInstance(raw); + } catch (Exception ex) { + throw reflectionException(ex); + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/MethodInvokingStringConversion.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/MethodInvokingStringConversion.java new file mode 100644 index 0000000000..4d07aa3488 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/MethodInvokingStringConversion.java @@ -0,0 +1,48 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.conversion; + +import org.utbot.quickcheck.conversion.StringConversion; + +import java.lang.reflect.Method; + +import static org.utbot.quickcheck.internal.Reflection.reflectionException; + +public class MethodInvokingStringConversion implements StringConversion { + private final Method method; + + MethodInvokingStringConversion(Method method) { + this.method = method; + } + + @Override public Object convert(String raw) { + try { + return method.invoke(null, raw); + } catch (Exception ex) { + throw reflectionException(ex); + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/StringConversions.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/StringConversions.java new file mode 100644 index 0000000000..9fe2ca44fe --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/StringConversions.java @@ -0,0 +1,97 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.conversion; + +import org.utbot.quickcheck.conversion.StringConversion; +import org.utbot.quickcheck.generator.Also; +import org.utbot.quickcheck.generator.Only; +import org.utbot.quickcheck.internal.ParameterTypeContext; +import org.utbot.quickcheck.internal.ReflectionException; +import org.utbot.quickcheck.internal.conversion.ConstructorInvokingStringConversion; +import org.utbot.quickcheck.internal.conversion.MethodInvokingStringConversion; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +import static org.utbot.quickcheck.internal.Reflection.*; + +public final class StringConversions { + private StringConversions() { + throw new UnsupportedOperationException(); + } + + public static StringConversion to(Class clazz) { + Class wrapped = maybeWrap(clazz); + + try { + Method method = + findMethod(clazz, "valueOf", String.class); + if (Modifier.isStatic(method.getModifiers()) + && wrapped.equals(method.getReturnType())) { + + return new MethodInvokingStringConversion(method); + } + } catch (ReflectionException reserveJudgment) { + // fall back to other means of conversion + } + + if (Character.class.equals(wrapped)) + return characterConversion(clazz); + + return new ConstructorInvokingStringConversion( + findConstructor(wrapped, String.class)); + } + + public static StringConversion decide(ParameterTypeContext p, Only only) { + return decide(p, only.by(), Only.class); + } + + public static StringConversion decide(ParameterTypeContext p, Also also) { + return decide(p, also.by(), Also.class); + } + + private static StringConversion decide( + ParameterTypeContext p, + Class custom, + Class markerClass) { + + return custom.equals(defaultValueOf(markerClass, "by")) + ? to(p.getRawClass()) + : instantiate(custom); + } + + private static StringConversion characterConversion(Class clazz) { + return raw -> { + if (raw.length() > 1) { + throw new IllegalArgumentException( + "Cannot convert " + raw + " into an instance of " + clazz); + } + + return raw.charAt(0); + }; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java new file mode 100644 index 0000000000..7e49215568 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java @@ -0,0 +1,65 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.internal.GeometricDistribution; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +abstract class AbstractGenerationStatus implements GenerationStatus { + private final GeometricDistribution distro; + private final SourceOfRandomness random; + private final Map, Object> contextValues = new HashMap<>(); + + AbstractGenerationStatus( + GeometricDistribution distro, + SourceOfRandomness random) { + + this.distro = distro; + this.random = random; + } + + @Override public GenerationStatus setValue(Key key, T value) { + contextValues.put(key, value); + return this; + } + + @Override public Optional valueOf(Key key) { + return Optional.ofNullable(key.cast(contextValues.get(key))); + } + + @Override public int size() { + return distro.sampleWithMean(attempts() + 1, random); + } + + protected final SourceOfRandomness random() { + return random; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java new file mode 100644 index 0000000000..9797644e87 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java @@ -0,0 +1,229 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import javassist.bytecode.ByteArray; +import org.antlr.runtime.misc.IntArray; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.concrete.UtModelConstructor; +import org.utbot.framework.plugin.api.ClassId; +import org.utbot.framework.plugin.api.UtArrayModel; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.framework.plugin.api.UtNullModel; +import org.utbot.framework.plugin.api.util.IdUtilKt; +import org.utbot.quickcheck.generator.*; +import org.utbot.quickcheck.internal.Lists; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Array; +import java.math.BigDecimal; +import java.util.*; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static java.math.BigDecimal.ZERO; +import static java.util.stream.Collectors.toList; +import static java.util.stream.StreamSupport.stream; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Lists.removeFrom; +import static org.utbot.quickcheck.internal.Lists.shrinksOfOneItem; +import static org.utbot.quickcheck.internal.Ranges.Type.INTEGRAL; +import static org.utbot.quickcheck.internal.Ranges.checkRange; +import static org.utbot.quickcheck.internal.Reflection.annotatedComponentTypes; +import static org.utbot.quickcheck.internal.Sequences.halving; + +public class ArrayGenerator extends Generator { + private final Class componentType; + private final Generator component; + + private Size lengthRange; + private boolean distinct; + + ArrayGenerator(Class componentType, Generator component) { + super(Object.class); + + this.componentType = componentType; + this.component = component; + } + + public Generator getComponent() { + return component; + } + + /** + * Tells this generator to produce values with a length within a specified + * minimum and/or maximum, inclusive, chosen with uniform distribution. + * + * @param size annotation that gives the length constraints + */ + public void configure(Size size) { + this.lengthRange = size; + checkRange(INTEGRAL, size.min(), size.max()); + } + + /** + * Tells this generator to produce values which are distinct from each + * other. + * + * @param distinct Generated values will be distinct if this param is not + * null. + */ + public void configure(Distinct distinct) { + this.distinct = distinct != null; + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + int length = length(random, status); + final ClassId componentTypeId = classIdForType(componentType); + + final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); + final int modelId = modelConstructor.computeUnusedIdAndUpdate(); + final Map stores = new HashMap<>(); + final UtModel generatedModel = new UtArrayModel( + modelId, getClassIdForArrayType(componentType), length, IdUtilKt.defaultValueModel(componentTypeId), stores + ); + + for (int i = 0; i < length; ++i) { + final UtModel item = component.generate(random, status); + stores.put(i, item); + } + + return generatedModel; + } + private ClassId getClassIdForArrayType(Class componentType) { + if (int.class.equals(componentType)) { + return new ClassId("[i", classIdForType(int.class)); + } else if (boolean.class.equals(componentType)) { + return new ClassId("[z", classIdForType(boolean.class)); + } else if (byte.class.equals(componentType)) { + return new ClassId("[b", classIdForType(byte.class)); + } else if (char.class.equals(componentType)) { + return new ClassId("[c", classIdForType(char.class)); + } else if (double.class.equals(componentType)) { + return new ClassId("[d", classIdForType(double.class)); + } else if (float.class.equals(componentType)) { + return new ClassId("[f", classIdForType(float.class)); + } else if (long.class.equals(componentType)) { + return new ClassId("[j", classIdForType(long.class)); + } else if (short.class.equals(componentType)) { + return new ClassId("[s", classIdForType(short.class)); + } else { + return new ClassId("[L", classIdForType(componentType)); + } + } + @Override public boolean canShrink(Object larger) { + return larger.getClass().getComponentType() == componentType; + } + + @Override public List doShrink( + SourceOfRandomness random, + Object larger) { + + int length = Array.getLength(larger); + List asList = new ArrayList<>(); + for (int i = 0; i < length; ++i) { + asList.add(Array.get(larger, i)); + } + + List shrinks = new ArrayList<>(removals(asList)); + + @SuppressWarnings("unchecked") + Stream> oneItemShrinks = + shrinksOfOneItem(random, asList, (Shrink) component) + .stream(); + if (distinct) { + oneItemShrinks = oneItemShrinks.filter(Lists::isDistinct); + } + + shrinks.addAll( + oneItemShrinks + .map(this::convert) + .filter(this::inLengthRange) + .collect(toList())); + + return shrinks; + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + component.provide(provided); + } + + @Override public BigDecimal magnitude(Object value) { + int length = Array.getLength(value); + if (length == 0) + return ZERO; + + BigDecimal elementsMagnitude = + IntStream.range(0, length) + .mapToObj(i -> component.magnitude(Array.get(value, i))) + .reduce(ZERO, BigDecimal::add); + return BigDecimal.valueOf(length).multiply(elementsMagnitude); + } + + @Override public void configure(AnnotatedType annotatedType) { + super.configure(annotatedType); + + List annotated = annotatedComponentTypes(annotatedType); + if (!annotated.isEmpty()) { + component.configure(annotated.get(0)); + } + } + + private int length(SourceOfRandomness random, GenerationStatus status) { + return lengthRange != null + ? random.nextInt(lengthRange.min(), lengthRange.max()) + : status.size(); + } + + private boolean inLengthRange(Object items) { + int length = Array.getLength(items); + return lengthRange == null + || (length >= lengthRange.min() && length <= lengthRange.max()); + } + + private List removals(List items) { + return stream(halving(items.size()).spliterator(), false) + .map(i -> removeFrom(items, i)) + .flatMap(Collection::stream) + .map(this::convert) + .filter(this::inLengthRange) + .collect(toList()); + } + + private Object convert(List items) { + Object array = Array.newInstance(componentType, items.size()); + for (int i = 0; i < items.size(); ++i) { + Array.set(array, i, items.get(i)); + } + return array; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java new file mode 100644 index 0000000000..49dafb4ac2 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java @@ -0,0 +1,175 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.GeneratorConfigurationException; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.internal.Items; +import org.utbot.quickcheck.internal.Weighted; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.AnnotatedType; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import static java.util.stream.Collectors.toList; + +public class CompositeGenerator extends Generator { + private final List>> composed; + + CompositeGenerator(List>> composed) { + super(Object.class); + + this.composed = new ArrayList<>(composed); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + Generator choice = Items.chooseWeighted(composed, random); + return choice.generate(random, status); + } + + @Override public boolean canShrink(Object larger) { + return composed.stream() + .map(w -> w.item) + .anyMatch(g -> g.canShrink(larger)); + } + + @Override public List doShrink( + SourceOfRandomness random, + Object larger) { + + List>> shrinkers = + composed.stream() + .filter(w -> w.item.canShrink(larger)) + .collect(toList()); + + Generator choice = Items.chooseWeighted(shrinkers, random); + return new ArrayList<>(choice.shrink(random, larger)); + } + + Generator composed(int index) { + return composed.get(index).item; + } + + int numberOfComposedGenerators() { + return composed.size(); + } + + @Override public void provide(Generators provided) { + super.provide(provided); + + for (Weighted> each : composed) + each.item.provide(provided); + } + + @Override public BigDecimal magnitude(Object value) { + List>> shrinkers = + composed.stream() + .filter(w -> w.item.canShrink(value)) + .collect(toList()); + + return shrinkers.get(0).item.magnitude(value); + } + + @Override public void configure(AnnotatedType annotatedType) { + List>> candidates = new ArrayList<>(composed); + + for (Iterator>> it = candidates.iterator(); + it.hasNext();) { + + try { + it.next().item.configure(annotatedType); + } catch (GeneratorConfigurationException e) { + it.remove(); + } + } + + installCandidates(candidates, annotatedType); + } + + @Override public void configure(AnnotatedElement element) { + List>> candidates = new ArrayList<>(composed); + + for (Iterator>> it = candidates.iterator(); + it.hasNext();) { + + try { + it.next().item.configure(element); + } catch (GeneratorConfigurationException e) { + it.remove(); + } + } + + installCandidates(candidates, element); + } + + @Override public void addComponentGenerators(List> newComponents) { + for (Weighted> each : composed) { + each.item.addComponentGenerators(newComponents); + } + } + + private void installCandidates( + List>> candidates, + AnnotatedElement element) { + + if (candidates.isEmpty()) { + throw new GeneratorConfigurationException( + String.format( + "None of the candidate generators %s" + + " understands all of the configuration annotations %s", + candidateGeneratorDescriptions(), + configurationAnnotationNames(element))); + } + + composed.clear(); + composed.addAll(candidates); + } + + private String candidateGeneratorDescriptions() { + return composed.stream() + .map(w -> w.item.getClass().getName()) + .collect(toList()) + .toString(); + } + + private static List configurationAnnotationNames( + AnnotatedElement element) { + + return configurationAnnotationsOn(element).stream() + .map(a -> a.annotationType().getName()) + .collect(toList()); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java new file mode 100644 index 0000000000..6c2196c57f --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java @@ -0,0 +1,57 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +public class EnumGenerator extends Generator { + private final Class enumType; + + EnumGenerator(Class enumType) { + super(Enum.class); + + this.enumType = enumType; + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + Object[] values = enumType.getEnumConstants(); + int index = random.nextInt(0, values.length - 1); + return UtModelGenerator.getUtModelConstructor().construct(values[index], classIdForType(Enum.class)); + } + + @Override public boolean canShrink(Object larger) { + return enumType.isInstance(larger); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ExhaustiveDomainGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ExhaustiveDomainGenerator.java new file mode 100644 index 0000000000..d7a1ff37d2 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ExhaustiveDomainGenerator.java @@ -0,0 +1,66 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.*; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; + +public class ExhaustiveDomainGenerator extends Generator { + private final Iterator items; + + public ExhaustiveDomainGenerator(Collection items) { + super(Object.class); + + List list = new ArrayList<>(new HashSet<>(items)); + + try { + Collections.sort(list); + } catch (ClassCastException forgiven) { + // non-Comparable types such as Target type will go through + // this exception which cannot be sorted. + } + + this.items = list.iterator(); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(items.next(), getObjectClassId()); + } + + boolean hasNext() { + return items.hasNext(); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java new file mode 100644 index 0000000000..32c5c22a7a --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java @@ -0,0 +1,443 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.quickcheck.generator.*; +import org.utbot.quickcheck.internal.ParameterTypeContext; +import org.utbot.quickcheck.internal.Weighted; +import org.utbot.quickcheck.internal.Zilch; +import org.utbot.quickcheck.internal.generator.ArrayGenerator; +import org.utbot.quickcheck.random.SourceOfRandomness; +import org.javaruntype.type.TypeParameter; + +import java.lang.annotation.Annotation; +import java.lang.reflect.*; +import java.util.*; +import java.util.stream.Stream; + +import static org.utbot.quickcheck.internal.Items.choose; +import static org.utbot.quickcheck.internal.Reflection.*; +import static java.util.Arrays.asList; +import static java.util.Collections.unmodifiableSet; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; + +public class GeneratorRepository implements Generators { + private static final Set NULLABLE_ANNOTATIONS = + unmodifiableSet( + Stream.of( + "javax.annotation.Nullable", // JSR-305 + NullAllowed.class.getCanonicalName()) + .collect(toSet())); + + private final SourceOfRandomness random; + + private final Map, Set>> generators; + + public GeneratorRepository(SourceOfRandomness random) { + this(random, new HashMap<>()); + } + + private GeneratorRepository( + SourceOfRandomness random, + Map, Set>> generators) { + + this.random = random; + this.generators = generators; + } + + public Map, Set>> getGenerators() { + return generators; + } + + public void addUserClassGenerator(Class forClass, Generator source) { + generators.put(forClass, Set.of(source)); + } + + public void removeGenerator(Class forClass) { + generators.remove(forClass); + } + + public void removeGeneratorForObjectClass() { + generators.remove(Object.class); + } + + public GeneratorRepository register(Generator source) { + registerTypes(source); + return this; + } + + public GeneratorRepository register(Iterable> source) { + for (Generator each : source) + registerTypes(each); + + return this; + } + + private void registerTypes(Generator generator) { + for (Class each : generator.types()) + registerHierarchy(each, generator); + } + + private void registerHierarchy(Class type, Generator generator) { + maybeRegisterGeneratorForType(type, generator); + + if (type.getSuperclass() != null) + registerHierarchy(type.getSuperclass(), generator); + else if (type.isInterface()) + registerHierarchy(Object.class, generator); + + for (Class each : type.getInterfaces()) + registerHierarchy(each, generator); + } + + private void maybeRegisterGeneratorForType( + Class type, + Generator generator) { + + if (generator.canRegisterAsType(type)) + registerGeneratorForType(type, generator); + } + + private void registerGeneratorForType( + Class type, + Generator generator) { + + Set> forType = + generators.computeIfAbsent(type, k -> new LinkedHashSet<>()); + + forType.add(generator); + } + + @Override public Generator field(Class type, String fieldName) { + return field(findField(type, fieldName)); + } + + @Override public Generator constructor( + Class type, + Class... argumentTypes) { + + Constructor constructor = findConstructor(type, argumentTypes); + Ctor ctor = new Ctor<>(constructor); + ctor.provide(this); + ctor.configure(constructor.getAnnotatedReturnType()); + + return ctor; + } + + @Override public Generator fieldsOf(Class type) { + Fields fields = new Fields<>(type); + + fields.provide(this); + fields.configure(type); + + return fields; + } + + @SuppressWarnings("unchecked") + @Override public Generator type( + Class type, + Class... componentTypes) { + + Generator generator = + (Generator) produceGenerator( + ParameterTypeContext.forClass(type)); + generator.addComponentGenerators( + Arrays.stream(componentTypes).map(c -> type(c)).collect(toList())); + return generator; + } + + @Override public Generator parameter(Parameter parameter) { + return produceGenerator( + ParameterTypeContext.forParameter(parameter).annotate(parameter)); + } + + @Override public Generator field(Field field) { + return produceGenerator( + ParameterTypeContext.forField(field).annotate(field)); + } + + @SafeVarargs + @SuppressWarnings("unchecked") + @Override public final Generator oneOf( + Class first, + Class... rest) { + + return oneOf( + type(first), + Arrays.stream(rest) + .map(t -> type(t)) + .toArray(Generator[]::new)); + } + + @SafeVarargs + @SuppressWarnings("unchecked") + @Override public final Generator oneOf( + Generator first, + Generator... rest) { + + if (rest.length == 0) + return (Generator) first; + + List> gens = new ArrayList<>(); + gens.add(first); + Collections.addAll(gens, rest); + + List>> weightings = gens.stream() + .map(g -> new Weighted>(g, 1)) + .collect(toList()); + + return (Generator) new CompositeGenerator(weightings); + } + + @Override public final > T make( + Class genType, + Generator... components) { + + T generator = instantiate(genType); + generator.provide(this); + generator.configure(genType); + generator.addComponentGenerators(asList(components)); + + return generator; + } + + @Override public final Generators withRandom(SourceOfRandomness other) { + return new GeneratorRepository(other, this.generators); + } + + public Generator produceGenerator(ParameterTypeContext parameter) { + Generator generator = generatorFor(parameter); + + if (!isPrimitiveType(parameter.annotatedType().getType()) + && hasNullableAnnotation(parameter.annotatedElement())) { + + generator = new NullableGenerator<>(generator); + } + + generator.provide(this); + generator.configure(parameter.annotatedType()); + if (parameter.topLevel()) + generator.configure(parameter.annotatedElement()); + + return generator; + } + + public Generator generatorFor(ParameterTypeContext parameter) { + if (!parameter.explicitGenerators().isEmpty()) + return composeWeighted(parameter, parameter.explicitGenerators()); + if (parameter.isArray()) + return generatorForArrayType(parameter); + if (parameter.isEnum()) + return new EnumGenerator(parameter.getRawClass()); + + return compose(parameter, matchingGenerators(parameter)); + } + + private Generator generatorForArrayType( + ParameterTypeContext parameter) { + + ParameterTypeContext component = parameter.arrayComponentContext(); + return new ArrayGenerator( + component.getRawClass(), + generatorFor(component)); + } + + private List> matchingGenerators( + ParameterTypeContext parameter) { + + List> matches = new ArrayList<>(); + + if (!hasGeneratorsFor(parameter)) { + maybeAddGeneratorByNamingConvention(parameter, matches); + maybeAddLambdaGenerator(parameter, matches); + maybeAddMarkerInterfaceGenerator(parameter, matches); + } else { + maybeAddGeneratorsFor(parameter, matches); + } + if (matches.isEmpty()) { + throw new IllegalArgumentException( + "Cannot find generator for " + parameter.name() + + " of type " + parameter.type().getTypeName()); + } + + return matches; + } + + private void maybeAddGeneratorByNamingConvention( + ParameterTypeContext parameter, + List> matches) { + + Class genClass; + try { + genClass = + Class.forName(parameter.getRawClass().getName() + "Gen"); + } catch (ClassNotFoundException noGenObeyingConvention) { + return; + } + + if (Generator.class.isAssignableFrom(genClass)) { + try { + Generator generator = (Generator) genClass.newInstance(); + if (generator.types().contains(parameter.getRawClass())) { + matches.add(generator); + } + } catch (IllegalAccessException | InstantiationException e) { + throw new IllegalStateException( + "Cannot instantiate " + genClass.getName() + + " using default constructor"); + } + } + } + + private void maybeAddLambdaGenerator( + ParameterTypeContext parameter, + List> matches) { + + Method method = singleAbstractMethodOf(parameter.getRawClass()); + if (method != null) { + ParameterTypeContext returnType = + parameter.methodReturnTypeContext(method); + Generator returnTypeGenerator = generatorFor(returnType); + + matches.add( + new LambdaGenerator<>( + parameter.getRawClass(), + returnTypeGenerator)); + } + } + + private void maybeAddMarkerInterfaceGenerator( + ParameterTypeContext parameter, + List> matches) { + + Class rawClass = parameter.getRawClass(); + if (isMarkerInterface(rawClass)) { + matches.add( + new MarkerInterfaceGenerator<>(parameter.getRawClass())); + } + } + + private void maybeAddGeneratorsFor( + ParameterTypeContext parameter, + List> matches) { + + List> candidates = generatorsFor(parameter); + List> typeParameters = parameter.getTypeParameters(); + + if (typeParameters.isEmpty()) { + matches.addAll(candidates); + } else { + for (Generator each : candidates) { + if (each.canGenerateForParametersOfTypes(typeParameters)) + matches.add(each); + } + } + } + + private Generator compose( + ParameterTypeContext parameter, + List> matches) { + + List>> weightings = + matches.stream() + .map(g -> new Weighted>(g, 1)) + .collect(toList()); + + return composeWeighted(parameter, weightings); + } + + private Generator composeWeighted( + ParameterTypeContext parameter, + List>> matches) { + + List> forComponents = new ArrayList<>(); + for (ParameterTypeContext c : parameter.typeParameterContexts(random)) + forComponents.add(generatorFor(c)); + + for (Weighted> each : matches) + applyComponentGenerators(each.item, forComponents); + + return matches.size() == 1 + ? matches.get(0).item + : new CompositeGenerator(matches); + } + + private void applyComponentGenerators( + Generator generator, + List> componentGenerators) { + + if (!generator.hasComponents()) + return; + + if (componentGenerators.isEmpty()) { + List> substitutes = new ArrayList<>(); + Generator zilch = + generatorFor( + ParameterTypeContext.forClass(Zilch.class) + .allowMixedTypes(true)); + for (int i = 0; i < generator.numberOfNeededComponents(); ++i) { + substitutes.add(zilch); + } + + generator.addComponentGenerators(substitutes); + } else { + generator.addComponentGenerators(componentGenerators); + } + } + + private List> generatorsFor(ParameterTypeContext parameter) { + Set> matches = generators.get(parameter.getRawClass()); + + if (!parameter.allowMixedTypes()) { + Generator match = choose(matches, random); + matches = new HashSet<>(); + matches.add(match); + } + + List> copies = new ArrayList<>(); + for (Generator each : matches) { + copies.add(each.copy()); + } + return copies; + } + + private boolean hasGeneratorsFor(ParameterTypeContext parameter) { + return generators.get(parameter.getRawClass()) != null; + } + + private static boolean isPrimitiveType(Type type) { + return type instanceof Class && ((Class) type).isPrimitive(); + } + + private static boolean hasNullableAnnotation(AnnotatedElement element) { + return element != null + && Arrays.stream(element.getAnnotations()) + .map(Annotation::annotationType) + .map(Class::getCanonicalName) + .anyMatch(NULLABLE_ANNOTATIONS::contains); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GuaranteeValuesGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GuaranteeValuesGenerator.java new file mode 100644 index 0000000000..7f46f126bc --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GuaranteeValuesGenerator.java @@ -0,0 +1,58 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.internal.generator.ExhaustiveDomainGenerator; +import org.utbot.quickcheck.random.SourceOfRandomness; + + +public class GuaranteeValuesGenerator extends Generator { + private final ExhaustiveDomainGenerator guaranteed; + private final Generator rest; + + + public GuaranteeValuesGenerator( + ExhaustiveDomainGenerator guaranteed, + Generator rest) { + + super(Object.class); + + this.guaranteed = guaranteed; + this.rest = rest; + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return guaranteed.hasNext() + ? guaranteed.generate(random, status) + : rest.generate(random, status); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java new file mode 100644 index 0000000000..8e029899e1 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java @@ -0,0 +1,54 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.framework.plugin.api.UtNullModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.generator.Lambdas.makeLambda; + +public class LambdaGenerator extends Generator { + private final Class lambdaType; + private final Generator returnValueGenerator; + + LambdaGenerator(Class lambdaType, Generator returnValueGenerator) { + super(lambdaType); + + this.lambdaType = lambdaType; + this.returnValueGenerator = returnValueGenerator; + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return new UtNullModel(classIdForType(Object.class));//makeLambda(lambdaType, returnValueGenerator, status); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java new file mode 100644 index 0000000000..4f53f30d30 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java @@ -0,0 +1,118 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.internal.DefaultMethodHandleMaker; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.lang.invoke.MethodHandle; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +import static java.lang.System.identityHashCode; +import static java.lang.reflect.Proxy.newProxyInstance; +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +public class MarkerInterfaceGenerator extends Generator { + private final Class markerType; + + MarkerInterfaceGenerator(Class markerType) { + super(markerType); + + this.markerType = markerType; + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + return UtModelGenerator.getUtModelConstructor().construct(markerType.cast( + newProxyInstance( + markerType.getClassLoader(), + new Class[] { markerType }, + new MarkerInvocationHandler<>(markerType))), classIdForType(markerType)); +// return markerType.cast( +// newProxyInstance( +// markerType.getClassLoader(), +// new Class[] { markerType }, +// new MarkerInvocationHandler<>(markerType))); + } + + private static class MarkerInvocationHandler + implements InvocationHandler { + + private final Class markerType; + private final DefaultMethodHandleMaker methodHandleMaker = + new DefaultMethodHandleMaker(); + + MarkerInvocationHandler(Class markerType) { + this.markerType = markerType; + } + + @Override + public Object invoke(Object proxy, Method method, Object[] args) + throws Throwable { + + if (Object.class.equals(method.getDeclaringClass())) + return handleObjectMethod(proxy, method, args); + if (method.isDefault()) + return handleDefaultMethod(proxy, method, args); + + return null; + } + + private Object handleObjectMethod( + Object proxy, + Method method, + Object[] args) { + + if ("equals".equals(method.getName())) + return proxy == args[0]; + if ("hashCode".equals(method.getName())) + return identityHashCode(proxy); + + return handleToString(); + } + + private Object handleDefaultMethod( + Object proxy, + Method method, + Object[] args) + throws Throwable { + + MethodHandle handle = + methodHandleMaker.handleForSpecialMethod(method); + return handle.bindTo(proxy).invokeWithArguments(args); + } + + private String handleToString() { + return "a synthetic instance of " + markerType; + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java new file mode 100644 index 0000000000..b1cb174bd7 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java @@ -0,0 +1,124 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ +package org.utbot.quickcheck.internal.generator; + +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.framework.plugin.api.UtNullModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Generators; +import org.utbot.quickcheck.generator.NullAllowed; +import org.utbot.quickcheck.random.SourceOfRandomness; +import org.javaruntype.type.TypeParameter; + +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.AnnotatedType; +import java.math.BigDecimal; +import java.util.List; +import java.util.Optional; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; + +class NullableGenerator extends Generator { + private final Generator delegate; + private double probabilityOfNull = + (Double) defaultValueOf(NullAllowed.class, "probability"); + + NullableGenerator(Generator delegate) { + super(delegate.types()); + + this.delegate = delegate; + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return random.nextFloat(0, 1) < probabilityOfNull + ? new UtNullModel(classIdForType(types().get(0))) + : delegate.generate(random, status); + } + + @Override public boolean canRegisterAsType(Class type) { + return delegate.canRegisterAsType(type); + } + + @Override public boolean hasComponents() { + return delegate.hasComponents(); + } + + @Override public int numberOfNeededComponents() { + return delegate.numberOfNeededComponents(); + } + + @Override public void addComponentGenerators( + List> newComponents) { + + delegate.addComponentGenerators(newComponents); + } + + @Override public boolean canGenerateForParametersOfTypes( + List> typeParameters) { + + return delegate.canGenerateForParametersOfTypes(typeParameters); + } + + @Override public void configure(AnnotatedType annotatedType) { + Optional.ofNullable(annotatedType.getAnnotation(NullAllowed.class)) + .ifPresent(this::configure); + + delegate.configure(annotatedType); + } + + @Override public void configure(AnnotatedElement element) { + delegate.configure(element); + } + + @Override public void provide(Generators provided) { + delegate.provide(provided); + } + + @Override public boolean canShrink(Object larger) { + return delegate.canShrink(larger); + } + + @Override public List doShrink(SourceOfRandomness random, T larger) { + return delegate.doShrink(random, larger); + } + + @Override public BigDecimal magnitude(Object value) { + return delegate.magnitude(value); + } + + private void configure(NullAllowed allowed) { + if (allowed.probability() >= 0 && allowed.probability() <= 1) { + this.probabilityOfNull = allowed.probability(); + } else { + throw new IllegalArgumentException( + "NullAllowed probability must be in the range [0, 1]"); + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/PropertyParameterGenerationContext.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/PropertyParameterGenerationContext.java new file mode 100644 index 0000000000..7c7b4fb6bc --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/PropertyParameterGenerationContext.java @@ -0,0 +1,182 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.internal.GeometricDistribution; +import org.utbot.quickcheck.internal.ParameterSampler; +import org.utbot.quickcheck.internal.PropertyParameterContext; +import org.utbot.quickcheck.internal.constraint.ConstraintEvaluator; +import org.utbot.quickcheck.internal.generator.GeneratorRepository; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.List; + +import static java.lang.Math.min; +import static java.lang.String.format; +import static java.math.BigDecimal.ZERO; +import static java.util.Collections.emptyList; + +public class PropertyParameterGenerationContext + extends org.utbot.quickcheck.internal.generator.AbstractGenerationStatus { + + private final PropertyParameterContext parameter; + private final ConstraintEvaluator evaluator; + private final Generator generator; + private final int sampleSize; + + private int successfulEvaluations; + private int discards; + private int semiAttempts; + + public PropertyParameterGenerationContext( + PropertyParameterContext parameter, + GeneratorRepository repository, + GeometricDistribution distro, + SourceOfRandomness random, + ParameterSampler sampler) { + + super(distro, initializeRandomness(parameter, random)); + + this.parameter = parameter; + this.evaluator = new ConstraintEvaluator(parameter.constraint()); + this.generator = + sampler.decideGenerator(repository, parameter.typeContext()); + this.sampleSize = sampler.sizeFactor(parameter.typeContext()); + } + + private static SourceOfRandomness initializeRandomness( + PropertyParameterContext p, + SourceOfRandomness r) { + + if (p.fixedSeed()) + r.setSeed(p.seed()); + + return r; + } + + public Object generate() { + Object nextValue; + + for (nextValue = generator.generate(random(), this); + !evaluate(nextValue);) { + + nextValue = generator.generate(random(), this); + } + + return nextValue; + } + + public List shrink(Object larger) { + return generator.canShrink(larger) + ? new ArrayList<>(generator.shrink(random(), larger)) + : emptyList(); + } + + private boolean evaluate(Object value) { + evaluator.bind(value); + boolean result = evaluator.evaluate(); + + if (result) { + ++successfulEvaluations; + } else { + ++discards; + } + + if (tooManyDiscards()) { + throw new DiscardRatioExceededException( + parameter, + discards, + successfulEvaluations); + } + + return result; + } + + private boolean tooManyDiscards() { + if (parameter.discardRatio() == 0) + return discards > sampleSize(); + + return successfulEvaluations == 0 + ? discards > parameter.discardRatio() + : (discards / successfulEvaluations) >= parameter.discardRatio(); + } + + @Override public int size() { + return min(super.size(), sampleSize()); + } + + @Override public int attempts() { + return successfulEvaluations + discards + (semiAttempts / 10); + } + + @Override public void semiAttempt() { + ++semiAttempts; + } + + public long effectiveSeed() { + return random().seed(); + } + + public int sampleSize() { + return sampleSize; + } + + public String name() { + return parameter.typeContext().name(); + } + + public BigDecimal magnitude(Object value) { + return generator.canShrink(value) + ? generator.magnitude(value).abs() + : ZERO; + } + + public static class DiscardRatioExceededException + extends RuntimeException { + + static final String MESSAGE_TEMPLATE = + "For parameter [%s] with discard ratio [%d]," + + " %d unsuccessful values and %d successes. Stopping."; + + private static final long serialVersionUID = Long.MIN_VALUE; + + DiscardRatioExceededException( + PropertyParameterContext parameter, + int discards, + int successfulEvaluations) { + + super(format( + MESSAGE_TEMPLATE, + parameter.typeContext().name(), + parameter.discardRatio(), + discards, + successfulEvaluations)); + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SamplingDomainGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SamplingDomainGenerator.java new file mode 100644 index 0000000000..ac04034b2d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SamplingDomainGenerator.java @@ -0,0 +1,55 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; + +public class SamplingDomainGenerator extends Generator { + private final List items; + + public SamplingDomainGenerator(Set items) { + super(Object.class); + + this.items = new ArrayList<>(items); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(random.choose(items), getObjectClassId()); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ServiceLoaderGeneratorSource.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ServiceLoaderGeneratorSource.java new file mode 100644 index 0000000000..8f7b0c4896 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ServiceLoaderGeneratorSource.java @@ -0,0 +1,57 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.quickcheck.generator.Generator; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ServiceLoader; + +import static java.util.Collections.unmodifiableList; +import static java.util.Comparator.comparing; + +public class ServiceLoaderGeneratorSource implements Iterable> { + @SuppressWarnings("rawtypes") + private final ServiceLoader loader; + + public ServiceLoaderGeneratorSource() { + loader = ServiceLoader.load(Generator.class); + } + + @Override public Iterator> iterator() { + List> generators = new ArrayList<>(); + + for (Generator each : loader) { + generators.add(each); + } + + generators.sort(comparing(g -> g.getClass().getName())); + + return unmodifiableList(generators).iterator(); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java new file mode 100644 index 0000000000..4cd741d482 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java @@ -0,0 +1,46 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.quickcheck.internal.GeometricDistribution; +import org.utbot.quickcheck.random.SourceOfRandomness; + +public class SimpleGenerationStatus extends org.utbot.quickcheck.internal.generator.AbstractGenerationStatus { + private final int attempts; + + public SimpleGenerationStatus( + GeometricDistribution distro, + SourceOfRandomness random, + int attempts) { + + super(distro, random); + this.attempts = attempts; + } + + @Override public int attempts() { + return attempts; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java new file mode 100644 index 0000000000..fc6ab5e63d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java @@ -0,0 +1,48 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.generator; + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; +import org.utbot.framework.plugin.api.UtModel; +import org.utbot.quickcheck.generator.GenerationStatus; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.internal.Zilch; +import org.utbot.quickcheck.random.SourceOfRandomness; + +import static org.utbot.external.api.UtModelFactoryKt.classIdForType; + +public class ZilchGenerator extends Generator { + public ZilchGenerator() { + super(Zilch.class); + } + + @Override public UtModel generate( + SourceOfRandomness random, + GenerationStatus status) { + + return UtModelGenerator.getUtModelConstructor().construct(Zilch.INSTANCE, classIdForType(Zilch.class)); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/ExhaustiveParameterSampler.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/ExhaustiveParameterSampler.java new file mode 100644 index 0000000000..67d8ff97b8 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/ExhaustiveParameterSampler.java @@ -0,0 +1,139 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.sampling; + +import org.utbot.quickcheck.conversion.StringConversion; +import org.utbot.quickcheck.generator.Also; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Only; +import org.utbot.quickcheck.internal.CartesianIterator; +import org.utbot.quickcheck.internal.ParameterSampler; +import org.utbot.quickcheck.internal.ParameterTypeContext; +import org.utbot.quickcheck.internal.SeededValue; +import org.utbot.quickcheck.internal.conversion.StringConversions; +import org.utbot.quickcheck.internal.generator.ExhaustiveDomainGenerator; +import org.utbot.quickcheck.internal.generator.GeneratorRepository; +import org.utbot.quickcheck.internal.generator.GuaranteeValuesGenerator; +import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; + +import java.lang.reflect.Array; +import java.util.*; +import java.util.stream.Stream; +import java.util.stream.StreamSupport; + +import static org.utbot.quickcheck.internal.Reflection.*; +import static java.lang.Math.max; +import static java.util.Arrays.asList; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; + +public class ExhaustiveParameterSampler implements ParameterSampler { + private final int sizeFactor; + + public ExhaustiveParameterSampler(int sizeFactor) { + this.sizeFactor = sizeFactor; + } + + @Override public int sizeFactor(ParameterTypeContext p) { + Only only = p.annotatedType().getAnnotation(Only.class); + if (only != null) + return new HashSet<>(asList(only.value())).size(); + + Also also = p.annotatedType().getAnnotation(Also.class); + if (also != null) + return max(sizeFactor, new HashSet<>(asList(also.value())).size()); + + if (Boolean.class.equals(maybeWrap(p.getRawClass()))) + return 2; + + if (p.isEnum()) { + return Array.getLength( + invoke( + findMethod(p.getRawClass(), "values"), + null)); + } + + return sizeFactor; + } + + @Override + public Stream> sample( + List parameters) { + + List> sources = + parameters.stream() + .map(p -> + Stream.generate(() -> new SeededValue(p)) + .limit(p.sampleSize()) + .iterator()) + .collect(toList()); + + return cartesian(sources); + } + + @Override public Generator decideGenerator( + GeneratorRepository repository, + ParameterTypeContext p) { + + Only only = p.annotatedType().getAnnotation(Only.class); + if (only != null) { + StringConversion conversion = StringConversions.decide(p, only); + Set values = + Arrays.stream(only.value()) + .map(conversion::convert) + .collect(toSet()); + return new ExhaustiveDomainGenerator(values); + } + + Also also = p.annotatedType().getAnnotation(Also.class); + if (also != null) { + StringConversion conversion = StringConversions.decide(p, also); + Set values = + Arrays.stream(also.value()) + .map(conversion::convert) + .collect(toSet()); + return new GuaranteeValuesGenerator( + new ExhaustiveDomainGenerator(values), + repository.produceGenerator(p)); + } + + if (Boolean.class.equals(maybeWrap(p.getRawClass()))) { + return new ExhaustiveDomainGenerator(asList(true, false)); + } + + if (p.isEnum()) { + return new ExhaustiveDomainGenerator( + asList(p.getRawClass().getEnumConstants())); + } + + return repository.produceGenerator(p); + } + + private Stream> cartesian(List> sources) { + Iterable> cartesian = () -> new CartesianIterator<>(sources); + return StreamSupport.stream(cartesian.spliterator(), false); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/TupleParameterSampler.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/TupleParameterSampler.java new file mode 100644 index 0000000000..fa09848233 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/TupleParameterSampler.java @@ -0,0 +1,96 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal.sampling; + +import org.utbot.quickcheck.conversion.StringConversion; +import org.utbot.quickcheck.generator.Also; +import org.utbot.quickcheck.generator.Generator; +import org.utbot.quickcheck.generator.Only; +import org.utbot.quickcheck.internal.ParameterSampler; +import org.utbot.quickcheck.internal.ParameterTypeContext; +import org.utbot.quickcheck.internal.SeededValue; +import org.utbot.quickcheck.internal.conversion.StringConversions; +import org.utbot.quickcheck.internal.generator.*; + +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Stream; + +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toSet; + +public class TupleParameterSampler implements ParameterSampler { + private final int trials; + + public TupleParameterSampler(int trials) { + this.trials = trials; + } + + @Override public int sizeFactor(ParameterTypeContext p) { + return trials; + } + + @Override public Stream> sample( + List parameters) { + + Stream> tupleStream = + Stream.generate( + () -> parameters.stream() + .map(SeededValue::new) + .collect(toList())); + return tupleStream.limit(trials); + } + + @Override public Generator decideGenerator( + GeneratorRepository repository, + ParameterTypeContext p) { + + Only only = p.annotatedType().getAnnotation(Only.class); + if (only != null) { + StringConversion conversion = StringConversions.decide(p, only); + Set values = + Arrays.stream(only.value()) + .map(conversion::convert) + .collect(toSet()); + return new SamplingDomainGenerator(values); + } + + Also also = p.annotatedType().getAnnotation(Also.class); + if (also != null) { + StringConversion conversion = StringConversions.decide(p, also); + Set values = + Arrays.stream(also.value()) + .map(conversion::convert) + .collect(toSet()); + return new GuaranteeValuesGenerator( + new ExhaustiveDomainGenerator(values), + repository.produceGenerator(p)); + } + + return repository.produceGenerator(p); + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java b/utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java new file mode 100644 index 0000000000..0e27b210e9 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java @@ -0,0 +1,402 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.random; + +import org.utbot.quickcheck.internal.Items; +import org.utbot.quickcheck.internal.Ranges; + +import java.io.*; +import java.math.BigInteger; +import java.time.Duration; +import java.time.Instant; +import java.util.Collection; +import java.util.Random; + +import static org.utbot.quickcheck.internal.Ranges.checkRange; +import static java.util.concurrent.TimeUnit.SECONDS; + +/** + * A source of randomness, fed to + * {@linkplain org.utbot.quickcheck.generator.Generator generators} + * so they can produce random values for property parameters. + */ +public class SourceOfRandomness { + private static final BigInteger NANOS_PER_SECOND = + BigInteger.valueOf(SECONDS.toNanos(1)); + + private final Random delegate; + + private long seed; + + /** + * Makes a new source of randomness. + * + * @param delegate a JDK source of randomness, to which the new instance + * will delegate + */ + + public SourceOfRandomness(Random delegate) { + seed = delegate.nextLong(); + this.delegate = delegate; + delegate.setSeed(seed); + } + + /** + *

Gives a JDK source of randomness, with the same internal state as + * this source of randomness.

+ * + * @return a JDK "clone" of self + */ + public Random toJDKRandom() { + ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); + + try (ObjectOutputStream objectOut = new ObjectOutputStream(bytesOut)) { + objectOut.writeObject(delegate); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } + + ByteArrayInputStream bytesIn = + new ByteArrayInputStream(bytesOut.toByteArray()); + + try (ObjectInputStream objectIn = new ObjectInputStream(bytesIn)) { + return (Random) objectIn.readObject(); + } catch (IOException ex) { + throw new IllegalStateException(ex); + } catch (ClassNotFoundException shouldNeverHappen) { + throw new AssertionError(shouldNeverHappen); + } + } + + /** + * @return a uniformly distributed boolean value + * @see Random#nextBoolean() + */ + public boolean nextBoolean() { + return delegate.nextBoolean(); + } + + /** + * @param bytes a byte array to fill with random values + * @see Random#nextBytes(byte[]) + */ + public void nextBytes(byte[] bytes) { + delegate.nextBytes(bytes); + } + + /** + * Gives an array of a given length containing random bytes. + * + * @param count the desired length of the random byte array + * @return random bytes + * @see Random#nextBytes(byte[]) + */ + public byte[] nextBytes(int count) { + byte[] buffer = new byte[count]; + delegate.nextBytes(buffer); + return buffer; + } + + /** + * @return a uniformly distributed random {@code double} value in the + * interval {@code [0.0, 1.0)} + * @see Random#nextDouble() + */ + public double nextDouble() { + return delegate.nextDouble(); + } + + /** + * @return a uniformly distributed random {@code float} value in the + * interval {@code [0.0, 1.0)} + * @see Random#nextFloat() + */ + public float nextFloat() { + return delegate.nextFloat(); + } + + /** + * @return a Gaussian-distributed random double value + * @see Random#nextGaussian() + */ + public double nextGaussian() { + return delegate.nextGaussian(); + } + + /** + * @return a uniformly distributed random {@code int} value + * @see Random#nextInt() + */ + public int nextInt() { + return delegate.nextInt(); + } + + /** + * @param n upper bound + * @return a uniformly distributed random {@code int} value in the interval + * {@code [0, n)} + * @see Random#nextInt(int) + */ + public int nextInt(int n) { + return delegate.nextInt(n); + } + + /** + * @return a uniformly distributed random {@code long} value + * @see Random#nextLong() + */ + public long nextLong() { + return delegate.nextLong(); + } + + /** + * @param seed value with which to seed this source of randomness + * @see Random#setSeed(long) + */ + public void setSeed(long seed) { + this.seed = seed; + delegate.setSeed(seed); + } + + /** + * @return the value used to initially seed this source of randomness + */ + public long seed() { + return seed; + } + + /** + * Gives a random {@code byte} value, uniformly distributed across the + * interval {@code [min, max]}. + * + * @param min lower bound of the desired interval + * @param max upper bound of the desired interval + * @return a random value + */ + public byte nextByte(byte min, byte max) { + return (byte) nextLong(min, max); + } + + /** + * Gives a random {@code char} value, uniformly distributed across the + * interval {@code [min, max]}. + * + * @param min lower bound of the desired interval + * @param max upper bound of the desired interval + * @return a random value + */ + public char nextChar(char min, char max) { + checkRange(Ranges.Type.CHARACTER, min, max); + + return (char) nextLong(min, max); + } + + /** + *

Gives a random {@code double} value in the interval + * {@code [min, max)}.

+ * + *

This naive implementation takes a random {@code double} value from + * {@link Random#nextDouble()} and scales/shifts the value into the desired + * interval. This may give surprising results for large ranges.

+ * + * @param min lower bound of the desired interval + * @param max upper bound of the desired interval + * @return a random value + */ + public double nextDouble(double min, double max) { + int comparison = checkRange(Ranges.Type.FLOAT, min, max); + return comparison == 0 ? min : min + (max - min) * nextDouble(); + } + + /** + *

Gives a random {@code float} value in the interval + * {@code [min, max)}.

+ * + *

This naive implementation takes a random {@code float} value from + * {@link Random#nextFloat()} and scales/shifts the value into the desired + * interval. This may give surprising results for large ranges.

+ * + * @param min lower bound of the desired interval + * @param max upper bound of the desired interval + * @return a random value + */ + public float nextFloat(float min, float max) { + int comparison = checkRange(Ranges.Type.FLOAT, min, max); + return comparison == 0 ? min : min + (max - min) * nextFloat(); + } + + /** + * Gives a random {@code int} value, uniformly distributed across the + * interval {@code [min, max]}. + * + * @param min lower bound of the desired interval + * @param max upper bound of the desired interval + * @return a random value + */ + public int nextInt(int min, int max) { + return (int) nextLong(min, max); + } + + /** + * Gives a random {@code long} value, uniformly distributed across the + * interval {@code [min, max]}. + * + * @param min lower bound of the desired interval + * @param max upper bound of the desired interval + * @return a random value + */ + public long nextLong(long min, long max) { + int comparison = checkRange(Ranges.Type.INTEGRAL, min, max); + if (comparison == 0) + return min; + + return Ranges.choose(this, min, max); + } + + /** + * Gives a random {@code short} value, uniformly distributed across the + * interval {@code [min, max]}. + * + * @param min lower bound of the desired interval + * @param max upper bound of the desired interval + * @return a random value + */ + public short nextShort(short min, short max) { + return (short) nextLong(min, max); + } + + /** + * Gives a random {@code BigInteger} representable by the given number + * of bits. + * + * @param numberOfBits the desired number of bits + * @return a random {@code BigInteger} + * @see BigInteger#BigInteger(int, Random) + */ + public BigInteger nextBigInteger(int numberOfBits) { + return new BigInteger(numberOfBits, delegate); + } + + /** + * Gives a random {@code Instant} value, uniformly distributed across the + * interval {@code [min, max]}. + * + * @param min lower bound of the desired interval + * @param max upper bound of the desired interval + * @return a random value + */ + public Instant nextInstant(Instant min, Instant max) { + int comparison = checkRange(Ranges.Type.STRING, min, max); + if (comparison == 0) + return min; + + long[] next = + nextSecondsAndNanos( + min.getEpochSecond(), + min.getNano(), + max.getEpochSecond(), + max.getNano()); + + return Instant.ofEpochSecond(next[0], next[1]); + } + + /** + * Gives a random {@code Duration} value, uniformly distributed across the + * interval {@code [min, max]}. + * + * @param min lower bound of the desired interval + * @param max upper bound of the desired interval + * @return a random value + */ + public Duration nextDuration(Duration min, Duration max) { + int comparison = checkRange(Ranges.Type.STRING, min, max); + if (comparison == 0) + return min; + + long[] next = + nextSecondsAndNanos( + min.getSeconds(), + min.getNano(), + max.getSeconds(), + max.getNano()); + + return Duration.ofSeconds(next[0], next[1]); + } + + /** + * Gives a random element of the given collection. + * + * @param type of items in the collection + * @param items a collection + * @return a randomly chosen element from the collection + */ + public T choose(Collection items) { + return Items.choose(items, this); + } + + /** + * Gives a random element of the given array. + * + * @param type of items in the array + * @param items an array + * @return a randomly chosen element from the array + */ + public T choose(T[] items) { + return items[nextInt(items.length)]; + } + + /** + * Gives a reference to the JDK-random delegate of this instance. + * Intended for subclasses. + * + * @return the JDK-random delegate + */ + protected final Random delegate() { + return delegate; + } + + private long[] nextSecondsAndNanos( + long minSeconds, + long minNanos, + long maxSeconds, + long maxNanos) { + + BigInteger nanoMin = + BigInteger.valueOf(minSeconds) + .multiply(NANOS_PER_SECOND) + .add(BigInteger.valueOf(minNanos)); + BigInteger nanoMax = + BigInteger.valueOf(maxSeconds) + .multiply(NANOS_PER_SECOND) + .add(BigInteger.valueOf(maxNanos)); + + BigInteger[] generated = + Ranges.choose(this, nanoMin, nanoMax) + .divideAndRemainder(NANOS_PER_SECOND); + + return new long[] { generated[0].longValue(), generated[1].longValue() }; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheck.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheck.java new file mode 100644 index 0000000000..a9320c1679 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheck.java @@ -0,0 +1,110 @@ +///* +// The MIT License +// +// Copyright (c) 2010-2021 Paul R. Holser, Jr. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//*/ +// +//package org.utbot.quickcheck.runner; +// +//import org.utbot.quickcheck.Property; +//import org.utbot.quickcheck.internal.GeometricDistribution; +//import org.utbot.quickcheck.internal.generator.GeneratorRepository; +//import org.utbot.quickcheck.internal.generator.ServiceLoaderGeneratorSource; +//import org.utbot.quickcheck.random.SourceOfRandomness; +//import org.utbot.quickcheck.runner.JUnitQuickcheckTestClass; +//import org.junit.Test; +//import org.junit.runners.BlockJUnit4ClassRunner; +//import org.junit.runners.model.FrameworkMethod; +//import org.junit.runners.model.InitializationError; +//import org.junit.runners.model.Statement; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +// +//import java.util.ArrayList; +//import java.util.List; +//import java.util.Random; +// +///** +// *

JUnit test runner for junit-quickcheck property-based tests.

+// * +// *

When this runner runs a given test class, it regards only +// * {@code public} instance methods with a return type of {@code void} that are +// * marked with either the {@link Property} +// * annotation or the {@code org.junit.Test} annotation.

+// * +// *

This runner honors {@link org.junit.Rule}, {@link org.junit.Before}, +// * {@link org.junit.After}, {@link org.junit.BeforeClass}, and +// * {@link org.junit.AfterClass}. Their execution is wrapped around the +// * verification of a property or execution of a test in the expected +// * order.

+// */ +//public class JUnitQuickcheck extends BlockJUnit4ClassRunner { +// private final GeneratorRepository repo; +// private final GeometricDistribution distro; +// private final Logger logger; +// +// /** +// * Invoked reflectively by JUnit. +// * +// * @param clazz class containing properties to verify +// * @throws InitializationError if there is a problem with the +// * properties class +// */ +// public JUnitQuickcheck(Class clazz) throws InitializationError { +// super(new JUnitQuickcheckTestClass(clazz)); +// +// SourceOfRandomness random = new SourceOfRandomness(new Random()); +// repo = +// new GeneratorRepository(random) +// .register(new ServiceLoaderGeneratorSource()); +// distro = new GeometricDistribution(); +// logger = LoggerFactory.getLogger("junit-quickcheck.value-reporting"); +// } +// +// @Override protected void validateTestMethods(List errors) { +// validatePublicVoidNoArgMethods(Test.class, false, errors); +// validatePropertyMethods(errors); +// } +// +// private void validatePropertyMethods(List errors) { +// getTestClass().getAnnotatedMethods(Property.class) +// .forEach(m -> m.validatePublicVoid(false, errors)); +// } +// +// @Override protected List computeTestMethods() { +// List methods = new ArrayList<>(); +// methods.addAll(getTestClass().getAnnotatedMethods(Test.class)); +// methods.addAll(getTestClass().getAnnotatedMethods(Property.class)); +// return methods; +// } +// +// @Override public Statement methodBlock(FrameworkMethod method) { +// return method.getAnnotation(Test.class) != null +// ? super.methodBlock(method) +// : new org.utbot.quickcheck.runner.PropertyStatement( +// method, +// getTestClass(), +// repo, +// distro, +// logger); +// } +//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheckTestClass.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheckTestClass.java new file mode 100644 index 0000000000..edae19cbfb --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheckTestClass.java @@ -0,0 +1,107 @@ +///* +// The MIT License +// +// Copyright (c) 2010-2021 Paul R. Holser, Jr. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//*/ +// +//package org.utbot.quickcheck.runner; +// +//import org.junit.internal.MethodSorter; +//import org.junit.runners.model.FrameworkField; +//import org.junit.runners.model.FrameworkMethod; +//import org.junit.runners.model.TestClass; +// +//import java.lang.annotation.Annotation; +//import java.lang.reflect.Field; +//import java.lang.reflect.Method; +//import java.lang.reflect.Modifier; +//import java.util.*; +//import java.util.stream.Stream; +// +//import static java.util.stream.Collectors.toList; +// +///** +// * Extension of JUnit framework class for junit-quickcheck's discovery +// * of JUnit annotations/methods/fields. +// * +// * This is a member of a JUnit package so that it has access to +// * {@link FrameworkField}. +// */ +//public class JUnitQuickcheckTestClass extends TestClass { +// /** +// * Makes a new instance, wrapping the given test class. +// * +// * @param testClass class with junit-quickcheck tests +// */ +// JUnitQuickcheckTestClass(Class testClass) { +// super(testClass); +// } +// +// @Override protected void scanAnnotatedMembers( +// Map, List> methods, +// Map, List> fields) { +// +// ancestry().forEachOrdered(c -> { +// for (Method each : applicableMethodsOf(c)) { +// addToAnnotationLists(new FrameworkMethod(each), methods); +// } +// for (Field each : applicableFieldsOf(c)) { +// addToAnnotationLists(new FrameworkField(each), fields); +// } +// }); +// } +// +// private static List applicableMethodsOf(Class clazz) { +// return Arrays.stream(MethodSorter.getDeclaredMethods(clazz)) +// .filter(m -> +// !m.getDeclaringClass().isInterface() +// || m.isDefault() +// || Modifier.isStatic(m.getModifiers())) +// .collect(toList()); +// } +// +// private static Field[] applicableFieldsOf(Class clazz) { +// Field[] declaredFields = clazz.getDeclaredFields(); +// Arrays.sort(declaredFields, Comparator.comparing(Field::getName)); +// return declaredFields; +// } +// +// private Stream> ancestry() { +// return superclassHierarchy(getJavaClass()) +// .flatMap(JUnitQuickcheckTestClass::interfaceAncestry); +// } +// +// private static Stream> superclassHierarchy(Class clazz) { +// List> hierarchy = new ArrayList<>(); +// for (Class c = clazz; c != null; c = c.getSuperclass()) { +// hierarchy.add(c); +// } +// return hierarchy.stream(); +// } +// +// private static Stream> interfaceAncestry(Class clazz) { +// return Stream.concat( +// Stream.of(clazz), +// Arrays.stream(clazz.getInterfaces()) +// .flatMap(JUnitQuickcheckTestClass::interfaceAncestry)); +// } +//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/NoValuesSatisfiedPropertyAssumptions.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/NoValuesSatisfiedPropertyAssumptions.java new file mode 100644 index 0000000000..963596927a --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/NoValuesSatisfiedPropertyAssumptions.java @@ -0,0 +1,17 @@ +//package org.utbot.quickcheck.runner; +// +//import org.junit.internal.AssumptionViolatedException; +// +//import java.util.List; +// +//class NoValuesSatisfiedPropertyAssumptions +// extends org.junit.AssumptionViolatedException { +// +// NoValuesSatisfiedPropertyAssumptions( +// List violations) { +// +// super( +// "No values satisfied property assumptions. Violated assumptions: " +// + violations); +// } +//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyFalsified.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyFalsified.java new file mode 100644 index 0000000000..603d8f5424 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyFalsified.java @@ -0,0 +1,101 @@ +///* +// The MIT License +// +// Copyright (c) 2010-2021 Paul R. Holser, Jr. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//*/ +// +//package org.utbot.quickcheck.runner; +// +//import java.util.Arrays; +// +//import static java.lang.String.format; +// +//final class PropertyFalsified { +// private PropertyFalsified() { +// throw new UnsupportedOperationException(); +// } +// +// static AssertionError counterexampleFound( +// String propertyName, +// Object[] args, +// long[] seeds, +// AssertionError e) { +// +// String template = "Property named '%s' failed%s%n" +// + "With arguments: %s%n" +// + "Seeds for reproduction: %s"; +// String assertionErrorMessage = +// e.getMessage() == null +// ? ":" +// : format(" (%s)", e.getMessage()); +// +// return new AssertionError( +// format( +// template, +// propertyName, +// assertionErrorMessage, +// Arrays.deepToString(args), +// Arrays.toString(seeds)), +// e); +// } +// +// static AssertionError smallerCounterexampleFound( +// String propertyName, +// Object[] originalArgs, +// Object[] args, +// long[] seeds, +// AssertionError smallerFailure, +// AssertionError originalFailure) { +// +// String originalFailureMessageSegment = +// originalFailure.getMessage() == null +// ? "" +// : format( +// "Original failure message: %s%n", +// originalFailure.getMessage()); +// String smallerFailureMessageSegment = +// smallerFailure.getMessage() == null +// ? ":" +// : format(" (%s):", smallerFailure.getMessage()); +// +// String template = +// "Property named '%s' failed%s%n" +// + "With arguments: %s%n" +// + "%s" +// + "First arguments found to also provoke a failure: %s%n" +// + "Seeds for reproduction: %s"; +// +// AssertionError e = +// new AssertionError( +// format( +// template, +// propertyName, +// smallerFailureMessageSegment, +// Arrays.deepToString(args), +// originalFailureMessageSegment, +// Arrays.deepToString(originalArgs), +// Arrays.toString(seeds)), +// originalFailure); +// e.setStackTrace(smallerFailure.getStackTrace()); +// return e; +// } +//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyStatement.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyStatement.java new file mode 100644 index 0000000000..f5da2eb15d --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyStatement.java @@ -0,0 +1,197 @@ +///* +// The MIT License +// +// Copyright (c) 2010-2021 Paul R. Holser, Jr. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//*/ +// +//package org.utbot.quickcheck.runner; +// +//import org.utbot.quickcheck.Property; +//import org.utbot.quickcheck.internal.*; +//import org.utbot.quickcheck.internal.generator.GeneratorRepository; +//import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; +//import org.utbot.quickcheck.internal.sampling.ExhaustiveParameterSampler; +//import org.utbot.quickcheck.internal.sampling.TupleParameterSampler; +//import org.utbot.quickcheck.random.SourceOfRandomness; +//import org.junit.internal.AssumptionViolatedException; +//import org.junit.runners.model.FrameworkMethod; +//import org.junit.runners.model.InitializationError; +//import org.junit.runners.model.Statement; +//import org.junit.runners.model.TestClass; +//import org.slf4j.Logger; +//import ru.vyarus.java.generics.resolver.GenericsResolver; +//import ru.vyarus.java.generics.resolver.context.MethodGenericsContext; +// +//import java.lang.reflect.Parameter; +//import java.util.ArrayList; +//import java.util.Arrays; +//import java.util.List; +//import java.util.Random; +//import java.util.stream.Stream; +// +//import static org.utbot.quickcheck.runner.PropertyFalsified.counterexampleFound; +//import static java.util.stream.Collectors.toList; +// +//class PropertyStatement extends Statement { +// private final FrameworkMethod method; +// private final TestClass testClass; +// private final GeneratorRepository repo; +// private final GeometricDistribution distro; +// private final List assumptionViolations; +// private final Logger logger; +// +// private int successes; +// +// PropertyStatement( +// FrameworkMethod method, +// TestClass testClass, +// GeneratorRepository repo, +// GeometricDistribution distro, +// Logger logger) { +// +// this.method = method; +// this.testClass = testClass; +// this.repo = repo; +// this.distro = distro; +// assumptionViolations = new ArrayList<>(); +// this.logger = logger; +// } +// +// @Override public void evaluate() throws Throwable { +// Property marker = method.getAnnotation(Property.class); +// ParameterSampler sampler = sampler(marker); +// ShrinkControl shrinkControl = new ShrinkControl(marker); +// +// MethodGenericsContext generics = +// GenericsResolver.resolve(testClass.getJavaClass()) +// .method(method.getMethod()); +// List paramContexts = +// Arrays.stream(method.getMethod().getParameters()) +// .map(p -> parameterContextFor(p, generics)) +// .map(p -> new PropertyParameterGenerationContext( +// p, +// repo, +// distro, +// new SourceOfRandomness(new Random()), +// sampler +// )) +// .collect(toList()); +// +// Stream> sample = sampler.sample(paramContexts); +// for (List args : +// (Iterable>) sample::iterator) { +// +// property(args, shrinkControl).verify(); +// } +// +// if (successes == 0 && !assumptionViolations.isEmpty()) { +// throw new NoValuesSatisfiedPropertyAssumptions( +// assumptionViolations); +// } +// } +// +// private org.utbot.quickcheck.runner.PropertyVerifier property( +// List arguments, +// ShrinkControl shrinkControl) +// throws InitializationError { +// +// if (logger.isDebugEnabled()) { +// logger.debug( +// "Verifying property {} from {} with these values:", +// method.getName(), +// testClass.getName()); +// logger.debug("{}", Arrays.deepToString(arguments.toArray())); +// } +// +// List params = +// arguments.stream().map(SeededValue::parameter).collect(toList()); +// Object[] args = arguments.stream().map(SeededValue::value).toArray(); +// long[] seeds = +// arguments.stream().mapToLong(SeededValue::seed).toArray(); +// +// return new org.utbot.quickcheck.runner.PropertyVerifier( +// testClass, +// method, +// args, +// seeds, +// s -> ++successes, +// assumptionViolations::add, +// (e, action) -> { +// if (!shrinkControl.shouldShrink()) { +// shrinkControl.onMinimalCounterexample() +// .handle(args, action); +// throw counterexampleFound( +// method.getName(), +// args, +// seeds, +// e); +// } +// +// try { +// shrink(params, args, seeds, shrinkControl, e); +// } catch (AssertionError ex) { +// throw ex; +// } catch (Throwable ex) { +// throw new AssertionError(ex); +// } +// } +// ); +// } +// +// private void shrink( +// List params, +// Object[] args, +// long[] seeds, +// ShrinkControl shrinkControl, +// AssertionError failure) +// throws Throwable { +// +// new Shrinker( +// method, +// testClass, +// failure, +// shrinkControl) +// .shrink(params, args, seeds); +// } +// +// private PropertyParameterContext parameterContextFor( +// Parameter parameter, +// MethodGenericsContext generics) { +// +// return new PropertyParameterContext( +// ParameterTypeContext.forParameter(parameter, generics) +// .allowMixedTypes(true) +// ).annotate(parameter); +// } +// +// private ParameterSampler sampler(Property marker) { +// switch (marker.mode()) { +// case SAMPLING: +// return new TupleParameterSampler(marker.trials()); +// case EXHAUSTIVE: +// return new ExhaustiveParameterSampler(marker.trials()); +// default: +// throw new AssertionError( +// "Don't recognize mode " + marker.mode()); +// } +// } +//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyVerifier.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyVerifier.java new file mode 100644 index 0000000000..920f2c2f06 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyVerifier.java @@ -0,0 +1,122 @@ +///* +// The MIT License +// +// Copyright (c) 2010-2021 Paul R. Holser, Jr. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//*/ +// +//package org.utbot.quickcheck.runner; +// +//import org.junit.internal.AssumptionViolatedException; +//import org.junit.runners.BlockJUnit4ClassRunner; +//import org.junit.runners.model.FrameworkMethod; +//import org.junit.runners.model.InitializationError; +//import org.junit.runners.model.Statement; +//import org.junit.runners.model.TestClass; +// +//import java.util.Arrays; +//import java.util.List; +//import java.util.function.BiConsumer; +//import java.util.function.Consumer; +// +//class PropertyVerifier extends BlockJUnit4ClassRunner { +// private final FrameworkMethod method; +// private final Object[] args; +// private final long[] seeds; +// private final Consumer onSuccess; +// private final Consumer onAssumptionViolated; +// private final BiConsumer onFailure; +// +// PropertyVerifier( +// TestClass clazz, +// FrameworkMethod method, +// Object[] args, +// long[] seeds, +// Consumer onSuccess, +// Consumer onAssumptionViolated, +// BiConsumer onFailure) +// throws InitializationError { +// +// super(clazz.getJavaClass()); +// +// this.method = method; +// this.args = args; +// this.seeds = seeds; +// this.onSuccess = onSuccess; +// this.onAssumptionViolated = onAssumptionViolated; +// this.onFailure = onFailure; +// } +// +// void verify() throws Throwable { +// methodBlock().evaluate(); +// } +// +// private Statement methodBlock() { +// Statement statement = super.methodBlock(method); +// return new Statement() { +// @Override public void evaluate() { +// try { +// statement.evaluate(); +// onSuccess.accept(null); +// } catch (AssumptionViolatedException e) { +// onAssumptionViolated.accept(e); +// } catch (AssertionError e) { +// Runnable repeat = () -> { +// try { +// statement.evaluate(); +// } catch (Throwable ignored) { +// } +// }; +// onFailure.accept(e, repeat); +// } catch (Throwable t) { +// reportErrorWithArguments(t); +// } +// } +// }; +// } +// +// @Override protected void collectInitializationErrors( +// List errors) { +// +// // do nothing +// } +// +// @Override protected Statement methodInvoker( +// FrameworkMethod frameworkMethod, +// Object test) { +// +// return new Statement() { +// @Override public void evaluate() throws Throwable { +// frameworkMethod.invokeExplosively(test, args); +// } +// }; +// } +// +// private void reportErrorWithArguments(Throwable e) { +// throw new AssertionError( +// String.format( +// "Unexpected error in property %s with args %s and seeds %s", +// method.getName(), +// Arrays.deepToString(args), +// Arrays.toString(seeds)), +// e); +// } +//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/ShrinkNode.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/ShrinkNode.java new file mode 100644 index 0000000000..f1383082f5 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/ShrinkNode.java @@ -0,0 +1,223 @@ +///* +// The MIT License +// +// Copyright (c) 2010-2021 Paul R. Holser, Jr. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//*/ +// +//package org.utbot.quickcheck.runner; +// +//import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; +//import org.junit.runners.model.FrameworkMethod; +//import org.junit.runners.model.InitializationError; +//import org.junit.runners.model.TestClass; +// +//import java.math.BigDecimal; +//import java.util.Arrays; +//import java.util.Comparator; +//import java.util.List; +//import java.util.stream.IntStream; +// +//import static org.utbot.quickcheck.runner.PropertyFalsified.counterexampleFound; +//import static org.utbot.quickcheck.runner.PropertyFalsified.smallerCounterexampleFound; +//import static java.util.Comparator.comparing; +//import static java.util.function.Function.identity; +//import static java.util.stream.Collectors.toList; +// +//final class ShrinkNode implements Comparable { +// private final FrameworkMethod method; +// private final TestClass testClass; +// private final List params; +// private final Object[] args; +// private final long[] seeds; +// private final int[] depths; +// private final int totalDepth; +// private final BigDecimal totalMagnitude; +// +// private AssertionError failure; +// +// private ShrinkNode( +// FrameworkMethod method, +// TestClass testClass, +// List params, +// Object[] args, +// long[] seeds, +// int[] depths, +// AssertionError failure) { +// +// this.method = method; +// this.testClass = testClass; +// this.params = params; +// this.args = args; +// this.seeds = seeds; +// this.depths = depths; +// this.totalDepth = IntStream.of(depths).sum(); +// this.totalMagnitude = computeTotalMagnitude(); +// +// this.failure = failure; +// } +// +// static ShrinkNode root( +// FrameworkMethod method, +// TestClass testClass, +// List params, +// Object[] args, +// long[] seeds, +// AssertionError failure) { +// +// return new ShrinkNode( +// method, +// testClass, +// params, +// args, +// seeds, +// new int[args.length], +// failure); +// } +// +// List shrinks() { +// return IntStream.range(0, params.size()) +// .mapToObj(i -> params.get(i).shrink(args[i]).stream() +// .filter(o -> !o.equals(args[i])) +// .map(o -> shrinkNodeFor(o, i))) +// .flatMap(identity()) +// .collect(toList()); +// } +// +// boolean verifyProperty() throws Throwable { +// boolean[] result = new boolean[1]; +// +// property(result).verify(); +// +// return result[0]; +// } +// +// AssertionError fail( +// AssertionError originalFailure, +// Object[] originalArgs) { +// +// return originalFailure == failure +// ? counterexampleFound( +// method.getName(), +// args, +// seeds, +// failure) +// : smallerCounterexampleFound( +// method.getName(), +// originalArgs, +// args, +// seeds, +// failure, +// originalFailure); +// } +// +// Object[] args() { +// return args; +// } +// +// int depth() { +// return totalDepth; +// } +// +// BigDecimal magnitude() { +// return totalMagnitude; +// } +// +// private org.utbot.quickcheck.runner.PropertyVerifier property(boolean[] result) +// throws InitializationError { +// +// return new org.utbot.quickcheck.runner.PropertyVerifier( +// testClass, +// method, +// args, +// seeds, +// s -> result[0] = true, +// v -> result[0] = true, +// (e, repeatTestOption) -> { +// failure = e; +// result[0] = false; +// }); +// } +// +// private ShrinkNode shrinkNodeFor(Object shrunk, int index) { +// Object[] shrunkArgs = new Object[args.length]; +// System.arraycopy(args, 0, shrunkArgs, 0, args.length); +// shrunkArgs[index] = shrunk; +// +// int[] newDepths = new int[depths.length]; +// System.arraycopy(depths, 0, newDepths, 0, depths.length); +// ++newDepths[index]; +// +// return new ShrinkNode( +// method, +// testClass, +// params, +// shrunkArgs, +// seeds, +// newDepths, +// failure); +// } +// +// private BigDecimal computeTotalMagnitude() { +// BigDecimal total = BigDecimal.ZERO; +// +// for (int i = 0; i < args.length; ++i) { +// BigDecimal magnitude = magnitudeAt(i); +// BigDecimal factor = BigDecimal.valueOf(2).pow(args.length - i - 1); +// total = total.add(magnitude.multiply(factor)); +// } +// +// return total; +// } +// +// private BigDecimal magnitudeAt(int index) { +// return params.get(index).magnitude(args[index]); +// } +// +// @Override public boolean equals(Object o) { +// if (!(o instanceof ShrinkNode)) +// return false; +// +// ShrinkNode other = (ShrinkNode) o; +// return Arrays.equals(args, other.args) +// && Arrays.equals(depths, other.depths); +// } +// +// @Override public int hashCode() { +// return Arrays.hashCode(args) ^ Arrays.hashCode(depths); +// } +// +// @Override public int compareTo(ShrinkNode other) { +// // Nodes at lesser depth compare less than nodes of greater depth. +// // Nodes at equal depth needs to compare their args one by one. +// // prefer larger-magnitude args before smaller. +// +// Comparator comparison = comparing(ShrinkNode::depth); +// for (int i = 0; i < params.size(); ++i) { +// int index = i; +// Comparator byMagnitude = +// comparing(s -> s.magnitudeAt(index)); +// comparison = comparison.thenComparing(byMagnitude.reversed()); +// } +// +// return comparison.compare(this, other); +// } +//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/Shrinker.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/Shrinker.java new file mode 100644 index 0000000000..b290ce9f7e --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/Shrinker.java @@ -0,0 +1,111 @@ +///* +// The MIT License +// +// Copyright (c) 2010-2021 Paul R. Holser, Jr. +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +//*/ +// +//package org.utbot.quickcheck.runner; +// +//import org.utbot.quickcheck.MinimalCounterexampleHook; +//import org.utbot.quickcheck.internal.ShrinkControl; +//import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; +//import org.junit.runners.model.FrameworkMethod; +//import org.junit.runners.model.TestClass; +// +//import java.util.ArrayDeque; +//import java.util.List; +//import java.util.Queue; +// +//class Shrinker { +// private final FrameworkMethod method; +// private final TestClass testClass; +// private final AssertionError failure; +// private final int maxShrinks; +// private final int maxShrinkDepth; +// private final int maxShrinkTime; +// private final MinimalCounterexampleHook onMinimalCounterexample; +// +// private int shrinkAttempts; +// private long shrinkTimeout; +// +// Shrinker( +// FrameworkMethod method, +// TestClass testClass, +// AssertionError failure, +// ShrinkControl shrinkControl) { +// +// this.method = method; +// this.testClass = testClass; +// this.failure = failure; +// this.maxShrinks = shrinkControl.maxShrinks(); +// this.maxShrinkDepth = +// shrinkControl.maxShrinkDepth() * method.getMethod().getParameterCount(); +// this.maxShrinkTime = shrinkControl.maxShrinkTime(); +// this.onMinimalCounterexample = shrinkControl.onMinimalCounterexample(); +// } +// +// void shrink( +// List params, +// Object[] args, +// long[] seeds) +// throws Throwable { +// +// org.utbot.quickcheck.runner.ShrinkNode smallest = +// org.utbot.quickcheck.runner.ShrinkNode.root(method, testClass, params, args, seeds, failure); +// Queue nodes = new ArrayDeque<>(smallest.shrinks()); +// +// shrinkTimeout = System.currentTimeMillis() + maxShrinkTime; +// +// while (shouldContinueShrinking(nodes)) { +// org.utbot.quickcheck.runner.ShrinkNode next = nodes.poll(); +// +// boolean result = next.verifyProperty(); +// ++shrinkAttempts; +// +// if (!result) { +// smallest = next; +// nodes = new ArrayDeque<>(smallest.shrinks()); +// } +// } +// +// handleMinimalCounterexample(smallest); +// throw smallest.fail(failure, args); +// } +// +// private void handleMinimalCounterexample(org.utbot.quickcheck.runner.ShrinkNode counterexample) { +// Runnable repeat = () -> { +// try { +// counterexample.verifyProperty(); +// } catch (Throwable ignored) { +// } +// }; +// +// onMinimalCounterexample.handle(counterexample.args(), repeat); +// } +// +// private boolean shouldContinueShrinking(Queue nodes) { +// return shrinkAttempts < maxShrinks +// && shrinkTimeout >= System.currentTimeMillis() +// && !nodes.isEmpty() +// && nodes.peek().depth() <= maxShrinkDepth; +// } +//} diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index 10a9138a8c..730e84d683 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -11,6 +11,7 @@ import org.utbot.api.exception.UtMockAssumptionViolatedException import org.utbot.common.bracket import org.utbot.common.debug import org.utbot.engine.MockStrategy.NO_MOCKS +import org.utbot.engine.greyboxfuzzer.GreyBoxFuzzer import org.utbot.engine.pc.* import org.utbot.engine.selectors.* import org.utbot.engine.selectors.nurs.NonUniformRandomSearch @@ -32,7 +33,9 @@ import org.utbot.framework.UtSettings.pathSelectorStepsLimit import org.utbot.framework.UtSettings.pathSelectorType import org.utbot.framework.UtSettings.processUnknownStatesDuringConcreteExecution import org.utbot.framework.UtSettings.useDebugVisualization -import org.utbot.framework.util.convertToAssemble +import org.utbot.framework.concrete.UtConcreteExecutionData +import org.utbot.framework.concrete.UtConcreteExecutionResult +import org.utbot.framework.concrete.UtExecutionInstrumentation import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.Step import org.utbot.framework.plugin.api.util.* @@ -416,6 +419,27 @@ class UtBotSymbolicEngine( } } + //Simple fuzzing + fun greyBoxFuzzing(until: Long = Long.MAX_VALUE) = + flow { + GenericsInfoFactory.disableCache() + val isFuzzable = methodUnderTest.parameters.all { classId -> + classId != Method::class.java.id // causes the child process crash at invocation + } + if (!isFuzzable) { + return@flow + } + + try { + GreyBoxFuzzer(concreteExecutor.pathsToUserClasses, concreteExecutor.pathsToDependencyClasses, methodUnderTest).fuzz() + } catch (e: CancellationException) { + logger.debug { "Cancelled by timeout" } + } catch (e: Throwable) { + emit(UtError("Unexpected fuzzing crash", e)) + } + return@flow + } + private suspend fun FlowCollector.emitFailedConcreteExecutionResult( stateBefore: EnvironmentModels, e: ConcreteExecutionFailureException diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt new file mode 100644 index 0000000000..009632efe6 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -0,0 +1,253 @@ +package org.utbot.engine.greyboxfuzzer + +import org.utbot.engine.* +import org.utbot.engine.greyboxfuzzer.generator.* +import org.utbot.engine.greyboxfuzzer.mutator.Mutator +import org.utbot.engine.greyboxfuzzer.mutator.Seed +import org.utbot.engine.greyboxfuzzer.mutator.SeedCollector +import org.utbot.engine.greyboxfuzzer.util.* +import org.utbot.external.api.classIdForType +import org.utbot.framework.concrete.* +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.* +import org.utbot.framework.util.sootMethod +import org.utbot.instrumentation.ConcreteExecutor +import java.lang.reflect.Field +import java.lang.reflect.Method +import kotlin.random.Random +import kotlin.reflect.KFunction +import kotlin.reflect.jvm.javaMethod +import kotlin.system.exitProcess + +class GreyBoxFuzzer( + private val pathsToUserClasses: String, + private val pathsToDependencyClasses: String, + private val methodUnderTest: ExecutableId, +) { + + private val seeds = SeedCollector() +// val kfunction = methodUnderTest as KFunction<*> + private val explorationStageIterations = 10 + private val exploitationStageIterations = 100 + private var thisInstance: UtModel? = generateThisInstance(methodUnderTest.classId.jClass) + + //TODO make it return Sequence + suspend fun fuzz(): Sequence> { + logger.debug { "Started to fuzz ${methodUnderTest.name}" } + val javaClazz = methodUnderTest.classId.jClass + val javaMethod = methodUnderTest.sootMethod.toJavaMethod()!! + val sootMethod = methodUnderTest.sootMethod + val classFieldsUsedByFunc = sootMethod.getClassFieldsUsedByFunc(javaClazz) + val methodLines = sootMethod.activeBody.units.map { it.javaSourceStartLineNumber }.filter { it != -1 }.toSet() + val currentCoverageByLines = CoverageCollector.coverage + .filter { it.methodSignature == methodUnderTest.signature } + .map { it.lineNumber } + .toSet() + //TODO repeat or while + explorationStage( + javaMethod, + explorationStageIterations, + methodLines, + javaClazz, + classFieldsUsedByFunc, + methodUnderTest, + currentCoverageByLines + ) + logger.debug { "SEEDS AFTER EXPLORATION STAGE = ${seeds.seedsSize()}" } + //exploitationStage(exploitationStageIterations, javaClazz, methodLines, currentCoverageByLines) + //UtModelGenerator.reset() + return sequenceOf() + } + + private suspend fun explorationStage( + method: Method, + numberOfIterations: Int, + methodLinesToCover: Set, + clazz: Class<*>, + classFieldsUsedByFunc: Set, + methodUnderTest: ExecutableId, + prevMethodCoverage: Set + ) { + val parametersToGenericsReplacer = method.parameters.map { it to GenericsReplacer() } + repeat(numberOfIterations) { iterationNumber -> + logger.debug { "Iteration number $iterationNumber" } + if (thisInstance != null && iterationNumber != 0) { + if (Random.getTrue(20)) { + logger.debug { "Trying to regenerate this instance" } + generateThisInstance(clazz)?.let { thisInstance = it } + } else if (Random.getTrue(50) && thisInstance is UtAssembleModel) { + thisInstance = + Mutator.regenerateFields( + clazz, + thisInstance as UtAssembleModel, + classFieldsUsedByFunc.toList() + ) + } + } + /** + * Replacing unresolved generics to random compatible to bounds type + */ + when { + Random.getTrue(10) -> parametersToGenericsReplacer.map { it.second.revert() } + Random.getTrue(50) -> parametersToGenericsReplacer.map { + it.second.replaceUnresolvedGenericsToRandomTypes( + it.first + ) + } + } + val generatedParameters = + method.parameters.mapIndexed { index, parameter -> + DataGenerator.generate( + parameter, + index, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus + ) + } + logger.debug { "Generated params = $generatedParameters" } + logger.debug { "This instance = $thisInstance" } + val stateBefore = + EnvironmentModels(thisInstance, generatedParameters.map { it.utModel }, mapOf()) + try { + val executionResult = execute(stateBefore, methodUnderTest) ?: return@repeat + logger.debug { "Execution result: $executionResult" } + val seedScore = + handleCoverage( + executionResult, + prevMethodCoverage, + methodLinesToCover + ) + seeds.addSeed(Seed(thisInstance, generatedParameters, seedScore.toDouble())) + logger.debug { "Execution result: ${executionResult.result}" } + } catch (e: Throwable) { + logger.debug(e) { "Exception while execution :(" } + return@repeat + } + } + } + + private fun handleCoverage( + executionResult: UtFuzzingConcreteExecutionResult, + prevMethodCoverage: Set, + currentMethodLines: Set + ): Int { + val coverage = + executionResult.coverage.coveredInstructions + .map { it.lineNumber } + .filter { it in currentMethodLines } + .toSet() + executionResult.coverage.coveredInstructions.forEach { CoverageCollector.coverage.add(it) } + return (coverage - prevMethodCoverage).size + } + + + //TODO under construction + private fun exploitationStage( + numberOfIterations: Int, + clazz: Class<*>, + methodLinesToCover: Set, + prevMethodCoverage: Set + ) { + logger.debug { "Exploitation began" } + repeat(numberOfIterations) { + val randomSeed = seeds.getRandomWeightedSeed() ?: return@repeat + val randomSeedArgs = randomSeed.arguments.toMutableList() + val randomParameter = randomSeedArgs.random() + Mutator.mutateParameter(randomParameter) + } + } +// private suspend fun exploitationStage( +// numberOfIterations: Int, +// clazz: Class<*>, +// methodLinesToCover: Set, +// prevMethodCoverage: Set +// ) { +// logger.debug { "Exploitation began" } +// repeat(numberOfIterations) { +// val randomSeed = seeds.getRandomWeightedSeed() ?: return@repeat +// val randomSeedArguments = randomSeed.arguments.toMutableList() +// val m = IdentityHashMap() +// val modelConstructor = UtModelConstructor(m) +// val randomParameterIndex = +// when { +// randomSeedArguments.isEmpty() -> return@repeat +// randomSeedArguments.size == 1 -> 0 +// else -> Random.nextInt(0, randomSeedArguments.size) +// } +// val randomArgument = randomSeedArguments[randomParameterIndex] +// println("BEFORE = ${randomArgument.first!!.utModel}") +// val fRandomArgument = randomArgument.first!! +// val randomSeedArgumentsAsUtModels = +// modelConstructor.constructModelFromValues(randomSeedArguments).toMutableList() +// val initialInstanceForMutation = +// randomSeedArguments[randomParameterIndex].first?.utModel as? UtReferenceModel ?: return@repeat +// val mutatedArgument = +// Mutator.mutateParameter( +// fRandomArgument, +// initialInstanceForMutation, +// modelConstructor +// ) +//// randomSeedArguments[randomParameterIndex] = fRandomArgument to randomArgument.second +// println("AFTER = ${mutatedArgument!!.utModel}") +// if (mutatedArgument?.utModel == null) return@repeat +// randomSeedArgumentsAsUtModels[randomParameterIndex] = mutatedArgument.utModel +// val stateBefore = +// EnvironmentModels(thisInstance, randomSeedArgumentsAsUtModels, mapOf()) +// //println(stateBefore) +// try { +// val executionResult = execute(stateBefore, methodUnderTest) +// val seedScore = +// handleCoverage( +// executionResult!!, +// prevMethodCoverage, +// methodLinesToCover +// ) +// //seeds.addSeed(Seed(thisInstance, generatedParameters, seedScore.toDouble())) +// println("MUTATED SEED SCORE = $seedScore") +// println("Execution result1: ${executionResult.result}") +// println("-----------------------------------------") +// } catch (e: Throwable) { +// return@repeat +// } +// } +// } + + private suspend fun ConcreteExecutor.executeConcretely( + methodUnderTest: ExecutableId, + stateBefore: EnvironmentModels, + instrumentation: List + ): UtFuzzingConcreteExecutionResult = executeAsync( + methodUnderTest.classId.name, + methodUnderTest.signature, + arrayOf(), + parameters = UtConcreteExecutionData(stateBefore, instrumentation) + ) + + private suspend fun execute( + stateBefore: EnvironmentModels, + methodUnderTest: ExecutableId + ): UtFuzzingConcreteExecutionResult? = + try { + val executor = + ConcreteExecutor( + UtFuzzingExecutionInstrumentation, + pathsToUserClasses, + pathsToDependencyClasses + ).apply { this.classLoader = utContext.classLoader } + executor.executeConcretely(methodUnderTest, stateBefore, listOf()) + } catch (e: Throwable) { + logger.debug { "Exception in $methodUnderTest :( $e" } + null + } + + private fun generateThisInstance(clazz: Class<*>) = + if (!methodUnderTest.isStatic) { + DataGenerator.generate( + clazz, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus + ) + } else { + null + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt new file mode 100644 index 0000000000..0920bdec06 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt @@ -0,0 +1,236 @@ +package org.utbot.engine.greyboxfuzzer.generator + +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.logger +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import java.lang.reflect.Parameter + +object DataGenerator { + + private val generatorRepository = GreyBoxFuzzerGenerators.generatorRepository + + fun generate( + clazz: Class<*>, + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel? = generatorRepository.getOrProduceGenerator(clazz)?.generate(random, status) + + fun generate( + parameterTypeContext: ParameterTypeContext, + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel? = generatorRepository.getOrProduceGenerator(parameterTypeContext, 0)?.generate(random, status) + + fun generate( + parameterTypeContext: ParameterTypeContext, + random: SourceOfRandomness, + status: GenerationStatus, + depth: Int + ): UtModel? = generatorRepository.getOrProduceGenerator(parameterTypeContext, depth)?.generate(random, status) + + fun generate( + parameter: Parameter, + parameterIndex: Int, + random: SourceOfRandomness, + status: GenerationStatus + ): FParameter { + val generator = + generatorRepository.getOrProduceGenerator(parameter, parameterIndex) + return generate(generator, parameter, random, status) + } + + fun generate( + generator: Generator<*>?, + parameter: Parameter, + random: SourceOfRandomness, + status: GenerationStatus, + numberOfTries: Int = 3 + ): FParameter { + logger.debug { "Trying to generate value for parameter ${parameter.name} of type ${parameter.type} $numberOfTries times" } + generatorRepository.removeGeneratorForObjectClass() + val classId = classIdForType(parameter.type) + if (generator == null) { + return FParameter(parameter, null, UtNullModel(classId), null, classId, listOf()) + } + var generatedValue: UtModel? + repeat(numberOfTries) { + logger.debug { "Try $it" } + try { + generatedValue = generator.generate(random, status) + if (generatedValue != null) { + return FParameter( + parameter, + null, + generatedValue!!, + generator, + emptyList() + ) + } + } catch (e: Throwable) { + logger.error(e) { "Exception while generation :(" } + return@repeat + } + } + return FParameter(parameter, null, UtNullModel(classId), generator, classId, listOf()) + } + +// //TODO Make it work with type parameters +// private fun Type.getFFieldsForClass(value: Any, depth: Int, originalField: Field?): List { +// println("GETTING FFIelds from $value") +// createFFieldFromPrimitivesOrBoxedPrimitives(this, value, originalField)?.let { return listOf(it) } +// val parameterizedType = this as? ParameterizedType +// val genericsContext = +// if (this is GenericArrayTypeImpl) { +// (this.genericComponentType as? ParameterizedType)?.buildGenericsContext() +// } else { +// parameterizedType?.buildGenericsContext() +// } +// if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) { +// return emptyList() +// } +// val subFields = mutableListOf() +// if (this.toClass()?.isArray == true) { +// val arrayContentType = this.toClass()?.componentType ?: return subFields +// getFFieldsFromArray(value, subFields, originalField, this, arrayContentType, depth) +// return subFields +// } +// val classFields = +// this.toClass()?.getAllDeclaredFields()?.filter { !it.hasModifiers(Modifier.FINAL) } ?: emptyList() +// for (field in classFields) { +// val resolvedFieldType = +// if (genericsContext != null) { +// //TODO make it work for subclasses +// parameterizedType.let { field.resolveFieldType(genericsContext) } ?: field.type +// } else { +// field.type +// } +// assert(resolvedFieldType.toClass() != null) +//// if (field.hasModifiers(Modifier.FINAL)) { +//// //subFields.add(FField(field, value)) +//// continue +//// } +// if (resolvedFieldType.toClass()!!.isArray) { +// val arrayOfObjects = field.getFieldValue(value) +// val arrayContentType = +// (resolvedFieldType as? GenericArrayTypeImpl)?.genericComponentType ?: field.type.componentType +// getFFieldsFromArray(arrayOfObjects, subFields, field, resolvedFieldType, arrayContentType, depth) +// //TODO!!!! +// } else { +// field.getFieldValue(value)?.let { fieldValue -> +// try { +// val generatorForField = generatorRepository.getOrProduceGenerator(field) +// if (field.type.isPrimitive) { +// subFields.add(FField(field, fieldValue, resolvedFieldType, generatorForField)) +// } else { +// //println("GETTING SUBFIELDS FOR ${field.type} value = ${fieldValue} DEPTH = $depth") +// //TODO resolve type +// val subFFields = resolvedFieldType.getFFieldsForClass(fieldValue, depth + 1, null) +// subFields.add(FField(field, fieldValue, resolvedFieldType, generatorForField, subFFields)) +// } +// } catch (e: java.lang.IllegalStateException) { +// subFields.add(FField(field, fieldValue, resolvedFieldType, null, listOf())) +// } +// } ?: subFields.add(FField(field, null, resolvedFieldType, null, listOf())) +// } +// } +// return subFields +// } + +// private fun createFFieldFromPrimitivesOrBoxedPrimitives(originalType: Type, value: Any?, field: Field?): FField? { +// val clazz = originalType.toClass() ?: return null +// val listOfPrimitives = listOf( +// Byte::class, +// Short::class, +// Int::class, +// Long::class, +// Float::class, +// Double::class, +// Boolean::class, +// Char::class, +// String::class +// ) +// return if (clazz.kotlin in listOfPrimitives || clazz.isPrimitive) { +// FField(field, value, originalType, getGenerator(originalType)) +// } else null +// } + +// private fun getFFieldsFromArray( +// array: Any?, +// subFields: MutableList, +// field: Field?, +// arrayType: Type, +// arrayContentType: Type, +// depth: Int +// ) { +// val typedArray = +// when (array) { +// is BooleanArray -> { +// array.toList() +// } +// is ByteArray -> { +// array.toList() +// } +// is CharArray -> { +// array.toList() +// } +// is ShortArray -> { +// array.toList() +// } +// is IntArray -> { +// array.toList() +// } +// is LongArray -> { +// array.toList() +// } +// is FloatArray -> { +// array.toList() +// } +// is DoubleArray -> { +// array.toList() +// } +// else -> { +// if (array == null) { +// subFields.add(FField(null, null, arrayContentType, null, listOf())) +// return +// } else { +// (array as Array<*>).toList() +// } +// } +// } +// val generatorOfNeededType = field?.let { getGenerator(it, arrayType) } ?: getGenerator(arrayType) +// val localSubFields = mutableListOf() +// val indexOfLastNotNullElement = typedArray.indexOfLast { it != null } +// val arrayContentGenerator = getGenerator(arrayContentType) +// if (indexOfLastNotNullElement == -1) { +// localSubFields.add(FField(field, null, arrayContentType, arrayContentGenerator)) +// } else { +// typedArray.filterNotNull().map { el -> +// val ssFFields = arrayContentType.getFFieldsForClass(el, depth + 1, null) +// localSubFields.add(FField(field, el, arrayContentType, arrayContentGenerator, ssFFields)) +// } +// } +// subFields.add(FField(field, typedArray, arrayType, generatorOfNeededType, localSubFields)) +// } + +// private fun getGenerator(field: Field, fieldType: Type): Generator<*>? { +// return if (fieldType is ParameterizedType) { +// generatorRepository.getOrProduceGenerator(field.buildParameterContext(fieldType), 0) +// } else { +// generatorRepository.getOrProduceGenerator(field) +// }.let { gen -> +// if (gen is ComponentizedGenerator && gen.getComponents().any { it is ZilchGenerator }) null +// else gen +// } +// } +// private fun getGenerator(resolvedType: Type): Generator<*>? = +// generatorRepository.getOrProduceGenerator(resolvedType).let { gen -> +// if (gen is ComponentizedGenerator && gen.getComponents().any { it is ZilchGenerator }) null +// else gen +// } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt new file mode 100644 index 0000000000..6bb01acb50 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt @@ -0,0 +1,74 @@ +package org.utbot.engine.greyboxfuzzer.generator + +import org.utbot.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.util.toClass +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.ClassId +import java.lang.reflect.Field +import java.lang.reflect.Type + +data class FField( + val field: Field?, + val value: Any?, + val resolvedType: Type, + val generator: Generator<*>?, + val classId: ClassId, + val subFields: List, + var isBlocked: Boolean, +) { + + constructor( + field: Field?, + value: Any?, + resolvedType: Type, + generator: Generator<*>?, + subFields: List, + isBlocked: Boolean + ) : this( + field, + value, + resolvedType, + generator, + classIdForType(field?.type ?: resolvedType.toClass()!!), + subFields, + isBlocked + ) + + constructor( + field: Field?, + value: Any?, + resolvedType: Type, + generator: Generator<*>?, + subFields: List, + ) : this( + field, + value, + resolvedType, + generator, + classIdForType(field?.type ?: resolvedType.toClass()!!), + subFields, + false + ) + + constructor( + field: Field?, + value: Any?, + resolvedType: Type, + generator: Generator<*>?, + ) : this( + field, + value, + resolvedType, + generator, + classIdForType(field?.type ?: resolvedType.toClass()!!), + listOf(), + false + ) + + constructor( + field: Field?, + value: Any?, + resolvedType: Type + ) : this(field, value, resolvedType, null, classIdForType(field?.type ?: resolvedType.toClass()!!), listOf(), false) + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt new file mode 100644 index 0000000000..9162715a5a --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt @@ -0,0 +1,59 @@ +package org.utbot.engine.greyboxfuzzer.generator + +import org.utbot.engine.greyboxfuzzer.mutator.Mutator +import org.utbot.engine.greyboxfuzzer.util.getAllDeclaredFields +import org.utbot.quickcheck.generator.Generator +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.jClass +import java.lang.reflect.Field +import java.lang.reflect.Parameter + +data class FParameter( + val parameter: Parameter, + val value: Any?, + var utModel: UtModel, + val generator: Generator<*>?, + val classId: ClassId, + val fields: List +) { + + constructor( + parameter: Parameter, + value: Any?, + utModel: UtModel, + generator: Generator<*>? + ) : this(parameter, value, utModel, generator, classIdForType(parameter.type), emptyList()) + + constructor( + parameter: Parameter, + value: Any?, + utModel: UtModel, + generator: Generator<*>?, + fields: List + ) : this(parameter, value, utModel, generator, classIdForType(parameter.type), fields) + + fun getAllSubFields(): List { + val res = mutableListOf() + val queue = ArrayDeque() + queue.addAll(fields) + while (queue.isNotEmpty()) { + val element = queue.removeFirst() + queue.addAll(element.subFields) + res.add(element) + } + return res + } + + fun regenerateFields() { + regenerateFields(classId.jClass.getAllDeclaredFields()) + } + fun regenerateFields(fieldsToRegenerate: List) { + if (utModel is UtAssembleModel) { + utModel = Mutator.regenerateFields(classId.jClass, utModel as UtAssembleModel, fieldsToRegenerate) + } + } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FakeAnnotatedTypeFactory.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FakeAnnotatedTypeFactory.kt new file mode 100644 index 0000000000..c36253d03b --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FakeAnnotatedTypeFactory.kt @@ -0,0 +1,74 @@ +package org.utbot.engine.greyboxfuzzer.generator + +import java.lang.reflect.AnnotatedArrayType +import java.lang.reflect.AnnotatedType +import java.lang.reflect.Type + + +internal class FakeAnnotatedTypeFactory private constructor() { + + companion object { + fun makeFrom(clazz: Class<*>): AnnotatedType { + return if (clazz.isArray) makeArrayType(clazz) else makePlainType(clazz) + } + + private fun makeArrayType(type: Class<*>): AnnotatedArrayType { + return FakeAnnotatedArrayType(type) + } + + private fun makePlainType(type: Class<*>): AnnotatedType { + return FakeAnnotatedType(type) + } + } + + private class FakeAnnotatedArrayType internal constructor(private val type: Class<*>) : AnnotatedArrayType { + override fun getAnnotatedGenericComponentType(): AnnotatedType { + return makeFrom(type.componentType) + } + + // Not introduced until JDK 9 -- not marking as... + // @Override + override fun getAnnotatedOwnerType(): AnnotatedType? { + return null + } + + override fun getType(): Type { + return type + } + + override fun getAnnotation( + annotationClass: Class + ): T? { + return null + } + + override fun getAnnotations(): Array { + return arrayOfNulls(0) + } + + override fun getDeclaredAnnotations(): Array { + return arrayOfNulls(0) + } + } + + private class FakeAnnotatedType internal constructor(private val type: Class<*>) : AnnotatedType { + override fun getType(): Type { + return type + } + + override fun getAnnotation( + annotationClass: Class + ): T? { + return null + } + + override fun getAnnotations(): Array { + return arrayOfNulls(0) + } + + override fun getDeclaredAnnotations(): Array { + return arrayOfNulls(0) + } + } + +} diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt new file mode 100644 index 0000000000..9fc517bea8 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt @@ -0,0 +1,97 @@ +package org.utbot.engine.greyboxfuzzer.generator + +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.Size +import org.utbot.quickcheck.generator.java.util.CollectionGenerator +import org.utbot.quickcheck.generator.java.util.MapGenerator +import org.utbot.quickcheck.internal.generator.ArrayGenerator +import org.utbot.engine.greyboxfuzzer.util.getTrue +import org.utbot.engine.greyboxfuzzer.util.setFieldValue +import org.utbot.quickcheck.generator.java.lang.* +import kotlin.random.Random + +object GeneratorConfigurator { + private const val minByte: Byte = -100 + private const val maxByte: Byte = 100 + private val minShort: Short = -100 + private val maxShort: Short = 100 + private val minChar: Char = Character.MIN_VALUE + private val maxChar: Char = Character.MAX_VALUE + private val minInt: Int = -100 + private val maxInt: Int = 100 + private val minLong: Long = -100 + private val maxLong: Long = 100 + private val minFloat: Float = -100.0f + private val maxFloat: Float = 100.0f + private val minDouble: Double = -100.0 + private val maxDouble: Double = 100.0 + private val minStringLength: Int = 1 + private val maxStringLength: Int = 10 + val minCollectionSize: Int = 1 + val maxCollectionSize: Int = 5 + + private val sizeAnnotationInstance: Size + private val inRangeAnnotationInstance: InRange + + init { + val sizeAnnotationParams = + Size::class.constructors.first().parameters.associateWith { + if (it.name == "max") maxCollectionSize else minCollectionSize + } + sizeAnnotationInstance = Size::class.constructors.first().callBy(sizeAnnotationParams) + val inRangeAnnotationParams = + InRange::class.constructors.first().parameters.associateWith { + when (it.name) { + "minByte" -> minByte + "maxByte" -> maxByte + "minShort" -> minShort + "maxShort" -> maxShort + "minChar" -> minChar + "maxChar" -> maxChar + "minInt" -> minInt + "maxInt" -> maxInt + "minLong" -> minLong + "maxLong" -> maxLong + "minFloat" -> minFloat + "maxFloat" -> maxFloat + "minDouble" -> minDouble + "maxDouble" -> maxDouble + "max" -> "" + "min" -> "" + "format" -> "" + else -> "" + } + } + inRangeAnnotationInstance = InRange::class.constructors.first().callBy(inRangeAnnotationParams) + } + + fun configureGenerator(generator: Generator<*>, prob: Int) { + (listOf(generator) + generator.getAllComponents()).forEach { + if (Random.getTrue(prob)) handleGenerator(it) + } + } + + private fun handleGenerator(generator: Generator<*>) = + when (generator) { + is IntegerGenerator -> generator.configure(inRangeAnnotationInstance) + is ByteGenerator -> generator.configure(inRangeAnnotationInstance) + is ShortGenerator -> generator.configure(inRangeAnnotationInstance) + is CharacterGenerator -> generator.configure(inRangeAnnotationInstance) + is FloatGenerator -> generator.configure(inRangeAnnotationInstance) + is DoubleGenerator -> generator.configure(inRangeAnnotationInstance) + is LongGenerator -> generator.configure(inRangeAnnotationInstance) + is PrimitiveIntGenerator -> generator.configure(inRangeAnnotationInstance) + is PrimitiveByteGenerator -> generator.configure(inRangeAnnotationInstance) + is PrimitiveShortGenerator -> generator.configure(inRangeAnnotationInstance) + is PrimitiveCharGenerator -> generator.configure(inRangeAnnotationInstance) + is PrimitiveFloatGenerator -> generator.configure(inRangeAnnotationInstance) + is PrimitiveDoubleGenerator -> generator.configure(inRangeAnnotationInstance) + is PrimitiveLongGenerator -> generator.configure(inRangeAnnotationInstance) + is CollectionGenerator<*> -> generator.configure(sizeAnnotationInstance) + is ArrayGenerator -> generator.configure(sizeAnnotationInstance) + is MapGenerator -> generator.configure(sizeAnnotationInstance) + else -> Unit + } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt new file mode 100644 index 0000000000..38aa3de28f --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt @@ -0,0 +1,79 @@ +package org.utbot.engine.greyboxfuzzer.generator + + +import org.utbot.quickcheck.NonTrackingGenerationStatus +import org.utbot.quickcheck.generator.* +import org.utbot.quickcheck.generator.java.time.* +import org.utbot.quickcheck.generator.java.util.* +import org.utbot.quickcheck.generator.java.lang.* +import org.utbot.quickcheck.generator.java.math.* +import org.utbot.quickcheck.generator.java.nio.charset.CharsetGenerator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.* + +object GreyBoxFuzzerGenerators { + + const val seed = 42L + const val maxDepthOfGeneration = 4 + val sourceOfRandomness = SourceOfRandomness(Random(seed)) + val genStatus = NonTrackingGenerationStatus(sourceOfRandomness) + + val generatorRepository = + UTGeneratorRepository(sourceOfRandomness).also { + it.register(DurationGenerator()) + it.register(MonthDayGenerator()) + it.register(LocalDateTimeGenerator()) + it.register(YearMonthGenerator()) + it.register(ClockGenerator()) + it.register(ZonedDateTimeGenerator()) + it.register(LocalDateGenerator()) + it.register(ZoneIdGenerator()) + it.register(YearGenerator()) + it.register(OffsetTimeGenerator()) + it.register(InstantGenerator()) + it.register(ZoneOffsetGenerator()) + it.register(LocalTimeGenerator()) + it.register(OffsetDateTimeGenerator()) + it.register(PeriodGenerator()) + it.register(BigDecimalGenerator()) + it.register(BigIntegerGenerator()) + it.register(CharsetGenerator()) + it.register(ShortGenerator()) + it.register(BooleanGenerator()) + it.register(IntegerGenerator()) + it.register(Encoded()) + it.register(ByteGenerator()) + it.register(StringGenerator()) + it.register(LongGenerator()) + it.register(DoubleGenerator()) + it.register(CharacterGenerator()) + it.register(FloatGenerator()) + it.register(OptionalIntGenerator()) + it.register(OptionalDoubleGenerator()) + it.register(LinkedListGenerator()) + it.register(LinkedHashSetGenerator()) + it.register(HashMapGenerator()) + it.register(LocaleGenerator()) + it.register(BitSetGenerator()) + it.register(TimeZoneGenerator()) + it.register(HashSetGenerator()) + it.register(ArrayListGenerator()) + it.register(VectorGenerator()) + it.register(LinkedHashMapGenerator()) + it.register(HashtableGenerator()) + it.register(OptionalLongGenerator()) + it.register(PropertiesGenerator()) + it.register(OptionalGenerator()) + it.register(DateGenerator()) + it.register(StackGenerator()) + it.register(VoidGenerator()) + it.register(PrimitiveCharGenerator()) + it.register(PrimitiveBooleanGenerator()) + it.register(PrimitiveByteGenerator()) + it.register(PrimitiveDoubleGenerator()) + it.register(PrimitiveFloatGenerator()) + it.register(PrimitiveIntGenerator()) + it.register(PrimitiveLongGenerator()) + it.register(PrimitiveShortGenerator()) + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt new file mode 100644 index 0000000000..65636e54c4 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -0,0 +1,273 @@ +@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") + +package org.utbot.engine.greyboxfuzzer.generator + +import org.javaruntype.exceptions.TypeValidationException +import org.javaruntype.type.StandardTypeParameter +import org.javaruntype.type.Types +import org.utbot.common.withAccessibility +import org.utbot.engine.greyboxfuzzer.generator.userclasses.UserClassGenerator +import org.utbot.engine.greyboxfuzzer.util.ReflectionUtils +import org.utbot.engine.greyboxfuzzer.util.getActualTypeArguments +import org.utbot.engine.greyboxfuzzer.util.toClass +import org.utbot.engine.logger +import org.utbot.engine.rawType +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.quickcheck.internal.generator.ArrayGenerator +import org.utbot.quickcheck.internal.generator.GeneratorRepository +import ru.vyarus.java.generics.resolver.GenericsResolver +import ru.vyarus.java.generics.resolver.context.ConstructorGenericsContext +import ru.vyarus.java.generics.resolver.context.GenericsContext +import ru.vyarus.java.generics.resolver.context.GenericsInfo +import ru.vyarus.java.generics.resolver.context.MethodGenericsContext +import java.lang.reflect.* + + +fun Generator<*>.getAllComponents(): List> { + val queue = ArrayDeque>() + val res = mutableListOf>() + this.getComponents().forEach { queue.add(it) } + while (queue.isNotEmpty()) { + val comp = queue.removeFirst() + res.add(comp) + comp.getComponents().forEach(queue::add) + } + return res +} + +fun Generator<*>.getComponents(): List> = + when (this) { + is ComponentizedGenerator<*> -> this.componentGenerators() + is ArrayGenerator -> listOf(this.component) + else -> emptyList() + } + +fun GeneratorRepository.produceUserClassGenerator( + forClass: Class<*>, + parameterTypeContext: ParameterTypeContext, + depth: Int +): UserClassGenerator { + val userClassGenerator = UserClassGenerator().also { + it.clazz = forClass + it.parameterTypeContext = parameterTypeContext + it.depth = depth + } + addUserClassGenerator(forClass, userClassGenerator) + return userClassGenerator +} + +fun GeneratorRepository.getOrProduceGenerator(field: Field, depth: Int = 0): Generator<*>? = + getOrProduceGenerator(ParameterTypeContext.forField(field), depth) + +fun GeneratorRepository.getOrProduceGenerator(param: Parameter, parameterIndex: Int, depth: Int = 0): Generator<*>? = + getOrProduceGenerator(param.createParameterTypeContext(parameterIndex), depth) + +fun GeneratorRepository.getOrProduceGenerator(clazz: Class<*>, depth: Int = 0): Generator<*>? = + getOrProduceGenerator(clazz.createParameterTypeContext(), depth) + +fun GeneratorRepository.getOrProduceGenerator( + parameterTypeContext: ParameterTypeContext, + depth: Int +): Generator<*>? { + val producedUserClassesGenerators = mutableListOf() + parameterTypeContext.getAllSubParameterTypeContexts(GreyBoxFuzzerGenerators.sourceOfRandomness).reversed() + .forEach { typeContext -> + try { + this.produceGenerator(typeContext) + //TODO catch specific exception + } catch (e: Exception) { + producedUserClassesGenerators += produceUserClassGenerator(typeContext.rawClass, typeContext, depth + 1) + } + } + val generator = + try { + this.produceGenerator(parameterTypeContext) + } catch (e: Exception) { + logger.debug { "Can not get generator for ${parameterTypeContext.resolved}" } + return null + } finally { + producedUserClassesGenerators.forEach { removeGenerator(it.parameterTypeContext!!.resolved.rawClass) } + } + (listOf(generator) + generator.getAllComponents()).forEach { + GeneratorConfigurator.configureGenerator(it, 85) + } + return generator +} + +fun Parameter.createParameterTypeContext(parameterIndex: Int): ParameterTypeContext = + try { + //Classic scheme doesn't work for types with generics + if (this.type.typeParameters.isNotEmpty() && this.parameterizedType !is ParameterizedType) { + throw TypeValidationException("") + } + ParameterTypeContext.forParameter(this) + } catch (e: TypeValidationException) { + val clazz = this.type + val parametersBounds = + this.type.typeParameters.map { it.bounds.firstOrNull() ?: Any::class.java.rawType }.toTypedArray() + val p = ru.vyarus.java.generics.resolver.context.container.ParameterizedTypeImpl( + this.type, + *parametersBounds + ) + val genericContext = p.createGenericsContext(clazz) + createParameterContextForParameter(this, parameterIndex, genericContext, p) + } + +//fun ParameterTypeContext.getAllParameterTypeContexts(): List { +// fun ArrayDeque.addParameterContext(ctx: ParameterTypeContext) { +// if (ctx.resolved.name == Zilch::class.java.name) return +// add(ctx) +// } +// +// val res = mutableListOf(this) +// val queue = ArrayDeque() +// if (this.isArray) { +// this.arrayComponentContext().let { queue.addParameterContext(it) } +// } +// this.typeParameterContexts(GreyBoxFuzzerGenerators.sourceOfRandomness).forEach { queue.addParameterContext(it) } +// while (queue.isNotEmpty()) { +// val el = queue.removeFirst() +// if (el.isArray) { +// el.arrayComponentContext().let { queue.addParameterContext(it) } +// } +// el.typeParameterContexts(GreyBoxFuzzerGenerators.sourceOfRandomness).forEach { queue.addParameterContext(it) } +// res.add(el) +// } +// return res +//} + +fun Type.createGenericsContext(clazz: Class<*>): GenericsContext { + val actualTypeParams = this.getActualTypeArguments() + val klassTypeParams = this.toClass()?.typeParameters?.map { it.name } + val gm = LinkedHashMap() + klassTypeParams?.zip(actualTypeParams)?.forEach { gm[it.first] = it.second } + val m = mutableMapOf(clazz to gm) + val genericsInfo = GenericsInfo(clazz, m) + return GenericsContext(genericsInfo, clazz) +} + +fun Class<*>.createParameterTypeContext(): ParameterTypeContext { + val generics = GenericsResolver.resolve(this) + val resolvedGenerics = + generics.resolveTypeGenerics(this).map { createStandardTypeParameter(Types.forJavaLangReflectType(it)) } + val resolvedType = Types.forClass(this, *resolvedGenerics.toTypedArray()) + return ParameterTypeContext( + this.typeName, + FakeAnnotatedTypeFactory.makeFrom(this), + this.typeName, + resolvedType, + generics + ) +} + +fun createParameterContextForParameter( + parameter: Parameter, + parameterIndex: Int, + generics: GenericsContext +): ParameterTypeContext { + val exec = parameter.declaringExecutable + val clazz = exec.declaringClass + val declarerName = clazz.name + '.' + exec.name + val resolvedType = + when (generics) { + is MethodGenericsContext -> generics.resolveParameterType(parameterIndex) + is ConstructorGenericsContext -> generics.resolveParameterType(parameterIndex) + else -> throw IllegalArgumentException("Unexpected type of GenericsContext") + } + return ParameterTypeContext( + parameter.name, + parameter.annotatedType, + declarerName, + Types.forJavaLangReflectType( + resolvedType + ), + generics, + parameterIndex + ) +} + +fun createParameterContextForParameter( + parameter: Parameter, + parameterIndex: Int, + generics: GenericsContext, + type: Type +): ParameterTypeContext { + val exec = parameter.declaringExecutable + val clazz = exec.declaringClass + val declarerName = clazz.name + '.' + exec.name + return ParameterTypeContext( + parameter.name, + parameter.annotatedType, + declarerName, + ReflectionUtils.forJavaReflectTypeSafe(type), + generics, + parameterIndex + ) +} + +private fun createStandardTypeParameter(type: org.javaruntype.type.Type<*>): StandardTypeParameter<*> { + val constructor = StandardTypeParameter::class.java.declaredConstructors.first() + constructor.isAccessible = true + return constructor.withAccessibility { + constructor.newInstance(type) as StandardTypeParameter<*> + } +} + +//fun ParameterizedType.buildGenericsContext(): GenericsContext { +// val clazz = this.toClass()!! +// val klassTypeParams = clazz.typeParameters?.map { it.name } +// val gm = LinkedHashMap() +// klassTypeParams?.zip(this.actualTypeArguments)?.forEach { gm[it.first] = it.second } +// val m = mutableMapOf(clazz to gm) +// val genericsInfo = GenericsInfo(clazz, m) +// return GenericsContext(genericsInfo, clazz) +//} + +//fun Field.resolveFieldType(originalType: ParameterizedType): Type { +// return originalType.buildGenericsContext().resolveFieldType(this) +//} +// +//fun Field.resolveFieldType(genericsContext: GenericsContext): Type? = +// try { +// genericsContext.resolveFieldType(this) +// } catch (_: Throwable) { +// null +// } + +//fun Field.buildParameterContext(originalType: ParameterizedType): ParameterTypeContext { +// val ctx = originalType.buildGenericsContext() +// return createParameterTypeContext( +// this.name, +// this.annotatedType, +// this.declaringClass.name, +// Types.forJavaLangReflectType(ctx.resolveFieldType(this)), +// ctx +// ) +//} + +//fun Field.buildParameterContext(genericsContext: GenericsContext): ParameterTypeContext { +// return createParameterTypeContext( +// this.name, +// this.annotatedType, +// this.declaringClass.name, +// Types.forJavaLangReflectType(genericsContext.resolveFieldType(this)), +// genericsContext +// ) +//} +//@Deprecated("Not implemented") +//fun Type.buildParameterContext(): ParameterTypeContext? { +// val clazz = this.toClass() ?: return null +// return if (this is ParameterizedType) { +// buildParameterContext() +// } else { +// createParameterTypeContext( +// clazz.typeName, +// FakeAnnotatedTypeFactory.makeFrom(clazz), +// clazz.typeName, +// Types.forJavaLangReflectType(this), +// GenericsResolver.resolve(clazz) +// ) +// } +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/ThisInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/ThisInstanceGenerator.kt new file mode 100644 index 0000000000..4a518716d9 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/ThisInstanceGenerator.kt @@ -0,0 +1,18 @@ +package org.utbot.engine.greyboxfuzzer.generator + +import org.utbot.external.api.classIdForType +import org.utbot.framework.concrete.UtModelConstructor +import org.utbot.framework.plugin.api.UtModel +import java.util.* + +//object ThisInstanceGenerator { +// +// var utModelThisInstance: UtModel? = null +// +// fun generateThis(clazz: Class<*>) { +// utModelThisInstance = InstancesGenerator.generateInstanceWithUnsafe(clazz, 0, true, null)?.let { +// UtModelConstructor(IdentityHashMap()).construct(it, classIdForType(clazz)) +// } +// } +// +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt new file mode 100644 index 0000000000..77b0c0789f --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt @@ -0,0 +1,28 @@ +package org.utbot.engine.greyboxfuzzer.generator + +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.quickcheck.internal.generator.GeneratorRepository +import org.utbot.quickcheck.internal.generator.LambdaGenerator +import org.utbot.quickcheck.internal.generator.MarkerInterfaceGenerator +import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.util.toClass +import org.utbot.engine.logger + +class UTGeneratorRepository(random: SourceOfRandomness) : GeneratorRepository(random) { + + override fun generatorFor(parameter: ParameterTypeContext): Generator<*>? { + logger.debug { "TRYING TO GET GENERATOR FOR ${parameter.resolved}" } + if (parameter.resolved.name == "org.utbot.quickcheck.internal.Zilch") return null + val generator = super.generatorFor(parameter) + if (generator is MarkerInterfaceGenerator<*>) { + throw IllegalArgumentException( + "Cannot find generator for " + parameter.name() + + " of type " + parameter.type().typeName + ) + } else if (generator is LambdaGenerator<*, *>) { + return null + } + return generator + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashMapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashMapGenerator.kt new file mode 100644 index 0000000000..480eab9a9c --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashMapGenerator.kt @@ -0,0 +1,9 @@ +//package org.utbot.engine.greyboxfuzzer.generator.map +// +//import java.util.* +// +//class HashMapGenerator : MapGenerator>(HashMap::class.java) { +// override fun okToAdd(key: Any?, value: Any?): Boolean { +// return key != null && value != null +// } +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashtableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashtableGenerator.kt new file mode 100644 index 0000000000..8ad61b5138 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashtableGenerator.kt @@ -0,0 +1,9 @@ +//package org.utbot.engine.greyboxfuzzer.generator.map +// +//import java.util.* +// +//class HashtableGenerator : MapGenerator>(Hashtable::class.java) { +// override fun okToAdd(key: Any?, value: Any?): Boolean { +// return key != null && value != null +// } +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/LinkedHashMapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/LinkedHashMapGenerator.kt new file mode 100644 index 0000000000..b881f2f31e --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/LinkedHashMapGenerator.kt @@ -0,0 +1,7 @@ +//package org.utbot.engine.greyboxfuzzer.generator.map +// +//class LinkedHashMapGenerator : MapGenerator>(LinkedHashMap::class.java) { +// override fun okToAdd(key: Any?, value: Any?): Boolean { +// return key != null && value != null +// } +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/MapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/MapGenerator.kt new file mode 100644 index 0000000000..27cbd7dc63 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/MapGenerator.kt @@ -0,0 +1,60 @@ +//package org.utbot.engine.greyboxfuzzer.generator.map +// +//import org.utbot.quickcheck.generator.ComponentizedGenerator +//import org.utbot.quickcheck.generator.Distinct +//import org.utbot.quickcheck.generator.GenerationStatus +//import org.utbot.quickcheck.generator.Size +//import org.utbot.quickcheck.internal.Reflection +//import org.utbot.quickcheck.random.SourceOfRandomness +//import org.javaruntype.type.TypeParameter +//import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator +//import kotlin.random.Random +//import kotlin.system.exitProcess +// +//abstract class MapGenerator>(type: Class) : ComponentizedGenerator(type) { +// +// private var sizeRange: Size? = null +// private var distinct = false +// +// open fun configure(size: Size) { +// sizeRange = size +// } +// open fun configure(distinct: Distinct?) { +// this.distinct = distinct != null +// } +// +// override fun generate(random: SourceOfRandomness?, status: GenerationStatus?): T { +// val items = empty() +// val minSize = sizeRange?.min ?: GeneratorConfigurator.minCollectionSize +// val maxSize = sizeRange?.max ?: GeneratorConfigurator.maxCollectionSize +// val size = Random.nextInt(minSize, maxSize) +// val keyGenerator = componentGenerators().first() +// val valueGenerator = componentGenerators().last() +// repeat(size) { +// val key = keyGenerator.generate(random, status) +// val value = valueGenerator.generate(random, status) +// if (okToAdd(key, value)) { +// items[key] = value +// } +// } +// return items as T +// } +// +// override fun canGenerateForParametersOfTypes( +// typeParameters: List?> +// ): Boolean { +// return true +// } +// +// override fun numberOfNeededComponents(): Int { +// return 2 +// } +// +// protected fun empty(): MutableMap { +// return Reflection.instantiate(Reflection.findConstructor(types()[0])) as MutableMap +// } +// +// protected open fun okToAdd(key: Any?, value: Any?): Boolean { +// return true +// } +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt new file mode 100644 index 0000000000..408f8a9145 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt @@ -0,0 +1,5 @@ +package org.utbot.engine.greyboxfuzzer.generator.set + +import org.utbot.quickcheck.generator.java.util.SetGenerator + +class HashSetGenerator: SetGenerator>(HashSet::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/LinkedHashSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/LinkedHashSetGenerator.kt new file mode 100644 index 0000000000..ee2871e244 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/LinkedHashSetGenerator.kt @@ -0,0 +1,3 @@ +//package org.utbot.engine.greyboxfuzzer.generator.set +// +//class LinkedHashSetGenerator: SetGenerator>(LinkedHashSet::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/SetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/SetGenerator.kt new file mode 100644 index 0000000000..df6ce0f375 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/SetGenerator.kt @@ -0,0 +1,43 @@ +//package org.utbot.engine.greyboxfuzzer.generator.set +// +//import org.utbot.quickcheck.generator.GenerationStatus +//import org.utbot.quickcheck.generator.Size +//import org.utbot.quickcheck.generator.java.util.CollectionGenerator +//import org.utbot.quickcheck.internal.Reflection +//import org.utbot.quickcheck.random.SourceOfRandomness +//import org.javaruntype.type.TypeParameter +//import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator +//import kotlin.random.Random +// +//abstract class SetGenerator>(type: Class) : CollectionGenerator(type) { +// override fun configure(size: Size?) { +// super.configure(size) +// } +// +// override fun generate(random: SourceOfRandomness?, status: GenerationStatus?): T { +// val minSize = GeneratorConfigurator.minCollectionSize +// val maxSize = GeneratorConfigurator.maxCollectionSize +// val size = Random.nextInt(minSize, maxSize) +// val set = createSet() +// val valueGenerator = componentGenerators().first() +// repeat(size) { +// valueGenerator.generate(random, status)?.let { set.add(it) } +// } +// return set as T +// } +// +// override fun canGenerateForParametersOfTypes( +// typeParameters: List?> +// ): Boolean { +// return true +// } +// +// override fun numberOfNeededComponents(): Int { +// return 1 +// } +// +// fun createSet(): MutableSet { +// return Reflection.instantiate(Reflection.findConstructor(types()[0])) as MutableSet +// } +// +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/InstancesGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/InstancesGenerator.kt new file mode 100644 index 0000000000..8f170ea0c7 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/InstancesGenerator.kt @@ -0,0 +1,521 @@ +//@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") +// +//package org.utbot.engine.greyboxfuzzer.generator.userclasses +// +//import org.utbot.quickcheck.internal.ParameterTypeContext +//import org.javaruntype.type.Types +//import org.utbot.engine.greyboxfuzzer.generator.DataGenerator +//import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGenerators +//import org.utbot.engine.greyboxfuzzer.generator.createParameterContextForParameter +//import org.utbot.engine.greyboxfuzzer.generator.getOrProduceGenerator +//import org.utbot.engine.greyboxfuzzer.util.* +//import org.utbot.engine.isPublic +//import org.utbot.external.api.classIdForType +//import org.utbot.framework.plugin.api.* +//import org.utbot.framework.plugin.api.util.* +//import ru.vyarus.java.generics.resolver.context.GenericsContext +//import ru.vyarus.java.generics.resolver.util.GenericsUtils +//import soot.Scene +//import sun.reflect.annotation.AnnotatedTypeFactory +//import sun.reflect.annotation.TypeAnnotation +//import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl +//import java.lang.reflect.* +//import java.util.* +//import kotlin.collections.LinkedHashMap +//import kotlin.random.Random +//import ru.vyarus.java.generics.resolver.context.container.ParameterizedTypeImpl as GParameterizedTypeImpl +// +//object InstancesGenerator { +// +// fun generateInstanceUsingConstructor( +// clazz: Class<*>, +// gctx: GenericsContext, +// initGenericContext: GenericsContext, +// depth: Int +// ): UtModel? { +// val randomPublicConstructor = +// try { +// clazz.declaredConstructors +// .filter { +// it.isPublic || !it.hasAtLeastOneOfModifiers( +// Modifier.PROTECTED, +// Modifier.PRIVATE +// ) +// } +// //Avoiding recursion +// .filter { it.parameterTypes.all { !it.name.contains(clazz.name) } } +// .chooseRandomConstructor() +// } catch (_: Throwable) { +// null +// } +// val randomConstructor = +// try { +// clazz.declaredConstructors +// .filter { it.parameterTypes.all { !it.name.contains(clazz.name) } } +// .toList().chooseRandomConstructor() +// } catch (_: Throwable) { +// null +// } +// val constructor = if (Random.getTrue(75)) randomPublicConstructor ?: randomConstructor else randomConstructor +// constructor ?: return null +// constructor.isAccessible = true +// val resolvedConstructor = +// gctx.constructor(constructor).let { +// try { +// it.toString() +// it +// } catch (_: Throwable) { +// initGenericContext.constructor(constructor) +// } +// } +// val parameterValues = constructor.parameters.withIndex().map { indexedParameter -> +// val parameterContext = +// createParameterContextForParameter(indexedParameter.value, indexedParameter.index, resolvedConstructor) +// val generator = GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator( +// parameterContext, +// depth +// ) +// println("GOT A GENERATOR $generator") +// try { +// generator?.generate(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) +// } catch (e: Exception) { +// null +// } +// } +// if (parameterValues.any { it == null }) { +// return UtNullModel(classIdForType(clazz)) +// } +// return UtModelGenerator.utModelConstructor.constructAssembleModelUsingMethodInvocation( +// clazz, +// constructor.executableId, +// parameterValues.filterNotNull() +// ) +//// return try { +//// //constructor.newInstance(*parameterValues.toTypedArray()) +//// UtNullModel(classIdForType(clazz)) +//// } catch (e: Exception) { +//// null +//// } catch (e: Error) { +//// null +//// } +// } +// +// //TODO rewrite this +// fun generateInstanceUsingStatics( +// resolvedType: org.javaruntype.type.Type<*>, +// gctx: GenericsContext, +// parameterTypeContext: ParameterTypeContext, +// depth: Int +// ): UtModel? { +// println("VIA STATIC FIELD") +// if (depth > GreyBoxFuzzerGenerators.maxDepthOfGeneration) return null +// //TODO filter not suitable methods with generics with bad bounds +// //TODO make it work for subtypes +// val resolvedStaticMethods = +// try { +// resolvedType.componentClass.declaredMethods.filter { it.hasModifiers(Modifier.STATIC, Modifier.PUBLIC) } +// .map { it to gctx.method(it).resolveReturnType() } +// .filter { it.first.returnType.toClass() == resolvedType.componentClass } +// .filter { it.first.parameterTypes.all { !it.name.contains(resolvedType.componentClass.name) } } +// } catch (e: Error) { +// listOf() +// } +// val resolvedStaticFields = +// try { +// resolvedType.componentClass.declaredFields.filter { it.hasModifiers(Modifier.STATIC, Modifier.PUBLIC) } +// .map { it to gctx.resolveFieldType(it) } +// .filter { it.first.type.toClass() == resolvedType.componentClass } +// } catch (e: Error) { +// listOf() +// } +// //println("FIELD = $resolvedStaticFields") +// val (fieldOrMethodToProvideInstance, typeToGenerate) = +// if (Random.nextBoolean()) { +// resolvedStaticFields.randomOrNull() ?: resolvedStaticMethods.randomOrNull() +// } else { +// resolvedStaticMethods.randomOrNull() ?: resolvedStaticFields.randomOrNull() +// } ?: return null +// val fieldValue = when (fieldOrMethodToProvideInstance) { +// is Field -> with(UtModelGenerator.utModelConstructor){ +// val generatedModelId = computeUnusedIdAndUpdate() +// val instantiationChain = mutableListOf() +// val generatedModel = UtAssembleModel( +// id = generatedModelId, +// classId = classIdForType(fieldOrMethodToProvideInstance.type), +// modelName = "xxx_$generatedModelId", +// instantiationChain = instantiationChain +// ) +// +// val fieldModelId = computeUnusedIdAndUpdate() +// val fieldModel = UtCompositeModel(fieldModelId, Field::class.java.id, isMock = false) +// +// val classModelId = computeUnusedIdAndUpdate() +// val classModel = UtCompositeModel(classModelId, Class::class.java.id, isMock = false) +// +// val classInstanceModel = construct(resolvedType.rawClass, classClassId) as UtReferenceModel +// +// instantiationChain += UtExecutableCallModel( +// instance = null, +// executable = methodId(Objects::class.java.id, "requireNonNull", objectClassId, objectClassId), +// params = listOf(classInstanceModel), +// returnValue = classModel +// ) +// +// instantiationChain += UtExecutableCallModel( +// classModel, +// Class<*>::getField.executableId, +// listOf(construct(fieldOrMethodToProvideInstance.name, stringClassId)), +// returnValue = fieldModel +// ) +// +// instantiationChain += UtExecutableCallModel( +// fieldModel, +// Field::get.executableId, +// listOf(UtNullModel(resolvedType.rawClass.id)), +// returnValue = generatedModel +// ) +// +// generatedModel +// +//// fieldOrMethodToProvideInstance.getFieldValue(null)?.let { +//// UtModelGenerator.utModelConstructor.construct(it, classIdForType(it::class.java)) +//// } ?: return null +// } +// is Method -> { +// val parameterValues = +// if (fieldOrMethodToProvideInstance.typeParameters.isNotEmpty()) { +// generateParameterValuesToFunctionsWithGenerics( +// fieldOrMethodToProvideInstance, +// gctx, +// resolvedType, +// parameterTypeContext, +// depth +// ) +// } else { +// fieldOrMethodToProvideInstance.parameters.map { parameter -> +// generateParameterValue( +// parameter, +// resolvedType.componentClass.name, +// gctx, +// false, +// null, +// depth +// ) +// } +// } +// fieldOrMethodToProvideInstance.isAccessible = true +// UtModelGenerator.utModelConstructor.constructAssembleModelUsingMethodInvocation( +// resolvedType.rawClass, +// fieldOrMethodToProvideInstance.executableId, +// parameterValues.filterNotNull() +// ) +// } +// else -> return null +// } +// return fieldValue +// } +// +// fun generateInterfaceInstanceViaStaticCall( +// method: Method, +// parameterTypeContext: ParameterTypeContext, +// depth: Int +// ): UtModel? { +// return try { +// val methodReturnTypeAsParameterizedType = method.genericReturnType as? ParameterizedType +// val actualTypeArguments = methodReturnTypeAsParameterizedType?.actualTypeArguments?.toList() ?: emptyList() +// val (generics, gctx) = method.resolveMethod(parameterTypeContext, actualTypeArguments) +// val args = method.parameters.mapIndexed { index, parameter -> +// val resolvedParameterType = GenericsUtils.resolveTypeVariables(parameter.parameterizedType, generics) +// createParameterContextForParameter(parameter, index, gctx, resolvedParameterType).let { ptx -> +// val generator = GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(ptx, depth) +// generator?.generate(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) +// } +// } +// method.isAccessible = true +// //method.invoke(null, *args.toTypedArray()) +// val clazzAsClass = method.genericReturnType.toClass() ?: return null +// UtModelGenerator.utModelConstructor.constructAssembleModelUsingMethodInvocation( +// clazzAsClass, +// method.executableId, +// args.filterNotNull() +// ) +// } catch (e: Throwable) { +// null +// } +// } +// +// //TODO finish someday +// fun generateFunctionalInterface( +// parameterTypeContext: ParameterTypeContext, +// depth: Int +// ): Any? { +// val clazz = parameterTypeContext.type().toClass() ?: return null +// val methodToImplement = clazz.methods.filterNot { +// it.hasModifiers(Modifier.STATIC) || it.toGenericString() +// .contains(" default ") || it.name == "equals" || it.name == "toString" || it.name == "hashCode" +// }.first() +// val (generics, gctx) = methodToImplement.resolveMethod(parameterTypeContext, clazz.typeParameters.toList()) +// val resolvedTypes = +// methodToImplement.parameters.mapIndexed { index, parameter -> +// val resolvedParameterType = GenericsUtils.resolveTypeVariables(parameter.parameterizedType, generics) +// createParameterContextForParameter(parameter, index, gctx, resolvedParameterType).resolved +// } +// val resolvedReturnType = gctx.method(methodToImplement).resolveReturnType() +// val methodToRef = Scene.v().classes.flatMap { it.methods } +// .filter { it.isStatic && it.returnType.toString() == resolvedReturnType.toString() } +// .filter { +// it.parameterTypes.joinToString() == resolvedTypes.map { it.convertToPrimitiveIfPossible() } +// .joinToString() +// } +// return null +// } +// +// private fun generateParameterValuesToFunctionsWithGenerics( +// method: Method, +// gctx: GenericsContext, +// resolvedType: org.javaruntype.type.Type<*>, +// parameterTypeContext: ParameterTypeContext, +// depth: Int +// ): List { +// val parameterType = parameterTypeContext.generics.resolveType(parameterTypeContext.type()) +// val generics = LinkedHashMap() +// (method.genericReturnType as? ParameterizedTypeImpl)?.actualTypeArguments?.forEachIndexed { index, typeVariable -> +// val actualTypeArg = (parameterType as? GParameterizedTypeImpl)?.actualTypeArguments?.get(index) +// if (actualTypeArg != null) { +// generics[typeVariable.typeName] = actualTypeArg +// } +// } +// gctx.method(method).methodGenericsMap().forEach { (s, type) -> generics.getOrPut(s) { type } } +// return method.parameters.map { parameter -> +// println("OLD TYPE = ${parameter.type}") +// val resolvedParameterType = GenericsUtils.resolveTypeVariables(parameter.parameterizedType, generics) +// println("NEW TYPE = ${resolvedParameterType}") +// val value = +// generateParameterValue( +// parameter, +// resolvedType.componentClass.name, +// gctx, +// false, +// resolvedParameterType, +// depth +// ) +// println("GENERATED VALUE = $value") +// value +// } +// } +// +// +// fun generateValueOfType( +// fieldOrParameterForGeneration: Any, +// gctx: GenericsContext, +// name: String, +// annotatedType: AnnotatedType, +// declaringTypeName: String, +// alternativeTypeContext: ParameterTypeContext, +// setAllObjectsToNull: Boolean, +// resolvedType: Type? = null, +// depth: Int +// ): UtModel? { +// //TODO!!!!!!! Make it work for inner classes +// if (fieldOrParameterForGeneration.toString().contains("$")) return null +// +// var clazz: Class<*>? +// val context = +// try { +// val finallyResolvedType = when (fieldOrParameterForGeneration) { +// is Field -> { +// clazz = fieldOrParameterForGeneration.type +// gctx.resolveFieldType(fieldOrParameterForGeneration) +// } +// is Parameter -> { +// clazz = fieldOrParameterForGeneration.type +// resolvedType ?: gctx.resolveType(fieldOrParameterForGeneration.parameterizedType) +// } +// else -> return null +// } +// ParameterTypeContext( +// name, +// AnnotatedTypeFactory.buildAnnotatedType( +// finallyResolvedType, +// TypeAnnotation.LocationInfo.BASE_LOCATION, +// arrayOf(), +// arrayOf(), +// null +// ), +// //annotatedType, +// declaringTypeName, +// Types.forJavaLangReflectType(finallyResolvedType), +// gctx +// ) +// } catch (e: java.lang.IllegalArgumentException) { +// clazz = alternativeTypeContext.type().toClass() +// alternativeTypeContext +// } +// if (!clazz!!.isPrimitive && setAllObjectsToNull) +// return null +// +// val generator = GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(context, depth) +// //generator.generate(DataGeneratorSettings.sourceOfRandomness, DataGeneratorSettings.genStatus) +// return generator?.generate(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) +// } +// +// private fun generateParameterValue( +// parameter: Parameter, +// clazzName: String, +// gctx: GenericsContext, +// setAllObjectsToNull: Boolean, +// resolvedType: Type? = null, +// depth: Int +// ): UtModel? = +// generateValueOfType( +// parameter, +// gctx, +// parameter.name, +// //parameter.declaringExecutable.let { it.declaringClass.name + '.' + it.name }, +// parameter.annotatedType, +// clazzName, +// ParameterTypeContext.forParameter(parameter), +// setAllObjectsToNull, +// resolvedType, +// depth +// ) +// +// // fun regenerateRandomFields(clazz: Class<*>, classInstance: Any, numOfFields: Int): Any? { +//// +//// } +//// fun regenerateRandomFields(clazz: Class<*>, classInstance: Any) { +//// val parameterTypeContext = ParameterTypeContext.forClass(clazz) +//// val fields = clazz.getAllDeclaredFields() +//// .filterNot { it.hasModifiers(Modifier.STATIC, Modifier.FINAL) } +//// .toMutableList() +//// repeat(Random.nextInt(0, 10)) { +//// val randomField = fields.randomOrNull() ?: return@repeat +//// if (Random.getTrue(20)) { +//// randomField.setDefaultValue(classInstance) +//// } else { +//// setNewFieldValue(randomField, parameterTypeContext, classInstance, 0, false) +//// } +//// fields.remove(randomField) +//// } +//// } +// +// fun regenerateFields(clazz: Class<*>, classInstance: UtAssembleModel, fieldsToRegenerate: List): UtModel { +// val parameterTypeContext = ParameterTypeContext.forClass(clazz) +// var resUtModel = classInstance +// for (field in fieldsToRegenerate) { +// resUtModel = setNewFieldValue(field, parameterTypeContext, resUtModel) +// } +// return resUtModel +// } +// +// private fun setNewFieldValue( +// field: Field, +// parameterTypeContext: ParameterTypeContext, +// clazzInstance: UtAssembleModel +// ): UtAssembleModel { +// field.isAccessible = true +// val oldFieldValue = field.getFieldValue(clazzInstance) +// if (field.hasAtLeastOneOfModifiers(Modifier.STATIC, Modifier.FINAL) && oldFieldValue != null) return clazzInstance +// val fieldType = parameterTypeContext.generics.resolveFieldType(field) +// println("F = $field TYPE = $fieldType OLDVALUE = $oldFieldValue") +// val parameterTypeContextForResolvedType = ParameterTypeContext( +// field.name, +// field.annotatedType, +// field.declaringClass.name, +// Types.forJavaLangReflectType(fieldType), +// parameterTypeContext.generics +// ) +// val newFieldValue = DataGenerator.generate( +// parameterTypeContextForResolvedType, +// GreyBoxFuzzerGenerators.sourceOfRandomness, +// GreyBoxFuzzerGenerators.genStatus +// ) +// println("NEW FIELD VALUE = $newFieldValue") +// if (newFieldValue != null) { +// return clazzInstance.addModification(UtDirectSetFieldModel(clazzInstance, field.fieldId, newFieldValue)) +// } +// return clazzInstance +//// val generator = DataGeneratorSettings.generatorRepository.getOrProduceGenerator( +//// parameterTypeContextForResolvedType, +//// 0 +//// ) ?: return null +//// if (isRecursiveWithUnsafe) { +//// (listOf(generator) + generator.getAllComponents()).forEach { +//// if (it is UserClassesGenerator) it.generationMethod = GenerationMethod.UNSAFE +//// } +//// } +//// println("I GOT GENERATOR!! $generator") +//// var newFieldValue: Any? = null +//// repeat(3) { +//// try { +//// if (newFieldValue == null) { +//// newFieldValue = +//// generator.generate(DataGeneratorSettings.sourceOfRandomness, DataGeneratorSettings.genStatus) +//// } +//// } catch (e: Exception) { +//// return@repeat +//// } +//// } +//// println("NEW VALUE GENERATED!!") +//// if (newFieldValue != null) { +//// try { +//// println("NEW VALUE = ${newFieldValue} CLASS ${newFieldValue!!::class.java}") +//// } catch (e: Throwable) { +//// println("NEW VALUE OF CLASS ${newFieldValue!!::class.java} generated") +//// } +//// } +//// if (newFieldValue != null) { +//// field.setFieldValue(clazzInstance, newFieldValue) +//// } +//// return newFieldValue +// } +// +//// fun generateInstanceWithUnsafe( +//// clazz: Class<*>, +//// depth: Int, +//// isRecursiveWithUnsafe: Boolean, +//// genericsContext: GenericsContext? +//// ): UtModel? { +//// println("TRYING TO GENERATE ${clazz.name} instance") +//// if (depth >= DataGeneratorSettings.maxDepthOfGeneration) return null +//// val clazzInstance = +//// try { +//// InstancesGenerator.generateInstanceViaConstructor( +//// resolvedJavaType.toClass()!!, +//// gctx, +//// parameterTypeContext!!.getGenericContext(), +//// depth +//// ) +//// val defaultConstructor = clazz.constructors.minByOrNull { it.parameterCount } ?: return null +//// } catch (e: Exception) { +//// return null +//// } catch (e: Error) { +//// return null +//// } +//// clazz.getAllDeclaredFields().forEach { field -> +//// try { +//// val ptx = genericsContext?.let { field.buildParameterContext(genericsContext) } +//// ?: ParameterTypeContext.forField(field) +//// val newFieldValue = setNewFieldValue(field, ptx, clazzInstance, depth, isRecursiveWithUnsafe) +//// println("SET ${field.name} value of type ${ptx.resolved} to $newFieldValue") +//// } catch (_: Throwable) { +//// println("CANT SET FIELD ${field.name}") +//// } +//// } +//// return UtNullModel(classIdForType(clazz)) +//// } +// +//// fun generateInstanceWithDefaultConstructorOrUnsafe(clazz: Class<*>): Any? { +//// val defaultConstructor = clazz.constructors.find { it.parameterCount == 0 } +//// return if (defaultConstructor != null) { +//// defaultConstructor.newInstance() +//// } else { +//// try { +//// UserClassesGenerator.UNSAFE.allocateInstance(clazz) +//// } catch (e: Throwable) { +//// null +//// } +//// } +//// } +// +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt new file mode 100644 index 0000000000..30bd7fbd6a --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt @@ -0,0 +1,79 @@ +@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") + +package org.utbot.engine.greyboxfuzzer.generator.userclasses + +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.quickcheck.random.SourceOfRandomness +import org.javaruntype.type.TypeParameter +import org.utbot.engine.greyboxfuzzer.generator.* +import org.utbot.engine.greyboxfuzzer.generator.userclasses.generator.* +import org.utbot.engine.greyboxfuzzer.util.* +import org.utbot.engine.logger +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.id +import java.lang.reflect.* + +class UserClassGenerator : ComponentizedGenerator(Any::class.java) { + + var clazz: Class<*>? = null + var parameterTypeContext: ParameterTypeContext? = null + var depth = 0 + var generationMethod = GenerationMethod.ANY + + override fun copy(): Generator { + return UserClassGenerator().also { + it.clazz = clazz + it.depth = depth + it.parameterTypeContext = parameterTypeContext + } + } + + override fun canGenerateForParametersOfTypes(typeParameters: MutableList>?): Boolean { + return true + } + + override fun numberOfNeededComponents(): Int { + return parameterTypeContext?.resolved?.typeParameters?.size ?: 0 + } + + fun generate(random: SourceOfRandomness, status: GenerationStatus, generationMethod: GenerationMethod): UtModel? { + this.generationMethod = generationMethod + return generate(random, status) + } + + override fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel? { + logger.debug { "Trying to generate ${parameterTypeContext!!.resolved}. Current depth depth: $depth" } + if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return null + val immutableClazz = clazz!! + if (immutableClazz == Any::class.java) return ObjectGenerator(random, status).generate() + if (immutableClazz == Class::class.java) return ReflectionClassGenerator(parameterTypeContext!!).generate() + //TODO! generate inner classes instances + if (immutableClazz.declaringClass != null && !immutableClazz.hasModifiers(Modifier.STATIC)) { + return UtNullModel(immutableClazz.id) + } + val resolvedJavaType = parameterTypeContext!!.generics.resolveType(parameterTypeContext!!.type()) + val gctx = resolvedJavaType.createGenericsContext(immutableClazz) + if (!immutableClazz.canBeInstantiated()) { + return InterfaceImplementationsInstanceGenerator( + resolvedJavaType, + gctx, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus, + depth + ).generate() + } + return ClassesInstanceGenerator( + clazz!!, + gctx, + parameterTypeContext!!.generics, + generationMethod, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus, + depth + ).generate() + } +} diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt new file mode 100644 index 0000000000..b5e117c6b5 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt @@ -0,0 +1,50 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.engine.logger +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.GenericsContext + +class ClassesInstanceGenerator( + private val clazz: Class<*>, + private val gctx: GenericsContext, + private val initialContext: GenericsContext?, + private val generationMethod: GenerationMethod, + private val sourceOfRandomness: SourceOfRandomness, + private val genStatus: GenerationStatus, + private val depth: Int +): InstanceGenerator { + override fun generate(): UtModel? { + val typeOfGenerations = when (generationMethod) { + GenerationMethod.CONSTRUCTOR -> mutableListOf('c') + GenerationMethod.STATIC -> mutableListOf('s') + else -> mutableListOf('c', 'c', 's') + } + while (typeOfGenerations.isNotEmpty()) { + val randomTypeOfGeneration = typeOfGenerations.randomOrNull() ?: return null + logger.debug { "Type of generation: $randomTypeOfGeneration" } + val generatedInstance = + when (randomTypeOfGeneration) { + 'c' -> ConstructorBasedInstanceGenerator( + clazz, + gctx, + initialContext, + sourceOfRandomness, + genStatus, + depth + ).generate() + 's' -> StaticsBasedInstanceGenerator( + clazz, + gctx, + sourceOfRandomness, + genStatus, + depth + ).generate() + else -> null + } + generatedInstance?.let { return it } ?: typeOfGenerations.removeIf { it == randomTypeOfGeneration } + } + return null + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt new file mode 100644 index 0000000000..f79a24fbbb --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt @@ -0,0 +1,77 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.common.isPublic +import org.utbot.engine.greyboxfuzzer.util.* +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.executableId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.GenericsContext +import java.lang.reflect.Constructor +import java.lang.reflect.Modifier +import kotlin.random.Random + +class ConstructorBasedInstanceGenerator( + private val clazz: Class<*>, + private val gctx: GenericsContext, + private val initialGenericContext: GenericsContext?, + private val sourceOfRandomness: SourceOfRandomness, + private val generationStatus: GenerationStatus, + private val depth: Int +): InstanceGenerator { + + override fun generate(): UtModel? { + val constructor = chooseRandomConstructor(clazz) ?: return null + val resolvedConstructor = + //In case if we can not resolve constructor + gctx.constructor(constructor).let { + try { + it.toString() + it + } catch (_: Throwable) { + try { + initialGenericContext?.constructor(constructor) + } catch (_: Throwable) { + null + } + } + } + return ExecutableInvoker( + constructor, + clazz, + constructor.executableId, + resolvedConstructor, + sourceOfRandomness, + generationStatus, + depth + ).invoke() + } + + private fun chooseRandomConstructor(clazz: Class<*>): Constructor<*>? { + val randomPublicConstructor = + try { + clazz.declaredConstructors + .filter { + it.isPublic || !it.hasAtLeastOneOfModifiers( + Modifier.PROTECTED, + Modifier.PRIVATE + ) + } + //Avoiding recursion + .filter { it.parameterTypes.all { !it.name.contains(clazz.name) } } + .chooseRandomConstructor() + } catch (_: Throwable) { + null + } + val randomConstructor = + try { + clazz.declaredConstructors + .filter { it.parameterTypes.all { !it.name.contains(clazz.name) } } + .toList().chooseRandomConstructor() + } catch (_: Throwable) { + null + } + return if (Random.getTrue(75)) randomPublicConstructor ?: randomConstructor else randomConstructor + } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt new file mode 100644 index 0000000000..f6ecbe6bcd --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt @@ -0,0 +1,42 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.engine.greyboxfuzzer.generator.DataGenerator +import org.utbot.engine.greyboxfuzzer.generator.createParameterContextForParameter +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator +import org.utbot.engine.greyboxfuzzer.util.constructAssembleModelUsingMethodInvocation +import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.GenericsContext +import java.lang.reflect.Executable + +class ExecutableInvoker( + private val executable: Executable, + private val clazz: Class<*>, + private val executableId: ExecutableId, + private val genericsContext: GenericsContext?, + private val sourceOfRandomness: SourceOfRandomness, + private val generationStatus: GenerationStatus, + private val depth: Int +) { + fun invoke(): UtModel { + val parameterValues = executable.parameters.withIndex().map { indexedParameter -> + val parameterContext = + if (genericsContext != null) { + createParameterContextForParameter(indexedParameter.value, indexedParameter.index, genericsContext) + } else { + ParameterTypeContext.forParameter(indexedParameter.value) + } + DataGenerator.generate(parameterContext, sourceOfRandomness, generationStatus, depth)?: UtNullModel(parameterContext.rawClass.id) + } + return UtModelGenerator.utModelConstructor.constructAssembleModelUsingMethodInvocation( + clazz, + executableId, + parameterValues + ) + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt new file mode 100644 index 0000000000..648c494b7f --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt @@ -0,0 +1,5 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +enum class GenerationMethod { + CONSTRUCTOR, STATIC, STATIC_EXT, ANY +} diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt new file mode 100644 index 0000000000..09ffc014ed --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt @@ -0,0 +1,7 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.framework.plugin.api.UtModel + +interface InstanceGenerator { + fun generate(): UtModel? +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt new file mode 100644 index 0000000000..b01d34d35f --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt @@ -0,0 +1,88 @@ +@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.engine.greyboxfuzzer.util.* +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.GenericsContext +import ru.vyarus.java.generics.resolver.context.GenericsInfo +import java.lang.reflect.Type +import kotlin.random.Random + +class InterfaceImplementationsInstanceGenerator( + private val resolvedType: Type, + private val typeContext: GenericsContext, + private val sourceOfRandomness: SourceOfRandomness, + private val generationStatus: GenerationStatus, + private val depth: Int +) : InstanceGenerator { + override fun generate(): UtModel? { + //Try to generate with statics with some probability + val clazz = resolvedType.toClass() ?: return null + if (Random.getTrue(50)) { + StaticsBasedInstanceGenerator( + clazz, + typeContext, + sourceOfRandomness, + generationStatus, + depth + ).generate()?.let { + return it + } + } + val genericsContext = getRandomImplementerGenericContext(clazz, resolvedType) ?: return null + return ClassesInstanceGenerator( + genericsContext.currentClass(), + genericsContext, + null, + GenerationMethod.ANY, + sourceOfRandomness, + generationStatus, + depth + ).generate() + } + + private fun getRandomImplementerGenericContext(clazz: Class<*>, resolvedType: Type): GenericsContext? { + val sootClass = clazz.toSootClass() ?: return null + val implementers = + sootClass.getImplementersOfWithChain() + .filter { it.all { !it.toString().contains("$") } } + .filter { it.last().isConcrete } + val randomImplementersChain = + if (Random.getTrue(75)) { + implementers.shuffled().minByOrNull { it.size }?.drop(1) + } else { + implementers.randomOrNull()?.drop(1) + } ?: return null + //Deal with generics + val generics = mutableListOf>>() + var prevImplementer = sootClass.toJavaClass() + resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> + if (prevImplementer.toClass() != null) { + generics.add(typeVariable to mutableListOf(prevImplementer.toClass()!!.typeParameters[index])) + } + } + for (implementer in randomImplementersChain) { + val javaImplementer = implementer.toJavaClass() + val extendType = javaImplementer.let { it.genericInterfaces + it.genericSuperclass } + .find { it.toClass() == prevImplementer } + val tp = prevImplementer.typeParameters + prevImplementer = javaImplementer + if (tp.isEmpty()) continue + val newTp = extendType?.getActualTypeArguments()?.ifEmpty { return null } ?: return null + tp.mapIndexed { index, typeVariable -> typeVariable to newTp[index] } + .forEach { typeVar -> + val indexOfTypeParam = generics.indexOfFirst { it.second.last() == typeVar.first } + if (indexOfTypeParam != -1) { + generics[indexOfTypeParam].second.add(typeVar.second) + } + } + } + val g = prevImplementer.typeParameters.map { tp -> tp.name to generics.find { it.second.last() == tp }?.first }.toMap() + val gm = LinkedHashMap() + g.forEach { gm[it.key] = it.value!! } + val m = mutableMapOf(prevImplementer to gm) + return GenericsContext(GenericsInfo(prevImplementer, m), prevImplementer) + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt new file mode 100644 index 0000000000..95bfa36bb5 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt @@ -0,0 +1,20 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGenerators +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.random.SourceOfRandomness + +class ObjectGenerator( + private val sourceOfRandomness: SourceOfRandomness, + private val generationStatus: GenerationStatus +): InstanceGenerator { + override fun generate(): UtModel? = + GreyBoxFuzzerGenerators.generatorRepository + .generators + .toList() + .flatMap { it.second } + .filter { !it.hasComponents() } + .randomOrNull() + ?.generate(sourceOfRandomness, generationStatus) +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt new file mode 100644 index 0000000000..6abe8993cb --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt @@ -0,0 +1,15 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.internal.ParameterTypeContext + +class ReflectionClassGenerator( + private val parameterTypeContext: ParameterTypeContext +) : InstanceGenerator { + override fun generate(): UtModel? = + parameterTypeContext.resolved.typeParameters.randomOrNull()?.type?.componentClass?.let { + UtModelGenerator.utModelConstructor.construct(it, Class::class.java.id) + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt new file mode 100644 index 0000000000..6f8d354360 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt @@ -0,0 +1,28 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.GenericsContext +import kotlin.random.Random + +open class StaticsBasedInstanceGenerator( + private val clazz: Class<*>, + private val gctx: GenericsContext, + private val sourceOfRandomness: SourceOfRandomness, + private val generationStatus: GenerationStatus, + private val depth: Int +) : InstanceGenerator { + override fun generate(): UtModel? { + val staticMethodBasedGenerator = + StaticsMethodBasedInstanceGenerator(clazz, gctx, sourceOfRandomness, generationStatus, depth) + val staticFieldBasedGenerator = + StaticsFieldBasedInstanceGenerator(clazz, gctx) + //TODO: repair StaticFieldBasedGenerator + return if (true) { + staticMethodBasedGenerator.generate() ?: staticFieldBasedGenerator.generate() + } else { + staticFieldBasedGenerator.generate() ?: staticMethodBasedGenerator.generate() + } + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt new file mode 100644 index 0000000000..982fe3f71a --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt @@ -0,0 +1,78 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.engine.greyboxfuzzer.util.SootStaticsCollector +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator +import org.utbot.engine.greyboxfuzzer.util.hasModifiers +import org.utbot.engine.greyboxfuzzer.util.toClass +import org.utbot.external.api.classIdForType +import org.utbot.framework.codegen.model.constructor.builtin.setAccessible +import org.utbot.framework.concrete.UtModelConstructor +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.* +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.GenericsContext +import java.lang.reflect.Field +import java.lang.reflect.Method +import java.lang.reflect.Modifier +import java.util.* + +internal class StaticsFieldBasedInstanceGenerator( + private val clazz: Class<*>, + private val gctx: GenericsContext +) : InstanceGenerator { + override fun generate(): UtModel? = + getRandomStaticToProduceInstanceUsingSoot()?.let { fieldToProvideInstance -> + createUtModelForStaticFieldInvocation(UtModelGenerator.utModelConstructor, fieldToProvideInstance) + } + + //In case of no Soot + private fun getStaticFieldToProduceInstance(): Field? { + val resolvedStaticFields = + try { + clazz.declaredFields.filter { it.hasModifiers(Modifier.STATIC) } + .map { it to gctx.resolveFieldType(it) } + .filter { it.first.type.toClass() == clazz } + } catch (e: Error) { + listOf() + } + return resolvedStaticFields.randomOrNull()?.first + } + + private fun getRandomStaticToProduceInstanceUsingSoot(): Field? = + SootStaticsCollector.getStaticFieldsInitializersOf(clazz).randomOrNull() + + private fun createUtModelForStaticFieldInvocation( + utModelConstructor: UtModelConstructor, + field: Field + ): UtAssembleModel { + with(utModelConstructor) { + val classInstanceModel = construct(clazz, classClassId) as UtReferenceModel + + val fieldModelId = computeUnusedIdAndUpdate() + val fieldModel = UtAssembleModel( + fieldModelId, + Field::class.java.id, + "field_$fieldModelId", + UtExecutableCallModel( + classInstanceModel, + Class<*>::getField.executableId, + listOf(construct(field.name, stringClassId)), + ) + ) + + val generatedModelId = computeUnusedIdAndUpdate() + return UtAssembleModel( + id = generatedModelId, + classId = classIdForType(field.type), + modelName = "value_$generatedModelId", + UtExecutableCallModel( + fieldModel, + Field::get.executableId, + listOf(UtNullModel(clazz.id)), + ) + ) + } + } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt new file mode 100644 index 0000000000..826e52b7ed --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt @@ -0,0 +1,56 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.engine.greyboxfuzzer.util.SootStaticsCollector +import org.utbot.engine.greyboxfuzzer.util.hasModifiers +import org.utbot.engine.greyboxfuzzer.util.toClass +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.* +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.GenericsContext +import java.lang.reflect.Method +import java.lang.reflect.Modifier + +//TODO filter not suitable methods with generics with bad bounds +//TODO make it work for subtypes +internal class StaticsMethodBasedInstanceGenerator( + private val clazz: Class<*>, + private val gctx: GenericsContext, + private val sourceOfRandomness: SourceOfRandomness, + private val generationStatus: GenerationStatus, + private val depth: Int +) : InstanceGenerator { + override fun generate(): UtModel? = + getRandomStaticToProduceInstanceUsingSoot()?.let { methodToProvideInstance -> + val resolvedMethodContext = + try { + gctx.method(methodToProvideInstance) + } catch (_: Throwable) { + null + } + ExecutableInvoker( + methodToProvideInstance, + clazz, + methodToProvideInstance.executableId, + resolvedMethodContext, + sourceOfRandomness, + generationStatus, + depth + ).invoke() + } + + //In case of no Soot + private fun getRandomStaticToProduceInstance(): Method? = + try { + clazz.declaredMethods.filter { it.hasModifiers(Modifier.STATIC) } + .map { it to gctx.method(it).resolveReturnType() } + .filter { it.first.returnType.toClass() == clazz } + .filter { it.first.parameterTypes.all { !it.name.contains(clazz.name) } } + .randomOrNull()?.first + } catch (e: Error) { + null + } + + private fun getRandomStaticToProduceInstanceUsingSoot(): Method? = + SootStaticsCollector.getStaticMethodsInitializersOf(clazz).randomOrNull() +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt new file mode 100644 index 0000000000..6cd36eee39 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt @@ -0,0 +1,164 @@ +package org.utbot.engine.greyboxfuzzer.mutator + +import org.javaruntype.type.Types +import org.utbot.engine.greyboxfuzzer.generator.DataGenerator +import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGenerators +import org.utbot.engine.greyboxfuzzer.generator.FParameter +import org.utbot.engine.greyboxfuzzer.generator.getOrProduceGenerator +import org.utbot.engine.greyboxfuzzer.util.* +import org.utbot.engine.logger +import org.utbot.external.api.classIdForType +import org.utbot.framework.concrete.UtModelConstructor +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.fieldId +import org.utbot.framework.plugin.api.util.method +import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.quickcheck.internal.generator.GeneratorRepository +import java.lang.reflect.Field +import java.lang.reflect.Modifier +import kotlin.random.Random +import java.util.* + +object Mutator { + + /** + * Mean number of mutations to perform in each round. + */ + private val MEAN_MUTATION_COUNT = 8.0 + + /** + * Mean number of contiguous bytes to mutate in each mutation. + */ + private val MEAN_MUTATION_SIZE = 4.0 // Bytes + + private fun regenerateRandomParameter(fParameter: FParameter): FParameter? { + return fParameter + } + + fun regenerateFields(clazz: Class<*>, classInstance: UtAssembleModel, fieldsToRegenerate: List): UtModel { + val parameterTypeContext = ParameterTypeContext.forClass(clazz) + var resUtModel = classInstance + for (field in fieldsToRegenerate) { + resUtModel = setNewFieldValue(field, parameterTypeContext, resUtModel) + } + return resUtModel + } + + private fun setNewFieldValue( + field: Field, + parameterTypeContext: ParameterTypeContext, + clazzInstance: UtAssembleModel + ): UtAssembleModel { + field.isAccessible = true + val oldFieldValue = field.getFieldValue(clazzInstance) + if (field.hasAtLeastOneOfModifiers( + Modifier.STATIC, + Modifier.FINAL + ) && oldFieldValue != null + ) return clazzInstance + val fieldType = parameterTypeContext.generics.resolveFieldType(field) + logger.debug { "F = $field TYPE = $fieldType OLDVALUE = $oldFieldValue" } + val parameterTypeContextForResolvedType = ParameterTypeContext( + field.name, + field.annotatedType, + field.declaringClass.name, + Types.forJavaLangReflectType(fieldType), + parameterTypeContext.generics + ) + val newFieldValue = DataGenerator.generate( + parameterTypeContextForResolvedType, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus + ) + logger.debug { "NEW FIELD VALUE = $newFieldValue" } + if (newFieldValue != null) { + return clazzInstance.addModification(UtDirectSetFieldModel(clazzInstance, field.fieldId, newFieldValue)) + } + return clazzInstance + } + + + fun mutateParameter( + fParameter: FParameter + ): FParameter { + val originalParameter = fParameter.parameter + val originalUtModel = fParameter.utModel +// if (Random.getTrue(100)) { +// return regenerateRandomParameter(fParameter) +// } +// val randomMethod = initialInstance.classId.allMethods +// .filter { !it.name.startsWith("get") && !it.name.startsWith("to")} +// .filter { it.classId.name != "java.lang.Object" } +// .filter { it.parameters.all { !it.name.startsWith("java.util.function") } } +// .toList() +// .randomOrNull() ?: return null + val randomMethod = fParameter.classId.allMethods.toList().randomOrNull() ?: return fParameter + val parametersForMethodInvocation = + randomMethod.method.parameters.mapIndexed { index, parameter -> + val resolvedParameterCtx = + originalParameter.resolveParameterTypeAndBuildParameterContext(index, randomMethod.method) + val generatorForParameter = + GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(resolvedParameterCtx, 0) + ?: return fParameter + DataGenerator.generate( + generatorForParameter, + parameter, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus + ).utModel + } + val callModel = UtExecutableCallModel(fParameter.utModel as UtReferenceModel, randomMethod, parametersForMethodInvocation) + (originalUtModel as UtAssembleModel).addModification(callModel) + return FParameter(originalParameter, null, fParameter.utModel, fParameter.generator, fParameter.fields) + } + + +// private fun mutateInput(oldData: Any, sourceOfRandomness: SourceOfRandomness): Any { +// val castedData = oldData as LongArray +// print("BEFORE = ") +// castedData.forEach { print("$it ") } +// println() +// // Clone this input to create initial version of new child +// //val newInput = LinearInput(this) +// val bos = ByteArrayOutputStream(); +// val oos = ObjectOutputStream(bos); +// oos.writeObject(oldData); +// oos.flush(); +// val data = bos.toByteArray() +// val random = java.util.Random()//sourceOfRandomness.toJDKRandom() +// +// // Stack a bunch of mutations +// val numMutations = 3//ZestGuidance.Input.sampleGeometric(random, MEAN_MUTATION_COUNT) +// println("mutations = $numMutations") +// //newInput.desc += ",havoc:$numMutations" +// val setToZero = random.nextDouble() < 0.1 // one out of 10 times +// for (mutation in 1..numMutations) { +// +// // Select a random offset and size +// val offset = random.nextInt(data.size) +// val mutationSize = ZestGuidance.Input.sampleGeometric(random, MEAN_MUTATION_SIZE) +// +// // desc += String.format(":%d@%d", mutationSize, idx); +// +// // Mutate a contiguous set of bytes from offset +// for (i in offset until offset + mutationSize) { +// // Don't go past end of list +// if (i >= data.size) { +// break +// } +// +// // Otherwise, apply a random mutation +// val mutatedValue = if (setToZero) 0 else random.nextInt(256) +// data[i] = mutatedValue.toByte() +// } +// } +// val `in` = ByteArrayInputStream(data) +// val `is` = ObjectInputStream(`in`) +// val afterMutationData = `is`.readObject() as LongArray +// print("AFTER = ") +// afterMutationData.forEach { print("$it ") } +// println() +// return data +// } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/ObjectMerger.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/ObjectMerger.kt new file mode 100644 index 0000000000..22a0e91661 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/ObjectMerger.kt @@ -0,0 +1,14 @@ +package org.utbot.engine.greyboxfuzzer.mutator + +import org.utbot.engine.greyboxfuzzer.generator.FParameter + +class ObjectMerger { + + fun mergeObjects(obj1: FParameter, obj2: FParameter) { + val obj1SubFields = obj1.getAllSubFields() + val obj2SubFields = obj2.getAllSubFields() + val randomSubField = obj1SubFields.randomOrNull() ?: return + + return + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt new file mode 100644 index 0000000000..ea6ddcf8e8 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt @@ -0,0 +1,10 @@ +package org.utbot.engine.greyboxfuzzer.mutator + +import org.utbot.engine.greyboxfuzzer.generator.FParameter +import org.utbot.framework.plugin.api.ClassId + +data class Seed( + val thisInstance: Any?, + val arguments: List, + val priority: Double = 0.0 +) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt new file mode 100644 index 0000000000..a90d05c909 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt @@ -0,0 +1,55 @@ +package org.utbot.engine.greyboxfuzzer.mutator + +import org.utbot.engine.greyboxfuzzer.util.getTrue +import java.util.PriorityQueue +import java.util.TreeSet +import kotlin.math.abs +import kotlin.math.exp +import kotlin.math.pow +import kotlin.random.Random + +class SeedCollector(private val maxSize: Int = 50) { + private val seeds = sortedSetOf( + comparator = + compareByDescending { seed: Seed -> seed.priority }.thenComparator { seed1, seed2 -> if (seed1 === seed2) 0 else 1 } + ) + + fun addSeed(seed: Seed) { + seeds.add(seed) + while (seeds.size >= maxSize) { + seeds.remove(seeds.last()) + } + } + +// fun getRandomWeightedSeed(): Seed { +// val priorityWeightedFunction = { a: Double -> exp(a).pow(2) } +// val minPriority = seeds.last().priority +// val maxPriority = seeds.first().priority +// val priorityDiffs = if (maxPriority == minPriority) 1.0 else maxPriority - minPriority +// val normalizedSeeds = seeds.map { it to (it.priority - minPriority) / priorityDiffs } +// val sumOfSeedPriorities = normalizedSeeds.sumOf { priorityWeightedFunction.invoke(it.second) } +// val randomSeedPriority = Random.nextDouble(0.0, sumOfSeedPriorities) +// var priorityCounter = 0.0 +// normalizedSeeds.forEach { (seed, priority) -> +// priorityCounter += priorityWeightedFunction.invoke(priority) +// if (priorityCounter >= randomSeedPriority) { +// return seed +// } +// } +// return seeds.first() +// } + + fun getRandomWeightedSeed() = + if (Random.getTrue(75)) { + val bestSeed = getBestSeed().priority + seeds.filter { abs(it.priority - bestSeed) < 1e-5 }.randomOrNull() + } else { + seeds.randomOrNull() + } + + fun getBestSeed() = seeds.first() + fun removeSeed(seed: Seed) = seeds.remove(seed) + fun seedsSize() = seeds.size + + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt new file mode 100644 index 0000000000..719ef087ef --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt @@ -0,0 +1,9 @@ +package org.utbot.engine.greyboxfuzzer.util + +import org.utbot.framework.plugin.api.Instruction +import java.util.concurrent.CopyOnWriteArraySet + +object CoverageCollector { + + val coverage = CopyOnWriteArraySet() +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt new file mode 100644 index 0000000000..19d40f1ff6 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt @@ -0,0 +1,7 @@ +package org.utbot.engine.greyboxfuzzer.util + +import java.net.URLClassLoader + +object CustomClassLoader { + lateinit var classLoader: URLClassLoader +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GenericsReplacer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GenericsReplacer.kt new file mode 100644 index 0000000000..af052847d6 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GenericsReplacer.kt @@ -0,0 +1,55 @@ +//package org.utbot.engine.greyboxfuzzer.util +// +//import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl +//import java.lang.reflect.Parameter +//import java.lang.reflect.Type +//import java.lang.reflect.TypeVariable +//import java.lang.reflect.WildcardType +// +//class GenericsReplacer { +// +// private val replacedGenerics = mutableListOf>() +// +// fun replaceUnresolvedGenericsToRandomTypes(parameter: Parameter) { +// if (replacedGenerics.isNotEmpty()) { +// makeReplacement(replacedGenerics) +// return +// } +// val allUnresolvedTypesInType = (parameter.parameterizedType as? ParameterizedTypeImpl) +// ?.actualTypeArgumentsRecursive +// ?.filter { it is WildcardType || it is TypeVariable<*> } +// ?: return +// val allUnresolvedTypesInAnnotatedType = (parameter.annotatedType.type as? ParameterizedTypeImpl) +// ?.actualTypeArgumentsRecursive +// ?.filter { it is WildcardType || it is TypeVariable<*> } +// ?: return +// val allUnresolvedTypes = allUnresolvedTypesInType.zip(allUnresolvedTypesInAnnotatedType) +// replacedGenerics.addAll(allUnresolvedTypes) +// makeReplacement(allUnresolvedTypes) +// } +// +// private fun makeReplacement(allUnresolvedTypes: List>) { +// for ((unresolvedType, unresolvedTypeCopy) in allUnresolvedTypes) { +// val upperBound = +// if (unresolvedType is WildcardType) { +// unresolvedType.upperBounds.firstOrNull() ?: continue +// } else if (unresolvedType is TypeVariable<*>) { +// unresolvedType.bounds?.firstOrNull() ?: continue +// } else continue +// val upperBoundAsSootClass = upperBound.toClass()?.toSootClass() ?: continue +// val randomChild = +// upperBoundAsSootClass.children.filterNot { it.name.contains("$") }.randomOrNull()?.toJavaClass() ?: continue +// val upperBoundsFields = +// if (unresolvedType is WildcardType) { +// unresolvedType.javaClass.getAllDeclaredFields().find { it.name.contains("upperBounds") }!! to +// unresolvedTypeCopy.javaClass.getAllDeclaredFields().find { it.name.contains("upperBounds") }!! +// } else if (unresolvedType is TypeVariable<*>) { +// unresolvedType.javaClass.getAllDeclaredFields().find { it.name.contains("bounds") }!! to +// unresolvedTypeCopy.javaClass.getAllDeclaredFields().find { it.name.contains("bounds") }!! +// } else continue +// upperBoundsFields.first.setFieldValue(unresolvedType, arrayOf(randomChild)) +// upperBoundsFields.second.setFieldValue(unresolvedType, arrayOf(randomChild)) +// } +// } +// +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt new file mode 100644 index 0000000000..f5c85559ca --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt @@ -0,0 +1,54 @@ +package org.utbot.engine.greyboxfuzzer.util + +import org.utbot.engine.logger +import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.api.util.jClass +import org.utbot.framework.plugin.api.util.signature +import soot.Scene +import kotlin.reflect.jvm.jvmName +import kotlin.reflect.jvm.kotlinFunction + +object GreyBoxFuzzingStatisticPrinter { + + fun printFuzzingStats(methods: List) { +// //Printing to console + val clazz = methods.first().classId + val sootClazz = Scene.v().classes.find { it.name == clazz.name }!! + val methodsToLineNumbers = sootClazz.methods.mapNotNull { sootMethod -> + val javaMethod = sootMethod.toJavaMethod() + if (javaMethod?.kotlinFunction != null) { + javaMethod to sootMethod.activeBody.units + .map { it.javaSourceStartLineNumber } + .filter { it != -1 } + .toSet() + } else { + null + } + } + logger.debug { "OVERALL RESULTS:" } + logger.debug { "------------------------------------------" } + for ((method, lines) in methodsToLineNumbers) { + val coveredMethodInstructions = CoverageCollector.coverage + .filter { it.methodSignature == method.signature } + .map { it.lineNumber } + .toSet() + .filter { it in lines } + + logger.debug { "METHOD: ${method.name}" } + logger.debug { "COVERED: ${coveredMethodInstructions.size} from ${lines.size} ${coveredMethodInstructions.size.toDouble() / lines.size * 100}%" } + logger.debug { "COVERED: ${coveredMethodInstructions.sorted()}" } + logger.debug { "NOT COVERED: ${lines.filter { it !in coveredMethodInstructions }.sorted()}" } + logger.debug { "------------------" } + } + logger.debug { "------------------------------------------" } + val allLinesToCover = methodsToLineNumbers.flatMap { it.second }.toSet() + val allLinesToCoverSize = allLinesToCover.size + val allCoveredLines = CoverageCollector.coverage + .filter { it.className.replace('/', '.') == clazz.name } + .map { it.lineNumber }.toSet() + .filter { it in allLinesToCover } + .size + logger.debug { "FINALLY COVERED $allCoveredLines from $allLinesToCoverSize ${allCoveredLines.toDouble() / allLinesToCoverSize * 100}%" } + logger.debug { "------------------------------------------" } + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt new file mode 100644 index 0000000000..92a96f6b8c --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt @@ -0,0 +1,43 @@ +package org.utbot.engine.greyboxfuzzer.util + +import org.utbot.engine.greyboxfuzzer.util.kcheck.nextInRange +import java.util.* + +fun kotlin.random.Random.getTrue(prob: Int) = Random().nextInRange(0, 100) < prob + +fun List.sublistBeforeLast(element: T): List = + this.indexOfLast { it == element }.let { lastIndex -> + if (lastIndex == -1) this + else this.subList(0, lastIndex) + } + +fun MutableList.removeIfAndReturnRemovedElements(cond: (T) -> Boolean): List { + val res = mutableListOf() + val iterator = this.iterator() + while (iterator.hasNext()) { + val element = iterator.next() + if (cond.invoke(element)) { + res.add(element) + iterator.remove() + } + } + return res +} + +fun String.removeBetweenAll(startChar: Char, endChar: Char): String { + val resultingString = StringBuilder() + var flToRemove = false + for (ch in this) { + if (ch == startChar) { + flToRemove = true + continue + } else if (ch == endChar) { + flToRemove = false + continue + } + if (!flToRemove) { + resultingString.append(ch) + } + } + return resultingString.toString() +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt new file mode 100644 index 0000000000..6912e3e3e9 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt @@ -0,0 +1,381 @@ +@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") + +package org.utbot.engine.greyboxfuzzer.util + +import org.utbot.quickcheck.internal.ParameterTypeContext +import org.javaruntype.type.Types +import org.utbot.common.withAccessibility +import org.utbot.engine.rawType +import ru.vyarus.java.generics.resolver.context.GenericsContext +import ru.vyarus.java.generics.resolver.context.GenericsInfo +import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl +import java.lang.reflect.* +import java.lang.reflect.Array as RArray +import kotlin.random.Random + +fun Class<*>.getAllDeclaredFields(): List { + val res = mutableListOf() + var current: Class<*>? = this + while (current != null) { + try { + res.addAll(current.declaredFields) + } catch (_: Error) { + + } + current = current.superclass + } + return res +} + +fun Class<*>.getAllDeclaredMethods(): List { + val res = mutableListOf() + var current: Class<*>? = this + while (current != null) { + res.addAll(current.declaredMethods) + current = current.superclass + } + return res +} + +fun Field.getFieldValue(instance: Any?): Any? { + try { + val fixedInstance = + if (this.isStatic()) { + null + } else instance + return withAccessibility { + when (this.type) { + Boolean::class.javaPrimitiveType -> this.getBoolean(fixedInstance) + Byte::class.javaPrimitiveType -> this.getByte(fixedInstance) + Char::class.javaPrimitiveType -> this.getChar(fixedInstance) + Short::class.javaPrimitiveType -> this.getShort(fixedInstance) + Int::class.javaPrimitiveType -> this.getInt(fixedInstance) + Long::class.javaPrimitiveType -> this.getLong(fixedInstance) + Float::class.javaPrimitiveType -> this.getFloat(fixedInstance) + Double::class.javaPrimitiveType -> this.getDouble(fixedInstance) + else -> this.get(fixedInstance) + } + } + } catch (_: Throwable) { + return null + } +} + +fun Field.setFieldValue(instance: Any?, fieldValue: Any?) { + withAccessibility { + val fixedInstance = + if (this.isStatic()) { + null + } else instance + when (this.type) { + Boolean::class.javaPrimitiveType -> this.setBoolean(fixedInstance, fieldValue as Boolean) + Byte::class.javaPrimitiveType -> this.setByte(fixedInstance, fieldValue as Byte) + Char::class.javaPrimitiveType -> this.setChar(fixedInstance, fieldValue as Char) + Short::class.javaPrimitiveType -> this.setShort(fixedInstance, fieldValue as Short) + Int::class.javaPrimitiveType -> this.setInt(fixedInstance, fieldValue as Int) + Long::class.javaPrimitiveType -> this.setLong(fixedInstance, fieldValue as Long) + Float::class.javaPrimitiveType -> this.setFloat(fixedInstance, fieldValue as Float) + Double::class.javaPrimitiveType -> this.setDouble(fixedInstance, fieldValue as Double) + else -> this.set(fixedInstance, fieldValue) + } + } +} + +fun Type.toClass(): Class<*>? = + try { + when (this) { + is ParameterizedTypeImpl -> this.rawType + is ru.vyarus.java.generics.resolver.context.container.ParameterizedTypeImpl -> this.rawType.toClass() + is GenericArrayTypeImpl -> java.lang.reflect.Array.newInstance( + this.genericComponentType.toClass(), + 0 + ).javaClass + is ru.vyarus.java.generics.resolver.context.container.GenericArrayTypeImpl -> java.lang.reflect.Array.newInstance( + this.genericComponentType.toClass(), + 0 + ).javaClass + is ru.vyarus.java.generics.resolver.context.container.ExplicitTypeVariable -> this.rawType.toClass() + else -> this as? Class<*> + } + } catch (e: Exception) { + null + } + +fun Field.generateInstance(instance: Any, generatedValue: Any?) { + if (this.isStatic() && this.isFinal) return + this.isAccessible = true + this.isFinal = false + if (this.isEnumConstant || this.isSynthetic) return + if (this.type.isPrimitive) { + val definedValue = generatedValue + when (definedValue?.javaClass) { + null -> this.set(instance, null) + Boolean::class.javaObjectType -> this.setBoolean(instance, definedValue as Boolean) + Byte::class.javaObjectType -> this.setByte(instance, definedValue as Byte) + Char::class.javaObjectType -> this.setChar(instance, definedValue as Char) + Short::class.javaObjectType -> this.setShort(instance, definedValue as Short) + Int::class.javaObjectType -> this.setInt(instance, definedValue as Int) + Long::class.javaObjectType -> this.setLong(instance, definedValue as Long) + Float::class.javaObjectType -> this.setFloat(instance, definedValue as Float) + Double::class.javaObjectType -> this.setDouble(instance, definedValue as Double) + else -> return + } + } else { + this.set(instance, generatedValue) + } +} + +private fun Class<*>.processArray(value: Any): List { +// return (0 until JArray.getLength(value)).map { JArray.get(value, it) } +// val subFields = mutableListOf() +// for (i in 0 until JArray.getLength(value)) { +// val field = JArray.get(value, i) +// } + return emptyList() +} + +//private fun Field + +var Field.isFinal: Boolean + get() = (this.modifiers and Modifier.FINAL) == Modifier.FINAL + set(value) { + if (value == this.isFinal) return + val modifiersField = this.javaClass.getDeclaredField("modifiers") + modifiersField.isAccessible = true + modifiersField.setInt(this, this.modifiers and if (value) Modifier.FINAL else Modifier.FINAL.inv()) + } + +fun Method.isStatic() = modifiers.and(Modifier.STATIC) > 0 +fun Field.isStatic() = modifiers.and(Modifier.STATIC) > 0 +fun Method.hasModifiers(vararg modifiers: Int) = modifiers.all { it.and(this.modifiers) > 0 } +fun Field.hasModifiers(vararg modifiers: Int) = modifiers.all { it.and(this.modifiers) > 0 } +fun Class<*>.hasModifiers(vararg modifiers: Int) = modifiers.all { it.and(this.modifiers) > 0 } +fun Constructor<*>.hasModifiers(vararg modifiers: Int) = modifiers.all { it.and(this.modifiers) > 0 } +fun Constructor<*>.hasAtLeastOneOfModifiers(vararg modifiers: Int) = modifiers.any { it.and(this.modifiers) > 0 } +fun Class<*>.hasAtLeastOneOfModifiers(vararg modifiers: Int) = modifiers.any { it.and(this.modifiers) > 0 } +fun Class<*>.canBeInstantiated() = !hasAtLeastOneOfModifiers(Modifier.ABSTRACT, Modifier.INTERFACE) +fun Field.hasAtLeastOneOfModifiers(vararg modifiers: Int) = modifiers.any { it.and(this.modifiers) > 0 } + +fun ru.vyarus.java.generics.resolver.context.container.ParameterizedTypeImpl.getActualArguments(): Array { + val args = this.javaClass.getAllDeclaredFields().find { it.name == "actualArguments" } ?: return arrayOf() + return args.let { + it.isAccessible = true + it.get(this) as Array + }.also { args.isAccessible = false } +} + +fun List>.chooseRandomConstructor() = + if (Random.getTrue(75)) { + this.shuffled().minByOrNull { it.parameterCount } + } else this.randomOrNull() + +fun List.chooseRandomMethodToGenerateInstance() = + if (Random.getTrue(75)) { + this.shuffled().minByOrNull { it.parameterCount } + } else this.randomOrNull() + +fun generateParameterizedTypeImpl( + clazz: Class<*>, + actualTypeParameters: Array +): ParameterizedTypeImpl { + val constructor = ParameterizedTypeImpl::class.java.declaredConstructors.first() + constructor.isAccessible = true + return constructor.newInstance(clazz, actualTypeParameters, null) as ParameterizedTypeImpl +} + +object ReflectionUtils { + fun getRandomClassWithBounds(bound: Class<*>): Class<*> { + return Any::class.java + } + + fun forJavaReflectTypeSafe(type: Type): org.javaruntype.type.Type<*> { + val strType = type.toString() + val safeType = + if (type is WildcardType) { + if ((strType.contains(" super ") && strType.contains("extends")) || strType.contains("extends")) { + type.upperBounds.firstOrNull() ?: Any::class.java.rawType + } else if (strType.contains(" super ")) { + type.lowerBounds.firstOrNull() ?: Any::class.java.rawType + } else { + Any::class.java.rawType + } + } else type + return Types.forJavaLangReflectType(safeType) + } + +} + +val ParameterizedTypeImpl.actualTypeArgumentsRecursive: List + get() { + val queue = ArrayDeque() + val res = mutableListOf() + if (this is TypeVariable<*>) { + queue.add(this) + } + this.actualTypeArguments.map { queue.add(it) } + while (queue.isNotEmpty()) { + val el = queue.removeFirst() + if (el is ParameterizedTypeImpl) { + el.actualTypeArguments.map { queue.add(it) } + } + res.add(el) + } + return res + } + + +//fun Parameter.replaceUnresolvedGenericsToRandomTypes() { +// val allUnresolvedTypesInType = (this.parameterizedType as? ParameterizedTypeImpl) +// ?.actualTypeArgumentsRecursive +// ?.filter { it is WildcardType || it is TypeVariable<*> } +// ?: return +// val allUnresolvedTypesInAnnotatedType = (this.annotatedType.type as? ParameterizedTypeImpl) +// ?.actualTypeArgumentsRecursive +// ?.filter { it is WildcardType || it is TypeVariable<*> } +// ?: return +// val allUnresolvedTypes = allUnresolvedTypesInType.zip(allUnresolvedTypesInAnnotatedType) +// for ((unresolvedType, unresolvedTypeCopy) in allUnresolvedTypes) { +// val upperBound = +// if (unresolvedType is WildcardType) { +// unresolvedType.upperBounds.firstOrNull() ?: continue +// } else if (unresolvedType is TypeVariable<*>) { +// unresolvedType.bounds?.firstOrNull() ?: continue +// } else continue +// val upperBoundAsSootClass = upperBound.toClass()?.toSootClass() ?: continue +// val randomChild = +// upperBoundAsSootClass.children.filterNot { it.name.contains("$") }.randomOrNull()?.toJavaClass() ?: continue +// val upperBoundsFields = +// if (unresolvedType is WildcardType) { +// unresolvedType.javaClass.getAllDeclaredFields().find { it.name.contains("upperBounds") }!! to +// unresolvedTypeCopy.javaClass.getAllDeclaredFields().find { it.name.contains("upperBounds") }!! +// } else if (unresolvedType is TypeVariable<*>) { +// unresolvedType.javaClass.getAllDeclaredFields().find { it.name.contains("bounds") }!! to +// unresolvedTypeCopy.javaClass.getAllDeclaredFields().find { it.name.contains("bounds") }!! +// } else continue +// upperBoundsFields.first.setFieldValue(unresolvedType, arrayOf(randomChild)) +// upperBoundsFields.second.setFieldValue(unresolvedType, arrayOf(randomChild)) +// } +//} + +fun Method.resolveMethod( + parameterTypeContext: ParameterTypeContext, + typeArguments: List +): Pair, GenericsContext> { + val cl = this.declaringClass//parameterTypeContext.resolved.rawClass + val resolvedJavaType = + parameterTypeContext.generics.resolveType(parameterTypeContext.type()) as? ParameterizedType + val gm = LinkedHashMap() + if (resolvedJavaType != null) { + typeArguments.zip(resolvedJavaType.actualTypeArguments.toList()).forEach { + gm[it.first.typeName] = it.second + } + } + val m = mutableMapOf(cl to gm) + val generics = LinkedHashMap() + typeArguments.forEachIndexed { index, typeVariable -> + generics[typeVariable.typeName] = + (resolvedJavaType as ru.vyarus.java.generics.resolver.context.container.ParameterizedTypeImpl).actualTypeArguments[index] + } + val gctx = GenericsContext(GenericsInfo(cl, m), cl) + gctx.method(this).methodGenericsMap().forEach { (s, type) -> generics.getOrPut(s) { type } } + return generics to gctx +} + +fun org.javaruntype.type.Type<*>.convertToPrimitiveIfPossible(): org.javaruntype.type.Type<*> { + val possiblePrimitive = when (this.toString()) { + java.lang.Short::class.java.name -> Short::class.java + java.lang.Byte::class.java.name -> Byte::class.java + java.lang.Integer::class.java.name -> Int::class.java + java.lang.Long::class.java.name -> Long::class.java + java.lang.Float::class.java.name -> Float::class.java + java.lang.Double::class.java.name -> Double::class.java + java.lang.Character::class.java.name -> Char::class.java + java.lang.Boolean::class.java.name -> Boolean::class.java + else -> null + } + return possiblePrimitive?.let { ReflectionUtils.forJavaReflectTypeSafe(it) } ?: this +} + +fun Type.getActualTypeArguments(): Array = + when (this) { + is ParameterizedTypeImpl -> this.actualTypeArguments + is ru.vyarus.java.generics.resolver.context.container.ParameterizedTypeImpl -> this.actualTypeArguments + else -> arrayOf() + } + +class GenericsReplacer { + private val replacedGenerics = mutableListOf() + + private data class ReplacedTypeParameter( + val type: Type, + val typeBound: Type?, + val annotatedType: Type, + val annotatedTypeBound: Type? + ) + + fun replaceUnresolvedGenericsToRandomTypes(parameter: Parameter) { + if (replacedGenerics.isNotEmpty()) { + makeReplacement(replacedGenerics) + return + } + val allUnresolvedTypesInType = (parameter.parameterizedType as? ParameterizedTypeImpl) + ?.actualTypeArgumentsRecursive + ?.filter { it is WildcardType || it is TypeVariable<*> } + ?: return + val allUnresolvedTypesInAnnotatedType = (parameter.annotatedType.type as? ParameterizedTypeImpl) + ?.actualTypeArgumentsRecursive + ?.filter { it is WildcardType || it is TypeVariable<*> } + ?: return + val allUnresolvedTypes = allUnresolvedTypesInType.zip(allUnresolvedTypesInAnnotatedType) + replacedGenerics.addAll( + allUnresolvedTypes.map { + ReplacedTypeParameter(it.first, getUpperBound(it.first), it.second, getUpperBound(it.second)) + } + ) + makeReplacement(replacedGenerics) + } + + fun revert() { + if (replacedGenerics.isEmpty()) return + for ((type, upperBound, annotatedType, _) in replacedGenerics) { + setUpperBoundTo(type, annotatedType, upperBound?.toClass() ?: Any::class.java) + } + } + + private fun makeReplacement(allUnresolvedTypes: List) { + for ((type, upperBound, annotatedType, _) in allUnresolvedTypes) { + val upperBoundAsSootClass = upperBound?.toClass()?.toSootClass() ?: continue + val newRandomBound = + upperBoundAsSootClass.children.filterNot { it.name.contains("$") }.randomOrNull()?.toJavaClass() + ?: continue + setUpperBoundTo(type, annotatedType, newRandomBound) + } + } + + private fun setUpperBoundTo(type: Type, annotatedType: Type, clazz: Class<*>) { + val upperBoundsFields = + when (type) { + is WildcardType -> { + type.javaClass.getAllDeclaredFields().find { it.name.contains("upperBounds") }!! to + annotatedType.javaClass.getAllDeclaredFields() + .find { it.name.contains("upperBounds") }!! + } + is TypeVariable<*> -> { + type.javaClass.getAllDeclaredFields().find { it.name.contains("bounds") }!! to + annotatedType.javaClass.getAllDeclaredFields().find { it.name.contains("bounds") }!! + } + else -> return + } + upperBoundsFields.first.setFieldValue(type, arrayOf(clazz)) + upperBoundsFields.second.setFieldValue(type, arrayOf(clazz)) + } + + private fun getUpperBound(unresolvedType: Type): Type? = + when (unresolvedType) { + is WildcardType -> unresolvedType.upperBounds.firstOrNull() + is TypeVariable<*> -> unresolvedType.bounds?.firstOrNull() + else -> null + } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt new file mode 100644 index 0000000000..29e5c76d3e --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt @@ -0,0 +1,148 @@ +package org.utbot.engine.greyboxfuzzer.util + +import org.utbot.framework.plugin.api.util.signature +import soot.Hierarchy +import soot.Scene +import soot.SootClass +import soot.SootField +import soot.SootMethod +import soot.jimple.internal.JAssignStmt +import soot.jimple.internal.JInstanceFieldRef +import java.lang.reflect.Field +import java.lang.reflect.Method +import kotlin.reflect.KFunction +import kotlin.reflect.jvm.javaMethod + +fun SootClass.getImplementersOfWithChain(): List> { + this.checkLevel(SootClass.HIERARCHY) + if (!this.isInterface && !this.isAbstract) { + throw RuntimeException("interfaced needed; got $this") + } + val hierarchy = Hierarchy() + val res = mutableListOf(mutableListOf(this)) + val queue = ArrayDeque() + queue.add(this) + while (queue.isNotEmpty()) { + val curSootClass = queue.removeFirst() + val implementers = + if (curSootClass.isInterface) { + hierarchy.getDirectImplementersOf(curSootClass) + .filter { it.interfaces.contains(curSootClass) } + hierarchy.getDirectSubinterfacesOf(curSootClass) + } else { + hierarchy.getDirectSubclassesOf(curSootClass) + } + if (implementers.isEmpty()) continue + val oldLists = res.removeIfAndReturnRemovedElements { it.last() == curSootClass } + if (curSootClass.isConcrete) { + oldLists.forEach { res.add(it.toMutableList()) } + } + for (implementer in implementers) { + queue.add(implementer) + oldLists.forEach { res.add((it + listOf(implementer)).toMutableList()) } + } + } + return res +} + +fun SootMethod.getClassFieldsUsedByFunc(clazz: Class<*>) = + activeBody.units + .asSequence() + .mapNotNull { it as? JAssignStmt } + .map { it.rightOp } + .mapNotNull { it as? JInstanceFieldRef } + .mapNotNull { fieldRef -> clazz.getAllDeclaredFields().find { it.name == fieldRef.field.name } } + .toSet() + +fun SootClass.toJavaClass(): Class<*> = + try { + Class.forName(this.name) + } catch (e: ClassNotFoundException) { + CustomClassLoader.classLoader.loadClass(this.name) + } + +fun KFunction<*>.toSootMethod(): SootMethod? = this.javaMethod?.toSootMethod() + +fun Class<*>.toSootClass() = + Scene.v().classes.find { it.name == this.name } +fun Method.toSootMethod(): SootMethod? { + val cl = declaringClass.toSootClass() ?: return null + return cl.methods.find { + val sig = it.bytecodeSignature.drop(1).dropLast(1).substringAfter("${cl.name}: ") + this.signature == sig + } +} + +fun SootMethod.toJavaMethod(): Method? = + declaringClass.toJavaClass().getAllDeclaredMethods().find { + it.signature == this.bytecodeSignature.drop(1).dropLast(1).substringAfter("${declaringClass.name}: ") + } + +fun SootField.toJavaField(): Field? = + declaringClass.toJavaClass().getAllDeclaredFields().find { it.name == name } + +fun Field.toSootField(): SootField? = + declaringClass.toSootClass()?.fields?.find { it.name == name } + +fun SootClass.getAllAncestors(): List { + val queue = ArrayDeque() + val res = mutableSetOf() + this.superclassOrNull?.let { queue.add(it) } + queue.addAll(this.interfaces) + while (queue.isNotEmpty()) { + val el = queue.removeFirst() + el.superclassOrNull?.let { + if (!res.contains(it) && !queue.contains(it)) queue.add(it) + } + el.interfaces.map { if (!res.contains(it) && !queue.contains(it)) queue.add(it) } + res.add(el) + } + return res.toList() +} + +val SootClass.children + get() = + Scene.v().classes.filter { it.getAllAncestors().contains(this) } + +val SootClass.superclassOrNull + get() = + try { + superclass + } catch (e: Exception) { + null + } + +//TODO add stuff with generics +object SootStaticsCollector { + + private val classToStaticMethodsInstanceProviders = mutableMapOf, List>() + private val classToStaticFieldsInstanceProviders = mutableMapOf, List>() + fun getStaticMethodsInitializersOf(clazz: Class<*>): List { + if (classToStaticMethodsInstanceProviders.contains(clazz)) return classToStaticMethodsInstanceProviders[clazz]!! + val classes = Scene.v().classes.filter { !it.name.contains("$") } + val sootMethodsToProvideInstance = classes.flatMap { + it.methods + .asSequence() + .filter { it.isStatic && it.returnType.toString() == clazz.name } + .filter { it.parameterTypes.all { !it.toString().contains(clazz.name) } } + .filter { !it.toString().contains('$') } + .toList() + } + val javaMethodsToProvideInstance = sootMethodsToProvideInstance.mapNotNull { it.toJavaMethod() } + classToStaticMethodsInstanceProviders[clazz] = javaMethodsToProvideInstance + return javaMethodsToProvideInstance + } + + fun getStaticFieldsInitializersOf(clazz: Class<*>): List { + if (classToStaticFieldsInstanceProviders.contains(clazz)) return classToStaticFieldsInstanceProviders[clazz]!! + val classes = Scene.v().classes.filter { !it.name.contains("$") } + val sootFieldsToProvideInstance = classes.flatMap { + it.fields + .asSequence() + .filter { it.isStatic && it.type.toString() == clazz.name } + .toList() + } + val javaFieldsToProvideInstance = sootFieldsToProvideInstance.mapNotNull { it.toJavaField() } + classToStaticFieldsInstanceProviders[clazz] = javaFieldsToProvideInstance + return javaFieldsToProvideInstance + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt new file mode 100644 index 0000000000..fb10a25a3f --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt @@ -0,0 +1,77 @@ +package org.utbot.engine.greyboxfuzzer.util + +import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.generator.* +import org.utbot.external.api.classIdForType +import org.utbot.framework.concrete.UtModelConstructor +import org.utbot.framework.plugin.api.* +import java.lang.reflect.Method +import java.lang.reflect.Parameter + + +fun UtAssembleModel.addModification(modification: UtStatementModel) = + UtAssembleModel( + this.id, + this.classId, + "${this.classId.name}#" + this.id?.toString(16), + this.instantiationCall, + this.modificationsChain + modification, + this.origin + ) + + +fun UtModelConstructor.constructAssembleModelUsingMethodInvocation( + clazz: Class<*>, + methodExecutableId: ExecutableId, + parameterValues: List +): UtAssembleModel { + val genId = UtModelGenerator.utModelConstructor.computeUnusedIdAndUpdate() + return UtAssembleModel( + genId, + classIdForType(clazz), + "${clazz.name}#" + genId.toString(16), + UtExecutableCallModel( + null, + methodExecutableId, + parameterValues + ) + ) +} + +//fun UtModelConstructor.constructModelFromValue(value: Any?, classId: ClassId) = +// if (value == null) { +// UtNullModel(classId) +// } else { +// try { +// ZestUtils.setUnserializableFieldsToNull(value) +// construct(value, classId) +// } catch (e: Throwable) { +// UtNullModel(classId) +// } +// } +// +//fun UtModelConstructor.constructModelFromValues(list: List>) = +// list.map { (value, classId) -> +// if (value?.value == null) { +// UtNullModel(classId) +// } else { +// try { +// ZestUtils.setUnserializableFieldsToNull(value.value) +// construct(value.value, classId) +// } catch (e: Throwable) { +// UtNullModel(classId) +// } +// } +// } + +fun Parameter.resolveParameterTypeAndBuildParameterContext( + parameterIndex: Int, + method: Method +): ParameterTypeContext { + val parameterTypeContext = this.createParameterTypeContext(0) + val resolvedOriginalType = parameterTypeContext.generics.resolveType(parameterTypeContext.type()) + val genericContext = resolvedOriginalType.createGenericsContext(this.type.toClass()!!) + val resolvedParameterType = genericContext.method(method).resolveParameterType(parameterIndex) + val newGenericContext = resolvedParameterType.createGenericsContext(resolvedParameterType.toClass()!!) + return createParameterContextForParameter(this, parameterIndex, newGenericContext, resolvedParameterType) +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt new file mode 100644 index 0000000000..cd6c88fed8 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt @@ -0,0 +1,16 @@ +package org.utbot.engine.greyboxfuzzer.util + +import org.utbot.framework.concrete.UtModelConstructor +import org.utbot.framework.plugin.api.UtModel +import java.util.* + +object UtModelGenerator { + + @JvmStatic + var utModelConstructor = UtModelConstructor(IdentityHashMap()) + + fun reset() { + utModelConstructor = UtModelConstructor(IdentityHashMap()) + } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/Common.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/Common.kt new file mode 100644 index 0000000000..4139bed5a7 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/Common.kt @@ -0,0 +1,77 @@ +package org.utbot.engine.greyboxfuzzer.util.kcheck + +import java.util.* + +object FancyFunctions { + fun (() -> R1).mapResult(mapper: (R1) -> R2): () -> R2 = + { mapper(this()) } + fun ((A1) -> R1).mapResult(mapper: (R1) -> R2): (A1) -> R2 = + { a1 -> mapper(this(a1)) } + fun ((A1, A2) -> R1).mapResult(mapper: (R1) -> R2): (A1, A2) -> R2 = + { a1, a2 -> mapper(this(a1, a2)) } + fun ((A1, A2, A3) -> R1).mapResult(mapper: (R1) -> R2): (A1, A2, A3) -> R2 = + { a1, a2, a3 -> mapper(this(a1, a2, a3)) } + fun ((A1, A2, A3, A4) -> R1).mapResult(mapper: (R1) -> R2): (A1, A2, A3, A4) -> R2 = + { a1, a2, a3, a4 -> mapper(this(a1, a2, a3, a4)) } +} + +inline infix fun Int.times(body: () -> Unit) { + for (i in 0..this) body() +} + +private class CharProgressionAsCharSequence(val from: CharProgression): CharSequence { + override val length: Int + get() = (from.last - from.first + 1) / from.step + + override operator fun get(index: Int): Char = + when (index) { + !in 0..(length - 1) -> throw IndexOutOfBoundsException("get(index: Int)") + else -> from.first + index + } + + override fun subSequence(startIndex: Int, endIndex: Int): CharSequence = + when{ + startIndex > endIndex -> throw IllegalArgumentException("startIndex > endIndex") + startIndex !in 0..(length - 1) -> throw IndexOutOfBoundsException("subSequence(startIndex: Int, endIndex: Int)") + endIndex !in 0..(length - 1) -> throw IndexOutOfBoundsException("subSequence(startIndex: Int, endIndex: Int)") + else -> CharProgression.fromClosedRange( + from.first + startIndex * from.step, + from.first + endIndex * from.step, + from.step + ).asCharSequence() + } + + override fun toString(): String = from.joinToString(separator = "") + override fun hashCode() = Objects.hash(from, 42) + override fun equals(other: Any?) = + other is CharProgressionAsCharSequence + && other.from == from +} + +fun CharProgression.asCharSequence(): CharSequence = CharProgressionAsCharSequence(this) + +private class CharListAsCharSequence(val from: List): CharSequence { + override val length: Int + get() = from.size + + override operator fun get(index: Int): Char = from[index] + + override fun subSequence(startIndex: Int, endIndex: Int) = from.subList(startIndex, endIndex).asCharSequence() + + override fun toString(): String = from.joinToString(separator = "") + override fun hashCode() = Objects.hash(from, 42) + override fun equals(other: Any?) = + other is CharListAsCharSequence + && other.from == from +} + +fun List.asCharSequence(): CharSequence = CharListAsCharSequence(this) + +inline fun Iterable<*>.firstInstanceOf(): T? { + for(e in this) if(e is T) return e + return null +} + +operator fun List.component6(): T = get(5) +operator fun List.component7(): T = get(6) +operator fun List.component8(): T = get(7) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/RandomEx.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/RandomEx.kt new file mode 100644 index 0000000000..69f7dce847 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/RandomEx.kt @@ -0,0 +1,83 @@ +package org.utbot.engine.greyboxfuzzer.util.kcheck + +import java.util.* + +class HighQualityRandom(seed: Long = System.nanoTime()): Random(seed) { + private var u: Long = 0L + private var v = 4101842887655102017L + private var w = 1L + + init { + u = seed xor v; + nextLong() + v = u; + nextLong() + w = v; + nextLong() + } + + override fun nextLong(): Long { + u = u * 2862933555777941757L + 7046029254386353087L; + v = v xor (v ushr 17) + v = v xor (v shl 31) + v = v xor (v ushr 8) + w = 4294957665L * (w and 0xffffffff) + (w ushr 32); + var x = u xor (u shl 21); + x = x xor (x ushr 35) + x = x xor (x shl 4) + return (x + v) xor w + } + + override fun next(bits: Int): Int { + return (nextLong() ushr (64 - bits)).toInt() + } +} + +fun Random.nextLong(bound: Long): Long { + var bits: Long + var v: Long + do { + bits = (nextLong() shl 1).ushr(1) + v = bits % bound + } while (bits - v + (bound - 1) < 0L) + return v +} +fun Random.nextShort(): Short = nextInRange(Short.MIN_VALUE.toInt(), Short.MAX_VALUE.toInt() + 1).toShort() +fun Random.nextShort(bound: Short): Short = nextInt(bound.toInt()).toShort() +fun Random.nextByte(): Byte = nextInRange(Byte.MIN_VALUE.toInt(), Byte.MAX_VALUE.toInt() + 1).toByte() +fun Random.nextByte(bound: Byte): Byte = nextInt(bound.toInt()).toByte() +fun Random.nextChar(): Char = nextShort().toChar() +fun Random.nextChar(alphabet: CharSequence) = alphabet[nextInt(alphabet.length)] +fun Random.nextString(alphabet: CharSequence, minLength: Int = 0, maxLength: Int = 1001) = + charSequence(alphabet).take(nextInRange(minLength, maxLength)).joinToString(separator = "") + +fun Random.nextInRange(min: Int, max: Int): Int = when { + max == min -> min + else -> (nextLong(max.toLong() - min.toLong()) + min).toInt() +} + + +fun Random.nextInRange(min: Long, max: Long): Long { + // this is a bit tricky + val minHalf = min / 2 + val maxHalf = max / 2 + val minOtherHalf = min - minHalf + val maxOtherHalf = max - maxHalf + return nextLong(maxHalf - minHalf + 1) + nextLong(maxOtherHalf - minOtherHalf) + min +} + +fun Random.nextInRange(min: Short, max: Short): Short = (nextInt(max - min) + min).toShort() +fun Random.nextInRange(min: Byte, max: Byte): Byte = (nextInt(max - min) + min).toByte() +fun Random.nextInRange(min: Float, max: Float): Float = nextFloat() * (max - min) + min +fun Random.nextInRange(min: Double, max: Double): Double = nextDouble() * (max - min) + min + +fun Random.intSequence() = generateSequence { nextInt() } +fun Random.longSequence() = generateSequence { nextLong() } +fun Random.shortSequence() = generateSequence { nextShort() } +fun Random.byteSequence() = generateSequence { nextByte() } +fun Random.booleanSequence() = generateSequence { nextBoolean() } +fun Random.floatSequence() = generateSequence { nextFloat() } +fun Random.doubleSequence() = generateSequence { nextDouble() } +fun Random.charSequence(alphabet: CharSequence) = generateSequence { nextChar(alphabet) } +fun Random.stringSequence(alphabet: CharSequence, minLength: Int = 0, maxLength: Int = 1000) = + generateSequence { nextString(alphabet, minLength, maxLength) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt index d3bf6bfbe4..4dbaf06fe0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt @@ -145,6 +145,7 @@ object UtBotJavaApi { dependencyClassPath: String, mockStrategyApi: MockStrategyApi = MockStrategyApi.OTHER_PACKAGES, generationTimeoutInMillis: Long = UtSettings.utBotGenerationTimeoutInMillis, + isGreyBoxFuzzing: Boolean = false, primitiveValuesSupplier: CustomFuzzerValueSupplier = CustomFuzzerValueSupplier { null } ): MutableList { fun createPrimitiveModels(supplier: CustomFuzzerValueSupplier, classId: ClassId): Sequence = @@ -182,8 +183,12 @@ object UtBotJavaApi { chosenClassesToMockAlways = emptySet(), generationTimeoutInMillis, generate = { symbolicEngine -> - symbolicEngine.fuzzing { defaultModelProvider -> - customModelProvider.withFallback(defaultModelProvider) + if (isGreyBoxFuzzing) { + symbolicEngine.greyBoxFuzzing() + } else { + symbolicEngine.fuzzing { defaultModelProvider -> + customModelProvider.withFallback(defaultModelProvider) + } } } ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt index c86c96e274..e7247e98f8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt @@ -17,6 +17,7 @@ import org.utbot.common.trace import org.utbot.engine.EngineController import org.utbot.engine.Mocker import org.utbot.engine.UtBotSymbolicEngine +import org.utbot.engine.greyboxfuzzer.util.GreyBoxFuzzingStatisticPrinter import org.utbot.engine.util.mockListeners.ForceMockListener import org.utbot.engine.util.mockListeners.ForceStaticMockListener import org.utbot.framework.TestSelectionStrategyType @@ -230,6 +231,9 @@ open class TestCaseGenerator( forceMockListener.detach(this, forceMockListener) forceStaticMockListener.detach(this, forceStaticMockListener) + if (UtSettings.useGreyBoxFuzzing) { + GreyBoxFuzzingStatisticPrinter.printFuzzingStats(methods) + } return methods.map { method -> UtMethodTestSet( method, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt index 2407407acd..12e672a995 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt @@ -19,6 +19,7 @@ fun defaultTestFlow(timeout: Long) = testFlow { isSymbolicEngineEnabled = true generationTimeout = timeout isFuzzingEnabled = UtSettings.useFuzzing + isGreyBoxFuzzingEnabled = UtSettings.useGreyBoxFuzzing if (generationTimeout > 0) { fuzzingValue = UtSettings.fuzzingTimeoutInMillis.coerceIn(0, generationTimeout) / generationTimeout.toDouble() } @@ -41,6 +42,7 @@ class TestFlow internal constructor(block: TestFlow.() -> Unit) { } var isSymbolicEngineEnabled = true var isFuzzingEnabled = false + var isGreyBoxFuzzingEnabled = false var fuzzingValue: Double = 0.1 set(value) { field = value.coerceIn(0.0, 1.0) @@ -59,6 +61,7 @@ class TestFlow internal constructor(block: TestFlow.() -> Unit) { fun build(engine: UtBotSymbolicEngine): Flow { return when { generationTimeout == 0L -> emptyFlow() + isGreyBoxFuzzingEnabled -> engine.greyBoxFuzzing(System.currentTimeMillis() + generationTimeout) isFuzzingEnabled -> { when (val value = if (isSymbolicEngineEnabled) (fuzzingValue * generationTimeout).toLong() else generationTimeout) { 0L -> engine.traverse() diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt index e95e76f5ea..5a02645a50 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt @@ -16,7 +16,12 @@ import soot.jimple.JimpleBody import soot.options.Options import soot.toolkits.graph.ExceptionalUnitGraph import java.io.File +import java.net.URI +import java.nio.file.FileSystems +import java.nio.file.Files import java.nio.file.Path +import kotlin.io.path.absolutePathString +import kotlin.streams.toList object SootUtils { /** @@ -87,6 +92,8 @@ private fun initSoot(buildDirs: List, classpath: String?, jdkInfo: JdkInfo } addBasicClasses(*classesToLoad) + addLibraryClasses(libraryClassesToLoad) + loadJavaStdLibClasses() Scene.v().loadNecessaryClasses() PackManager.v().runPacks() @@ -131,13 +138,35 @@ val ExecutableId.sootMethod: SootMethod fun jimpleBody(method: ExecutableId): JimpleBody = method.sootMethod.jimpleBody() - private fun addBasicClasses(vararg classes: Class<*>) { classes.forEach { Scene.v().addBasicClass(it.name, SootClass.BODIES) } } +private fun addLibraryClasses(classesNames: kotlin.collections.List) { + classesNames.forEach { + Scene.v().addBasicClass(it, SootClass.BODIES) + } +} + +private fun loadJavaStdLibClasses() { + val fs = FileSystems.getFileSystem(URI.create("jrt:/")) + val javaUtilsClasses = Files.walk(fs.getPath("modules", "java.base", "java/util")).toList() + val javaLangClasses = Files.walk(fs.getPath("modules", "java.base", "java/lang")).toList() + val classesToLoad = + (javaUtilsClasses + javaLangClasses) + .filter { it.absolutePathString().endsWith(".class") } + .filterNot { it.absolutePathString().contains("$") } + classesToLoad + .map { it.absolutePathString().removePrefix("/modules/java.base/").replace('/', '.') } + .forEach { + Scene.v().addBasicClass(it, SootClass.BODIES) + } +} + +val libraryClassesToLoad = mutableListOf() + private val classesToLoad = arrayOf( org.utbot.engine.overrides.collections.AbstractCollection::class, org.utbot.api.mock.UtMock::class, diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt index c86ddd0206..ed7d2fe420 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/ConcreteExecutor.kt @@ -103,8 +103,8 @@ class ConcreteExecutorPool(val maxCount: Int = Settings.defaultConcreteExecutorP * @param TIResult the return type of [Instrumentation.invoke] function for the given [instrumentation]. */ class ConcreteExecutor> private constructor( - internal val instrumentation: TInstrumentation, - internal val pathsToUserClasses: String + val instrumentation: TInstrumentation, + val pathsToUserClasses: String ) : Closeable, Executor { private val ldef: LifetimeDefinition = LifetimeDefinition() private val instrumentedProcessRunner: InstrumentedProcessRunner = InstrumentedProcessRunner() diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BigNumberConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BigNumberConstructor.kt new file mode 100644 index 0000000000..8b6a6318f0 --- /dev/null +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BigNumberConstructor.kt @@ -0,0 +1,32 @@ +package org.utbot.framework.concrete + +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.jClass +import org.utbot.framework.plugin.api.util.stringClassId + +internal class BigNumberConstructor : UtAssembleModelConstructorBase() { + + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, + value: Any, + classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + + val stringValue = value.toString() + val stringValueModel = internalConstructor.construct(stringValue, stringClassId) + + return UtExecutableCallModel( + instance = null, + ConstructorId(classId, listOf(stringClassId)), + listOf(stringValueModel), + + ) + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, + value: Any + ): List = emptyList() +} diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BitSetConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BitSetConstructor.kt new file mode 100644 index 0000000000..d1c7327f7a --- /dev/null +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BitSetConstructor.kt @@ -0,0 +1,37 @@ +package org.utbot.framework.concrete + +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtStatementModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.jClass +import org.utbot.framework.plugin.api.util.longArrayClassId +import org.utbot.framework.plugin.api.util.methodId + +internal class BitSetConstructor : UtAssembleModelConstructorBase() { + + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, + value: Any, + classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.util.BitSet + return with(internalConstructor) { + UtExecutableCallModel( + instance = null, + methodId(classId, "valueOf", classId, longArrayClassId), + listOf( + construct(value.toLongArray(), longArrayClassId), + ), + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, + value: Any + ): List = emptyList() + +} diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/DateTimeConstructors.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/DateTimeConstructors.kt new file mode 100644 index 0000000000..a28a678264 --- /dev/null +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/DateTimeConstructors.kt @@ -0,0 +1,433 @@ +package org.utbot.framework.concrete + +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtStatementModel +import org.utbot.framework.plugin.api.util.* + +internal class InstantConstructor : UtAssembleModelConstructorBase() { + + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + + checkClassCast(classId.jClass, value::class.java) + value as java.time.Instant + val seconds = value.epochSecond + val nanos = value.nano.toLong() + + val secondsModel = internalConstructor.construct(seconds, longClassId) + val nanosModel = internalConstructor.construct(nanos, longClassId) + + + return UtExecutableCallModel( + instance = null, + methodId(classId, "ofEpochSecond", classId, longClassId, longClassId), + listOf(secondsModel, nanosModel), + ) + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() +} + +internal class DurationConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.Duration + val seconds = value.seconds + val nanos = value.nano.toLong() + + val secondsModel = internalConstructor.construct(seconds, longClassId) + val nanosModel = internalConstructor.construct(nanos, longClassId) + + + return UtExecutableCallModel( + instance = null, + methodId(classId, "ofSeconds", classId, longClassId, longClassId), + listOf(secondsModel, nanosModel), + + ) + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class LocalDateConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.LocalDate + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "of", classId, intClassId, intClassId, intClassId), + listOf( + construct(value.year, intClassId), + construct(value.monthValue, intClassId), + construct(value.dayOfMonth, intClassId) + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class LocalTimeConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.LocalTime + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "of", classId, intClassId, intClassId, intClassId, intClassId), + listOf( + construct(value.hour, intClassId), + construct(value.minute, intClassId), + construct(value.second, intClassId), + construct(value.nano, intClassId) + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class LocalDateTimeConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.LocalDateTime + val timeClassId = java.time.LocalTime::class.java.id + val dateClassId = java.time.LocalTime::class.java.id + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "of", classId, dateClassId, timeClassId), + listOf( + construct(value.toLocalDate(), dateClassId), + construct(value.toLocalTime(), timeClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class ZoneIdConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.ZoneId + val id = value.id + + val idModel = internalConstructor.construct(id, stringClassId) + + + return UtExecutableCallModel( + instance = null, methodId(classId, "of", classId, stringClassId), listOf(idModel) + ) + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class MonthDayConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.MonthDay + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "of", classId, intClassId, intClassId), + listOf( + construct(value.monthValue, intClassId), + construct(value.dayOfMonth, intClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class YearConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.Year + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "of", classId, intClassId), + listOf( + construct(value.value, intClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class YearMonthConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.YearMonth + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "of", classId, intClassId, intClassId), + listOf( + construct(value.year, intClassId), + construct(value.monthValue, intClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class PeriodConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.Period + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "of", classId, intClassId, intClassId, intClassId), + listOf( + construct(value.years, intClassId), + construct(value.months, intClassId), + construct(value.days, intClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class ZoneOffsetConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.ZoneOffset + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "ofTotalSeconds", classId, intClassId), + listOf( + construct(value.totalSeconds, intClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class OffsetTimeConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.OffsetTime + val timeClassId = java.time.LocalTime::class.java.id + val offsetClassId = java.time.ZoneOffset::class.java.id + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "of", classId, timeClassId, offsetClassId), + listOf( + construct(value.toLocalTime(), timeClassId), + construct(value.offset, offsetClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class OffsetDateTimeConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.OffsetDateTime + val dateTimeClassId = java.time.LocalDateTime::class.java.id + val offsetClassId = java.time.ZoneOffset::class.java.id + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "of", classId, dateTimeClassId, offsetClassId), + listOf( + construct(value.toLocalDateTime(), dateTimeClassId), + construct(value.offset, offsetClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class ZonedDateTimeConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.time.ZonedDateTime + val dateTimeClassId = java.time.LocalDateTime::class.java.id + val offsetClassId = java.time.ZoneOffset::class.java.id + val zoneClassId = java.time.ZoneId::class.java.id + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "ofLenient", classId, dateTimeClassId, offsetClassId, zoneClassId), + listOf( + construct(value.toLocalDateTime(), dateTimeClassId), + construct(value.offset, offsetClassId), + construct(value.zone, zoneClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class DateConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.util.Date + val instantClassId = java.time.Instant::class.java.id + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "from", classId, instantClassId), + listOf( + construct(value.toInstant(), instantClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} + +internal class TimeZoneConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, value: Any, classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as java.util.TimeZone + val zoneClassId = java.time.ZoneId::class.java.id + + with(internalConstructor) { + return UtExecutableCallModel( + instance = null, + methodId(classId, "getTimeZone", classId, zoneClassId), + listOf( + construct(value.toZoneId(), zoneClassId), + ), + + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, value: Any + ): List = emptyList() + +} diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/LocaleConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/LocaleConstructor.kt new file mode 100644 index 0000000000..debee9aa67 --- /dev/null +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/LocaleConstructor.kt @@ -0,0 +1,37 @@ +package org.utbot.framework.concrete + +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtStatementModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.jClass +import org.utbot.framework.plugin.api.util.methodId +import org.utbot.framework.plugin.api.util.stringClassId +import java.util.* + +internal class LocaleConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, + value: Any, + classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as Locale + + return with(internalConstructor) { + UtExecutableCallModel( + instance = null, + methodId(classId, "forLanguageTag", classId, stringClassId), + listOf( + construct(value.toLanguageTag(), stringClassId), + ), + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, + value: Any + ): List = emptyList() +} \ No newline at end of file diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UUIDConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UUIDConstructor.kt new file mode 100644 index 0000000000..c97058e748 --- /dev/null +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UUIDConstructor.kt @@ -0,0 +1,35 @@ +package org.utbot.framework.concrete + +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtStatementModel +import org.utbot.framework.plugin.api.util.* +import java.util.* + +internal class UUIDConstructor : UtAssembleModelConstructorBase() { + override fun provideInstantiationCall( + internalConstructor: UtModelConstructorInterface, + value: Any, + classId: ClassId + ): UtExecutableCallModel { + checkClassCast(classId.jClass, value::class.java) + value as UUID + + return with(internalConstructor) { + UtExecutableCallModel( + instance = null, + constructorId(classId, longClassId, longClassId), + listOf( + construct(value.mostSignificantBits, longClassId), + construct(value.leastSignificantBits, longClassId), + ), + ) + } + } + + override fun UtAssembleModel.provideModificationChain( + internalConstructor: UtModelConstructorInterface, + value: Any + ): List = emptyList() +} \ No newline at end of file diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt index 3ab2051f72..788fa93c1e 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentation.kt @@ -190,3 +190,12 @@ object UtExecutionInstrumentation : Instrumentation { return instrumenter.classByteCode } } + +/** + * Transforms a list of internal [EtInstruction]s to a list of api [Instruction]s. + */ +internal fun List.toApiCoverage(instructionsCount: Long? = null): Coverage = + Coverage( + map { Instruction(it.className, it.methodSignature, it.line, it.id) }, + instructionsCount + ) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt new file mode 100644 index 0000000000..bcaa281e9e --- /dev/null +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt @@ -0,0 +1,196 @@ +package org.utbot.framework.concrete + +import org.objectweb.asm.Type +import org.utbot.common.StopWatch +import org.utbot.common.ThreadBasedExecutor +import org.utbot.common.withAccessibility +import org.utbot.framework.assemble.AssembleModelGenerator +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.* +import org.utbot.framework.util.isInaccessibleViaReflection +import org.utbot.instrumentation.instrumentation.ArgumentList +import org.utbot.instrumentation.instrumentation.Instrumentation +import org.utbot.instrumentation.instrumentation.InvokeInstrumentation +import org.utbot.instrumentation.instrumentation.et.ExplicitThrowInstruction +import org.utbot.instrumentation.instrumentation.et.TraceHandler +import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter +import org.utbot.instrumentation.instrumentation.mock.MockClassVisitor +import java.security.AccessControlException +import java.security.ProtectionDomain +import java.util.* +import kotlin.reflect.jvm.javaMethod + +class UtFuzzingConcreteExecutionResult( + val result: UtExecutionResult, + val coverage: Coverage +) {} + + +object UtFuzzingExecutionInstrumentation : Instrumentation { + private val delegateInstrumentation = InvokeInstrumentation() + + private val instrumentationContext = InstrumentationContext() + + private val traceHandler = TraceHandler() + private val pathsToUserClasses = mutableSetOf() + + override fun init(pathsToUserClasses: Set) { + this.pathsToUserClasses.clear() + this.pathsToUserClasses += pathsToUserClasses + } + + /** + * Ignores [arguments], because concrete arguments will be constructed + * from models passed via [parameters]. + * + * Argument [parameters] must be of type [UtConcreteExecutionData]. + */ + override fun invoke( + clazz: Class<*>, + methodSignature: String, + arguments: ArgumentList, + parameters: Any? + ): UtFuzzingConcreteExecutionResult { + + if (parameters !is UtConcreteExecutionData) { + throw IllegalArgumentException("Argument parameters must be of type UtConcreteExecutionData, but was: ${parameters?.javaClass}") + } + val (stateBefore, instrumentations, timeout) = parameters // smart cast to UtConcreteExecutionData + val parametersModels = listOfNotNull(stateBefore.thisInstance) + stateBefore.parameters + traceHandler.resetTrace() + return MockValueConstructor(instrumentationContext).use { constructor -> + val params = constructor.constructMethodParameters(parametersModels) + val staticFields = constructor + .constructStatics( + stateBefore + .statics + .filterKeys { !it.isInaccessibleViaReflection } + ) + .mapValues { (_, value) -> value.value } + + val concreteExecutionResult = withStaticFields(staticFields) { + val staticMethodsInstrumentation = instrumentations.filterIsInstance() + constructor.mockStaticMethods(staticMethodsInstrumentation) + val newInstanceInstrumentation = instrumentations.filterIsInstance() + constructor.mockNewInstances(newInstanceInstrumentation) + + traceHandler.resetTrace() + val stopWatch = StopWatch() + val context = UtContext(utContext.classLoader, stopWatch) + val concreteResult = ThreadBasedExecutor.threadLocal.invokeWithTimeout(timeout, stopWatch) { + withUtContext(context) { + delegateInstrumentation.invoke(clazz, methodSignature, params.map { it.value }) + } + }?.getOrThrow() as? Result<*> ?: Result.failure(TimeoutException("Timeout $timeout elapsed")) + val traceList = traceHandler.computeInstructionList() + + val cache = constructor.objectToModelCache + val utCompositeModelStrategy = + ConstructOnlyUserClassesOrCachedObjectsStrategy(pathsToUserClasses, cache) + val utModelConstructor = UtModelConstructor(cache, utCompositeModelStrategy) + utModelConstructor.run { + val concreteUtModelResult = concreteResult.fold({ + UtExecutionSuccessConcrete(it) + }) { + sortOutException(it) + } + UtFuzzingConcreteExecutionResult( + concreteUtModelResult, + traceList.toApiCoverage( + traceHandler.processingStorage.getInstructionsCount( + Type.getInternalName(clazz) + ) + ) + ) + } + } + + concreteExecutionResult + } + + } + + override fun getStaticField(fieldId: FieldId): Result = + delegateInstrumentation.getStaticField(fieldId).map { value -> + val cache = IdentityHashMap() + val strategy = ConstructOnlyUserClassesOrCachedObjectsStrategy( + pathsToUserClasses, cache + ) + UtModelConstructor(cache, strategy).run { + construct(value, fieldId.type) + } + } + + + private fun sortOutException(exception: Throwable): UtExecutionFailure { + if (exception is TimeoutException) { + return UtTimeoutException(exception) + } + if (exception is AccessControlException) { + return UtSandboxFailure(exception) + } + val instrs = traceHandler.computeInstructionList() + val isNested = if (instrs.isEmpty()) { + false + } else { + instrs.first().callId != instrs.last().callId + } + return if (instrs.isNotEmpty() && instrs.last().instructionData is ExplicitThrowInstruction) { + UtExplicitlyThrownException(exception, isNested) + } else { + UtImplicitlyThrownException(exception, isNested) + } + + } + + override fun transform( + loader: ClassLoader?, + className: String, + classBeingRedefined: Class<*>?, + protectionDomain: ProtectionDomain, + classfileBuffer: ByteArray + ): ByteArray { + val instrumenter = Instrumenter(classfileBuffer, loader) + + traceHandler.registerClass(className) + instrumenter.visitInstructions(traceHandler.computeInstructionVisitor(className)) + + val mockClassVisitor = instrumenter.visitClass { writer -> + MockClassVisitor( + writer, + InstrumentationContext.MockGetter::getMock.javaMethod!!, + InstrumentationContext.MockGetter::checkCallSite.javaMethod!!, + InstrumentationContext.MockGetter::hasMock.javaMethod!! + ) + } + + mockClassVisitor.signatureToId.forEach { (method, id) -> + instrumentationContext.methodSignatureToId += method to id + } + + return instrumenter.classByteCode + } + + private fun withStaticFields(staticFields: Map, block: () -> T): T { + val savedFields = mutableMapOf() + try { + staticFields.forEach { (fieldId, value) -> + fieldId.jField.run { + withAccessibility { + savedFields[fieldId] = get(null) + set(null, value) + } + } + } + return block() + } finally { + savedFields.forEach { (fieldId, value) -> + fieldId.jField.run { + withAccessibility { + set(null, value) + } + } + } + } + } +} diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtAssembleModelConstructors.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtAssembleModelConstructors.kt index 39576b949b..2850cf5632 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtAssembleModelConstructors.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtAssembleModelConstructors.kt @@ -76,6 +76,31 @@ private val predefinedConstructors = mutableMapOf, () -> UtAssembleMode /** * TODO: JIRA:1405 -- Add assemble constructors for another standard classes as well. */ + java.math.BigInteger::class.java.let { it to { BigNumberConstructor() } }, + java.math.BigDecimal::class.java.let { it to { BigNumberConstructor() } }, + + java.util.BitSet::class.java.let { it to { BitSetConstructor() } }, + java.util.UUID::class.java.let { it to { UUIDConstructor() } }, + java.util.Locale::class.java.let { it to { LocaleConstructor() } }, + java.util.Date::class.java.let { it to { DateConstructor() } }, + java.util.TimeZone::class.java.let { it to { TimeZoneConstructor() } }, + + java.time.Instant::class.java.let { it to { InstantConstructor() } }, + java.time.Duration::class.java.let { it to { DurationConstructor() } }, + java.time.ZoneId::class.java.let { it to { ZoneIdConstructor() } }, + java.time.LocalDate::class.java.let { it to { LocalDateConstructor() } }, + java.time.LocalTime::class.java.let { it to { LocalTimeConstructor() } }, + java.time.LocalDateTime::class.java.let { it to { LocalDateTimeConstructor() } }, + java.time.MonthDay::class.java.let { it to { MonthDayConstructor() } }, + java.time.Year::class.java.let { it to { YearConstructor() } }, + java.time.YearMonth::class.java.let { it to { YearMonthConstructor() } }, + java.time.Period::class.java.let { it to { PeriodConstructor() } }, + java.time.ZoneOffset::class.java.let { it to { ZoneOffsetConstructor() } }, + java.time.OffsetTime::class.java.let { it to { OffsetTimeConstructor() } }, + java.time.OffsetDateTime::class.java.let { it to { OffsetDateTimeConstructor() } }, + java.time.ZonedDateTime::class.java.let { it to { ZonedDateTimeConstructor() } }, + + ).apply { /** * Primitive wrappers diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtModelConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtModelConstructor.kt index f020382c85..d9942f4132 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtModelConstructor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtModelConstructor.kt @@ -68,7 +68,7 @@ class UtModelConstructor( .mapNotNull { it.id } .toMutableSet() - private fun computeUnusedIdAndUpdate(): Int { + fun computeUnusedIdAndUpdate(): Int { while (unusedId in usedIds) { unusedId++ } diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt index c41a617309..3cf98d97ba 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt @@ -165,6 +165,7 @@ fun main(args: Array) { fun setOptions() { Settings.defaultConcreteExecutorPoolSize = 1 UtSettings.useFuzzing = true + UtSettings.useGreyBoxFuzzing = false UtSettings.classfilesCanChange = false // We need to use assemble model generator to increase readability UtSettings.useAssembleModelGenerator = true diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt index 9a42bae1d7..8a5a1ff902 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt @@ -12,6 +12,7 @@ import org.utbot.framework.plugin.api.UtOverflowFailure import org.utbot.framework.plugin.api.UtSandboxFailure import org.utbot.framework.plugin.api.UtStreamConsumingFailure import org.utbot.framework.plugin.api.UtSymbolicExecution +import org.utbot.framework.plugin.api.UtExecutionSuccessConcrete import org.utbot.framework.plugin.api.UtTimeoutException import org.utbot.framework.plugin.api.util.humanReadableName import org.utbot.framework.plugin.api.util.isCheckedException @@ -220,6 +221,7 @@ private fun UtExecutionResult.clusterKind() = when (this) { is UtTimeoutException -> ExecutionGroup.TIMEOUTS is UtConcreteExecutionFailure -> ExecutionGroup.CRASH_SUITE is UtSandboxFailure -> ExecutionGroup.SECURITY + is UtExecutionSuccessConcrete -> ExecutionGroup.SUCCESSFUL_EXECUTIONS } /** From 9fa553a8157297135a593b583d0a67b70266b934 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 15 Nov 2022 15:26:21 +0300 Subject: [PATCH 02/30] mocks generation --- .../FakeAnnotatedTypeFactoryWithType.java | 111 +++++++ .../internal/ParameterTypeContext.java | 307 ++++++++++-------- .../engine/greyboxfuzzer/GreyBoxFuzzer.kt | 35 +- .../greyboxfuzzer/generator/DataGenerator.kt | 1 + .../generator/GreyBoxFuzzerGenerators.kt | 2 +- .../generator/QuickCheckExtensions.kt | 2 +- .../userclasses/UserClassGenerator.kt | 9 +- .../generator/ClassesInstanceGenerator.kt | 7 +- .../ConstructorBasedInstanceGenerator.kt | 6 +- ...terfaceImplementationsInstanceGenerator.kt | 99 +++++- .../userclasses/generator/ObjectGenerator.kt | 28 +- .../generator/ReflectionClassGenerator.kt | 25 +- .../generator/ReflectionTypeGenerator.kt | 34 ++ .../engine/greyboxfuzzer/util/SootUtils.kt | 28 +- .../framework/plugin/api/TestCaseGenerator.kt | 2 + 15 files changed, 514 insertions(+), 182 deletions(-) create mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.java create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.java new file mode 100644 index 0000000000..5d45e6963a --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.java @@ -0,0 +1,111 @@ +/* + The MIT License + + Copyright (c) 2010-2021 Paul R. Holser, Jr. + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE + LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION + OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION + WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +package org.utbot.quickcheck.internal; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedArrayType; +import java.lang.reflect.AnnotatedType; +import java.lang.reflect.Type; + +final class FakeAnnotatedTypeFactoryWithType { + private FakeAnnotatedTypeFactoryWithType() { + throw new UnsupportedOperationException(); + } + + static AnnotatedType makeFrom(Type type) { + return type.getClass().isArray() ? makeArrayType(type) : makePlainType(type); + } + + private static AnnotatedArrayType makeArrayType(Type type) { + return new FakeAnnotatedArrayType(type); + } + + private static AnnotatedType makePlainType(Type type) { + return new FakeAnnotatedType(type); + } + + private static final class FakeAnnotatedArrayType + implements AnnotatedArrayType { + + private final Type type; + + FakeAnnotatedArrayType(Type type) { + this.type = type; + } + + @Override public AnnotatedType getAnnotatedGenericComponentType() { + return makeFrom(type.getClass().getComponentType()); + } + + // Not introduced until JDK 9 -- not marking as... + // @Override + public AnnotatedType getAnnotatedOwnerType() { + return null; + } + + @Override public Type getType() { + return type; + } + + @Override public T getAnnotation(Class annotationClass) { + + return null; + } + + @Override public Annotation[] getAnnotations() { + return new Annotation[0]; + } + + @Override public Annotation[] getDeclaredAnnotations() { + return new Annotation[0]; + } + } + + private static final class FakeAnnotatedType implements AnnotatedType { + private final Type type; + + FakeAnnotatedType(Type type) { + this.type = type; + } + + @Override public Type getType() { + return type; + } + + @Override public T getAnnotation(Class annotationClass) { + + return null; + } + + @Override public Annotation[] getAnnotations() { + return new Annotation[0]; + } + + @Override public Annotation[] getDeclaredAnnotations() { + return new Annotation[0]; + } + } +} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java index 6b4388534e..31aca8dc41 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java @@ -50,7 +50,7 @@ a copy of this software and associated documentation files (the public class ParameterTypeContext { private static final String EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE = - "The generator %s named in @%s on parameter %s does not produce a type-compatible object"; + "The generator %s named in @%s on parameter %s does not produce a type-compatible object"; private static org.utbot.quickcheck.internal.Zilch zilch; private final String parameterName; @@ -64,31 +64,56 @@ public class ParameterTypeContext { private AnnotatedElement annotatedElement; private boolean allowMixedTypes; + public String getDeclarerName() { + return declarerName; + } + public GenericsContext getGenerics() { return generics; } + public org.javaruntype.type.Type getResolved() { return resolved; } + public static ParameterTypeContext forClass(Class clazz) { return new ParameterTypeContext( - clazz.getTypeName(), - org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(clazz), - clazz.getTypeName(), - Types.forJavaLangReflectType(clazz), - GenericsResolver.resolve(clazz)); + clazz.getTypeName(), + org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(clazz), + clazz.getTypeName(), + Types.forJavaLangReflectType(clazz), + GenericsResolver.resolve(clazz)); + } + + public static ParameterTypeContext forType(Type type) { + return forType(type, null); + } + + public static ParameterTypeContext forType(Type type, GenericsContext generics) { + GenericsContext gctx; + if (generics == null) { + gctx = GenericsResolver.resolve(type.getClass()); + } else { + gctx = generics; + } + return new ParameterTypeContext( + type.getTypeName(), + org.utbot.quickcheck.internal.FakeAnnotatedTypeFactoryWithType.makeFrom(type), + type.getTypeName(), + Types.forJavaLangReflectType(type), + gctx); } public static ParameterTypeContext forField(Field field) { GenericsContext generics = - GenericsResolver.resolve(field.getDeclaringClass()); + GenericsResolver.resolve(field.getDeclaringClass()); return new ParameterTypeContext( - field.getName(), - field.getAnnotatedType(), - field.getDeclaringClass().getName(), - Types.forJavaLangReflectType(generics.resolveFieldType(field)), - generics); + field.getName(), + field.getAnnotatedType(), + field.getDeclaringClass().getName(), + Types.forJavaLangReflectType(generics.resolveFieldType(field)), + generics); } public static ParameterTypeContext forParameter(Parameter parameter) { @@ -103,35 +128,35 @@ public static ParameterTypeContext forParameter(Parameter parameter) { if (exec instanceof Method) { Method method = (Method) exec; MethodGenericsContext methodGenerics = - GenericsResolver.resolve(clazz).method(method); + GenericsResolver.resolve(clazz).method(method); resolved = - Types.forJavaLangReflectType( - methodGenerics.resolveParameterType(parameterIndex)); + Types.forJavaLangReflectType( + methodGenerics.resolveParameterType(parameterIndex)); generics = methodGenerics; } else if (exec instanceof Constructor) { Constructor ctor = (Constructor) exec; ConstructorGenericsContext constructorGenerics = - GenericsResolver.resolve(clazz).constructor(ctor); + GenericsResolver.resolve(clazz).constructor(ctor); resolved = - Types.forJavaLangReflectType( - constructorGenerics.resolveParameterType(parameterIndex)); + Types.forJavaLangReflectType( + constructorGenerics.resolveParameterType(parameterIndex)); generics = constructorGenerics; } else { throw new IllegalStateException("Unrecognized subtype of Executable"); } return new ParameterTypeContext( - parameter.getName(), - parameter.getAnnotatedType(), - declarerName, - resolved, - generics, - parameterIndex); + parameter.getName(), + parameter.getAnnotatedType(), + declarerName, + resolved, + generics, + parameterIndex); } public static ParameterTypeContext forParameter( - Parameter parameter, - MethodGenericsContext generics) { + Parameter parameter, + MethodGenericsContext generics) { Executable exec = parameter.getDeclaringExecutable(); Class clazz = exec.getDeclaringClass(); @@ -139,13 +164,13 @@ public static ParameterTypeContext forParameter( int parameterIndex = parameterIndex(exec, parameter); return new ParameterTypeContext( - parameter.getName(), - parameter.getAnnotatedType(), - declarerName, - Types.forJavaLangReflectType( - generics.resolveParameterType(parameterIndex)), - generics, - parameterIndex); + parameter.getName(), + parameter.getAnnotatedType(), + declarerName, + Types.forJavaLangReflectType( + generics.resolveParameterType(parameterIndex)), + generics, + parameterIndex); } private static int parameterIndex(Executable exec, Parameter parameter) { @@ -156,32 +181,32 @@ private static int parameterIndex(Executable exec, Parameter parameter) { } throw new IllegalStateException( - "Cannot find parameter " + parameter + " on " + exec); + "Cannot find parameter " + parameter + " on " + exec); } public ParameterTypeContext( - String parameterName, - AnnotatedType parameterType, - String declarerName, - org.javaruntype.type.Type resolvedType, - GenericsContext generics) { + String parameterName, + AnnotatedType parameterType, + String declarerName, + org.javaruntype.type.Type resolvedType, + GenericsContext generics) { this( - parameterName, - parameterType, - declarerName, - resolvedType, - generics, - -1); - } - - public ParameterTypeContext( - String parameterName, - AnnotatedType parameterType, - String declarerName, - org.javaruntype.type.Type resolvedType, - GenericsContext generics, - int parameterIndex) { + parameterName, + parameterType, + declarerName, + resolvedType, + generics, + -1); + } + + public ParameterTypeContext( + String parameterName, + AnnotatedType parameterType, + String declarerName, + org.javaruntype.type.Type resolvedType, + GenericsContext generics, + int parameterIndex) { this.parameterName = parameterName; this.parameterType = parameterType; @@ -195,7 +220,7 @@ public ParameterTypeContext annotate(AnnotatedElement element) { this.annotatedElement = element; List producedGenerators = - allAnnotationsByType(element, Produced.class); + allAnnotationsByType(element, Produced.class); List generators; if (producedGenerators.size() == 1) { @@ -203,10 +228,10 @@ public ParameterTypeContext annotate(AnnotatedElement element) { } else { generators = allAnnotationsByType(element, From.class); if (!generators.isEmpty() - && element instanceof AnnotatedWildcardType) { + && element instanceof AnnotatedWildcardType) { throw new IllegalArgumentException( - "Wildcards cannot be marked with @From"); + "Wildcards cannot be marked with @From"); } } @@ -232,20 +257,20 @@ public boolean allowMixedTypes() { public ParameterTypeContext methodReturnTypeContext(Method method) { if (!(generics instanceof MethodGenericsContext)) { throw new IllegalStateException( - "invoking methodReturnTypeContext in present of " + generics); + "invoking methodReturnTypeContext in present of " + generics); } MethodGenericsContext testMethodGenerics = - (MethodGenericsContext) generics; + (MethodGenericsContext) generics; MethodGenericsContext argMethodGenerics = - testMethodGenerics.parameterType(parameterIndex).method(method); + testMethodGenerics.parameterType(parameterIndex).method(method); return new ParameterTypeContext( - "return value", - method.getAnnotatedReturnType(), - method.getName(), - Types.forJavaLangReflectType(argMethodGenerics.resolveReturnType()), - argMethodGenerics); + "return value", + method.getAnnotatedReturnType(), + method.getName(), + Types.forJavaLangReflectType(argMethodGenerics.resolveReturnType()), + argMethodGenerics); } private void addGenerators(List generators) { @@ -257,7 +282,7 @@ private void addGenerators(List generators) { } private Generator makeGenerator( - Class generatorType) { + Class generatorType) { Constructor ctor; @@ -283,14 +308,14 @@ private Class rawParameterType() { private void ensureCorrectType(Generator generator) { for (Class each : generator.types()) { if (!maybeWrap(resolved.getRawClass()) - .isAssignableFrom(maybeWrap(each))) { + .isAssignableFrom(maybeWrap(each))) { throw new IllegalArgumentException( - format( - EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE, - each, - From.class.getName(), - parameterName)); + format( + EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE, + each, + From.class.getName(), + parameterName)); } } } @@ -308,12 +333,12 @@ public Type type() { } /** + * @return the annotated program element this context represents + * @see + * this issue * @deprecated This will likely go away when languages whose compilers * and interpreters produce class files that support annotations on type * uses. - * @see - * this issue - * @return the annotated program element this context represents */ @Deprecated public AnnotatedElement annotatedElement() { @@ -321,17 +346,17 @@ public AnnotatedElement annotatedElement() { } /** + * @return the annotated program element this context represents + * @see + * this issue * @deprecated This will likely go away when languages whose compilers * and interpreters produce class files that support annotations on type * uses. - * @see - * this issue - * @return the annotated program element this context represents */ @Deprecated public boolean topLevel() { return annotatedElement instanceof Parameter - || annotatedElement instanceof Field; + || annotatedElement instanceof Field; } public List>> explicitGenerators() { @@ -342,6 +367,7 @@ private void addParameterTypeContextToDeque(ArrayDeque deq if (ptx.resolved.getName().equals(Zilch.class.getName())) return; deque.add(ptx); } + public List getAllSubParameterTypeContexts(SourceOfRandomness sourceOfRandomness) { ArrayList res = new ArrayList<>(); res.add(this); @@ -361,27 +387,28 @@ public List getAllSubParameterTypeContexts(SourceOfRandomn } return res; } + public ParameterTypeContext arrayComponentContext() { @SuppressWarnings("unchecked") org.javaruntype.type.Type component = - arrayComponentOf((org.javaruntype.type.Type) resolved); + arrayComponentOf((org.javaruntype.type.Type) resolved); AnnotatedType annotatedComponent = annotatedArrayComponent(component); return new ParameterTypeContext( - annotatedComponent.getType().getTypeName(), - annotatedComponent, - parameterType.getType().getTypeName(), - component, - generics) - .annotate(annotatedComponent) - .allowMixedTypes(true); + annotatedComponent.getType().getTypeName(), + annotatedComponent, + parameterType.getType().getTypeName(), + component, + generics) + .annotate(annotatedComponent) + .allowMixedTypes(true); } private AnnotatedType annotatedArrayComponent( - org.javaruntype.type.Type component) { + org.javaruntype.type.Type component) { return parameterType instanceof AnnotatedArrayType - ? ((AnnotatedArrayType) parameterType).getAnnotatedGenericComponentType() - : org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(component.getComponentClass()); + ? ((AnnotatedArrayType) parameterType).getAnnotatedGenericComponentType() + : org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(component.getComponentClass()); } public boolean isArray() { @@ -401,19 +428,19 @@ public List> getTypeParameters() { } public List typeParameterContexts( - SourceOfRandomness random) { + SourceOfRandomness random) { List typeParamContexts = new ArrayList<>(); List> typeParameters = getTypeParameters(); List annotatedTypeParameters = - annotatedComponentTypes(annotatedType()); + annotatedComponentTypes(annotatedType()); for (int i = 0; i < typeParameters.size(); ++i) { TypeParameter p = typeParameters.get(i); AnnotatedType a = - annotatedTypeParameters.size() > i - ? annotatedTypeParameters.get(i) - : zilch(); + annotatedTypeParameters.size() > i + ? annotatedTypeParameters.get(i) + : zilch(); if (p instanceof StandardTypeParameter) addStandardTypeParameterContext(typeParamContexts, p, a); @@ -431,76 +458,76 @@ else if (p instanceof ExtendsTypeParameter) } private void addStandardTypeParameterContext( - List typeParameterContexts, - TypeParameter p, - AnnotatedType a) { + List typeParameterContexts, + TypeParameter p, + AnnotatedType a) { typeParameterContexts.add( - new ParameterTypeContext( - p.getType().getName(), - a, - annotatedType().getType().getTypeName(), - p.getType(), - generics) - .allowMixedTypes(!(a instanceof TypeVariable)) - .annotate(a)); + new ParameterTypeContext( + p.getType().getName(), + a, + annotatedType().getType().getTypeName(), + p.getType(), + generics) + .allowMixedTypes(!(a instanceof TypeVariable)) + .annotate(a)); } private void addWildcardTypeParameterContext( - List typeParameterContexts, - AnnotatedType a) { + List typeParameterContexts, + AnnotatedType a) { typeParameterContexts.add( - new ParameterTypeContext( - "Zilch", - a, - annotatedType().getType().getTypeName(), - Types.forJavaLangReflectType(org.utbot.quickcheck.internal.Zilch.class), - GenericsResolver.resolve(Zilch.class)) - .allowMixedTypes(true) - .annotate(a)); + new ParameterTypeContext( + "Zilch", + a, + annotatedType().getType().getTypeName(), + Types.forJavaLangReflectType(org.utbot.quickcheck.internal.Zilch.class), + GenericsResolver.resolve(Zilch.class)) + .allowMixedTypes(true) + .annotate(a)); } private void addExtendsTypeParameterContext( - List typeParameterContexts, - TypeParameter p, - AnnotatedType a) { + List typeParameterContexts, + TypeParameter p, + AnnotatedType a) { typeParameterContexts.add( - new ParameterTypeContext( - p.getType().getName(), - annotatedComponentTypes(a).get(0), - annotatedType().getType().getTypeName(), - p.getType(), - generics) - .allowMixedTypes(false) - .annotate(a)); + new ParameterTypeContext( + p.getType().getName(), + annotatedComponentTypes(a).get(0), + annotatedType().getType().getTypeName(), + p.getType(), + generics) + .allowMixedTypes(false) + .annotate(a)); } private void addSuperTypeParameterContext( - SourceOfRandomness random, - List typeParameterContexts, - TypeParameter p, - AnnotatedType a) { + SourceOfRandomness random, + List typeParameterContexts, + TypeParameter p, + AnnotatedType a) { Set> supertypes = supertypes(p.getType()); org.javaruntype.type.Type choice = choose(supertypes, random); typeParameterContexts.add( - new ParameterTypeContext( - p.getType().getName(), - annotatedComponentTypes(a).get(0), - annotatedType().getType().getTypeName(), - choice, - generics) - .allowMixedTypes(false) - .annotate(a)); + new ParameterTypeContext( + p.getType().getName(), + annotatedComponentTypes(a).get(0), + annotatedType().getType().getTypeName(), + choice, + generics) + .allowMixedTypes(false) + .annotate(a)); } private static AnnotatedType zilch() { try { return ParameterTypeContext.class.getDeclaredField("zilch") - .getAnnotatedType(); + .getAnnotatedType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt index 009632efe6..754ddc2783 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -6,7 +6,6 @@ import org.utbot.engine.greyboxfuzzer.mutator.Mutator import org.utbot.engine.greyboxfuzzer.mutator.Seed import org.utbot.engine.greyboxfuzzer.mutator.SeedCollector import org.utbot.engine.greyboxfuzzer.util.* -import org.utbot.external.api.classIdForType import org.utbot.framework.concrete.* import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* @@ -14,10 +13,8 @@ import org.utbot.framework.util.sootMethod import org.utbot.instrumentation.ConcreteExecutor import java.lang.reflect.Field import java.lang.reflect.Method +import java.lang.reflect.Modifier import kotlin.random.Random -import kotlin.reflect.KFunction -import kotlin.reflect.jvm.javaMethod -import kotlin.system.exitProcess class GreyBoxFuzzer( private val pathsToUserClasses: String, @@ -26,13 +23,12 @@ class GreyBoxFuzzer( ) { private val seeds = SeedCollector() -// val kfunction = methodUnderTest as KFunction<*> - private val explorationStageIterations = 10 + private val explorationStageIterations = 100 private val exploitationStageIterations = 100 - private var thisInstance: UtModel? = generateThisInstance(methodUnderTest.classId.jClass) + private var thisInstance: UtModel? = null //TODO make it return Sequence - suspend fun fuzz(): Sequence> { + suspend fun fuzz(): Sequence { logger.debug { "Started to fuzz ${methodUnderTest.name}" } val javaClazz = methodUnderTest.classId.jClass val javaMethod = methodUnderTest.sootMethod.toJavaMethod()!! @@ -71,6 +67,9 @@ class GreyBoxFuzzer( val parametersToGenericsReplacer = method.parameters.map { it to GenericsReplacer() } repeat(numberOfIterations) { iterationNumber -> logger.debug { "Iteration number $iterationNumber" } + if (!methodUnderTest.isStatic && thisInstance == null) { + thisInstance = generateThisInstance(methodUnderTest.classId.jClass) + } if (thisInstance != null && iterationNumber != 0) { if (Random.getTrue(20)) { logger.debug { "Trying to regenerate this instance" } @@ -134,7 +133,7 @@ class GreyBoxFuzzer( val coverage = executionResult.coverage.coveredInstructions .map { it.lineNumber } - .filter { it in currentMethodLines } + //.filter { it in currentMethodLines } .toSet() executionResult.coverage.coveredInstructions.forEach { CoverageCollector.coverage.add(it) } return (coverage - prevMethodCoverage).size @@ -241,13 +240,17 @@ class GreyBoxFuzzer( } private fun generateThisInstance(clazz: Class<*>) = - if (!methodUnderTest.isStatic) { - DataGenerator.generate( - clazz, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus - ) - } else { + try { + if (!methodUnderTest.isStatic) { + DataGenerator.generate( + clazz, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus + ) + } else { + null + } + } catch (_: Throwable) { null } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt index 0920bdec06..ae2829650f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt @@ -8,6 +8,7 @@ import org.utbot.engine.logger import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel +import soot.SootMethod import java.lang.reflect.Parameter object DataGenerator { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt index 38aa3de28f..342ba86de4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt @@ -55,7 +55,7 @@ object GreyBoxFuzzerGenerators { it.register(HashMapGenerator()) it.register(LocaleGenerator()) it.register(BitSetGenerator()) - it.register(TimeZoneGenerator()) + //it.register(TimeZoneGenerator()) it.register(HashSetGenerator()) it.register(ArrayListGenerator()) it.register(VectorGenerator()) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt index 65636e54c4..cecc8595c0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -169,7 +169,7 @@ fun createParameterContextForParameter( ): ParameterTypeContext { val exec = parameter.declaringExecutable val clazz = exec.declaringClass - val declarerName = clazz.name + '.' + exec.name + val declarerName = clazz.name val resolvedType = when (generics) { is MethodGenericsContext -> generics.resolveParameterType(parameterIndex) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt index 30bd7fbd6a..dcf01364ea 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt @@ -47,10 +47,13 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { override fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel? { logger.debug { "Trying to generate ${parameterTypeContext!!.resolved}. Current depth depth: $depth" } - if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return null + if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return UtNullModel(clazz!!.id) val immutableClazz = clazz!! - if (immutableClazz == Any::class.java) return ObjectGenerator(random, status).generate() - if (immutableClazz == Class::class.java) return ReflectionClassGenerator(parameterTypeContext!!).generate() + when (immutableClazz) { + Any::class.java -> return ObjectGenerator(parameterTypeContext!!, random, status).generate() + Class::class.java -> return ReflectionClassGenerator(parameterTypeContext!!).generate() + Type::class.java -> return ReflectionTypeGenerator(parameterTypeContext!!).generate() + } //TODO! generate inner classes instances if (immutableClazz.declaringClass != null && !immutableClazz.hasModifiers(Modifier.STATIC)) { return UtNullModel(immutableClazz.id) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt index b5e117c6b5..773a7a2e09 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt @@ -2,6 +2,7 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.logger import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel import org.utbot.quickcheck.generator.GenerationStatus import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext @@ -43,7 +44,11 @@ class ClassesInstanceGenerator( ).generate() else -> null } - generatedInstance?.let { return it } ?: typeOfGenerations.removeIf { it == randomTypeOfGeneration } + if (generatedInstance == null || generatedInstance is UtNullModel) { + typeOfGenerations.remove(randomTypeOfGeneration) + } else { + return generatedInstance + } } return null } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt index f79a24fbbb..c564f4c063 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt @@ -3,7 +3,9 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.common.isPublic import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext @@ -32,7 +34,7 @@ class ConstructorBasedInstanceGenerator( try { initialGenericContext?.constructor(constructor) } catch (_: Throwable) { - null + return UtNullModel(clazz.id) } } } @@ -58,7 +60,7 @@ class ConstructorBasedInstanceGenerator( ) } //Avoiding recursion - .filter { it.parameterTypes.all { !it.name.contains(clazz.name) } } +// .filter { it.parameterTypes.all { !it.name.contains(clazz.name) } } .chooseRandomConstructor() } catch (_: Throwable) { null diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt index b01d34d35f..409fc685ef 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt @@ -1,14 +1,21 @@ @file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") + package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +import org.utbot.common.isAbstract +import org.utbot.engine.greyboxfuzzer.generator.DataGenerator import org.utbot.engine.greyboxfuzzer.util.* -import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import ru.vyarus.java.generics.resolver.context.GenericsInfo import java.lang.reflect.Type import kotlin.random.Random +import kotlin.system.exitProcess class InterfaceImplementationsInstanceGenerator( private val resolvedType: Type, @@ -31,7 +38,7 @@ class InterfaceImplementationsInstanceGenerator( return it } } - val genericsContext = getRandomImplementerGenericContext(clazz, resolvedType) ?: return null + val genericsContext = getRandomImplementerGenericContext(clazz, resolvedType) ?: return generateMock(clazz, resolvedType, typeContext) return ClassesInstanceGenerator( genericsContext.currentClass(), genericsContext, @@ -40,7 +47,46 @@ class InterfaceImplementationsInstanceGenerator( sourceOfRandomness, generationStatus, depth - ).generate() + ).generate() ?: generateMock(clazz, resolvedType, typeContext) + } + + private fun generateMock(clazz: Class<*>, resolvedType: Type, typeContext: GenericsContext): UtModel? { + if (!clazz.isInterface) return UtNullModel(clazz.id) + val sootClazz = clazz.toSootClass() ?: return UtNullModel(clazz.id) + val constructor = UtModelGenerator.utModelConstructor + val allNeededInterfaces = clazz.methods.map { it.declaringClass }.filter { it != clazz }.toSet() + val chainToGenericsContext = allNeededInterfaces.map { cl -> + val chain = cl.toSootClass() + ?.getImplementersOfWithChain() + ?.filter { it.contains(sootClazz) } + ?.map { it.dropLastWhile { it != sootClazz } } + ?.minByOrNull { it.size } + ?.map { it.toJavaClass() } + if (chain == null || chain.any { it == null }) { + null + } else { + cl to buildGenericsContextForInterfaceParent(resolvedType, clazz, chain.map { it!! }.reversed().drop(1)) + } + } + val allChainToGenericsContext = chainToGenericsContext + (clazz to typeContext) + val mocks = clazz.methods + .filter { it.isAbstract } + .associateTo(mutableMapOf()) { method -> + val genericsContextForMethod = allChainToGenericsContext.find { it!!.first == method.declaringClass }?.second + val methodReturnType = + if (genericsContextForMethod != null) { + genericsContextForMethod.method(method).resolveReturnType().let { + if (it.toClass() == null) method.returnType else it + } + } else { + method.returnType + } + val parameterTypeContext = ParameterTypeContext.forType(methodReturnType, genericsContextForMethod) + val generatedUtModelWithReturnType = + DataGenerator.generate(parameterTypeContext, sourceOfRandomness, generationStatus) ?: UtNullModel(methodReturnType.toClass()!!.id) + method.executableId as ExecutableId to listOf(generatedUtModelWithReturnType) + } + return UtCompositeModel(constructor.computeUnusedIdAndUpdate(), clazz.id, isMock = true, mocks = mocks) } private fun getRandomImplementerGenericContext(clazz: Class<*>, resolvedType: Type): GenericsContext? { @@ -57,14 +103,14 @@ class InterfaceImplementationsInstanceGenerator( } ?: return null //Deal with generics val generics = mutableListOf>>() - var prevImplementer = sootClass.toJavaClass() + var prevImplementer = clazz resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> if (prevImplementer.toClass() != null) { generics.add(typeVariable to mutableListOf(prevImplementer.toClass()!!.typeParameters[index])) } } for (implementer in randomImplementersChain) { - val javaImplementer = implementer.toJavaClass() + val javaImplementer = implementer.toJavaClass() ?: return null val extendType = javaImplementer.let { it.genericInterfaces + it.genericSuperclass } .find { it.toClass() == prevImplementer } val tp = prevImplementer.typeParameters @@ -79,10 +125,49 @@ class InterfaceImplementationsInstanceGenerator( } } } - val g = prevImplementer.typeParameters.map { tp -> tp.name to generics.find { it.second.last() == tp }?.first }.toMap() + val g = + prevImplementer.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } val gm = LinkedHashMap() - g.forEach { gm[it.key] = it.value!! } + g.forEach { + if (it.value != null) { + gm[it.key] = it.value!! + } + } val m = mutableMapOf(prevImplementer to gm) return GenericsContext(GenericsInfo(prevImplementer, m), prevImplementer) } + + private fun buildGenericsContextForInterfaceParent(resolvedType: Type, clazz: Class<*>, parentChain: List>): GenericsContext? { + val generics = mutableListOf>>() + var curClass = clazz + resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> + if (curClass.toClass() != null) { + generics.add(typeVariable to mutableListOf(curClass.toClass()!!.typeParameters[index])) + } + } + for (parent in parentChain) { + val parentType = curClass.let { it.genericInterfaces.toList() + listOf(it.genericSuperclass) } + .find { it.toClass() == parent } + val tp = curClass.typeParameters + curClass = parent + if (tp.isEmpty()) continue + val newTp = parentType?.getActualTypeArguments()?.ifEmpty { return null } ?: return null + tp.mapIndexed { index, typeVariable -> typeVariable to newTp[index] } + .forEach { typeVar -> + val indexOfTypeParam = generics.indexOfFirst { it.second.last() == typeVar.first } + if (indexOfTypeParam != -1) { + generics[indexOfTypeParam].second.add(curClass.typeParameters[indexOfTypeParam]) + } + } + } + val g = curClass.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } + val gm = LinkedHashMap() + g.forEach { + if (it.value != null) { + gm[it.key] = it.value!! + } + } + val m = mutableMapOf(curClass to gm) + return GenericsContext(GenericsInfo(curClass, m), curClass) + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt index 95bfa36bb5..e6832b6157 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt @@ -1,20 +1,42 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGenerators +import org.utbot.engine.greyboxfuzzer.generator.getOrProduceGenerator +import org.utbot.engine.greyboxfuzzer.util.getAllTypesFromCastAndInstanceOfInstructions +import org.utbot.engine.greyboxfuzzer.util.getTrue +import org.utbot.engine.greyboxfuzzer.util.toJavaClass +import org.utbot.engine.greyboxfuzzer.util.toSootMethod import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.MethodGenericsContext +import kotlin.random.Random class ObjectGenerator( + private val parameterTypeContext: ParameterTypeContext, private val sourceOfRandomness: SourceOfRandomness, private val generationStatus: GenerationStatus -): InstanceGenerator { - override fun generate(): UtModel? = - GreyBoxFuzzerGenerators.generatorRepository +) : InstanceGenerator { + override fun generate(): UtModel? { + val currentSootMethod = + (parameterTypeContext.generics as? MethodGenericsContext)?.currentMethod()?.toSootMethod() + val potentialUsefulClasses = + currentSootMethod?.getAllTypesFromCastAndInstanceOfInstructions()?.mapNotNull { it.toJavaClass() } + val potentialInterestingObjectReplacement = + if (potentialUsefulClasses?.isNotEmpty() == true && Random.getTrue(50)) { + val randomClass = potentialUsefulClasses.random() + GreyBoxFuzzerGenerators.generatorRepository + .getOrProduceGenerator(randomClass) + ?.generate(sourceOfRandomness, generationStatus) + } else null + potentialInterestingObjectReplacement?.let { return it } + return GreyBoxFuzzerGenerators.generatorRepository .generators .toList() .flatMap { it.second } .filter { !it.hasComponents() } .randomOrNull() ?.generate(sourceOfRandomness, generationStatus) + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt index 6abe8993cb..238dbbd060 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt @@ -1,15 +1,34 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator +import org.utbot.engine.greyboxfuzzer.util.getTrue +import org.utbot.engine.greyboxfuzzer.util.toJavaClass import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.internal.ParameterTypeContext +import soot.Scene +import java.lang.reflect.Type +import kotlin.random.Random class ReflectionClassGenerator( private val parameterTypeContext: ParameterTypeContext ) : InstanceGenerator { - override fun generate(): UtModel? = - parameterTypeContext.resolved.typeParameters.randomOrNull()?.type?.componentClass?.let { - UtModelGenerator.utModelConstructor.construct(it, Class::class.java.id) + override fun generate(): UtModel { + val packageName = parameterTypeContext.declarerName.substringBeforeLast('.') + val randomClassFromSamePackage = + Scene.v().classes + .filter { it.name.startsWith(packageName) } + .filterNot { it.isInnerClass } + .mapNotNull { it.toJavaClass() } + .randomOrNull() + if (randomClassFromSamePackage != null && Random.getTrue(50)) { + return UtModelGenerator.utModelConstructor.construct(randomClassFromSamePackage, Class::class.java.id) } + Scene.v().classes.randomOrNull()?.toJavaClass()?.let { + if (Random.getTrue(75)) { + return UtModelGenerator.utModelConstructor.construct(it, Class::class.java.id) + } + } + return UtModelGenerator.utModelConstructor.construct(Any::class.java, Class::class.java.id) + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt new file mode 100644 index 0000000000..7aa714906d --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt @@ -0,0 +1,34 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator +import org.utbot.engine.greyboxfuzzer.util.getTrue +import org.utbot.engine.greyboxfuzzer.util.toJavaClass +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.internal.ParameterTypeContext +import soot.Scene +import java.lang.reflect.Type +import kotlin.random.Random + +class ReflectionTypeGenerator(private val parameterTypeContext: ParameterTypeContext) : InstanceGenerator { + override fun generate(): UtModel { + val packageName = parameterTypeContext.declarerName.substringBeforeLast('.') + val randomClassFromSamePackage = + Scene.v().classes + .filter { it.name.startsWith(packageName) } + .filterNot { it.isInnerClass } + .mapNotNull { it.toJavaClass() } + .randomOrNull() + if (randomClassFromSamePackage != null && Random.getTrue(50)) { + return UtModelGenerator.utModelConstructor.construct(randomClassFromSamePackage, Type::class.java.id) + } + Scene.v().classes.randomOrNull()?.toJavaClass()?.let { + return UtModelGenerator.utModelConstructor.construct(it, Type::class.java.id) + } + return UtModelGenerator.utModelConstructor.construct(Any::class.java, Type::class.java.id) + } +} + +//val packageName = parameterTypeContext.declarerName.substringBeforeLast('.') +//Scene.v().classes.filter { it.name.startsWith("com.alibaba.fastjson.util") } +////parameterTypeContext.declarerName \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt index 29e5c76d3e..9227e35565 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt @@ -2,12 +2,15 @@ package org.utbot.engine.greyboxfuzzer.util import org.utbot.framework.plugin.api.util.signature import soot.Hierarchy +import soot.RefType import soot.Scene import soot.SootClass import soot.SootField import soot.SootMethod import soot.jimple.internal.JAssignStmt +import soot.jimple.internal.JCastExpr import soot.jimple.internal.JInstanceFieldRef +import soot.jimple.internal.JInstanceOfExpr import java.lang.reflect.Field import java.lang.reflect.Method import kotlin.reflect.KFunction @@ -44,6 +47,17 @@ fun SootClass.getImplementersOfWithChain(): List> { return res } +fun SootMethod.getAllTypesFromCastAndInstanceOfInstructions(): Set = + this.activeBody.units.asSequence().filterIsInstance() + .map { it.rightOp } + .filter { it is JCastExpr || it is JInstanceOfExpr } + .mapNotNull { + when (it) { + is JCastExpr -> (it.type as? RefType)?.sootClass + else -> ((it as JInstanceOfExpr).checkType as? RefType)?.sootClass + } + }.toSet() + fun SootMethod.getClassFieldsUsedByFunc(clazz: Class<*>) = activeBody.units .asSequence() @@ -53,11 +67,15 @@ fun SootMethod.getClassFieldsUsedByFunc(clazz: Class<*>) = .mapNotNull { fieldRef -> clazz.getAllDeclaredFields().find { it.name == fieldRef.field.name } } .toSet() -fun SootClass.toJavaClass(): Class<*> = +fun SootClass.toJavaClass(): Class<*>? = try { Class.forName(this.name) - } catch (e: ClassNotFoundException) { - CustomClassLoader.classLoader.loadClass(this.name) + } catch (e: Throwable) { + try { + CustomClassLoader.classLoader.loadClass(this.name) + } catch (e: Throwable) { + null + } } fun KFunction<*>.toSootMethod(): SootMethod? = this.javaMethod?.toSootMethod() @@ -73,12 +91,12 @@ fun Method.toSootMethod(): SootMethod? { } fun SootMethod.toJavaMethod(): Method? = - declaringClass.toJavaClass().getAllDeclaredMethods().find { + declaringClass.toJavaClass()?.getAllDeclaredMethods()?.find { it.signature == this.bytecodeSignature.drop(1).dropLast(1).substringAfter("${declaringClass.name}: ") } fun SootField.toJavaField(): Field? = - declaringClass.toJavaClass().getAllDeclaredFields().find { it.name == name } + declaringClass.toJavaClass()?.getAllDeclaredFields()?.find { it.name == name } fun Field.toSootField(): SootField? = declaringClass.toSootClass()?.fields?.find { it.name == name } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt index e7247e98f8..fbaae6ca63 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt @@ -150,6 +150,8 @@ open class TestCaseGenerator( for ((method, controller) in method2controller) { controller.job = launch(currentUtContext) { if (!isActive) return@launch + //TODO remove + if (!method.name.contains("readString")) return@launch try { //yield one to From 390d805a76a6f203502884e9e860d8e6a78fb216 Mon Sep 17 00:00:00 2001 From: Saloed Date: Thu, 10 Nov 2022 16:41:51 +0300 Subject: [PATCH 03/30] remove shrinker --- .../main/java/org/utbot/quickcheck/From.java | 65 --- .../quickcheck/MinimalCounterexampleHook.java | 46 --- .../main/java/org/utbot/quickcheck/Mode.java | 63 --- .../NonTrackingGenerationStatus.java | 15 - .../main/java/org/utbot/quickcheck/Pair.java | 70 ---- .../java/org/utbot/quickcheck/Produced.java | 55 --- .../java/org/utbot/quickcheck/Property.java | 97 ----- .../main/java/org/utbot/quickcheck/When.java | 68 ---- .../conversion/StringConversion.java | 40 -- .../org/utbot/quickcheck/generator/Also.java | 69 ---- .../generator/ComponentizedGenerator.java | 29 +- .../org/utbot/quickcheck/generator/Ctor.java | 152 ------- .../generator/DecimalGenerator.java | 123 ------ .../utbot/quickcheck/generator/Distinct.java | 26 -- .../utbot/quickcheck/generator/Fields.java | 123 ------ .../org/utbot/quickcheck/generator/Gen.java | 222 ----------- .../generator/GenerationStatus.java | 100 ----- .../utbot/quickcheck/generator/Generator.java | 109 +---- .../generator/GeneratorConfiguration.java | 26 -- .../GeneratorConfigurationException.java | 26 -- .../quickcheck/generator/Generators.java | 126 ------ .../utbot/quickcheck/generator/InRange.java | 29 +- .../generator/IntegralGenerator.java | 100 ----- .../utbot/quickcheck/generator/Lambdas.java | 29 +- .../org/utbot/quickcheck/generator/Only.java | 79 ---- .../utbot/quickcheck/generator/Precision.java | 29 +- .../utbot/quickcheck/generator/Shrink.java | 47 --- .../org/utbot/quickcheck/generator/Size.java | 29 +- .../quickcheck/generator/VoidGenerator.java | 27 -- .../java/lang/AbstractStringGenerator.java | 84 ---- .../generator/java/lang/BooleanGenerator.java | 41 -- .../generator/java/lang/ByteGenerator.java | 46 --- .../java/lang/CharacterGenerator.java | 48 --- .../generator/java/lang/CodePointShrink.java | 83 ---- .../generator/java/lang/DoubleGenerator.java | 50 --- .../generator/java/lang/Encoded.java | 28 -- .../generator/java/lang/FloatGenerator.java | 54 +-- .../generator/java/lang/IntegerGenerator.java | 47 --- .../generator/java/lang/LongGenerator.java | 48 --- .../java/lang/PrimitiveBooleanGenerator.java | 41 -- .../java/lang/PrimitiveByteGenerator.java | 47 --- .../java/lang/PrimitiveCharGenerator.java | 45 --- .../java/lang/PrimitiveDoubleGenerator.java | 50 --- .../java/lang/PrimitiveFloatGenerator.java | 49 --- .../java/lang/PrimitiveIntGenerator.java | 46 --- .../java/lang/PrimitiveLongGenerator.java | 46 --- .../java/lang/PrimitiveShortGenerator.java | 46 --- .../generator/java/lang/ShortGenerator.java | 46 --- .../generator/java/lang/StringGenerator.java | 27 -- .../java/lang/strings/CodePoints.java | 25 +- .../java/math/BigDecimalGenerator.java | 57 +-- .../java/math/BigIntegerGenerator.java | 48 +-- .../java/nio/charset/CharsetGenerator.java | 25 -- .../generator/java/time/ClockGenerator.java | 26 +- .../java/time/DurationGenerator.java | 23 -- .../generator/java/time/InstantGenerator.java | 23 -- .../java/time/LocalDateGenerator.java | 23 -- .../java/time/LocalDateTimeGenerator.java | 23 -- .../java/time/LocalTimeGenerator.java | 23 -- .../java/time/MonthDayGenerator.java | 23 -- .../java/time/OffsetDateTimeGenerator.java | 23 -- .../java/time/OffsetTimeGenerator.java | 23 -- .../generator/java/time/PeriodGenerator.java | 23 -- .../generator/java/time/YearGenerator.java | 23 -- .../java/time/YearMonthGenerator.java | 23 -- .../generator/java/time/ZoneIdGenerator.java | 25 +- .../java/time/ZoneOffsetGenerator.java | 23 -- .../java/time/ZonedDateTimeGenerator.java | 23 -- .../java/util/ArrayListGenerator.java | 25 -- .../generator/java/util/BitSetGenerator.java | 56 --- .../java/util/CollectionGenerator.java | 104 +---- .../generator/java/util/DateGenerator.java | 46 --- .../generator/java/util/HashMapGenerator.java | 24 -- .../generator/java/util/HashSetGenerator.java | 24 -- .../java/util/HashtableGenerator.java | 24 -- .../java/util/LinkedHashMapGenerator.java | 24 -- .../java/util/LinkedHashSetGenerator.java | 24 -- .../java/util/LinkedListGenerator.java | 24 -- .../generator/java/util/ListGenerator.java | 24 -- .../generator/java/util/LocaleGenerator.java | 25 +- .../generator/java/util/MapGenerator.java | 139 ------- .../java/util/OptionalDoubleGenerator.java | 53 --- .../java/util/OptionalGenerator.java | 52 --- .../java/util/OptionalIntGenerator.java | 54 --- .../java/util/OptionalLongGenerator.java | 51 --- .../java/util/PropertiesGenerator.java | 43 -- .../generator/java/util/RFC4122.java | 30 +- .../generator/java/util/SetGenerator.java | 26 +- .../generator/java/util/StackGenerator.java | 24 -- .../java/util/TimeZoneGenerator.java | 25 +- .../generator/java/util/VectorGenerator.java | 24 -- .../util/concurrent/CallableGenerator.java | 26 +- .../util/function/BiFunctionGenerator.java | 24 -- .../util/function/BiPredicateGenerator.java | 24 -- .../function/BinaryOperatorGenerator.java | 24 -- .../function/DoubleFunctionGenerator.java | 24 -- .../java/util/function/FunctionGenerator.java | 24 -- .../util/function/IntFunctionGenerator.java | 25 -- .../util/function/LongFunctionGenerator.java | 24 -- .../util/function/PredicateGenerator.java | 24 -- .../java/util/function/SupplierGenerator.java | 26 +- .../function/ToDoubleBiFunctionGenerator.java | 24 -- .../function/ToDoubleFunctionGenerator.java | 24 -- .../function/ToIntBiFunctionGenerator.java | 25 -- .../util/function/ToIntFunctionGenerator.java | 24 -- .../function/ToLongBiFunctionGenerator.java | 25 -- .../function/ToLongFunctionGenerator.java | 25 -- .../util/function/UnaryOperatorGenerator.java | 24 -- .../hook/NilMinimalCounterexampleHook.java | 39 -- .../internal/CartesianIterator.java | 96 ----- .../quickcheck/internal/Comparables.java | 50 --- .../internal/FakeAnnotatedTypeFactory.java | 25 +- .../internal/GeometricDistribution.java | 25 +- .../org/utbot/quickcheck/internal/Items.java | 24 -- .../org/utbot/quickcheck/internal/Lists.java | 111 ------ .../quickcheck/internal/ParameterSampler.java | 49 --- .../internal/ParameterTypeContext.java | 372 +++++++----------- .../internal/PropertyParameterContext.java | 110 ------ .../org/utbot/quickcheck/internal/Ranges.java | 25 +- .../utbot/quickcheck/internal/Reflection.java | 27 +- .../internal/ReflectionException.java | 23 -- .../quickcheck/internal/SeededValue.java | 59 --- .../utbot/quickcheck/internal/Sequences.java | 152 ------- .../quickcheck/internal/ShrinkControl.java | 68 ---- .../utbot/quickcheck/internal/Weighted.java | 23 -- .../org/utbot/quickcheck/internal/Zilch.java | 23 -- .../constraint/ConstraintEvaluator.java | 84 ---- .../ConstructorInvokingStringConversion.java | 48 --- .../MethodInvokingStringConversion.java | 48 --- .../conversion/StringConversions.java | 97 ----- .../generator/AbstractGenerationStatus.java | 37 -- .../internal/generator/ArrayGenerator.java | 105 +---- .../generator/CompositeGenerator.java | 54 --- .../internal/generator/EnumGenerator.java | 28 +- .../generator/ExhaustiveDomainGenerator.java | 66 ---- .../generator/GeneratorRepository.java | 103 +---- .../generator/GuaranteeValuesGenerator.java | 58 --- .../internal/generator/LambdaGenerator.java | 26 +- .../generator/MarkerInterfaceGenerator.java | 25 +- .../internal/generator/NullableGenerator.java | 38 +- .../PropertyParameterGenerationContext.java | 182 --------- .../generator/SamplingDomainGenerator.java | 55 --- .../ServiceLoaderGeneratorSource.java | 57 --- .../generator/SimpleGenerationStatus.java | 23 -- .../internal/generator/ZilchGenerator.java | 23 -- .../sampling/ExhaustiveParameterSampler.java | 139 ------- .../sampling/TupleParameterSampler.java | 96 ----- .../quickcheck/random/SourceOfRandomness.java | 25 +- .../quickcheck/runner/JUnitQuickcheck.java | 110 ------ .../runner/JUnitQuickcheckTestClass.java | 107 ----- .../NoValuesSatisfiedPropertyAssumptions.java | 17 - .../quickcheck/runner/PropertyFalsified.java | 101 ----- .../quickcheck/runner/PropertyStatement.java | 197 ---------- .../quickcheck/runner/PropertyVerifier.java | 122 ------ .../utbot/quickcheck/runner/ShrinkNode.java | 223 ----------- .../org/utbot/quickcheck/runner/Shrinker.java | 111 ------ .../generator/GreyBoxFuzzerGenerators.kt | 3 + 157 files changed, 179 insertions(+), 8387 deletions(-) delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/From.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/MinimalCounterexampleHook.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/Mode.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/Pair.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/Produced.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/Property.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/When.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/conversion/StringConversion.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Also.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Ctor.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Fields.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Only.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/Shrink.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CodePointShrink.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/hook/NilMinimalCounterexampleHook.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/CartesianIterator.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Lists.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterSampler.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/PropertyParameterContext.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/SeededValue.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Sequences.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/ShrinkControl.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/constraint/ConstraintEvaluator.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/ConstructorInvokingStringConversion.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/MethodInvokingStringConversion.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/StringConversions.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ExhaustiveDomainGenerator.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GuaranteeValuesGenerator.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/PropertyParameterGenerationContext.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SamplingDomainGenerator.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ServiceLoaderGeneratorSource.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/ExhaustiveParameterSampler.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/TupleParameterSampler.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheck.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheckTestClass.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/NoValuesSatisfiedPropertyAssumptions.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyFalsified.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyStatement.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyVerifier.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/ShrinkNode.java delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/runner/Shrinker.java diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/From.java b/utbot-framework/src/main/java/org/utbot/quickcheck/From.java deleted file mode 100644 index 9456b496b0..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/From.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck; - -import org.utbot.quickcheck.Produced; -import org.utbot.quickcheck.Property; -import org.utbot.quickcheck.generator.Generator; - -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - *

Mark a parameter of a {@link Property} method with this annotation to - * have random values supplied to it via the specified - * {@link Generator}.

- * - *

You may specify as many of these annotations as as you wish on a given - * parameter. On a given generation, one of the specified generators will be - * chosen at random with probability in proportion to {@link #frequency()}.

- * - *

If any such generator produces values of a type incompatible with the - * type of the marked parameter, {@link IllegalArgumentException} is - * raised.

- */ -@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) -@Retention(RUNTIME) -@Repeatable(Produced.class) -public @interface From { - /** - * @return the generator to be used for the annotated property parameter - */ - Class value(); - - /** - * @return a weight to influence how often the generator is chosen - */ - int frequency() default 1; -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/MinimalCounterexampleHook.java b/utbot-framework/src/main/java/org/utbot/quickcheck/MinimalCounterexampleHook.java deleted file mode 100644 index 54da339a4f..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/MinimalCounterexampleHook.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck; - -import org.utbot.quickcheck.Property; - -/** - *

Allows access to an actual failing example.

- * - *

This may be useful if any of the objects' {@link Object#toString()} - * representations is difficult to understand.

- * - * @see Property#onMinimalCounterexample() - */ -public interface MinimalCounterexampleHook { - /** - * @param counterexample the minimal counterexample (after shrinking) - * @param action work to perform with the minimal counterexample; - * for example, this could repeat the test using the same inputs. - * This action should be safely callable multiple times. - */ - void handle(Object[] counterexample, Runnable action); -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/Mode.java b/utbot-framework/src/main/java/org/utbot/quickcheck/Mode.java deleted file mode 100644 index 4d8ac52c6d..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/Mode.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck; - -import org.utbot.quickcheck.Property; -import org.utbot.quickcheck.internal.ParameterSampler; -import org.utbot.quickcheck.internal.sampling.ExhaustiveParameterSampler; -import org.utbot.quickcheck.internal.sampling.TupleParameterSampler; - -/** - * Represents different modes of execution of property-based tests. - * - * @see org.utbot.quickcheck.generator.Only - * @see org.utbot.quickcheck.generator.Also - */ -public enum Mode { - /** - * Verify {@link org.utbot.quickcheck.Property#trials()} tuples of arguments for a property's - * parameters. - */ - SAMPLING { - @Override ParameterSampler sampler(int defaultSampleSize) { - return new TupleParameterSampler(defaultSampleSize); - } - }, - - /** - * Generate {@link Property#trials()} arguments for each parameter - * property, and verify the cross-products of those sets of arguments. - * This behavior mirrors that of the JUnit - * {@link org.junit.experimental.theories.Theories} runner. - */ - EXHAUSTIVE { - @Override ParameterSampler sampler(int defaultSampleSize) { - return new ExhaustiveParameterSampler(defaultSampleSize); - } - }; - - abstract ParameterSampler sampler(int defaultSampleSize); -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java b/utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java index 8d107083ca..e5bffee1df 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java @@ -32,10 +32,6 @@ import org.utbot.quickcheck.internal.GeometricDistribution; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - /** * Provides a generation status that does not track the number of trials @@ -49,7 +45,6 @@ public class NonTrackingGenerationStatus implements GenerationStatus { public static final int MEAN_SIZE = 10; private final SourceOfRandomness random; - private final Map, Object> contextValues = new HashMap<>(); private final GeometricDistribution geometric = new GeometricDistribution(); @@ -68,14 +63,4 @@ public int attempts() { " is not supported in guided mode."); } - @Override - public GenerationStatus setValue(Key key, T value) { - contextValues.put(key, value); - return this; - } - - @Override - public Optional valueOf(Key key) { - return Optional.ofNullable(key.cast(contextValues.get(key))); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/Pair.java b/utbot-framework/src/main/java/org/utbot/quickcheck/Pair.java deleted file mode 100644 index d641703a84..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/Pair.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck; - -import java.util.Objects; - -/** - * Typed pair of elements. - * - * @param type of first element of pair - * @param type of second element of pair - * @see org.utbot.quickcheck.generator.Gen#frequency(Pair, Pair[]) - */ -public final class Pair { - public final F first; - public final S second; - - /** - * Makes a pair. - * - * @param first first element of the pair - * @param second second element of the pair - */ - public Pair(F first, S second) { - this.first = first; - this.second = second; - } - - @Override public int hashCode() { - return Objects.hash(first, second); - } - - @Override public boolean equals(Object o) { - if (o == this) - return true; - if (!(o instanceof Pair)) - return false; - - Pair other = (Pair) o; - return Objects.equals(first, other.first) - && Objects.equals(second, other.second); - } - - @Override public String toString() { - return String.format("[%s = %s]", first, second); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/Produced.java b/utbot-framework/src/main/java/org/utbot/quickcheck/Produced.java deleted file mode 100644 index ce137809b8..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/Produced.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck; - -import org.utbot.quickcheck.From; -import org.utbot.quickcheck.Property; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - *

Mark a parameter of a {@link Property} method with this annotation to - * have random values supplied to it via one of the - * {@link org.utbot.quickcheck.generator.Generator}s specified by the - * aggregated {@link From} annotations.

- * - *

Alternatively, you can specify many generators via many repetitions of - * {@link From}, without using this container annotation.

- * - *

On a given generation, one of the specified generators will be chosen at - * random with probability in proportion to {@link From#frequency()}.

- * - * @see From - */ -@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) -@Retention(RUNTIME) -public @interface Produced { - From[] value(); -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/Property.java b/utbot-framework/src/main/java/org/utbot/quickcheck/Property.java deleted file mode 100644 index 513686b46e..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/Property.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck; - -import org.utbot.quickcheck.MinimalCounterexampleHook; -import org.utbot.quickcheck.Mode; -import org.utbot.quickcheck.hook.NilMinimalCounterexampleHook; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static org.utbot.quickcheck.Mode.SAMPLING; -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - *

Mark a method on a class that is {@linkplain org.junit.runner.RunWith - * run with} the {@link org.utbot.quickcheck.runner.JUnitQuickcheck} - * runner with this annotation to have it run as a property-based test.

- * - *

A method marked with this annotation should be an instance method - * declared as {@code public} with a return type of {@code void}.

- */ -@Target(METHOD) -@Retention(RUNTIME) -public @interface Property { - /** - * @return the verification mode for the property - */ - Mode mode() default SAMPLING; - - /** - * @return how many sets of parameters to verify the property with, in - * {@link Mode#SAMPLING} mode; in {@link Mode#EXHAUSTIVE} mode, how many - * values to generate for each property parameter - */ - int trials() default 100; - - /** - * @return whether or not to attempt to {@linkplain - * org.utbot.quickcheck.generator.Shrink shrink} a failing set - * of parameters - */ - boolean shrink() default true; - - /** - * @return the maximum number of {@linkplain - * org.utbot.quickcheck.generator.Shrink shrink} attempts to make - * on a failing set of parameters; in effect only when {@link #shrink()} - * is {@code true} - */ - int maxShrinks() default 100; - - /** - * @return the maximum depth of {@linkplain - * org.utbot.quickcheck.generator.Shrink shrink} tree to make on - * a failing set of parameters; in effect only when {@link #shrink()} is - * {@code true} - */ - int maxShrinkDepth() default 20; - - /** - * @return the maximum elapsed time for the shrinking process in - * milliseconds; in effect only when {@link #shrink()} is {@code true} - */ - int maxShrinkTime() default 60_000; - - /** - * @return callback that it is executed if a minimal counterexample - * is found (after shrinking) - */ - Class onMinimalCounterexample() - default NilMinimalCounterexampleHook.class; -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/When.java b/utbot-framework/src/main/java/org/utbot/quickcheck/When.java deleted file mode 100644 index 992b304054..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/When.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck; - -import org.utbot.quickcheck.Property; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.PARAMETER; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - * Mark a parameter of a {@link Property} method with this annotation to - * specify metadata about values generated for that parameter. - */ -@Target(PARAMETER) -@Retention(RUNTIME) -public @interface When { - /** - * @return the ratio of discarded generated values to successful generated - * values above which values for the annotated property parameter will - * no longer be generated. For a non-positive value, an - * {@link IllegalArgumentException} is raised. The default value is 10, - * to curtail generation for {@link #satisfies()} expressions that are - * difficult to satisfy or can never be satisfied (inadvertently or - * otherwise). - */ - int discardRatio() default 10; - - /** - * @return an OGNL expression - * used to constrain the values fed to the annotated property parameter. - * The expression should evaluate to a {@code boolean} value. Within the - * expression, {@code "_"} refers to the property parameter. - */ - String satisfies() default ""; - - /** - * @return a value to be used as the initial seed for the random value - * generator. Not specifying a value causes the seed to be chosen - * randomly. - */ - long seed() default 0; -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/conversion/StringConversion.java b/utbot-framework/src/main/java/org/utbot/quickcheck/conversion/StringConversion.java deleted file mode 100644 index 150a57b10f..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/conversion/StringConversion.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.conversion; - -/** - * Describes ways of transforming string input into objects of another type. - */ -@FunctionalInterface -public interface StringConversion { - /** - * Transform the given "raw" string" into an object of another type. - * - * @param raw the string to convert - * @return the result of the conversion - */ - Object convert(String raw); -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Also.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Also.java deleted file mode 100644 index 0bc1c56191..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Also.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.generator; - -import org.utbot.quickcheck.Property; -import org.utbot.quickcheck.conversion.StringConversion; -import org.utbot.quickcheck.generator.Only; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - *

Mark a parameter of a {@link Property} method with this annotation to - * ensure that a limited set of values are guaranteed to be used as the value - * of that parameter to test the property.

- * - *

In {@linkplain org.utbot.quickcheck.Mode#SAMPLING sampling} - * mode, on each trial junit-quickcheck ensures that the first n - * values are the given set, and generates the remaining (trials - n) - * values in the usual way. - * - *

In {@linkplain org.utbot.quickcheck.Mode#EXHAUSTIVE exhaustive} - * mode, junit-quickcheck uses the values in the limited set for the property - * parameter, and generates the remaining (trials - n) values in the - * usual way.

- * - *

Note: You will still need a generator defined for the - * property parameter's type when this annotation is used.

- */ -@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) -@Retention(RUNTIME) -public @interface Also { - /** - * @return the values to which the property parameter will certainly be - * assigned during property verification - */ - String[] value(); - - /** - * @see Only#by() - */ - Class by() default StringConversion.class; -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java index 17343c0ed1..86a7749f0a 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java @@ -1,40 +1,13 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; import org.javaruntype.type.TypeParameter; import java.lang.reflect.AnnotatedType; import java.util.ArrayList; import java.util.List; -import static org.utbot.quickcheck.internal.Reflection.annotatedComponentTypes; import static java.util.Collections.unmodifiableList; +import static org.utbot.quickcheck.internal.Reflection.annotatedComponentTypes; /** * Produces values for property parameters of types that have parameterizations diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Ctor.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Ctor.java deleted file mode 100644 index 65636aa75a..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Ctor.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.generator; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.external.api.UtModelFactoryKt; -import org.utbot.framework.concrete.UtModelConstructor; -import org.utbot.framework.plugin.api.*; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.reflect.AnnotatedType; -import java.lang.reflect.Constructor; -import java.lang.reflect.Parameter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.instantiate; -import static org.utbot.quickcheck.internal.Reflection.singleAccessibleConstructor; - -/** - *

Produces instances of a class by generating values for the parameters of - * one of the constructors on the class, and invoking the constructor.

- * - *

If a constructor parameter is marked with an annotation that influences - * the generation of a given kind of value, that annotation will be applied to - * the generation of values for that parameter.

- * - *

This generator is intended to be used with - * {@link org.utbot.quickcheck.From}, and not to be available via the - * {@link java.util.ServiceLoader} mechanism.

- * - * @param the type of objects generated - */ -public class Ctor extends Generator { - private final Constructor ctor; - private final Parameter[] parameters; - private final List> parameterGenerators = new ArrayList<>(); - - /** - * Reflects the given type for a single accessible constructor to be used - * to generate values of that type. - * - * @param type the type of objects to be generated - */ - public Ctor(Class type) { - this(singleAccessibleConstructor(type)); - } - - /** - * Uses the given constructor to generate values of the declaring type. - * - * @param ctor the constructor to reflect on to generate constructor - * parameter values - */ - public Ctor(Constructor ctor) { - super(ctor.getDeclaringClass()); - - this.ctor = ctor; - this.parameters = ctor.getParameters(); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); - - final ClassId classId = classIdForType(ctor.getDeclaringClass()); - final List argumentTypes = Arrays.stream(ctor.getParameterTypes()) - .map(UtModelFactoryKt::classIdForType) - .collect(Collectors.toList()); - - final ExecutableId constructorId = new ConstructorId(classId, argumentTypes); - - final int generatedModelId = modelConstructor.computeUnusedIdAndUpdate(); - - final List args = arguments(random, status); - final UtAssembleModel generatedModel = new UtAssembleModel( - generatedModelId, - classId, - constructorId.getName() + "#" + generatedModelId, - new UtExecutableCallModel(null, constructorId, args), - null, - (a) -> List.of() - ); - - return generatedModel; - } - - @Override public void provide(Generators provided) { - super.provide(provided); - - parameterGenerators.clear(); - for (Parameter each : parameters) { - parameterGenerators.add(gen().parameter(each)); - } - } - - @Override public void configure(AnnotatedType annotatedType) { - super.configure(annotatedType); - - for (int i = 0; i < parameters.length; ++i) { - parameterGenerators.get(i) - .configure(parameters[i].getAnnotatedType()); - } - } - - @Override public Ctor copy() { - return new Ctor<>(ctor); - } - - private List arguments( - SourceOfRandomness random, - GenerationStatus status) { - - UtModel[] args = new UtModel[parameters.length]; - - for (int i = 0; i < args.length; ++i) { - args[i] = parameterGenerators.get(i).generate(random, status); - } - - return List.of(args); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java index 71ff1e4f5b..f4bac88b4a 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java @@ -1,46 +1,11 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - import java.math.BigDecimal; -import java.util.ArrayList; import java.util.List; -import java.util.function.Function; import java.util.function.Predicate; -import java.util.stream.Stream; -import static org.utbot.quickcheck.internal.Sequences.halvingDecimal; -import static org.utbot.quickcheck.internal.Sequences.halvingIntegral; -import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; -import static java.util.stream.Collectors.toList; -import static java.util.stream.StreamSupport.stream; /** * Base class for generators of decimal types, such as {@code double} and @@ -58,98 +23,10 @@ protected DecimalGenerator(List> types) { super(types); } - @Override public List doShrink( - SourceOfRandomness random, - T largestGeneric) { - - if (largestGeneric.equals(leastMagnitude())) - return emptyList(); - - // We work with BigDecimal, so convert all inputs - BigDecimal largest = widen().apply(largestGeneric); - BigDecimal least = widen().apply(leastMagnitude()); - - List results = new ArrayList<>(); - - // Positive numbers are considered easier than negative ones - if (negative(largestGeneric)) - results.add(negate(largestGeneric)); - - // Try your luck by testing the smallest possible value - results.add(leastMagnitude()); - - // Try values between smallest and largest, with smaller and smaller - // increments as we approach the largest - - // Integrals are considered easier than decimals - results.addAll(shrunkenIntegrals(largest, least)); - results.addAll(shrunkenDecimals(largest, least)); - - return results; - } - - private List shrunkenIntegrals(BigDecimal largest, BigDecimal least) { - return decimalsFrom( - stream( - halvingIntegral( - largest.toBigInteger(), - least.toBigInteger()) - .spliterator(), - false) - .map(BigDecimal::new)); - } - - private List shrunkenDecimals(BigDecimal largest, BigDecimal least) { - return decimalsFrom( - stream( - halvingDecimal(largest, least).spliterator(), - false)); - } - - private List decimalsFrom(Stream stream) { - return stream.limit(15) - .map(narrow()) - .filter(inRange()) - .distinct() - .collect(toList()); - } - - /** - * @return a function converting a value of the base type into a - * {@link BigDecimal} - */ - protected abstract Function widen(); - - /** - * @return a function converting a {@link BigDecimal} into the equivalent - * value in the base type - */ - protected abstract Function narrow(); - /** * @return a predicate checking whether its input is in the configured * range */ protected abstract Predicate inRange(); - /** - * @return the lowest magnitude number, respecting the configured range. - * The ideal shrink value is always this value (i.e. this value cannot - * be shrunk any further). - */ - protected abstract T leastMagnitude(); - - /** - * @return whether the given number is negative or not - */ - protected abstract boolean negative(T target); - - /** - * Used when shrinking negative numbers to add the positive equivalent - * value at the top of shrinks list. - * - * @param target always a negative number - * @return the positive equivalent to target - */ - protected abstract T negate(T target); } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java index f64a7e1e8b..e41b6e58c0 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java @@ -1,33 +1,7 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.GeneratorConfiguration; -import org.utbot.quickcheck.generator.Size; - import java.lang.annotation.Retention; import java.lang.annotation.Target; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Fields.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Fields.java deleted file mode 100644 index f4e32289b4..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Fields.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.generator; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtNullModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.reflect.AnnotatedType; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.List; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.*; -import static java.util.stream.Collectors.toList; - -/** - *

Produces instances of a class by reflecting the class's fields and - * generating random values for them.

- * - *

All fields of the class and its class hierarchy are auto-generated.

- * - *

In order for this generator to work, the type it is given must have an - * accessible zero-arg constructor.

- * - *

If a field is marked with an annotation that influences the generation of - * a given kind of value, that annotation will be applied to the generation of - * values for that field.

- * - *

This generator is intended to be used with - * {@link org.utbot.quickcheck.From}, and not to be available via the - * {@link java.util.ServiceLoader} mechanism.

- * - * @param the type of objects generated - */ -public class Fields extends org.utbot.quickcheck.generator.Generator { - private final List fields; - private final List> fieldGenerators = new ArrayList<>(); - - /** - * @param type the type of objects to be generated - */ - public Fields(Class type) { - super(type); - - this.fields = - allDeclaredFieldsOf(type).stream() - .filter(f -> !Modifier.isFinal(f.getModifiers())) - .collect(toList()); - - instantiate(type); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - Class type = types().get(0); - Object generated = instantiate(type); - - for (int i = 0; i < fields.size(); i++) { - setField( - fields.get(i), - generated, - fieldGenerators.get(i).generate(random, status), - true); - } - - //return UtModelGenerator.getUtModelConstructor().construct(type.cast(generated),); - return new UtNullModel(classIdForType(type)); - } - - @Override public void provide(Generators provided) { - super.provide(provided); - - fieldGenerators.clear(); - for (Field each : fields) { - fieldGenerators.add(gen().field(each)); - } - } - - @Override public void configure(AnnotatedType annotatedType) { - super.configure(annotatedType); - - for (int i = 0; i < fields.size(); ++i) { - fieldGenerators.get(i).configure( - fields.get(i).getAnnotatedType()); - } - } - - @Override public Generator copy() { - return new Fields<>(types().get(0)); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java index 1ac1ae84d0..eef5c5a9d5 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java @@ -1,27 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator; @@ -47,202 +23,4 @@ public interface Gen { * @return the generated value */ UtModel generate(SourceOfRandomness random, GenerationStatus status); - -// /** -// * Gives a generation strategy that produces a random value by having this -// * strategy produce a random value, then applying the given function to -// * that value, and returning the result. -// * -// * @param type of values produced by the mapped generation strategy -// * @param mapper function that converts receiver's random values to -// * result's values -// * @return a new generation strategy -// */ -// default Gen map(Function mapper) { -// return (random, status) -> mapper.apply(_gen(random, status)); -// } -// -// /** -// * Gives a generation strategy that produces a random value by having this -// * strategy produce a random value, then applying the given function to -// * that value, and asking the result to produce a value. -// * -// * @param type of values produced by the mapped generation strategy -// * @param mapper function that converts receiver's random values to -// * another kind of generation strategy -// * @return a new generation strategy -// */ -// default Gen flatMap( -// Function> mapper) { -// -// return (random, status) -> -// mapper.apply(_gen(random, status))._gen(random, status); -// } -// -// /** -// * Gives a generation strategy that produces a random value by having this -// * strategy produce random values until one satisfies the given condition, -// * then using that value as the result. -// * -// * @param condition a condition the generated value is to meet -// * @return a new generation strategy -// */ -// default Gen filter(Predicate condition) { -// return (random, status) -> { -// T next = _gen(random, status); -// while (!condition.test(next)) { -// next = _gen(random, status); -// } -// return next; -// }; -// } -// -// /** -// *

Gives a generation strategy that produces a random value by having -// * this strategy produce a random value and wrapping it in an -// * {@link Optional}; if the value meets the given condition, the wrapping -// * optional will be {@linkplain Optional#isPresent() present}.

-// * -// *

If the value meets the condition but is {@code null}, the wrapping -// * optional will not be considered -// * {@linkplain Optional#isPresent() present}.

-// * -// * @param condition a condition the generated value is to meet -// * @return a new generation strategy -// */ -// default Gen> filterOptional(Predicate condition) { -// return (random, status) -> { -// T next = _gen(random, status); -// return condition.test(next) -// ? Optional.ofNullable(next) -// : Optional.empty(); -// }; -// } -// -// default Gen> times(int times) { -// if (times < 0) -// throw new IllegalArgumentException("negative times: " + times); -// -// return (random, status) -> { -// List values = new ArrayList<>(); -// for (int i = 0; i < times; ++i) { -// values.add(_gen(random, status)); -// } -// return values; -// }; -// } -// -// /** -// * Gives a generation strategy that produces the given value, always. -// * -// * @param type of values produced by the resulting strategy -// * @param constant the value to be returned by the resulting strategy -// * @return a new generation strategy -// */ -// static Gen pure(U constant) { -// return (random, status) -> constant; -// } -// -// /** -// * Gives a generation strategy that produces a random value by choosing -// * one of the given values at random with (approximately) equal -// * probability. -// * -// * @param type of values produced by the resulting strategy -// * @param first first possible choice -// * @param rest the other possible choices -// * @return a new generation strategy -// */ -// @SafeVarargs static Gen oneOf(U first, U... rest) { -// List choices = new ArrayList<>(); -// choices.add(first); -// Collections.addAll(choices, rest); -// -// return (random, status) -> Items.choose(choices, random); -// } -// -// /** -// * Gives a generation strategy that produces a random value by choosing -// * one of the given generators at random with (approximately) equal -// * probability, and having it generate a value. -// * -// * @param type of values produced by the resulting strategy -// * @param first first possible generator choice -// * @param rest the other possible generator choices -// * @return a new generation strategy -// */ -// @SafeVarargs static Gen oneOf( -// Gen first, -// Gen... rest) { -// -// List> choices = new ArrayList<>(); -// choices.add(first); -// Collections.addAll(choices, rest); -// -// return (random, status) -> -// Items.choose(choices, random)._gen(random, status); -// } -// -// /** -// * Gives a generation strategy that produces a random value by choosing -// * one of the given generators at random with probability in proportion -// * to their given weights, and having it generate a value. -// * -// * @param type of values produced by the resulting strategy -// * @param first first possible (weighted) generator choice -// * @param rest the other possible (weighted) generator choices -// * @return a new generation strategy -// */ -// @SafeVarargs static Gen frequency( -// Pair> first, -// Pair>... rest) { -// -// List>> pairs = new ArrayList<>(); -// pairs.add(first); -// Collections.addAll(pairs, rest); -// -// List>> weighted = -// pairs.stream() -// .map(p -> new Weighted>(p.second, p.first)) -// .collect(toList()); -// -// return (random, status) -> -// Items.chooseWeighted(weighted, random)._gen(random, status); -// } -// -// /** -// * Helper for making a weighted generator indicator for -// * {@link #frequency(Pair, Pair[])}. -// * -// * @param type of values produced by the given generation strategy -// * @param weight an integer weight -// * @param generator a generator -// * @return a weight-generator pair -// */ -// static Pair> freq( -// int weight, -// Gen generator) { -// -// return new Pair<>(weight, generator); -// } -// -// /** -// * @deprecated For use by junit-quickcheck only -- when we migrate to Java -// * 9 or better, this method will likely become {@code private}. -// * -// * @param random source of randomness to be used when generating the value -// * @param status an object that can be used to influence the generated -// * value. For example, generating lists can use the {@link -// * GenerationStatus#size() size} method to generate lists with a given -// * number of elements. -// * @return the generated value -// */ -// @Deprecated -// default T _gen(SourceOfRandomness random, GenerationStatus status) { -// T result = generate(random, status); -// -// status.semiAttempt(); -// -// return result; -// } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java index 4668fff487..735536ea90 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java @@ -1,35 +1,7 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.Generator; - -import java.util.Objects; -import java.util.Optional; - /** * {@link Generator}s are fed instances of this interface on each generation * so that, if they choose, they can use these instances to influence the @@ -48,76 +20,4 @@ public interface GenerationStatus { */ int attempts(); - /** - *

Signals part of an attempt to generate a value.

- * - *

Mostly for use by junit-quickcheck itself; generators can call this - * to convince the framework that it's doing work to generate a complex - * value, but doing so is not strictly necessary.

- */ - default void semiAttempt() { - } - - /** - * Associates the given value with the given key for the duration of the - * generation of a value for a property parameter, or until overwritten. - * - * @param type of the value - * @param key a key to associate with a value - * @param value the associated value - * @return self, so that calls to this method can be chained - */ - GenerationStatus setValue(Key key, T value); - - /** - * Retrieves the value associated with the given key. - * - * @param type of the value associated with the key - * @param key key to look up - * @return the (optional) associated value - */ - Optional valueOf(Key key); - - /** - * Type-safe keys for {@link GenerationStatus#setValue(Key, Object) - * setValue} and {@link GenerationStatus#valueOf(Key) valueOf}. - * - * @param type of value that can be associated with the key - */ - final class Key { - private final String name; - private final Class type; - - public Key(String name, Class type) { - if (name == null) - throw new NullPointerException("name must not be null"); - if (type == null) - throw new NullPointerException("type must not be null"); - - this.name = name; - this.type = type; - } - - public T cast(Object o) { - return type.cast(o); - } - - @Override public boolean equals(Object o) { - if (o == this) - return true; - if (!(o instanceof Key)) - return false; - - Key other = (Key) o; - return name.equals(other.name) && type.equals(other.type); - } - - @Override public int hashCode() { - return Objects.hash(name, type); - } - - @Override public String toString() { - return name + ": " + type; - } - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java index f612425d5f..23fca1c56b 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator; @@ -35,14 +12,12 @@ a copy of this software and associated documentation files (the import java.lang.reflect.AnnotatedElement; import java.lang.reflect.AnnotatedType; import java.lang.reflect.Method; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; -import static java.math.BigDecimal.ONE; import static java.util.Collections.*; import static java.util.stream.Collectors.toList; import static org.utbot.quickcheck.internal.Reflection.*; @@ -52,7 +27,7 @@ a copy of this software and associated documentation files (the * * @param type of property parameter to apply this generator's values to */ -public abstract class Generator implements Gen, Shrink { +public abstract class Generator implements Gen { private final List> types = new ArrayList<>(); private Generators repo; @@ -97,86 +72,6 @@ public boolean canRegisterAsType(Class type) { return true; } - /** - * {@inheritDoc} - * - *

Generators first ensure that they {@linkplain #canShrink(Object) can - * participate} in shrinking the given value, and if so, they - * {@linkplain #doShrink(SourceOfRandomness, Object) produce shrinks}.

- */ - @Override public final List shrink(SourceOfRandomness random, Object larger) { - if (!canShrink(larger)) { - throw new IllegalStateException( - getClass() + " not capable of shrinking " + larger); - } - - return doShrink(random, narrow(larger)); - } - - /** - *

Tells whether this generator is allowed to participate in the - * {@link Shrink} process for the given "larger" value.

- * - *

Unless overridden, the only criterion for whether a generator is - * allowed to participate in shrinking a value is if the value can be - * safely cast to the type of values the generator produces.

- * - * @param larger the "larger" value - * @return whether this generator can participate in "shrinking" the larger - * value - */ - public boolean canShrink(Object larger) { - return types().get(0).isInstance(larger); - } - - /** - *

Gives some objects that are "smaller" than a given "larger" - * object.

- * - *

Unless overridden, a generator will produce an empty list of - * "smaller" values.

- * - * @param random source of randomness to use in shrinking, if desired - * @param larger the larger object - * @return objects that are "smaller" than the larger object. Smaller objects should be provided before bigger objects to make shrinking process faster. - */ - public List doShrink(SourceOfRandomness random, T larger) { - return emptyList(); - } - - /** - *

Gives a hint to the shrinking process as to the magnitude of the given - * value. The shrinking process will prefer trying values of greater - * magnitude before values of lesser magnitude. If not overridden, this - * implementation returns "one".

- * - *

Note to generator writers: Do not worry about normalizing - * a magnitude to a positive value; the shrinking mechanism will take care - * of it.

- * - * @see #narrow(Object) - * @param value the value to assess - * @return a measure of the given value's magnitude - */ - public BigDecimal magnitude(Object value) { - return ONE; - } - - /** - *

Attempts to "narrow" the given object to the type this generator - * produces.

- * - *

This is intended for use only by junit-quickcheck itself, and not by - * creators of custom generators.

- * - * @param wider target of the narrowing - * @return narrowed the result of the narrowing - * @throws ClassCastException if the narrowing cannot be performed - */ - protected final T narrow(Object wider) { - return types().get(0).cast(wider); - } - /** *

This is intended for use only by junit-quickcheck itself, and not by * creators of custom generators.

diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java index 1e311ec3a5..845af79cc8 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java @@ -1,32 +1,6 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.Generator; - import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.Target; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java index f03ba5d629..8ce0b01b4f 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java @@ -1,32 +1,6 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.Generator; - /** * Raised if a problem arises when attempting to configure a generator with * annotations from a property parameter. diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java index 965e566d5d..9bf54af2bd 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java @@ -1,32 +1,5 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.random.SourceOfRandomness; import java.lang.reflect.Field; @@ -36,87 +9,6 @@ a copy of this software and associated documentation files (the * An access point for available generators. */ public interface Generators { - /** - *

Gives a generator that can produce instances of one of a given set of - * related types on every generation.

- * - *

On each generation, one of the available generators that can produce - * one of the named types will be chosen with (approximately) equal - * probability.

- * - * @param type of objects produced by the resulting generator - * @param first first type of generated value - * @param rest other (related) types of generated values - * @return generator that can produce values of the given types - */ - Generator oneOf( - Class first, - Class... rest); - - /** - *

Gives a generator that can produce instances of one of a given set of - * related types on every generation.

- * - *

On each generation, one of the given generators will be called upon - * with (approximately) equal probability.

- * - * @param type of objects produced by the resulting generator - * @param first first generator - * @param rest other generators - * @return generator that can produce values using the given generators - */ - Generator oneOf( - Generator first, - Generator... rest); - - /** - *

Gives a generator that can produce an instance of the type described - * by the field with the given name and containing type.

- * - *

If the field is marked with an annotation that influences the - * generation of a given kind of value, that annotation will be applied to - * the resulting generator's values.

- * - * @param type containing type for a field - * @param fieldName name of a field - * @return generator that can produce values of the field's type - */ - Generator field(Class type, String fieldName); - - /** - *

Gives a generator that can produce an instance of the type described - * by a constructor of a given type that accepts the given types of - * arguments. It will generate values for the parameters of the given - * constructor, and then invoke the constructor.

- * - *

If the constructor's parameters are marked with annotations that - * influence the generation of a given kind of value, those annotations - * will be applied to the generators that will produce values to be used - * as arguments to the constructor.

- * - * @param type of objects produced by the resulting generator - * @param type containing type for a constructor - * @param argumentTypes types of arguments to the constructor - * @return generator that can produce values using the constructor - */ - Generator constructor(Class type, Class... argumentTypes); - - /** - *

Gives a generator that can produce an instance of the given type - * by reflecting the class's fields on up its class hierarchy and - * generating random values for them.

- * - *

The given type must have an accessible zero-arg constructor.

- * - *

If a field of the given type is marked with an annotation that - * influences the generation of a given kind of value, that annotation - * will be applied to the generation of values for that field.

- * - * @param type of objects produced by the resulting generator - * @param type a type - * @return generator that can produce values of that type - */ - Generator fieldsOf(Class type); /** *

Gives a generator that can produce values of the given type, @@ -156,24 +48,6 @@ Generator oneOf( */ Generator field(Field field); - /** - *

Makes a new generator of the given type, provides it with access to - * other available generators, - * {@linkplain Generator#configure(java.lang.reflect.AnnotatedType) - * configures} it with any configuration annotations present on the - * generator type, and supplies it any - * {@linkplain Generator#hasComponents() component generators} it needs. - * - * @param type of objects produced by the resulting generator - * @param genType type of generator to create - * @param componentGenerators any generators for components of the type - * @return a generator for producing values - * @see ComponentizedGenerator - */ - > T make( - Class genType, - Generator... componentGenerators); - /** *

Makes a generator access point just like the receiver, but which * uses the given source of randomness for making random choices.

diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java index b503f2c074..7a6245255d 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java @@ -1,32 +1,5 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.GeneratorConfiguration; - import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -34,7 +7,7 @@ a copy of this software and associated documentation files (the import static java.lang.annotation.RetentionPolicy.RUNTIME; /** - *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + *

Mark a parameter of a * method with this annotation to constrain the values generated for the * parameter to a given range.

* diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java index b4767edd72..7f5c27e2fe 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java @@ -1,44 +1,10 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - import java.math.BigInteger; -import java.util.ArrayList; import java.util.List; -import java.util.function.Function; import java.util.function.Predicate; -import static org.utbot.quickcheck.internal.Sequences.halvingIntegral; -import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; -import static java.util.stream.Collectors.toList; -import static java.util.stream.StreamSupport.stream; /** * Base class for generators of integral types, such as {@code int} and @@ -58,76 +24,10 @@ protected IntegralGenerator(List> types) { super(types); } - @Override public List doShrink(SourceOfRandomness random, T larger) { - if (larger.equals(leastMagnitude())) - return emptyList(); - - List results =new ArrayList<>(); - - // Positive numbers are considered easier than negative ones - if (negative(larger)) - results.add(negate(larger)); - - // Try your luck by testing the smallest possible value - results.add(leastMagnitude()); - - // Try values between smallest and largest, with smaller and smaller - // increments as we approach the largest - results.addAll( - stream( - halvingIntegral( - // We work with BigInteger, so convert all inputs - widen().apply(larger), - widen().apply(leastMagnitude()) - ).spliterator(), - false) - .limit(15) - .map(narrow()) - .filter(inRange()) - .distinct() - .collect(toList())); - - return results; - } - - /** - * @return a function converting a value of the base type into a - * {@link BigInteger} - */ - protected Function widen() { - return n -> BigInteger.valueOf(n.longValue()); - } - - /** - * @return a function converting a {@link BigInteger} into the equivalent - * value in the base type - */ - protected abstract Function narrow(); - /** * @return a predicate checking whether its input is in the configured * range */ protected abstract Predicate inRange(); - /** - * @return the lowest magnitude number, respecting the configured range. - * The ideal shrink value is always this value (i.e. this value cannot - * be shrunk any further). - */ - protected abstract T leastMagnitude(); - - /** - * @return whether the given number is negative or not - */ - protected abstract boolean negative(T target); - - /** - * Used when shrinking negative numbers to add the positive equivalent - * value at the top of shrinks list. - * - * @param target always a negative number - * @return the positive equivalent to target - */ - protected abstract T negate(T target); } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java index cfe86c946c..a4bd81bfb1 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java @@ -1,32 +1,5 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.internal.DefaultMethodHandleMaker; import org.utbot.quickcheck.internal.GeometricDistribution; import org.utbot.quickcheck.internal.generator.SimpleGenerationStatus; @@ -38,9 +11,9 @@ a copy of this software and associated documentation files (the import java.util.Arrays; import java.util.Random; -import static org.utbot.quickcheck.internal.Reflection.singleAbstractMethodOf; import static java.lang.System.identityHashCode; import static java.lang.reflect.Proxy.newProxyInstance; +import static org.utbot.quickcheck.internal.Reflection.singleAbstractMethodOf; /** * Helper class for creating instances of "functional interfaces". diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Only.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Only.java deleted file mode 100644 index c9bf61dabe..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Only.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.generator; - -import org.utbot.quickcheck.Property; -import org.utbot.quickcheck.conversion.StringConversion; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -/** - *

Mark a parameter of a {@link Property} method with this annotation to - * limit the set of values of that parameter used to test the property.

- * - *

In {@linkplain org.utbot.quickcheck.Mode#SAMPLING sampling} - * mode, on each trial junit-quickcheck chooses a value from the limited set - * at random with equal probability. - * - *

In {@linkplain org.utbot.quickcheck.Mode#EXHAUSTIVE exhaustive} - * mode, junit-quickcheck will use the values in the limited set for the - * property parameter, and no others.

- * - *

Note: When a parameter is marked with this annotation, - * junit-quickcheck doesn't call upon any generators. Thus, it ignores any - * generator configuration annotations present on the parameter.

- */ -@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) -@Retention(RUNTIME) -public @interface Only { - /** - * @return the values to which the property parameter should be limited - */ - String[] value(); - - /** - *

How to convert the values in {@link #value()} into instances of the - * property parameter's type.

- * - *

If not specified, junit-quickcheck employs the following strategies - * for value conversion for the marked parameter:

- *
    - *
  • If present, use a {@code public static} method on the property - * parameter type called {@code valueOf} which accepts a single - * {@code String} argument and whose return type is the type itself.
  • - *
  • Otherwise, if present, use a {@code public} constructor on the - * property parameter type which accepts a single {@code String} - * argument.
  • - *
- * - * @return a type for a value conversion strategy - */ - Class by() default StringConversion.class; -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java index 0ebb4f74a1..01ffd4d044 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java @@ -1,32 +1,5 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.GeneratorConfiguration; - import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -34,7 +7,7 @@ a copy of this software and associated documentation files (the import static java.lang.annotation.RetentionPolicy.RUNTIME; /** - *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + *

Mark a parameter of a * method with this annotation to constrain the values generated for the * parameter to a given precision.

*/ diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Shrink.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Shrink.java deleted file mode 100644 index c6b783b38c..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Shrink.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.generator; - -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.List; - -/** - * Represents a strategy for producing objects "smaller than" a given object. - * - * @param type of shrunken objects produced - */ -@FunctionalInterface -public interface Shrink { - /** - * Gives some objects that are "smaller" than a given object. - * - * @param random source of randomness to use in shrinking, if desired - * @param larger the larger object - * @return objects that are "smaller" than the larger object - */ - List shrink(SourceOfRandomness random, Object larger); -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java index fced0b8e00..de93e110ad 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java @@ -1,32 +1,5 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator; -import org.utbot.quickcheck.generator.GeneratorConfiguration; - import java.lang.annotation.Retention; import java.lang.annotation.Target; @@ -34,7 +7,7 @@ a copy of this software and associated documentation files (the import static java.lang.annotation.RetentionPolicy.RUNTIME; /** - *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + *

Mark a parameter of a * method with this annotation to constrain the size of values generated for * the parameter.

* diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java index b26b3f0d47..4e99370a77 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java @@ -1,34 +1,7 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator; import org.utbot.framework.plugin.api.UtModel; import org.utbot.framework.plugin.api.UtNullModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.random.SourceOfRandomness; import static java.util.Arrays.asList; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java index bc0511c0e6..ec597b25f2 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java @@ -1,47 +1,12 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator.java.lang; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.GenerationStatus; import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.internal.Lists; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - import static org.utbot.framework.plugin.api.util.IdUtilKt.getStringClassId; -import static org.utbot.quickcheck.internal.Lists.shrinksOfOneItem; -import static org.utbot.quickcheck.internal.Sequences.halving; -import static java.util.stream.Collectors.toList; -import static java.util.stream.StreamSupport.stream; /** *

Base class for generators of values of type {@link String}.

@@ -69,55 +34,6 @@ public String generateValue( SourceOfRandomness random, return new String(codePoints, 0, codePoints.length); } - @Override public boolean canShrink(Object larger) { - return super.canShrink(larger) && codePointsInRange((String) larger); - } - - @Override public List doShrink( - SourceOfRandomness random, - String larger) { - - List codePoints = - larger.codePoints().boxed().collect(toList()); - List shrinks = new ArrayList<>(removals(codePoints)); - - List> oneItemShrinks = - shrinksOfOneItem( - random, - codePoints, - new org.utbot.quickcheck.generator.java.lang.CodePointShrink(this::codePointInRange)); - shrinks.addAll( - oneItemShrinks.stream() - .map(this::convert) - .filter(this::codePointsInRange) - .collect(toList())); - - return shrinks; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value).length()); - } - protected abstract int nextCodePoint(SourceOfRandomness random); - protected abstract boolean codePointInRange(int codePoint); - - private boolean codePointsInRange(String s) { - return s.codePoints().allMatch(this::codePointInRange); - } - - private List removals(List codePoints) { - return stream(halving(codePoints.size()).spliterator(), false) - .map(i -> Lists.removeFrom(codePoints, i)) - .flatMap(Collection::stream) - .map(this::convert) - .collect(toList()); - } - - private String convert(List codePoints) { - StringBuilder s = new StringBuilder(); - codePoints.forEach(s::appendCodePoint); - return s.toString(); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java index 6232d5233e..eb5542a3b0 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java @@ -1,27 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -31,13 +7,6 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.util.List; - -import static java.math.BigDecimal.ONE; -import static java.math.BigDecimal.ZERO; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.utbot.framework.plugin.api.util.IdUtilKt.getBooleanWrapperClassId; @@ -56,14 +25,4 @@ public BooleanGenerator() { return UtModelGenerator.getUtModelConstructor().construct(random.nextBoolean(), getBooleanWrapperClassId()); } - @Override public List doShrink( - SourceOfRandomness random, - Boolean larger) { - - return larger ? singletonList(false) : emptyList(); - } - - @Override public BigDecimal magnitude(Object value) { - return narrow(value) ? ONE : ZERO; - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java index bf3bbe8f0f..66857a36cf 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,15 +10,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code byte} or {@link Byte}. @@ -81,27 +54,8 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(random.nextByte(min, max), classIdForType(Byte.class)); } - @Override protected Function narrow() { - return BigInteger::byteValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Byte leastMagnitude() { - return Comparables.leastMagnitude(min, max, (byte) 0); - } - - @Override protected boolean negative(Byte target) { - return target < 0; - } - - @Override protected Byte negate(Byte target) { - return (byte) -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java index 9af11c314d..df46a2cd4e 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java @@ -1,27 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -30,17 +6,12 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.generator.GenerationStatus; import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; import java.util.Collections; -import java.util.List; import static org.utbot.framework.plugin.api.util.IdUtilKt.getCharWrapperClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toList; /** * Produces values of type {@code char} or {@link Character}. @@ -74,23 +45,4 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(random.nextChar(min, max), getCharWrapperClassId()); } - @Override public List doShrink( - SourceOfRandomness random, - Character larger) { - - return new org.utbot.quickcheck.generator.java.lang.CodePointShrink(cp -> cp >= min && cp <= max) - .shrink(random, (int) larger) - .stream() - .map((Integer cp) -> (char) cp.intValue()) - .filter(this::inRange) - .collect(toList()); - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } - - private boolean inRange(Character value) { - return Comparables.inRange(min, max).test(value); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CodePointShrink.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CodePointShrink.java deleted file mode 100644 index af8df1237f..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CodePointShrink.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.quickcheck.generator.Shrink; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.function.Function; -import java.util.function.Predicate; - -import static java.lang.Character.isUpperCase; -import static java.util.Collections.addAll; -import static java.util.Collections.reverse; -import static java.util.Comparator.comparing; -import static java.util.Comparator.naturalOrder; -import static java.util.stream.Collectors.toList; - -class CodePointShrink implements Shrink { - private final Predicate filter; - - CodePointShrink(Predicate filter) { - this.filter = filter; - } - - @Override public List shrink( - SourceOfRandomness random, - Object larger) { - - int codePoint = (Integer) larger; - - List shrinks = new ArrayList<>(); - addAll(shrinks, (int) 'a', (int) 'b', (int) 'c'); - if (isUpperCase(codePoint)) - shrinks.add(Character.toLowerCase(codePoint)); - addAll( - shrinks, - (int) 'A', (int) 'B', (int) 'C', (int) '1', (int) '2', (int) '3', - (int) ' ', (int) '\n'); - reverse(shrinks); - - Comparator comparator = - comparing((Function) Character::isLowerCase) - .thenComparing( - (Function) Character::isUpperCase) - .thenComparing( - (Function) Character::isDigit) - .thenComparing(cp -> Integer.valueOf(' ').equals(cp)) - .thenComparing( - (Function) Character::isSpaceChar) - .thenComparing(naturalOrder()); - return shrinks.stream() - .filter(filter) - .filter(cp -> comparator.compare(cp, codePoint) < 0) - .distinct() - .collect(toList()); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java index 193a5748b6..8107e401de 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java @@ -1,27 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,14 +9,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getDoubleWrapperClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values for property parameters of type {@code double} or @@ -87,31 +60,8 @@ public double generateValue(SourceOfRandomness random, return random.nextDouble(min, max); } - @Override protected Function widen() { - return BigDecimal::valueOf; - } - - @Override protected Function narrow() { - return BigDecimal::doubleValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Double leastMagnitude() { - return Comparables.leastMagnitude(min, max, 0D); - } - - @Override protected boolean negative(Double target) { - return target < 0; - } - - @Override protected Double negate(Double target) { - return -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java index de4ea749b3..d002986a5c 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java @@ -1,32 +1,8 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; import org.utbot.quickcheck.generator.GeneratorConfiguration; -import org.utbot.quickcheck.generator.java.lang.AbstractStringGenerator; import org.utbot.quickcheck.generator.java.lang.strings.CodePoints; import org.utbot.quickcheck.random.SourceOfRandomness; @@ -67,10 +43,6 @@ private void initialize(Charset charset) { return charsetPoints.at(random.nextInt(0, charsetPoints.size() - 1)); } - @Override protected boolean codePointInRange(int codePoint) { - return charsetPoints.contains(codePoint); - } - /** * Names a {@link Charset}. */ diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java index 5bdf96bd4b..01a497d14c 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java @@ -1,28 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator.java.lang; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -33,13 +8,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.util.function.Function; +import java.util.Collections; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getFloatWrapperClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code float} or {@link Float}. @@ -49,7 +22,7 @@ public class FloatGenerator extends DecimalGenerator { private float max = (Float) defaultValueOf(InRange.class, "maxFloat"); public FloatGenerator() { - super(asList(Float.class)); + super(Collections.singletonList(Float.class)); } /** @@ -79,31 +52,8 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(random.nextFloat(min, max), getFloatWrapperClassId()); } - @Override protected Function widen() { - return BigDecimal::valueOf; - } - - @Override protected Function narrow() { - return BigDecimal::floatValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Float leastMagnitude() { - return Comparables.leastMagnitude(min, max, 0F); - } - - @Override protected boolean negative(Float target) { - return target < 0; - } - - @Override protected Float negate(Float target) { - return -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java index a52daeb769..7deef84004 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java @@ -1,27 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,15 +9,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getIntWrapperClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code int} or {@link Integer}. @@ -85,27 +57,8 @@ public int generateValue(SourceOfRandomness random, return random.nextInt(min, max); } - @Override protected Function narrow() { - return BigInteger::intValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Integer leastMagnitude() { - return Comparables.leastMagnitude(min, max, 0); - } - - @Override protected boolean negative(Integer target) { - return target < 0; - } - - @Override protected Integer negate(Integer target) { - return -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java index f3cbeab966..26717f3345 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java @@ -1,28 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator.java.lang; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -33,15 +8,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getLongWrapperClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code long} or {@link Long}. @@ -86,27 +57,8 @@ public long generateValue(SourceOfRandomness random, return random.nextLong(min, max); } - @Override protected Function narrow() { - return BigInteger::longValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Long leastMagnitude() { - return Comparables.leastMagnitude(min, max, 0L); - } - - @Override protected boolean negative(Long target) { - return target < 0; - } - - @Override protected Long negate(Long target) { - return -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java index 8841df9bf0..744bd363d8 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java @@ -1,27 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -31,13 +7,6 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.util.List; - -import static java.math.BigDecimal.ONE; -import static java.math.BigDecimal.ZERO; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.utbot.framework.plugin.api.util.IdUtilKt.getBooleanClassId; @@ -56,14 +25,4 @@ public PrimitiveBooleanGenerator() { return UtModelGenerator.getUtModelConstructor().construct(random.nextBoolean(), getBooleanClassId()); } - @Override public List doShrink( - SourceOfRandomness random, - Boolean larger) { - - return larger ? singletonList(false) : emptyList(); - } - - @Override public BigDecimal magnitude(Object value) { - return narrow(value) ? ONE : ZERO; - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java index f6c6dda6f2..ddf7392865 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java @@ -1,27 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,15 +9,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getByteClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code byte} or {@link Byte}. @@ -81,27 +53,8 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(random.nextByte(min, max), getByteClassId()); } - @Override protected Function narrow() { - return BigInteger::byteValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Byte leastMagnitude() { - return Comparables.leastMagnitude(min, max, (byte) 0); - } - - @Override protected boolean negative(Byte target) { - return target < 0; - } - - @Override protected Byte negate(Byte target) { - return (byte) -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java index 98cc15a85a..678cf229b0 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java @@ -1,28 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - package org.utbot.quickcheck.generator.java.lang; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -33,14 +8,10 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; import java.util.Collections; -import java.util.List; import static org.utbot.framework.plugin.api.util.IdUtilKt.getCharClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toList; /** * Produces values of type {@code char} or {@link Character}. @@ -74,22 +45,6 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(random.nextChar(min, max), getCharClassId()); } - @Override public List doShrink( - SourceOfRandomness random, - Character larger) { - - return new org.utbot.quickcheck.generator.java.lang.CodePointShrink(cp -> cp >= min && cp <= max) - .shrink(random, (int) larger) - .stream() - .map((Integer cp) -> (char) cp.intValue()) - .filter(this::inRange) - .collect(toList()); - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } - private boolean inRange(Character value) { return Comparables.inRange(min, max).test(value); } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java index 9b1deec5c9..d4e9241c87 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java @@ -1,27 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,14 +9,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getDoubleClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values for property parameters of type {@code double} or @@ -87,31 +60,8 @@ public double generateValue(SourceOfRandomness random, return random.nextDouble(min, max); } - @Override protected Function widen() { - return BigDecimal::valueOf; - } - - @Override protected Function narrow() { - return BigDecimal::doubleValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Double leastMagnitude() { - return Comparables.leastMagnitude(min, max, 0D); - } - - @Override protected boolean negative(Double target) { - return target < 0; - } - - @Override protected Double negate(Double target) { - return -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java index 9462188547..a861668d85 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,14 +10,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getFloatClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code float} or {@link Float}. @@ -80,31 +54,8 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(random.nextFloat(min, max), getFloatClassId()); } - @Override protected Function widen() { - return BigDecimal::valueOf; - } - - @Override protected Function narrow() { - return BigDecimal::floatValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Float leastMagnitude() { - return Comparables.leastMagnitude(min, max, 0F); - } - - @Override protected boolean negative(Float target) { - return target < 0; - } - - @Override protected Float negate(Float target) { - return -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java index 2e36e77eeb..49de2f9945 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,15 +10,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getIntClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code int} or {@link Integer}. @@ -85,27 +58,8 @@ public int generateValue(SourceOfRandomness random, return random.nextInt(min, max); } - @Override protected Function narrow() { - return BigInteger::intValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Integer leastMagnitude() { - return Comparables.leastMagnitude(min, max, 0); - } - - @Override protected boolean negative(Integer target) { - return target < 0; - } - - @Override protected Integer negate(Integer target) { - return -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java index 026a717ea4..c28fd95ee3 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,15 +10,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getLongClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code long} or {@link Long}. @@ -86,27 +59,8 @@ public long generateValue(SourceOfRandomness random, return random.nextLong(min, max); } - @Override protected Function narrow() { - return BigInteger::longValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Long leastMagnitude() { - return Comparables.leastMagnitude(min, max, 0L); - } - - @Override protected boolean negative(Long target) { - return target < 0; - } - - @Override protected Long negate(Long target) { - return -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java index e886a03e06..9a5cea74ba 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,15 +10,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getShortClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code short} or {@link Short}. @@ -81,27 +54,8 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(random.nextShort(min, max), getShortClassId()); } - @Override protected Function narrow() { - return BigInteger::shortValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Short leastMagnitude() { - return Comparables.leastMagnitude(min, max, (short) 0); - } - - @Override protected boolean negative(Short target) { - return target < 0; - } - - @Override protected Short negate(Short target) { - return (short) -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java index e47c69a2a8..a721cc2d49 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; @@ -33,15 +10,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Comparables; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.math.BigInteger; import java.util.Collections; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.framework.plugin.api.util.IdUtilKt.getShortWrapperClassId; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.util.Arrays.asList; /** * Produces values of type {@code short} or {@link Short}. @@ -81,27 +54,8 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(random.nextShort(min, max), getShortWrapperClassId()); } - @Override protected Function narrow() { - return BigInteger::shortValue; - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected Short leastMagnitude() { - return Comparables.leastMagnitude(min, max, (short) 0); - } - - @Override protected boolean negative(Short target) { - return target < 0; - } - - @Override protected Short negate(Short target) { - return (short) -target; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java index a71d01dd2d..c011c0dd13 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java @@ -1,31 +1,7 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.lang; -import org.utbot.quickcheck.generator.java.lang.AbstractStringGenerator; import org.utbot.quickcheck.random.SourceOfRandomness; /** @@ -37,7 +13,4 @@ public class StringGenerator extends AbstractStringGenerator { return random.nextInt(0, Character.MIN_SURROGATE - 1); } - @Override protected boolean codePointInRange(int codePoint) { - return codePoint >= 0 && codePoint < Character.MIN_SURROGATE; - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java index e1e87c6674..9d2b8dfbd2 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.lang.strings; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java index 038652e846..1c78e25065 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.math; @@ -37,7 +14,6 @@ a copy of this software and associated documentation files (the import java.math.BigDecimal; import java.math.BigInteger; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; @@ -45,8 +21,6 @@ a copy of this software and associated documentation files (the import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; import static java.lang.Math.max; import static java.math.BigDecimal.TEN; -import static java.math.BigDecimal.ZERO; -import static java.util.function.Function.identity; /** *

Produces values of type {@link BigDecimal}.

@@ -153,38 +127,9 @@ private int decideScale() { return max(scale, 0); } - @Override - protected Function widen() { - return identity(); - } - - @Override - protected Function narrow() { - return identity(); - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override - protected BigDecimal leastMagnitude() { - return Comparables.leastMagnitude(min, max, ZERO); - } - - @Override - protected boolean negative(BigDecimal target) { - return target.signum() < 0; - } - - @Override - protected BigDecimal negate(BigDecimal target) { - return target.negate(); - } - - @Override - public BigDecimal magnitude(Object value) { - return narrow(value); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java index b9ad104f8c..f682d5014c 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.math; @@ -34,17 +11,13 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.Ranges; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; import java.math.BigInteger; -import java.util.function.Function; import java.util.function.Predicate; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; import static org.utbot.quickcheck.internal.Ranges.checkRange; import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; import static java.math.BigInteger.TEN; -import static java.math.BigInteger.ZERO; -import static java.util.function.Function.identity; /** *

Produces values of type {@link BigInteger}.

@@ -101,27 +74,8 @@ else if (maxToUse == null) return UtModelGenerator.getUtModelConstructor().construct(Ranges.choose(random, minToUse, maxToUse), classIdForType(BigInteger.class)); } - @Override protected Function narrow() { - return identity(); - } - @Override protected Predicate inRange() { return Comparables.inRange(min, max); } - @Override protected BigInteger leastMagnitude() { - return Comparables.leastMagnitude(min, max, ZERO); - } - - @Override protected boolean negative(BigInteger target) { - return target.signum() < 0; - } - - @Override protected BigInteger negate(BigInteger target) { - return target.negate(); - } - - @Override public BigDecimal magnitude(Object value) { - return new BigDecimal(narrow(value)); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java index 8525796a48..4ed1444ad4 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.nio.charset; @@ -35,8 +12,6 @@ a copy of this software and associated documentation files (the import java.lang.reflect.Method; import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Collection; import java.util.List; import static java.nio.charset.Charset.availableCharsets; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java index 404548d412..985ea9100c 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.time; @@ -38,7 +15,6 @@ a copy of this software and associated documentation files (the import java.time.Clock; import java.time.Instant; import java.time.ZoneId; -import java.util.ArrayList; import java.util.List; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java index 93c861126c..226be4efe2 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java index 1bc4285643..eab3ee052d 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java index bd03487e1d..3fea491b2f 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java index f41d4e03f9..ae0272a792 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java index 85f9e561eb..7fd58018d4 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java index c906345170..4e11b564eb 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java index aa2fef9393..afd0ee789f 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java index 8768ec4da1..eefc83d0cd 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java index 70b741bd55..388f7b157b 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java index 7b8a043475..194ab340e8 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java index 8ae4870667..e211782600 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java index eba2bfcd9e..ca7b66d6ac 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java index 12f8172272..05ed4ab2f5 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java index 2033f8a3bc..97b5e78b71 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.time; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java index 7b946bead3..cd84d09d93 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java @@ -1,31 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.ListGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java index 38d981273f..b9b22d25d8 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java @@ -1,44 +1,15 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.GenerationStatus; import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.util.ArrayList; import java.util.BitSet; -import java.util.List; -import static java.util.Collections.emptyList; -import static java.util.stream.Collectors.toList; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; /** @@ -63,31 +34,4 @@ public BitSetGenerator() { return UtModelGenerator.getUtModelConstructor().construct(bits, classIdForType(BitSet.class)); } - @Override public List doShrink( - SourceOfRandomness random, - BitSet larger) { - - if (larger.length() == 0) - return emptyList(); - - List shrinks = new ArrayList<>(); - shrinks.addAll( - larger.stream() - .mapToObj(i -> larger.get(0, i)) - .collect(toList())); - shrinks.addAll( - larger.stream() - .mapToObj(i -> { - BitSet smaller = (BitSet) larger.clone(); - smaller.clear(i); - return smaller; - }) - .collect(toList())); - - return shrinks; - } - - @Override public BigDecimal magnitude(Object value) { - return BigDecimal.valueOf(narrow(value).size()); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java index fe5375f810..e6875e9d78 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.util; @@ -31,29 +8,16 @@ a copy of this software and associated documentation files (the import org.utbot.framework.plugin.api.util.IdUtilKt; import org.utbot.quickcheck.generator.*; -import org.utbot.quickcheck.internal.Lists; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.lang.reflect.Constructor; import java.lang.reflect.Method; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.stream.Stream; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; -import static org.utbot.quickcheck.internal.Lists.removeFrom; -import static org.utbot.quickcheck.internal.Lists.shrinksOfOneItem; import static org.utbot.quickcheck.internal.Ranges.Type.INTEGRAL; import static org.utbot.quickcheck.internal.Ranges.checkRange; -import static org.utbot.quickcheck.internal.Reflection.findConstructor; -import static org.utbot.quickcheck.internal.Reflection.instantiate; -import static org.utbot.quickcheck.internal.Sequences.halving; -import static java.math.BigDecimal.ZERO; -import static java.util.stream.Collectors.toList; -import static java.util.stream.StreamSupport.stream; /** *

Base class for generators of {@link Collection}s.

@@ -105,7 +69,6 @@ protected final void setDistinct(boolean distinct) { this.distinct = distinct; } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, @@ -152,80 +115,15 @@ public UtModel generate( return collectionAssembleModel; } - @Override - public List doShrink(SourceOfRandomness random, T larger) { - @SuppressWarnings("unchecked") - List asList = new ArrayList<>(larger); - - List shrinks = new ArrayList<>(removals(asList)); - - @SuppressWarnings("unchecked") - Shrink generator = - (Shrink) componentGenerators().get(0); - - Stream> oneItemShrinks = - shrinksOfOneItem(random, asList, generator) - .stream(); - if (distinct) - oneItemShrinks = oneItemShrinks.filter(Lists::isDistinct); - - shrinks.addAll( - oneItemShrinks - .map(this::convert) - .filter(this::inSizeRange) - .collect(toList())); - - return shrinks; - } - @Override public int numberOfNeededComponents() { return 1; } - @Override - public BigDecimal magnitude(Object value) { - Collection narrowed = narrow(value); - - if (narrowed.isEmpty()) - return ZERO; - - BigDecimal elementsMagnitude = - narrowed.stream() - .map(e -> componentGenerators().get(0).magnitude(e)) - .reduce(ZERO, BigDecimal::add); - return BigDecimal.valueOf(narrowed.size()).multiply(elementsMagnitude); - } - - protected final T empty() { - return instantiate(findConstructor(types().get(0))); - } - - private boolean inSizeRange(T items) { - return sizeRange == null - || (items.size() >= sizeRange.min() - && items.size() <= sizeRange.max()); - } - private int size(SourceOfRandomness random, GenerationStatus status) { return sizeRange != null ? random.nextInt(sizeRange.min(), sizeRange.max()) : status.size(); } - private List removals(List items) { - return stream(halving(items.size()).spliterator(), false) - .map(i -> removeFrom(items, i)) - .flatMap(Collection::stream) - .map(this::convert) - .filter(this::inSizeRange) - .collect(toList()); - } - - @SuppressWarnings("unchecked") - private T convert(List items) { - T converted = empty(); - converted.addAll(items); - return converted; - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java index 830c00bb0f..3f59edcd75 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java @@ -1,52 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java index 8b7ecc873b..6b4bdc3448 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.MapGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java index 62c045407c..fb23f3cdb4 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.SetGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java index b8d1852167..e7a798bf0e 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.MapGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java index 182881ecca..2ae83b4bf8 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.MapGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java index 3d829c1c21..b61f776ac7 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.SetGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java index c15c30064d..33eebfa64f 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.ListGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java index 05a96d9f17..c5267bfc0c 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.CollectionGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java index edf7114257..812fb10fdf 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.util; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java index 84964abcc8..14dd5024d1 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; @@ -29,27 +6,17 @@ a copy of this software and associated documentation files (the import org.utbot.framework.concrete.UtModelConstructor; import org.utbot.framework.plugin.api.*; import org.utbot.quickcheck.generator.*; -import org.utbot.quickcheck.internal.Lists; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.util.AbstractMap.SimpleEntry; import java.util.*; -import java.util.Map.Entry; -import java.util.stream.Stream; -import static java.util.stream.Collectors.toList; -import static java.util.stream.StreamSupport.stream; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; -import static org.utbot.quickcheck.internal.Lists.removeFrom; -import static org.utbot.quickcheck.internal.Lists.shrinksOfOneItem; import static org.utbot.quickcheck.internal.Ranges.Type.INTEGRAL; import static org.utbot.quickcheck.internal.Ranges.checkRange; import static org.utbot.quickcheck.internal.Reflection.findConstructor; import static org.utbot.quickcheck.internal.Reflection.instantiate; -import static org.utbot.quickcheck.internal.Sequences.halving; /** *

Base class for generators of {@link Map}s.

@@ -97,7 +64,6 @@ public void configure(Distinct distinct) { this.distinct = distinct != null; } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { @@ -139,123 +105,18 @@ public void configure(Distinct distinct) { return generatedModel; } - @Override public List doShrink(SourceOfRandomness random, T larger) { - @SuppressWarnings("unchecked") - List> entries = new ArrayList<>(larger.entrySet()); - - List shrinks = new ArrayList<>(removals(entries)); - - @SuppressWarnings("unchecked") - Shrink> entryShrink = entryShrinker( - (Shrink) componentGenerators().get(0), - (Shrink) componentGenerators().get(1)); - - Stream>> oneEntryShrinks = - shrinksOfOneItem(random, entries, entryShrink) - .stream(); - if (distinct) - oneEntryShrinks = oneEntryShrinks.filter(MapGenerator::isKeyDistinct); - - shrinks.addAll( - oneEntryShrinks - .map(this::convert) - .filter(this::inSizeRange) - .collect(toList())); - - return shrinks; - } - @Override public int numberOfNeededComponents() { return 2; } - @Override public BigDecimal magnitude(Object value) { - Map narrowed = narrow(value); - - if (narrowed.isEmpty()) - return BigDecimal.ZERO; - - BigDecimal keysMagnitude = - narrowed.keySet().stream() - .map(e -> componentGenerators().get(0).magnitude(e)) - .reduce(BigDecimal.ZERO, BigDecimal::add); - BigDecimal valuesMagnitude = - narrowed.values().stream() - .map(e -> componentGenerators().get(1).magnitude(e)) - .reduce(BigDecimal.ZERO, BigDecimal::add); - return BigDecimal.valueOf(narrowed.size()) - .multiply(keysMagnitude) - .add(valuesMagnitude); - } - - protected final T empty() { - return instantiate(findConstructor(types().get(0))); - } - protected boolean okToAdd(Object key, Object value) { return true; } - private boolean inSizeRange(T target) { - return sizeRange == null - || (target.size() >= sizeRange.min() && target.size() <= sizeRange.max()); - } - private int size(SourceOfRandomness random, GenerationStatus status) { return sizeRange != null ? random.nextInt(sizeRange.min(), sizeRange.max()) : status.size(); } - private List removals(List> items) { - return stream(halving(items.size()).spliterator(), false) - .map(i -> removeFrom(items, i)) - .flatMap(Collection::stream) - .map(this::convert) - .filter(this::inSizeRange) - .collect(toList()); - } - - @SuppressWarnings("unchecked") - private T convert(List entries) { - T converted = empty(); - - for (Object each : entries) { - Entry entry = (Entry) each; - converted.put(entry.getKey(), entry.getValue()); - } - - return converted; - } - - private Shrink> entryShrinker( - Shrink keyShrinker, - Shrink valueShrinker) { - - return (r, e) -> { - @SuppressWarnings("unchecked") - Entry entry = (Entry) e; - - List keyShrinks = keyShrinker.shrink(r, entry.getKey()); - List valueShrinks = valueShrinker.shrink(r, entry.getValue()); - List> shrinks = new ArrayList<>(); - shrinks.addAll( - keyShrinks.stream() - .map(k -> new SimpleEntry<>(k, entry.getValue())) - .collect(toList())); - shrinks.addAll( - valueShrinks.stream() - .map(v -> new SimpleEntry<>(entry.getKey(), v)) - .collect(toList())); - - return shrinks; - }; - } - - private static boolean isKeyDistinct(List> entries) { - return Lists.isDistinct( - entries.stream() - .map(Entry::getKey) - .collect(toList())); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java index 0f9488ea9d..4c7b4ddb3f 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java @@ -1,46 +1,17 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtNullModel; import org.utbot.quickcheck.generator.GenerationStatus; import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.generator.InRange; import org.utbot.quickcheck.generator.java.lang.DoubleGenerator; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; import java.util.OptionalDouble; -import static java.math.BigDecimal.ZERO; -import static java.util.stream.Collectors.toList; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; /** @@ -80,28 +51,4 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(generated, classIdForType(OptionalDouble.class)); } - @Override public List doShrink( - SourceOfRandomness random, - OptionalDouble larger) { - - if (!larger.isPresent()) - return new ArrayList<>(); - - List shrinks = new ArrayList<>(); - shrinks.add(OptionalDouble.empty()); - shrinks.addAll( - doubles.shrink(random, larger.getAsDouble()) - .stream() - .map(OptionalDouble::of) - .collect(toList())); - return shrinks; - } - - @Override public BigDecimal magnitude(Object value) { - OptionalDouble narrowed = narrow(value); - - return narrowed.isPresent() - ? doubles.magnitude(narrowed.getAsDouble()) - : ZERO; - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java index 3b1729cc8e..0b20932d44 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -30,16 +7,11 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.generator.ComponentizedGenerator; import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.util.ArrayList; import java.util.List; import java.util.Optional; -import static java.math.BigDecimal.ZERO; -import static java.util.stream.Collectors.toList; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; @@ -78,32 +50,8 @@ public OptionalGenerator() { ); } - @Override public List doShrink( - SourceOfRandomness random, - Optional larger) { - - if (!larger.isPresent()) - return new ArrayList<>(); - - List shrinks = new ArrayList<>(); - shrinks.add(Optional.empty()); - shrinks.addAll( - componentGenerators().get(0) - .shrink(random, larger.get()) - .stream() - .map(Optional::of) - .collect(toList())); - return shrinks; - } - @Override public int numberOfNeededComponents() { return 1; } - @Override public BigDecimal magnitude(Object value) { - Optional narrowed = narrow(value); - - return narrowed.map(componentGenerators().get(0)::magnitude) - .orElse(ZERO); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java index 77ce377a3c..15dd4bcd2f 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java @@ -1,47 +1,17 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtNullModel; import org.utbot.quickcheck.generator.GenerationStatus; import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.generator.InRange; import org.utbot.quickcheck.generator.java.lang.IntegerGenerator; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; -import java.util.OptionalDouble; import java.util.OptionalInt; -import static java.math.BigDecimal.ZERO; -import static java.util.stream.Collectors.toList; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; /** @@ -80,28 +50,4 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(generated, classIdForType(OptionalInt.class)); } - @Override public List doShrink( - SourceOfRandomness random, - OptionalInt larger) { - - if (!larger.isPresent()) - return new ArrayList<>(); - - List shrinks = new ArrayList<>(); - shrinks.add(OptionalInt.empty()); - shrinks.addAll( - integers.shrink(random, larger.getAsInt()) - .stream() - .map(OptionalInt::of) - .collect(toList())); - return shrinks; - } - - @Override public BigDecimal magnitude(Object value) { - OptionalInt narrowed = narrow(value); - - return narrowed.isPresent() - ? BigDecimal.valueOf(narrowed.getAsInt()) - : ZERO; - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java index 69f8b62448..5682f74f6e 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java @@ -1,44 +1,17 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtNullModel; import org.utbot.quickcheck.generator.GenerationStatus; import org.utbot.quickcheck.generator.Generator; import org.utbot.quickcheck.generator.InRange; import org.utbot.quickcheck.generator.java.lang.LongGenerator; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; import java.util.*; -import static java.math.BigDecimal.ZERO; -import static java.util.stream.Collectors.toList; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; /** @@ -77,28 +50,4 @@ public void configure(InRange range) { return UtModelGenerator.getUtModelConstructor().construct(generated, classIdForType(OptionalLong.class)); } - @Override public List doShrink( - SourceOfRandomness random, - OptionalLong larger) { - - if (!larger.isPresent()) - return new ArrayList<>(); - - List shrinks = new ArrayList<>(); - shrinks.add(OptionalLong.empty()); - shrinks.addAll( - longs.shrink(random, larger.getAsLong()) - .stream() - .map(OptionalLong::of) - .collect(toList())); - return shrinks; - } - - @Override public BigDecimal magnitude(Object value) { - OptionalLong narrowed = narrow(value); - - return narrowed.isPresent() - ? BigDecimal.valueOf(narrowed.getAsLong()) - : ZERO; - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java index 96d777c7b2..c9c8a1eab6 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java @@ -1,29 +1,6 @@ package org.utbot.quickcheck.generator.java.util; -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -37,10 +14,8 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.generator.java.lang.StringGenerator; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.math.BigDecimal; import java.util.*; -import static java.math.BigDecimal.ZERO; import static java.util.Arrays.asList; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; @@ -108,22 +83,4 @@ public UtModel generate( return !exclusions.contains(type); } - @Override public BigDecimal magnitude(Object value) { - Properties narrowed = narrow(value); - - if (narrowed.isEmpty()) - return ZERO; - - BigDecimal keysMagnitude = - narrowed.keySet().stream() - .map(e -> stringGenerator.magnitude(e)) - .reduce(ZERO, BigDecimal::add); - BigDecimal valuesMagnitude = - narrowed.values().stream() - .map(e -> stringGenerator.magnitude(e)) - .reduce(ZERO, BigDecimal::add); - return BigDecimal.valueOf(narrowed.size()) - .multiply(keysMagnitude) - .add(valuesMagnitude); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java index 1e43b04f55..b8d2a7bec4 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.util; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -40,7 +17,6 @@ a copy of this software and associated documentation files (the import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; -import java.util.Properties; import java.util.UUID; import static java.lang.annotation.ElementType.*; @@ -166,8 +142,8 @@ public static class Version4 extends AbstractUUIDGenerator { byte[] bytes = random.nextBytes(16); setVersion(bytes, (byte) 0x40); setVariant(bytes); - //return newUUID(bytes); - return new UtNullModel(classIdForType(UUID.class)); + final UUID generatedUUID = newUUID(bytes); + return UtModelGenerator.getUtModelConstructor().construct(generatedUUID, classIdForType(UUID.class)); } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java index e82e4f1212..6a05b67408 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.Size; import org.utbot.quickcheck.generator.java.util.CollectionGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java index 53c82828c7..cc7fe219bc 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.ListGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java index f0e67f5ddb..7ac9ef719e 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.util; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java index e530987906..376051f73f 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java @@ -1,30 +1,6 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.java.util.ListGenerator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java index 677a618ecc..75dc9392c4 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.util.concurrent; @@ -46,7 +23,6 @@ public CallableGenerator() { super(Callable.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java index 38c61da0db..b0d5935548 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -50,7 +27,6 @@ public BiFunctionGenerator() { super(BiFunction.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java index ea10fca834..884eed26e9 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -59,7 +36,6 @@ public BiPredicateGenerator() { generator = gen().type(boolean.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java index 0ea1e3f7b6..dd4a6e91dc 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -48,7 +25,6 @@ public BinaryOperatorGenerator() { super(BinaryOperator.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java index 2539e6c237..48dbcea56d 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -48,7 +25,6 @@ public DoubleFunctionGenerator() { super(DoubleFunction.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java index 17ef355d7d..caf71bec88 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -47,7 +24,6 @@ public FunctionGenerator() { super(Function.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java index 202199d58d..cd150361df 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java @@ -1,31 +1,7 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.ComponentizedGenerator; @@ -49,7 +25,6 @@ public IntFunctionGenerator() { super(IntFunction.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java index 2dc3b9c815..39f7e476c1 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -48,7 +25,6 @@ public LongFunctionGenerator() { super(LongFunction.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java index 2c7e747467..7dbfae02b6 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -56,7 +33,6 @@ public PredicateGenerator() { generator = gen().type(boolean.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java index ce0809f2bd..7ea6b20f30 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -46,7 +23,6 @@ public SupplierGenerator() { super(Supplier.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java index ddeffe0bea..1ee1fc7ff3 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -59,7 +36,6 @@ public ToDoubleBiFunctionGenerator() { generator = gen().type(double.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java index e742ef755e..fcc3bcf326 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -58,7 +35,6 @@ public ToDoubleFunctionGenerator() { generator = gen().type(double.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java index 97accf0e3e..6c34d374d3 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java @@ -1,31 +1,7 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.ComponentizedGenerator; @@ -60,7 +36,6 @@ public ToIntBiFunctionGenerator() { generator = gen().type(int.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java index 7605a9b149..f0790134b3 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -58,7 +35,6 @@ public ToIntFunctionGenerator() { generator = gen().type(int.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java index 3958edf8d4..33fa9d8264 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java @@ -1,31 +1,7 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; import org.utbot.framework.plugin.api.UtModel; import org.utbot.quickcheck.generator.ComponentizedGenerator; @@ -60,7 +36,6 @@ public ToLongBiFunctionGenerator() { generator = gen().type(long.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java index 5e81c40094..fd17b25029 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -33,7 +10,6 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.generator.Generators; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.util.function.ToLongBiFunction; import java.util.function.ToLongFunction; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; @@ -60,7 +36,6 @@ public void provide(Generators provided) { generator = gen().type(long.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java index 1c8a4a0191..ea61a9a7cc 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.generator.java.util.function; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; @@ -48,7 +25,6 @@ public UnaryOperatorGenerator() { super(UnaryOperator.class); } - @SuppressWarnings("unchecked") @Override public UtModel generate( SourceOfRandomness random, GenerationStatus status) { diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/hook/NilMinimalCounterexampleHook.java b/utbot-framework/src/main/java/org/utbot/quickcheck/hook/NilMinimalCounterexampleHook.java deleted file mode 100644 index 9a17b5946e..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/hook/NilMinimalCounterexampleHook.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.hook; - -import org.utbot.quickcheck.MinimalCounterexampleHook; - -/** - * Counterexample hook that does nothing. - */ -public class NilMinimalCounterexampleHook - implements MinimalCounterexampleHook { - - @Override public void handle(Object[] counterexample, Runnable action) { - // do nothing purposely - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/CartesianIterator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/CartesianIterator.java deleted file mode 100644 index d6e91c087f..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/CartesianIterator.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import static java.util.stream.Collectors.toList; - -public class CartesianIterator implements Iterator> { - private final List> buffers; - private final boolean allStartedAvailable; - - private int count; - - public CartesianIterator(List> sources) { - this.buffers = - sources.stream() - .map(s -> new Buffer<>(s, new ArrayList<>())) - .collect(toList()); - allStartedAvailable = sources.stream().allMatch(Iterator::hasNext); - } - - @Override public boolean hasNext() { - return allStartedAvailable - && buffers.stream().anyMatch(Buffer::available); - } - - @Override public List next() { - List result = new ArrayList<>(); - int n = count; - - for (Buffer each : buffers) { - int divisor = each.divisor(); - - result.add(each.get(n)); - - n /= divisor; - } - - ++count; - return result; - } - - private static class Buffer { - private final Iterator source; - private final List consumed; - private int index; - - Buffer(Iterator source, List consumed) { - this.source = source; - this.consumed = consumed; - } - - boolean available() { - return source.hasNext() || index < consumed.size() - 1; - } - - int divisor() { - return source.hasNext() ? consumed.size() + 1 : consumed.size(); - } - - T get(int n) { - index = n % divisor(); - if (index == consumed.size()) { - consumed.add(source.next()); - } - - return consumed.get(index); - } - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java index 6ce54c7eaa..4db8182c04 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.internal; @@ -45,31 +22,4 @@ Predicate inRange(T min, T max) { }; } - /** - * @return the value with the lowest magnitude between the min, max and zero. - *
    - *
  • [-10, 5] = 0
  • - *
  • [-10, -5] = -5
  • - *
  • [5, 10] = 5
  • - *
  • [-5, 0] = 0
  • - *
  • [0, 5] = 0
  • - *
- */ - public static > - T leastMagnitude(T min, T max, T zero) { - if (min == null && max == null) - return zero; - - if (min == null) - return max.compareTo(zero) <= 0 ? max : zero; - if (max == null) - return min.compareTo(zero) >= 0 ? min : zero; - - if (min.compareTo(zero) > 0) - return min; - if (max.compareTo(zero) < 0) - return max; - - return zero; - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java index 5acfa88ef6..bee540a624 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java index 1184d6ab7d..47212e9031 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java index b7a3d0b214..78d39b568d 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java @@ -1,31 +1,7 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.internal; -import org.utbot.quickcheck.internal.Weighted; import org.utbot.quickcheck.random.SourceOfRandomness; import java.util.Collection; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Lists.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Lists.java deleted file mode 100644 index f684b3150f..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Lists.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal; - -import org.utbot.quickcheck.generator.Shrink; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; -import static java.util.stream.Collectors.toList; - -public final class Lists { - private Lists() { - throw new UnsupportedOperationException(); - } - - public static List> removeFrom(List target, int howMany) { - if (howMany < 0) { - throw new IllegalArgumentException( - "Can't remove " + howMany + " elements from a list"); - } - if (howMany == 0) - return singletonList(target); - if (howMany > target.size()) - return emptyList(); - - List left = target.subList(0, howMany); - List right = target.subList(howMany, target.size()); - if (right.isEmpty()) - return singletonList(emptyList()); - - List> removals = new ArrayList<>(); - removals.add(right); - removals.addAll(removeFrom(right, howMany) - .stream() - .map(r -> { - List items = new ArrayList<>(left); - items.addAll(r); - return items; - }) - .collect(toList())); - return removals; - } - - public static List> shrinksOfOneItem( - SourceOfRandomness random, - List target, - Shrink shrink) { - - if (target.isEmpty()) - return new ArrayList<>(); - - T head = target.get(0); - List tail = target.subList(1, target.size()); - - List> shrinks = new ArrayList<>(); - shrinks.addAll( - shrink.shrink(random, head) - .stream() - .map(i -> { - List items = new ArrayList<>(); - items.add(i); - items.addAll(tail); - return items; - }) - .collect(toList())); - shrinks.addAll( - shrinksOfOneItem(random, tail, shrink) - .stream() - .map(s -> { - List items = new ArrayList<>(); - items.add(head); - items.addAll(s); - return items; - }) - .collect(toList())); - - return shrinks; - } - - public static boolean isDistinct(List target) { - return new HashSet<>(target).size() == target.size(); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterSampler.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterSampler.java deleted file mode 100644 index ad2735ae6e..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterSampler.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal; - -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.internal.ParameterTypeContext; -import org.utbot.quickcheck.internal.SeededValue; -import org.utbot.quickcheck.internal.generator.GeneratorRepository; -import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; - -import java.util.List; -import java.util.stream.Stream; - -public interface ParameterSampler { - int sizeFactor(org.utbot.quickcheck.internal.ParameterTypeContext p); - - Stream> sample( - List parameters); - - default Generator decideGenerator( - GeneratorRepository repository, - ParameterTypeContext p) { - - return repository.produceGenerator(p); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java index 31aca8dc41..f95cf5a3a1 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java @@ -1,38 +1,10 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal; -import org.utbot.quickcheck.From; -import org.utbot.quickcheck.Produced; +import org.javaruntype.type.*; import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.internal.ReflectionException; -import org.utbot.quickcheck.internal.Weighted; -import org.utbot.quickcheck.internal.Zilch; import org.utbot.quickcheck.random.SourceOfRandomness; -import org.javaruntype.type.*; import ru.vyarus.java.generics.resolver.GenericsResolver; import ru.vyarus.java.generics.resolver.context.ConstructorGenericsContext; import ru.vyarus.java.generics.resolver.context.GenericsContext; @@ -40,17 +12,19 @@ a copy of this software and associated documentation files (the import java.lang.reflect.Type; import java.lang.reflect.*; -import java.util.*; +import java.util.ArrayDeque; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; -import static org.utbot.quickcheck.internal.Items.choose; -import static org.utbot.quickcheck.internal.Reflection.*; -import static java.lang.String.format; import static java.util.Collections.unmodifiableList; import static org.javaruntype.type.Types.arrayComponentOf; +import static org.utbot.quickcheck.internal.Items.choose; +import static org.utbot.quickcheck.internal.Reflection.*; public class ParameterTypeContext { private static final String EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE = - "The generator %s named in @%s on parameter %s does not produce a type-compatible object"; + "The generator %s named in @%s on parameter %s does not produce a type-compatible object"; private static org.utbot.quickcheck.internal.Zilch zilch; private final String parameterName; @@ -64,56 +38,31 @@ public class ParameterTypeContext { private AnnotatedElement annotatedElement; private boolean allowMixedTypes; - public String getDeclarerName() { - return declarerName; - } - public GenericsContext getGenerics() { return generics; } - public org.javaruntype.type.Type getResolved() { return resolved; } - public static ParameterTypeContext forClass(Class clazz) { return new ParameterTypeContext( - clazz.getTypeName(), - org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(clazz), - clazz.getTypeName(), - Types.forJavaLangReflectType(clazz), - GenericsResolver.resolve(clazz)); - } - - public static ParameterTypeContext forType(Type type) { - return forType(type, null); - } - - public static ParameterTypeContext forType(Type type, GenericsContext generics) { - GenericsContext gctx; - if (generics == null) { - gctx = GenericsResolver.resolve(type.getClass()); - } else { - gctx = generics; - } - return new ParameterTypeContext( - type.getTypeName(), - org.utbot.quickcheck.internal.FakeAnnotatedTypeFactoryWithType.makeFrom(type), - type.getTypeName(), - Types.forJavaLangReflectType(type), - gctx); + clazz.getTypeName(), + org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(clazz), + clazz.getTypeName(), + Types.forJavaLangReflectType(clazz), + GenericsResolver.resolve(clazz)); } public static ParameterTypeContext forField(Field field) { GenericsContext generics = - GenericsResolver.resolve(field.getDeclaringClass()); + GenericsResolver.resolve(field.getDeclaringClass()); return new ParameterTypeContext( - field.getName(), - field.getAnnotatedType(), - field.getDeclaringClass().getName(), - Types.forJavaLangReflectType(generics.resolveFieldType(field)), - generics); + field.getName(), + field.getAnnotatedType(), + field.getDeclaringClass().getName(), + Types.forJavaLangReflectType(generics.resolveFieldType(field)), + generics); } public static ParameterTypeContext forParameter(Parameter parameter) { @@ -128,35 +77,35 @@ public static ParameterTypeContext forParameter(Parameter parameter) { if (exec instanceof Method) { Method method = (Method) exec; MethodGenericsContext methodGenerics = - GenericsResolver.resolve(clazz).method(method); + GenericsResolver.resolve(clazz).method(method); resolved = - Types.forJavaLangReflectType( - methodGenerics.resolveParameterType(parameterIndex)); + Types.forJavaLangReflectType( + methodGenerics.resolveParameterType(parameterIndex)); generics = methodGenerics; } else if (exec instanceof Constructor) { Constructor ctor = (Constructor) exec; ConstructorGenericsContext constructorGenerics = - GenericsResolver.resolve(clazz).constructor(ctor); + GenericsResolver.resolve(clazz).constructor(ctor); resolved = - Types.forJavaLangReflectType( - constructorGenerics.resolveParameterType(parameterIndex)); + Types.forJavaLangReflectType( + constructorGenerics.resolveParameterType(parameterIndex)); generics = constructorGenerics; } else { throw new IllegalStateException("Unrecognized subtype of Executable"); } return new ParameterTypeContext( - parameter.getName(), - parameter.getAnnotatedType(), - declarerName, - resolved, - generics, - parameterIndex); + parameter.getName(), + parameter.getAnnotatedType(), + declarerName, + resolved, + generics, + parameterIndex); } public static ParameterTypeContext forParameter( - Parameter parameter, - MethodGenericsContext generics) { + Parameter parameter, + MethodGenericsContext generics) { Executable exec = parameter.getDeclaringExecutable(); Class clazz = exec.getDeclaringClass(); @@ -164,13 +113,13 @@ public static ParameterTypeContext forParameter( int parameterIndex = parameterIndex(exec, parameter); return new ParameterTypeContext( - parameter.getName(), - parameter.getAnnotatedType(), - declarerName, - Types.forJavaLangReflectType( - generics.resolveParameterType(parameterIndex)), - generics, - parameterIndex); + parameter.getName(), + parameter.getAnnotatedType(), + declarerName, + Types.forJavaLangReflectType( + generics.resolveParameterType(parameterIndex)), + generics, + parameterIndex); } private static int parameterIndex(Executable exec, Parameter parameter) { @@ -181,32 +130,32 @@ private static int parameterIndex(Executable exec, Parameter parameter) { } throw new IllegalStateException( - "Cannot find parameter " + parameter + " on " + exec); + "Cannot find parameter " + parameter + " on " + exec); } public ParameterTypeContext( - String parameterName, - AnnotatedType parameterType, - String declarerName, - org.javaruntype.type.Type resolvedType, - GenericsContext generics) { + String parameterName, + AnnotatedType parameterType, + String declarerName, + org.javaruntype.type.Type resolvedType, + GenericsContext generics) { this( - parameterName, - parameterType, - declarerName, - resolvedType, - generics, - -1); - } - - public ParameterTypeContext( - String parameterName, - AnnotatedType parameterType, - String declarerName, - org.javaruntype.type.Type resolvedType, - GenericsContext generics, - int parameterIndex) { + parameterName, + parameterType, + declarerName, + resolvedType, + generics, + -1); + } + + public ParameterTypeContext( + String parameterName, + AnnotatedType parameterType, + String declarerName, + org.javaruntype.type.Type resolvedType, + GenericsContext generics, + int parameterIndex) { this.parameterName = parameterName; this.parameterType = parameterType; @@ -218,24 +167,6 @@ public ParameterTypeContext( public ParameterTypeContext annotate(AnnotatedElement element) { this.annotatedElement = element; - - List producedGenerators = - allAnnotationsByType(element, Produced.class); - - List generators; - if (producedGenerators.size() == 1) { - generators = Arrays.asList(producedGenerators.get(0).value()); - } else { - generators = allAnnotationsByType(element, From.class); - if (!generators.isEmpty() - && element instanceof AnnotatedWildcardType) { - - throw new IllegalArgumentException( - "Wildcards cannot be marked with @From"); - } - } - - addGenerators(generators); return this; } @@ -257,32 +188,24 @@ public boolean allowMixedTypes() { public ParameterTypeContext methodReturnTypeContext(Method method) { if (!(generics instanceof MethodGenericsContext)) { throw new IllegalStateException( - "invoking methodReturnTypeContext in present of " + generics); + "invoking methodReturnTypeContext in present of " + generics); } MethodGenericsContext testMethodGenerics = - (MethodGenericsContext) generics; + (MethodGenericsContext) generics; MethodGenericsContext argMethodGenerics = - testMethodGenerics.parameterType(parameterIndex).method(method); + testMethodGenerics.parameterType(parameterIndex).method(method); return new ParameterTypeContext( - "return value", - method.getAnnotatedReturnType(), - method.getName(), - Types.forJavaLangReflectType(argMethodGenerics.resolveReturnType()), - argMethodGenerics); - } - - private void addGenerators(List generators) { - for (From each : generators) { - Generator generator = makeGenerator(each.value()); - ensureCorrectType(generator); - explicits.add(new org.utbot.quickcheck.internal.Weighted<>(generator, each.frequency())); - } + "return value", + method.getAnnotatedReturnType(), + method.getName(), + Types.forJavaLangReflectType(argMethodGenerics.resolveReturnType()), + argMethodGenerics); } private Generator makeGenerator( - Class generatorType) { + Class generatorType) { Constructor ctor; @@ -305,21 +228,6 @@ private Class rawParameterType() { return (Class) type(); } - private void ensureCorrectType(Generator generator) { - for (Class each : generator.types()) { - if (!maybeWrap(resolved.getRawClass()) - .isAssignableFrom(maybeWrap(each))) { - - throw new IllegalArgumentException( - format( - EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE, - each, - From.class.getName(), - parameterName)); - } - } - } - public String name() { return declarerName + ':' + parameterName; } @@ -333,12 +241,12 @@ public Type type() { } /** - * @return the annotated program element this context represents - * @see - * this issue * @deprecated This will likely go away when languages whose compilers * and interpreters produce class files that support annotations on type * uses. + * @see + * this issue + * @return the annotated program element this context represents */ @Deprecated public AnnotatedElement annotatedElement() { @@ -346,17 +254,17 @@ public AnnotatedElement annotatedElement() { } /** - * @return the annotated program element this context represents - * @see - * this issue * @deprecated This will likely go away when languages whose compilers * and interpreters produce class files that support annotations on type * uses. + * @see + * this issue + * @return the annotated program element this context represents */ @Deprecated public boolean topLevel() { return annotatedElement instanceof Parameter - || annotatedElement instanceof Field; + || annotatedElement instanceof Field; } public List>> explicitGenerators() { @@ -367,7 +275,6 @@ private void addParameterTypeContextToDeque(ArrayDeque deq if (ptx.resolved.getName().equals(Zilch.class.getName())) return; deque.add(ptx); } - public List getAllSubParameterTypeContexts(SourceOfRandomness sourceOfRandomness) { ArrayList res = new ArrayList<>(); res.add(this); @@ -387,28 +294,27 @@ public List getAllSubParameterTypeContexts(SourceOfRandomn } return res; } - public ParameterTypeContext arrayComponentContext() { @SuppressWarnings("unchecked") org.javaruntype.type.Type component = - arrayComponentOf((org.javaruntype.type.Type) resolved); + arrayComponentOf((org.javaruntype.type.Type) resolved); AnnotatedType annotatedComponent = annotatedArrayComponent(component); return new ParameterTypeContext( - annotatedComponent.getType().getTypeName(), - annotatedComponent, - parameterType.getType().getTypeName(), - component, - generics) - .annotate(annotatedComponent) - .allowMixedTypes(true); + annotatedComponent.getType().getTypeName(), + annotatedComponent, + parameterType.getType().getTypeName(), + component, + generics) + .annotate(annotatedComponent) + .allowMixedTypes(true); } private AnnotatedType annotatedArrayComponent( - org.javaruntype.type.Type component) { + org.javaruntype.type.Type component) { return parameterType instanceof AnnotatedArrayType - ? ((AnnotatedArrayType) parameterType).getAnnotatedGenericComponentType() - : org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(component.getComponentClass()); + ? ((AnnotatedArrayType) parameterType).getAnnotatedGenericComponentType() + : org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(component.getComponentClass()); } public boolean isArray() { @@ -428,19 +334,19 @@ public List> getTypeParameters() { } public List typeParameterContexts( - SourceOfRandomness random) { + SourceOfRandomness random) { List typeParamContexts = new ArrayList<>(); List> typeParameters = getTypeParameters(); List annotatedTypeParameters = - annotatedComponentTypes(annotatedType()); + annotatedComponentTypes(annotatedType()); for (int i = 0; i < typeParameters.size(); ++i) { TypeParameter p = typeParameters.get(i); AnnotatedType a = - annotatedTypeParameters.size() > i - ? annotatedTypeParameters.get(i) - : zilch(); + annotatedTypeParameters.size() > i + ? annotatedTypeParameters.get(i) + : zilch(); if (p instanceof StandardTypeParameter) addStandardTypeParameterContext(typeParamContexts, p, a); @@ -458,76 +364,76 @@ else if (p instanceof ExtendsTypeParameter) } private void addStandardTypeParameterContext( - List typeParameterContexts, - TypeParameter p, - AnnotatedType a) { + List typeParameterContexts, + TypeParameter p, + AnnotatedType a) { typeParameterContexts.add( - new ParameterTypeContext( - p.getType().getName(), - a, - annotatedType().getType().getTypeName(), - p.getType(), - generics) - .allowMixedTypes(!(a instanceof TypeVariable)) - .annotate(a)); + new ParameterTypeContext( + p.getType().getName(), + a, + annotatedType().getType().getTypeName(), + p.getType(), + generics) + .allowMixedTypes(!(a instanceof TypeVariable)) + .annotate(a)); } private void addWildcardTypeParameterContext( - List typeParameterContexts, - AnnotatedType a) { + List typeParameterContexts, + AnnotatedType a) { typeParameterContexts.add( - new ParameterTypeContext( - "Zilch", - a, - annotatedType().getType().getTypeName(), - Types.forJavaLangReflectType(org.utbot.quickcheck.internal.Zilch.class), - GenericsResolver.resolve(Zilch.class)) - .allowMixedTypes(true) - .annotate(a)); + new ParameterTypeContext( + "Zilch", + a, + annotatedType().getType().getTypeName(), + Types.forJavaLangReflectType(org.utbot.quickcheck.internal.Zilch.class), + GenericsResolver.resolve(Zilch.class)) + .allowMixedTypes(true) + .annotate(a)); } private void addExtendsTypeParameterContext( - List typeParameterContexts, - TypeParameter p, - AnnotatedType a) { + List typeParameterContexts, + TypeParameter p, + AnnotatedType a) { typeParameterContexts.add( - new ParameterTypeContext( - p.getType().getName(), - annotatedComponentTypes(a).get(0), - annotatedType().getType().getTypeName(), - p.getType(), - generics) - .allowMixedTypes(false) - .annotate(a)); + new ParameterTypeContext( + p.getType().getName(), + annotatedComponentTypes(a).get(0), + annotatedType().getType().getTypeName(), + p.getType(), + generics) + .allowMixedTypes(false) + .annotate(a)); } private void addSuperTypeParameterContext( - SourceOfRandomness random, - List typeParameterContexts, - TypeParameter p, - AnnotatedType a) { + SourceOfRandomness random, + List typeParameterContexts, + TypeParameter p, + AnnotatedType a) { Set> supertypes = supertypes(p.getType()); org.javaruntype.type.Type choice = choose(supertypes, random); typeParameterContexts.add( - new ParameterTypeContext( - p.getType().getName(), - annotatedComponentTypes(a).get(0), - annotatedType().getType().getTypeName(), - choice, - generics) - .allowMixedTypes(false) - .annotate(a)); + new ParameterTypeContext( + p.getType().getName(), + annotatedComponentTypes(a).get(0), + annotatedType().getType().getTypeName(), + choice, + generics) + .allowMixedTypes(false) + .annotate(a)); } private static AnnotatedType zilch() { try { return ParameterTypeContext.class.getDeclaredField("zilch") - .getAnnotatedType(); + .getAnnotatedType(); } catch (NoSuchFieldException e) { throw new AssertionError(e); } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/PropertyParameterContext.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/PropertyParameterContext.java deleted file mode 100644 index d9d89f0be7..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/PropertyParameterContext.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal; - -import org.utbot.quickcheck.When; -import org.utbot.quickcheck.internal.ParameterTypeContext; - - -import java.lang.reflect.AnnotatedElement; - -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; - -public class PropertyParameterContext { - private static final long DEFAULT_SEED = - (long) defaultValueOf(When.class, "seed"); - - private final ParameterTypeContext typeContext; - - private int discardRatio; - private String constraint; - private long seed = DEFAULT_SEED; - - - public PropertyParameterContext(ParameterTypeContext typeContext) { - this.typeContext = typeContext; - } - - public PropertyParameterContext annotate(AnnotatedElement element) { - When quantifier = element.getAnnotation(When.class); - addQuantifier(quantifier); - addConstraint(quantifier); - typeContext.annotate(element); - - return this; - } - - public PropertyParameterContext addQuantifier(When quantifier) { - if (quantifier != null) { - this.discardRatio = ensurePositiveDiscardRatio(quantifier); - this.seed = quantifier.seed(); - } - - return this; - } - - public PropertyParameterContext addConstraint(When quantifier) { - if (quantifier != null - && !defaultValueOf(When.class, "satisfies") - .equals(quantifier.satisfies())) { - - constraint = quantifier.satisfies(); - } - - return this; - } - - - public ParameterTypeContext typeContext() { - return typeContext; - } - - public int discardRatio() { - return discardRatio; - } - - public String constraint() { - return constraint; - } - - public boolean fixedSeed() { - return seed != DEFAULT_SEED; - } - - public long seed() { - return seed; - } - - private int ensurePositiveDiscardRatio(When quantifier) { - if (quantifier.discardRatio() <= 0) { - throw new IllegalArgumentException( - "Non-positive discard ratio for parameter " + typeContext.name() - + " of type " + typeContext.type().getTypeName()); - } - - return quantifier.discardRatio(); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java index cd74806c38..355719468e 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java index 661531db5b..5c3cd6cfad 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java @@ -1,31 +1,6 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -package org.utbot.quickcheck.internal; -import org.utbot.quickcheck.internal.ReflectionException; +package org.utbot.quickcheck.internal; import org.javaruntype.type.Type; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java index aedce2b0d1..9eea362d3d 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.internal; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/SeededValue.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/SeededValue.java deleted file mode 100644 index 5e5363f9cc..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/SeededValue.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal; - -import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; - - -public final class SeededValue { - private final PropertyParameterGenerationContext p; - private final Object value; - private final long seed; - - - public SeededValue(PropertyParameterGenerationContext p) { - this.p = p; - this.value = p.generate(); - this.seed = p.effectiveSeed(); - } - - - public PropertyParameterGenerationContext parameter() { - return p; - } - - public Object value() { - return value; - } - - public long seed() { - return seed; - } - - @Override public String toString() { - return String.format("%s = [%s], seed = %d", p.name(), value, seed); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Sequences.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Sequences.java deleted file mode 100644 index 348cc72c7d..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Sequences.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.Iterator; -import java.util.NoSuchElementException; - -import static java.math.RoundingMode.HALF_UP; - -public final class Sequences { - private Sequences() { - throw new UnsupportedOperationException(); - } - - public static Iterable halvingIntegral( - BigInteger max, - BigInteger start) { - - return () -> new BigIntegerHalvingIterator(start, max); - } - - public static Iterable halvingDecimal( - BigDecimal max, - BigDecimal start) { - - return () -> new BigDecimalHalvingIterator(start, max); - } - - public static Iterable halving(int start) { - return () -> new IntegerHalvingIterator(start); - } - - private static final class BigIntegerHalvingIterator - implements Iterator { - - private final BigInteger max; - - private boolean done; - private BigInteger next; - - BigIntegerHalvingIterator(BigInteger start, BigInteger max) { - this.max = max; - next = start; - } - - @Override public boolean hasNext() { - return !done; - } - - @Override public BigInteger next() { - if (!hasNext()) - throw new NoSuchElementException(); - - next = peek(); - done = next.equals(peek()); - return next; - } - - private BigInteger peek() { - return next.add( - max.subtract(next) - .divide(BigInteger.valueOf(2))); - } - } - - private static final class BigDecimalHalvingIterator - implements Iterator { - - private final BigDecimal max; - - private boolean done; - private BigDecimal next; - - BigDecimalHalvingIterator(BigDecimal start, BigDecimal max) { - this.max = max; - next = start; - } - - @Override public boolean hasNext() { - return !done; - } - - @Override public BigDecimal next() { - if (!hasNext()) - throw new NoSuchElementException(); - - next = peek(); - done = next.equals(peek()); - return next; - } - - private BigDecimal peek() { - return next.add( - max.subtract(next) - .divide(BigDecimal.valueOf(2), HALF_UP)); - } - } - - private static final class IntegerHalvingIterator - implements Iterator { - - private boolean done; - private int next; - - IntegerHalvingIterator(int start) { - next = start; - } - - @Override public boolean hasNext() { - return !done; - } - - @Override public Integer next() { - if (!hasNext()) - throw new NoSuchElementException(); - - int result = next; - next = peek(); - done = next == 0; - return result; - } - - private int peek() { - return next / 2; - } - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ShrinkControl.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ShrinkControl.java deleted file mode 100644 index b93fb2191a..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ShrinkControl.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal; - -import org.utbot.quickcheck.MinimalCounterexampleHook; -import org.utbot.quickcheck.Property; - -public class ShrinkControl { - private final boolean shouldShrink; - private final int maxShrinks; - private final int maxShrinkDepth; - private final int maxShrinkTime; - private final MinimalCounterexampleHook onMinimalCounterexample; - - public ShrinkControl(Property marker) - throws IllegalAccessException, InstantiationException { - - this.shouldShrink = marker.shrink(); - this.maxShrinks = marker.maxShrinks(); - this.maxShrinkDepth = marker.maxShrinkDepth(); - this.maxShrinkTime = marker.maxShrinkTime(); - this.onMinimalCounterexample = - marker.onMinimalCounterexample().newInstance(); - } - - public boolean shouldShrink() { - return shouldShrink; - } - - public int maxShrinks() { - return maxShrinks; - } - - public int maxShrinkDepth() { - return maxShrinkDepth; - } - - public int maxShrinkTime() { - return maxShrinkTime; - } - - public MinimalCounterexampleHook onMinimalCounterexample() { - return onMinimalCounterexample; - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java index e07dd2cd4e..516f054fe7 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.internal; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java index 87a4f60958..f0074cb6e1 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.internal; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/constraint/ConstraintEvaluator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/constraint/ConstraintEvaluator.java deleted file mode 100644 index 5f735e7cf9..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/constraint/ConstraintEvaluator.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -package org.utbot.quickcheck.internal.constraint; - -import ognl.Ognl; -import ognl.OgnlException; - -import java.util.HashMap; -import java.util.Map; - -public class ConstraintEvaluator { - private final Object constraint; - private final Map bindings; - - public ConstraintEvaluator(String expression) { - try { - constraint = - expression == null ? null : Ognl.parseExpression(expression); - bindings = new EvalMap(); - } catch (OgnlException ex) { - throw new EvaluationException(ex); - } - } - - public boolean evaluate() { - try { - return constraint == null - || (Boolean) Ognl.getValue(constraint, bindings, (Object) null); - } catch (OgnlException ex) { - throw new EvaluationException(ex); - } - } - - public void bind(Object value) { - bindings.put("_", value); - } - - public static class EvaluationException extends RuntimeException { - private static final long serialVersionUID = Integer.MIN_VALUE; - - EvaluationException(String message) { - super(message); - } - - EvaluationException(Throwable cause) { - super(cause); - } - } - - private static class EvalMap extends HashMap { - private static final long serialVersionUID = Long.MIN_VALUE; - - @Override public Object get(Object key) { - if (!containsKey(key)) { - throw new EvaluationException( - "Referring to undefined variable '" + key + "']"); - } - return super.get(key); - } - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/ConstructorInvokingStringConversion.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/ConstructorInvokingStringConversion.java deleted file mode 100644 index 644d19f3be..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/ConstructorInvokingStringConversion.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.conversion; - -import org.utbot.quickcheck.conversion.StringConversion; - -import java.lang.reflect.Constructor; - -import static org.utbot.quickcheck.internal.Reflection.reflectionException; - -public class ConstructorInvokingStringConversion implements StringConversion { - private final Constructor ctor; - - ConstructorInvokingStringConversion(Constructor ctor) { - this.ctor = ctor; - } - - @Override public Object convert(String raw) { - try { - return ctor.newInstance(raw); - } catch (Exception ex) { - throw reflectionException(ex); - } - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/MethodInvokingStringConversion.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/MethodInvokingStringConversion.java deleted file mode 100644 index 4d07aa3488..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/MethodInvokingStringConversion.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.conversion; - -import org.utbot.quickcheck.conversion.StringConversion; - -import java.lang.reflect.Method; - -import static org.utbot.quickcheck.internal.Reflection.reflectionException; - -public class MethodInvokingStringConversion implements StringConversion { - private final Method method; - - MethodInvokingStringConversion(Method method) { - this.method = method; - } - - @Override public Object convert(String raw) { - try { - return method.invoke(null, raw); - } catch (Exception ex) { - throw reflectionException(ex); - } - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/StringConversions.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/StringConversions.java deleted file mode 100644 index 9fe2ca44fe..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/conversion/StringConversions.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.conversion; - -import org.utbot.quickcheck.conversion.StringConversion; -import org.utbot.quickcheck.generator.Also; -import org.utbot.quickcheck.generator.Only; -import org.utbot.quickcheck.internal.ParameterTypeContext; -import org.utbot.quickcheck.internal.ReflectionException; -import org.utbot.quickcheck.internal.conversion.ConstructorInvokingStringConversion; -import org.utbot.quickcheck.internal.conversion.MethodInvokingStringConversion; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; - -import static org.utbot.quickcheck.internal.Reflection.*; - -public final class StringConversions { - private StringConversions() { - throw new UnsupportedOperationException(); - } - - public static StringConversion to(Class clazz) { - Class wrapped = maybeWrap(clazz); - - try { - Method method = - findMethod(clazz, "valueOf", String.class); - if (Modifier.isStatic(method.getModifiers()) - && wrapped.equals(method.getReturnType())) { - - return new MethodInvokingStringConversion(method); - } - } catch (ReflectionException reserveJudgment) { - // fall back to other means of conversion - } - - if (Character.class.equals(wrapped)) - return characterConversion(clazz); - - return new ConstructorInvokingStringConversion( - findConstructor(wrapped, String.class)); - } - - public static StringConversion decide(ParameterTypeContext p, Only only) { - return decide(p, only.by(), Only.class); - } - - public static StringConversion decide(ParameterTypeContext p, Also also) { - return decide(p, also.by(), Also.class); - } - - private static StringConversion decide( - ParameterTypeContext p, - Class custom, - Class markerClass) { - - return custom.equals(defaultValueOf(markerClass, "by")) - ? to(p.getRawClass()) - : instantiate(custom); - } - - private static StringConversion characterConversion(Class clazz) { - return raw -> { - if (raw.length() > 1) { - throw new IllegalArgumentException( - "Cannot convert " + raw + " into an instance of " + clazz); - } - - return raw.charAt(0); - }; - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java index 7e49215568..c3f0d2389f 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.internal.generator; @@ -29,14 +6,9 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.internal.GeometricDistribution; import org.utbot.quickcheck.random.SourceOfRandomness; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - abstract class AbstractGenerationStatus implements GenerationStatus { private final GeometricDistribution distro; private final SourceOfRandomness random; - private final Map, Object> contextValues = new HashMap<>(); AbstractGenerationStatus( GeometricDistribution distro, @@ -46,15 +18,6 @@ abstract class AbstractGenerationStatus implements GenerationStatus { this.random = random; } - @Override public GenerationStatus setValue(Key key, T value) { - contextValues.put(key, value); - return this; - } - - @Override public Optional valueOf(Key key) { - return Optional.ofNullable(key.cast(contextValues.get(key))); - } - @Override public int size() { return distro.sampleWithMean(attempts() + 1, random); } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java index 9797644e87..6c35b52911 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java @@ -1,60 +1,23 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal.generator; -import javassist.bytecode.ByteArray; -import org.antlr.runtime.misc.IntArray; import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; import org.utbot.framework.concrete.UtModelConstructor; import org.utbot.framework.plugin.api.ClassId; import org.utbot.framework.plugin.api.UtArrayModel; import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtNullModel; import org.utbot.framework.plugin.api.util.IdUtilKt; import org.utbot.quickcheck.generator.*; -import org.utbot.quickcheck.internal.Lists; import org.utbot.quickcheck.random.SourceOfRandomness; import java.lang.reflect.AnnotatedType; -import java.lang.reflect.Array; -import java.math.BigDecimal; import java.util.*; -import java.util.stream.IntStream; -import java.util.stream.Stream; -import static java.math.BigDecimal.ZERO; -import static java.util.stream.Collectors.toList; -import static java.util.stream.StreamSupport.stream; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Lists.removeFrom; -import static org.utbot.quickcheck.internal.Lists.shrinksOfOneItem; import static org.utbot.quickcheck.internal.Ranges.Type.INTEGRAL; import static org.utbot.quickcheck.internal.Ranges.checkRange; import static org.utbot.quickcheck.internal.Reflection.annotatedComponentTypes; -import static org.utbot.quickcheck.internal.Sequences.halving; public class ArrayGenerator extends Generator { private final Class componentType; @@ -138,38 +101,6 @@ private ClassId getClassIdForArrayType(Class componentType) { return new ClassId("[L", classIdForType(componentType)); } } - @Override public boolean canShrink(Object larger) { - return larger.getClass().getComponentType() == componentType; - } - - @Override public List doShrink( - SourceOfRandomness random, - Object larger) { - - int length = Array.getLength(larger); - List asList = new ArrayList<>(); - for (int i = 0; i < length; ++i) { - asList.add(Array.get(larger, i)); - } - - List shrinks = new ArrayList<>(removals(asList)); - - @SuppressWarnings("unchecked") - Stream> oneItemShrinks = - shrinksOfOneItem(random, asList, (Shrink) component) - .stream(); - if (distinct) { - oneItemShrinks = oneItemShrinks.filter(Lists::isDistinct); - } - - shrinks.addAll( - oneItemShrinks - .map(this::convert) - .filter(this::inLengthRange) - .collect(toList())); - - return shrinks; - } @Override public void provide(Generators provided) { super.provide(provided); @@ -177,18 +108,6 @@ private ClassId getClassIdForArrayType(Class componentType) { component.provide(provided); } - @Override public BigDecimal magnitude(Object value) { - int length = Array.getLength(value); - if (length == 0) - return ZERO; - - BigDecimal elementsMagnitude = - IntStream.range(0, length) - .mapToObj(i -> component.magnitude(Array.get(value, i))) - .reduce(ZERO, BigDecimal::add); - return BigDecimal.valueOf(length).multiply(elementsMagnitude); - } - @Override public void configure(AnnotatedType annotatedType) { super.configure(annotatedType); @@ -204,26 +123,4 @@ private int length(SourceOfRandomness random, GenerationStatus status) { : status.size(); } - private boolean inLengthRange(Object items) { - int length = Array.getLength(items); - return lengthRange == null - || (length >= lengthRange.min() && length <= lengthRange.max()); - } - - private List removals(List items) { - return stream(halving(items.size()).spliterator(), false) - .map(i -> removeFrom(items, i)) - .flatMap(Collection::stream) - .map(this::convert) - .filter(this::inLengthRange) - .collect(toList()); - } - - private Object convert(List items) { - Object array = Array.newInstance(componentType, items.size()); - for (int i = 0; i < items.size(); ++i) { - Array.set(array, i, items.get(i)); - } - return array; - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java index 49dafb4ac2..eb9a63531c 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java @@ -1,28 +1,3 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - package org.utbot.quickcheck.internal.generator; import org.utbot.framework.plugin.api.UtModel; @@ -36,7 +11,6 @@ a copy of this software and associated documentation files (the import java.lang.reflect.AnnotatedElement; import java.lang.reflect.AnnotatedType; -import java.math.BigDecimal; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -60,25 +34,6 @@ public class CompositeGenerator extends Generator { return choice.generate(random, status); } - @Override public boolean canShrink(Object larger) { - return composed.stream() - .map(w -> w.item) - .anyMatch(g -> g.canShrink(larger)); - } - - @Override public List doShrink( - SourceOfRandomness random, - Object larger) { - - List>> shrinkers = - composed.stream() - .filter(w -> w.item.canShrink(larger)) - .collect(toList()); - - Generator choice = Items.chooseWeighted(shrinkers, random); - return new ArrayList<>(choice.shrink(random, larger)); - } - Generator composed(int index) { return composed.get(index).item; } @@ -94,15 +49,6 @@ int numberOfComposedGenerators() { each.item.provide(provided); } - @Override public BigDecimal magnitude(Object value) { - List>> shrinkers = - composed.stream() - .filter(w -> w.item.canShrink(value)) - .collect(toList()); - - return shrinkers.get(0).item.magnitude(value); - } - @Override public void configure(AnnotatedType annotatedType) { List>> candidates = new ArrayList<>(composed); diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java index 6c2196c57f..be7a2640e5 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal.generator; @@ -51,7 +28,4 @@ public class EnumGenerator extends Generator { return UtModelGenerator.getUtModelConstructor().construct(values[index], classIdForType(Enum.class)); } - @Override public boolean canShrink(Object larger) { - return enumType.isInstance(larger); - } } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ExhaustiveDomainGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ExhaustiveDomainGenerator.java deleted file mode 100644 index d7a1ff37d2..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ExhaustiveDomainGenerator.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.*; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; - -public class ExhaustiveDomainGenerator extends Generator { - private final Iterator items; - - public ExhaustiveDomainGenerator(Collection items) { - super(Object.class); - - List list = new ArrayList<>(new HashSet<>(items)); - - try { - Collections.sort(list); - } catch (ClassCastException forgiven) { - // non-Comparable types such as Target type will go through - // this exception which cannot be sorted. - } - - this.items = list.iterator(); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(items.next(), getObjectClassId()); - } - - boolean hasNext() { - return items.hasNext(); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java index 32c5c22a7a..c126f2aad3 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java @@ -1,49 +1,24 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal.generator; +import org.javaruntype.type.TypeParameter; import org.utbot.quickcheck.generator.*; import org.utbot.quickcheck.internal.ParameterTypeContext; import org.utbot.quickcheck.internal.Weighted; import org.utbot.quickcheck.internal.Zilch; -import org.utbot.quickcheck.internal.generator.ArrayGenerator; import org.utbot.quickcheck.random.SourceOfRandomness; -import org.javaruntype.type.TypeParameter; import java.lang.annotation.Annotation; import java.lang.reflect.*; import java.util.*; import java.util.stream.Stream; -import static org.utbot.quickcheck.internal.Items.choose; -import static org.utbot.quickcheck.internal.Reflection.*; -import static java.util.Arrays.asList; import static java.util.Collections.unmodifiableSet; import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toSet; +import static org.utbot.quickcheck.internal.Items.choose; +import static org.utbot.quickcheck.internal.Reflection.*; public class GeneratorRepository implements Generators { private static final Set NULLABLE_ANNOTATIONS = @@ -132,31 +107,6 @@ private void registerGeneratorForType( forType.add(generator); } - @Override public Generator field(Class type, String fieldName) { - return field(findField(type, fieldName)); - } - - @Override public Generator constructor( - Class type, - Class... argumentTypes) { - - Constructor constructor = findConstructor(type, argumentTypes); - Ctor ctor = new Ctor<>(constructor); - ctor.provide(this); - ctor.configure(constructor.getAnnotatedReturnType()); - - return ctor; - } - - @Override public Generator fieldsOf(Class type) { - Fields fields = new Fields<>(type); - - fields.provide(this); - fields.configure(type); - - return fields; - } - @SuppressWarnings("unchecked") @Override public Generator type( Class type, @@ -180,51 +130,6 @@ private void registerGeneratorForType( ParameterTypeContext.forField(field).annotate(field)); } - @SafeVarargs - @SuppressWarnings("unchecked") - @Override public final Generator oneOf( - Class first, - Class... rest) { - - return oneOf( - type(first), - Arrays.stream(rest) - .map(t -> type(t)) - .toArray(Generator[]::new)); - } - - @SafeVarargs - @SuppressWarnings("unchecked") - @Override public final Generator oneOf( - Generator first, - Generator... rest) { - - if (rest.length == 0) - return (Generator) first; - - List> gens = new ArrayList<>(); - gens.add(first); - Collections.addAll(gens, rest); - - List>> weightings = gens.stream() - .map(g -> new Weighted>(g, 1)) - .collect(toList()); - - return (Generator) new CompositeGenerator(weightings); - } - - @Override public final > T make( - Class genType, - Generator... components) { - - T generator = instantiate(genType); - generator.provide(this); - generator.configure(genType); - generator.addComponentGenerators(asList(components)); - - return generator; - } - @Override public final Generators withRandom(SourceOfRandomness other) { return new GeneratorRepository(other, this.generators); } diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GuaranteeValuesGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GuaranteeValuesGenerator.java deleted file mode 100644 index 7f46f126bc..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GuaranteeValuesGenerator.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.internal.generator.ExhaustiveDomainGenerator; -import org.utbot.quickcheck.random.SourceOfRandomness; - - -public class GuaranteeValuesGenerator extends Generator { - private final ExhaustiveDomainGenerator guaranteed; - private final Generator rest; - - - public GuaranteeValuesGenerator( - ExhaustiveDomainGenerator guaranteed, - Generator rest) { - - super(Object.class); - - this.guaranteed = guaranteed; - this.rest = rest; - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return guaranteed.hasNext() - ? guaranteed.generate(random, status) - : rest.generate(random, status); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java index 8e029899e1..786af00211 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal.generator; @@ -32,7 +9,6 @@ a copy of this software and associated documentation files (the import org.utbot.quickcheck.random.SourceOfRandomness; import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; public class LambdaGenerator extends Generator { private final Class lambdaType; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java index 4f53f30d30..170a1dbfe1 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal.generator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java index b1cb174bd7..cf64173427 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.internal.generator; import org.utbot.framework.plugin.api.UtModel; @@ -35,7 +12,6 @@ a copy of this software and associated documentation files (the import java.lang.reflect.AnnotatedElement; import java.lang.reflect.AnnotatedType; -import java.math.BigDecimal; import java.util.List; import java.util.Optional; @@ -101,18 +77,6 @@ class NullableGenerator extends Generator { delegate.provide(provided); } - @Override public boolean canShrink(Object larger) { - return delegate.canShrink(larger); - } - - @Override public List doShrink(SourceOfRandomness random, T larger) { - return delegate.doShrink(random, larger); - } - - @Override public BigDecimal magnitude(Object value) { - return delegate.magnitude(value); - } - private void configure(NullAllowed allowed) { if (allowed.probability() >= 0 && allowed.probability() <= 1) { this.probabilityOfNull = allowed.probability(); diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/PropertyParameterGenerationContext.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/PropertyParameterGenerationContext.java deleted file mode 100644 index 7c7b4fb6bc..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/PropertyParameterGenerationContext.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.internal.GeometricDistribution; -import org.utbot.quickcheck.internal.ParameterSampler; -import org.utbot.quickcheck.internal.PropertyParameterContext; -import org.utbot.quickcheck.internal.constraint.ConstraintEvaluator; -import org.utbot.quickcheck.internal.generator.GeneratorRepository; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.List; - -import static java.lang.Math.min; -import static java.lang.String.format; -import static java.math.BigDecimal.ZERO; -import static java.util.Collections.emptyList; - -public class PropertyParameterGenerationContext - extends org.utbot.quickcheck.internal.generator.AbstractGenerationStatus { - - private final PropertyParameterContext parameter; - private final ConstraintEvaluator evaluator; - private final Generator generator; - private final int sampleSize; - - private int successfulEvaluations; - private int discards; - private int semiAttempts; - - public PropertyParameterGenerationContext( - PropertyParameterContext parameter, - GeneratorRepository repository, - GeometricDistribution distro, - SourceOfRandomness random, - ParameterSampler sampler) { - - super(distro, initializeRandomness(parameter, random)); - - this.parameter = parameter; - this.evaluator = new ConstraintEvaluator(parameter.constraint()); - this.generator = - sampler.decideGenerator(repository, parameter.typeContext()); - this.sampleSize = sampler.sizeFactor(parameter.typeContext()); - } - - private static SourceOfRandomness initializeRandomness( - PropertyParameterContext p, - SourceOfRandomness r) { - - if (p.fixedSeed()) - r.setSeed(p.seed()); - - return r; - } - - public Object generate() { - Object nextValue; - - for (nextValue = generator.generate(random(), this); - !evaluate(nextValue);) { - - nextValue = generator.generate(random(), this); - } - - return nextValue; - } - - public List shrink(Object larger) { - return generator.canShrink(larger) - ? new ArrayList<>(generator.shrink(random(), larger)) - : emptyList(); - } - - private boolean evaluate(Object value) { - evaluator.bind(value); - boolean result = evaluator.evaluate(); - - if (result) { - ++successfulEvaluations; - } else { - ++discards; - } - - if (tooManyDiscards()) { - throw new DiscardRatioExceededException( - parameter, - discards, - successfulEvaluations); - } - - return result; - } - - private boolean tooManyDiscards() { - if (parameter.discardRatio() == 0) - return discards > sampleSize(); - - return successfulEvaluations == 0 - ? discards > parameter.discardRatio() - : (discards / successfulEvaluations) >= parameter.discardRatio(); - } - - @Override public int size() { - return min(super.size(), sampleSize()); - } - - @Override public int attempts() { - return successfulEvaluations + discards + (semiAttempts / 10); - } - - @Override public void semiAttempt() { - ++semiAttempts; - } - - public long effectiveSeed() { - return random().seed(); - } - - public int sampleSize() { - return sampleSize; - } - - public String name() { - return parameter.typeContext().name(); - } - - public BigDecimal magnitude(Object value) { - return generator.canShrink(value) - ? generator.magnitude(value).abs() - : ZERO; - } - - public static class DiscardRatioExceededException - extends RuntimeException { - - static final String MESSAGE_TEMPLATE = - "For parameter [%s] with discard ratio [%d]," - + " %d unsuccessful values and %d successes. Stopping."; - - private static final long serialVersionUID = Long.MIN_VALUE; - - DiscardRatioExceededException( - PropertyParameterContext parameter, - int discards, - int successfulEvaluations) { - - super(format( - MESSAGE_TEMPLATE, - parameter.typeContext().name(), - parameter.discardRatio(), - discards, - successfulEvaluations)); - } - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SamplingDomainGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SamplingDomainGenerator.java deleted file mode 100644 index ac04034b2d..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SamplingDomainGenerator.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; - -public class SamplingDomainGenerator extends Generator { - private final List items; - - public SamplingDomainGenerator(Set items) { - super(Object.class); - - this.items = new ArrayList<>(items); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.choose(items), getObjectClassId()); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ServiceLoaderGeneratorSource.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ServiceLoaderGeneratorSource.java deleted file mode 100644 index 8f7b0c4896..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ServiceLoaderGeneratorSource.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.quickcheck.generator.Generator; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ServiceLoader; - -import static java.util.Collections.unmodifiableList; -import static java.util.Comparator.comparing; - -public class ServiceLoaderGeneratorSource implements Iterable> { - @SuppressWarnings("rawtypes") - private final ServiceLoader loader; - - public ServiceLoaderGeneratorSource() { - loader = ServiceLoader.load(Generator.class); - } - - @Override public Iterator> iterator() { - List> generators = new ArrayList<>(); - - for (Generator each : loader) { - generators.add(each); - } - - generators.sort(comparing(g -> g.getClass().getName())); - - return unmodifiableList(generators).iterator(); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java index 4cd741d482..74ab5a2e0e 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.internal.generator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java index fc6ab5e63d..a42a5d6d28 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java @@ -1,27 +1,4 @@ -/* - The MIT License - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ package org.utbot.quickcheck.internal.generator; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/ExhaustiveParameterSampler.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/ExhaustiveParameterSampler.java deleted file mode 100644 index 67d8ff97b8..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/ExhaustiveParameterSampler.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.sampling; - -import org.utbot.quickcheck.conversion.StringConversion; -import org.utbot.quickcheck.generator.Also; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Only; -import org.utbot.quickcheck.internal.CartesianIterator; -import org.utbot.quickcheck.internal.ParameterSampler; -import org.utbot.quickcheck.internal.ParameterTypeContext; -import org.utbot.quickcheck.internal.SeededValue; -import org.utbot.quickcheck.internal.conversion.StringConversions; -import org.utbot.quickcheck.internal.generator.ExhaustiveDomainGenerator; -import org.utbot.quickcheck.internal.generator.GeneratorRepository; -import org.utbot.quickcheck.internal.generator.GuaranteeValuesGenerator; -import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; - -import java.lang.reflect.Array; -import java.util.*; -import java.util.stream.Stream; -import java.util.stream.StreamSupport; - -import static org.utbot.quickcheck.internal.Reflection.*; -import static java.lang.Math.max; -import static java.util.Arrays.asList; -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toSet; - -public class ExhaustiveParameterSampler implements ParameterSampler { - private final int sizeFactor; - - public ExhaustiveParameterSampler(int sizeFactor) { - this.sizeFactor = sizeFactor; - } - - @Override public int sizeFactor(ParameterTypeContext p) { - Only only = p.annotatedType().getAnnotation(Only.class); - if (only != null) - return new HashSet<>(asList(only.value())).size(); - - Also also = p.annotatedType().getAnnotation(Also.class); - if (also != null) - return max(sizeFactor, new HashSet<>(asList(also.value())).size()); - - if (Boolean.class.equals(maybeWrap(p.getRawClass()))) - return 2; - - if (p.isEnum()) { - return Array.getLength( - invoke( - findMethod(p.getRawClass(), "values"), - null)); - } - - return sizeFactor; - } - - @Override - public Stream> sample( - List parameters) { - - List> sources = - parameters.stream() - .map(p -> - Stream.generate(() -> new SeededValue(p)) - .limit(p.sampleSize()) - .iterator()) - .collect(toList()); - - return cartesian(sources); - } - - @Override public Generator decideGenerator( - GeneratorRepository repository, - ParameterTypeContext p) { - - Only only = p.annotatedType().getAnnotation(Only.class); - if (only != null) { - StringConversion conversion = StringConversions.decide(p, only); - Set values = - Arrays.stream(only.value()) - .map(conversion::convert) - .collect(toSet()); - return new ExhaustiveDomainGenerator(values); - } - - Also also = p.annotatedType().getAnnotation(Also.class); - if (also != null) { - StringConversion conversion = StringConversions.decide(p, also); - Set values = - Arrays.stream(also.value()) - .map(conversion::convert) - .collect(toSet()); - return new GuaranteeValuesGenerator( - new ExhaustiveDomainGenerator(values), - repository.produceGenerator(p)); - } - - if (Boolean.class.equals(maybeWrap(p.getRawClass()))) { - return new ExhaustiveDomainGenerator(asList(true, false)); - } - - if (p.isEnum()) { - return new ExhaustiveDomainGenerator( - asList(p.getRawClass().getEnumConstants())); - } - - return repository.produceGenerator(p); - } - - private Stream> cartesian(List> sources) { - Iterable> cartesian = () -> new CartesianIterator<>(sources); - return StreamSupport.stream(cartesian.spliterator(), false); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/TupleParameterSampler.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/TupleParameterSampler.java deleted file mode 100644 index fa09848233..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/sampling/TupleParameterSampler.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -package org.utbot.quickcheck.internal.sampling; - -import org.utbot.quickcheck.conversion.StringConversion; -import org.utbot.quickcheck.generator.Also; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Only; -import org.utbot.quickcheck.internal.ParameterSampler; -import org.utbot.quickcheck.internal.ParameterTypeContext; -import org.utbot.quickcheck.internal.SeededValue; -import org.utbot.quickcheck.internal.conversion.StringConversions; -import org.utbot.quickcheck.internal.generator.*; - -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Stream; - -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toSet; - -public class TupleParameterSampler implements ParameterSampler { - private final int trials; - - public TupleParameterSampler(int trials) { - this.trials = trials; - } - - @Override public int sizeFactor(ParameterTypeContext p) { - return trials; - } - - @Override public Stream> sample( - List parameters) { - - Stream> tupleStream = - Stream.generate( - () -> parameters.stream() - .map(SeededValue::new) - .collect(toList())); - return tupleStream.limit(trials); - } - - @Override public Generator decideGenerator( - GeneratorRepository repository, - ParameterTypeContext p) { - - Only only = p.annotatedType().getAnnotation(Only.class); - if (only != null) { - StringConversion conversion = StringConversions.decide(p, only); - Set values = - Arrays.stream(only.value()) - .map(conversion::convert) - .collect(toSet()); - return new SamplingDomainGenerator(values); - } - - Also also = p.annotatedType().getAnnotation(Also.class); - if (also != null) { - StringConversion conversion = StringConversions.decide(p, also); - Set values = - Arrays.stream(also.value()) - .map(conversion::convert) - .collect(toSet()); - return new GuaranteeValuesGenerator( - new ExhaustiveDomainGenerator(values), - repository.produceGenerator(p)); - } - - return repository.produceGenerator(p); - } -} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java b/utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java index 0e27b210e9..dbab5da57c 100644 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java +++ b/utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java @@ -1,27 +1,4 @@ -/* - The MIT License - - Copyright (c) 2010-2021 Paul R. Holser, Jr. - - Permission is hereby granted, free of charge, to any person obtaining - a copy of this software and associated documentation files (the - "Software"), to deal in the Software without restriction, including - without limitation the rights to use, copy, modify, merge, publish, - distribute, sublicense, and/or sell copies of the Software, and to - permit persons to whom the Software is furnished to do so, subject to - the following conditions: - - The above copyright notice and this permission notice shall be - included in all copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE - LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION - OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION - WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ + package org.utbot.quickcheck.random; diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheck.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheck.java deleted file mode 100644 index a9320c1679..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheck.java +++ /dev/null @@ -1,110 +0,0 @@ -///* -// The MIT License -// -// Copyright (c) 2010-2021 Paul R. Holser, Jr. -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -//*/ -// -//package org.utbot.quickcheck.runner; -// -//import org.utbot.quickcheck.Property; -//import org.utbot.quickcheck.internal.GeometricDistribution; -//import org.utbot.quickcheck.internal.generator.GeneratorRepository; -//import org.utbot.quickcheck.internal.generator.ServiceLoaderGeneratorSource; -//import org.utbot.quickcheck.random.SourceOfRandomness; -//import org.utbot.quickcheck.runner.JUnitQuickcheckTestClass; -//import org.junit.Test; -//import org.junit.runners.BlockJUnit4ClassRunner; -//import org.junit.runners.model.FrameworkMethod; -//import org.junit.runners.model.InitializationError; -//import org.junit.runners.model.Statement; -//import org.slf4j.Logger; -//import org.slf4j.LoggerFactory; -// -//import java.util.ArrayList; -//import java.util.List; -//import java.util.Random; -// -///** -// *

JUnit test runner for junit-quickcheck property-based tests.

-// * -// *

When this runner runs a given test class, it regards only -// * {@code public} instance methods with a return type of {@code void} that are -// * marked with either the {@link Property} -// * annotation or the {@code org.junit.Test} annotation.

-// * -// *

This runner honors {@link org.junit.Rule}, {@link org.junit.Before}, -// * {@link org.junit.After}, {@link org.junit.BeforeClass}, and -// * {@link org.junit.AfterClass}. Their execution is wrapped around the -// * verification of a property or execution of a test in the expected -// * order.

-// */ -//public class JUnitQuickcheck extends BlockJUnit4ClassRunner { -// private final GeneratorRepository repo; -// private final GeometricDistribution distro; -// private final Logger logger; -// -// /** -// * Invoked reflectively by JUnit. -// * -// * @param clazz class containing properties to verify -// * @throws InitializationError if there is a problem with the -// * properties class -// */ -// public JUnitQuickcheck(Class clazz) throws InitializationError { -// super(new JUnitQuickcheckTestClass(clazz)); -// -// SourceOfRandomness random = new SourceOfRandomness(new Random()); -// repo = -// new GeneratorRepository(random) -// .register(new ServiceLoaderGeneratorSource()); -// distro = new GeometricDistribution(); -// logger = LoggerFactory.getLogger("junit-quickcheck.value-reporting"); -// } -// -// @Override protected void validateTestMethods(List errors) { -// validatePublicVoidNoArgMethods(Test.class, false, errors); -// validatePropertyMethods(errors); -// } -// -// private void validatePropertyMethods(List errors) { -// getTestClass().getAnnotatedMethods(Property.class) -// .forEach(m -> m.validatePublicVoid(false, errors)); -// } -// -// @Override protected List computeTestMethods() { -// List methods = new ArrayList<>(); -// methods.addAll(getTestClass().getAnnotatedMethods(Test.class)); -// methods.addAll(getTestClass().getAnnotatedMethods(Property.class)); -// return methods; -// } -// -// @Override public Statement methodBlock(FrameworkMethod method) { -// return method.getAnnotation(Test.class) != null -// ? super.methodBlock(method) -// : new org.utbot.quickcheck.runner.PropertyStatement( -// method, -// getTestClass(), -// repo, -// distro, -// logger); -// } -//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheckTestClass.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheckTestClass.java deleted file mode 100644 index edae19cbfb..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/JUnitQuickcheckTestClass.java +++ /dev/null @@ -1,107 +0,0 @@ -///* -// The MIT License -// -// Copyright (c) 2010-2021 Paul R. Holser, Jr. -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -//*/ -// -//package org.utbot.quickcheck.runner; -// -//import org.junit.internal.MethodSorter; -//import org.junit.runners.model.FrameworkField; -//import org.junit.runners.model.FrameworkMethod; -//import org.junit.runners.model.TestClass; -// -//import java.lang.annotation.Annotation; -//import java.lang.reflect.Field; -//import java.lang.reflect.Method; -//import java.lang.reflect.Modifier; -//import java.util.*; -//import java.util.stream.Stream; -// -//import static java.util.stream.Collectors.toList; -// -///** -// * Extension of JUnit framework class for junit-quickcheck's discovery -// * of JUnit annotations/methods/fields. -// * -// * This is a member of a JUnit package so that it has access to -// * {@link FrameworkField}. -// */ -//public class JUnitQuickcheckTestClass extends TestClass { -// /** -// * Makes a new instance, wrapping the given test class. -// * -// * @param testClass class with junit-quickcheck tests -// */ -// JUnitQuickcheckTestClass(Class testClass) { -// super(testClass); -// } -// -// @Override protected void scanAnnotatedMembers( -// Map, List> methods, -// Map, List> fields) { -// -// ancestry().forEachOrdered(c -> { -// for (Method each : applicableMethodsOf(c)) { -// addToAnnotationLists(new FrameworkMethod(each), methods); -// } -// for (Field each : applicableFieldsOf(c)) { -// addToAnnotationLists(new FrameworkField(each), fields); -// } -// }); -// } -// -// private static List applicableMethodsOf(Class clazz) { -// return Arrays.stream(MethodSorter.getDeclaredMethods(clazz)) -// .filter(m -> -// !m.getDeclaringClass().isInterface() -// || m.isDefault() -// || Modifier.isStatic(m.getModifiers())) -// .collect(toList()); -// } -// -// private static Field[] applicableFieldsOf(Class clazz) { -// Field[] declaredFields = clazz.getDeclaredFields(); -// Arrays.sort(declaredFields, Comparator.comparing(Field::getName)); -// return declaredFields; -// } -// -// private Stream> ancestry() { -// return superclassHierarchy(getJavaClass()) -// .flatMap(JUnitQuickcheckTestClass::interfaceAncestry); -// } -// -// private static Stream> superclassHierarchy(Class clazz) { -// List> hierarchy = new ArrayList<>(); -// for (Class c = clazz; c != null; c = c.getSuperclass()) { -// hierarchy.add(c); -// } -// return hierarchy.stream(); -// } -// -// private static Stream> interfaceAncestry(Class clazz) { -// return Stream.concat( -// Stream.of(clazz), -// Arrays.stream(clazz.getInterfaces()) -// .flatMap(JUnitQuickcheckTestClass::interfaceAncestry)); -// } -//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/NoValuesSatisfiedPropertyAssumptions.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/NoValuesSatisfiedPropertyAssumptions.java deleted file mode 100644 index 963596927a..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/NoValuesSatisfiedPropertyAssumptions.java +++ /dev/null @@ -1,17 +0,0 @@ -//package org.utbot.quickcheck.runner; -// -//import org.junit.internal.AssumptionViolatedException; -// -//import java.util.List; -// -//class NoValuesSatisfiedPropertyAssumptions -// extends org.junit.AssumptionViolatedException { -// -// NoValuesSatisfiedPropertyAssumptions( -// List violations) { -// -// super( -// "No values satisfied property assumptions. Violated assumptions: " -// + violations); -// } -//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyFalsified.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyFalsified.java deleted file mode 100644 index 603d8f5424..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyFalsified.java +++ /dev/null @@ -1,101 +0,0 @@ -///* -// The MIT License -// -// Copyright (c) 2010-2021 Paul R. Holser, Jr. -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -//*/ -// -//package org.utbot.quickcheck.runner; -// -//import java.util.Arrays; -// -//import static java.lang.String.format; -// -//final class PropertyFalsified { -// private PropertyFalsified() { -// throw new UnsupportedOperationException(); -// } -// -// static AssertionError counterexampleFound( -// String propertyName, -// Object[] args, -// long[] seeds, -// AssertionError e) { -// -// String template = "Property named '%s' failed%s%n" -// + "With arguments: %s%n" -// + "Seeds for reproduction: %s"; -// String assertionErrorMessage = -// e.getMessage() == null -// ? ":" -// : format(" (%s)", e.getMessage()); -// -// return new AssertionError( -// format( -// template, -// propertyName, -// assertionErrorMessage, -// Arrays.deepToString(args), -// Arrays.toString(seeds)), -// e); -// } -// -// static AssertionError smallerCounterexampleFound( -// String propertyName, -// Object[] originalArgs, -// Object[] args, -// long[] seeds, -// AssertionError smallerFailure, -// AssertionError originalFailure) { -// -// String originalFailureMessageSegment = -// originalFailure.getMessage() == null -// ? "" -// : format( -// "Original failure message: %s%n", -// originalFailure.getMessage()); -// String smallerFailureMessageSegment = -// smallerFailure.getMessage() == null -// ? ":" -// : format(" (%s):", smallerFailure.getMessage()); -// -// String template = -// "Property named '%s' failed%s%n" -// + "With arguments: %s%n" -// + "%s" -// + "First arguments found to also provoke a failure: %s%n" -// + "Seeds for reproduction: %s"; -// -// AssertionError e = -// new AssertionError( -// format( -// template, -// propertyName, -// smallerFailureMessageSegment, -// Arrays.deepToString(args), -// originalFailureMessageSegment, -// Arrays.deepToString(originalArgs), -// Arrays.toString(seeds)), -// originalFailure); -// e.setStackTrace(smallerFailure.getStackTrace()); -// return e; -// } -//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyStatement.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyStatement.java deleted file mode 100644 index f5da2eb15d..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyStatement.java +++ /dev/null @@ -1,197 +0,0 @@ -///* -// The MIT License -// -// Copyright (c) 2010-2021 Paul R. Holser, Jr. -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -//*/ -// -//package org.utbot.quickcheck.runner; -// -//import org.utbot.quickcheck.Property; -//import org.utbot.quickcheck.internal.*; -//import org.utbot.quickcheck.internal.generator.GeneratorRepository; -//import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; -//import org.utbot.quickcheck.internal.sampling.ExhaustiveParameterSampler; -//import org.utbot.quickcheck.internal.sampling.TupleParameterSampler; -//import org.utbot.quickcheck.random.SourceOfRandomness; -//import org.junit.internal.AssumptionViolatedException; -//import org.junit.runners.model.FrameworkMethod; -//import org.junit.runners.model.InitializationError; -//import org.junit.runners.model.Statement; -//import org.junit.runners.model.TestClass; -//import org.slf4j.Logger; -//import ru.vyarus.java.generics.resolver.GenericsResolver; -//import ru.vyarus.java.generics.resolver.context.MethodGenericsContext; -// -//import java.lang.reflect.Parameter; -//import java.util.ArrayList; -//import java.util.Arrays; -//import java.util.List; -//import java.util.Random; -//import java.util.stream.Stream; -// -//import static org.utbot.quickcheck.runner.PropertyFalsified.counterexampleFound; -//import static java.util.stream.Collectors.toList; -// -//class PropertyStatement extends Statement { -// private final FrameworkMethod method; -// private final TestClass testClass; -// private final GeneratorRepository repo; -// private final GeometricDistribution distro; -// private final List assumptionViolations; -// private final Logger logger; -// -// private int successes; -// -// PropertyStatement( -// FrameworkMethod method, -// TestClass testClass, -// GeneratorRepository repo, -// GeometricDistribution distro, -// Logger logger) { -// -// this.method = method; -// this.testClass = testClass; -// this.repo = repo; -// this.distro = distro; -// assumptionViolations = new ArrayList<>(); -// this.logger = logger; -// } -// -// @Override public void evaluate() throws Throwable { -// Property marker = method.getAnnotation(Property.class); -// ParameterSampler sampler = sampler(marker); -// ShrinkControl shrinkControl = new ShrinkControl(marker); -// -// MethodGenericsContext generics = -// GenericsResolver.resolve(testClass.getJavaClass()) -// .method(method.getMethod()); -// List paramContexts = -// Arrays.stream(method.getMethod().getParameters()) -// .map(p -> parameterContextFor(p, generics)) -// .map(p -> new PropertyParameterGenerationContext( -// p, -// repo, -// distro, -// new SourceOfRandomness(new Random()), -// sampler -// )) -// .collect(toList()); -// -// Stream> sample = sampler.sample(paramContexts); -// for (List args : -// (Iterable>) sample::iterator) { -// -// property(args, shrinkControl).verify(); -// } -// -// if (successes == 0 && !assumptionViolations.isEmpty()) { -// throw new NoValuesSatisfiedPropertyAssumptions( -// assumptionViolations); -// } -// } -// -// private org.utbot.quickcheck.runner.PropertyVerifier property( -// List arguments, -// ShrinkControl shrinkControl) -// throws InitializationError { -// -// if (logger.isDebugEnabled()) { -// logger.debug( -// "Verifying property {} from {} with these values:", -// method.getName(), -// testClass.getName()); -// logger.debug("{}", Arrays.deepToString(arguments.toArray())); -// } -// -// List params = -// arguments.stream().map(SeededValue::parameter).collect(toList()); -// Object[] args = arguments.stream().map(SeededValue::value).toArray(); -// long[] seeds = -// arguments.stream().mapToLong(SeededValue::seed).toArray(); -// -// return new org.utbot.quickcheck.runner.PropertyVerifier( -// testClass, -// method, -// args, -// seeds, -// s -> ++successes, -// assumptionViolations::add, -// (e, action) -> { -// if (!shrinkControl.shouldShrink()) { -// shrinkControl.onMinimalCounterexample() -// .handle(args, action); -// throw counterexampleFound( -// method.getName(), -// args, -// seeds, -// e); -// } -// -// try { -// shrink(params, args, seeds, shrinkControl, e); -// } catch (AssertionError ex) { -// throw ex; -// } catch (Throwable ex) { -// throw new AssertionError(ex); -// } -// } -// ); -// } -// -// private void shrink( -// List params, -// Object[] args, -// long[] seeds, -// ShrinkControl shrinkControl, -// AssertionError failure) -// throws Throwable { -// -// new Shrinker( -// method, -// testClass, -// failure, -// shrinkControl) -// .shrink(params, args, seeds); -// } -// -// private PropertyParameterContext parameterContextFor( -// Parameter parameter, -// MethodGenericsContext generics) { -// -// return new PropertyParameterContext( -// ParameterTypeContext.forParameter(parameter, generics) -// .allowMixedTypes(true) -// ).annotate(parameter); -// } -// -// private ParameterSampler sampler(Property marker) { -// switch (marker.mode()) { -// case SAMPLING: -// return new TupleParameterSampler(marker.trials()); -// case EXHAUSTIVE: -// return new ExhaustiveParameterSampler(marker.trials()); -// default: -// throw new AssertionError( -// "Don't recognize mode " + marker.mode()); -// } -// } -//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyVerifier.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyVerifier.java deleted file mode 100644 index 920f2c2f06..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/PropertyVerifier.java +++ /dev/null @@ -1,122 +0,0 @@ -///* -// The MIT License -// -// Copyright (c) 2010-2021 Paul R. Holser, Jr. -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -//*/ -// -//package org.utbot.quickcheck.runner; -// -//import org.junit.internal.AssumptionViolatedException; -//import org.junit.runners.BlockJUnit4ClassRunner; -//import org.junit.runners.model.FrameworkMethod; -//import org.junit.runners.model.InitializationError; -//import org.junit.runners.model.Statement; -//import org.junit.runners.model.TestClass; -// -//import java.util.Arrays; -//import java.util.List; -//import java.util.function.BiConsumer; -//import java.util.function.Consumer; -// -//class PropertyVerifier extends BlockJUnit4ClassRunner { -// private final FrameworkMethod method; -// private final Object[] args; -// private final long[] seeds; -// private final Consumer onSuccess; -// private final Consumer onAssumptionViolated; -// private final BiConsumer onFailure; -// -// PropertyVerifier( -// TestClass clazz, -// FrameworkMethod method, -// Object[] args, -// long[] seeds, -// Consumer onSuccess, -// Consumer onAssumptionViolated, -// BiConsumer onFailure) -// throws InitializationError { -// -// super(clazz.getJavaClass()); -// -// this.method = method; -// this.args = args; -// this.seeds = seeds; -// this.onSuccess = onSuccess; -// this.onAssumptionViolated = onAssumptionViolated; -// this.onFailure = onFailure; -// } -// -// void verify() throws Throwable { -// methodBlock().evaluate(); -// } -// -// private Statement methodBlock() { -// Statement statement = super.methodBlock(method); -// return new Statement() { -// @Override public void evaluate() { -// try { -// statement.evaluate(); -// onSuccess.accept(null); -// } catch (AssumptionViolatedException e) { -// onAssumptionViolated.accept(e); -// } catch (AssertionError e) { -// Runnable repeat = () -> { -// try { -// statement.evaluate(); -// } catch (Throwable ignored) { -// } -// }; -// onFailure.accept(e, repeat); -// } catch (Throwable t) { -// reportErrorWithArguments(t); -// } -// } -// }; -// } -// -// @Override protected void collectInitializationErrors( -// List errors) { -// -// // do nothing -// } -// -// @Override protected Statement methodInvoker( -// FrameworkMethod frameworkMethod, -// Object test) { -// -// return new Statement() { -// @Override public void evaluate() throws Throwable { -// frameworkMethod.invokeExplosively(test, args); -// } -// }; -// } -// -// private void reportErrorWithArguments(Throwable e) { -// throw new AssertionError( -// String.format( -// "Unexpected error in property %s with args %s and seeds %s", -// method.getName(), -// Arrays.deepToString(args), -// Arrays.toString(seeds)), -// e); -// } -//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/ShrinkNode.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/ShrinkNode.java deleted file mode 100644 index f1383082f5..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/ShrinkNode.java +++ /dev/null @@ -1,223 +0,0 @@ -///* -// The MIT License -// -// Copyright (c) 2010-2021 Paul R. Holser, Jr. -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -//*/ -// -//package org.utbot.quickcheck.runner; -// -//import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; -//import org.junit.runners.model.FrameworkMethod; -//import org.junit.runners.model.InitializationError; -//import org.junit.runners.model.TestClass; -// -//import java.math.BigDecimal; -//import java.util.Arrays; -//import java.util.Comparator; -//import java.util.List; -//import java.util.stream.IntStream; -// -//import static org.utbot.quickcheck.runner.PropertyFalsified.counterexampleFound; -//import static org.utbot.quickcheck.runner.PropertyFalsified.smallerCounterexampleFound; -//import static java.util.Comparator.comparing; -//import static java.util.function.Function.identity; -//import static java.util.stream.Collectors.toList; -// -//final class ShrinkNode implements Comparable { -// private final FrameworkMethod method; -// private final TestClass testClass; -// private final List params; -// private final Object[] args; -// private final long[] seeds; -// private final int[] depths; -// private final int totalDepth; -// private final BigDecimal totalMagnitude; -// -// private AssertionError failure; -// -// private ShrinkNode( -// FrameworkMethod method, -// TestClass testClass, -// List params, -// Object[] args, -// long[] seeds, -// int[] depths, -// AssertionError failure) { -// -// this.method = method; -// this.testClass = testClass; -// this.params = params; -// this.args = args; -// this.seeds = seeds; -// this.depths = depths; -// this.totalDepth = IntStream.of(depths).sum(); -// this.totalMagnitude = computeTotalMagnitude(); -// -// this.failure = failure; -// } -// -// static ShrinkNode root( -// FrameworkMethod method, -// TestClass testClass, -// List params, -// Object[] args, -// long[] seeds, -// AssertionError failure) { -// -// return new ShrinkNode( -// method, -// testClass, -// params, -// args, -// seeds, -// new int[args.length], -// failure); -// } -// -// List shrinks() { -// return IntStream.range(0, params.size()) -// .mapToObj(i -> params.get(i).shrink(args[i]).stream() -// .filter(o -> !o.equals(args[i])) -// .map(o -> shrinkNodeFor(o, i))) -// .flatMap(identity()) -// .collect(toList()); -// } -// -// boolean verifyProperty() throws Throwable { -// boolean[] result = new boolean[1]; -// -// property(result).verify(); -// -// return result[0]; -// } -// -// AssertionError fail( -// AssertionError originalFailure, -// Object[] originalArgs) { -// -// return originalFailure == failure -// ? counterexampleFound( -// method.getName(), -// args, -// seeds, -// failure) -// : smallerCounterexampleFound( -// method.getName(), -// originalArgs, -// args, -// seeds, -// failure, -// originalFailure); -// } -// -// Object[] args() { -// return args; -// } -// -// int depth() { -// return totalDepth; -// } -// -// BigDecimal magnitude() { -// return totalMagnitude; -// } -// -// private org.utbot.quickcheck.runner.PropertyVerifier property(boolean[] result) -// throws InitializationError { -// -// return new org.utbot.quickcheck.runner.PropertyVerifier( -// testClass, -// method, -// args, -// seeds, -// s -> result[0] = true, -// v -> result[0] = true, -// (e, repeatTestOption) -> { -// failure = e; -// result[0] = false; -// }); -// } -// -// private ShrinkNode shrinkNodeFor(Object shrunk, int index) { -// Object[] shrunkArgs = new Object[args.length]; -// System.arraycopy(args, 0, shrunkArgs, 0, args.length); -// shrunkArgs[index] = shrunk; -// -// int[] newDepths = new int[depths.length]; -// System.arraycopy(depths, 0, newDepths, 0, depths.length); -// ++newDepths[index]; -// -// return new ShrinkNode( -// method, -// testClass, -// params, -// shrunkArgs, -// seeds, -// newDepths, -// failure); -// } -// -// private BigDecimal computeTotalMagnitude() { -// BigDecimal total = BigDecimal.ZERO; -// -// for (int i = 0; i < args.length; ++i) { -// BigDecimal magnitude = magnitudeAt(i); -// BigDecimal factor = BigDecimal.valueOf(2).pow(args.length - i - 1); -// total = total.add(magnitude.multiply(factor)); -// } -// -// return total; -// } -// -// private BigDecimal magnitudeAt(int index) { -// return params.get(index).magnitude(args[index]); -// } -// -// @Override public boolean equals(Object o) { -// if (!(o instanceof ShrinkNode)) -// return false; -// -// ShrinkNode other = (ShrinkNode) o; -// return Arrays.equals(args, other.args) -// && Arrays.equals(depths, other.depths); -// } -// -// @Override public int hashCode() { -// return Arrays.hashCode(args) ^ Arrays.hashCode(depths); -// } -// -// @Override public int compareTo(ShrinkNode other) { -// // Nodes at lesser depth compare less than nodes of greater depth. -// // Nodes at equal depth needs to compare their args one by one. -// // prefer larger-magnitude args before smaller. -// -// Comparator comparison = comparing(ShrinkNode::depth); -// for (int i = 0; i < params.size(); ++i) { -// int index = i; -// Comparator byMagnitude = -// comparing(s -> s.magnitudeAt(index)); -// comparison = comparison.thenComparing(byMagnitude.reversed()); -// } -// -// return comparison.compare(this, other); -// } -//} diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/Shrinker.java b/utbot-framework/src/main/java/org/utbot/quickcheck/runner/Shrinker.java deleted file mode 100644 index b290ce9f7e..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/runner/Shrinker.java +++ /dev/null @@ -1,111 +0,0 @@ -///* -// The MIT License -// -// Copyright (c) 2010-2021 Paul R. Holser, Jr. -// -// Permission is hereby granted, free of charge, to any person obtaining -// a copy of this software and associated documentation files (the -// "Software"), to deal in the Software without restriction, including -// without limitation the rights to use, copy, modify, merge, publish, -// distribute, sublicense, and/or sell copies of the Software, and to -// permit persons to whom the Software is furnished to do so, subject to -// the following conditions: -// -// The above copyright notice and this permission notice shall be -// included in all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -//*/ -// -//package org.utbot.quickcheck.runner; -// -//import org.utbot.quickcheck.MinimalCounterexampleHook; -//import org.utbot.quickcheck.internal.ShrinkControl; -//import org.utbot.quickcheck.internal.generator.PropertyParameterGenerationContext; -//import org.junit.runners.model.FrameworkMethod; -//import org.junit.runners.model.TestClass; -// -//import java.util.ArrayDeque; -//import java.util.List; -//import java.util.Queue; -// -//class Shrinker { -// private final FrameworkMethod method; -// private final TestClass testClass; -// private final AssertionError failure; -// private final int maxShrinks; -// private final int maxShrinkDepth; -// private final int maxShrinkTime; -// private final MinimalCounterexampleHook onMinimalCounterexample; -// -// private int shrinkAttempts; -// private long shrinkTimeout; -// -// Shrinker( -// FrameworkMethod method, -// TestClass testClass, -// AssertionError failure, -// ShrinkControl shrinkControl) { -// -// this.method = method; -// this.testClass = testClass; -// this.failure = failure; -// this.maxShrinks = shrinkControl.maxShrinks(); -// this.maxShrinkDepth = -// shrinkControl.maxShrinkDepth() * method.getMethod().getParameterCount(); -// this.maxShrinkTime = shrinkControl.maxShrinkTime(); -// this.onMinimalCounterexample = shrinkControl.onMinimalCounterexample(); -// } -// -// void shrink( -// List params, -// Object[] args, -// long[] seeds) -// throws Throwable { -// -// org.utbot.quickcheck.runner.ShrinkNode smallest = -// org.utbot.quickcheck.runner.ShrinkNode.root(method, testClass, params, args, seeds, failure); -// Queue nodes = new ArrayDeque<>(smallest.shrinks()); -// -// shrinkTimeout = System.currentTimeMillis() + maxShrinkTime; -// -// while (shouldContinueShrinking(nodes)) { -// org.utbot.quickcheck.runner.ShrinkNode next = nodes.poll(); -// -// boolean result = next.verifyProperty(); -// ++shrinkAttempts; -// -// if (!result) { -// smallest = next; -// nodes = new ArrayDeque<>(smallest.shrinks()); -// } -// } -// -// handleMinimalCounterexample(smallest); -// throw smallest.fail(failure, args); -// } -// -// private void handleMinimalCounterexample(org.utbot.quickcheck.runner.ShrinkNode counterexample) { -// Runnable repeat = () -> { -// try { -// counterexample.verifyProperty(); -// } catch (Throwable ignored) { -// } -// }; -// -// onMinimalCounterexample.handle(counterexample.args(), repeat); -// } -// -// private boolean shouldContinueShrinking(Queue nodes) { -// return shrinkAttempts < maxShrinks -// && shrinkTimeout >= System.currentTimeMillis() -// && !nodes.isEmpty() -// && nodes.peek().depth() <= maxShrinkDepth; -// } -//} diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt index 342ba86de4..54877ac4ce 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt @@ -75,5 +75,8 @@ object GreyBoxFuzzerGenerators { it.register(PrimitiveIntGenerator()) it.register(PrimitiveLongGenerator()) it.register(PrimitiveShortGenerator()) + it.register(RFC4122.Version3()) + it.register(RFC4122.Version4()) + it.register(RFC4122.Version5()) } } \ No newline at end of file From d823f2928926704eb5a0e0f9281fd8ccccafb7f0 Mon Sep 17 00:00:00 2001 From: Saloed Date: Thu, 10 Nov 2022 19:51:25 +0300 Subject: [PATCH 04/30] Rename .java to .kt --- .../org/utbot/quickcheck/NonTrackingGenerationStatus.kt} | 0 .../org/utbot/quickcheck/generator/ComponentizedGenerator.kt} | 0 .../org/utbot/quickcheck/generator/DecimalGenerator.kt} | 0 .../org/utbot/quickcheck/generator/Distinct.kt} | 0 .../Gen.java => kotlin/org/utbot/quickcheck/generator/Gen.kt} | 0 .../org/utbot/quickcheck/generator/GenerationStatus.kt} | 0 .../org/utbot/quickcheck/generator/Generator.kt} | 0 .../org/utbot/quickcheck/generator/GeneratorConfiguration.kt} | 0 .../quickcheck/generator/GeneratorConfigurationException.kt} | 0 .../org/utbot/quickcheck/generator/Generators.kt} | 0 .../org/utbot/quickcheck/generator/InRange.kt} | 0 .../org/utbot/quickcheck/generator/IntegralGenerator.kt} | 0 .../org/utbot/quickcheck/generator/Lambdas.kt} | 0 .../org/utbot/quickcheck/generator/NullAllowed.kt} | 0 .../org/utbot/quickcheck/generator/Precision.kt} | 0 .../Size.java => kotlin/org/utbot/quickcheck/generator/Size.kt} | 0 .../org/utbot/quickcheck/generator/VoidGenerator.kt} | 0 .../quickcheck/generator/java/lang/AbstractStringGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt} | 0 .../utbot/quickcheck/generator/java/lang/CharacterGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/lang/Encoded.kt} | 0 .../org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/lang/LongGenerator.kt} | 0 .../quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt} | 0 .../quickcheck/generator/java/lang/PrimitiveByteGenerator.kt} | 0 .../quickcheck/generator/java/lang/PrimitiveCharGenerator.kt} | 0 .../quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt} | 0 .../quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt} | 0 .../quickcheck/generator/java/lang/PrimitiveIntGenerator.kt} | 0 .../quickcheck/generator/java/lang/PrimitiveLongGenerator.kt} | 0 .../quickcheck/generator/java/lang/PrimitiveShortGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/lang/StringGenerator.kt} | 0 .../utbot/quickcheck/generator/java/lang/strings/CodePoints.kt} | 0 .../utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt} | 0 .../utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt} | 0 .../quickcheck/generator/java/nio/charset/CharsetGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/time/ClockGenerator.kt} | 0 .../utbot/quickcheck/generator/java/time/DurationGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/time/InstantGenerator.kt} | 0 .../utbot/quickcheck/generator/java/time/LocalDateGenerator.kt} | 0 .../quickcheck/generator/java/time/LocalDateTimeGenerator.kt} | 0 .../utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt} | 0 .../utbot/quickcheck/generator/java/time/MonthDayGenerator.kt} | 0 .../quickcheck/generator/java/time/OffsetDateTimeGenerator.kt} | 0 .../utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/time/YearGenerator.kt} | 0 .../utbot/quickcheck/generator/java/time/YearMonthGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt} | 0 .../utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt} | 0 .../quickcheck/generator/java/time/ZonedDateTimeGenerator.kt} | 0 .../utbot/quickcheck/generator/java/util/ArrayListGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt} | 0 .../utbot/quickcheck/generator/java/util/CollectionGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/DateGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt} | 0 .../utbot/quickcheck/generator/java/util/HashtableGenerator.kt} | 0 .../quickcheck/generator/java/util/LinkedHashMapGenerator.kt} | 0 .../quickcheck/generator/java/util/LinkedHashSetGenerator.kt} | 0 .../utbot/quickcheck/generator/java/util/LinkedListGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/ListGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/MapGenerator.kt} | 0 .../quickcheck/generator/java/util/OptionalDoubleGenerator.kt} | 0 .../utbot/quickcheck/generator/java/util/OptionalGenerator.kt} | 0 .../utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt} | 0 .../quickcheck/generator/java/util/OptionalLongGenerator.kt} | 0 .../utbot/quickcheck/generator/java/util/PropertiesGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/RFC4122.kt} | 0 .../org/utbot/quickcheck/generator/java/util/SetGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/StackGenerator.kt} | 0 .../utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt} | 0 .../org/utbot/quickcheck/generator/java/util/VectorGenerator.kt} | 0 .../generator/java/util/concurrent/CallableGenerator.kt} | 0 .../generator/java/util/function/BiFunctionGenerator.kt} | 0 .../generator/java/util/function/BiPredicateGenerator.kt} | 0 .../generator/java/util/function/BinaryOperatorGenerator.kt} | 0 .../generator/java/util/function/DoubleFunctionGenerator.kt} | 0 .../quickcheck/generator/java/util/function/FunctionGenerator.kt} | 0 .../generator/java/util/function/IntFunctionGenerator.kt} | 0 .../generator/java/util/function/LongFunctionGenerator.kt} | 0 .../generator/java/util/function/PredicateGenerator.kt} | 0 .../quickcheck/generator/java/util/function/SupplierGenerator.kt} | 0 .../generator/java/util/function/ToDoubleBiFunctionGenerator.kt} | 0 .../generator/java/util/function/ToDoubleFunctionGenerator.kt} | 0 .../generator/java/util/function/ToIntBiFunctionGenerator.kt} | 0 .../generator/java/util/function/ToIntFunctionGenerator.kt} | 0 .../generator/java/util/function/ToLongBiFunctionGenerator.kt} | 0 .../generator/java/util/function/ToLongFunctionGenerator.kt} | 0 .../generator/java/util/function/UnaryOperatorGenerator.kt} | 0 .../org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt} | 0 .../org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt} | 0 .../org/utbot/quickcheck/internal/GeometricDistribution.kt} | 0 .../Items.java => kotlin/org/utbot/quickcheck/internal/Items.kt} | 0 .../org/utbot/quickcheck/internal/ParameterTypeContext.kt} | 0 .../org/utbot/quickcheck/internal/Ranges.kt} | 0 .../org/utbot/quickcheck/internal/Reflection.kt} | 0 .../org/utbot/quickcheck/internal/ReflectionException.kt} | 0 .../org/utbot/quickcheck/internal/Weighted.kt} | 0 .../Zilch.java => kotlin/org/utbot/quickcheck/internal/Zilch.kt} | 0 .../quickcheck/internal/generator/AbstractGenerationStatus.kt} | 0 .../org/utbot/quickcheck/internal/generator/ArrayGenerator.kt} | 0 .../utbot/quickcheck/internal/generator/CompositeGenerator.kt} | 0 .../org/utbot/quickcheck/internal/generator/EnumGenerator.kt} | 0 .../utbot/quickcheck/internal/generator/GeneratorRepository.kt} | 0 .../org/utbot/quickcheck/internal/generator/LambdaGenerator.kt} | 0 .../quickcheck/internal/generator/MarkerInterfaceGenerator.kt} | 0 .../org/utbot/quickcheck/internal/generator/NullableGenerator.kt} | 0 .../quickcheck/internal/generator/SimpleGenerationStatus.kt} | 0 .../org/utbot/quickcheck/internal/generator/ZilchGenerator.kt} | 0 .../org/utbot/quickcheck/random/SourceOfRandomness.kt} | 0 116 files changed, 0 insertions(+), 0 deletions(-) rename utbot-framework/src/main/{java/org/utbot/quickcheck/NonTrackingGenerationStatus.java => kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/ComponentizedGenerator.java => kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/DecimalGenerator.java => kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/Distinct.java => kotlin/org/utbot/quickcheck/generator/Distinct.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/Gen.java => kotlin/org/utbot/quickcheck/generator/Gen.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/GenerationStatus.java => kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/Generator.java => kotlin/org/utbot/quickcheck/generator/Generator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/GeneratorConfiguration.java => kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java => kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/Generators.java => kotlin/org/utbot/quickcheck/generator/Generators.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/InRange.java => kotlin/org/utbot/quickcheck/generator/InRange.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/IntegralGenerator.java => kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/Lambdas.java => kotlin/org/utbot/quickcheck/generator/Lambdas.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/NullAllowed.java => kotlin/org/utbot/quickcheck/generator/NullAllowed.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/Precision.java => kotlin/org/utbot/quickcheck/generator/Precision.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/Size.java => kotlin/org/utbot/quickcheck/generator/Size.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/VoidGenerator.java => kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/Encoded.java => kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java => kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java => kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java => kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java => kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java => kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/YearGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java => kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/DateGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/ListGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/MapGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/RFC4122.java => kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/SetGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/StackGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java => kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.java => kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java => kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/GeometricDistribution.java => kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/Items.java => kotlin/org/utbot/quickcheck/internal/Items.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/ParameterTypeContext.java => kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/Ranges.java => kotlin/org/utbot/quickcheck/internal/Ranges.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/Reflection.java => kotlin/org/utbot/quickcheck/internal/Reflection.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/ReflectionException.java => kotlin/org/utbot/quickcheck/internal/ReflectionException.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/Weighted.java => kotlin/org/utbot/quickcheck/internal/Weighted.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/Zilch.java => kotlin/org/utbot/quickcheck/internal/Zilch.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java => kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java => kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java => kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/EnumGenerator.java => kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java => kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java => kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java => kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/NullableGenerator.java => kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java => kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java => kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt} (100%) rename utbot-framework/src/main/{java/org/utbot/quickcheck/random/SourceOfRandomness.java => kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt} (100%) diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/NonTrackingGenerationStatus.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/ComponentizedGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/DecimalGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Distinct.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/Distinct.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Distinct.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Gen.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/Gen.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Gen.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/GenerationStatus.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfiguration.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/GeneratorConfigurationException.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generators.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/Generators.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generators.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/InRange.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/InRange.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/InRange.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/IntegralGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/Lambdas.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/NullAllowed.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/NullAllowed.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/NullAllowed.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/NullAllowed.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Precision.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/Precision.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Precision.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Size.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/Size.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Size.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/VoidGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ByteGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/Encoded.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/FloatGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/LongGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/ShortGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/StringGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ClockGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/DurationGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/InstantGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/PeriodGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/BitSetGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/CollectionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/DateGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashMapGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashSetGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/HashtableGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/ListGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/LocaleGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/MapGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/RFC4122.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/SetGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/StackGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/VectorGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/GeometricDistribution.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Items.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/Items.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Items.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/ParameterTypeContext.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Ranges.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/Ranges.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Ranges.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Reflection.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/Reflection.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Reflection.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ReflectionException.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/ReflectionException.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ReflectionException.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Weighted.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/Weighted.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Weighted.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/Zilch.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ArrayGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/CompositeGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/EnumGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/GeneratorRepository.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/LambdaGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/NullableGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/generator/ZilchGenerator.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/random/SourceOfRandomness.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt From 13436668de9d1ac03d9533a8c0006fbc23f6acc8 Mon Sep 17 00:00:00 2001 From: Saloed Date: Thu, 10 Nov 2022 19:51:25 +0300 Subject: [PATCH 05/30] rewrite quickcheck on Kotlin --- .../quickcheck/internal/Comparables.java | 25 - .../greyboxfuzzer/generator/DataGenerator.kt | 2 +- .../engine/greyboxfuzzer/generator/FField.kt | 8 +- .../greyboxfuzzer/generator/FParameter.kt | 6 +- .../generator/GeneratorConfigurator.kt | 7 +- .../generator/QuickCheckExtensions.kt | 18 +- .../generator/UTGeneratorRepository.kt | 12 +- .../generator/set/HashSetGenerator.kt | 2 +- .../userclasses/UserClassGenerator.kt | 17 +- .../generator/ClassesInstanceGenerator.kt | 6 +- .../ConstructorBasedInstanceGenerator.kt | 4 +- .../generator/InstanceGenerator.kt | 2 +- ...terfaceImplementationsInstanceGenerator.kt | 103 +-- .../userclasses/generator/ObjectGenerator.kt | 32 +- .../generator/ReflectionClassGenerator.kt | 27 +- .../StaticsBasedInstanceGenerator.kt | 2 +- .../StaticsFieldBasedInstanceGenerator.kt | 4 +- .../StaticsMethodBasedInstanceGenerator.kt | 4 +- .../quickcheck/NonTrackingGenerationStatus.kt | 68 +- .../generator/ComponentizedGenerator.kt | 107 ++- .../quickcheck/generator/DecimalGenerator.kt | 33 +- .../utbot/quickcheck/generator/Distinct.kt | 32 +- .../org/utbot/quickcheck/generator/Gen.kt | 21 +- .../quickcheck/generator/GenerationStatus.kt | 15 +- .../utbot/quickcheck/generator/Generator.kt | 329 ++++----- .../generator/GeneratorConfiguration.kt | 31 +- .../GeneratorConfigurationException.kt | 20 +- .../utbot/quickcheck/generator/Generators.kt | 57 +- .../org/utbot/quickcheck/generator/InRange.kt | 108 ++- .../quickcheck/generator/IntegralGenerator.kt | 35 +- .../org/utbot/quickcheck/generator/Lambdas.kt | 224 +++--- .../utbot/quickcheck/generator/NullAllowed.kt | 25 +- .../utbot/quickcheck/generator/Precision.kt | 25 +- .../org/utbot/quickcheck/generator/Size.kt | 29 +- .../quickcheck/generator/VoidGenerator.kt | 39 +- .../java/lang/AbstractStringGenerator.kt | 57 +- .../generator/java/lang/BooleanGenerator.kt | 42 +- .../generator/java/lang/ByteGenerator.kt | 73 +- .../generator/java/lang/CharacterGenerator.kt | 61 +- .../generator/java/lang/DoubleGenerator.kt | 79 +- .../quickcheck/generator/java/lang/Encoded.kt | 58 +- .../generator/java/lang/FloatGenerator.kt | 68 +- .../generator/java/lang/IntegerGenerator.kt | 76 +- .../generator/java/lang/LongGenerator.kt | 76 +- .../java/lang/PrimitiveBooleanGenerator.kt | 38 +- .../java/lang/PrimitiveByteGenerator.kt | 69 +- .../java/lang/PrimitiveCharGenerator.kt | 59 +- .../java/lang/PrimitiveDoubleGenerator.kt | 79 +- .../java/lang/PrimitiveFloatGenerator.kt | 70 +- .../java/lang/PrimitiveIntGenerator.kt | 77 +- .../java/lang/PrimitiveLongGenerator.kt | 78 +- .../java/lang/PrimitiveShortGenerator.kt | 70 +- .../generator/java/lang/ShortGenerator.kt | 70 +- .../generator/java/lang/StringGenerator.kt | 20 +- .../generator/java/lang/strings/CodePoints.kt | 213 +++--- .../java/math/BigDecimalGenerator.kt | 183 ++--- .../java/math/BigIntegerGenerator.kt | 115 ++- .../java/nio/charset/CharsetGenerator.kt | 86 +-- .../generator/java/time/ClockGenerator.kt | 142 ++-- .../generator/java/time/DurationGenerator.kt | 82 +-- .../generator/java/time/InstantGenerator.kt | 84 +-- .../generator/java/time/LocalDateGenerator.kt | 97 ++- .../java/time/LocalDateTimeGenerator.kt | 113 ++- .../generator/java/time/LocalTimeGenerator.kt | 99 ++- .../generator/java/time/MonthDayGenerator.kt | 103 ++- .../java/time/OffsetDateTimeGenerator.kt | 108 ++- .../java/time/OffsetTimeGenerator.kt | 118 ++- .../generator/java/time/PeriodGenerator.kt | 124 ++-- .../generator/java/time/YearGenerator.kt | 92 +-- .../generator/java/time/YearMonthGenerator.kt | 109 ++- .../generator/java/time/ZoneIdGenerator.kt | 44 +- .../java/time/ZoneOffsetGenerator.kt | 101 ++- .../java/time/ZonedDateTimeGenerator.kt | 119 ++- .../generator/java/util/ArrayListGenerator.kt | 16 +- .../generator/java/util/BitSetGenerator.kt | 51 +- .../java/util/CollectionGenerator.kt | 167 ++--- .../generator/java/util/DateGenerator.kt | 101 ++- .../generator/java/util/HashMapGenerator.kt | 16 +- .../generator/java/util/HashSetGenerator.kt | 16 +- .../generator/java/util/HashtableGenerator.kt | 22 +- .../java/util/LinkedHashMapGenerator.kt | 16 +- .../java/util/LinkedHashSetGenerator.kt | 16 +- .../java/util/LinkedListGenerator.kt | 16 +- .../generator/java/util/ListGenerator.kt | 20 +- .../generator/java/util/LocaleGenerator.kt | 46 +- .../generator/java/util/MapGenerator.kt | 163 ++-- .../java/util/OptionalDoubleGenerator.kt | 67 +- .../generator/java/util/OptionalGenerator.kt | 86 +-- .../java/util/OptionalIntGenerator.kt | 67 +- .../java/util/OptionalLongGenerator.kt | 66 +- .../java/util/PropertiesGenerator.kt | 136 ++-- .../quickcheck/generator/java/util/RFC4122.kt | 234 +++--- .../generator/java/util/SetGenerator.kt | 31 +- .../generator/java/util/StackGenerator.kt | 16 +- .../generator/java/util/TimeZoneGenerator.kt | 47 +- .../generator/java/util/VectorGenerator.kt | 16 +- .../java/util/concurrent/CallableGenerator.kt | 58 +- .../java/util/function/BiFunctionGenerator.kt | 60 +- .../util/function/BiPredicateGenerator.kt | 69 +- .../util/function/BinaryOperatorGenerator.kt | 59 +- .../util/function/DoubleFunctionGenerator.kt | 59 +- .../java/util/function/FunctionGenerator.kt | 57 +- .../util/function/IntFunctionGenerator.kt | 59 +- .../util/function/LongFunctionGenerator.kt | 59 +- .../java/util/function/PredicateGenerator.kt | 69 +- .../java/util/function/SupplierGenerator.kt | 57 +- .../function/ToDoubleBiFunctionGenerator.kt | 70 +- .../function/ToDoubleFunctionGenerator.kt | 70 +- .../util/function/ToIntBiFunctionGenerator.kt | 70 +- .../util/function/ToIntFunctionGenerator.kt | 70 +- .../function/ToLongBiFunctionGenerator.kt | 70 +- .../util/function/ToLongFunctionGenerator.kt | 71 +- .../util/function/UnaryOperatorGenerator.kt | 59 +- .../internal/DefaultMethodHandleMaker.kt | 81 +- .../internal/FakeAnnotatedTypeFactory.kt | 109 ++- .../internal/GeometricDistribution.kt | 49 +- .../org/utbot/quickcheck/internal/Items.kt | 79 +- .../internal/ParameterTypeContext.kt | 693 ++++++++---------- .../org/utbot/quickcheck/internal/Ranges.kt | 130 ++-- .../utbot/quickcheck/internal/Reflection.kt | 437 +++++------ .../internal/ReflectionException.kt | 19 +- .../org/utbot/quickcheck/internal/Weighted.kt | 24 +- .../org/utbot/quickcheck/internal/Zilch.kt | 12 +- .../generator/AbstractGenerationStatus.kt | 40 +- .../internal/generator/ArrayGenerator.kt | 170 ++--- .../internal/generator/CompositeGenerator.kt | 156 ++-- .../internal/generator/EnumGenerator.kt | 48 +- .../internal/generator/GeneratorRepository.kt | 471 ++++++------ .../internal/generator/LambdaGenerator.kt | 50 +- .../generator/MarkerInterfaceGenerator.kt | 133 ++-- .../internal/generator/NullableGenerator.kt | 121 ++- .../generator/SimpleGenerationStatus.kt | 35 +- .../internal/generator/ZilchGenerator.kt | 37 +- .../quickcheck/random/SourceOfRandomness.kt | 375 +++++----- 134 files changed, 4465 insertions(+), 6153 deletions(-) delete mode 100644 utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java b/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java deleted file mode 100644 index 4db8182c04..0000000000 --- a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/Comparables.java +++ /dev/null @@ -1,25 +0,0 @@ - - -package org.utbot.quickcheck.internal; - -import java.util.function.Predicate; - -public final class Comparables { - private Comparables() { - throw new UnsupportedOperationException(); - } - - public static > - Predicate inRange(T min, T max) { - return c -> { - if (min == null && max == null) - return true; - if (min == null) - return c.compareTo(max) <= 0; - if (max == null) - return c.compareTo(min) >= 0; - return c.compareTo(min) >= 0 && c.compareTo(max) <= 0; - }; - } - -} diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt index ae2829650f..d1470178ab 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt @@ -46,7 +46,7 @@ object DataGenerator { } fun generate( - generator: Generator<*>?, + generator: Generator?, parameter: Parameter, random: SourceOfRandomness, status: GenerationStatus, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt index 6bb01acb50..50bdbba9e1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt @@ -11,7 +11,7 @@ data class FField( val field: Field?, val value: Any?, val resolvedType: Type, - val generator: Generator<*>?, + val generator: Generator?, val classId: ClassId, val subFields: List, var isBlocked: Boolean, @@ -21,7 +21,7 @@ data class FField( field: Field?, value: Any?, resolvedType: Type, - generator: Generator<*>?, + generator: Generator?, subFields: List, isBlocked: Boolean ) : this( @@ -38,7 +38,7 @@ data class FField( field: Field?, value: Any?, resolvedType: Type, - generator: Generator<*>?, + generator: Generator?, subFields: List, ) : this( field, @@ -54,7 +54,7 @@ data class FField( field: Field?, value: Any?, resolvedType: Type, - generator: Generator<*>?, + generator: Generator?, ) : this( field, value, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt index 9162715a5a..65b2bb652d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt @@ -15,7 +15,7 @@ data class FParameter( val parameter: Parameter, val value: Any?, var utModel: UtModel, - val generator: Generator<*>?, + val generator: Generator?, val classId: ClassId, val fields: List ) { @@ -24,14 +24,14 @@ data class FParameter( parameter: Parameter, value: Any?, utModel: UtModel, - generator: Generator<*>? + generator: Generator? ) : this(parameter, value, utModel, generator, classIdForType(parameter.type), emptyList()) constructor( parameter: Parameter, value: Any?, utModel: UtModel, - generator: Generator<*>?, + generator: Generator?, fields: List ) : this(parameter, value, utModel, generator, classIdForType(parameter.type), fields) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt index 9fc517bea8..88a57a7f46 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt @@ -7,7 +7,6 @@ import org.utbot.quickcheck.generator.java.util.CollectionGenerator import org.utbot.quickcheck.generator.java.util.MapGenerator import org.utbot.quickcheck.internal.generator.ArrayGenerator import org.utbot.engine.greyboxfuzzer.util.getTrue -import org.utbot.engine.greyboxfuzzer.util.setFieldValue import org.utbot.quickcheck.generator.java.lang.* import kotlin.random.Random @@ -66,13 +65,13 @@ object GeneratorConfigurator { inRangeAnnotationInstance = InRange::class.constructors.first().callBy(inRangeAnnotationParams) } - fun configureGenerator(generator: Generator<*>, prob: Int) { + fun configureGenerator(generator: Generator, prob: Int) { (listOf(generator) + generator.getAllComponents()).forEach { if (Random.getTrue(prob)) handleGenerator(it) } } - private fun handleGenerator(generator: Generator<*>) = + private fun handleGenerator(generator: Generator) = when (generator) { is IntegerGenerator -> generator.configure(inRangeAnnotationInstance) is ByteGenerator -> generator.configure(inRangeAnnotationInstance) @@ -88,7 +87,7 @@ object GeneratorConfigurator { is PrimitiveFloatGenerator -> generator.configure(inRangeAnnotationInstance) is PrimitiveDoubleGenerator -> generator.configure(inRangeAnnotationInstance) is PrimitiveLongGenerator -> generator.configure(inRangeAnnotationInstance) - is CollectionGenerator<*> -> generator.configure(sizeAnnotationInstance) + is CollectionGenerator -> generator.configure(sizeAnnotationInstance) is ArrayGenerator -> generator.configure(sizeAnnotationInstance) is MapGenerator -> generator.configure(sizeAnnotationInstance) else -> Unit diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt index cecc8595c0..8fa7aad37f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -25,9 +25,9 @@ import ru.vyarus.java.generics.resolver.context.MethodGenericsContext import java.lang.reflect.* -fun Generator<*>.getAllComponents(): List> { - val queue = ArrayDeque>() - val res = mutableListOf>() +fun Generator.getAllComponents(): List { + val queue = ArrayDeque() + val res = mutableListOf() this.getComponents().forEach { queue.add(it) } while (queue.isNotEmpty()) { val comp = queue.removeFirst() @@ -37,9 +37,9 @@ fun Generator<*>.getAllComponents(): List> { return res } -fun Generator<*>.getComponents(): List> = +fun Generator.getComponents(): List = when (this) { - is ComponentizedGenerator<*> -> this.componentGenerators() + is ComponentizedGenerator -> this.componentGenerators() is ArrayGenerator -> listOf(this.component) else -> emptyList() } @@ -58,19 +58,19 @@ fun GeneratorRepository.produceUserClassGenerator( return userClassGenerator } -fun GeneratorRepository.getOrProduceGenerator(field: Field, depth: Int = 0): Generator<*>? = +fun GeneratorRepository.getOrProduceGenerator(field: Field, depth: Int = 0): Generator? = getOrProduceGenerator(ParameterTypeContext.forField(field), depth) -fun GeneratorRepository.getOrProduceGenerator(param: Parameter, parameterIndex: Int, depth: Int = 0): Generator<*>? = +fun GeneratorRepository.getOrProduceGenerator(param: Parameter, parameterIndex: Int, depth: Int = 0): Generator? = getOrProduceGenerator(param.createParameterTypeContext(parameterIndex), depth) -fun GeneratorRepository.getOrProduceGenerator(clazz: Class<*>, depth: Int = 0): Generator<*>? = +fun GeneratorRepository.getOrProduceGenerator(clazz: Class<*>, depth: Int = 0): Generator? = getOrProduceGenerator(clazz.createParameterTypeContext(), depth) fun GeneratorRepository.getOrProduceGenerator( parameterTypeContext: ParameterTypeContext, depth: Int -): Generator<*>? { +): Generator? { val producedUserClassesGenerators = mutableListOf() parameterTypeContext.getAllSubParameterTypeContexts(GreyBoxFuzzerGenerators.sourceOfRandomness).reversed() .forEach { typeContext -> diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt index 77b0c0789f..994d1140b7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt @@ -6,22 +6,22 @@ import org.utbot.quickcheck.internal.generator.GeneratorRepository import org.utbot.quickcheck.internal.generator.LambdaGenerator import org.utbot.quickcheck.internal.generator.MarkerInterfaceGenerator import org.utbot.quickcheck.random.SourceOfRandomness -import org.utbot.engine.greyboxfuzzer.util.toClass import org.utbot.engine.logger +import org.utbot.quickcheck.internal.Zilch class UTGeneratorRepository(random: SourceOfRandomness) : GeneratorRepository(random) { - override fun generatorFor(parameter: ParameterTypeContext): Generator<*>? { + override fun generatorFor(parameter: ParameterTypeContext): Generator { logger.debug { "TRYING TO GET GENERATOR FOR ${parameter.resolved}" } - if (parameter.resolved.name == "org.utbot.quickcheck.internal.Zilch") return null + if (parameter.resolved.name == Zilch::class.java.name) return TODO("null") val generator = super.generatorFor(parameter) - if (generator is MarkerInterfaceGenerator<*>) { + if (generator is MarkerInterfaceGenerator) { throw IllegalArgumentException( "Cannot find generator for " + parameter.name() + " of type " + parameter.type().typeName ) - } else if (generator is LambdaGenerator<*, *>) { - return null + } else if (generator is LambdaGenerator<*>) { + return TODO("null") } return generator } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt index 408f8a9145..fd593a6a73 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt @@ -2,4 +2,4 @@ package org.utbot.engine.greyboxfuzzer.generator.set import org.utbot.quickcheck.generator.java.util.SetGenerator -class HashSetGenerator: SetGenerator>(HashSet::class.java) \ No newline at end of file +class HashSetGenerator: SetGenerator(HashSet::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt index dcf01364ea..64e0299a12 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt @@ -17,14 +17,14 @@ import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id import java.lang.reflect.* -class UserClassGenerator : ComponentizedGenerator(Any::class.java) { +class UserClassGenerator : ComponentizedGenerator(Any::class.java) { var clazz: Class<*>? = null var parameterTypeContext: ParameterTypeContext? = null var depth = 0 var generationMethod = GenerationMethod.ANY - override fun copy(): Generator { + override fun copy(): Generator { return UserClassGenerator().also { it.clazz = clazz it.depth = depth @@ -32,7 +32,7 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { } } - override fun canGenerateForParametersOfTypes(typeParameters: MutableList>?): Boolean { + override fun canGenerateForParametersOfTypes(typeParameters: List>): Boolean { return true } @@ -45,15 +45,12 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { return generate(random, status) } - override fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel? { + override fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel { logger.debug { "Trying to generate ${parameterTypeContext!!.resolved}. Current depth depth: $depth" } - if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return UtNullModel(clazz!!.id) + if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return TODO("null") val immutableClazz = clazz!! - when (immutableClazz) { - Any::class.java -> return ObjectGenerator(parameterTypeContext!!, random, status).generate() - Class::class.java -> return ReflectionClassGenerator(parameterTypeContext!!).generate() - Type::class.java -> return ReflectionTypeGenerator(parameterTypeContext!!).generate() - } + if (immutableClazz == Any::class.java) return ObjectGenerator(random, status).generate() + if (immutableClazz == Class::class.java) return ReflectionClassGenerator(parameterTypeContext!!).generate() //TODO! generate inner classes instances if (immutableClazz.declaringClass != null && !immutableClazz.hasModifiers(Modifier.STATIC)) { return UtNullModel(immutableClazz.id) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt index 773a7a2e09..d342d28f00 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt @@ -16,14 +16,14 @@ class ClassesInstanceGenerator( private val genStatus: GenerationStatus, private val depth: Int ): InstanceGenerator { - override fun generate(): UtModel? { + override fun generate(): UtModel { val typeOfGenerations = when (generationMethod) { GenerationMethod.CONSTRUCTOR -> mutableListOf('c') GenerationMethod.STATIC -> mutableListOf('s') else -> mutableListOf('c', 'c', 's') } while (typeOfGenerations.isNotEmpty()) { - val randomTypeOfGeneration = typeOfGenerations.randomOrNull() ?: return null + val randomTypeOfGeneration = typeOfGenerations.randomOrNull() ?: return TODO("null") logger.debug { "Type of generation: $randomTypeOfGeneration" } val generatedInstance = when (randomTypeOfGeneration) { @@ -50,6 +50,6 @@ class ClassesInstanceGenerator( return generatedInstance } } - return null + return TODO("null") } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt index c564f4c063..5fa31432b1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt @@ -22,8 +22,8 @@ class ConstructorBasedInstanceGenerator( private val depth: Int ): InstanceGenerator { - override fun generate(): UtModel? { - val constructor = chooseRandomConstructor(clazz) ?: return null + override fun generate(): UtModel { + val constructor = chooseRandomConstructor(clazz) ?: return TODO("null") val resolvedConstructor = //In case if we can not resolve constructor gctx.constructor(constructor).let { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt index 09ffc014ed..a4b09f3afd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt @@ -3,5 +3,5 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.framework.plugin.api.UtModel interface InstanceGenerator { - fun generate(): UtModel? + fun generate(): UtModel } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt index 409fc685ef..62d028b022 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt @@ -1,21 +1,14 @@ @file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") - package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator -import org.utbot.common.isAbstract -import org.utbot.engine.greyboxfuzzer.generator.DataGenerator import org.utbot.engine.greyboxfuzzer.util.* -import org.utbot.framework.plugin.api.* -import org.utbot.framework.plugin.api.util.executableId -import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import ru.vyarus.java.generics.resolver.context.GenericsInfo import java.lang.reflect.Type import kotlin.random.Random -import kotlin.system.exitProcess class InterfaceImplementationsInstanceGenerator( private val resolvedType: Type, @@ -24,9 +17,9 @@ class InterfaceImplementationsInstanceGenerator( private val generationStatus: GenerationStatus, private val depth: Int ) : InstanceGenerator { - override fun generate(): UtModel? { + override fun generate(): UtModel { //Try to generate with statics with some probability - val clazz = resolvedType.toClass() ?: return null + val clazz = resolvedType.toClass() ?: return TODO("null") if (Random.getTrue(50)) { StaticsBasedInstanceGenerator( clazz, @@ -38,7 +31,7 @@ class InterfaceImplementationsInstanceGenerator( return it } } - val genericsContext = getRandomImplementerGenericContext(clazz, resolvedType) ?: return generateMock(clazz, resolvedType, typeContext) + val genericsContext = getRandomImplementerGenericContext(clazz, resolvedType) ?: return TODO("null") return ClassesInstanceGenerator( genericsContext.currentClass(), genericsContext, @@ -47,46 +40,7 @@ class InterfaceImplementationsInstanceGenerator( sourceOfRandomness, generationStatus, depth - ).generate() ?: generateMock(clazz, resolvedType, typeContext) - } - - private fun generateMock(clazz: Class<*>, resolvedType: Type, typeContext: GenericsContext): UtModel? { - if (!clazz.isInterface) return UtNullModel(clazz.id) - val sootClazz = clazz.toSootClass() ?: return UtNullModel(clazz.id) - val constructor = UtModelGenerator.utModelConstructor - val allNeededInterfaces = clazz.methods.map { it.declaringClass }.filter { it != clazz }.toSet() - val chainToGenericsContext = allNeededInterfaces.map { cl -> - val chain = cl.toSootClass() - ?.getImplementersOfWithChain() - ?.filter { it.contains(sootClazz) } - ?.map { it.dropLastWhile { it != sootClazz } } - ?.minByOrNull { it.size } - ?.map { it.toJavaClass() } - if (chain == null || chain.any { it == null }) { - null - } else { - cl to buildGenericsContextForInterfaceParent(resolvedType, clazz, chain.map { it!! }.reversed().drop(1)) - } - } - val allChainToGenericsContext = chainToGenericsContext + (clazz to typeContext) - val mocks = clazz.methods - .filter { it.isAbstract } - .associateTo(mutableMapOf()) { method -> - val genericsContextForMethod = allChainToGenericsContext.find { it!!.first == method.declaringClass }?.second - val methodReturnType = - if (genericsContextForMethod != null) { - genericsContextForMethod.method(method).resolveReturnType().let { - if (it.toClass() == null) method.returnType else it - } - } else { - method.returnType - } - val parameterTypeContext = ParameterTypeContext.forType(methodReturnType, genericsContextForMethod) - val generatedUtModelWithReturnType = - DataGenerator.generate(parameterTypeContext, sourceOfRandomness, generationStatus) ?: UtNullModel(methodReturnType.toClass()!!.id) - method.executableId as ExecutableId to listOf(generatedUtModelWithReturnType) - } - return UtCompositeModel(constructor.computeUnusedIdAndUpdate(), clazz.id, isMock = true, mocks = mocks) + ).generate() } private fun getRandomImplementerGenericContext(clazz: Class<*>, resolvedType: Type): GenericsContext? { @@ -103,14 +57,14 @@ class InterfaceImplementationsInstanceGenerator( } ?: return null //Deal with generics val generics = mutableListOf>>() - var prevImplementer = clazz + var prevImplementer = sootClass.toJavaClass() resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> if (prevImplementer.toClass() != null) { generics.add(typeVariable to mutableListOf(prevImplementer.toClass()!!.typeParameters[index])) } } for (implementer in randomImplementersChain) { - val javaImplementer = implementer.toJavaClass() ?: return null + val javaImplementer = implementer.toJavaClass() val extendType = javaImplementer.let { it.genericInterfaces + it.genericSuperclass } .find { it.toClass() == prevImplementer } val tp = prevImplementer.typeParameters @@ -125,49 +79,10 @@ class InterfaceImplementationsInstanceGenerator( } } } - val g = - prevImplementer.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } + val g = prevImplementer.typeParameters.map { tp -> tp.name to generics.find { it.second.last() == tp }?.first }.toMap() val gm = LinkedHashMap() - g.forEach { - if (it.value != null) { - gm[it.key] = it.value!! - } - } + g.forEach { gm[it.key] = it.value!! } val m = mutableMapOf(prevImplementer to gm) return GenericsContext(GenericsInfo(prevImplementer, m), prevImplementer) } - - private fun buildGenericsContextForInterfaceParent(resolvedType: Type, clazz: Class<*>, parentChain: List>): GenericsContext? { - val generics = mutableListOf>>() - var curClass = clazz - resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> - if (curClass.toClass() != null) { - generics.add(typeVariable to mutableListOf(curClass.toClass()!!.typeParameters[index])) - } - } - for (parent in parentChain) { - val parentType = curClass.let { it.genericInterfaces.toList() + listOf(it.genericSuperclass) } - .find { it.toClass() == parent } - val tp = curClass.typeParameters - curClass = parent - if (tp.isEmpty()) continue - val newTp = parentType?.getActualTypeArguments()?.ifEmpty { return null } ?: return null - tp.mapIndexed { index, typeVariable -> typeVariable to newTp[index] } - .forEach { typeVar -> - val indexOfTypeParam = generics.indexOfFirst { it.second.last() == typeVar.first } - if (indexOfTypeParam != -1) { - generics[indexOfTypeParam].second.add(curClass.typeParameters[indexOfTypeParam]) - } - } - } - val g = curClass.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } - val gm = LinkedHashMap() - g.forEach { - if (it.value != null) { - gm[it.key] = it.value!! - } - } - val m = mutableMapOf(curClass to gm) - return GenericsContext(GenericsInfo(curClass, m), curClass) - } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt index e6832b6157..31c48ff782 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt @@ -1,42 +1,20 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGenerators -import org.utbot.engine.greyboxfuzzer.generator.getOrProduceGenerator -import org.utbot.engine.greyboxfuzzer.util.getAllTypesFromCastAndInstanceOfInstructions -import org.utbot.engine.greyboxfuzzer.util.getTrue -import org.utbot.engine.greyboxfuzzer.util.toJavaClass -import org.utbot.engine.greyboxfuzzer.util.toSootMethod import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness -import ru.vyarus.java.generics.resolver.context.MethodGenericsContext -import kotlin.random.Random class ObjectGenerator( - private val parameterTypeContext: ParameterTypeContext, private val sourceOfRandomness: SourceOfRandomness, private val generationStatus: GenerationStatus -) : InstanceGenerator { - override fun generate(): UtModel? { - val currentSootMethod = - (parameterTypeContext.generics as? MethodGenericsContext)?.currentMethod()?.toSootMethod() - val potentialUsefulClasses = - currentSootMethod?.getAllTypesFromCastAndInstanceOfInstructions()?.mapNotNull { it.toJavaClass() } - val potentialInterestingObjectReplacement = - if (potentialUsefulClasses?.isNotEmpty() == true && Random.getTrue(50)) { - val randomClass = potentialUsefulClasses.random() - GreyBoxFuzzerGenerators.generatorRepository - .getOrProduceGenerator(randomClass) - ?.generate(sourceOfRandomness, generationStatus) - } else null - potentialInterestingObjectReplacement?.let { return it } - return GreyBoxFuzzerGenerators.generatorRepository - .generators +): InstanceGenerator { + override fun generate(): UtModel = + GreyBoxFuzzerGenerators.generatorRepository + .getGenerators() .toList() .flatMap { it.second } .filter { !it.hasComponents() } .randomOrNull() - ?.generate(sourceOfRandomness, generationStatus) - } + ?.generate(sourceOfRandomness, generationStatus) ?: TODO("null") } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt index 238dbbd060..c4e0856d94 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt @@ -1,34 +1,15 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator -import org.utbot.engine.greyboxfuzzer.util.getTrue -import org.utbot.engine.greyboxfuzzer.util.toJavaClass import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.internal.ParameterTypeContext -import soot.Scene -import java.lang.reflect.Type -import kotlin.random.Random class ReflectionClassGenerator( private val parameterTypeContext: ParameterTypeContext ) : InstanceGenerator { - override fun generate(): UtModel { - val packageName = parameterTypeContext.declarerName.substringBeforeLast('.') - val randomClassFromSamePackage = - Scene.v().classes - .filter { it.name.startsWith(packageName) } - .filterNot { it.isInnerClass } - .mapNotNull { it.toJavaClass() } - .randomOrNull() - if (randomClassFromSamePackage != null && Random.getTrue(50)) { - return UtModelGenerator.utModelConstructor.construct(randomClassFromSamePackage, Class::class.java.id) - } - Scene.v().classes.randomOrNull()?.toJavaClass()?.let { - if (Random.getTrue(75)) { - return UtModelGenerator.utModelConstructor.construct(it, Class::class.java.id) - } - } - return UtModelGenerator.utModelConstructor.construct(Any::class.java, Class::class.java.id) - } + override fun generate(): UtModel = + parameterTypeContext.resolved.typeParameters.randomOrNull()?.type?.componentClass?.let { + UtModelGenerator.utModelConstructor.construct(it, Class::class.java.id) + } ?: TODO("null") } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt index 6f8d354360..6732f7e5c5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt @@ -13,7 +13,7 @@ open class StaticsBasedInstanceGenerator( private val generationStatus: GenerationStatus, private val depth: Int ) : InstanceGenerator { - override fun generate(): UtModel? { + override fun generate(): UtModel { val staticMethodBasedGenerator = StaticsMethodBasedInstanceGenerator(clazz, gctx, sourceOfRandomness, generationStatus, depth) val staticFieldBasedGenerator = diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt index 982fe3f71a..86487c7218 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt @@ -21,10 +21,10 @@ internal class StaticsFieldBasedInstanceGenerator( private val clazz: Class<*>, private val gctx: GenericsContext ) : InstanceGenerator { - override fun generate(): UtModel? = + override fun generate(): UtModel = getRandomStaticToProduceInstanceUsingSoot()?.let { fieldToProvideInstance -> createUtModelForStaticFieldInvocation(UtModelGenerator.utModelConstructor, fieldToProvideInstance) - } + } ?: TODO("null") //In case of no Soot private fun getStaticFieldToProduceInstance(): Field? { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt index 826e52b7ed..5dac847814 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt @@ -20,7 +20,7 @@ internal class StaticsMethodBasedInstanceGenerator( private val generationStatus: GenerationStatus, private val depth: Int ) : InstanceGenerator { - override fun generate(): UtModel? = + override fun generate(): UtModel = getRandomStaticToProduceInstanceUsingSoot()?.let { methodToProvideInstance -> val resolvedMethodContext = try { @@ -37,7 +37,7 @@ internal class StaticsMethodBasedInstanceGenerator( generationStatus, depth ).invoke() - } + } ?: TODO("null") //In case of no Soot private fun getRandomStaticToProduceInstance(): Method? = diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt index e5bffee1df..ec4fcfe5c6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt @@ -1,37 +1,8 @@ -/* - * Copyright (c) 2017-2018 The Regents of the University of California - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are - * met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.utbot.quickcheck; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.internal.GeometricDistribution; -import org.utbot.quickcheck.random.SourceOfRandomness; +package org.utbot.quickcheck +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.internal.GeometricDistribution +import org.utbot.quickcheck.random.SourceOfRandomness /** * Provides a generation status that does not track the number of trials @@ -40,27 +11,20 @@ import org.utbot.quickcheck.random.SourceOfRandomness; * * @author Rohan Padhye */ -public class NonTrackingGenerationStatus implements GenerationStatus { - - public static final int MEAN_SIZE = 10; - - private final SourceOfRandomness random; - private final GeometricDistribution geometric = new GeometricDistribution(); - - - public NonTrackingGenerationStatus(SourceOfRandomness random) { - this.random = random; +class NonTrackingGenerationStatus(private val random: SourceOfRandomness) : GenerationStatus { + private val geometric = GeometricDistribution() + override fun size(): Int { + return geometric.sampleWithMean(MEAN_SIZE.toDouble(), random) } - @Override - public int size() { - return geometric.sampleWithMean(MEAN_SIZE, random); + override fun attempts(): Int { + throw UnsupportedOperationException( + "attempts() and @ValueOf" + + " is not supported in guided mode." + ) } - @Override - public int attempts() { - throw new UnsupportedOperationException("attempts() and @ValueOf" + - " is not supported in guided mode."); + companion object { + const val MEAN_SIZE = 10 } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt index 86a7749f0a..10b40152fb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt @@ -1,85 +1,70 @@ -package org.utbot.quickcheck.generator; +package org.utbot.quickcheck.generator -import org.javaruntype.type.TypeParameter; - -import java.lang.reflect.AnnotatedType; -import java.util.ArrayList; -import java.util.List; - -import static java.util.Collections.unmodifiableList; -import static org.utbot.quickcheck.internal.Reflection.annotatedComponentTypes; +import org.javaruntype.type.TypeParameter +import org.utbot.quickcheck.internal.Reflection +import java.lang.reflect.AnnotatedType +import java.util.Collections /** * Produces values for property parameters of types that have parameterizations * that would also need generation, such as collections, maps, and predicates. * * @param type of property parameter to apply this generator's values to - */ -public abstract class ComponentizedGenerator extends Generator { - - private final List> components = new ArrayList<>(); - - /** - * @param type class token for type of property parameter this generator - * is applicable to - */ - protected ComponentizedGenerator(Class type) { - super(type); - } + * @param type class token for type of property parameter this generator + * is applicable to + */ +abstract class ComponentizedGenerator constructor(type: Class<*>) : Generator(type) { + private val components: MutableList = ArrayList() /** * {@inheritDoc} * - *

Generators of this type do not get called upon to generate values - * for parameters of type {@link Object}.

+ * + * Generators of this type do not get called upon to generate values + * for parameters of type [Object]. */ - @Override public boolean canRegisterAsType(Class type) { - return !Object.class.equals(type); + override fun canRegisterAsType(type: Class<*>): Boolean { + return Any::class.java != type } - @Override public final boolean hasComponents() { - return true; + override fun hasComponents(): Boolean { + return true } - @Override public void addComponentGenerators( - List> newComponents) { - - if (newComponents.size() != numberOfNeededComponents()) { - throw new IllegalArgumentException( - String.format( - "Needed %d components for %s, but got %d", - numberOfNeededComponents(), - getClass(), - newComponents.size())); + override fun addComponentGenerators( + newComponents: List + ) { + require(newComponents.size == numberOfNeededComponents()) { + String.format( + "Needed %d components for %s, but got %d", + numberOfNeededComponents(), + javaClass, + newComponents.size + ) } - - components.clear(); - components.addAll(newComponents); + components.clear() + components.addAll(newComponents) } - @Override public boolean canGenerateForParametersOfTypes( - List> typeParameters) { - - return numberOfNeededComponents() == typeParameters.size(); + override fun canGenerateForParametersOfTypes( + typeParameters: List> + ): Boolean { + return numberOfNeededComponents() == typeParameters.size } - @Override public void provide(Generators provided) { - super.provide(provided); - - for (org.utbot.quickcheck.generator.Generator each : components) { - each.provide(provided); + override fun provide(provided: Generators) { + super.provide(provided) + for (each in components) { + each.provide(provided) } } - @Override public void configure(AnnotatedType annotatedType) { - super.configure(annotatedType); - - List annotatedComponentTypes = - annotatedComponentTypes(annotatedType); - - if (annotatedComponentTypes.size() == components.size()) { - for (int i = 0; i < components.size(); ++i) { - components.get(i).configure(annotatedComponentTypes.get(i)); + override fun configure(annotatedType: AnnotatedType?) { + super.configure(annotatedType) + val annotatedComponentTypes = Reflection.annotatedComponentTypes(annotatedType) + if (annotatedComponentTypes.size == components.size) { + for (i in components.indices) { + components[i].configure(annotatedComponentTypes[i]) } } } @@ -87,7 +72,7 @@ public abstract class ComponentizedGenerator extends Generator { /** * @return this generator's component generators */ - public List> componentGenerators() { - return unmodifiableList(components); + fun componentGenerators(): List { + return Collections.unmodifiableList(components) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt index f4bac88b4a..977f2f91ca 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt @@ -1,32 +1,13 @@ - -package org.utbot.quickcheck.generator; - -import java.math.BigDecimal; -import java.util.List; -import java.util.function.Predicate; - -import static java.util.Collections.singletonList; +package org.utbot.quickcheck.generator /** - * Base class for generators of decimal types, such as {@code double} and - * {@link BigDecimal}. All numbers are converted to/from BigDecimal for + * Base class for generators of decimal types, such as `double` and + * [BigDecimal]. All numbers are converted to/from BigDecimal for * processing. * * @param type of values this generator produces - */ -public abstract class DecimalGenerator extends Generator { - protected DecimalGenerator(Class type) { - super(singletonList(type)); - } - - protected DecimalGenerator(List> types) { - super(types); - } - - /** - * @return a predicate checking whether its input is in the configured - * range - */ - protected abstract Predicate inRange(); - + */ +abstract class DecimalGenerator : Generator { + protected constructor(type: Class<*>) : super(type) + protected constructor(types: List>) : super(types) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Distinct.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Distinct.kt index e41b6e58c0..3ece9eb43c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Distinct.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Distinct.kt @@ -1,26 +1,20 @@ - - -package org.utbot.quickcheck.generator; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +package org.utbot.quickcheck.generator /** - *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + * + * Mark a parameter of a * method with this annotation to make values generated for the parameter - * distinct from each other.

+ * distinct from each other. + * + * + * This annotation is recognized on array parameters and parameters of type + * [java.util.Collection] and [java.util.Map]. * - *

This annotation is recognized on array parameters and parameters of type - * {@link java.util.Collection} and {@link java.util.Map}.

* - *

Using this annotation with {@link Size} on {@link java.util.Set} or - * {@link java.util.Map} leads to strict size constraint.

+ * Using this annotation with [Size] on [java.util.Set] or + * [java.util.Map] leads to strict size constraint. */ -@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) -@Retention(RUNTIME) +@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.TYPE) +@Retention(AnnotationRetention.RUNTIME) @GeneratorConfiguration -public @interface Distinct { -} +annotation class Distinct diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Gen.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Gen.kt index eef5c5a9d5..5e07e2baf6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Gen.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Gen.kt @@ -1,26 +1,21 @@ +package org.utbot.quickcheck.generator -package org.utbot.quickcheck.generator; - -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.random.SourceOfRandomness; +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.random.SourceOfRandomness /** * Represents a strategy for generating random values. - * - * @param type of values generated - */ -@FunctionalInterface -public interface Gen { + * */ +fun interface Gen { /** * Generates a value, possibly influenced by a source of randomness and * metadata about the generation. * * @param random source of randomness to be used when generating the value * @param status an object that can be used to influence the generated - * value. For example, generating lists can use the {@link - * GenerationStatus#size() size} method to generate lists with a given + * value. For example, generating lists can use the [ ][GenerationStatus.size] method to generate lists with a given * number of elements. * @return the generated value */ - UtModel generate(SourceOfRandomness random, GenerationStatus status); -} + fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt index 735536ea90..642323507c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt @@ -1,23 +1,20 @@ - - -package org.utbot.quickcheck.generator; +package org.utbot.quickcheck.generator /** - * {@link Generator}s are fed instances of this interface on each generation + * [Generator]s are fed instances of this interface on each generation * so that, if they choose, they can use these instances to influence the * results of a generation for a particular property parameter. */ -public interface GenerationStatus { +interface GenerationStatus { /** * @return an arbitrary "size" parameter; this value (probabilistically) * increases for every successful generation */ - int size(); + fun size(): Int /** * @return how many attempts have been made to generate a value for a * property parameter */ - int attempts(); - -} + fun attempts(): Int +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt index 23fca1c56b..6d0cc8435f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt @@ -1,63 +1,49 @@ - - -package org.utbot.quickcheck.generator; - -import org.javaruntype.type.TypeParameter; -import org.javaruntype.type.Types; -import org.javaruntype.type.WildcardTypeParameter; -import org.utbot.quickcheck.internal.ReflectionException; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.AnnotatedType; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.Consumer; - -import static java.util.Collections.*; -import static java.util.stream.Collectors.toList; -import static org.utbot.quickcheck.internal.Reflection.*; +package org.utbot.quickcheck.generator + +import org.javaruntype.type.TypeParameter +import org.javaruntype.type.Types +import org.javaruntype.type.WildcardTypeParameter +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.internal.ReflectionException +import org.utbot.quickcheck.random.SourceOfRandomness +import java.lang.reflect.AnnotatedElement +import java.lang.reflect.AnnotatedType +import java.lang.reflect.Method +import java.util.Collections +import java.lang.annotation.Annotation as JavaAnnotation /** * Produces values for property parameters. * - * @param type of property parameter to apply this generator's values to */ -public abstract class Generator implements Gen { - private final List> types = new ArrayList<>(); - - private Generators repo; +abstract class Generator protected constructor(types: List>) : Gen { + private val types: MutableList> = ArrayList() + private var repo: Generators? = null /** * @param type class token for type of property parameter this generator is * applicable to */ - protected Generator(Class type) { - this(singletonList(type)); - } + protected constructor(type: Class<*>) : this(listOf(type)) /** * Used for generators of primitives and their wrappers. For example, a - * {@code Generator} can be used for property parameters of type - * {@code Integer} or {@code int}. + * `Generator` can be used for property parameters of type + * `Integer` or `int`. * * @param types class tokens for type of property parameter this generator * is applicable to */ - protected Generator(List> types) { - this.types.addAll(types); + init { + this.types.addAll(types) } /** * @return class tokens for the types of property parameters this generator * is applicable to */ - public List> types() { - return unmodifiableList(types); + fun types(): List> { + return Collections.unmodifiableList(types) } /** @@ -65,50 +51,55 @@ public abstract class Generator implements Gen { * parameters of the given type. * * @param type type against which to test this generator - * @return {@code true} if the generator is allowed to participate in - * generating values for property parameters of {@code type} + * @return `true` if the generator is allowed to participate in + * generating values for property parameters of `type` */ - public boolean canRegisterAsType(Class type) { - return true; + open fun canRegisterAsType(type: Class<*>): Boolean { + return true } /** - *

This is intended for use only by junit-quickcheck itself, and not by - * creators of custom generators.

+ * + * This is intended for use only by junit-quickcheck itself, and not by + * creators of custom generators. * * @return whether this generator has component generators, such as for * those generators that produce lists or maps - * @see #addComponentGenerators(List) + * @see .addComponentGenerators */ - public boolean hasComponents() { - return false; + open fun hasComponents(): Boolean { + return false } /** - *

This is intended for use only by junit-quickcheck itself, and not by - * creators of custom generators.

+ * + * This is intended for use only by junit-quickcheck itself, and not by + * creators of custom generators. * * @return how many component generators this generator needs - * @see #addComponentGenerators(List) + * @see .addComponentGenerators */ - public int numberOfNeededComponents() { - return 0; + open fun numberOfNeededComponents(): Int { + return 0 } /** - *

Adds component generators to this generator.

* - *

Some generators need component generators to create proper values. + * Adds component generators to this generator. + * + * + * Some generators need component generators to create proper values. * For example, list generators require a single component generator in * order to generate elements that have the type of the list parameter's - * type argument.

+ * type argument. + * * - *

This is intended for use only by junit-quickcheck itself, and not by - * creators of custom generators.

+ * This is intended for use only by junit-quickcheck itself, and not by + * creators of custom generators. * * @param newComponents component generators to add */ - public void addComponentGenerators(List> newComponents) { + open fun addComponentGenerators(newComponents: List) { // do nothing by default } @@ -118,57 +109,62 @@ public abstract class Generator implements Gen { * for property parameters that have the given type parameters in their * signatures */ - public boolean canGenerateForParametersOfTypes(List> typeParameters) { - return true; + open fun canGenerateForParametersOfTypes(typeParameters: List>): Boolean { + return true } /** - *

Configures this generator using annotations from a given annotated - * type.

* - *

This method considers only annotations that are themselves marked - * with {@link GeneratorConfiguration}.

+ * Configures this generator using annotations from a given annotated + * type. + * + * + * This method considers only annotations that are themselves marked + * with [GeneratorConfiguration]. + * + * + * By default, the generator will configure itself using this + * procedure: + * + * * For each of the given annotations: + * + * * Find a `public` method on the generator named + * `configure`, that accepts a single parameter of the + * annotation type + * * Invoke the `configure` method reflectively, passing the + * annotation as the argument + * + * * - *

By default, the generator will configure itself using this - * procedure:

- *
    - *
  • For each of the given annotations: - *
      - *
    • Find a {@code public} method on the generator named - * {@code configure}, that accepts a single parameter of the - * annotation type
    • - *
    • Invoke the {@code configure} method reflectively, passing the - * annotation as the argument
    • - *
    - *
  • - *
* * @param annotatedType a type usage * @throws GeneratorConfigurationException if the generator does not * "understand" one of the generation configuration annotations on * the annotated type */ - public void configure(AnnotatedType annotatedType) { - configureStrict(collectConfigurationAnnotations(annotatedType)); + open fun configure(annotatedType: AnnotatedType?) { + configureStrict(collectConfigurationJavaAnnotations(annotatedType)) } /** * @param element an annotated program element */ - public void configure(AnnotatedElement element) { - configureLenient(collectConfigurationAnnotations(element)); + open fun configure(element: AnnotatedElement?) { + configureLenient(collectConfigurationJavaAnnotations(element)) } /** - *

Supplies the available generators to this one.

* - *

This is intended for use only by junit-quickcheck itself, and not by - * creators of custom generators.

- + * Supplies the available generators to this one. + * + * + * This is intended for use only by junit-quickcheck itself, and not by + * creators of custom generators. + * * @param provided repository of available generators */ - public void provide(Generators provided) { - repo = provided; + open fun provide(provided: Generators) { + repo = provided } /** @@ -176,30 +172,15 @@ public abstract class Generator implements Gen { * * @return a copy of the receiver */ - @SuppressWarnings("unchecked") - public Generator copy() { - return (Generator) instantiate(getClass()); - } - - /** - * @param parameter a generic type parameter - * @param clazz a type - * @return whether the type is compatible with the generic type parameter - * @see #canGenerateForParametersOfTypes(List) - */ - protected static boolean compatibleWithTypeParameter( - TypeParameter parameter, - Class clazz) { - - return parameter instanceof WildcardTypeParameter - || parameter.getType().isAssignableFrom(Types.forJavaLangReflectType(clazz)); + open fun copy(): Generator { + return Reflection.instantiate(javaClass) as Generator } /** * @return an access point for the available generators */ - protected Generators gen() { - return repo; + protected fun gen(): Generators? { + return repo } /** @@ -207,85 +188,95 @@ public abstract class Generator implements Gen { * generators * @return an access point for the available generators */ - protected Generators gen(SourceOfRandomness random) { - return repo.withRandom(random); + protected fun gen(random: SourceOfRandomness?): Generators { + return repo!!.withRandom(random!!) } - /** - * Gives a list of the {@link GeneratorConfiguration} annotations present - * on the given program element. - * - * @param element an annotated program element - * @return what configuration annotations are present on that element - */ - protected static List configurationAnnotationsOn(AnnotatedElement element) { - return allAnnotations(element).stream() - .filter(a -> a.annotationType().isAnnotationPresent(GeneratorConfiguration.class)) - .collect(toList()); + private fun collectConfigurationJavaAnnotations( + element: AnnotatedElement? + ): Map, JavaAnnotation> { + if (element == null) return emptyMap() + val configs = configurationAnnotationsOn(element) + return configs.associateBy { it.annotationType() as Class } } - private Map, Annotation> collectConfigurationAnnotations( - AnnotatedElement element) { - - if (element == null) - return emptyMap(); - - List configs = configurationAnnotationsOn(element); - - Map, Annotation> byType = new HashMap<>(); - for (Annotation each : configs) - byType.put(each.annotationType(), each); - return byType; - } - - private void configureStrict(Map, Annotation> byType) { - for (Map.Entry, Annotation> each : byType.entrySet()) - configureStrict(each.getKey(), each.getValue()); + private fun configureStrict(byType: Map, JavaAnnotation>) { + for ((key, value) in byType) configureStrict(key, value) } - private void configureStrict( - Class annotationType, - Annotation configuration) { - + private fun configureStrict( + annotationType: Class, + configuration: JavaAnnotation + ) { configure( annotationType, - configuration, - ex -> { - throw new GeneratorConfigurationException( - String.format( - "Generator %s does not understand configuration annotation %s", - getClass().getName(), - annotationType.getName()), - ex); - }); + configuration + ) { ex: ReflectionException? -> + throw GeneratorConfigurationException( + String.format( + "Generator %s does not understand configuration annotation %s", + javaClass.name, + annotationType.name + ), + ex + ) + } } - private void configureLenient(Map, Annotation> byType) { - for (Map.Entry, Annotation> each : byType.entrySet()) - configureLenient(each.getKey(), each.getValue()); + private fun configureLenient(byType: Map, JavaAnnotation>) { + for ((key, value) in byType) configureLenient(key, value) } - private void configureLenient( - Class annotationType, - Annotation configuration) { - - configure(annotationType, configuration, ex -> {}); + private fun configureLenient( + annotationType: Class, + configuration: JavaAnnotation + ) { + configure(annotationType, configuration) { ex: ReflectionException? -> } } - private void configure( - Class annotationType, - Annotation configuration, - Consumer exceptionHandler) { - - Method configurer = null; - + private fun configure( + annotationType: Class, + configuration: JavaAnnotation, + exceptionHandler: (ReflectionException) -> Unit + ) { + var configurer: Method? = null try { - configurer = findMethod(getClass(), "configure", annotationType); - } catch (ReflectionException ex) { - exceptionHandler.accept(ex); + configurer = Reflection.findMethod(javaClass, "configure", annotationType) + } catch (ex: ReflectionException) { + exceptionHandler(ex) + } + if (configurer != null) Reflection.invoke(configurer, this, configuration) + } + + companion object { + /** + * @param parameter a generic type parameter + * @param clazz a type + * @return whether the type is compatible with the generic type parameter + * @see .canGenerateForParametersOfTypes + */ + protected fun compatibleWithTypeParameter( + parameter: TypeParameter<*>, + clazz: Class<*>? + ): Boolean { + return (parameter is WildcardTypeParameter + || parameter.type.isAssignableFrom(Types.forJavaLangReflectType(clazz))) } - if (configurer != null) - invoke(configurer, this, configuration); + /** + * Gives a list of the [GeneratorConfiguration] annotations present + * on the given program element. + * + * @param element an annotated program element + * @return what configuration annotations are present on that element + */ + @JvmStatic + protected fun configurationAnnotationsOn(element: AnnotatedElement): List = + Reflection.allAnnotations(element) + .filter { + it.annotationType().isAnnotationPresent( + GeneratorConfiguration::class.java + ) + } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt index 845af79cc8..f595967ee1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt @@ -1,27 +1,20 @@ - -package org.utbot.quickcheck.generator; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.ANNOTATION_TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +package org.utbot.quickcheck.generator /** - *

Apply this annotation to an annotation that marks property parameters, + * + * Apply this annotation to an annotation that marks property parameters, * in order that the marked annotation can be used to configure - * {@linkplain Generator generators} for values of the parameter's type.

+ * [generators][Generator] for values of the parameter's type. + * * - *

If a generator has a public instance method named {@code configure}, + * If a generator has a public instance method named `configure`, * with a single parameter whose type is an annotation that has this annotation * applied, then when a property that has a parameter marked with method that * annotation is verified, the generator that generates the value for that - * parameter will have its {@code configure} method called with the annotation - * as the argument.

+ * parameter will have its `configure` method called with the annotation + * as the argument. */ -@Target(ANNOTATION_TYPE) -@Retention(RUNTIME) -@Documented -public @interface GeneratorConfiguration { -} +@Target(AnnotationTarget.ANNOTATION_CLASS) +@Retention(AnnotationRetention.RUNTIME) +@MustBeDocumented +annotation class GeneratorConfiguration diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt index 8ce0b01b4f..80c1cc2542 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt @@ -1,20 +1,16 @@ - -package org.utbot.quickcheck.generator; +package org.utbot.quickcheck.generator /** * Raised if a problem arises when attempting to configure a generator with * annotations from a property parameter. * - * @see Generator#configure(java.lang.reflect.AnnotatedType) + * @see Generator.configure */ -public class GeneratorConfigurationException extends RuntimeException { - private static final long serialVersionUID = 1L; - - public GeneratorConfigurationException(String message) { - super(message); - } +class GeneratorConfigurationException : RuntimeException { + constructor(message: String) : super(message) + constructor(message: String, cause: Throwable?) : super(message, cause) - public GeneratorConfigurationException(String message, Throwable cause) { - super(message, cause); + companion object { + private const val serialVersionUID = 1L } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generators.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generators.kt index 9bf54af2bd..09bed76c5e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generators.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generators.kt @@ -1,62 +1,67 @@ -package org.utbot.quickcheck.generator; +package org.utbot.quickcheck.generator -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.reflect.Field; -import java.lang.reflect.Parameter; +import org.utbot.quickcheck.random.SourceOfRandomness +import java.lang.reflect.Field +import java.lang.reflect.Parameter /** * An access point for available generators. */ -public interface Generators { - +interface Generators { /** - *

Gives a generator that can produce values of the given type, - * parameterized by the given "component" types.

+ * + * Gives a generator that can produce values of the given type, + * parameterized by the given "component" types. * * @param type of objects produced by the resulting generator * @param type a type * @param componentTypes types for the "components" of the type, if any * @return generator that can produce values of that type * @see ComponentizedGenerator - */ - Generator type(Class type, Class... componentTypes); + */ + fun type(type: Class, vararg componentTypes: Class<*>): Generator /** - *

Gives a generator that can produce instances of the type of the - * given reflected method parameter.

* - *

If the parameter is marked with an annotation that influences the + * Gives a generator that can produce instances of the type of the + * given reflected method parameter. + * + * + * If the parameter is marked with an annotation that influences the * generation of its value, that annotation will be applied to the - * generation of values for that parameter's type.

+ * generation of values for that parameter's type. * * @param parameter a reflected method parameter * @return generator that can produce values of the parameter's type */ - Generator parameter(Parameter parameter); + fun parameter(parameter: Parameter): Generator /** - *

Gives a generator that can produce instances of the type of the - * given reflected field.

* - *

If the field is marked with an annotation that influences the + * Gives a generator that can produce instances of the type of the + * given reflected field. + * + * + * If the field is marked with an annotation that influences the * generation of its value, that annotation will be applied to the - * generation of values for that field's type.

+ * generation of values for that field's type. * * @param field a reflected field * @return generator that can produce values of the field's type */ - Generator field(Field field); + fun field(field: Field): Generator /** - *

Makes a generator access point just like the receiver, but which - * uses the given source of randomness for making random choices.

* - *

Intended for use by junit-quickcheck.

+ * Makes a generator access point just like the receiver, but which + * uses the given source of randomness for making random choices. + * + * + * Intended for use by junit-quickcheck. * * @param random a source of randomness * @return a generator access point that has the source of randomness * available to it */ - Generators withRandom(SourceOfRandomness random); -} + fun withRandom(random: SourceOfRandomness): Generators +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/InRange.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/InRange.kt index 7a6245255d..0506d16190 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/InRange.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/InRange.kt @@ -1,111 +1,91 @@ -package org.utbot.quickcheck.generator; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +package org.utbot.quickcheck.generator /** - *

Mark a parameter of a + * + * Mark a parameter of a * method with this annotation to constrain the values generated for the - * parameter to a given range.

+ * parameter to a given range. * - *

Different generators may use different min/max attribute pairs. + * + * Different generators may use different min/max attribute pairs. * Generators that produce primitive values or values of their wrapper types * will likely want to use the attribute pairs of corresponding type. - * Otherwise, a generator can use {@link #min()} and {@link #max()}, and + * Otherwise, a generator can use [.min] and [.max], and * take on the responsibility of converting their string values to values of - * the desired type.

+ * the desired type. */ -@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) -@Retention(RUNTIME) +@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.TYPE) +@Retention(AnnotationRetention.RUNTIME) @GeneratorConfiguration -public @interface InRange { +annotation class InRange( /** - * @return a minimum {@code byte} value + * @return a minimum `byte` value */ - byte minByte() default Byte.MIN_VALUE; - + val minByte: Byte = Byte.MIN_VALUE, /** - * @return a maximum {@code byte} value + * @return a maximum `byte` value */ - byte maxByte() default Byte.MAX_VALUE; - + val maxByte: Byte = Byte.MAX_VALUE, /** - * @return a minimum {@code short} value + * @return a minimum `short` value */ - short minShort() default Short.MIN_VALUE; - + val minShort: Short = Short.MIN_VALUE, /** - * @return a maximum {@code short} value + * @return a maximum `short` value */ - short maxShort() default Short.MAX_VALUE; - + val maxShort: Short = Short.MAX_VALUE, /** - * @return a minimum {@code char} value + * @return a minimum `char` value */ - char minChar() default Character.MIN_VALUE; - + val minChar: Char = Character.MIN_VALUE, /** - * @return a maximum {@code char} value + * @return a maximum `char` value */ - char maxChar() default Character.MAX_VALUE; - + val maxChar: Char = Character.MAX_VALUE, /** - * @return a minimum {@code int} value + * @return a minimum `int` value */ - int minInt() default Integer.MIN_VALUE; - + val minInt: Int = Int.MIN_VALUE, /** - * @return a maximum {@code int} value + * @return a maximum `int` value */ - int maxInt() default Integer.MAX_VALUE; - + val maxInt: Int = Int.MAX_VALUE, /** - * @return a minimum {@code long} value + * @return a minimum `long` value */ - long minLong() default Long.MIN_VALUE; - + val minLong: Long = Long.MIN_VALUE, /** - * @return a maximum {@code long} value + * @return a maximum `long` value */ - long maxLong() default Long.MAX_VALUE; - + val maxLong: Long = Long.MAX_VALUE, /** - * @return a minimum {@code float} value + * @return a minimum `float` value */ - float minFloat() default 0F; - + val minFloat: Float = 0f, /** - * @return a maximum {@code float} value + * @return a maximum `float` value */ - float maxFloat() default 1F; - + val maxFloat: Float = 1f, /** - * @return a minimum {@code double} value + * @return a minimum `double` value */ - double minDouble() default 0D; - + val minDouble: Double = 0.0, /** - * @return a maximum {@code double} value + * @return a maximum `double` value */ - double maxDouble() default 1D; - + val maxDouble: Double = 1.0, /** * @return a minimum value, represented in string form */ - String min() default ""; - + val min: String = "", /** * @return a maximum value, represented in string form */ - String max() default ""; - + val max: String = "", /** * @return a formatting hint, such as a - * {@linkplain java.text.SimpleDateFormat date format string}, that + * [date format string][java.text.SimpleDateFormat], that * generators can use when converting values from strings */ - String format() default ""; -} + val format: String = "" +) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt index 7f5c27e2fe..8c632a4083 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt @@ -1,33 +1,14 @@ -package org.utbot.quickcheck.generator; - -import java.math.BigInteger; -import java.util.List; -import java.util.function.Predicate; - -import static java.util.Collections.singletonList; +package org.utbot.quickcheck.generator /** - * Base class for generators of integral types, such as {@code int} and - * {@link BigInteger}. All numbers are converted to/from BigInteger for + * Base class for generators of integral types, such as `int` and + * [BigInteger]. All numbers are converted to/from BigInteger for * processing. * * @param type of values this generator produces - */ -public abstract class IntegralGenerator - extends Generator { - - protected IntegralGenerator(Class type) { - super(singletonList(type)); - } - - protected IntegralGenerator(List> types) { - super(types); - } - - /** - * @return a predicate checking whether its input is in the configured - * range - */ - protected abstract Predicate inRange(); + */ +abstract class IntegralGenerator : Generator { + protected constructor(type: Class<*>) : super(type) + protected constructor(types: List>) : super(types) -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt index a4bd81bfb1..6de2acd24a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt @@ -1,140 +1,116 @@ -package org.utbot.quickcheck.generator; - -import org.utbot.quickcheck.internal.DefaultMethodHandleMaker; -import org.utbot.quickcheck.internal.GeometricDistribution; -import org.utbot.quickcheck.internal.generator.SimpleGenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.invoke.MethodHandle; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.util.Arrays; -import java.util.Random; - -import static java.lang.System.identityHashCode; -import static java.lang.reflect.Proxy.newProxyInstance; -import static org.utbot.quickcheck.internal.Reflection.singleAbstractMethodOf; +package org.utbot.quickcheck.generator + +import org.utbot.quickcheck.internal.DefaultMethodHandleMaker +import org.utbot.quickcheck.internal.GeometricDistribution +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.internal.generator.SimpleGenerationStatus +import org.utbot.quickcheck.random.SourceOfRandomness +import java.lang.reflect.InvocationHandler +import java.lang.reflect.Method +import java.lang.reflect.Proxy +import java.util.Arrays +import java.util.Random /** * Helper class for creating instances of "functional interfaces". */ -public final class Lambdas { - private Lambdas() { - throw new UnsupportedOperationException(); +class Lambdas private constructor() { + init { + throw UnsupportedOperationException() } - /** - *

Creates an instance of a given "functional interface" type, whose - * single abstract method returns values of the type produced by the given - * generator. The arguments to the lambda's single method will be used to - * seed a random generator that will be used to generate the return value - * of that method.

- * - *

junit-quickcheck uses this to create random values for property - * parameters whose type is determined to be a - * {@linkplain FunctionalInterface functional interface}. Custom generators - * for functional interface types can use this also.

- * - * @param lambdaType a functional interface type token - * @param returnValueGenerator a generator for the return type of the - * functional interface's single method - * @param status an object to be passed along to the generator that will - * produce the functional interface's method return value - * @param the functional interface type token - * @param the type of the generated return value of the functional - * interface method - * @return an instance of the functional interface type, whose single - * method will return a generated value - * @throws IllegalArgumentException if {@code lambdaType} is not a - * functional interface type - */ - public static T makeLambda( - Class lambdaType, - org.utbot.quickcheck.generator.Generator returnValueGenerator, - GenerationStatus status) { - - if (singleAbstractMethodOf(lambdaType) == null) { - throw new IllegalArgumentException( - lambdaType + " is not a functional interface type"); - } - - return lambdaType.cast( - newProxyInstance( - lambdaType.getClassLoader(), - new Class[] { lambdaType }, - new LambdaInvocationHandler<>( - lambdaType, - returnValueGenerator, - status.attempts()))); - } - - private static class LambdaInvocationHandler - implements InvocationHandler { - - private final Class lambdaType; - private final org.utbot.quickcheck.generator.Generator returnValueGenerator; - private final int attempts; - private final DefaultMethodHandleMaker methodHandleMaker = - new DefaultMethodHandleMaker(); - - LambdaInvocationHandler( - Class lambdaType, - Generator returnValueGenerator, - Integer attempts) { - - this.lambdaType = lambdaType; - this.returnValueGenerator = returnValueGenerator; - this.attempts = attempts; + private class LambdaInvocationHandler internal constructor( + private val lambdaType: Class, + private val returnValueGenerator: Generator, + private val attempts: Int + ) : InvocationHandler { + private val methodHandleMaker = DefaultMethodHandleMaker() + + override fun invoke( + proxy: Any, + method: Method, + args: Array + ): Any { + if (Any::class.java == method.declaringClass) return handleObjectMethod(proxy, method, args) + if (method.isDefault) return handleDefaultMethod(proxy, method, args) + val source = SourceOfRandomness(Random()) + source.setSeed(args.contentHashCode().toLong()) + val status: GenerationStatus = SimpleGenerationStatus( + GeometricDistribution(), + source, + attempts + ) + return returnValueGenerator.generate(source, status) } - @Override public Object invoke( - Object proxy, - Method method, - Object[] args) - throws Throwable { - - if (Object.class.equals(method.getDeclaringClass())) - return handleObjectMethod(proxy, method, args); - if (method.isDefault()) - return handleDefaultMethod(proxy, method, args); - - SourceOfRandomness source = new SourceOfRandomness(new Random()); - source.setSeed(Arrays.hashCode(args)); - GenerationStatus status = - new SimpleGenerationStatus( - new GeometricDistribution(), - source, - attempts); - return returnValueGenerator.generate(source, status); + private fun handleObjectMethod( + proxy: Any, + method: Method, + args: Array + ): Any { + if ("equals" == method.name) return proxy === args[0] + return if ("hashCode" == method.name) System.identityHashCode(proxy) else handleToString() } - private Object handleObjectMethod( - Object proxy, - Method method, - Object[] args) { - - if ("equals".equals(method.getName())) - return proxy == args[0]; - - if ("hashCode".equals(method.getName())) - return identityHashCode(proxy); - - return handleToString(); + private fun handleToString(): String { + return "a randomly generated instance of $lambdaType" } - private String handleToString() { - return "a randomly generated instance of " + lambdaType; + private fun handleDefaultMethod( + proxy: Any, + method: Method, + args: Array + ): Any { + val handle = methodHandleMaker.handleForSpecialMethod(method) + return handle.bindTo(proxy).invokeWithArguments(*args) } + } - private Object handleDefaultMethod( - Object proxy, - Method method, - Object[] args) - throws Throwable { - - MethodHandle handle = - methodHandleMaker.handleForSpecialMethod(method); - return handle.bindTo(proxy).invokeWithArguments(args); + companion object { + /** + * + * Creates an instance of a given "functional interface" type, whose + * single abstract method returns values of the type produced by the given + * generator. The arguments to the lambda's single method will be used to + * seed a random generator that will be used to generate the return value + * of that method. + * + * + * junit-quickcheck uses this to create random values for property + * parameters whose type is determined to be a + * [functional interface][FunctionalInterface]. Custom generators + * for functional interface types can use this also. + * + * @param lambdaType a functional interface type token + * @param returnValueGenerator a generator for the return type of the + * functional interface's single method + * @param status an object to be passed along to the generator that will + * produce the functional interface's method return value + * @param the functional interface type token + * @param the type of the generated return value of the functional + * interface method + * @return an instance of the functional interface type, whose single + * method will return a generated value + * @throws IllegalArgumentException if `lambdaType` is not a + * functional interface type + */ + @JvmStatic + fun makeLambda( + lambdaType: Class, + returnValueGenerator: Generator, + status: GenerationStatus + ): T { + requireNotNull(Reflection.singleAbstractMethodOf(lambdaType)) { "$lambdaType is not a functional interface type" } + return lambdaType.cast( + Proxy.newProxyInstance( + lambdaType.classLoader, arrayOf>(lambdaType), + LambdaInvocationHandler( + lambdaType, + returnValueGenerator, + status.attempts() + ) + ) + ) } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/NullAllowed.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/NullAllowed.kt index 6ee0e12c2c..58f03ef534 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/NullAllowed.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/NullAllowed.kt @@ -1,21 +1,16 @@ -package org.utbot.quickcheck.generator; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +package org.utbot.quickcheck.generator /** - *

Mark a parameter of a {@link org.utbot.quickcheck.Property} + * + * Mark a parameter of a * method with this annotation to indicate that the parameter is nullable, and - * to optionally configure the probability of generating a null value.

+ * to optionally configure the probability of generating a null value. */ -@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) -@Retention(RUNTIME) -public @interface NullAllowed { +@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.TYPE) +@Retention(AnnotationRetention.RUNTIME) +annotation class NullAllowed( /** - * @return probability of generating {@code null}, in the range [0,1] + * @return probability of generating `null`, in the range [0,1] */ - double probability() default 0.2; -} + val probability: Double = 0.2 +) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Precision.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Precision.kt index 01ffd4d044..cfb8b895f9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Precision.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Precision.kt @@ -1,23 +1,18 @@ -package org.utbot.quickcheck.generator; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +package org.utbot.quickcheck.generator /** - *

Mark a parameter of a + * + * Mark a parameter of a * method with this annotation to constrain the values generated for the - * parameter to a given precision.

+ * parameter to a given precision. */ -@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) -@Retention(RUNTIME) +@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.TYPE) +@Retention(AnnotationRetention.RUNTIME) @GeneratorConfiguration -public @interface Precision { +annotation class Precision( /** - * @return desired {@linkplain java.math.BigDecimal#scale() scale} of the + * @return desired [scale][java.math.BigDecimal.scale] of the * generated values */ - int scale(); -} + val scale: Int +) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Size.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Size.kt index de93e110ad..94f3b31fa1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Size.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Size.kt @@ -1,25 +1,16 @@ -package org.utbot.quickcheck.generator; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +package org.utbot.quickcheck.generator /** - *

Mark a parameter of a + * + * Mark a parameter of a * method with this annotation to constrain the size of values generated for - * the parameter.

+ * the parameter. * - *

This annotation is recognized on array parameters and parameters of type - * {@link java.util.Collection#size() Collection} and {@link - * java.util.Map#size() Map}.

+ * + * This annotation is recognized on array parameters and parameters of type + * [Collection][java.util.Collection.size] and [ ][java.util.Map.size]. */ -@Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) -@Retention(RUNTIME) +@Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.TYPE) +@Retention(AnnotationRetention.RUNTIME) @GeneratorConfiguration -public @interface Size { - int min() default 0; - - int max(); -} +annotation class Size(val min: Int = 0, val max: Int) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt index 4e99370a77..b842d64c13 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt @@ -1,30 +1,23 @@ -package org.utbot.quickcheck.generator; +package org.utbot.quickcheck.generator -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtNullModel; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import static java.util.Arrays.asList; -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values for property parameters of type {@code void} or - * {@link Void}. + * Produces values for property parameters of type `void` or + * [Void]. */ -public class VoidGenerator extends Generator { - public VoidGenerator() { - super(asList(Void.class, void.class)); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return new UtNullModel(classIdForType(Void.class)); +class VoidGenerator : Generator(listOf(Void::class.java, Void.TYPE)) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return UtNullModel(classIdForType(Void::class.java)) } - @Override - public boolean canRegisterAsType(Class type) { - return !Object.class.equals(type); + override fun canRegisterAsType(type: Class<*>): Boolean { + return Any::class.java != type } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt index ec597b25f2..a2ad748b2c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt @@ -1,39 +1,36 @@ -package org.utbot.quickcheck.generator.java.lang; +package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getStringClassId; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.stringClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness /** - *

Base class for generators of values of type {@link String}.

* - *

The generated values will have {@linkplain String#length()} decided by - * {@link GenerationStatus#size()}.

+ * Base class for generators of values of type [String]. + * + * + * The generated values will have [String.length] decided by + * [GenerationStatus.size]. */ -public abstract class AbstractStringGenerator extends Generator { - protected AbstractStringGenerator() { - super(String.class); +abstract class AbstractStringGenerator : Generator(String::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(generateValue(random, status), stringClassId) } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getStringClassId()); + fun generateValue( + random: SourceOfRandomness, + status: GenerationStatus + ): String { + val codePoints = IntArray(status.size()) + for (i in codePoints.indices) codePoints[i] = nextCodePoint(random) + return String(codePoints, 0, codePoints.size) } - public String generateValue( SourceOfRandomness random, - GenerationStatus status){ - int[] codePoints = new int[status.size()]; - - for (int i = 0; i < codePoints.length; ++i) - codePoints[i] = nextCodePoint(random); - return new String(codePoints, 0, codePoints.length); - } - - protected abstract int nextCodePoint(SourceOfRandomness random); - -} + protected abstract fun nextCodePoint(random: SourceOfRandomness): Int +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt index eb5542a3b0..7f7f29b05b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt @@ -1,28 +1,24 @@ +package org.utbot.quickcheck.generator.java.lang -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import static java.util.Collections.singletonList; -import static org.utbot.framework.plugin.api.util.IdUtilKt.getBooleanWrapperClassId; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.booleanWrapperClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code boolean} or {@link Boolean}. + * Produces values of type `boolean` or [Boolean]. */ -public class BooleanGenerator extends Generator { - public BooleanGenerator() { - super(singletonList(Boolean.class)); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextBoolean(), getBooleanWrapperClassId()); +class BooleanGenerator : Generator( + listOf( + Boolean::class.java + ) +) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextBoolean(), booleanWrapperClassId) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt index 66857a36cf..1d4b99f6fa 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt @@ -1,61 +1,40 @@ - - -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.IntegralGenerator; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.lang + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.byteWrapperClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.IntegralGenerator +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code byte} or {@link Byte}. + * Produces values of type `byte` or [Byte]. */ -public class ByteGenerator extends IntegralGenerator { - private byte min = (Byte) defaultValueOf(InRange.class, "minByte"); - private byte max = (Byte) defaultValueOf(InRange.class, "maxByte"); - - public ByteGenerator() { - super(Collections.singletonList(Byte.class)); - } +class ByteGenerator : IntegralGenerator(listOf(Byte::class.java)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minByte") as Byte + private var max = Reflection.defaultValueOf(InRange::class.java, "maxByte") as Byte /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minByte()} and {@link InRange#maxByte()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minByte] and [InRange.maxByte], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minByte() - : Byte.parseByte(range.min()); - max = - range.max().isEmpty() - ? range.maxByte() - : Byte.parseByte(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minByte else range.min.toByte() + max = if (range.max.isEmpty()) range.maxByte else range.max.toByte() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextByte(min, max), classIdForType(Byte.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextByte(min, max), byteWrapperClassId) } - - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); - } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt index df46a2cd4e..9eced4f0ae 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt @@ -1,48 +1,43 @@ +package org.utbot.quickcheck.generator.java.lang -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getCharWrapperClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.charWrapperClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code char} or {@link Character}. + * Produces values of type `char` or [Character]. */ -public class CharacterGenerator extends Generator { - private char min = (Character) defaultValueOf(InRange.class, "minChar"); - private char max = (Character) defaultValueOf(InRange.class, "maxChar"); - - public CharacterGenerator() { - super(Collections.singletonList(Character.class)); - } +class CharacterGenerator : Generator( + listOf( + Char::class.java + ) +) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minChar") as Char + private var max = Reflection.defaultValueOf(InRange::class.java, "maxChar") as Char /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minChar()} and {@link InRange#maxChar()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minChar] and [InRange.maxChar], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = range.min().isEmpty() ? range.minChar() : range.min().charAt(0); - max = range.max().isEmpty() ? range.maxChar() : range.max().charAt(0); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minChar else range.min[0] + max = if (range.max.isEmpty()) range.maxChar else range.max[0] } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextChar(min, max), getCharWrapperClassId()); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextChar(min, max), charWrapperClassId) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt index 8107e401de..33ad67cbb2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt @@ -1,67 +1,48 @@ +package org.utbot.quickcheck.generator.java.lang -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.DecimalGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getDoubleWrapperClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.doubleWrapperClassId +import org.utbot.quickcheck.generator.DecimalGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values for property parameters of type {@code double} or - * {@link Double}. + * Produces values for property parameters of type `double` or + * [Double]. */ -public class DoubleGenerator extends DecimalGenerator { - private double min = (Double) defaultValueOf(InRange.class, "minDouble"); - private double max = (Double) defaultValueOf(InRange.class, "maxDouble"); - - public DoubleGenerator() { - super(Collections.singletonList(Double.class)); - } +class DoubleGenerator : DecimalGenerator(listOf(Double::class.java)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minDouble") as Double + private var max = Reflection.defaultValueOf(InRange::class.java, "maxDouble") as Double /** * Tells this generator to produce values within a specified minimum * (inclusive) and/or maximum (exclusive) with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minDouble()} and {@link InRange#maxDouble()}, + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minDouble] and [InRange.maxDouble], * if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minDouble() - : Double.parseDouble(range.min()); - max = - range.max().isEmpty() - ? range.maxDouble() - : Double.parseDouble(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minDouble else range.min.toDouble() + max = if (range.max.isEmpty()) range.maxDouble else range.max.toDouble() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getDoubleWrapperClassId()); - } - - public double generateValue(SourceOfRandomness random, - GenerationStatus status) { - return random.nextDouble(min, max); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(generateValue(random, status), doubleWrapperClassId) } - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); + fun generateValue( + random: SourceOfRandomness, + status: GenerationStatus? + ): Double { + return random.nextDouble(min, max) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt index d002986a5c..e1e4b4641b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt @@ -1,28 +1,22 @@ +package org.utbot.quickcheck.generator.java.lang - -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.quickcheck.generator.GeneratorConfiguration; -import org.utbot.quickcheck.generator.java.lang.strings.CodePoints; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import java.nio.charset.Charset; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; +import org.utbot.quickcheck.generator.GeneratorConfiguration +import org.utbot.quickcheck.generator.java.lang.strings.CodePoints +import org.utbot.quickcheck.generator.java.lang.strings.CodePoints.Companion.forCharset +import org.utbot.quickcheck.random.SourceOfRandomness +import java.nio.charset.Charset /** - *

Produces {@link String}s whose code points correspond to code points in - * a given {@link Charset} - * ({@link Charset#defaultCharset() by default}).

+ * + * Produces [String]s whose code points correspond to code points in + * a given [Charset] + * ([by default][Charset.defaultCharset]). */ -public class Encoded extends AbstractStringGenerator { - private CodePoints charsetPoints; +class Encoded : AbstractStringGenerator() { + private var charsetPoints: CodePoints? = null - public Encoded() { - initialize(Charset.defaultCharset()); + init { + initialize(Charset.defaultCharset()) } /** @@ -31,25 +25,23 @@ public class Encoded extends AbstractStringGenerator { * @param charset a charset to use as the source for characters of * generated strings */ - public void configure(InCharset charset) { - initialize(Charset.forName(charset.value())); + fun configure(charset: InCharset) { + initialize(Charset.forName(charset.value)) } - private void initialize(Charset charset) { - charsetPoints = CodePoints.forCharset(charset); + private fun initialize(charset: Charset) { + charsetPoints = forCharset(charset) } - @Override protected int nextCodePoint(SourceOfRandomness random) { - return charsetPoints.at(random.nextInt(0, charsetPoints.size() - 1)); + override fun nextCodePoint(random: SourceOfRandomness): Int { + return charsetPoints!!.at(random.nextInt(0, charsetPoints!!.size() - 1)) } /** - * Names a {@link Charset}. + * Names a [Charset]. */ - @Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) - @Retention(RUNTIME) + @Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.TYPE) + @Retention(AnnotationRetention.RUNTIME) @GeneratorConfiguration - public @interface InCharset { - String value(); - } -} + annotation class InCharset(val value: String) +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt index 01a497d14c..cb4cf6115f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt @@ -1,59 +1,39 @@ -package org.utbot.quickcheck.generator.java.lang; +package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.DecimalGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getFloatWrapperClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.floatWrapperClassId +import org.utbot.quickcheck.generator.DecimalGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code float} or {@link Float}. + * Produces values of type `float` or [Float]. */ -public class FloatGenerator extends DecimalGenerator { - private float min = (Float) defaultValueOf(InRange.class, "minFloat"); - private float max = (Float) defaultValueOf(InRange.class, "maxFloat"); - - public FloatGenerator() { - super(Collections.singletonList(Float.class)); - } +class FloatGenerator : DecimalGenerator(listOf(Float::class.java)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minFloat") as Float + private var max = Reflection.defaultValueOf(InRange::class.java, "maxFloat") as Float /** * Tells this generator to produce values within a specified minimum * (inclusive) and/or maximum (exclusive) with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minFloat()} and {@link InRange#maxFloat()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minFloat] and [InRange.maxFloat], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minFloat() - : Float.parseFloat(range.min()); - max = - range.max().isEmpty() - ? range.maxFloat() - : Float.parseFloat(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minFloat else range.min.toFloat() + max = if (range.max.isEmpty()) range.maxFloat else range.max.toFloat() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextFloat(min, max), getFloatWrapperClassId()); - } - - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextFloat(min, max), floatWrapperClassId) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt index 7deef84004..fa68e70b05 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt @@ -1,64 +1,46 @@ +package org.utbot.quickcheck.generator.java.lang -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.IntegralGenerator; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getIntWrapperClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.intWrapperClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.IntegralGenerator +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code int} or {@link Integer}. + * Produces values of type `int` or [Integer]. */ -public class IntegerGenerator extends IntegralGenerator { - private int min = (Integer) defaultValueOf(InRange.class, "minInt"); - private int max = (Integer) defaultValueOf(InRange.class, "maxInt"); - - public IntegerGenerator() { - super(Collections.singletonList(Integer.class)); - } +class IntegerGenerator : IntegralGenerator(listOf(Int::class.java)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minInt") as Int + private var max = Reflection.defaultValueOf(InRange::class.java, "maxInt") as Int /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minInt()} and {@link InRange#maxInt()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minInt] and [InRange.maxInt], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minInt() - : Integer.parseInt(range.min()); - max = - range.max().isEmpty() - ? range.maxInt() - : Integer.parseInt(range.max()); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getIntWrapperClassId()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minInt else range.min.toInt() + max = if (range.max.isEmpty()) range.maxInt else range.max.toInt() } - public int generateValue(SourceOfRandomness random, - GenerationStatus status) { - return random.nextInt(min, max); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(generateValue(random, status), intWrapperClassId) } - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); + fun generateValue( + random: SourceOfRandomness, + status: GenerationStatus? + ): Int { + return random.nextInt(min, max) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt index 26717f3345..2a44892f30 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt @@ -1,64 +1,46 @@ -package org.utbot.quickcheck.generator.java.lang; +package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.IntegralGenerator; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getLongWrapperClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.longWrapperClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.IntegralGenerator +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code long} or {@link Long}. + * Produces values of type `long` or [Long]. */ -public class LongGenerator extends IntegralGenerator { - private long min = (Long) defaultValueOf(InRange.class, "minLong"); - private long max = (Long) defaultValueOf(InRange.class, "maxLong"); - - public LongGenerator() { - super(Collections.singletonList(Long.class)); - } +class LongGenerator : IntegralGenerator(listOf(Long::class.java)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minLong") as Long + private var max = Reflection.defaultValueOf(InRange::class.java, "maxLong") as Long /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minLong()} and {@link InRange#maxLong()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minLong] and [InRange.maxLong], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minLong() - : Long.parseLong(range.min()); - max = - range.max().isEmpty() - ? range.maxLong() - : Long.parseLong(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minLong else range.min.toLong() + max = if (range.max.isEmpty()) range.maxLong else range.max.toLong() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getLongWrapperClassId()); - } - - public long generateValue(SourceOfRandomness random, - GenerationStatus status) { - return random.nextLong(min, max); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(generateValue(random, status), longWrapperClassId) } - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); + fun generateValue( + random: SourceOfRandomness, + status: GenerationStatus? + ): Long { + return random.nextLong(min, max) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt index 744bd363d8..a57ab68a86 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt @@ -1,28 +1,20 @@ +package org.utbot.quickcheck.generator.java.lang -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import static java.util.Collections.singletonList; -import static org.utbot.framework.plugin.api.util.IdUtilKt.getBooleanClassId; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.booleanClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code boolean} or {@link Boolean}. + * Produces values of type `boolean` or [Boolean]. */ -public class PrimitiveBooleanGenerator extends Generator { - public PrimitiveBooleanGenerator() { - super(singletonList(boolean.class)); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextBoolean(), getBooleanClassId()); +class PrimitiveBooleanGenerator : Generator(listOf(Boolean::class.javaPrimitiveType!!)) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextBoolean(), booleanClassId) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt index ddf7392865..dd94281b31 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt @@ -1,60 +1,39 @@ +package org.utbot.quickcheck.generator.java.lang -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.IntegralGenerator; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getByteClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.byteClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.IntegralGenerator +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code byte} or {@link Byte}. + * Produces values of type `byte` or [Byte]. */ -public class PrimitiveByteGenerator extends IntegralGenerator { - private byte min = (Byte) defaultValueOf(InRange.class, "minByte"); - private byte max = (Byte) defaultValueOf(InRange.class, "maxByte"); - - public PrimitiveByteGenerator() { - super(Collections.singletonList(byte.class)); - } +class PrimitiveByteGenerator : IntegralGenerator(listOf(Byte::class.javaPrimitiveType!!)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minByte") as Byte + private var max = Reflection.defaultValueOf(InRange::class.java, "maxByte") as Byte /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minByte()} and {@link InRange#maxByte()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minByte] and [InRange.maxByte], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minByte() - : Byte.parseByte(range.min()); - max = - range.max().isEmpty() - ? range.maxByte() - : Byte.parseByte(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minByte else range.min.toByte() + max = if (range.max.isEmpty()) range.maxByte else range.max.toByte() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextByte(min, max), getByteClassId()); - } - - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextByte(min, max), byteClassId) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt index 678cf229b0..43db91f4b0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt @@ -1,51 +1,40 @@ -package org.utbot.quickcheck.generator.java.lang; +package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getCharClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.charClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code char} or {@link Character}. + * Produces values of type `char` or [Character]. */ -public class PrimitiveCharGenerator extends Generator { - private char min = (Character) defaultValueOf(InRange.class, "minChar"); - private char max = (Character) defaultValueOf(InRange.class, "maxChar"); - - public PrimitiveCharGenerator() { - super(Collections.singletonList(char.class)); - } +class PrimitiveCharGenerator : Generator(listOf(Char::class.javaPrimitiveType!!)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minChar") as Char + private var max = Reflection.defaultValueOf(InRange::class.java, "maxChar") as Char /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minChar()} and {@link InRange#maxChar()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minChar] and [InRange.maxChar], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = range.min().isEmpty() ? range.minChar() : range.min().charAt(0); - max = range.max().isEmpty() ? range.maxChar() : range.max().charAt(0); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minChar else range.min[0] + max = if (range.max.isEmpty()) range.maxChar else range.max[0] } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextChar(min, max), getCharClassId()); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextChar(min, max), charClassId) } - private boolean inRange(Character value) { - return Comparables.inRange(min, max).test(value); - } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt index d4e9241c87..1235302a24 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt @@ -1,67 +1,48 @@ +package org.utbot.quickcheck.generator.java.lang -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.DecimalGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getDoubleClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.doubleClassId +import org.utbot.quickcheck.generator.DecimalGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values for property parameters of type {@code double} or - * {@link Double}. + * Produces values for property parameters of type `double` or + * [Double]. */ -public class PrimitiveDoubleGenerator extends DecimalGenerator { - private double min = (Double) defaultValueOf(InRange.class, "minDouble"); - private double max = (Double) defaultValueOf(InRange.class, "maxDouble"); - - public PrimitiveDoubleGenerator() { - super(Collections.singletonList(double.class)); - } +class PrimitiveDoubleGenerator : DecimalGenerator(listOf(Double::class.javaPrimitiveType!!)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minDouble") as Double + private var max = Reflection.defaultValueOf(InRange::class.java, "maxDouble") as Double /** * Tells this generator to produce values within a specified minimum * (inclusive) and/or maximum (exclusive) with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minDouble()} and {@link InRange#maxDouble()}, + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minDouble] and [InRange.maxDouble], * if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minDouble() - : Double.parseDouble(range.min()); - max = - range.max().isEmpty() - ? range.maxDouble() - : Double.parseDouble(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minDouble else range.min.toDouble() + max = if (range.max.isEmpty()) range.maxDouble else range.max.toDouble() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getDoubleClassId()); - } - - public double generateValue(SourceOfRandomness random, - GenerationStatus status) { - return random.nextDouble(min, max); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(generateValue(random, status), doubleClassId) } - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); + fun generateValue( + random: SourceOfRandomness, + status: GenerationStatus? + ): Double { + return random.nextDouble(min, max) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt index a861668d85..6b7ddb17a7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt @@ -1,61 +1,39 @@ +package org.utbot.quickcheck.generator.java.lang - -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.DecimalGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getFloatClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.floatClassId +import org.utbot.quickcheck.generator.DecimalGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code float} or {@link Float}. + * Produces values of type `float` or [Float]. */ -public class PrimitiveFloatGenerator extends DecimalGenerator { - private float min = (Float) defaultValueOf(InRange.class, "minFloat"); - private float max = (Float) defaultValueOf(InRange.class, "maxFloat"); - - public PrimitiveFloatGenerator() { - super(Collections.singletonList(float.class)); - } +class PrimitiveFloatGenerator : DecimalGenerator(listOf(Float::class.javaPrimitiveType!!)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minFloat") as Float + private var max = Reflection.defaultValueOf(InRange::class.java, "maxFloat") as Float /** * Tells this generator to produce values within a specified minimum * (inclusive) and/or maximum (exclusive) with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minFloat()} and {@link InRange#maxFloat()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minFloat] and [InRange.maxFloat], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minFloat() - : Float.parseFloat(range.min()); - max = - range.max().isEmpty() - ? range.maxFloat() - : Float.parseFloat(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minFloat else range.min.toFloat() + max = if (range.max.isEmpty()) range.maxFloat else range.max.toFloat() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextFloat(min, max), getFloatClassId()); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextFloat(min, max), floatClassId) } - - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); - } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt index 49de2f9945..e8029e4101 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt @@ -1,65 +1,46 @@ +package org.utbot.quickcheck.generator.java.lang - -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.IntegralGenerator; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getIntClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.intClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.IntegralGenerator +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code int} or {@link Integer}. + * Produces values of type `int` or [Integer]. */ -public class PrimitiveIntGenerator extends IntegralGenerator { - private int min = (Integer) defaultValueOf(InRange.class, "minInt"); - private int max = (Integer) defaultValueOf(InRange.class, "maxInt"); - - public PrimitiveIntGenerator() { - super(Collections.singletonList(int.class)); - } +class PrimitiveIntGenerator : IntegralGenerator(listOf(Int::class.javaPrimitiveType!!)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minInt") as Int + private var max = Reflection.defaultValueOf(InRange::class.java, "maxInt") as Int /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minInt()} and {@link InRange#maxInt()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minInt] and [InRange.maxInt], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minInt() - : Integer.parseInt(range.min()); - max = - range.max().isEmpty() - ? range.maxInt() - : Integer.parseInt(range.max()); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getIntClassId()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minInt else range.min.toInt() + max = if (range.max.isEmpty()) range.maxInt else range.max.toInt() } - public int generateValue(SourceOfRandomness random, - GenerationStatus status) { - return random.nextInt(min, max); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(generateValue(random, status), intClassId) } - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); + fun generateValue( + random: SourceOfRandomness, + status: GenerationStatus? + ): Int { + return random.nextInt(min, max) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt index c28fd95ee3..75617c02fc 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt @@ -1,66 +1,46 @@ +package org.utbot.quickcheck.generator.java.lang - -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.IntegralGenerator; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getLongClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.longClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.IntegralGenerator +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code long} or {@link Long}. + * Produces values of type `long` or [Long]. */ -public class PrimitiveLongGenerator extends IntegralGenerator { - private long min = (Long) defaultValueOf(InRange.class, "minLong"); - private long max = (Long) defaultValueOf(InRange.class, "maxLong"); - - public PrimitiveLongGenerator() { - super(Collections.singletonList(long.class)); - } +class PrimitiveLongGenerator : IntegralGenerator(listOf(Long::class.javaPrimitiveType!!)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minLong") as Long + private var max = Reflection.defaultValueOf(InRange::class.java, "maxLong") as Long /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minLong()} and {@link InRange#maxLong()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minLong] and [InRange.maxLong], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minLong() - : Long.parseLong(range.min()); - max = - range.max().isEmpty() - ? range.maxLong() - : Long.parseLong(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minLong else range.min.toLong() + max = if (range.max.isEmpty()) range.maxLong else range.max.toLong() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(generateValue(random, status), getLongClassId()); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(generateValue(random, status), longClassId) } - public long generateValue(SourceOfRandomness random, - GenerationStatus status) { - return random.nextLong(min, max); + fun generateValue( + random: SourceOfRandomness, + status: GenerationStatus? + ): Long { + return random.nextLong(min, max) } - - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); - } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt index 9a5cea74ba..ba5cb4fa03 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt @@ -1,61 +1,39 @@ +package org.utbot.quickcheck.generator.java.lang - -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.IntegralGenerator; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getShortClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.shortClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.IntegralGenerator +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code short} or {@link Short}. + * Produces values of type `short` or [Short]. */ -public class PrimitiveShortGenerator extends IntegralGenerator { - private short min = (Short) defaultValueOf(InRange.class, "minShort"); - private short max = (Short) defaultValueOf(InRange.class, "maxShort"); - - public PrimitiveShortGenerator() { - super(Collections.singletonList(short.class)); - } +class PrimitiveShortGenerator : IntegralGenerator(listOf(Short::class.javaPrimitiveType!!)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minShort") as Short + private var max = Reflection.defaultValueOf(InRange::class.java, "maxShort") as Short /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minShort()} and {@link InRange#maxShort()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minShort] and [InRange.maxShort], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minShort() - : Short.parseShort(range.min()); - max = - range.max().isEmpty() - ? range.maxShort() - : Short.parseShort(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minShort else range.min.toShort() + max = if (range.max.isEmpty()) range.maxShort else range.max.toShort() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextShort(min, max), getShortClassId()); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextShort(min, max), shortClassId) } - - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); - } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt index a721cc2d49..0d30ad243a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt @@ -1,61 +1,39 @@ +package org.utbot.quickcheck.generator.java.lang - -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.IntegralGenerator; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collections; -import java.util.function.Predicate; - -import static org.utbot.framework.plugin.api.util.IdUtilKt.getShortWrapperClassId; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.shortWrapperClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.IntegralGenerator +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness /** - * Produces values of type {@code short} or {@link Short}. + * Produces values of type `short` or [Short]. */ -public class ShortGenerator extends IntegralGenerator { - private short min = (Short) defaultValueOf(InRange.class, "minShort"); - private short max = (Short) defaultValueOf(InRange.class, "maxShort"); - - public ShortGenerator() { - super(Collections.singletonList(Short.class)); - } +class ShortGenerator : IntegralGenerator(listOf(Short::class.java)) { + private var min = Reflection.defaultValueOf(InRange::class.java, "minShort") as Short + private var max = Reflection.defaultValueOf(InRange::class.java, "maxShort") as Short /** * Tells this generator to produce values within a specified minimum and/or * maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minShort()} and {@link InRange#maxShort()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minShort] and [InRange.maxShort], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - min = - range.min().isEmpty() - ? range.minShort() - : Short.parseShort(range.min()); - max = - range.max().isEmpty() - ? range.maxShort() - : Short.parseShort(range.max()); + fun configure(range: InRange) { + min = if (range.min.isEmpty()) range.minShort else range.min.toShort() + max = if (range.max.isEmpty()) range.maxShort else range.max.toShort() } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextShort(min, max), getShortWrapperClassId()); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextShort(min, max), shortWrapperClassId) } - - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); - } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt index c011c0dd13..e76e31b3c8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt @@ -1,16 +1,14 @@ +package org.utbot.quickcheck.generator.java.lang - -package org.utbot.quickcheck.generator.java.lang; - -import org.utbot.quickcheck.random.SourceOfRandomness; +import org.utbot.quickcheck.random.SourceOfRandomness /** - *

Produces {@link String}s whose characters are in the interval - * {@code [0x0000, 0xD7FF]}.

+ * + * Produces [String]s whose characters are in the interval + * `[0x0000, 0xD7FF]`. */ -public class StringGenerator extends AbstractStringGenerator { - @Override protected int nextCodePoint(SourceOfRandomness random) { - return random.nextInt(0, Character.MIN_SURROGATE - 1); +class StringGenerator : AbstractStringGenerator() { + override fun nextCodePoint(random: SourceOfRandomness): Int { + return random.nextInt(0, Character.MIN_SURROGATE.code - 1) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt index 9d2b8dfbd2..bebb799fcc 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt @@ -1,167 +1,142 @@ +package org.utbot.quickcheck.generator.java.lang.strings - -package org.utbot.quickcheck.generator.java.lang.strings; - -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static java.lang.String.format; +import java.nio.charset.Charset +import java.nio.charset.CharsetEncoder /** * Maps ordinal values to corresponding Unicode code points in a - * {@link Charset}. + * [Charset]. */ -public class CodePoints { - private static final Map ENCODABLES = - new HashMap<>(); - - private final List ranges; +class CodePoints internal constructor() { + private val ranges: MutableList - CodePoints() { - ranges = new ArrayList<>(); + init { + ranges = ArrayList() } /** * @param index index to look up - * @return this code point set's {@code index}'th code point + * @return this code point set's `index`'th code point * @throws IndexOutOfBoundsException if there is no such code point */ - public int at(int index) { + fun at(index: Int): Int { if (index < 0) { - throw new IndexOutOfBoundsException( - "illegal negative index: " + index); + throw IndexOutOfBoundsException( + "illegal negative index: $index" + ) } - - int min = 0; - int max = ranges.size() - 1; - + var min = 0 + var max = ranges.size - 1 while (min <= max) { - int midpoint = min + ((max - min) / 2); - CodePointRange current = ranges.get(midpoint); - + val midpoint = min + (max - min) / 2 + val current = ranges[midpoint] if (index >= current.previousCount - && index < current.previousCount + current.size()) { - - return current.low + index - current.previousCount; + && index < current.previousCount + current.size() + ) { + return current.low + index - current.previousCount } else if (index < current.previousCount) { - max = midpoint - 1; + max = midpoint - 1 } else { - min = midpoint + 1; + min = midpoint + 1 } } - - throw new IndexOutOfBoundsException(String.valueOf(index)); + throw IndexOutOfBoundsException(index.toString()) } /** * @return how many code points are in this code point set */ - public int size() { - if (ranges.isEmpty()) - return 0; - - CodePointRange last = ranges.get(ranges.size() - 1); - return last.previousCount + last.size(); + fun size(): Int { + if (ranges.isEmpty()) return 0 + val last = ranges[ranges.size - 1] + return last.previousCount + last.size() } /** * @param codePoint a code point * @return whether this code point set contains the given code point */ - public boolean contains(int codePoint) { - return ranges.stream().anyMatch(r -> r.contains(codePoint)); - } - - /** - * Gives a set of the code points in the given charset. - * - * @param c a charset - * @return the set of code points in the charset - */ - public static CodePoints forCharset(Charset c) { - if (ENCODABLES.containsKey(c)) - return ENCODABLES.get(c); - - CodePoints points = load(c); - ENCODABLES.put(c, points); - return points; + operator fun contains(codePoint: Int): Boolean { + return ranges.stream().anyMatch { r: CodePointRange -> r.contains(codePoint) } } - private static CodePoints load(Charset c) { - if (!c.canEncode()) { - throw new IllegalArgumentException( - "Charset " + c.name() + " does not support encoding"); - } - - return encodableCodePoints(c.newEncoder()); - } - - void add(CodePointRange range) { - ranges.add(range); + fun add(range: CodePointRange) { + ranges.add(range) } - private static CodePoints encodableCodePoints(CharsetEncoder encoder) { - CodePoints points = new CodePoints(); + class CodePointRange(low: Int, high: Int, previousCount: Int) { + val low: Int + val high: Int + val previousCount: Int - int start = 0; - boolean inRange = false; - int current = 0; - int previousCount = 0; - int[] buffer = new int[1]; - - for (; current <= Character.MAX_CODE_POINT; ++current) { - encoder.reset(); - buffer[0] = current; - - String s = new String(buffer, 0, 1); - if (encoder.canEncode(s)) { - if (!inRange) { - inRange = true; - start = current; - } - } else if (inRange) { - inRange = false; - CodePointRange range = - new CodePointRange(start, current - 1, previousCount); - points.add(range); - previousCount += range.size(); - } + init { + require(low <= high) { String.format("%d > %d", low, high) } + this.low = low + this.high = high + this.previousCount = previousCount } - if (inRange) { - points.add( - new CodePointRange(start, current - 1, previousCount)); + operator fun contains(codePoint: Int): Boolean { + return codePoint >= low && codePoint <= high } - return points; + fun size(): Int { + return high - low + 1 + } } - static class CodePointRange { - final int low; - final int high; - final int previousCount; - - CodePointRange(int low, int high, int previousCount) { - if (low > high) { - throw new IllegalArgumentException( - format("%d > %d", low, high)); - } - - this.low = low; - this.high = high; - this.previousCount = previousCount; + companion object { + private val ENCODABLES: MutableMap = HashMap() + + /** + * Gives a set of the code points in the given charset. + * + * @param c a charset + * @return the set of code points in the charset + */ + @JvmStatic + fun forCharset(c: Charset): CodePoints? { + if (ENCODABLES.containsKey(c)) return ENCODABLES[c] + val points = load(c) + ENCODABLES[c] = points + return points } - boolean contains(int codePoint) { - return codePoint >= low && codePoint <= high; + private fun load(c: Charset): CodePoints { + require(c.canEncode()) { "Charset " + c.name() + " does not support encoding" } + return encodableCodePoints(c.newEncoder()) } - int size() { - return high - low + 1; + private fun encodableCodePoints(encoder: CharsetEncoder): CodePoints { + val points = CodePoints() + var start = 0 + var inRange = false + var current = 0 + var previousCount = 0 + val buffer = IntArray(1) + while (current <= Character.MAX_CODE_POINT) { + encoder.reset() + buffer[0] = current + val s = String(buffer, 0, 1) + if (encoder.canEncode(s)) { + if (!inRange) { + inRange = true + start = current + } + } else if (inRange) { + inRange = false + val range = CodePointRange(start, current - 1, previousCount) + points.add(range) + previousCount += range.size() + } + ++current + } + if (inRange) { + points.add( + CodePointRange(start, current - 1, previousCount) + ) + } + return points } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt index 1c78e25065..ce69bdb8a0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt @@ -1,135 +1,108 @@ - - -package org.utbot.quickcheck.generator.java.math; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.DecimalGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.Precision; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.internal.Ranges; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.math.BigDecimal; -import java.math.BigInteger; -import java.util.function.Predicate; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Ranges.checkRange; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.lang.Math.max; -import static java.math.BigDecimal.TEN; +package org.utbot.quickcheck.generator.java.math + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.DecimalGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.Precision +import org.utbot.quickcheck.internal.Ranges +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.math.BigDecimal +import java.math.BigInteger /** - *

Produces values of type {@link BigDecimal}.

* - *

With no additional configuration, the generated values are chosen from + * Produces values of type [BigDecimal]. + * + * + * With no additional configuration, the generated values are chosen from * a range with a magnitude decided by - * {@link GenerationStatus#size()}.

+ * [GenerationStatus.size]. */ -public class BigDecimalGenerator extends DecimalGenerator { - private BigDecimal min; - private BigDecimal max; - private Precision precision; - - public BigDecimalGenerator() { - super(BigDecimal.class); - } +class BigDecimalGenerator : DecimalGenerator(BigDecimal::class.java) { + private var min: BigDecimal? = null + private var max: BigDecimal? = null + private var precision: Precision? = null /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} (inclusive) and/or - * {@linkplain InRange#max() maximum} (exclusive), with uniform - * distribution.

* - *

If an endpoint of the range is not specified, its value takes on + * Tells this generator to produce values within a specified + * [minimum][InRange.min] (inclusive) and/or + * [maximum][InRange.max] (exclusive), with uniform + * distribution. + * + * + * If an endpoint of the range is not specified, its value takes on * a magnitude influenced by - * {@link GenerationStatus#size()}.

+ * [GenerationStatus.size]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = new BigDecimal(range.min()); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = new BigDecimal(range.max()); - - if (min != null && max != null) - checkRange(Ranges.Type.FLOAT, min, max); + fun configure(range: InRange) { + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = BigDecimal(range.min) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = BigDecimal(range.max) + if (min != null && max != null) Ranges.checkRange(Ranges.Type.FLOAT, min, max) } /** - *

Tells this generator to produce values that have a specified - * {@linkplain Precision#scale() scale}.

* - *

With no precision constraint and no {@linkplain #configure(InRange) - * min/max constraint}, the scale of the generated values is - * unspecified.

+ * Tells this generator to produce values that have a specified + * [scale][Precision.scale]. + * + * + * With no precision constraint and no [ min/max constraint][.configure], the scale of the generated values is + * unspecified. * - *

Otherwise, the scale of the generated values is set as - * {@code max(0, precision.scale, range.min.scale, range.max.scale)}.

+ * + * Otherwise, the scale of the generated values is set as + * `max(0, precision.scale, range.min.scale, range.max.scale)`. * * @param configuration annotation that gives the desired scale of the - * generated values + * generated values */ - public void configure(Precision configuration) { - precision = configuration; + fun configure(configuration: Precision?) { + precision = configuration } - @Override - public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - BigDecimal minToUse = min; - BigDecimal maxToUse = max; - int power = status.size() + 1; - + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + var minToUse = min + var maxToUse = max + val power = status.size() + 1 if (minToUse == null && maxToUse == null) { - maxToUse = TEN.pow(power); - minToUse = maxToUse.negate(); + maxToUse = BigDecimal.TEN.pow(power) + minToUse = maxToUse.negate() } - - if (minToUse == null) - minToUse = maxToUse.subtract(TEN.pow(power)); - else if (maxToUse == null) - maxToUse = minToUse.add(TEN.pow(power)); - - int scale = decideScale(); - - BigDecimal minShifted = minToUse.movePointRight(scale); - BigDecimal maxShifted = maxToUse.movePointRight(scale); - BigInteger range = - maxShifted.toBigInteger().subtract(minShifted.toBigInteger()); - - BigInteger generated; + when { + minToUse == null -> minToUse = maxToUse!!.subtract(BigDecimal.TEN.pow(power)) + maxToUse == null -> maxToUse = minToUse.add(BigDecimal.TEN.pow(power)) + } + val scale = decideScale() + val minShifted = minToUse!!.movePointRight(scale) + val maxShifted = maxToUse!!.movePointRight(scale) + val range = maxShifted.toBigInteger().subtract(minShifted.toBigInteger()) + var generated: BigInteger do { - generated = random.nextBigInteger(range.bitLength()); - } while (generated.compareTo(range) >= 0); - - - return UtModelGenerator.getUtModelConstructor().construct(minShifted.add(new BigDecimal(generated)) - .movePointLeft(scale), classIdForType(BigDecimal.class)); - } - - private int decideScale() { - int scale = Integer.MIN_VALUE; - - if (min != null) - scale = max(scale, min.scale()); - if (max != null) - scale = max(scale, max.scale()); - if (precision != null) - scale = max(scale, precision.scale()); + generated = random.nextBigInteger(range.bitLength()) + } while (generated >= range) - return max(scale, 0); + return utModelConstructor.construct( + minShifted.add(BigDecimal(generated)).movePointLeft(scale), + BigDecimal::class.id + ) } - @Override - protected Predicate inRange() { - return Comparables.inRange(min, max); + private fun decideScale(): Int { + var scale = Int.MIN_VALUE + if (min != null) scale = scale.coerceAtLeast(min!!.scale()) + if (max != null) scale = scale.coerceAtLeast(max!!.scale()) + if (precision != null) scale = scale.coerceAtLeast(precision!!.scale) + return scale.coerceAtLeast(0) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt index f682d5014c..337a5aa483 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt @@ -1,81 +1,66 @@ - - -package org.utbot.quickcheck.generator.java.math; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.IntegralGenerator; -import org.utbot.quickcheck.internal.Comparables; -import org.utbot.quickcheck.internal.Ranges; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.math.BigInteger; -import java.util.function.Predicate; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Ranges.checkRange; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; -import static java.math.BigInteger.TEN; +package org.utbot.quickcheck.generator.java.math + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.IntegralGenerator +import org.utbot.quickcheck.internal.Ranges +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.math.BigInteger /** - *

Produces values of type {@link BigInteger}.

* - *

With no additional configuration, the generated values are chosen from + * Produces values of type [BigInteger]. + * + * + * With no additional configuration, the generated values are chosen from * a range with a magnitude decided by - * {@link GenerationStatus#size()}.

+ * [GenerationStatus.size]. */ -public class BigIntegerGenerator extends IntegralGenerator { - private BigInteger min; - private BigInteger max; - - public BigIntegerGenerator() { - super(BigInteger.class); - } +class BigIntegerGenerator : IntegralGenerator(BigInteger::class.java) { + private var min: BigInteger? = null + private var max: BigInteger? = null /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or - * {@linkplain InRange#max() maximum} inclusive, with uniform - * distribution.

* - *

If an endpoint of the range is not specified, its value takes on + * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or + * [maximum][InRange.max] inclusive, with uniform + * distribution. + * + * + * If an endpoint of the range is not specified, its value takes on * a magnitude influenced by - * {@link GenerationStatus#size()}.

- + * [GenerationStatus.size]. + * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = new BigInteger(range.min()); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = new BigInteger(range.max()); - if (min != null && max != null) - checkRange(Ranges.Type.INTEGRAL, min, max); + fun configure(range: InRange) { + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = BigInteger(range.min) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = BigInteger(range.max) + if (min != null && max != null) Ranges.checkRange(Ranges.Type.INTEGRAL, min, max) } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - int numberOfBits = status.size() + 1; - + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val numberOfBits = status.size() + 1 if (min == null && max == null) - return UtModelGenerator.getUtModelConstructor().construct(random.nextBigInteger(numberOfBits), classIdForType(BigInteger.class)); - - BigInteger minToUse = min; - BigInteger maxToUse = max; - if (minToUse == null) - minToUse = maxToUse.subtract(TEN.pow(numberOfBits)); - else if (maxToUse == null) - maxToUse = minToUse.add(TEN.pow(numberOfBits)); - - return UtModelGenerator.getUtModelConstructor().construct(Ranges.choose(random, minToUse, maxToUse), classIdForType(BigInteger.class)); - } - - @Override protected Predicate inRange() { - return Comparables.inRange(min, max); + return utModelConstructor.construct( + random.nextBigInteger(numberOfBits), + BigInteger::class.id + ) + + val minToUse = min ?: max!!.subtract(BigInteger.TEN.pow(numberOfBits)) + val maxToUse = max ?: minToUse.add(BigInteger.TEN.pow(numberOfBits)) + return utModelConstructor.construct( + Ranges.choose(random, minToUse, maxToUse), + BigInteger::class.id + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt index 4ed1444ad4..c897af04c0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt @@ -1,60 +1,34 @@ - - -package org.utbot.quickcheck.generator.java.nio.charset; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.concrete.UtModelConstructor; -import org.utbot.framework.plugin.api.*; -import org.utbot.framework.plugin.api.util.IdUtilKt; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.reflect.Method; -import java.nio.charset.Charset; -import java.util.List; - -import static java.nio.charset.Charset.availableCharsets; -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.framework.plugin.api.util.IdUtilKt.getStringClassId; +package org.utbot.quickcheck.generator.java.nio.charset + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.stringClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.nio.charset.Charset /** - * Produces values of type {@link Charset}. + * Produces values of type [Charset]. */ -public class CharsetGenerator extends Generator { - public CharsetGenerator() { - super(Charset.class); - } - - @Override - public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); - - final String charsetName = random.choose(availableCharsets().keySet()); - final UtModel charsetNameModel = modelConstructor.construct(charsetName, getStringClassId()); - - final Method charsetForName; - try { - charsetForName = Charset.class.getMethod("forName", String.class); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - - final ClassId charsetClassId = classIdForType(Charset.class); - final ExecutableId charsetForNameId = IdUtilKt.getExecutableId(charsetForName); - - final int modelId = modelConstructor.computeUnusedIdAndUpdate(); - - return new UtAssembleModel( - modelId, - charsetClassId, - charsetForNameId.getName() + "#" + modelId, - new UtExecutableCallModel(null, charsetForNameId, List.of(charsetNameModel)), - null, - (a) -> List.of() - ); +class CharsetGenerator : Generator(Charset::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val charsetName = random.choose(Charset.availableCharsets().keys) + val charsetNameModel = utModelConstructor.construct(charsetName, stringClassId) + val charsetForNameId = Charset::forName.executableId + val modelId = utModelConstructor.computeUnusedIdAndUpdate() + return UtAssembleModel( + modelId, + Charset::class.id, + charsetForNameId.name + "#" + modelId, + UtExecutableCallModel(null, charsetForNameId, listOf(charsetNameModel)), + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt index 985ea9100c..a2ceb0c34a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt @@ -1,99 +1,73 @@ - - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.concrete.UtModelConstructor; -import org.utbot.framework.plugin.api.*; -import org.utbot.framework.plugin.api.util.IdUtilKt; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.reflect.Method; -import java.time.Clock; -import java.time.Instant; -import java.time.ZoneId; -import java.util.List; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.time + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.Clock +import java.time.Instant +import java.time.ZoneId /** - * Produces values of type {@link Clock}. + * Produces values of type [Clock]. */ -public class ClockGenerator extends Generator { - private static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); - - private Instant min = Instant.MIN; - private Instant max = Instant.MAX; - - public ClockGenerator() { - super(Clock.class); - } +class ClockGenerator : Generator(Clock::class.java) { + private var min = Instant.MIN + private var max = Instant.MAX /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution, down to the - * nanosecond.

* - *

Instances of this class are configured using {@link Instant} - * strings.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution, down to the + * nanosecond. + * + * + * Instances of this class are configured using [Instant] + * strings. * - *

If an endpoint of the range is not specified, the generator will use - * instants with values of either {@link Instant#MIN} or - * {@link Instant#MAX} as appropriate.

* - *

{@linkplain InRange#format()} is ignored. Instants are always - * parsed using {@link java.time.format.DateTimeFormatter#ISO_INSTANT}.

+ * If an endpoint of the range is not specified, the generator will use + * instants with values of either [Instant.MIN] or + * [Instant.MAX] as appropriate. + * + * + * [InRange.format] is ignored. Instants are always + * parsed using [java.time.format.DateTimeFormatter.ISO_INSTANT]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = Instant.parse(range.min()); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = Instant.parse(range.max()); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = Instant.parse(range.min) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = Instant.parse(range.max) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override - public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - final Instant instant = random.nextInstant(min, max); - final ZoneId zoneId = UTC_ZONE_ID; - - final Method clockFixed; - try { - clockFixed = Clock.class.getMethod("fixed", Instant.class, ZoneId.class); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - - final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); - final UtModel instantModel = modelConstructor.construct(instant, classIdForType(Instant.class)); - final UtModel zoneIdModel = modelConstructor.construct(zoneId, classIdForType(ZoneId.class)); - - final ClassId classId = classIdForType(Clock.class); - final ExecutableId constructorId = IdUtilKt.getExecutableId(clockFixed); - - final int modelId = modelConstructor.computeUnusedIdAndUpdate(); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val instant = random.nextInstant(min, max) + val zoneId = UTC_ZONE_ID + val instantModel = utModelConstructor.construct(instant, Instant::class.id) + val zoneIdModel = utModelConstructor.construct(zoneId, ZoneId::class.id) + val modelId = utModelConstructor.computeUnusedIdAndUpdate() + val constructorId = Clock::fixed.executableId + return UtAssembleModel( + id = modelId, + classId = Clock::class.id, + modelName = constructorId.name + "#" + modelId, + instantiationCall = UtExecutableCallModel(null, constructorId, listOf(instantModel, zoneIdModel)), + ) + } - return new UtAssembleModel( - modelId, - classId, - constructorId.getName() + "#" + modelId, - new UtExecutableCallModel(null, constructorId, List.of(instantModel, zoneIdModel)), - null, - (a) -> List.of() - ); + companion object { + private val UTC_ZONE_ID = ZoneId.of("UTC") } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt index 226be4efe2..3c41cb7bc4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt @@ -1,61 +1,49 @@ - - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.Duration; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.time + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.Duration /** - * Produces values of type {@link Duration}. + * Produces values of type [Duration]. */ -public class DurationGenerator extends Generator { - private Duration min = Duration.ofSeconds(Long.MIN_VALUE, 0); - private Duration max = Duration.ofSeconds(Long.MAX_VALUE, 999_999_999); - - public DurationGenerator() { - super(Duration.class); - } +class DurationGenerator : Generator(Duration::class.java) { + private var min = Duration.ofSeconds(Long.MIN_VALUE, 0) + private var max = Duration.ofSeconds(Long.MAX_VALUE, 999999999) /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution, down to the - * nanosecond.

* - *

If an endpoint of the range is not specified, the generator will use - * durations with second values of either {@link Long#MIN_VALUE} or - * {@link Long#MAX_VALUE} (with nanoseconds set to 999,999,999) as - * appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution, down to the + * nanosecond. + * + * + * If an endpoint of the range is not specified, the generator will use + * durations with second values of either [Long.MIN_VALUE] or + * [Long.MAX_VALUE] (with nanoseconds set to 999,999,999) as + * appropriate. * - *

{@linkplain InRange#format()} is ignored. Durations are always + * + * [InRange.format] is ignored. Durations are always * parsed using formats based on the ISO-8601 duration format - * {@code PnDTnHnMn.nS} with days considered to be exactly 24 hours. + * `PnDTnHnMn.nS` with days considered to be exactly 24 hours. * - * @see Duration#parse(CharSequence) + * @see Duration.parse * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = Duration.parse(range.min()); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = Duration.parse(range.max()); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = Duration.parse(range.min) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = Duration.parse(range.max) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate(SourceOfRandomness random, GenerationStatus status) { - return UtModelGenerator.getUtModelConstructor().construct(random.nextDuration(min, max), classIdForType(Duration.class)); + override fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return utModelConstructor.construct(random.nextDuration(min, max), Duration::class.id) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt index eab3ee052d..d73eb2d22e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt @@ -1,61 +1,49 @@ - - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.Instant; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.time + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.Instant /** - * Produces values of type {@link Instant}. + * Produces values of type [Instant]. */ -public class InstantGenerator extends Generator { - private Instant min = Instant.MIN; - private Instant max = Instant.MAX; - - public InstantGenerator() { - super(Instant.class); - } +class InstantGenerator : Generator(Instant::class.java) { + private var min = Instant.MIN + private var max = Instant.MAX /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution, down to the - * nanosecond.

* - *

If an endpoint of the range is not specified, the generator will use - * instants with values of either {@link Instant#MIN} or - * {@link Instant#MAX} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution, down to the + * nanosecond. + * + * + * If an endpoint of the range is not specified, the generator will use + * instants with values of either [Instant.MIN] or + * [Instant.MAX] as appropriate. * - *

{@linkplain InRange#format()} is ignored. Instants are always - * parsed using {@link java.time.format.DateTimeFormatter#ISO_INSTANT}.

+ * + * [InRange.format] is ignored. Instants are always + * parsed using [java.time.format.DateTimeFormatter.ISO_INSTANT]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = Instant.parse(range.min()); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = Instant.parse(range.max()); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = Instant.parse(range.min) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = Instant.parse(range.max) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.nextInstant(min, max), classIdForType(Instant.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(random.nextInstant(min, max), Instant::class.id) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt index 3fea491b2f..828aa6faed 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt @@ -1,66 +1,57 @@ - - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.LocalDate; -import java.time.format.DateTimeFormatter; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.time + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.LocalDate +import java.time.format.DateTimeFormatter /** - * Produces values of type {@link LocalDate}. + * Produces values of type [LocalDate]. */ -public class LocalDateGenerator extends Generator { - private LocalDate min = LocalDate.MIN; - private LocalDate max = LocalDate.MAX; - - public LocalDateGenerator() { - super(LocalDate.class); - } +class LocalDateGenerator : Generator(LocalDate::class.java) { + private var min = LocalDate.MIN + private var max = LocalDate.MAX /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution.

* - *

If an endpoint of the range is not specified, the generator will use - * dates with values of either {@link LocalDate#MIN} or - * {@link LocalDate#MAX} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution. * - *

{@link InRange#format()} describes - * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to - * interpret the range's endpoints}.

+ * + * If an endpoint of the range is not specified, the generator will use + * dates with values of either [LocalDate.MIN] or + * [LocalDate.MAX] as appropriate. + * + * + * [InRange.format] describes + * [how the generator is to][DateTimeFormatter.ofPattern]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - DateTimeFormatter formatter = - DateTimeFormatter.ofPattern(range.format()); - - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = LocalDate.parse(range.min(), formatter); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = LocalDate.parse(range.max(), formatter); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + val formatter = DateTimeFormatter.ofPattern(range.format) + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = + LocalDate.parse(range.min, formatter) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = + LocalDate.parse(range.max, formatter) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(LocalDate.ofEpochDay( - random.nextLong(min.toEpochDay(), max.toEpochDay())), classIdForType(LocalDate.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + LocalDate.ofEpochDay( + random.nextLong(min.toEpochDay(), max.toEpochDay()) + ), + LocalDate::class.id + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt index ae0272a792..af2c171080 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt @@ -1,75 +1,72 @@ +package org.utbot.quickcheck.generator.java.time - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.format.DateTimeFormatter /** - * Produces values of type {@link LocalDateTime}. + * Produces values of type [LocalDateTime]. */ -public class LocalDateTimeGenerator extends Generator { - private static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); - - private LocalDateTime min = LocalDateTime.MIN; - private LocalDateTime max = LocalDateTime.MAX; - - public LocalDateTimeGenerator() { - super(LocalDateTime.class); - } +class LocalDateTimeGenerator : Generator( + LocalDateTime::class.java +) { + private var min = LocalDateTime.MIN + private var max = LocalDateTime.MAX /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution, down to the - * nanosecond.

* - *

If an endpoint of the range is not specified, the generator will use - * dates with values of either {@link LocalDateTime#MIN} or - * {@link LocalDateTime#MAX} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution, down to the + * nanosecond. * - *

{@link InRange#format()} describes - * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to - * interpret the range's endpoints}.

+ * + * If an endpoint of the range is not specified, the generator will use + * dates with values of either [LocalDateTime.MIN] or + * [LocalDateTime.MAX] as appropriate. + * + * + * [InRange.format] describes + * [how the generator is to][DateTimeFormatter.ofPattern]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - DateTimeFormatter formatter = - DateTimeFormatter.ofPattern(range.format()); - - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = LocalDateTime.parse(range.min(), formatter); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = LocalDateTime.parse(range.max(), formatter); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + val formatter = DateTimeFormatter.ofPattern(range.format) + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = + LocalDateTime.parse(range.min, formatter) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = + LocalDateTime.parse(range.max, formatter) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { /* Project the LocalDateTime to an Instant for easy long-based generation. Any zone id will do as long as we use the same one throughout. */ - return UtModelGenerator.getUtModelConstructor().construct(LocalDateTime.ofInstant( - random.nextInstant( - min.atZone(UTC_ZONE_ID).toInstant(), - max.atZone(UTC_ZONE_ID).toInstant()), - UTC_ZONE_ID), classIdForType(LocalDateTime.class)); + return utModelConstructor.construct( + LocalDateTime.ofInstant( + random.nextInstant( + min.atZone(UTC_ZONE_ID).toInstant(), + max.atZone(UTC_ZONE_ID).toInstant() + ), + UTC_ZONE_ID + ), + LocalDateTime::class.id + ) + } + + companion object { + private val UTC_ZONE_ID = ZoneId.of("UTC") } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt index 7fd58018d4..58f2c87d02 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt @@ -1,67 +1,58 @@ - - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.LocalTime; -import java.time.format.DateTimeFormatter; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.time + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.LocalTime +import java.time.format.DateTimeFormatter /** - * Produces values of type {@link LocalTime}. + * Produces values of type [LocalTime]. */ -public class LocalTimeGenerator extends Generator { - private LocalTime min = LocalTime.MIN; - private LocalTime max = LocalTime.MAX; - - public LocalTimeGenerator() { - super(LocalTime.class); - } +class LocalTimeGenerator : Generator(LocalTime::class.java) { + private var min = LocalTime.MIN + private var max = LocalTime.MAX /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution, down to the - * nanosecond.

* - *

If an endpoint of the range is not specified, the generator will use - * times with values of either {@link LocalTime#MIN} or - * {@link LocalTime#MAX} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution, down to the + * nanosecond. * - *

{@link InRange#format()} describes - * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to - * interpret the range's endpoints}.

+ * + * If an endpoint of the range is not specified, the generator will use + * times with values of either [LocalTime.MIN] or + * [LocalTime.MAX] as appropriate. + * + * + * [InRange.format] describes + * [how the generator is to][DateTimeFormatter.ofPattern]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - DateTimeFormatter formatter = - DateTimeFormatter.ofPattern(range.format()); - - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = LocalTime.parse(range.min(), formatter); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = LocalTime.parse(range.max(), formatter); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + val formatter = DateTimeFormatter.ofPattern(range.format) + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = + LocalTime.parse(range.min, formatter) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = + LocalTime.parse(range.max, formatter) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(LocalTime.ofNanoOfDay( - random.nextLong(min.toNanoOfDay(), max.toNanoOfDay())), classIdForType(LocalTime.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + LocalTime.ofNanoOfDay( + random.nextLong(min.toNanoOfDay(), max.toNanoOfDay()) + ), + LocalTime::class.id + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt index 4e11b564eb..fc670ae5dd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt @@ -1,73 +1,62 @@ - - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.LocalDate; -import java.time.MonthDay; -import java.time.format.DateTimeFormatter; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.time + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.LocalDate +import java.time.MonthDay +import java.time.format.DateTimeFormatter /** - * Produces values of type {@link MonthDay}. + * Produces values of type [MonthDay]. */ -public class MonthDayGenerator extends Generator { - private MonthDay min = MonthDay.of(1, 1); - private MonthDay max = MonthDay.of(12, 31); - - public MonthDayGenerator() { - super(MonthDay.class); - } +class MonthDayGenerator : Generator(MonthDay::class.java) { + private var min = MonthDay.of(1, 1) + private var max = MonthDay.of(12, 31) /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution.

* - *

If an endpoint of the range is not specified, the generator will use - * dates with values of either {@code MonthDay(1, 1)} or - * {@code MonthDay(12, 31)} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution. * - *

{@link InRange#format()} describes - * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to - * interpret the range's endpoints}.

+ * + * If an endpoint of the range is not specified, the generator will use + * dates with values of either `MonthDay(1, 1)` or + * `MonthDay(12, 31)` as appropriate. + * + * + * [InRange.format] describes + * [how the generator is to][DateTimeFormatter.ofPattern]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - DateTimeFormatter formatter = - DateTimeFormatter.ofPattern(range.format()); - - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = MonthDay.parse(range.min(), formatter); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = MonthDay.parse(range.max(), formatter); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + val formatter = DateTimeFormatter.ofPattern(range.format) + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = + MonthDay.parse(range.min, formatter) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = + MonthDay.parse(range.max, formatter) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { /* Project the MonthDay to a LocalDate for easy long-based generation. Any leap year will do here. */ - long minEpochDay = min.atYear(2000).toEpochDay(); - long maxEpochDay = max.atYear(2000).toEpochDay(); - LocalDate date = - LocalDate.ofEpochDay(random.nextLong(minEpochDay, maxEpochDay)); - - return UtModelGenerator.getUtModelConstructor().construct(MonthDay.of(date.getMonthValue(), date.getDayOfMonth()), classIdForType(MonthDay.class)); + val minEpochDay = min.atYear(2000).toEpochDay() + val maxEpochDay = max.atYear(2000).toEpochDay() + val date = LocalDate.ofEpochDay(random.nextLong(minEpochDay, maxEpochDay)) + return utModelConstructor.construct( + MonthDay.of(date.monthValue, date.dayOfMonth), + MonthDay::class.id + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt index afd0ee789f..95c56cc99d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt @@ -1,72 +1,68 @@ +package org.utbot.quickcheck.generator.java.time - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.OffsetDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.OffsetDateTime +import java.time.ZoneId +import java.time.format.DateTimeFormatter /** - * Produces values of type {@link OffsetDateTime}. + * Produces values of type [OffsetDateTime]. */ -public class OffsetDateTimeGenerator extends Generator { - private static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); - - private OffsetDateTime min = OffsetDateTime.MIN; - private OffsetDateTime max = OffsetDateTime.MAX; - - public OffsetDateTimeGenerator() { - super(OffsetDateTime.class); - } +class OffsetDateTimeGenerator : Generator( + OffsetDateTime::class.java +) { + private var min = OffsetDateTime.MIN + private var max = OffsetDateTime.MAX /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution, down to the - * nanosecond.

* - *

If an endpoint of the range is not specified, the generator will use - * dates with values of either {@link OffsetDateTime#MIN} or - * {@link OffsetDateTime#MAX} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution, down to the + * nanosecond. * - *

{@link InRange#format()} describes - * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to - * interpret the range's endpoints}.

+ * + * If an endpoint of the range is not specified, the generator will use + * dates with values of either [OffsetDateTime.MIN] or + * [OffsetDateTime.MAX] as appropriate. + * + * + * [InRange.format] describes + * [how the generator is to][DateTimeFormatter.ofPattern]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - DateTimeFormatter formatter = - DateTimeFormatter.ofPattern(range.format()); - - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = OffsetDateTime.parse(range.min(), formatter); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = OffsetDateTime.parse(range.max(), formatter); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + val formatter = DateTimeFormatter.ofPattern(range.format) + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = + OffsetDateTime.parse(range.min, formatter) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = + OffsetDateTime.parse(range.max, formatter) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { // Project the OffsetDateTime to an Instant for easy long-based generation. - return UtModelGenerator.getUtModelConstructor().construct(OffsetDateTime.ofInstant( - random.nextInstant(min.toInstant(), max.toInstant()), - UTC_ZONE_ID), classIdForType(OffsetDateTime.class)); + return utModelConstructor.construct( + OffsetDateTime.ofInstant( + random.nextInstant(min.toInstant(), max.toInstant()), + UTC_ZONE_ID + ), + OffsetDateTime::class.id + ) + } + + companion object { + private val UTC_ZONE_ID = ZoneId.of("UTC") } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt index eefc83d0cd..6ead6bd49a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt @@ -1,78 +1,68 @@ +package org.utbot.quickcheck.generator.java.time - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.LocalTime; -import java.time.OffsetTime; -import java.time.ZoneOffset; -import java.time.format.DateTimeFormatter; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.LocalTime +import java.time.OffsetTime +import java.time.ZoneOffset +import java.time.format.DateTimeFormatter /** - * Produces values of type {@link OffsetTime}. + * Produces values of type [OffsetTime]. */ -public class OffsetTimeGenerator extends Generator { - private OffsetTime min = OffsetTime.MIN; - private OffsetTime max = OffsetTime.MAX; - - public OffsetTimeGenerator() { - super(OffsetTime.class); - } +class OffsetTimeGenerator : Generator(OffsetTime::class.java) { + private var min = OffsetTime.MIN + private var max = OffsetTime.MAX /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution, down to the - * nanosecond.

* - *

If an endpoint of the range is not specified, the generator will use - * times with values of either {@link OffsetTime#MIN} or - * {@link OffsetTime#MAX} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution, down to the + * nanosecond. + * * - *

{@link InRange#format()} describes - * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to - * interpret the range's endpoints}.

+ * If an endpoint of the range is not specified, the generator will use + * times with values of either [OffsetTime.MIN] or + * [OffsetTime.MAX] as appropriate. + * + * + * [InRange.format] describes + * [how the generator is to][DateTimeFormatter.ofPattern]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - DateTimeFormatter formatter = - DateTimeFormatter.ofPattern(range.format()); - - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = OffsetTime.parse(range.min(), formatter); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = OffsetTime.parse(range.max(), formatter); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + val formatter = DateTimeFormatter.ofPattern(range.format) + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = + OffsetTime.parse(range.min, formatter) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = + OffsetTime.parse(range.max, formatter) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - LocalTime time = - LocalTime.ofNanoOfDay( - random.nextLong( - min.withOffsetSameInstant(ZoneOffset.UTC) - .toLocalTime() - .toNanoOfDay(), - max.withOffsetSameInstant(ZoneOffset.UTC) - .toLocalTime() - .toNanoOfDay())); - - return UtModelGenerator.getUtModelConstructor().construct(OffsetTime.of(time, ZoneOffset.UTC), classIdForType(OffsetTime.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val time = LocalTime.ofNanoOfDay( + random.nextLong( + min.withOffsetSameInstant(ZoneOffset.UTC) + .toLocalTime() + .toNanoOfDay(), + max.withOffsetSameInstant(ZoneOffset.UTC) + .toLocalTime() + .toNanoOfDay() + ) + ) + return utModelConstructor.construct( + OffsetTime.of(time, ZoneOffset.UTC), + OffsetTime::class.id + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt index 388f7b157b..4b08170460 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt @@ -1,89 +1,81 @@ +package org.utbot.quickcheck.generator.java.time - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.internal.Ranges; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.math.BigInteger; -import java.time.Period; -import java.time.Year; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Ranges +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.math.BigInteger +import java.time.Period +import java.time.Year /** - * Produces values of type {@link Period}. + * Produces values of type [Period]. */ -public class PeriodGenerator extends Generator { - private static final BigInteger TWELVE = BigInteger.valueOf(12); - private static final BigInteger THIRTY_ONE = BigInteger.valueOf(31); - - private Period min = Period.of(Year.MIN_VALUE, -12, -31); - private Period max = Period.of(Year.MAX_VALUE, 12, 31); - - public PeriodGenerator() { - super(Period.class); - } +class PeriodGenerator : Generator(Period::class.java) { + private var min = Period.of(Year.MIN_VALUE, -12, -31) + private var max = Period.of(Year.MAX_VALUE, 12, 31) /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution.

* - *

If an endpoint of the range is not specified, the generator will use - * Periods with values of either {@code Period(Year#MIN_VALUE, -12, -31)} - * or {@code Period(Year#MAX_VALUE, 12, 31)} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution. + * * - *

{@linkplain InRange#format()} is ignored. Periods are always parsed - * using formats based on the ISO-8601 period formats {@code PnYnMnD} and - * {@code PnW}.

+ * If an endpoint of the range is not specified, the generator will use + * Periods with values of either `Period(Year#MIN_VALUE, -12, -31)` + * or `Period(Year#MAX_VALUE, 12, 31)` as appropriate. * - * @see Period#parse(CharSequence) + * + * [InRange.format] is ignored. Periods are always parsed + * using formats based on the ISO-8601 period formats `PnYnMnD` and + * `PnW`. + * + * @see Period.parse * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = Period.parse(range.min()); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = Period.parse(range.max()); - - if (toBigInteger(min).compareTo(toBigInteger(max)) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = Period.parse(range.min) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = Period.parse(range.max) + require(toBigInteger(min) <= toBigInteger(max)) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(fromBigInteger( - Ranges.choose(random, toBigInteger(min), toBigInteger(max))), classIdForType(Period.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + fromBigInteger( + Ranges.choose(random, toBigInteger(min), toBigInteger(max)) + ), + Period::class.id + ) } - private BigInteger toBigInteger(Period period) { - return BigInteger.valueOf(period.getYears()) + private fun toBigInteger(period: Period): BigInteger { + return BigInteger.valueOf(period.years.toLong()) .multiply(TWELVE) - .add(BigInteger.valueOf(period.getMonths())) + .add(BigInteger.valueOf(period.months.toLong())) .multiply(THIRTY_ONE) - .add(BigInteger.valueOf(period.getDays())); + .add(BigInteger.valueOf(period.days.toLong())) } - private Period fromBigInteger(BigInteger period) { - BigInteger[] monthsAndDays = - period.divideAndRemainder(THIRTY_ONE); - BigInteger[] yearsAndMonths = - monthsAndDays[0].divideAndRemainder(TWELVE); - + private fun fromBigInteger(period: BigInteger): Period { + val monthsAndDays = period.divideAndRemainder(THIRTY_ONE) + val yearsAndMonths = monthsAndDays[0].divideAndRemainder(TWELVE) return Period.of( yearsAndMonths[0].intValueExact(), yearsAndMonths[1].intValueExact(), - monthsAndDays[1].intValueExact()); + monthsAndDays[1].intValueExact() + ) + } + + companion object { + private val TWELVE = BigInteger.valueOf(12) + private val THIRTY_ONE = BigInteger.valueOf(31) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt index 194ab340e8..766512c4c5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt @@ -1,65 +1,53 @@ - - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.Year; -import java.time.format.DateTimeFormatter; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.time + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.Year +import java.time.format.DateTimeFormatter /** - * Produces values of type {@link Year}. + * Produces values of type [Year]. */ -public class YearGenerator extends Generator { - private Year min = Year.of(Year.MIN_VALUE); - private Year max = Year.of(Year.MAX_VALUE); - - public YearGenerator() { - super(Year.class); - } +class YearGenerator : Generator(Year::class.java) { + private var min = Year.of(Year.MIN_VALUE) + private var max = Year.of(Year.MAX_VALUE) /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution.

* - *

If an endpoint of the range is not specified, the generator will use - * Years with values of either {@code Year#MIN_VALUE} or - * {@code Year#MAX_VALUE} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution. * - *

{@link InRange#format()} describes - * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to - * interpret the range's endpoints}.

+ * + * If an endpoint of the range is not specified, the generator will use + * Years with values of either `Year#MIN_VALUE` or + * `Year#MAX_VALUE` as appropriate. + * + * + * [InRange.format] describes + * [how the generator is to][DateTimeFormatter.ofPattern]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - DateTimeFormatter formatter = - DateTimeFormatter.ofPattern(range.format()); - - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = Year.parse(range.min(), formatter); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = Year.parse(range.max(), formatter); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + val formatter = DateTimeFormatter.ofPattern(range.format) + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = Year.parse(range.min, formatter) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = Year.parse(range.max, formatter) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(Year.of(random.nextInt(min.getValue(), max.getValue())), classIdForType(Year.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + Year.of(random.nextInt(min.value, max.value)), + Year::class.id + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt index e211782600..8cb0427246 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt @@ -1,73 +1,64 @@ +package org.utbot.quickcheck.generator.java.time - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.Year; -import java.time.YearMonth; -import java.time.format.DateTimeFormatter; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.Year +import java.time.YearMonth +import java.time.format.DateTimeFormatter +import kotlin.math.abs /** - * Produces values of type {@link YearMonth}. + * Produces values of type [YearMonth]. */ -public class YearMonthGenerator extends Generator { - private YearMonth min = YearMonth.of(Year.MIN_VALUE, 1); - private YearMonth max = YearMonth.of(Year.MAX_VALUE, 12); - - public YearMonthGenerator() { - super(YearMonth.class); - } +class YearMonthGenerator : Generator(YearMonth::class.java) { + private var min = YearMonth.of(Year.MIN_VALUE, 1) + private var max = YearMonth.of(Year.MAX_VALUE, 12) /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution.

* - *

If an endpoint of the range is not specified, the generator will use - * dates with values of either {@code YearMonth(Year#MIN_VALUE, 1)} or - * {@code YearMonth(Year#MAX_VALUE, 12)} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution. + * * - *

{@link InRange#format()} describes - * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to - * interpret the range's endpoints}.

+ * If an endpoint of the range is not specified, the generator will use + * dates with values of either `YearMonth(Year#MIN_VALUE, 1)` or + * `YearMonth(Year#MAX_VALUE, 12)` as appropriate. + * + * + * [InRange.format] describes + * [how the generator is to][DateTimeFormatter.ofPattern]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - DateTimeFormatter formatter = - DateTimeFormatter.ofPattern(range.format()); - - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = YearMonth.parse(range.min(), formatter); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = YearMonth.parse(range.max(), formatter); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + val formatter = DateTimeFormatter.ofPattern(range.format) + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = + YearMonth.parse(range.min, formatter) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = + YearMonth.parse(range.max, formatter) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - long generated = - random.nextLong( - min.getYear() * 12L + min.getMonthValue() - 1, - max.getYear() * 12L + max.getMonthValue() - 1); - - return UtModelGenerator.getUtModelConstructor().construct(YearMonth.of( - (int) (generated / 12), - (int) Math.abs(generated % 12) + 1), classIdForType(YearMonth.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val generated = random.nextLong( + min.year * 12L + min.monthValue - 1, + max.year * 12L + max.monthValue - 1 + ) + return utModelConstructor.construct( + YearMonth.of( + (generated / 12).toInt(), + abs(generated % 12).toInt() + 1 + ), + YearMonth::class.id + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt index ca7b66d6ac..bc0a86dad7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt @@ -1,30 +1,24 @@ +package org.utbot.quickcheck.generator.java.time - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.ZoneId; - -import static java.time.ZoneId.getAvailableZoneIds; -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.ZoneId /** - * Produces values of type {@link ZoneId}. + * Produces values of type [ZoneId]. */ -public class ZoneIdGenerator extends Generator { - public ZoneIdGenerator() { - super(ZoneId.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(ZoneId.of(random.choose(getAvailableZoneIds())), classIdForType(ZoneId.class)); +class ZoneIdGenerator : Generator(ZoneId::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + ZoneId.of(random.choose(ZoneId.getAvailableZoneIds())), + ZoneId::class.id + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt index 05ed4ab2f5..f5b93fe6bd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt @@ -1,70 +1,63 @@ - - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.ZoneOffset; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.time + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.ZoneOffset /** - * Produces values of type {@link ZoneOffset}. + * Produces values of type [ZoneOffset]. */ -public class ZoneOffsetGenerator extends Generator { +class ZoneOffsetGenerator : Generator(ZoneOffset::class.java) { /* The way ZoneOffsets work, ZoneOffset.MAX (-18:00) is actually the lower end of the seconds range, whereas ZoneOffset.MIN (+18:00) is the upper end. */ - private ZoneOffset min = ZoneOffset.MAX; - private ZoneOffset max = ZoneOffset.MIN; - - public ZoneOffsetGenerator() { - super(ZoneOffset.class); - } + private var min = ZoneOffset.MAX + private var max = ZoneOffset.MIN /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution.

* - *

If an endpoint of the range is not specified, the generator will use - * ZoneOffsets with values of either {@code ZoneOffset#MIN} or - * {@code ZoneOffset#MAX} as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution. * - *

{@linkplain InRange#format()} is ignored. ZoneOffsets are always - * parsed using their zone id.

* - * @see ZoneOffset#of(String) + * If an endpoint of the range is not specified, the generator will use + * ZoneOffsets with values of either `ZoneOffset#MIN` or + * `ZoneOffset#MAX` as appropriate. + * + * + * [InRange.format] is ignored. ZoneOffsets are always + * parsed using their zone id. + * + * @see ZoneOffset.of * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = ZoneOffset.of(range.min()); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = ZoneOffset.of(range.max()); - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); - } + fun configure(range: InRange) { + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = ZoneOffset.of(range.min) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = ZoneOffset.of(range.max) + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - int minSeconds = min.getTotalSeconds(); - int maxSeconds = max.getTotalSeconds(); - - return UtModelGenerator.getUtModelConstructor().construct(ZoneOffset.ofTotalSeconds( - (minSeconds <= maxSeconds) - ? random.nextInt(minSeconds, maxSeconds) - : random.nextInt(maxSeconds, minSeconds)), classIdForType(ZoneOffset.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val minSeconds = min.totalSeconds + val maxSeconds = max.totalSeconds + + return utModelConstructor.construct( + ZoneOffset.ofTotalSeconds( + if (minSeconds <= maxSeconds) random.nextInt(minSeconds, maxSeconds) else random.nextInt( + maxSeconds, + minSeconds + ) + ), + ZoneOffset::class.id + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt index 97b5e78b71..d4ea76d080 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt @@ -1,83 +1,74 @@ +package org.utbot.quickcheck.generator.java.time - -package org.utbot.quickcheck.generator.java.time; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.time.Year; -import java.time.ZoneId; -import java.time.ZonedDateTime; -import java.time.format.DateTimeFormatter; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.time.Year +import java.time.ZoneId +import java.time.ZonedDateTime +import java.time.format.DateTimeFormatter /** - * Produces values of type {@link ZonedDateTime}. + * Produces values of type [ZonedDateTime]. */ -public class ZonedDateTimeGenerator extends Generator { - private static final ZoneId UTC_ZONE_ID = ZoneId.of("UTC"); - - private ZonedDateTime min = - ZonedDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, UTC_ZONE_ID); - private ZonedDateTime max = - ZonedDateTime.of( - Year.MAX_VALUE, 12, 31, 23, 59, 59, 999_999_999, UTC_ZONE_ID); - - public ZonedDateTimeGenerator() { - super(ZonedDateTime.class); - } +class ZonedDateTimeGenerator : Generator(ZonedDateTime::class.java) { + private var min = ZonedDateTime.of(Year.MIN_VALUE, 1, 1, 0, 0, 0, 0, UTC_ZONE_ID) + private var max = ZonedDateTime.of( + Year.MAX_VALUE, 12, 31, 23, 59, 59, 999999999, UTC_ZONE_ID + ) /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution, down to the - * nanosecond.

* - *

If an endpoint of the range is not specified, the generator will use - * dates with values of either {@link java.time.Instant#MIN} or - * {@link java.time.Instant#MAX} and UTC zone as appropriate.

+ * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution, down to the + * nanosecond. + * * - *

{@link InRange#format()} describes - * {@linkplain DateTimeFormatter#ofPattern(String) how the generator is to - * interpret the range's endpoints}.

+ * If an endpoint of the range is not specified, the generator will use + * dates with values of either [java.time.Instant.MIN] or + * [java.time.Instant.MAX] and UTC zone as appropriate. + * + * + * [InRange.format] describes + * [how the generator is to][DateTimeFormatter.ofPattern]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - DateTimeFormatter formatter = - DateTimeFormatter.ofPattern(range.format()); - - if (!defaultValueOf(InRange.class, "min").equals(range.min())) { - min = - ZonedDateTime.parse(range.min(), formatter) - .withZoneSameInstant(UTC_ZONE_ID); + fun configure(range: InRange) { + val formatter = DateTimeFormatter.ofPattern(range.format) + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) { + min = ZonedDateTime.parse(range.min, formatter) + .withZoneSameInstant(UTC_ZONE_ID) } - if (!defaultValueOf(InRange.class, "max").equals(range.max())) { - max = - ZonedDateTime.parse(range.max(), formatter) - .withZoneSameInstant(UTC_ZONE_ID); - } - - if (min.compareTo(max) > 0) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) { + max = ZonedDateTime.parse(range.max, formatter) + .withZoneSameInstant(UTC_ZONE_ID) } + require(min <= max) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { // Project the ZonedDateTime to an Instant for easy long-based // generation. - return UtModelGenerator.getUtModelConstructor().construct(ZonedDateTime.ofInstant( - random.nextInstant(min.toInstant(), max.toInstant()), - UTC_ZONE_ID), classIdForType(ZonedDateTime.class)); + return utModelConstructor.construct( + ZonedDateTime.ofInstant( + random.nextInstant(min.toInstant(), max.toInstant()), + UTC_ZONE_ID + ), + ZonedDateTime::class.id + ) + } + + companion object { + private val UTC_ZONE_ID = ZoneId.of("UTC") } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt index cd84d09d93..7d006faa1f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt @@ -1,16 +1,6 @@ - - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.ListGenerator; - -import java.util.ArrayList; +package org.utbot.quickcheck.generator.java.util /** - * Produces values of type {@link ArrayList}. + * Produces values of type [ArrayList]. */ -public class ArrayListGenerator extends ListGenerator { - public ArrayListGenerator() { - super(ArrayList.class); - } -} +class ArrayListGenerator : ListGenerator(ArrayList::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt index b9b22d25d8..f83a3589a2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt @@ -1,37 +1,26 @@ +package org.utbot.quickcheck.generator.java.util - -package org.utbot.quickcheck.generator.java.util; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.BitSet; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.BitSet /** - * Produces values of type {@link BitSet}. + * Produces values of type [BitSet]. */ -public class BitSetGenerator extends Generator { - public BitSetGenerator() { - super(BitSet.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - int size = status.size(); - - BitSet bits = new BitSet(size); - for (int i = 0; i < size; ++i) { - bits.set(i, random.nextBoolean()); +class BitSetGenerator : Generator(BitSet::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val size = status.size() + val bits = BitSet(size) + for (i in 0 until size) { + bits[i] = random.nextBoolean() } - - return UtModelGenerator.getUtModelConstructor().construct(bits, classIdForType(BitSet.class)); + return utModelConstructor.construct(bits, BitSet::class.id) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt index e6875e9d78..dfedb2f3c8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt @@ -1,129 +1,98 @@ - - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.concrete.UtModelConstructor; -import org.utbot.framework.plugin.api.*; - -import org.utbot.framework.plugin.api.util.IdUtilKt; -import org.utbot.quickcheck.generator.*; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Ranges.Type.INTEGRAL; -import static org.utbot.quickcheck.internal.Ranges.checkRange; +package org.utbot.quickcheck.generator.java.util + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.ConstructorId +import org.utbot.framework.plugin.api.MethodId +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.booleanClassId +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.objectClassId +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.Distinct +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Size +import org.utbot.quickcheck.internal.Ranges +import org.utbot.quickcheck.random.SourceOfRandomness /** - *

Base class for generators of {@link Collection}s.

* - *

The generated collection has a number of elements limited by - * {@link GenerationStatus#size()}, or else by the attributes of a {@link Size} + * Base class for generators of [Collection]s. + * + * + * The generated collection has a number of elements limited by + * [GenerationStatus.size], or else by the attributes of a [Size] * marking. The individual elements will have a type corresponding to the - * collection's type argument.

+ * collection's type argument. * * @param the type of collection generated - */ -public abstract class CollectionGenerator - extends ComponentizedGenerator { - - private Size sizeRange; - private boolean distinct; - - protected CollectionGenerator(Class type) { - super(type); - } + */ +abstract class CollectionGenerator(type: Class<*>) : ComponentizedGenerator(type) { + private var sizeRange: Size? = null + private var distinct = false /** - *

Tells this generator to add elements to the generated collection + * + * Tells this generator to add elements to the generated collection * a number of times within a specified minimum and/or maximum, inclusive, - * chosen with uniform distribution.

+ * chosen with uniform distribution. + * * - *

Note that some kinds of collections disallow duplicates, so the + * Note that some kinds of collections disallow duplicates, so the * number of elements added may not be equal to the collection's - * {@link Collection#size()}.

+ * [Collection.size]. * * @param size annotation that gives the size constraints */ - public void configure(Size size) { - this.sizeRange = size; - checkRange(INTEGRAL, size.min(), size.max()); + open fun configure(size: Size) { + sizeRange = size + Ranges.checkRange(Ranges.Type.INTEGRAL, size.min, size.max) } /** * Tells this generator to add elements which are distinct from each other. * * @param distinct Generated elements will be distinct if this param is - * not null + * not null */ - public void configure(Distinct distinct) { - setDistinct(distinct != null); + fun configure(distinct: Distinct?) { + setDistinct(distinct != null) } - protected final void setDistinct(boolean distinct) { - this.distinct = distinct; + protected fun setDistinct(distinct: Boolean) { + this.distinct = distinct } - @Override - public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - -// UtCompositeModel res = new UtCompositeModel( -// -// ) - UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); - Class collectionType = types().get(0); - ClassId collectionClassId = classIdForType(collectionType); - ExecutableId collectionConstructorId = new ConstructorId(collectionClassId, new ArrayList<>()); - int genId = modelConstructor.computeUnusedIdAndUpdate(); - - - UtAssembleModel collectionAssembleModel = new UtAssembleModel( - genId, - collectionClassId, - collectionConstructorId.getName() + "#" + genId, - new UtExecutableCallModel(null, collectionConstructorId, List.of()), - null, - (a) -> { - ArrayList modificationChain = new ArrayList<>(); - int size = size(random, status); - - Generator generator = componentGenerators().get(0); - Method m; - try { - m = Collection.class.getMethod("add", Object.class); - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - MethodId methodId = IdUtilKt.getExecutableId(m); - - //java.util.Collections::class.java.methodCall - for (int i = 0; i < size; ++i) { - UtModel item = generator.generate(random, status); - modificationChain.add(new UtExecutableCallModel(a, methodId, List.of(item))); - } - return modificationChain; - } - ); - - return collectionAssembleModel; + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val collectionClassId = types().single().id + val collectionConstructorId = ConstructorId(collectionClassId, emptyList()) + + val genId = utModelConstructor.computeUnusedIdAndUpdate() + return UtAssembleModel( + genId, + collectionClassId, + collectionConstructorId.name + "#" + genId, + UtExecutableCallModel(null, collectionConstructorId, emptyList()), + ) { + val addMethodId = MethodId(classId, "add", booleanClassId, listOf(objectClassId)) + val size = size(random, status) + val generator = componentGenerators().first() + (0..size).map { + val item = generator.generate(random, status) + UtExecutableCallModel(this, addMethodId, listOf(item)) + } + } } - @Override - public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } - private int size(SourceOfRandomness random, GenerationStatus status) { - return sizeRange != null - ? random.nextInt(sizeRange.min(), sizeRange.max()) - : status.size(); + private fun size(random: SourceOfRandomness, status: GenerationStatus): Int { + return if (sizeRange != null) random.nextInt(sizeRange!!.min, sizeRange!!.max) else status.size() } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt index 3f59edcd75..6b4aaa54a4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt @@ -1,73 +1,60 @@ - - - - -package org.utbot.quickcheck.generator.java.util; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Date; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; +package org.utbot.quickcheck.generator.java.util + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.text.ParseException +import java.text.SimpleDateFormat +import java.util.Date /** - * Produces values of type {@link Date}. + * Produces values of type [Date]. */ -public class DateGenerator extends Generator { - private Date min = new Date(Integer.MIN_VALUE); - private Date max = new Date(Long.MAX_VALUE); - - public DateGenerator() { - super(Date.class); - } +class DateGenerator : Generator(Date::class.java) { + private var min: Date = Date(Long.MIN_VALUE) + private var max = Date(Long.MAX_VALUE) /** - *

Tells this generator to produce values within a specified - * {@linkplain InRange#min() minimum} and/or {@linkplain InRange#max() - * maximum}, inclusive, with uniform distribution, down to the - * millisecond.

* - *

If an endpoint of the range is not specified, the generator will use + * Tells this generator to produce values within a specified + * [minimum][InRange.min] and/or [ maximum][InRange.max], inclusive, with uniform distribution, down to the + * millisecond. + * + * + * If an endpoint of the range is not specified, the generator will use * dates with milliseconds-since-the-epoch values of either - * {@link Integer#MIN_VALUE} or {@link Long#MAX_VALUE} as appropriate.

+ * [Integer.MIN_VALUE] or [Long.MAX_VALUE] as appropriate. + * * - *

{@link InRange#format()} describes - * {@linkplain SimpleDateFormat#parse(String) how the generator is to - * interpret the range's endpoints}.

+ * [InRange.format] describes + * [how the generator is to][SimpleDateFormat.parse]. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - SimpleDateFormat formatter = new SimpleDateFormat(range.format()); - formatter.setLenient(false); - + fun configure(range: InRange) { + val formatter = SimpleDateFormat(range.format) + formatter.isLenient = false try { - if (!defaultValueOf(InRange.class, "min").equals(range.min())) - min = formatter.parse(range.min()); - if (!defaultValueOf(InRange.class, "max").equals(range.max())) - max = formatter.parse(range.max()); - } catch (ParseException e) { - throw new IllegalArgumentException(e); - } - - if (min.getTime() > max.getTime()) { - throw new IllegalArgumentException( - String.format("bad range, %s > %s", min, max)); + if (Reflection.defaultValueOf(InRange::class.java, "min") != range.min) min = formatter.parse(range.min) + if (Reflection.defaultValueOf(InRange::class.java, "max") != range.max) max = formatter.parse(range.max) + } catch (e: ParseException) { + throw IllegalArgumentException(e) } + require(min.time <= max.time) { String.format("bad range, %s > %s", min, max) } } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(new Date(random.nextLong(min.getTime(), max.getTime())), classIdForType(Date.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + Date(random.nextLong(min.time, max.time)), + classIdForType(Date::class.java) + ) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt index 6b4bdc3448..3cadfd559a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt @@ -1,16 +1,6 @@ - - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.MapGenerator; - -import java.util.HashMap; +package org.utbot.quickcheck.generator.java.util /** - * Produces values of type {@link HashMap}. + * Produces values of type [HashMap]. */ -public class HashMapGenerator extends MapGenerator { - public HashMapGenerator() { - super(HashMap.class); - } -} +class HashMapGenerator : MapGenerator(HashMap::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt index fb23f3cdb4..176607dd8b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt @@ -1,16 +1,6 @@ - - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.SetGenerator; - -import java.util.HashSet; +package org.utbot.quickcheck.generator.java.util /** - * Produces values of type {@link HashSet}. + * Produces values of type [HashSet]. */ -public class HashSetGenerator extends SetGenerator { - public HashSetGenerator() { - super(HashSet.class); - } -} +class HashSetGenerator : SetGenerator(HashSet::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt index e7a798bf0e..c1beb5a60b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt @@ -1,20 +1,12 @@ +package org.utbot.quickcheck.generator.java.util - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.MapGenerator; - -import java.util.Hashtable; +import java.util.Hashtable /** - * Produces values of type {@link Hashtable}. + * Produces values of type [Hashtable]. */ -public class HashtableGenerator extends MapGenerator { - public HashtableGenerator() { - super(Hashtable.class); - } - - @Override protected boolean okToAdd(Object key, Object value) { - return key != null && value != null; +class HashtableGenerator : MapGenerator(Hashtable::class.java) { + override fun okToAdd(key: Any?, value: Any?): Boolean { + return key != null && value != null } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt index 2ae83b4bf8..551c1ff466 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt @@ -1,16 +1,6 @@ - - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.MapGenerator; - -import java.util.LinkedHashMap; +package org.utbot.quickcheck.generator.java.util /** - * Produces values of type {@link LinkedHashMap}. + * Produces values of type [LinkedHashMap]. */ -public class LinkedHashMapGenerator extends MapGenerator { - public LinkedHashMapGenerator() { - super(LinkedHashMap.class); - } -} +class LinkedHashMapGenerator : MapGenerator(LinkedHashMap::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt index b61f776ac7..8f72a9e941 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt @@ -1,16 +1,6 @@ - - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.SetGenerator; - -import java.util.LinkedHashSet; +package org.utbot.quickcheck.generator.java.util /** - * Produces values of type {@link LinkedHashSet}. + * Produces values of type [LinkedHashSet]. */ -public class LinkedHashSetGenerator extends SetGenerator { - public LinkedHashSetGenerator() { - super(LinkedHashSet.class); - } -} +class LinkedHashSetGenerator : SetGenerator(LinkedHashSet::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt index 33eebfa64f..a084b8ed1d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt @@ -1,16 +1,8 @@ +package org.utbot.quickcheck.generator.java.util - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.ListGenerator; - -import java.util.LinkedList; +import java.util.LinkedList /** - * Produces values of type {@link LinkedList}. + * Produces values of type [LinkedList]. */ -public class LinkedListGenerator extends ListGenerator { - public LinkedListGenerator() { - super(LinkedList.class); - } -} +class LinkedListGenerator : ListGenerator(LinkedList::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt index c5267bfc0c..66deab14a2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt @@ -1,20 +1,8 @@ - - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.CollectionGenerator; - -import java.util.List; +package org.utbot.quickcheck.generator.java.util /** - * Base class for generators of {@link List}s. + * Base class for generators of [List]s. * * @param the type of list generated - */ -public abstract class ListGenerator - extends CollectionGenerator { - - protected ListGenerator(Class type) { - super(type); - } -} + */ +abstract class ListGenerator protected constructor(type: Class<*>) : CollectionGenerator(type) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt index 812fb10fdf..9235d95bbd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt @@ -1,32 +1,28 @@ +package org.utbot.quickcheck.generator.java.util - -package org.utbot.quickcheck.generator.java.util; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Locale; - -import static java.util.Locale.getAvailableLocales; -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.Locale /** - * Produces values of type {@link Locale}. + * Produces values of type [Locale]. */ -public class LocaleGenerator extends Generator { - private static final Locale[] AVAILABLE_LOCALES = getAvailableLocales(); - - public LocaleGenerator() { - super(Locale.class); +class LocaleGenerator : Generator(Locale::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + random.choose(AVAILABLE_LOCALES), + classIdForType(Locale::class.java) + ) } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(random.choose(AVAILABLE_LOCALES), classIdForType(Locale.class)); + companion object { + private val AVAILABLE_LOCALES = Locale.getAvailableLocales() } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt index 14dd5024d1..affa2d5426 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt @@ -1,56 +1,51 @@ - - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.concrete.UtModelConstructor; -import org.utbot.framework.plugin.api.*; -import org.utbot.quickcheck.generator.*; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.*; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; -import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; -import static org.utbot.quickcheck.internal.Ranges.Type.INTEGRAL; -import static org.utbot.quickcheck.internal.Ranges.checkRange; -import static org.utbot.quickcheck.internal.Reflection.findConstructor; -import static org.utbot.quickcheck.internal.Reflection.instantiate; +package org.utbot.quickcheck.generator.java.util + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.ConstructorId +import org.utbot.framework.plugin.api.MethodId +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.objectClassId +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.Distinct +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Size +import org.utbot.quickcheck.internal.Ranges +import org.utbot.quickcheck.random.SourceOfRandomness /** - *

Base class for generators of {@link Map}s.

* - *

The generated map has a number of entries limited by - * {@link GenerationStatus#size()}, or else by the attributes of a {@link Size} + * Base class for generators of [Map]s. + * + * + * The generated map has a number of entries limited by + * [GenerationStatus.size], or else by the attributes of a [Size] * marking. The individual keys and values will have types corresponding to the - * property parameter's type arguments.

+ * property parameter's type arguments. * * @param the type of map generated - */ -public abstract class MapGenerator - extends ComponentizedGenerator { - - private Size sizeRange; - private boolean distinct; - - protected MapGenerator(Class type) { - super(type); - } + */ +abstract class MapGenerator protected constructor(type: Class<*>) : ComponentizedGenerator(type) { + private var sizeRange: Size? = null + private var distinct = false /** - *

Tells this generator to add key-value pairs to the generated map a + * + * Tells this generator to add key-value pairs to the generated map a * number of times within a specified minimum and/or maximum, inclusive, - * chosen with uniform distribution.

+ * chosen with uniform distribution. * - *

Note that maps disallow duplicate keys, so the number of pairs added - * may not be equal to the map's {@link Map#size()}.

+ * + * Note that maps disallow duplicate keys, so the number of pairs added + * may not be equal to the map's [Map.size]. * * @param size annotation that gives the size constraints */ - public void configure(Size size) { - this.sizeRange = size; - checkRange(INTEGRAL, size.min(), size.max()); + fun configure(size: Size) { + sizeRange = size + Ranges.checkRange(Ranges.Type.INTEGRAL, size.min, size.max) } /** @@ -60,63 +55,49 @@ public abstract class MapGenerator * @param distinct Keys of generated entries will be distinct if this * param is not null */ - public void configure(Distinct distinct) { - this.distinct = distinct != null; + fun configure(distinct: Distinct?) { + this.distinct = distinct != null } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - int size = size(random, status); - - final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); - final ClassId classId = classIdForType(types().get(0)); - final Generator keyGenerator = componentGenerators().get(0); - final Generator valueGenerator = componentGenerators().get(1); - - final ExecutableId constructorId = new ConstructorId(classId, List.of()); - final int generatedModelId = modelConstructor.computeUnusedIdAndUpdate(); - - final UtAssembleModel generatedModel = new UtAssembleModel( - generatedModelId, - classId, - constructorId.getName() + "#" + generatedModelId, - new UtExecutableCallModel(null, constructorId, List.of()), - null, - (a) -> { - final List modificationChain = new ArrayList<>(); - final ExecutableId putMethodId = methodId(classId, "put", getObjectClassId(), getObjectClassId(), getObjectClassId()); - - int i = 0; - while (i < size) { - final UtModel key = keyGenerator.generate(random, status); - final UtModel value = valueGenerator.generate(random, status); - if (!okToAdd(key, value)) continue; - i++; - modificationChain.add(new UtExecutableCallModel(a, putMethodId, List.of(key, value))); - } - return modificationChain; - } - ); - - - - return generatedModel; + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val size = size(random, status) + val classId = types().single().id + val keyGenerator = componentGenerators()[0] + val valueGenerator = componentGenerators()[1] + + val generatedModelId = utModelConstructor.computeUnusedIdAndUpdate() + val constructorId = ConstructorId(classId, emptyList()) + return UtAssembleModel( + generatedModelId, + classId, + constructorId.name + "#" + generatedModelId, + UtExecutableCallModel(null, constructorId, emptyList()), + ) { + val putMethodId = MethodId(classId, "put", objectClassId, listOf(objectClassId, objectClassId)) + generateSequence { + val key = keyGenerator.generate(random, status) + val value = valueGenerator.generate(random, status) + key to value + }.filter { (key, value) -> + okToAdd(key, value) + }.map { (key, value) -> + UtExecutableCallModel(this, putMethodId, listOf(key, value)) + }.take(size).toList() + } } - @Override public int numberOfNeededComponents() { - return 2; + override fun numberOfNeededComponents(): Int { + return 2 } - protected boolean okToAdd(Object key, Object value) { - return true; + protected open fun okToAdd(key: Any?, value: Any?): Boolean { + return true } - private int size(SourceOfRandomness random, GenerationStatus status) { - return sizeRange != null - ? random.nextInt(sizeRange.min(), sizeRange.max()) - : status.size(); + private fun size(random: SourceOfRandomness, status: GenerationStatus): Int { + return if (sizeRange != null) random.nextInt(sizeRange!!.min, sizeRange!!.max) else status.size() } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt index 4c7b4ddb3f..429290e1b4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt @@ -1,54 +1,43 @@ - - -package org.utbot.quickcheck.generator.java.util; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.java.lang.DoubleGenerator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.OptionalDouble; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +package org.utbot.quickcheck.generator.java.util + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.java.lang.DoubleGenerator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.OptionalDouble /** - * Produces values of type {@link OptionalDouble}. + * Produces values of type [OptionalDouble]. */ -public class OptionalDoubleGenerator extends Generator { - private final DoubleGenerator doubles = new DoubleGenerator(); - - public OptionalDoubleGenerator() { - super(OptionalDouble.class); - } +class OptionalDoubleGenerator : Generator(OptionalDouble::class.java) { + private val doubles = DoubleGenerator() /** * Tells this generator to produce values, when - * {@link OptionalDouble#isPresent() present}, within a specified minimum + * [present][OptionalDouble.isPresent], within a specified minimum * (inclusive) and/or maximum (exclusive) with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minDouble()} and {@link InRange#maxDouble()}, + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minDouble] and [InRange.maxDouble], * if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - doubles.configure(range); + fun configure(range: InRange?) { + doubles.configure(range!!) } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - double trial = random.nextDouble(); - final OptionalDouble generated = trial < 0.25 ? - OptionalDouble.empty() - : OptionalDouble.of(doubles.generateValue(random, status)); - - return UtModelGenerator.getUtModelConstructor().construct(generated, classIdForType(OptionalDouble.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val trial = random.nextDouble() + val generated = + if (trial < 0.25) OptionalDouble.empty() else OptionalDouble.of(doubles.generateValue(random, status)) + return utModelConstructor.construct(generated, classIdForType(OptionalDouble::class.java)) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt index 0b20932d44..145c81a245 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt @@ -1,57 +1,45 @@ - - -package org.utbot.quickcheck.generator.java.util; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.concrete.UtModelConstructor; -import org.utbot.framework.plugin.api.*; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.List; -import java.util.Optional; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; -import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; +package org.utbot.quickcheck.generator.java.util + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.methodId +import org.utbot.framework.plugin.api.util.objectClassId +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.Optional /** - * Produces values of type {@link Optional}. + * Produces values of type [Optional]. */ -public class OptionalGenerator extends ComponentizedGenerator { - public OptionalGenerator() { - super(Optional.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - double trial = random.nextDouble(); +class OptionalGenerator : ComponentizedGenerator(Optional::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val trial = random.nextDouble() + val classId = Optional::class.id if (trial < 0.25) { - return UtModelGenerator.getUtModelConstructor().construct(Optional.empty(), classIdForType(Optional.class)); + return utModelConstructor.construct( + Optional.empty(), + classId + ) } - - final UtModel value = componentGenerators().get(0).generate(random, status); - - final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); - final ClassId classId = classIdForType(Optional.class); - final ExecutableId constructorId = methodId(classId, "of", classId, getObjectClassId()); - - final int generatedModelId = modelConstructor.computeUnusedIdAndUpdate(); - return new UtAssembleModel( - generatedModelId, - classId, - constructorId.getName() + "#" + generatedModelId, - new UtExecutableCallModel(null, constructorId, List.of(value)), - null, - (a) -> List.of() - ); + val value = componentGenerators().first().generate(random, status) + val constructorId = methodId(classId, "of", classId, objectClassId) + val generatedModelId = utModelConstructor.computeUnusedIdAndUpdate() + return UtAssembleModel( + generatedModelId, + classId, + constructorId.name + "#" + generatedModelId, + UtExecutableCallModel(null, constructorId, listOf(value)), + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt index 15dd4bcd2f..ae44fe35a7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt @@ -1,53 +1,42 @@ - - -package org.utbot.quickcheck.generator.java.util; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.java.lang.IntegerGenerator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.OptionalInt; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +package org.utbot.quickcheck.generator.java.util + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.java.lang.IntegerGenerator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.OptionalInt /** - * Produces values of type {@link OptionalInt}. + * Produces values of type [OptionalInt]. */ -public class OptionalIntGenerator extends Generator { - private final IntegerGenerator integers = new IntegerGenerator(); - - public OptionalIntGenerator() { - super(OptionalInt.class); - } +class OptionalIntGenerator : Generator(OptionalInt::class.java) { + private val integers = IntegerGenerator() /** * Tells this generator to produce values, when - * {@link OptionalInt#isPresent() present}, within a specified minimum + * [present][OptionalInt.isPresent], within a specified minimum * and/or maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minInt()} and {@link InRange#maxInt()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minInt] and [InRange.maxInt], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - integers.configure(range); + fun configure(range: InRange?) { + integers.configure(range!!) } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - double trial = random.nextDouble(); - final OptionalInt generated = trial < 0.25 ? - OptionalInt.empty() - : OptionalInt.of(integers.generateValue(random, status)); - - return UtModelGenerator.getUtModelConstructor().construct(generated, classIdForType(OptionalInt.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val trial = random.nextDouble() + val generated = + if (trial < 0.25) OptionalInt.empty() else OptionalInt.of(integers.generateValue(random, status)) + return utModelConstructor.construct(generated, classIdForType(OptionalInt::class.java)) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt index 5682f74f6e..5ddda35c3a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt @@ -1,53 +1,41 @@ - - -package org.utbot.quickcheck.generator.java.util; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.InRange; -import org.utbot.quickcheck.generator.java.lang.LongGenerator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.*; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +package org.utbot.quickcheck.generator.java.util + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.InRange +import org.utbot.quickcheck.generator.java.lang.LongGenerator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.OptionalLong /** - * Produces values of type {@link OptionalLong}. + * Produces values of type [OptionalLong]. */ -public class OptionalLongGenerator extends Generator { - private final LongGenerator longs = new LongGenerator(); - - public OptionalLongGenerator() { - super(OptionalLong.class); - } +class OptionalLongGenerator : Generator(OptionalLong::class.java) { + private val longs = LongGenerator() /** * Tells this generator to produce values, when - * {@link OptionalLong#isPresent() present}, within a specified minimum + * [present][OptionalLong.isPresent], within a specified minimum * and/or maximum, inclusive, with uniform distribution. * - * {@link InRange#min} and {@link InRange#max} take precedence over - * {@link InRange#minLong()} and {@link InRange#maxLong()}, if non-empty. + * [InRange.min] and [InRange.max] take precedence over + * [InRange.minLong] and [InRange.maxLong], if non-empty. * * @param range annotation that gives the range's constraints */ - public void configure(InRange range) { - longs.configure(range); + fun configure(range: InRange?) { + longs.configure(range!!) } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - double trial = random.nextDouble(); - final OptionalLong generated = trial < 0.25 ? - OptionalLong.empty() - : OptionalLong.of(longs.generateValue(random, status)); - - return UtModelGenerator.getUtModelConstructor().construct(generated, classIdForType(OptionalLong.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val trial = random.nextDouble() + val generated = if (trial < 0.25) OptionalLong.empty() else OptionalLong.of(longs.generateValue(random, status)) + return utModelConstructor.construct(generated, classIdForType(OptionalLong::class.java)) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt index c9c8a1eab6..966622531a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt @@ -1,86 +1,66 @@ -package org.utbot.quickcheck.generator.java.util; - - - - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.concrete.UtModelConstructor; -import org.utbot.framework.plugin.api.*; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.java.lang.AbstractStringGenerator; -import org.utbot.quickcheck.generator.java.lang.Encoded; -import org.utbot.quickcheck.generator.java.lang.StringGenerator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.*; - -import static java.util.Arrays.asList; -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.framework.plugin.api.util.IdUtilKt.getObjectClassId; -import static org.utbot.framework.plugin.api.util.IdUtilKt.methodId; +package org.utbot.quickcheck.generator.java.util + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.ConstructorId +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtExecutableCallModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.methodId +import org.utbot.framework.plugin.api.util.objectClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.java.lang.AbstractStringGenerator +import org.utbot.quickcheck.generator.java.lang.Encoded +import org.utbot.quickcheck.generator.java.lang.Encoded.InCharset +import org.utbot.quickcheck.generator.java.lang.StringGenerator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.Dictionary +import java.util.Hashtable +import java.util.Properties /** - * Produces values of type {@link Properties}. + * Produces values of type [Properties]. */ -public class PropertiesGenerator extends Generator { - private AbstractStringGenerator stringGenerator = new StringGenerator(); - - public PropertiesGenerator() { - super(Properties.class); +class PropertiesGenerator : Generator(Properties::class.java) { + private var stringGenerator: AbstractStringGenerator = StringGenerator() + fun configure(charset: InCharset?) { + val encoded = Encoded() + encoded.configure(charset!!) + stringGenerator = encoded } - public void configure(Encoded.InCharset charset) { - Encoded encoded = new Encoded(); - encoded.configure(charset); - stringGenerator = encoded; + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val size = status.size() + val classId = Properties::class.id + + val generatedModelId = utModelConstructor.computeUnusedIdAndUpdate() + val constructorId = ConstructorId(classId, emptyList()) + return UtAssembleModel( + generatedModelId, + classId, + constructorId.name + "#" + generatedModelId, + UtExecutableCallModel(null, constructorId, emptyList()), + ) { + val setPropertyMethodId = methodId(classId, "setProperty", objectClassId, objectClassId, objectClassId) + (0..size).map { + val key = stringGenerator.generate(random, status) + val value = stringGenerator.generate(random, status) + UtExecutableCallModel(this, setPropertyMethodId, listOf(key, value)) + } + } } - @Override - public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - int size = status.size(); - - final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); - final ClassId classId = classIdForType(Properties.class); - - final ExecutableId constructorId = new ConstructorId(classId, List.of()); - final int generatedModelId = modelConstructor.computeUnusedIdAndUpdate(); - - final UtAssembleModel generatedModel = new UtAssembleModel( - generatedModelId, - classId, - constructorId.getName() + "#" + generatedModelId, - new UtExecutableCallModel(null, constructorId, List.of()), - null, - (a) -> { - final List modificationChain = new ArrayList<>(); - final ExecutableId setPropertyMethodId = methodId(classId, "setProperty", getObjectClassId(), getObjectClassId(), getObjectClassId()); - - for (int i = 0; i < size; i++) { - final UtModel key = stringGenerator.generate(random, status); - final UtModel value = stringGenerator.generate(random, status); - modificationChain.add(new UtExecutableCallModel(a, setPropertyMethodId, List.of(key, value))); - } - return modificationChain; - } - ); - - return generatedModel; - } - - @Override public boolean canRegisterAsType(Class type) { - Set> exclusions = - new HashSet<>( - asList( - Object.class, - Hashtable.class, - Map.class, - Dictionary.class)); - return !exclusions.contains(type); + override fun canRegisterAsType(type: Class<*>): Boolean { + val exclusions = setOf( + Any::class.java, + Hashtable::class.java, + MutableMap::class.java, + Dictionary::class.java + ) + return !exclusions.contains(type) } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt index b8d2a7bec4..00ac0a4842 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt @@ -1,169 +1,137 @@ - - -package org.utbot.quickcheck.generator.java.util; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.framework.plugin.api.UtNullModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.GeneratorConfiguration; -import org.utbot.quickcheck.generator.java.lang.StringGenerator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.annotation.Retention; -import java.lang.annotation.Target; -import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.UUID; - -import static java.lang.annotation.ElementType.*; -import static java.lang.annotation.RetentionPolicy.RUNTIME; -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +package org.utbot.quickcheck.generator.java.util + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.GeneratorConfiguration +import org.utbot.quickcheck.generator.java.lang.StringGenerator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.nio.ByteBuffer +import java.nio.charset.StandardCharsets +import java.security.MessageDigest +import java.security.NoSuchAlgorithmException +import java.util.UUID /** - * Home for machinery to produce {@link UUID}s according to - * RFC 4122. + * Home for machinery to produce [UUID]s according to + * [RFC 4122](http://www.ietf.org/rfc/rfc4122.txt). */ -public final class RFC4122 { - private RFC4122() { - throw new UnsupportedOperationException(); - } - - private abstract static class AbstractUUIDGenerator - extends Generator { +object RFC4122 { - protected AbstractUUIDGenerator() { - super(UUID.class); + abstract class AbstractUUIDGenerator : Generator(UUID::class.java) { + protected fun setVersion(bytes: ByteArray, mask: Byte) { + bytes[6] = (bytes[6].toInt() and 0x0F).toByte() + bytes[6] = (bytes[6].toInt() or mask.toInt()).toByte() } - protected final void setVersion(byte[] bytes, byte mask) { - bytes[6] &= 0x0F; - bytes[6] |= mask; + protected fun setVariant(bytes: ByteArray) { + bytes[8] = (bytes[8].toInt() and 0x3F).toByte() + bytes[8] = (bytes[8].toInt() or 0x80).toByte() } - protected final void setVariant(byte[] bytes) { - bytes[8] &= 0x3F; - bytes[8] |= 0x80; - } - - protected final UUID newUUID(byte[] bytes) { - ByteBuffer bytesIn = ByteBuffer.wrap(bytes); - return new UUID(bytesIn.getLong(), bytesIn.getLong()); + protected fun newUUID(bytes: ByteArray?): UUID { + val bytesIn = ByteBuffer.wrap(bytes) + return UUID(bytesIn.long, bytesIn.long) } } - private abstract static class NameBasedUUIDGenerator - extends AbstractUUIDGenerator { - - private final StringGenerator strings = new StringGenerator(); - private final int versionMask; - private final MessageDigest digest; - private Namespace namespace; + abstract class NameBasedUUIDGenerator(hashAlgorithmName: String?, private val versionMask: Int) : + AbstractUUIDGenerator() { + private val strings = StringGenerator() + private val digest: MessageDigest + private var namespace: Namespace? = null - protected NameBasedUUIDGenerator( - String hashAlgorithmName, - int versionMask) { - - this.versionMask = versionMask; - digest = MessageDigests.get(hashAlgorithmName); + init { + digest = MessageDigests[hashAlgorithmName] } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - digest.reset(); - - Namespaces namespaces = - namespace == null ? Namespaces.URL : namespace.value(); - digest.update(namespaces.bytes); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + digest.reset() + val namespaces = if (namespace == null) Namespaces.URL else namespace!!.value + digest.update(namespaces.bytes) digest.update( strings.generateValue(random, status) - .getBytes(StandardCharsets.UTF_8)); - - byte[] hash = digest.digest(); - setVersion(hash, (byte) versionMask); - setVariant(hash); - final UUID generatedUUID = newUUID(hash); - return UtModelGenerator.getUtModelConstructor().construct(generatedUUID, classIdForType(UUID.class)); + .toByteArray(StandardCharsets.UTF_8) + ) + val hash = digest.digest() + setVersion(hash, versionMask.toByte()) + setVariant(hash) + val generatedUUID = newUUID(hash) + return utModelConstructor.construct(generatedUUID, classIdForType(UUID::class.java)) } - protected void setNamespace(Namespace namespace) { - this.namespace = namespace; + protected fun setNamespace(namespace: Namespace?) { + this.namespace = namespace } } - static final class MessageDigests { - private MessageDigests() { - throw new UnsupportedOperationException(); + internal class MessageDigests private constructor() { + init { + throw UnsupportedOperationException() } - static MessageDigest get(String algorithmName) { - try { - return MessageDigest.getInstance(algorithmName); - } catch (NoSuchAlgorithmException shouldNeverHappen) { - throw new IllegalStateException(shouldNeverHappen); + companion object { + operator fun get(algorithmName: String?): MessageDigest { + return try { + MessageDigest.getInstance(algorithmName) + } catch (shouldNeverHappen: NoSuchAlgorithmException) { + throw IllegalStateException(shouldNeverHappen) + } } } } /** - * Produces values of type {@link UUID} that are RFC 4122 Version 3 + * Produces values of type [UUID] that are RFC 4122 Version 3 * identifiers. */ - public static class Version3 extends NameBasedUUIDGenerator { - public Version3() { - super("MD5", 0x30); - } - + class Version3 : NameBasedUUIDGenerator("MD5", 0x30) { /** * Tells this generator to prepend the given "namespace" UUID to the * names it generates for UUID production. * * @param namespace a handle for a "namespace" UUID */ - public void configure(Namespace namespace) { - setNamespace(namespace); + fun configure(namespace: Namespace?) { + setNamespace(namespace) } } /** - * Produces values of type {@link UUID} that are RFC 4122 Version 4 + * Produces values of type [UUID] that are RFC 4122 Version 4 * identifiers. */ - public static class Version4 extends AbstractUUIDGenerator { - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - byte[] bytes = random.nextBytes(16); - setVersion(bytes, (byte) 0x40); - setVariant(bytes); - final UUID generatedUUID = newUUID(bytes); - return UtModelGenerator.getUtModelConstructor().construct(generatedUUID, classIdForType(UUID.class)); + class Version4 : AbstractUUIDGenerator() { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val bytes = random.nextBytes(16) + setVersion(bytes, 0x40.toByte()) + setVariant(bytes) + val generatedUUID = newUUID(bytes) + return utModelConstructor.construct(generatedUUID, classIdForType(UUID::class.java)) } } /** - * Produces values of type {@link UUID} that are RFC 4122 Version 5 + * Produces values of type [UUID] that are RFC 4122 Version 5 * identifiers. */ - public static class Version5 extends NameBasedUUIDGenerator { - public Version5() { - super("SHA-1", 0x50); - } - + class Version5 : NameBasedUUIDGenerator("SHA-1", 0x50) { /** * Tells this generator to prepend the given "namespace" UUID to the * names it generates for UUID production. * * @param namespace a handle for a "namespace" UUID */ - public void configure(Namespace namespace) { - setNamespace(namespace); + fun configure(namespace: Namespace?) { + setNamespace(namespace) } } @@ -171,41 +139,45 @@ public final class RFC4122 { * Used in version 3 and version 5 UUID generation to specify a * "namespace" UUID for use in generation. */ - @Target({ PARAMETER, FIELD, ANNOTATION_TYPE, TYPE_USE }) - @Retention(RUNTIME) + @Target( + AnnotationTarget.VALUE_PARAMETER, + AnnotationTarget.FIELD, + AnnotationTarget.ANNOTATION_CLASS, + AnnotationTarget.TYPE + ) + @Retention(AnnotationRetention.RUNTIME) @GeneratorConfiguration - public @interface Namespace { + annotation class Namespace( /** * @return a handle on a "namespace" UUID to use in generation */ - Namespaces value() default Namespaces.URL; - } + val value: Namespaces = Namespaces.URL + ) /** * Well-known "namespace" UUIDs. */ - public enum Namespaces { - /** Fully-qualified DNS name. */ + enum class Namespaces(difference: Int) { + /** Fully-qualified DNS name. */ DNS(0x10), - /** URL. */ + /** URL. */ URL(0x11), - /** ISO object identifier. */ + /** ISO object identifier. */ ISO_OID(0x12), - /** X.500 distinguished name. */ + /** X.500 distinguished name. */ X500_DN(0x14); - final byte[] bytes; + val bytes: ByteArray - Namespaces(int difference) { - this.bytes = new byte[] { - 0x6B, (byte) 0xA7, (byte) 0xB8, (byte) difference, - (byte) 0x9D, (byte) 0xAD, - 0x11, (byte) 0xD1, - (byte) 0x80, (byte) 0xB4, - 0x00, (byte) 0xC0, 0x4F, (byte) 0xD4, 0x30, (byte) 0xC8 }; + init { + bytes = byteArrayOf( + 0x6B, 0xA7.toByte(), 0xB8.toByte(), difference.toByte(), 0x9D.toByte(), 0xAD.toByte(), + 0x11, 0xD1.toByte(), 0x80.toByte(), 0xB4.toByte(), + 0x00, 0xC0.toByte(), 0x4F, 0xD4.toByte(), 0x30, 0xC8.toByte() + ) } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt index 6a05b67408..e8d6d0b1b8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt @@ -1,27 +1,14 @@ +package org.utbot.quickcheck.generator.java.util - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.Size; -import org.utbot.quickcheck.generator.java.util.CollectionGenerator; - -import java.util.Set; +import org.utbot.quickcheck.generator.Size /** - * Base class for generators of {@link Set}s. + * Base class for generators of [Set]s. * - * @param the type of set generated - */ -public abstract class SetGenerator - extends CollectionGenerator { - - protected SetGenerator(Class type) { - super(type); - } - - @Override public void configure(Size size) { - super.configure(size); - - setDistinct(true); + * */ +abstract class SetGenerator constructor(type: Class<*>) : CollectionGenerator(type) { + override fun configure(size: Size) { + super.configure(size) + setDistinct(true) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt index cc7fe219bc..7280630eb0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt @@ -1,16 +1,8 @@ +package org.utbot.quickcheck.generator.java.util - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.ListGenerator; - -import java.util.Stack; +import java.util.Stack /** - * Produces values of type {@link Stack}. + * Produces values of type [Stack]. */ -public class StackGenerator extends ListGenerator { - public StackGenerator() { - super(Stack.class); - } -} +class StackGenerator : ListGenerator(Stack::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt index 7ac9ef719e..15767e8ba3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt @@ -1,33 +1,28 @@ +package org.utbot.quickcheck.generator.java.util - -package org.utbot.quickcheck.generator.java.util; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.TimeZone; - -import static java.util.TimeZone.getAvailableIDs; -import static java.util.TimeZone.getTimeZone; -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.TimeZone /** - * Produces values of type {@link TimeZone}. + * Produces values of type [TimeZone]. */ -public class TimeZoneGenerator extends Generator { - private static final String[] AVAILABLE_IDS = getAvailableIDs(); - - public TimeZoneGenerator() { - super(TimeZone.class); +class TimeZoneGenerator : Generator(TimeZone::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + TimeZone.getTimeZone(random.choose(AVAILABLE_IDS)), + classIdForType(TimeZone::class.java) + ) } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(getTimeZone(random.choose(AVAILABLE_IDS)), classIdForType(TimeZone.class)); + companion object { + private val AVAILABLE_IDS = TimeZone.getAvailableIDs() } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt index 376051f73f..e6c32ba018 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt @@ -1,16 +1,8 @@ +package org.utbot.quickcheck.generator.java.util - -package org.utbot.quickcheck.generator.java.util; - -import org.utbot.quickcheck.generator.java.util.ListGenerator; - -import java.util.Vector; +import java.util.Vector /** - * Produces values of type {@link Vector}. + * Produces values of type [Vector]. */ -public class VectorGenerator extends ListGenerator { - public VectorGenerator() { - super(Vector.class); - } -} +class VectorGenerator : ListGenerator(Vector::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt index 75dc9392c4..0568d602ea 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt @@ -1,39 +1,35 @@ +package org.utbot.quickcheck.generator.java.util.concurrent - -package org.utbot.quickcheck.generator.java.util.concurrent; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.concurrent.Callable; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.concurrent.Callable /** - * Produces values of type {@code Callable}. + * Produces values of type `Callable`. * * @param the type of the values produced by the generated instances - */ -public class CallableGenerator extends ComponentizedGenerator { - public CallableGenerator() { - super(Callable.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda( - Callable.class, - componentGenerators().get(0), - status), classIdForType(CallableGenerator.class)); + */ +class CallableGenerator : ComponentizedGenerator(Callable::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + Callable::class.java, + componentGenerators()[0], + status + ), + Callable::class.id + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt index b0d5935548..6bce20ecc0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt @@ -1,43 +1,37 @@ +package org.utbot.quickcheck.generator.java.util.function - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.BiFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.BiFunction /** - * Produces values of type {@link BiFunction}. + * Produces values of type [BiFunction]. * * @param type of first parameter of produced function * @param type of second parameter of produced function * @param return type of produced function - */ -public class BiFunctionGenerator - extends ComponentizedGenerator { - - public BiFunctionGenerator() { - super(BiFunction.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda( - BiFunction.class, - componentGenerators().get(2), - status), classIdForType(BiFunction.class)); + */ +class BiFunctionGenerator : ComponentizedGenerator(BiFunction::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + BiFunction::class.java, + componentGenerators()[2], + status + ), + classIdForType(BiFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 3; + override fun numberOfNeededComponents(): Int { + return 3 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt index 884eed26e9..36bd48ce17 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt @@ -1,49 +1,40 @@ - - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.BiPredicate; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +package org.utbot.quickcheck.generator.java.util.function + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.BiPredicate /** - * Produces values of type {@link BiPredicate}. + * Produces values of type [BiPredicate]. * * @param type of first parameter of produced predicate * @param type of second parameter of produced predicate - */ -public class BiPredicateGenerator - extends ComponentizedGenerator { - - private Generator generator; - - public BiPredicateGenerator() { - super(BiPredicate.class); + */ +class BiPredicateGenerator : ComponentizedGenerator(BiPredicate::class.java) { + private var generator: Generator? = null + override fun provide(provided: Generators) { + super.provide(provided) + generator = gen()!!.type(Boolean::class.javaPrimitiveType!!) } - @Override public void provide(Generators provided) { - super.provide(provided); - - generator = gen().type(boolean.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda(BiPredicate.class, generator, status), classIdForType(BiPredicateGenerator.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda(BiPredicate::class.java, generator!!, status), + classIdForType(BiPredicate::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 2; + override fun numberOfNeededComponents(): Int { + return 2 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt index dd4a6e91dc..70ce25c141 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt @@ -1,41 +1,34 @@ +package org.utbot.quickcheck.generator.java.util.function - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.BinaryOperator; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.BinaryOperator /** - * Produces values of type {@link BinaryOperator}. + * Produces values of type [BinaryOperator]. * * @param parameters type and return type of produced operator - */ -public class BinaryOperatorGenerator - extends ComponentizedGenerator { - - public BinaryOperatorGenerator() { - super(BinaryOperator.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda( - BinaryOperator.class, - componentGenerators().get(0), - status), classIdForType(BinaryOperator.class)); + */ +class BinaryOperatorGenerator : ComponentizedGenerator(BinaryOperator::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + BinaryOperator::class.java, + componentGenerators()[0], + status + ), classIdForType(BinaryOperator::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt index 48dbcea56d..bd0640ce49 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt @@ -1,41 +1,34 @@ +package org.utbot.quickcheck.generator.java.util.function - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.DoubleFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.DoubleFunction /** - * Produces values of type {@link DoubleFunction}. + * Produces values of type [DoubleFunction]. * * @param return type of produced function - */ -public class DoubleFunctionGenerator - extends ComponentizedGenerator { - - public DoubleFunctionGenerator() { - super(DoubleFunction.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda( - DoubleFunction.class, - componentGenerators().get(0), - status), classIdForType(DoubleFunction.class)); + */ +class DoubleFunctionGenerator : ComponentizedGenerator(DoubleFunction::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + DoubleFunction::class.java, + componentGenerators()[0], + status + ), classIdForType(DoubleFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt index caf71bec88..1fed09b2cf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt @@ -1,40 +1,35 @@ +package org.utbot.quickcheck.generator.java.util.function - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.Function; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.Function /** - * Produces values of type {@link Function}. + * Produces values of type [Function]. * * @param type of parameter of produced function * @param return type of produced function - */ -public class FunctionGenerator extends ComponentizedGenerator { - public FunctionGenerator() { - super(Function.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda( - Function.class, - componentGenerators().get(1), - status), classIdForType(Function.class)); + */ +class FunctionGenerator : ComponentizedGenerator(Function::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + Function::class.java, + componentGenerators()[1], + status + ), classIdForType(Function::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 2; + override fun numberOfNeededComponents(): Int { + return 2 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt index cd150361df..029f3893c2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt @@ -1,41 +1,34 @@ +package org.utbot.quickcheck.generator.java.util.function - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; - -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.IntFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.IntFunction /** - * Produces values of type {@link IntFunction}. + * Produces values of type [IntFunction]. * * @param return type of produced function - */ -public class IntFunctionGenerator - extends ComponentizedGenerator { - - public IntFunctionGenerator() { - super(IntFunction.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda( - IntFunction.class, - componentGenerators().get(0), - status), classIdForType(IntFunction.class)); + */ +class IntFunctionGenerator : ComponentizedGenerator(IntFunction::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + IntFunction::class.java, + componentGenerators()[0], + status + ), classIdForType(IntFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt index 39f7e476c1..b4bed86de6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt @@ -1,41 +1,34 @@ +package org.utbot.quickcheck.generator.java.util.function - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.LongFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.LongFunction /** - * Produces values of type {@link LongFunction}. + * Produces values of type [LongFunction]. * * @param return type of produced function - */ -public class LongFunctionGenerator - extends ComponentizedGenerator { - - public LongFunctionGenerator() { - super(LongFunction.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda( - LongFunction.class, - componentGenerators().get(0), - status), classIdForType(LongFunction.class)); + */ +class LongFunctionGenerator : ComponentizedGenerator(LongFunction::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + LongFunction::class.java, + componentGenerators()[0], + status + ), classIdForType(LongFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt index 7dbfae02b6..7e13e1743e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt @@ -1,46 +1,41 @@ - - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.Predicate; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +package org.utbot.quickcheck.generator.java.util.function + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.Predicate /** - * Produces values of type {@link Predicate}. + * Produces values of type [Predicate]. * * @param type of parameter of produced predicate - */ -public class PredicateGenerator extends ComponentizedGenerator { - private Generator generator; - - public PredicateGenerator() { - super(Predicate.class); + */ +class PredicateGenerator : ComponentizedGenerator(Predicate::class.java) { + private var generator: Generator? = null + override fun provide(provided: Generators) { + super.provide(provided) + generator = gen()!!.type(Boolean::class.javaPrimitiveType!!) } - @Override public void provide(Generators provided) { - super.provide(provided); - - generator = gen().type(boolean.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda(Predicate.class, generator, status), classIdForType(Predicate.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + Predicate::class.java, generator!!, status + ), + classIdForType(Predicate::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt index 7ea6b20f30..439a0a9841 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt @@ -1,39 +1,34 @@ +package org.utbot.quickcheck.generator.java.util.function - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.Supplier; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.Supplier /** - * Produces values of type {@code Supplier}. + * Produces values of type `Supplier`. * * @param the type of the values produced by the generated instances - */ -public class SupplierGenerator extends ComponentizedGenerator { - public SupplierGenerator() { - super(Supplier.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda( - Supplier.class, - componentGenerators().get(0), - status), classIdForType(Supplier.class)); + */ +class SupplierGenerator : ComponentizedGenerator(Supplier::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + Supplier::class.java, + componentGenerators()[0], + status + ), classIdForType(Supplier::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt index 1ee1fc7ff3..1f7623e601 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt @@ -1,49 +1,41 @@ - - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.ToDoubleBiFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +package org.utbot.quickcheck.generator.java.util.function + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.ToDoubleBiFunction /** - * Produces values of type {@link ToDoubleBiFunction}. + * Produces values of type [ToDoubleBiFunction]. * * @param type of first parameter of produced function * @param type of second parameter of produced function - */ -public class ToDoubleBiFunctionGenerator - extends ComponentizedGenerator { - - private Generator generator; - - public ToDoubleBiFunctionGenerator() { - super(ToDoubleBiFunction.class); + */ +class ToDoubleBiFunctionGenerator : ComponentizedGenerator(ToDoubleBiFunction::class.java) { + private var generator: Generator? = null + override fun provide(provided: Generators) { + super.provide(provided) + generator = gen()!!.type(Double::class.javaPrimitiveType!!) } - @Override public void provide(Generators provided) { - super.provide(provided); - - generator = gen().type(double.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToDoubleBiFunction.class, generator, status), classIdForType(ToDoubleBiFunction.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + ToDoubleBiFunction::class.java, generator!!, status + ), classIdForType(ToDoubleBiFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 2; + override fun numberOfNeededComponents(): Int { + return 2 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt index fcc3bcf326..1dedf3a68f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt @@ -1,48 +1,40 @@ - - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.ToDoubleFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +package org.utbot.quickcheck.generator.java.util.function + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.ToDoubleFunction /** - * Produces values of type {@link ToDoubleFunction}. + * Produces values of type [ToDoubleFunction]. * * @param type of parameter of produced function - */ -public class ToDoubleFunctionGenerator - extends ComponentizedGenerator { - - private Generator generator; - - public ToDoubleFunctionGenerator() { - super(ToDoubleFunction.class); + */ +class ToDoubleFunctionGenerator : ComponentizedGenerator(ToDoubleFunction::class.java) { + private var generator: Generator? = null + override fun provide(provided: Generators) { + super.provide(provided) + generator = gen()!!.type(Double::class.javaPrimitiveType!!) } - @Override public void provide(Generators provided) { - super.provide(provided); - - generator = gen().type(double.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToDoubleFunction.class, generator, status), classIdForType(ToDoubleFunction.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + ToDoubleFunction::class.java, generator!!, status + ), classIdForType(ToDoubleFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt index 6c34d374d3..f42f0b4a25 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt @@ -1,49 +1,41 @@ - - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; - -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.ToIntBiFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +package org.utbot.quickcheck.generator.java.util.function + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.ToIntBiFunction /** - * Produces values of type {@link ToIntBiFunction}. + * Produces values of type [ToIntBiFunction]. * * @param type of first parameter of produced function * @param type of second parameter of produced function - */ -public class ToIntBiFunctionGenerator - extends ComponentizedGenerator { - - private Generator generator; - - public ToIntBiFunctionGenerator() { - super(ToIntBiFunction.class); + */ +class ToIntBiFunctionGenerator : ComponentizedGenerator(ToIntBiFunction::class.java) { + private var generator: Generator? = null + override fun provide(provided: Generators) { + super.provide(provided) + generator = gen()!!.type(Int::class.javaPrimitiveType!!) } - @Override public void provide(Generators provided) { - super.provide(provided); - - generator = gen().type(int.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToIntBiFunction.class, generator, status), classIdForType(ToIntBiFunctionGenerator.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + ToIntBiFunction::class.java, generator!!, status + ), classIdForType(ToIntBiFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 2; + override fun numberOfNeededComponents(): Int { + return 2 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt index f0790134b3..19a66a881e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt @@ -1,48 +1,40 @@ - - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.ToIntFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +package org.utbot.quickcheck.generator.java.util.function + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.ToIntFunction /** - * Produces values of type {@link ToIntFunction}. + * Produces values of type [ToIntFunction]. * * @param type of parameter of produced function - */ -public class ToIntFunctionGenerator - extends ComponentizedGenerator { - - private Generator generator; - - public ToIntFunctionGenerator() { - super(ToIntFunction.class); + */ +class ToIntFunctionGenerator : ComponentizedGenerator(ToIntFunction::class.java) { + private var generator: Generator? = null + override fun provide(provided: Generators) { + super.provide(provided) + generator = gen()!!.type(Int::class.javaPrimitiveType!!) } - @Override public void provide(Generators provided) { - super.provide(provided); - - generator = gen().type(int.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToIntFunction.class, generator, status), classIdForType(ToIntFunction.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + ToIntFunction::class.java, generator!!, status + ), classIdForType(ToIntFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt index 33fa9d8264..ff4a80d08d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt @@ -1,49 +1,41 @@ - - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; - -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.ToLongBiFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +package org.utbot.quickcheck.generator.java.util.function + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.ToLongBiFunction /** - * Produces values of type {@link ToLongBiFunction}. + * Produces values of type [ToLongBiFunction]. * * @param type of first parameter of produced function * @param type of second parameter of produced function - */ -public class ToLongBiFunctionGenerator - extends ComponentizedGenerator { - - private Generator generator; - - public ToLongBiFunctionGenerator() { - super(ToLongBiFunction.class); + */ +class ToLongBiFunctionGenerator : ComponentizedGenerator(ToLongBiFunction::class.java) { + private var generator: Generator? = null + override fun provide(provided: Generators) { + super.provide(provided) + generator = gen()!!.type(Long::class.javaPrimitiveType!!) } - @Override public void provide(Generators provided) { - super.provide(provided); - - generator = gen().type(long.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToLongBiFunction.class, generator, status), classIdForType(ToLongBiFunction.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + ToLongBiFunction::class.java, generator!!, status + ), classIdForType(ToLongBiFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 2; + override fun numberOfNeededComponents(): Int { + return 2 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt index fd17b25029..50515db607 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt @@ -1,49 +1,40 @@ - - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.ToLongFunction; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +package org.utbot.quickcheck.generator.java.util.function + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.ToLongFunction /** - * Produces values of type {@link ToLongFunction}. + * Produces values of type [ToLongFunction]. * * @param type of parameter of produced function - */ -public class ToLongFunctionGenerator - extends ComponentizedGenerator { - - private Generator generator; - - public ToLongFunctionGenerator() { - super(ToLongFunction.class); + */ +class ToLongFunctionGenerator : ComponentizedGenerator(ToLongFunction::class.java) { + private var generator: Generator? = null + override fun provide(provided: Generators) { + super.provide(provided) + generator = gen()!!.type(Long::class.javaPrimitiveType!!) } - @Override - public void provide(Generators provided) { - super.provide(provided); - - generator = gen().type(long.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda(ToLongFunction.class, generator, status), classIdForType(ToLongFunction.class)); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + ToLongFunction::class.java, generator!!, status + ), classIdForType(ToLongFunction::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt index ea61a9a7cc..0d5ee7f5fd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt @@ -1,41 +1,34 @@ +package org.utbot.quickcheck.generator.java.util.function - -package org.utbot.quickcheck.generator.java.util.function; -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; - -import org.utbot.quickcheck.generator.ComponentizedGenerator; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.function.UnaryOperator; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.generator.Lambdas.makeLambda; +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.ComponentizedGenerator +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.quickcheck.random.SourceOfRandomness +import java.util.function.UnaryOperator /** - * Produces values of type {@link UnaryOperator}. + * Produces values of type [UnaryOperator]. * * @param type of parameter and return type of produced operator - */ -public class UnaryOperatorGenerator - extends ComponentizedGenerator { - - public UnaryOperatorGenerator() { - super(UnaryOperator.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(makeLambda( - UnaryOperator.class, - componentGenerators().get(0), - status), classIdForType(UnaryOperator.class)); + */ +class UnaryOperatorGenerator : ComponentizedGenerator(UnaryOperator::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + makeLambda( + UnaryOperator::class.java, + componentGenerators()[0], + status + ), classIdForType(UnaryOperator::class.java) + ) } - @Override public int numberOfNeededComponents() { - return 1; + override fun numberOfNeededComponents(): Int { + return 1 } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt index 55c64bc53c..d8e68d72a1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt @@ -1,55 +1,48 @@ -package org.utbot.quickcheck.internal; +package org.utbot.quickcheck.internal -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodHandles.Lookup; -import java.lang.invoke.MethodType; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; +import java.lang.invoke.MethodHandle +import java.lang.invoke.MethodHandles +import java.lang.invoke.MethodType +import java.lang.reflect.Constructor +import java.lang.reflect.Method -import static org.utbot.quickcheck.internal.Reflection.findDeclaredConstructor; -import static org.utbot.quickcheck.internal.Reflection.jdk9OrBetter; - -public final class DefaultMethodHandleMaker { - private static volatile Constructor methodLookupCtorJDK8; - - private static Constructor methodLookupCtorJDK8() { - if (methodLookupCtorJDK8 == null) { - methodLookupCtorJDK8 = - findDeclaredConstructor(Lookup.class, Class.class, int.class); - } - - return methodLookupCtorJDK8; - } - - public MethodHandle handleForSpecialMethod(Method method) - throws Exception { - - return jdk9OrBetter() - ? jdk9OrBetterMethodHandle(method) - : jdk8MethodHandleForDefault(method); +class DefaultMethodHandleMaker { + fun handleForSpecialMethod(method: Method): MethodHandle { + return if (Reflection.jdk9OrBetter()) jdk9OrBetterMethodHandle(method) else jdk8MethodHandleForDefault(method) } - private MethodHandle jdk9OrBetterMethodHandle(Method method) - throws Exception { - + private fun jdk9OrBetterMethodHandle(method: Method): MethodHandle { return MethodHandles.lookup() .findSpecial( - method.getDeclaringClass(), - method.getName(), + method.declaringClass, + method.name, MethodType.methodType( - method.getReturnType(), - method.getParameterTypes()), - method.getDeclaringClass()); + method.returnType, + method.parameterTypes + ), + method.declaringClass + ) } - private MethodHandle jdk8MethodHandleForDefault(Method method) - throws Exception { + private fun jdk8MethodHandleForDefault(method: Method): MethodHandle { + val lookup = methodLookupCtorJDK8()!! + .newInstance( + method.declaringClass, + MethodHandles.Lookup.PRIVATE + ) + return lookup.unreflectSpecial(method, method.declaringClass) + } - Lookup lookup = - methodLookupCtorJDK8().newInstance( - method.getDeclaringClass(), - Lookup.PRIVATE); - return lookup.unreflectSpecial(method, method.getDeclaringClass()); + companion object { + @Volatile + private var methodLookupCtorJDK8: Constructor? = null + private fun methodLookupCtorJDK8(): Constructor? { + if (methodLookupCtorJDK8 == null) { + methodLookupCtorJDK8 = Reflection.findDeclaredConstructor( + MethodHandles.Lookup::class.java, Class::class.java, Int::class.javaPrimitiveType + ) + } + return methodLookupCtorJDK8 + } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt index bee540a624..10c32735b6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt @@ -1,90 +1,73 @@ +package org.utbot.quickcheck.internal +import java.lang.reflect.AnnotatedArrayType +import java.lang.reflect.AnnotatedType +import java.lang.reflect.Type -package org.utbot.quickcheck.internal; +object FakeAnnotatedTypeFactory { -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedArrayType; -import java.lang.reflect.AnnotatedType; -import java.lang.reflect.Type; - -final class FakeAnnotatedTypeFactory { - private FakeAnnotatedTypeFactory() { - throw new UnsupportedOperationException(); - } - - static AnnotatedType makeFrom(Class clazz) { - return clazz.isArray() ? makeArrayType(clazz) : makePlainType(clazz); - } - - private static AnnotatedArrayType makeArrayType(Class type) { - return new FakeAnnotatedArrayType(type); - } - - private static AnnotatedType makePlainType(Class type) { - return new FakeAnnotatedType(type); - } - - private static final class FakeAnnotatedArrayType - implements AnnotatedArrayType { - - private final Class type; - - FakeAnnotatedArrayType(Class type) { - this.type = type; - } - - @Override public AnnotatedType getAnnotatedGenericComponentType() { - return makeFrom(type.getComponentType()); + private class FakeAnnotatedArrayType(private val type: Class<*>) : AnnotatedArrayType { + override fun getAnnotatedGenericComponentType(): AnnotatedType { + return makeFrom(type.componentType) } // Not introduced until JDK 9 -- not marking as... // @Override - public AnnotatedType getAnnotatedOwnerType() { - return null; + override fun getAnnotatedOwnerType(): AnnotatedType? { + return null } - @Override public Type getType() { - return type; + override fun getType(): Type { + return type } - @Override public T getAnnotation( - Class annotationClass) { - - return null; + override fun getAnnotation( + annotationClass: Class + ): T? { + return null } - @Override public Annotation[] getAnnotations() { - return new Annotation[0]; + override fun getAnnotations(): Array { + return arrayOfNulls(0) } - @Override public Annotation[] getDeclaredAnnotations() { - return new Annotation[0]; + override fun getDeclaredAnnotations(): Array { + return arrayOfNulls(0) } } - private static final class FakeAnnotatedType implements AnnotatedType { - private final Class type; - - FakeAnnotatedType(Class type) { - this.type = type; + private class FakeAnnotatedType(private val type: Class<*>) : AnnotatedType { + override fun getType(): Type { + return type } - @Override public Type getType() { - return type; + override fun getAnnotation( + annotationClass: Class + ): T? { + return null } - @Override public T getAnnotation( - Class annotationClass) { - - return null; + override fun getAnnotations(): Array { + return arrayOfNulls(0) } - @Override public Annotation[] getAnnotations() { - return new Annotation[0]; + override fun getDeclaredAnnotations(): Array { + return arrayOfNulls(0) } + } - @Override public Annotation[] getDeclaredAnnotations() { - return new Annotation[0]; - } + + @JvmStatic + fun makeFrom(clazz: Class<*>): AnnotatedType { + return if (clazz.isArray) makeArrayType(clazz) else makePlainType(clazz) + } + + private fun makeArrayType(type: Class<*>): AnnotatedArrayType { + return FakeAnnotatedArrayType(type) } -} + + private fun makePlainType(type: Class<*>): AnnotatedType { + return FakeAnnotatedType(type) + } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt index 47212e9031..918b2a771b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt @@ -1,40 +1,27 @@ +package org.utbot.quickcheck.internal +import org.utbot.quickcheck.random.SourceOfRandomness +import kotlin.math.ceil +import kotlin.math.ln -package org.utbot.quickcheck.internal; - -import org.utbot.quickcheck.random.SourceOfRandomness; - -import static java.lang.Math.ceil; -import static java.lang.Math.log; - -public class GeometricDistribution { - public int sampleWithMean(double mean, SourceOfRandomness random) { - return sample(probabilityOfMean(mean), random); +class GeometricDistribution { + fun sampleWithMean(mean: Double, random: SourceOfRandomness): Int { + return sample(probabilityOfMean(mean), random) } - int sample(double p, SourceOfRandomness random) { - ensureProbability(p); - - if (p == 1) - return 0; - - double uniform = random.nextDouble(); - return (int) ceil(log(1 - uniform) / log(1 - p)); + fun sample(p: Double, random: SourceOfRandomness): Int { + ensureProbability(p) + if (p == 1.0) return 0 + val uniform = random.nextDouble() + return ceil(ln(1 - uniform) / ln(1 - p)).toInt() } - double probabilityOfMean(double mean) { - if (mean <= 0) { - throw new IllegalArgumentException( - "Need a positive mean, got " + mean); - } - - return 1 / mean; + fun probabilityOfMean(mean: Double): Double { + require(mean > 0) { "Need a positive mean, got $mean" } + return 1 / mean } - private void ensureProbability(double p) { - if (p <= 0 || p > 1) { - throw new IllegalArgumentException( - "Need a probability in (0, 1], got " + p); - } + private fun ensureProbability(p: Double) { + require(!(p <= 0 || p > 1)) { "Need a probability in (0, 1], got $p" } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Items.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Items.kt index 78d39b568d..aef85ec297 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Items.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Items.kt @@ -1,59 +1,34 @@ - - -package org.utbot.quickcheck.internal; - -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.util.Collection; -import java.util.List; -import java.util.RandomAccess; - -public final class Items { - private Items() { - throw new UnsupportedOperationException(); - } - - @SuppressWarnings("unchecked") - public static T choose(Collection items, SourceOfRandomness random) { - int size = items.size(); - if (size == 0) { - throw new IllegalArgumentException( - "Collection is empty, can't pick an element from it"); +package org.utbot.quickcheck.internal + +import org.utbot.quickcheck.random.SourceOfRandomness + +object Items { + @JvmStatic + fun choose(items: Collection, random: SourceOfRandomness): T { + val size = items.size + require(size != 0) { "Collection is empty, can't pick an element from it" } + if (items is RandomAccess && items is List<*>) { + val list = items as List + return if (size == 1) list[0] else list[random.nextInt(size)] } - - if (items instanceof RandomAccess && items instanceof List) { - List list = (List) items; - return size == 1 - ? list.get(0) - : list.get(random.nextInt(size)); - } - if (size == 1) { - return items.iterator().next(); + return items.iterator().next() } - - Object[] array = items.toArray(new Object[0]); - return (T) array[random.nextInt(array.length)]; + return items.toList()[random.nextInt(items.size)] } - public static T chooseWeighted( - Collection> items, - SourceOfRandomness random) { - - if (items.size() == 1) - return items.iterator().next().item; - - int range = items.stream().mapToInt(i -> i.weight).sum(); - int sample = random.nextInt(range); - - int threshold = 0; - for (Weighted each : items) { - threshold += each.weight; - if (sample < threshold) - return each.item; + fun chooseWeighted( + items: Collection>, + random: SourceOfRandomness + ): T { + if (items.size == 1) return items.iterator().next().item + val range = items.stream().mapToInt { i: Weighted -> i.weight }.sum() + val sample = random.nextInt(range) + var threshold = 0 + for (each in items) { + threshold += each.weight + if (sample < threshold) return each.item } - - throw new AssertionError( - String.format("sample = %d, range = %d", sample, range)); + throw AssertionError(String.format("sample = %d, range = %d", sample, range)) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt index f95cf5a3a1..1d25b177d1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt @@ -1,182 +1,53 @@ - - -package org.utbot.quickcheck.internal; - -import org.javaruntype.type.*; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; -import ru.vyarus.java.generics.resolver.GenericsResolver; -import ru.vyarus.java.generics.resolver.context.ConstructorGenericsContext; -import ru.vyarus.java.generics.resolver.context.GenericsContext; -import ru.vyarus.java.generics.resolver.context.MethodGenericsContext; - -import java.lang.reflect.Type; -import java.lang.reflect.*; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import static java.util.Collections.unmodifiableList; -import static org.javaruntype.type.Types.arrayComponentOf; -import static org.utbot.quickcheck.internal.Items.choose; -import static org.utbot.quickcheck.internal.Reflection.*; - -public class ParameterTypeContext { - private static final String EXPLICIT_GENERATOR_TYPE_MISMATCH_MESSAGE = - "The generator %s named in @%s on parameter %s does not produce a type-compatible object"; - private static org.utbot.quickcheck.internal.Zilch zilch; - - private final String parameterName; - private final AnnotatedType parameterType; - private final String declarerName; - private final org.javaruntype.type.Type resolved; - private final List>> explicits = new ArrayList<>(); - private final GenericsContext generics; - private final int parameterIndex; - - private AnnotatedElement annotatedElement; - private boolean allowMixedTypes; - - public GenericsContext getGenerics() { - return generics; - } - public org.javaruntype.type.Type getResolved() { - return resolved; - } - public static ParameterTypeContext forClass(Class clazz) { - return new ParameterTypeContext( - clazz.getTypeName(), - org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(clazz), - clazz.getTypeName(), - Types.forJavaLangReflectType(clazz), - GenericsResolver.resolve(clazz)); - } - - public static ParameterTypeContext forField(Field field) { - GenericsContext generics = - GenericsResolver.resolve(field.getDeclaringClass()); - - return new ParameterTypeContext( - field.getName(), - field.getAnnotatedType(), - field.getDeclaringClass().getName(), - Types.forJavaLangReflectType(generics.resolveFieldType(field)), - generics); - } - - public static ParameterTypeContext forParameter(Parameter parameter) { - Executable exec = parameter.getDeclaringExecutable(); - Class clazz = exec.getDeclaringClass(); - String declarerName = clazz.getName() + '.' + exec.getName(); - int parameterIndex = parameterIndex(exec, parameter); - - GenericsContext generics; - org.javaruntype.type.Type resolved; - - if (exec instanceof Method) { - Method method = (Method) exec; - MethodGenericsContext methodGenerics = - GenericsResolver.resolve(clazz).method(method); - resolved = - Types.forJavaLangReflectType( - methodGenerics.resolveParameterType(parameterIndex)); - generics = methodGenerics; - } else if (exec instanceof Constructor) { - Constructor ctor = (Constructor) exec; - ConstructorGenericsContext constructorGenerics = - GenericsResolver.resolve(clazz).constructor(ctor); - resolved = - Types.forJavaLangReflectType( - constructorGenerics.resolveParameterType(parameterIndex)); - generics = constructorGenerics; - } else { - throw new IllegalStateException("Unrecognized subtype of Executable"); - } - - return new ParameterTypeContext( - parameter.getName(), - parameter.getAnnotatedType(), - declarerName, - resolved, - generics, - parameterIndex); - } - - public static ParameterTypeContext forParameter( - Parameter parameter, - MethodGenericsContext generics) { - - Executable exec = parameter.getDeclaringExecutable(); - Class clazz = exec.getDeclaringClass(); - String declarerName = clazz.getName() + '.' + exec.getName(); - int parameterIndex = parameterIndex(exec, parameter); - - return new ParameterTypeContext( - parameter.getName(), - parameter.getAnnotatedType(), - declarerName, - Types.forJavaLangReflectType( - generics.resolveParameterType(parameterIndex)), - generics, - parameterIndex); - } - - private static int parameterIndex(Executable exec, Parameter parameter) { - Parameter[] parameters = exec.getParameters(); - for (int i = 0; i < parameters.length; ++i) { - if (parameters[i].equals(parameter)) - return i; - } - - throw new IllegalStateException( - "Cannot find parameter " + parameter + " on " + exec); - } - - public ParameterTypeContext( - String parameterName, - AnnotatedType parameterType, - String declarerName, - org.javaruntype.type.Type resolvedType, - GenericsContext generics) { - - this( - parameterName, - parameterType, - declarerName, - resolvedType, - generics, - -1); - } - - public ParameterTypeContext( - String parameterName, - AnnotatedType parameterType, - String declarerName, - org.javaruntype.type.Type resolvedType, - GenericsContext generics, - int parameterIndex) { - - this.parameterName = parameterName; - this.parameterType = parameterType; - this.declarerName = declarerName; - this.resolved = resolvedType; - this.generics = generics; - this.parameterIndex = parameterIndex; - } - - public ParameterTypeContext annotate(AnnotatedElement element) { - this.annotatedElement = element; - return this; - } - - public ParameterTypeContext allowMixedTypes(boolean value) { - this.allowMixedTypes = value; - return this; - } - - public boolean allowMixedTypes() { - return allowMixedTypes; +package org.utbot.quickcheck.internal + +import org.javaruntype.type.ExtendsTypeParameter +import org.javaruntype.type.StandardTypeParameter +import org.javaruntype.type.Type +import org.javaruntype.type.TypeParameter +import org.javaruntype.type.Types +import org.javaruntype.type.WildcardTypeParameter +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom +import org.utbot.quickcheck.internal.Items.choose +import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.GenericsResolver +import ru.vyarus.java.generics.resolver.context.GenericsContext +import ru.vyarus.java.generics.resolver.context.MethodGenericsContext +import java.lang.reflect.AnnotatedArrayType +import java.lang.reflect.AnnotatedElement +import java.lang.reflect.AnnotatedType +import java.lang.reflect.Constructor +import java.lang.reflect.Executable +import java.lang.reflect.Field +import java.lang.reflect.Method +import java.lang.reflect.Parameter +import java.lang.reflect.ParameterizedType +import java.lang.reflect.TypeVariable + +class ParameterTypeContext( + private val parameterName: String, + private val parameterType: AnnotatedType, + private val declarerName: String, + val resolved: Type<*>, + val generics: GenericsContext, + private val parameterIndex: Int = -1 +) { + private val explicits = mutableListOf>() + private var annotatedElement: AnnotatedElement? = null + private var allowMixedTypes = false + + fun annotate(element: AnnotatedElement?): ParameterTypeContext { + annotatedElement = element + return this + } + + fun allowMixedTypes(value: Boolean): ParameterTypeContext { + allowMixedTypes = value + return this + } + + fun allowMixedTypes(): Boolean { + return allowMixedTypes } /** @@ -185,257 +56,329 @@ public class ParameterTypeContext { * @param method method whose return type we want to resolve * @return an associated parameter context */ - public ParameterTypeContext methodReturnTypeContext(Method method) { - if (!(generics instanceof MethodGenericsContext)) { - throw new IllegalStateException( - "invoking methodReturnTypeContext in present of " + generics); - } - - MethodGenericsContext testMethodGenerics = - (MethodGenericsContext) generics; - MethodGenericsContext argMethodGenerics = - testMethodGenerics.parameterType(parameterIndex).method(method); - - return new ParameterTypeContext( + fun methodReturnTypeContext(method: Method): ParameterTypeContext { + check(generics is MethodGenericsContext) { "invoking methodReturnTypeContext in present of $generics" } + val argMethodGenerics = generics.parameterType(parameterIndex).method(method) + return ParameterTypeContext( "return value", - method.getAnnotatedReturnType(), - method.getName(), + method.annotatedReturnType, + method.name, Types.forJavaLangReflectType(argMethodGenerics.resolveReturnType()), - argMethodGenerics); + argMethodGenerics + ) } - private Generator makeGenerator( - Class generatorType) { - - Constructor ctor; - - try { + private fun makeGenerator( + generatorType: Class + ): Generator { + val ctor = try { // for Ctor/Fields - ctor = findConstructor(generatorType, Class.class); - } catch (ReflectionException ex) { - return instantiate(generatorType); + Reflection.findConstructor(generatorType, Class::class.java) + } catch (ex: ReflectionException) { + return Reflection.instantiate(generatorType) } - - return instantiate(ctor, rawParameterType()); + return Reflection.instantiate(ctor, rawParameterType()) } - private Class rawParameterType() { - if (type() instanceof ParameterizedType) - return resolved.getRawClass(); - if (type() instanceof TypeVariable) - return resolved.getRawClass(); - - return (Class) type(); + private fun rawParameterType(): Class<*> { + return when { + type() is ParameterizedType -> resolved.rawClass + type() is TypeVariable<*> -> resolved.rawClass + else -> type() as Class<*> + } } - public String name() { - return declarerName + ':' + parameterName; + fun name(): String { + return "$declarerName:$parameterName" } - public AnnotatedType annotatedType() { - return parameterType; + fun annotatedType(): AnnotatedType { + return parameterType } - public Type type() { - return parameterType.getType(); + fun type(): java.lang.reflect.Type { + return parameterType.type } /** - * @deprecated This will likely go away when languages whose compilers - * and interpreters produce class files that support annotations on type - * uses. - * @see - * this issue + * @see [ + * this issue](https://github.com/pholser/junit-quickcheck/issues/77) + * * @return the annotated program element this context represents */ - @Deprecated - public AnnotatedElement annotatedElement() { - return annotatedElement; + @Deprecated( + """This will likely go away when languages whose compilers + and interpreters produce class files that support annotations on type + uses. + """ + ) + fun annotatedElement(): AnnotatedElement? { + return annotatedElement } /** - * @deprecated This will likely go away when languages whose compilers - * and interpreters produce class files that support annotations on type - * uses. - * @see - * this issue + * @see [ + * this issue](https://github.com/pholser/junit-quickcheck/issues/77) + * * @return the annotated program element this context represents */ - @Deprecated - public boolean topLevel() { - return annotatedElement instanceof Parameter - || annotatedElement instanceof Field; + @Deprecated( + """This will likely go away when languages whose compilers + and interpreters produce class files that support annotations on type + uses. + """ + ) + fun topLevel(): Boolean { + return (annotatedElement is Parameter || annotatedElement is Field) } - public List>> explicitGenerators() { - return unmodifiableList(explicits); + fun explicitGenerators(): List> { + return explicits } - private void addParameterTypeContextToDeque(ArrayDeque deque, ParameterTypeContext ptx) { - if (ptx.resolved.getName().equals(Zilch.class.getName())) return; - deque.add(ptx); + private fun addParameterTypeContextToDeque(deque: ArrayDeque, ptx: ParameterTypeContext) { + if (ptx.resolved.name == Zilch::class.java.name) return + deque.add(ptx) } - public List getAllSubParameterTypeContexts(SourceOfRandomness sourceOfRandomness) { - ArrayList res = new ArrayList<>(); - res.add(this); - ArrayDeque deque = new ArrayDeque<>(); - if (isArray()) { - addParameterTypeContextToDeque(deque, arrayComponentContext()); - deque.add(arrayComponentContext()); + + fun getAllSubParameterTypeContexts(sourceOfRandomness: SourceOfRandomness?): List { + val res = mutableListOf(this) + val deque = ArrayDeque() + if (isArray) { + addParameterTypeContextToDeque(deque, arrayComponentContext()) + deque.add(arrayComponentContext()) + } + typeParameterContexts(sourceOfRandomness).forEach { ptx: ParameterTypeContext -> + addParameterTypeContextToDeque(deque, ptx) } - typeParameterContexts(sourceOfRandomness).forEach(ptx -> addParameterTypeContextToDeque(deque, ptx)); while (!deque.isEmpty()) { - ParameterTypeContext ptx = deque.removeFirst(); - res.add(ptx); - if (ptx.isArray()) { - addParameterTypeContextToDeque(deque, ptx.arrayComponentContext()); + val ptx = deque.removeFirst() + res.add(ptx) + if (ptx.isArray) { + addParameterTypeContextToDeque(deque, ptx.arrayComponentContext()) + } + ptx.typeParameterContexts(sourceOfRandomness).forEach { ptxNested: ParameterTypeContext -> + addParameterTypeContextToDeque(deque, ptxNested) } - ptx.typeParameterContexts(sourceOfRandomness).forEach(ptxNested -> addParameterTypeContextToDeque(deque, ptxNested)); } - return res; + return res } - public ParameterTypeContext arrayComponentContext() { - @SuppressWarnings("unchecked") - org.javaruntype.type.Type component = - arrayComponentOf((org.javaruntype.type.Type) resolved); - AnnotatedType annotatedComponent = annotatedArrayComponent(component); - return new ParameterTypeContext( - annotatedComponent.getType().getTypeName(), + + fun arrayComponentContext(): ParameterTypeContext { + val component = Types.arrayComponentOf(resolved as Type>) + val annotatedComponent = annotatedArrayComponent(component) + return ParameterTypeContext( + annotatedComponent.type.typeName, annotatedComponent, - parameterType.getType().getTypeName(), + parameterType.type.typeName, component, - generics) - .annotate(annotatedComponent) - .allowMixedTypes(true); - } - - private AnnotatedType annotatedArrayComponent( - org.javaruntype.type.Type component) { - - return parameterType instanceof AnnotatedArrayType - ? ((AnnotatedArrayType) parameterType).getAnnotatedGenericComponentType() - : org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom(component.getComponentClass()); - } - - public boolean isArray() { - return resolved.isArray(); - } - - public Class getRawClass() { - return resolved.getRawClass(); - } - - public boolean isEnum() { - return getRawClass().isEnum(); + generics + ).annotate(annotatedComponent).allowMixedTypes(true) } - public List> getTypeParameters() { - return resolved.getTypeParameters(); + private fun annotatedArrayComponent(component: Type<*>): AnnotatedType { + return if (parameterType is AnnotatedArrayType) { + parameterType.annotatedGenericComponentType + } else { + makeFrom(component.componentClass) + } } - public List typeParameterContexts( - SourceOfRandomness random) { - - List typeParamContexts = new ArrayList<>(); - List> typeParameters = getTypeParameters(); - List annotatedTypeParameters = - annotatedComponentTypes(annotatedType()); - - for (int i = 0; i < typeParameters.size(); ++i) { - TypeParameter p = typeParameters.get(i); - AnnotatedType a = - annotatedTypeParameters.size() > i - ? annotatedTypeParameters.get(i) - : zilch(); - - if (p instanceof StandardTypeParameter) - addStandardTypeParameterContext(typeParamContexts, p, a); - else if (p instanceof WildcardTypeParameter) - addWildcardTypeParameterContext(typeParamContexts, a); - else if (p instanceof ExtendsTypeParameter) - addExtendsTypeParameterContext(typeParamContexts, p, a); - else { - // must be "? super X" - addSuperTypeParameterContext(random, typeParamContexts, p, a); + val isArray: Boolean + get() = resolved.isArray + val rawClass: Class<*> + get() = resolved.rawClass + val isEnum: Boolean + get() = rawClass.isEnum + val typeParameters: List> + get() = resolved.typeParameters + + fun typeParameterContexts(random: SourceOfRandomness?): List { + val typeParamContexts = mutableListOf() + val typeParameters = typeParameters + val annotatedTypeParameters = Reflection.annotatedComponentTypes(annotatedType()) + for (i in typeParameters.indices) { + val p = typeParameters[i] + val a = if (annotatedTypeParameters.size > i) annotatedTypeParameters[i] else zilch() + when (p) { + is StandardTypeParameter<*> -> addStandardTypeParameterContext(typeParamContexts, p, a) + is WildcardTypeParameter -> addWildcardTypeParameterContext(typeParamContexts, a) + is ExtendsTypeParameter<*> -> addExtendsTypeParameterContext(typeParamContexts, p, a) + else -> { + // must be "? super X" + addSuperTypeParameterContext(random, typeParamContexts, p, a) + } } } - - return typeParamContexts; + return typeParamContexts } - private void addStandardTypeParameterContext( - List typeParameterContexts, - TypeParameter p, - AnnotatedType a) { - + private fun addStandardTypeParameterContext( + typeParameterContexts: MutableList, + p: TypeParameter<*>, + a: AnnotatedType + ) { typeParameterContexts.add( - new ParameterTypeContext( - p.getType().getName(), + ParameterTypeContext( + p.type.name, a, - annotatedType().getType().getTypeName(), - p.getType(), - generics) - .allowMixedTypes(!(a instanceof TypeVariable)) - .annotate(a)); + annotatedType().type.typeName, + p.type, + generics + ).allowMixedTypes(a !is TypeVariable<*>).annotate(a) + ) } - private void addWildcardTypeParameterContext( - List typeParameterContexts, - AnnotatedType a) { - + private fun addWildcardTypeParameterContext( + typeParameterContexts: MutableList, + a: AnnotatedType + ) { typeParameterContexts.add( - new ParameterTypeContext( + ParameterTypeContext( "Zilch", a, - annotatedType().getType().getTypeName(), - Types.forJavaLangReflectType(org.utbot.quickcheck.internal.Zilch.class), - GenericsResolver.resolve(Zilch.class)) - .allowMixedTypes(true) - .annotate(a)); - } - - private void addExtendsTypeParameterContext( - List typeParameterContexts, - TypeParameter p, - AnnotatedType a) { - + annotatedType().type.typeName, + Types.forJavaLangReflectType(Zilch::class.java), + GenericsResolver.resolve(Zilch::class.java) + ).allowMixedTypes(true).annotate(a) + ) + } + + private fun addExtendsTypeParameterContext( + typeParameterContexts: MutableList, + p: TypeParameter<*>, + a: AnnotatedType + ) { typeParameterContexts.add( - new ParameterTypeContext( - p.getType().getName(), - annotatedComponentTypes(a).get(0), - annotatedType().getType().getTypeName(), - p.getType(), - generics) - .allowMixedTypes(false) - .annotate(a)); - } + ParameterTypeContext( + p.type.name, + Reflection.annotatedComponentTypes(a)[0], + annotatedType().type.typeName, + p.type, + generics + ).allowMixedTypes(false).annotate(a) + ) + } + + private fun addSuperTypeParameterContext( + random: SourceOfRandomness?, + typeParameterContexts: MutableList, + p: TypeParameter<*>, + a: AnnotatedType + ) { + val supertypes = Reflection.supertypes(p.type) + val choice = choose(supertypes, random!!) + typeParameterContexts.add( + ParameterTypeContext( + p.type.name, + Reflection.annotatedComponentTypes(a)[0], + annotatedType().type.typeName, + choice, + generics + ).allowMixedTypes(false).annotate(a) + ) + } + + companion object { + @Suppress("unused") + @JvmStatic + private val zilch: Zilch = Zilch + + fun forClass(clazz: Class<*>): ParameterTypeContext { + return ParameterTypeContext( + clazz.typeName, + makeFrom(clazz), + clazz.typeName, + Types.forJavaLangReflectType(clazz), + GenericsResolver.resolve(clazz) + ) + } - private void addSuperTypeParameterContext( - SourceOfRandomness random, - List typeParameterContexts, - TypeParameter p, - AnnotatedType a) { + fun forField(field: Field): ParameterTypeContext { + val generics = GenericsResolver.resolve(field.declaringClass) + return ParameterTypeContext( + field.name, + field.annotatedType, + field.declaringClass.name, + Types.forJavaLangReflectType(generics.resolveFieldType(field)), + generics + ) + } - Set> supertypes = supertypes(p.getType()); - org.javaruntype.type.Type choice = choose(supertypes, random); + fun forParameter(parameter: Parameter): ParameterTypeContext { + val exec = parameter.declaringExecutable + val clazz = exec.declaringClass + val declarerName = clazz.name + '.' + exec.name + val parameterIndex = parameterIndex(exec, parameter) + val generics: GenericsContext + val resolved: Type<*> + when (exec) { + is Method -> { + val methodGenerics = GenericsResolver.resolve(clazz).method(exec) + resolved = Types.forJavaLangReflectType( + methodGenerics.resolveParameterType(parameterIndex) + ) + generics = methodGenerics + } + + is Constructor<*> -> { + val constructorGenerics = GenericsResolver.resolve(clazz).constructor(exec) + resolved = Types.forJavaLangReflectType( + constructorGenerics.resolveParameterType(parameterIndex) + ) + generics = constructorGenerics + } + + else -> { + throw IllegalStateException("Unrecognized subtype of Executable") + } + } + return ParameterTypeContext( + parameter.name, + parameter.annotatedType, + declarerName, + resolved, + generics, + parameterIndex + ) + } - typeParameterContexts.add( - new ParameterTypeContext( - p.getType().getName(), - annotatedComponentTypes(a).get(0), - annotatedType().getType().getTypeName(), - choice, - generics) - .allowMixedTypes(false) - .annotate(a)); - } + fun forParameter( + parameter: Parameter, + generics: MethodGenericsContext + ): ParameterTypeContext { + val exec = parameter.declaringExecutable + val clazz = exec.declaringClass + val declarerName = clazz.name + '.' + exec.name + val parameterIndex = parameterIndex(exec, parameter) + return ParameterTypeContext( + parameter.name, + parameter.annotatedType, + declarerName, + Types.forJavaLangReflectType( + generics.resolveParameterType(parameterIndex) + ), + generics, + parameterIndex + ) + } - private static AnnotatedType zilch() { - try { - return ParameterTypeContext.class.getDeclaredField("zilch") - .getAnnotatedType(); - } catch (NoSuchFieldException e) { - throw new AssertionError(e); + private fun parameterIndex(exec: Executable, parameter: Parameter): Int { + val parameters = exec.parameters + for (i in parameters.indices) { + if (parameters[i] == parameter) return i + } + throw IllegalStateException( + "Cannot find parameter $parameter on $exec" + ) + } + + private fun zilch(): AnnotatedType { + return try { + Companion::class.java.getDeclaredField("zilch").annotatedType + } catch (e: NoSuchFieldException) { + throw AssertionError(e) + } } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Ranges.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Ranges.kt index 355719468e..b32a422368 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Ranges.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Ranges.kt @@ -1,104 +1,80 @@ +package org.utbot.quickcheck.internal +import org.utbot.quickcheck.random.SourceOfRandomness +import java.math.BigInteger -package org.utbot.quickcheck.internal; - -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.math.BigInteger; - -import static java.lang.String.format; - -public final class Ranges { - public enum Type { - CHARACTER("c"), - INTEGRAL("d"), - FLOAT("f"), - STRING("s"); - - private final String pattern; - - Type(String pattern) { - this.pattern = pattern; - } +object Ranges { + enum class Type(val pattern: String) { + CHARACTER("c"), INTEGRAL("d"), FLOAT("f"), STRING("s"); } - private Ranges() { - throw new UnsupportedOperationException(); - } - - public static > - int checkRange(Type type, T min, T max) { - int comparison = min.compareTo(max); - if (comparison > 0) { - throw new IllegalArgumentException( - format( - "bad range, %" + type.pattern + " > %" + type.pattern, - min, - max)); + fun ?> checkRange(type: Type, min: T, max: T): Int { + val comparison = min!!.compareTo(max) + require(comparison <= 0) { + String.format( + "bad range, %" + type.pattern + " > %" + type.pattern, + min, + max + ) } - - return comparison; + return comparison } - public static BigInteger choose( - SourceOfRandomness random, - BigInteger min, - BigInteger max) { - - BigInteger range = max.subtract(min).add(BigInteger.ONE); - BigInteger generated; - + fun choose( + random: SourceOfRandomness, + min: BigInteger?, + max: BigInteger + ): BigInteger { + val range = max.subtract(min).add(BigInteger.ONE) + var generated: BigInteger do { - generated = random.nextBigInteger(range.bitLength()); - } while (generated.compareTo(range) >= 0); - - return generated.add(min); + generated = random.nextBigInteger(range.bitLength()) + } while (generated.compareTo(range) >= 0) + return generated.add(min) } - public static long choose(SourceOfRandomness random, long min, long max) { - checkRange(Type.INTEGRAL, min, max); + fun choose(random: SourceOfRandomness, min: Long, max: Long): Long { + checkRange(Type.INTEGRAL, min, max) /* There are some edges cases with integer overflows, for instance, - when (max - min) exceeds Long.MAX_VALUE. These cases should be - relatively rare under the assumption that choosing - [Long.MIN_VALUE, Long.MAX_VALUE] can be simplified to choosing any - random long. Thus, the optimization here only deals with the common - situation that no overflows are possible (maybe the heuristic to - detect that could be improved). - */ - boolean noOverflowIssues = - max < ((long) 1 << 62) && min > -(((long) 1) << 62); - - if (noOverflowIssues) { + when (max - min) exceeds Long.MAX_VALUE. These cases should be + relatively rare under the assumption that choosing + [Long.MIN_VALUE, Long.MAX_VALUE] can be simplified to choosing any + random long. Thus, the optimization here only deals with the common + situation that no overflows are possible (maybe the heuristic to + detect that could be improved). + */ + val noOverflowIssues = max < 1L shl 62 && min > -(1L shl 62) + return if (noOverflowIssues) { // fast path: use long computations - long range = (max - min) + 1; - long mask = findNextPowerOfTwoLong(range) - 1; + val range = max - min + 1 + val mask = findNextPowerOfTwoLong(range) - 1 // loop to avoid distribution bias (as would be the case // with modulo division) - long generated; + var generated: Long do { - generated = Math.abs(random.nextLong()) & mask; - } while (generated >= range); - - return generated + min; + generated = Math.abs(random.nextLong()) and mask + } while (generated >= range) + generated + min } else { // slow path: fall back to BigInteger to avoid any surprises - return choose( + choose( random, BigInteger.valueOf(min), - BigInteger.valueOf(max)) - .longValue(); + BigInteger.valueOf(max) + ) + .toLong() } } - static long findNextPowerOfTwoLong(long positiveLong) { - return isPowerOfTwoLong(positiveLong) - ? positiveLong - : ((long) 1) << (64 - Long.numberOfLeadingZeros(positiveLong)); + fun findNextPowerOfTwoLong(positiveLong: Long): Long { + return if (isPowerOfTwoLong(positiveLong)) positiveLong else 1L shl 64 - java.lang.Long.numberOfLeadingZeros( + positiveLong + ) } - private static boolean isPowerOfTwoLong(long positiveLong) { - return (positiveLong & (positiveLong - 1)) == 0; + private fun isPowerOfTwoLong(positiveLong: Long): Boolean { + return positiveLong and positiveLong - 1 == 0L } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Reflection.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Reflection.kt index 5c3cd6cfad..b9040cf8b5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Reflection.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Reflection.kt @@ -1,307 +1,274 @@ - - -package org.utbot.quickcheck.internal; - -import org.javaruntype.type.Type; - -import java.lang.annotation.Annotation; -import java.lang.reflect.*; -import java.security.PrivilegedAction; -import java.util.*; - -import static java.lang.reflect.Modifier.isAbstract; -import static java.security.AccessController.doPrivileged; -import static java.util.Arrays.asList; -import static java.util.Arrays.stream; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; -import static java.util.stream.Collectors.toList; - -public final class Reflection { - private static final Map, Class> PRIMITIVES = - new HashMap<>(16); - - static { - PRIMITIVES.put(Boolean.TYPE, Boolean.class); - PRIMITIVES.put(Byte.TYPE, Byte.class); - PRIMITIVES.put(Character.TYPE, Character.class); - PRIMITIVES.put(Double.TYPE, Double.class); - PRIMITIVES.put(Float.TYPE, Float.class); - PRIMITIVES.put(Integer.TYPE, Integer.class); - PRIMITIVES.put(Long.TYPE, Long.class); - PRIMITIVES.put(Short.TYPE, Short.class); - } - - private Reflection() { - throw new UnsupportedOperationException(); +package org.utbot.quickcheck.internal + +import org.javaruntype.type.Type +import java.lang.reflect.AnnotatedArrayType +import java.lang.reflect.AnnotatedElement +import java.lang.reflect.AnnotatedParameterizedType +import java.lang.reflect.AnnotatedType +import java.lang.reflect.AnnotatedWildcardType +import java.lang.reflect.Constructor +import java.lang.reflect.Field +import java.lang.reflect.InvocationTargetException +import java.lang.reflect.Method +import java.lang.reflect.Modifier +import java.security.AccessController +import java.security.PrivilegedAction +import java.util.Arrays +import java.lang.annotation.Annotation as JavaAnnotation + +object Reflection { + private val PRIMITIVES = HashMap, Class<*>>(16) + + init { + PRIMITIVES[java.lang.Boolean.TYPE] = Boolean::class.java + PRIMITIVES[java.lang.Byte.TYPE] = Byte::class.java + PRIMITIVES[Character.TYPE] = Char::class.java + PRIMITIVES[java.lang.Double.TYPE] = Double::class.java + PRIMITIVES[java.lang.Float.TYPE] = Float::class.java + PRIMITIVES[Integer.TYPE] = Int::class.java + PRIMITIVES[java.lang.Long.TYPE] = Long::class.java + PRIMITIVES[java.lang.Short.TYPE] = Short::class.java } - public static Class maybeWrap(Class clazz) { - Class wrapped = PRIMITIVES.get(clazz); - return wrapped == null ? clazz : wrapped; + fun maybeWrap(clazz: Class<*>): Class<*> { + val wrapped = PRIMITIVES[clazz] + return wrapped ?: clazz } - public static Constructor findConstructor( - Class type, - Class... parameterTypes) { - - try { - return type.getConstructor(parameterTypes); - } catch (Exception ex) { - throw reflectionException(ex); + fun findConstructor( + type: Class, + vararg parameterTypes: Class<*>? + ): Constructor { + return try { + type.getConstructor(*parameterTypes) + } catch (ex: Exception) { + throw reflectionException(ex) } } - static Constructor findDeclaredConstructor( - Class type, - Class... parameterTypes) { - - try { - Constructor ctor = type.getDeclaredConstructor(parameterTypes); - ctor.setAccessible(true); - return ctor; - } catch (Exception ex) { - throw reflectionException(ex); + fun findDeclaredConstructor( + type: Class, + vararg parameterTypes: Class<*>? + ): Constructor { + return try { + val ctor = type.getDeclaredConstructor(*parameterTypes) + ctor.isAccessible = true + ctor + } catch (ex: Exception) { + throw reflectionException(ex) } } - @SuppressWarnings("unchecked") - public static Constructor singleAccessibleConstructor( - Class type) { - - Constructor[] constructors = type.getConstructors(); - if (constructors.length != 1) { - throw new org.utbot.quickcheck.internal.ReflectionException( - type + " needs a single accessible constructor"); + fun singleAccessibleConstructor( + type: Class + ): Constructor { + val constructors = type.constructors + if (constructors.size != 1) { + throw ReflectionException( + "$type needs a single accessible constructor" + ) } - - return (Constructor) constructors[0]; + return constructors[0] as Constructor } - - public static T instantiate(Class clazz) { - try { - return clazz.newInstance(); - } catch (Exception ex) { - throw reflectionException(ex); + fun instantiate(clazz: Class): T { + return try { + clazz.newInstance() + } catch (ex: Exception) { + throw reflectionException(ex) } } - public static T instantiate(Constructor ctor, Object... args) { - try { - return ctor.newInstance(args); - } catch (Exception ex) { - throw reflectionException(ex); + fun instantiate(ctor: Constructor, vararg args: Any?): T { + return try { + ctor.newInstance(*args) + } catch (ex: Exception) { + throw reflectionException(ex) } } - public static Set> supertypes(Type bottom) { - Set> supertypes = new HashSet<>(); - supertypes.add(bottom); - supertypes.addAll(bottom.getAllTypesAssignableFromThis()); - return supertypes; + fun supertypes(bottom: Type<*>): Set> { + val supertypes: MutableSet> = HashSet() + supertypes.add(bottom) + supertypes.addAll(bottom.allTypesAssignableFromThis) + return supertypes } - public static Object defaultValueOf( - Class annotationType, - String attribute) { - - try { - return annotationType.getMethod(attribute).getDefaultValue(); - } catch (Exception ex) { - throw reflectionException(ex); + fun defaultValueOf( + annotationType: Class, + attribute: String + ): Any { + return try { + annotationType.getMethod(attribute).defaultValue + } catch (ex: Exception) { + throw reflectionException(ex) } } - public static List allAnnotations(AnnotatedElement e) { - List thisAnnotations = nonSystemAnnotations(e); - - List annotations = new ArrayList<>(); - for (Annotation each : thisAnnotations) { - annotations.add(each); - annotations.addAll(allAnnotations(each.annotationType())); + fun allAnnotations(e: AnnotatedElement): List { + val thisAnnotations = nonSystemAnnotations(e) + val annotations = ArrayList() + for (each in thisAnnotations) { + annotations.add(each) + annotations.addAll(allAnnotations(each.annotationType())) } - - return annotations; + return annotations } - static List allAnnotationsByType( - AnnotatedElement e, - Class type) { - - List annotations = new ArrayList<>(); - Collections.addAll(annotations, e.getAnnotationsByType(type)); - - List thisAnnotations = nonSystemAnnotations(e); - - for (Annotation each : thisAnnotations) { - annotations.addAll( - allAnnotationsByType(each.annotationType(), type)); + fun allAnnotationsByType( + e: AnnotatedElement, + type: Class? + ): List { + val annotations = ArrayList(e.getAnnotationsByType(type).toList()) + val thisAnnotations = nonSystemAnnotations(e) + for (each in thisAnnotations) { + annotations.addAll(allAnnotationsByType(each.annotationType(), type)) } - - return annotations; + return annotations } - public static Method findMethod( - Class target, - String methodName, - Class... argTypes) { - - try { - return target.getMethod(methodName, argTypes); - } catch (Exception ex) { - throw reflectionException(ex); + fun findMethod( + target: Class<*>, + methodName: String, + vararg argTypes: Class<*>? + ): Method { + return try { + target.getMethod(methodName, *argTypes) + } catch (ex: Exception) { + throw reflectionException(ex) } } - public static Object invoke(Method method, Object target, Object... args) { - try { - return method.invoke(target, args); - } catch (Exception ex) { - throw reflectionException(ex); + operator fun invoke(method: Method, target: Any?, vararg args: Any?): Any { + return try { + method.invoke(target, *args) + } catch (ex: Exception) { + throw reflectionException(ex) } } - public static Field findField(Class type, String fieldName) { - try { - return type.getDeclaredField(fieldName); - } catch (NoSuchFieldException ex) { - throw reflectionException(ex); + fun findField(type: Class<*>, fieldName: String): Field { + return try { + type.getDeclaredField(fieldName) + } catch (ex: NoSuchFieldException) { + throw reflectionException(ex) } } - public static List allDeclaredFieldsOf(Class type) { - List allFields = new ArrayList<>(); - - for (Class c = type; c != null; c = c.getSuperclass()) { - Collections.addAll(allFields, c.getDeclaredFields()); + fun allDeclaredFieldsOf(type: Class<*>?): List { + val allFields = ArrayList() + var c = type + while (c != null) { + allFields.addAll(c.declaredFields) + c = c.superclass } - - List results = - allFields.stream() - .filter(f -> !f.isSynthetic()) - .collect(toList()); - results.forEach(f -> f.setAccessible(true)); - - return results; + val results = allFields.filter { !it.isSynthetic } + results.forEach { it.isAccessible = true } + return results } - public static void setField( - Field field, - Object target, - Object value, - boolean suppressProtection) { - - doPrivileged((PrivilegedAction) () -> { - field.setAccessible(suppressProtection); - return null; - }); - + fun setField( + field: Field, + target: Any?, + value: Any?, + suppressProtection: Boolean + ) { + AccessController.doPrivileged(PrivilegedAction { + field.isAccessible = suppressProtection + null + }) try { - field.set(target, value); - } catch (Exception ex) { - throw reflectionException(ex); + field[target] = value + } catch (ex: Exception) { + throw reflectionException(ex) } } - static boolean jdk9OrBetter() { - try { - Runtime.class.getMethod("version"); - return true; - } catch (NoSuchMethodException e) { - return false; + fun jdk9OrBetter(): Boolean { + return try { + Runtime::class.java.getMethod("version") + true + } catch (e: NoSuchMethodException) { + false } } - public static Method singleAbstractMethodOf(Class rawClass) { - if (!rawClass.isInterface()) - return null; - - int abstractCount = 0; - Method singleAbstractMethod = null; - for (Method each : rawClass.getMethods()) { - if (isAbstract(each.getModifiers()) - && !overridesJavaLangObjectMethod(each)) { - - singleAbstractMethod = each; - ++abstractCount; + fun singleAbstractMethodOf(rawClass: Class<*>): Method? { + if (!rawClass.isInterface) return null + var abstractCount = 0 + var singleAbstractMethod: Method? = null + for (each in rawClass.methods) { + if (Modifier.isAbstract(each.modifiers) + && !overridesJavaLangObjectMethod(each) + ) { + singleAbstractMethod = each + ++abstractCount } } - - return abstractCount == 1 ? singleAbstractMethod : null; + return if (abstractCount == 1) singleAbstractMethod else null } - public static boolean isMarkerInterface(Class clazz) { - if (!clazz.isInterface()) - return false; - - return Arrays.stream(clazz.getMethods()) - .filter(m -> !m.isDefault()) - .allMatch(Reflection::overridesJavaLangObjectMethod); + fun isMarkerInterface(clazz: Class<*>): Boolean { + return if (!clazz.isInterface) false else Arrays.stream(clazz.methods) + .filter { m: Method -> !m.isDefault } + .allMatch { method: Method -> overridesJavaLangObjectMethod(method) } } - private static boolean overridesJavaLangObjectMethod(Method method) { - return isEquals(method) || isHashCode(method) || isToString(method); + private fun overridesJavaLangObjectMethod(method: Method): Boolean { + return isEquals(method) || isHashCode(method) || isToString(method) } - private static boolean isEquals(Method method) { - return "equals".equals(method.getName()) - && method.getParameterTypes().length == 1 - && Object.class.equals(method.getParameterTypes()[0]); + private fun isEquals(method: Method): Boolean { + return "equals" == method.name && method.parameterTypes.size == 1 && Any::class.java == method.parameterTypes[0] } - private static boolean isHashCode(Method method) { - return "hashCode".equals(method.getName()) - && method.getParameterTypes().length == 0; + private fun isHashCode(method: Method): Boolean { + return "hashCode" == method.name && method.parameterTypes.size == 0 } - private static boolean isToString(Method method) { - return "toString".equals(method.getName()) - && method.getParameterTypes().length == 0; + private fun isToString(method: Method): Boolean { + return "toString" == method.name && method.parameterTypes.size == 0 } - public static RuntimeException reflectionException(Exception ex) { - if (ex instanceof InvocationTargetException) { - return new org.utbot.quickcheck.internal.ReflectionException( - ((InvocationTargetException) ex).getTargetException()); + fun reflectionException(ex: Exception?): RuntimeException { + if (ex is InvocationTargetException) { + return ReflectionException( + ex.targetException + ) } - if (ex instanceof RuntimeException) - return (RuntimeException) ex; - - return new ReflectionException(ex); + return if (ex is RuntimeException) ex else ReflectionException( + ex!! + ) } - private static List nonSystemAnnotations(AnnotatedElement e) { - return stream(e.getAnnotations()) - .filter(a -> - !a.annotationType().getName().startsWith( - "java.lang.annotation.")) - .filter(a -> !a.annotationType().getName().startsWith("kotlin.")) - .collect(toList()); + private fun nonSystemAnnotations(e: AnnotatedElement): List { + return e.annotations.map { it as JavaAnnotation } + .filter { !it.annotationType().name.startsWith("java.lang.annotation.") } + .filter { !it.annotationType().name.startsWith("kotlin.") } } - public static List annotatedComponentTypes( - AnnotatedType annotatedType) { - - if (annotatedType instanceof AnnotatedParameterizedType) { - return asList( - ((AnnotatedParameterizedType) annotatedType) - .getAnnotatedActualTypeArguments()); + fun annotatedComponentTypes( + annotatedType: AnnotatedType? + ): List { + if (annotatedType is AnnotatedParameterizedType) { + return Arrays.asList( + *annotatedType + .annotatedActualTypeArguments + ) } - if (annotatedType instanceof AnnotatedArrayType) { - return singletonList( - ((AnnotatedArrayType) annotatedType) - .getAnnotatedGenericComponentType()); + if (annotatedType is AnnotatedArrayType) { + return listOf( + annotatedType + .annotatedGenericComponentType + ) } - if (annotatedType instanceof AnnotatedWildcardType) { - AnnotatedWildcardType wildcard = - (AnnotatedWildcardType) annotatedType; - if (wildcard.getAnnotatedLowerBounds().length > 0) - return singletonList(wildcard.getAnnotatedLowerBounds()[0]); - - return asList(wildcard.getAnnotatedUpperBounds()); + if (annotatedType is AnnotatedWildcardType) { + val wildcard = annotatedType + return if (wildcard.annotatedLowerBounds.size > 0) listOf(wildcard.annotatedLowerBounds[0]) else Arrays.asList( + *wildcard.annotatedUpperBounds + ) } - - return emptyList(); + return emptyList() } -} + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ReflectionException.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ReflectionException.kt index 9eea362d3d..9a7e687daf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ReflectionException.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ReflectionException.kt @@ -1,15 +1,6 @@ +package org.utbot.quickcheck.internal - -package org.utbot.quickcheck.internal; - -public class ReflectionException extends RuntimeException { - private static final long serialVersionUID = Long.MIN_VALUE; - - public ReflectionException(String message) { - super(message); - } - - public ReflectionException(Throwable cause) { - super(cause.toString()); - } -} +class ReflectionException : RuntimeException { + constructor(message: String) : super(message) + constructor(cause: Throwable) : super(cause.toString()) +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Weighted.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Weighted.kt index 516f054fe7..1f9e6a2de4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Weighted.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Weighted.kt @@ -1,18 +1,12 @@ +package org.utbot.quickcheck.internal +class Weighted(item: T, weight: Int) { + val item: T + val weight: Int -package org.utbot.quickcheck.internal; - -public final class Weighted { - public final T item; - public final int weight; - - public Weighted(T item, int weight) { - if (weight <= 0) { - throw new IllegalArgumentException( - "non-positive weight: " + weight); - } - - this.item = item; - this.weight = weight; + init { + require(weight > 0) { "non-positive weight: $weight" } + this.item = item + this.weight = weight } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt index f0074cb6e1..845fdaf54f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt @@ -1,11 +1,3 @@ +package org.utbot.quickcheck.internal - -package org.utbot.quickcheck.internal; - -public final class Zilch { - public static final Zilch INSTANCE = new Zilch(); - - private Zilch() { - // nothing to do here - } -} +object Zilch diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt index c3f0d2389f..7ed7ebc341 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt @@ -1,28 +1,18 @@ - - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.internal.GeometricDistribution; -import org.utbot.quickcheck.random.SourceOfRandomness; - -abstract class AbstractGenerationStatus implements GenerationStatus { - private final GeometricDistribution distro; - private final SourceOfRandomness random; - - AbstractGenerationStatus( - GeometricDistribution distro, - SourceOfRandomness random) { - - this.distro = distro; - this.random = random; - } - - @Override public int size() { - return distro.sampleWithMean(attempts() + 1, random); +package org.utbot.quickcheck.internal.generator + +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.internal.GeometricDistribution +import org.utbot.quickcheck.random.SourceOfRandomness + +abstract class AbstractGenerationStatus( + private val distro: GeometricDistribution, + private val random: SourceOfRandomness +) : GenerationStatus { + override fun size(): Int { + return distro.sampleWithMean((attempts() + 1).toDouble(), random) } - protected final SourceOfRandomness random() { - return random; + protected fun random(): SourceOfRandomness { + return random } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt index 6c35b52911..38b140186d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt @@ -1,41 +1,33 @@ - - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.concrete.UtModelConstructor; -import org.utbot.framework.plugin.api.ClassId; -import org.utbot.framework.plugin.api.UtArrayModel; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.util.IdUtilKt; -import org.utbot.quickcheck.generator.*; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.reflect.AnnotatedType; -import java.util.*; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Ranges.Type.INTEGRAL; -import static org.utbot.quickcheck.internal.Ranges.checkRange; -import static org.utbot.quickcheck.internal.Reflection.annotatedComponentTypes; - -public class ArrayGenerator extends Generator { - private final Class componentType; - private final Generator component; - - private Size lengthRange; - private boolean distinct; - - ArrayGenerator(Class componentType, Generator component) { - super(Object.class); - - this.componentType = componentType; - this.component = component; - } - - public Generator getComponent() { - return component; - } +package org.utbot.quickcheck.internal.generator + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtArrayModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.booleanArrayClassId +import org.utbot.framework.plugin.api.util.byteArrayClassId +import org.utbot.framework.plugin.api.util.charArrayClassId +import org.utbot.framework.plugin.api.util.defaultValueModel +import org.utbot.framework.plugin.api.util.doubleArrayClassId +import org.utbot.framework.plugin.api.util.floatArrayClassId +import org.utbot.framework.plugin.api.util.intArrayClassId +import org.utbot.framework.plugin.api.util.longArrayClassId +import org.utbot.framework.plugin.api.util.objectArrayClassId +import org.utbot.framework.plugin.api.util.shortArrayClassId +import org.utbot.quickcheck.generator.Distinct +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.Size +import org.utbot.quickcheck.internal.Ranges +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.lang.reflect.AnnotatedType + +class ArrayGenerator(private val componentType: Class<*>, val component: Generator) : Generator(Any::class.java) { + private var lengthRange: Size? = null + private var distinct = false /** * Tells this generator to produce values with a length within a specified @@ -43,9 +35,9 @@ public class ArrayGenerator extends Generator { * * @param size annotation that gives the length constraints */ - public void configure(Size size) { - this.lengthRange = size; - checkRange(INTEGRAL, size.min(), size.max()); + fun configure(size: Size) { + lengthRange = size + Ranges.checkRange(Ranges.Type.INTEGRAL, size.min, size.max) } /** @@ -55,72 +47,52 @@ public class ArrayGenerator extends Generator { * @param distinct Generated values will be distinct if this param is not * null. */ - public void configure(Distinct distinct) { - this.distinct = distinct != null; + fun configure(distinct: Distinct?) { + this.distinct = distinct != null } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - int length = length(random, status); - final ClassId componentTypeId = classIdForType(componentType); - - final UtModelConstructor modelConstructor = UtModelGenerator.getUtModelConstructor(); - final int modelId = modelConstructor.computeUnusedIdAndUpdate(); - final Map stores = new HashMap<>(); - final UtModel generatedModel = new UtArrayModel( - modelId, getClassIdForArrayType(componentType), length, IdUtilKt.defaultValueModel(componentTypeId), stores - ); - - for (int i = 0; i < length; ++i) { - final UtModel item = component.generate(random, status); - stores.put(i, item); - } - - return generatedModel; + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val length = length(random, status) + val componentTypeId = classIdForType(componentType) + val modelId = utModelConstructor.computeUnusedIdAndUpdate() + return UtArrayModel( + modelId, + getClassIdForArrayType(componentType), + length, + componentTypeId.defaultValueModel(), + (0 until length).associateWithTo(hashMapOf()) { component.generate(random, status) } + ) } - private ClassId getClassIdForArrayType(Class componentType) { - if (int.class.equals(componentType)) { - return new ClassId("[i", classIdForType(int.class)); - } else if (boolean.class.equals(componentType)) { - return new ClassId("[z", classIdForType(boolean.class)); - } else if (byte.class.equals(componentType)) { - return new ClassId("[b", classIdForType(byte.class)); - } else if (char.class.equals(componentType)) { - return new ClassId("[c", classIdForType(char.class)); - } else if (double.class.equals(componentType)) { - return new ClassId("[d", classIdForType(double.class)); - } else if (float.class.equals(componentType)) { - return new ClassId("[f", classIdForType(float.class)); - } else if (long.class.equals(componentType)) { - return new ClassId("[j", classIdForType(long.class)); - } else if (short.class.equals(componentType)) { - return new ClassId("[s", classIdForType(short.class)); - } else { - return new ClassId("[L", classIdForType(componentType)); - } - } - - @Override public void provide(Generators provided) { - super.provide(provided); - component.provide(provided); + private fun getClassIdForArrayType(componentType: Class<*>): ClassId = when (componentType) { + Int::class.javaPrimitiveType -> intArrayClassId + Boolean::class.javaPrimitiveType -> booleanArrayClassId + Byte::class.javaPrimitiveType -> byteArrayClassId + Char::class.javaPrimitiveType -> charArrayClassId + Double::class.javaPrimitiveType -> doubleArrayClassId + Float::class.javaPrimitiveType -> floatArrayClassId + Long::class.javaPrimitiveType -> longArrayClassId + Short::class.javaPrimitiveType -> shortArrayClassId + else -> objectArrayClassId } - @Override public void configure(AnnotatedType annotatedType) { - super.configure(annotatedType); + override fun provide(provided: Generators) { + super.provide(provided) + component.provide(provided) + } - List annotated = annotatedComponentTypes(annotatedType); - if (!annotated.isEmpty()) { - component.configure(annotated.get(0)); + override fun configure(annotatedType: AnnotatedType?) { + super.configure(annotatedType) + val annotated = Reflection.annotatedComponentTypes(annotatedType) + if (annotated.isNotEmpty()) { + component.configure(annotated[0]) } } - private int length(SourceOfRandomness random, GenerationStatus status) { - return lengthRange != null - ? random.nextInt(lengthRange.min(), lengthRange.max()) - : status.size(); + private fun length(random: SourceOfRandomness, status: GenerationStatus): Int { + return if (lengthRange != null) random.nextInt(lengthRange!!.min, lengthRange!!.max) else status.size() } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt index eb9a63531c..f7808b3a6b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt @@ -1,121 +1,101 @@ -package org.utbot.quickcheck.internal.generator; - -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.GeneratorConfigurationException; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.internal.Items; -import org.utbot.quickcheck.internal.Weighted; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.AnnotatedType; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import static java.util.stream.Collectors.toList; - -public class CompositeGenerator extends Generator { - private final List>> composed; - - CompositeGenerator(List>> composed) { - super(Object.class); - - this.composed = new ArrayList<>(composed); +package org.utbot.quickcheck.internal.generator + +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.GeneratorConfigurationException +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.internal.Items +import org.utbot.quickcheck.internal.Weighted +import org.utbot.quickcheck.random.SourceOfRandomness +import java.lang.reflect.AnnotatedElement +import java.lang.reflect.AnnotatedType + +class CompositeGenerator(composed: List>) : Generator(Any::class.java) { + private val composed: MutableList> + + init { + this.composed = ArrayList(composed) } - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - Generator choice = Items.chooseWeighted(composed, random); - return choice.generate(random, status); + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val choice = Items.chooseWeighted(composed, random) + return choice.generate(random, status) } - Generator composed(int index) { - return composed.get(index).item; + fun composed(index: Int): Generator { + return composed[index].item } - int numberOfComposedGenerators() { - return composed.size(); + fun numberOfComposedGenerators(): Int { + return composed.size } - @Override public void provide(Generators provided) { - super.provide(provided); - - for (Weighted> each : composed) - each.item.provide(provided); + override fun provide(provided: Generators) { + super.provide(provided) + for (each in composed) each.item.provide(provided) } - @Override public void configure(AnnotatedType annotatedType) { - List>> candidates = new ArrayList<>(composed); - - for (Iterator>> it = candidates.iterator(); - it.hasNext();) { - + override fun configure(annotatedType: AnnotatedType?) { + val candidates = composed.mapNotNull { try { - it.next().item.configure(annotatedType); - } catch (GeneratorConfigurationException e) { - it.remove(); + it.item.configure(annotatedType) + it + } catch (e: GeneratorConfigurationException) { + null } } - - installCandidates(candidates, annotatedType); + installCandidates(candidates, annotatedType) } - @Override public void configure(AnnotatedElement element) { - List>> candidates = new ArrayList<>(composed); - - for (Iterator>> it = candidates.iterator(); - it.hasNext();) { - + override fun configure(element: AnnotatedElement?) { + val candidates = composed.mapNotNull { try { - it.next().item.configure(element); - } catch (GeneratorConfigurationException e) { - it.remove(); + it.item.configure(element) + it + } catch (e: GeneratorConfigurationException) { + null } } - - installCandidates(candidates, element); + installCandidates(candidates, element) } - @Override public void addComponentGenerators(List> newComponents) { - for (Weighted> each : composed) { - each.item.addComponentGenerators(newComponents); + override fun addComponentGenerators(newComponents: List) { + for (each in composed) { + each.item.addComponentGenerators(newComponents) } } - private void installCandidates( - List>> candidates, - AnnotatedElement element) { - + private fun installCandidates( + candidates: List>, + element: AnnotatedElement? + ) { + if (element == null) return if (candidates.isEmpty()) { - throw new GeneratorConfigurationException( + throw GeneratorConfigurationException( String.format( "None of the candidate generators %s" - + " understands all of the configuration annotations %s", + + " understands all of the configuration annotations %s", candidateGeneratorDescriptions(), - configurationAnnotationNames(element))); + configurationAnnotationNames(element) + ) + ) } - - composed.clear(); - composed.addAll(candidates); + composed.clear() + composed.addAll(candidates) } - private String candidateGeneratorDescriptions() { - return composed.stream() - .map(w -> w.item.getClass().getName()) - .collect(toList()) - .toString(); + private fun candidateGeneratorDescriptions(): String { + return composed.joinToString { it.item.javaClass.name } } - private static List configurationAnnotationNames( - AnnotatedElement element) { - - return configurationAnnotationsOn(element).stream() - .map(a -> a.annotationType().getName()) - .collect(toList()); + companion object { + private fun configurationAnnotationNames( + element: AnnotatedElement + ): List = configurationAnnotationsOn(element) + .map { a -> a.annotationType().name } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt index be7a2640e5..322ddcc2b7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt @@ -1,31 +1,19 @@ - - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; - -public class EnumGenerator extends Generator { - private final Class enumType; - - EnumGenerator(Class enumType) { - super(Enum.class); - - this.enumType = enumType; +package org.utbot.quickcheck.internal.generator + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness + +class EnumGenerator(private val enumType: Class<*>) : Generator(Enum::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val values = enumType.enumConstants + val index = random.nextInt(0, values.size - 1) + return utModelConstructor.construct(values[index], Enum::class.id) } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - Object[] values = enumType.getEnumConstants(); - int index = random.nextInt(0, values.length - 1); - return UtModelGenerator.getUtModelConstructor().construct(values[index], classIdForType(Enum.class)); - } - -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt index c126f2aad3..b03ce61713 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt @@ -1,348 +1,285 @@ - - -package org.utbot.quickcheck.internal.generator; - -import org.javaruntype.type.TypeParameter; -import org.utbot.quickcheck.generator.*; -import org.utbot.quickcheck.internal.ParameterTypeContext; -import org.utbot.quickcheck.internal.Weighted; -import org.utbot.quickcheck.internal.Zilch; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.annotation.Annotation; -import java.lang.reflect.*; -import java.util.*; -import java.util.stream.Stream; - -import static java.util.Collections.unmodifiableSet; -import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toSet; -import static org.utbot.quickcheck.internal.Items.choose; -import static org.utbot.quickcheck.internal.Reflection.*; - -public class GeneratorRepository implements Generators { - private static final Set NULLABLE_ANNOTATIONS = - unmodifiableSet( - Stream.of( - "javax.annotation.Nullable", // JSR-305 - NullAllowed.class.getCanonicalName()) - .collect(toSet())); - - private final SourceOfRandomness random; - - private final Map, Set>> generators; - - public GeneratorRepository(SourceOfRandomness random) { - this(random, new HashMap<>()); - } - - private GeneratorRepository( - SourceOfRandomness random, - Map, Set>> generators) { - - this.random = random; - this.generators = generators; - } - - public Map, Set>> getGenerators() { - return generators; +package org.utbot.quickcheck.internal.generator + +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.NullAllowed +import org.utbot.quickcheck.internal.Items.choose +import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.internal.Weighted +import org.utbot.quickcheck.internal.Zilch +import org.utbot.quickcheck.random.SourceOfRandomness +import java.lang.reflect.AnnotatedElement +import java.lang.reflect.Field +import java.lang.reflect.Parameter +import java.lang.reflect.Type +import java.lang.annotation.Annotation as JavaAnnotation + +open class GeneratorRepository private constructor( + private val random: SourceOfRandomness, + private val generators: MutableMap, MutableSet> +) : Generators { + constructor(random: SourceOfRandomness) : this(random, hashMapOf()) + + fun getGenerators(): Map, MutableSet> { + return generators } - public void addUserClassGenerator(Class forClass, Generator source) { - generators.put(forClass, Set.of(source)); + fun addUserClassGenerator(forClass: Class<*>, source: Generator) { + generators[forClass] = mutableSetOf(source) } - public void removeGenerator(Class forClass) { - generators.remove(forClass); + fun removeGenerator(forClass: Class<*>) { + generators.remove(forClass) } - public void removeGeneratorForObjectClass() { - generators.remove(Object.class); + fun removeGeneratorForObjectClass() { + generators.remove(Any::class.java) } - public GeneratorRepository register(Generator source) { - registerTypes(source); - return this; + fun register(source: Generator): GeneratorRepository { + registerTypes(source) + return this } - public GeneratorRepository register(Iterable> source) { - for (Generator each : source) - registerTypes(each); - - return this; + fun register(source: Iterable): GeneratorRepository { + for (each in source) registerTypes(each) + return this } - private void registerTypes(Generator generator) { - for (Class each : generator.types()) - registerHierarchy(each, generator); + private fun registerTypes(generator: Generator) { + for (each in generator.types()) registerHierarchy(each, generator) } - private void registerHierarchy(Class type, Generator generator) { - maybeRegisterGeneratorForType(type, generator); - - if (type.getSuperclass() != null) - registerHierarchy(type.getSuperclass(), generator); - else if (type.isInterface()) - registerHierarchy(Object.class, generator); - - for (Class each : type.getInterfaces()) - registerHierarchy(each, generator); + private fun registerHierarchy(type: Class<*>, generator: Generator) { + maybeRegisterGeneratorForType(type, generator) + when { + type.superclass != null -> registerHierarchy(type.superclass, generator) + type.isInterface -> registerHierarchy(Any::class.java, generator) + } + for (each in type.interfaces) registerHierarchy(each, generator) } - private void maybeRegisterGeneratorForType( - Class type, - Generator generator) { - - if (generator.canRegisterAsType(type)) - registerGeneratorForType(type, generator); + private fun maybeRegisterGeneratorForType(type: Class<*>, generator: Generator) { + if (generator.canRegisterAsType(type)) { + registerGeneratorForType(type, generator) + } } - private void registerGeneratorForType( - Class type, - Generator generator) { - - Set> forType = - generators.computeIfAbsent(type, k -> new LinkedHashSet<>()); - - forType.add(generator); + private fun registerGeneratorForType(type: Class<*>, generator: Generator) { + val forType = generators.getOrPut(type) { mutableSetOf() } + forType.add(generator) } - @SuppressWarnings("unchecked") - @Override public Generator type( - Class type, - Class... componentTypes) { - - Generator generator = - (Generator) produceGenerator( - ParameterTypeContext.forClass(type)); - generator.addComponentGenerators( - Arrays.stream(componentTypes).map(c -> type(c)).collect(toList())); - return generator; + override fun type(type: Class, vararg componentTypes: Class<*>): Generator { + val generator = produceGenerator( + ParameterTypeContext.forClass(type) + ) + generator.addComponentGenerators(componentTypes.map { type(it) }) + return generator } - @Override public Generator parameter(Parameter parameter) { + override fun parameter(parameter: Parameter): Generator { return produceGenerator( - ParameterTypeContext.forParameter(parameter).annotate(parameter)); + ParameterTypeContext.forParameter(parameter).annotate(parameter) + ) } - @Override public Generator field(Field field) { + override fun field(field: Field): Generator { return produceGenerator( - ParameterTypeContext.forField(field).annotate(field)); + ParameterTypeContext.forField(field).annotate(field) + ) } - @Override public final Generators withRandom(SourceOfRandomness other) { - return new GeneratorRepository(other, this.generators); + override fun withRandom(other: SourceOfRandomness): Generators { + return GeneratorRepository(other, generators) } - public Generator produceGenerator(ParameterTypeContext parameter) { - Generator generator = generatorFor(parameter); - - if (!isPrimitiveType(parameter.annotatedType().getType()) - && hasNullableAnnotation(parameter.annotatedElement())) { - - generator = new NullableGenerator<>(generator); + fun produceGenerator(parameter: ParameterTypeContext): Generator { + var generator = generatorFor(parameter) + if (!isPrimitiveType(parameter.annotatedType().type) + && hasNullableAnnotation(parameter.annotatedElement()) + ) { + generator = NullableGenerator(generator) } - - generator.provide(this); - generator.configure(parameter.annotatedType()); - if (parameter.topLevel()) - generator.configure(parameter.annotatedElement()); - - return generator; + generator.provide(this) + generator.configure(parameter.annotatedType()) + if (parameter.topLevel()) generator.configure(parameter.annotatedElement()) + return generator } - public Generator generatorFor(ParameterTypeContext parameter) { - if (!parameter.explicitGenerators().isEmpty()) - return composeWeighted(parameter, parameter.explicitGenerators()); - if (parameter.isArray()) - return generatorForArrayType(parameter); - if (parameter.isEnum()) - return new EnumGenerator(parameter.getRawClass()); - - return compose(parameter, matchingGenerators(parameter)); + open fun generatorFor(parameter: ParameterTypeContext): Generator { + return when { + parameter.explicitGenerators().isNotEmpty() -> composeWeighted(parameter, parameter.explicitGenerators()) + parameter.isArray -> generatorForArrayType(parameter) + else -> if (parameter.isEnum) { + EnumGenerator(parameter.rawClass) + } else { + compose(parameter, matchingGenerators(parameter)) + } + } } - private Generator generatorForArrayType( - ParameterTypeContext parameter) { - - ParameterTypeContext component = parameter.arrayComponentContext(); - return new ArrayGenerator( - component.getRawClass(), - generatorFor(component)); + private fun generatorForArrayType( + parameter: ParameterTypeContext + ): Generator { + val component = parameter.arrayComponentContext() + return ArrayGenerator(component.rawClass, generatorFor(component)) } - private List> matchingGenerators( - ParameterTypeContext parameter) { - - List> matches = new ArrayList<>(); - + private fun matchingGenerators( + parameter: ParameterTypeContext + ): List { + val matches = mutableListOf() if (!hasGeneratorsFor(parameter)) { - maybeAddGeneratorByNamingConvention(parameter, matches); - maybeAddLambdaGenerator(parameter, matches); - maybeAddMarkerInterfaceGenerator(parameter, matches); + maybeAddGeneratorByNamingConvention(parameter, matches) + maybeAddLambdaGenerator(parameter, matches) + maybeAddMarkerInterfaceGenerator(parameter, matches) } else { - maybeAddGeneratorsFor(parameter, matches); + maybeAddGeneratorsFor(parameter, matches) } - if (matches.isEmpty()) { - throw new IllegalArgumentException( - "Cannot find generator for " + parameter.name() - + " of type " + parameter.type().getTypeName()); + require(matches.isNotEmpty()) { + ("Cannot find generator for " + parameter.name() + + " of type " + parameter.type().typeName) } - - return matches; + return matches } - private void maybeAddGeneratorByNamingConvention( - ParameterTypeContext parameter, - List> matches) { - - Class genClass; - try { - genClass = - Class.forName(parameter.getRawClass().getName() + "Gen"); - } catch (ClassNotFoundException noGenObeyingConvention) { - return; + private fun maybeAddGeneratorByNamingConvention( + parameter: ParameterTypeContext, + matches: MutableList + ) { + val genClass = try { + Class.forName(parameter.rawClass.name + "Gen") + } catch (noGenObeyingConvention: ClassNotFoundException) { + return } - - if (Generator.class.isAssignableFrom(genClass)) { + if (Generator::class.java.isAssignableFrom(genClass)) { try { - Generator generator = (Generator) genClass.newInstance(); - if (generator.types().contains(parameter.getRawClass())) { - matches.add(generator); + val generator = genClass.newInstance() as Generator + if (generator.types().contains(parameter.rawClass)) { + matches += generator } - } catch (IllegalAccessException | InstantiationException e) { - throw new IllegalStateException( - "Cannot instantiate " + genClass.getName() - + " using default constructor"); + } catch (e: IllegalAccessException) { + throw IllegalStateException( + "Cannot instantiate " + genClass.name + + " using default constructor" + ) + } catch (e: InstantiationException) { + throw IllegalStateException( + "Cannot instantiate " + genClass.name + + " using default constructor" + ) } } } - private void maybeAddLambdaGenerator( - ParameterTypeContext parameter, - List> matches) { - - Method method = singleAbstractMethodOf(parameter.getRawClass()); + private fun maybeAddLambdaGenerator( + parameter: ParameterTypeContext, + matches: MutableList + ) { + val method = Reflection.singleAbstractMethodOf(parameter.rawClass) if (method != null) { - ParameterTypeContext returnType = - parameter.methodReturnTypeContext(method); - Generator returnTypeGenerator = generatorFor(returnType); - - matches.add( - new LambdaGenerator<>( - parameter.getRawClass(), - returnTypeGenerator)); + val returnType = parameter.methodReturnTypeContext(method) + val returnTypeGenerator = generatorFor(returnType) + matches += LambdaGenerator(parameter.rawClass, returnTypeGenerator) } } - private void maybeAddMarkerInterfaceGenerator( - ParameterTypeContext parameter, - List> matches) { - - Class rawClass = parameter.getRawClass(); - if (isMarkerInterface(rawClass)) { - matches.add( - new MarkerInterfaceGenerator<>(parameter.getRawClass())); + private fun maybeAddMarkerInterfaceGenerator( + parameter: ParameterTypeContext, + matches: MutableList + ) { + val rawClass = parameter.rawClass + if (Reflection.isMarkerInterface(rawClass)) { + matches += MarkerInterfaceGenerator(parameter.rawClass) } } - private void maybeAddGeneratorsFor( - ParameterTypeContext parameter, - List> matches) { - - List> candidates = generatorsFor(parameter); - List> typeParameters = parameter.getTypeParameters(); - + private fun maybeAddGeneratorsFor( + parameter: ParameterTypeContext, + matches: MutableList + ) { + val candidates = generatorsFor(parameter) + val typeParameters = parameter.typeParameters if (typeParameters.isEmpty()) { - matches.addAll(candidates); + matches.addAll(candidates) } else { - for (Generator each : candidates) { - if (each.canGenerateForParametersOfTypes(typeParameters)) - matches.add(each); + for (each in candidates) { + if (each.canGenerateForParametersOfTypes(typeParameters)) matches.add(each) } } } - private Generator compose( - ParameterTypeContext parameter, - List> matches) { - - List>> weightings = - matches.stream() - .map(g -> new Weighted>(g, 1)) - .collect(toList()); - - return composeWeighted(parameter, weightings); + private fun compose( + parameter: ParameterTypeContext, + matches: List + ): Generator { + val weightings = matches.map { Weighted(it, 1) } + return composeWeighted(parameter, weightings) } - private Generator composeWeighted( - ParameterTypeContext parameter, - List>> matches) { - - List> forComponents = new ArrayList<>(); - for (ParameterTypeContext c : parameter.typeParameterContexts(random)) - forComponents.add(generatorFor(c)); - - for (Weighted> each : matches) - applyComponentGenerators(each.item, forComponents); - - return matches.size() == 1 - ? matches.get(0).item - : new CompositeGenerator(matches); + private fun composeWeighted( + parameter: ParameterTypeContext, + matches: List> + ): Generator { + val forComponents = mutableListOf() + for (c in parameter.typeParameterContexts(random)) forComponents.add(generatorFor(c)) + for (each in matches) applyComponentGenerators(each.item, forComponents) + return if (matches.size == 1) matches[0].item else CompositeGenerator(matches) } - private void applyComponentGenerators( - Generator generator, - List> componentGenerators) { - - if (!generator.hasComponents()) - return; - + private fun applyComponentGenerators( + generator: Generator, + componentGenerators: List + ) { + if (!generator.hasComponents()) return if (componentGenerators.isEmpty()) { - List> substitutes = new ArrayList<>(); - Generator zilch = - generatorFor( - ParameterTypeContext.forClass(Zilch.class) - .allowMixedTypes(true)); - for (int i = 0; i < generator.numberOfNeededComponents(); ++i) { - substitutes.add(zilch); + val substitutes = mutableListOf() + val zilch = generatorFor( + ParameterTypeContext.forClass(Zilch::class.java) + .allowMixedTypes(true) + ) + for (i in 0 until generator.numberOfNeededComponents()) { + substitutes.add(zilch) } - - generator.addComponentGenerators(substitutes); + generator.addComponentGenerators(substitutes) } else { - generator.addComponentGenerators(componentGenerators); + generator.addComponentGenerators(componentGenerators) } } - private List> generatorsFor(ParameterTypeContext parameter) { - Set> matches = generators.get(parameter.getRawClass()); - + private fun generatorsFor(parameter: ParameterTypeContext): List { + var matches = generators[parameter.rawClass] + ?: error("No generator for type: ${parameter.rawClass}") if (!parameter.allowMixedTypes()) { - Generator match = choose(matches, random); - matches = new HashSet<>(); - matches.add(match); + val match = choose(matches, random) + matches = mutableSetOf(match) } - - List> copies = new ArrayList<>(); - for (Generator each : matches) { - copies.add(each.copy()); - } - return copies; + return matches.map { it.copy() } } - private boolean hasGeneratorsFor(ParameterTypeContext parameter) { - return generators.get(parameter.getRawClass()) != null; + private fun hasGeneratorsFor(parameter: ParameterTypeContext): Boolean { + return generators[parameter.rawClass] != null } - private static boolean isPrimitiveType(Type type) { - return type instanceof Class && ((Class) type).isPrimitive(); - } + companion object { + private val NULLABLE_ANNOTATIONS = setOf( + "javax.annotation.Nullable", // JSR-305 + NullAllowed::class.java.canonicalName + ) + - private static boolean hasNullableAnnotation(AnnotatedElement element) { - return element != null - && Arrays.stream(element.getAnnotations()) - .map(Annotation::annotationType) - .map(Class::getCanonicalName) - .anyMatch(NULLABLE_ANNOTATIONS::contains); + private fun isPrimitiveType(type: Type): Boolean { + return type is Class<*> && type.isPrimitive + } + + private fun hasNullableAnnotation(element: AnnotatedElement?): Boolean { + if (element == null) return false + return element.annotations.map { it as JavaAnnotation } + .map { it.annotationType() } + .map { it.canonicalName } + .any { NULLABLE_ANNOTATIONS.contains(it) } + } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt index 786af00211..68d87c8b79 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt @@ -1,30 +1,22 @@ - - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtNullModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; - -public class LambdaGenerator extends Generator { - private final Class lambdaType; - private final Generator returnValueGenerator; - - LambdaGenerator(Class lambdaType, Generator returnValueGenerator) { - super(lambdaType); - - this.lambdaType = lambdaType; - this.returnValueGenerator = returnValueGenerator; - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return new UtNullModel(classIdForType(Object.class));//makeLambda(lambdaType, returnValueGenerator, status); +package org.utbot.quickcheck.internal.generator + +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.objectClassId +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.random.SourceOfRandomness + +class LambdaGenerator internal constructor( + private val lambdaType: Class, + private val returnValueGenerator: Generator +) : Generator( + lambdaType +) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return UtNullModel(objectClassId) //makeLambda(lambdaType, returnValueGenerator, status); } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt index 170a1dbfe1..3aa867bd97 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt @@ -1,95 +1,60 @@ - - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.internal.DefaultMethodHandleMaker; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import java.lang.invoke.MethodHandle; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -import static java.lang.System.identityHashCode; -import static java.lang.reflect.Proxy.newProxyInstance; -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; - -public class MarkerInterfaceGenerator extends Generator { - private final Class markerType; - - MarkerInterfaceGenerator(Class markerType) { - super(markerType); - - this.markerType = markerType; - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - return UtModelGenerator.getUtModelConstructor().construct(markerType.cast( - newProxyInstance( - markerType.getClassLoader(), - new Class[] { markerType }, - new MarkerInvocationHandler<>(markerType))), classIdForType(markerType)); -// return markerType.cast( -// newProxyInstance( -// markerType.getClassLoader(), -// new Class[] { markerType }, -// new MarkerInvocationHandler<>(markerType))); +package org.utbot.quickcheck.internal.generator + +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.internal.DefaultMethodHandleMaker +import org.utbot.quickcheck.random.SourceOfRandomness +import java.lang.reflect.InvocationHandler +import java.lang.reflect.Method +import java.lang.reflect.Proxy + +class MarkerInterfaceGenerator(private val markerType: Class<*>) : Generator(markerType) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct( + markerType.cast( + Proxy.newProxyInstance( + markerType.classLoader, arrayOf(markerType), + MarkerInvocationHandler(markerType) + ) + ), + classIdForType(markerType) + ) } - private static class MarkerInvocationHandler - implements InvocationHandler { - - private final Class markerType; - private final DefaultMethodHandleMaker methodHandleMaker = - new DefaultMethodHandleMaker(); + private class MarkerInvocationHandler(private val markerType: Class<*>) : InvocationHandler { + private val methodHandleMaker = DefaultMethodHandleMaker() - MarkerInvocationHandler(Class markerType) { - this.markerType = markerType; + override fun invoke(proxy: Any, method: Method, args: Array): Any? { + if (Any::class.java == method.declaringClass) return handleObjectMethod(proxy, method, args) + return if (method.isDefault) handleDefaultMethod(proxy, method, args) else null } - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - - if (Object.class.equals(method.getDeclaringClass())) - return handleObjectMethod(proxy, method, args); - if (method.isDefault()) - return handleDefaultMethod(proxy, method, args); - - return null; + private fun handleObjectMethod( + proxy: Any, + method: Method, + args: Array + ): Any { + if ("equals" == method.name) return proxy === args[0] + return if ("hashCode" == method.name) System.identityHashCode(proxy) else handleToString() } - private Object handleObjectMethod( - Object proxy, - Method method, - Object[] args) { - - if ("equals".equals(method.getName())) - return proxy == args[0]; - if ("hashCode".equals(method.getName())) - return identityHashCode(proxy); - - return handleToString(); - } - - private Object handleDefaultMethod( - Object proxy, - Method method, - Object[] args) - throws Throwable { - - MethodHandle handle = - methodHandleMaker.handleForSpecialMethod(method); - return handle.bindTo(proxy).invokeWithArguments(args); + private fun handleDefaultMethod( + proxy: Any, + method: Method, + args: Array + ): Any { + val handle = methodHandleMaker.handleForSpecialMethod(method) + return handle.bindTo(proxy).invokeWithArguments(*args) } - private String handleToString() { - return "a synthetic instance of " + markerType; + private fun handleToString(): String { + return "a synthetic instance of $markerType" } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt index cf64173427..844c5a2271 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt @@ -1,88 +1,75 @@ - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.framework.plugin.api.UtNullModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.generator.Generators; -import org.utbot.quickcheck.generator.NullAllowed; -import org.utbot.quickcheck.random.SourceOfRandomness; -import org.javaruntype.type.TypeParameter; - -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.AnnotatedType; -import java.util.List; -import java.util.Optional; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; -import static org.utbot.quickcheck.internal.Reflection.defaultValueOf; - -class NullableGenerator extends Generator { - private final Generator delegate; - private double probabilityOfNull = - (Double) defaultValueOf(NullAllowed.class, "probability"); - - NullableGenerator(Generator delegate) { - super(delegate.types()); - - this.delegate = delegate; - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return random.nextFloat(0, 1) < probabilityOfNull - ? new UtNullModel(classIdForType(types().get(0))) - : delegate.generate(random, status); +package org.utbot.quickcheck.internal.generator + +import org.javaruntype.type.TypeParameter +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.NullAllowed +import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness +import java.lang.reflect.AnnotatedElement +import java.lang.reflect.AnnotatedType +import java.util.Optional + +internal class NullableGenerator(private val delegate: Generator) : Generator(delegate.types()) { + private var probabilityOfNull = Reflection.defaultValueOf(NullAllowed::class.java, "probability") as Double + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return if (random.nextFloat(0f, 1f) < probabilityOfNull) { + UtNullModel(classIdForType(types()[0])) + } else { + delegate.generate(random, status) + } } - @Override public boolean canRegisterAsType(Class type) { - return delegate.canRegisterAsType(type); + override fun canRegisterAsType(type: Class<*>): Boolean { + return delegate.canRegisterAsType(type) } - @Override public boolean hasComponents() { - return delegate.hasComponents(); + override fun hasComponents(): Boolean { + return delegate.hasComponents() } - @Override public int numberOfNeededComponents() { - return delegate.numberOfNeededComponents(); + override fun numberOfNeededComponents(): Int { + return delegate.numberOfNeededComponents() } - @Override public void addComponentGenerators( - List> newComponents) { - - delegate.addComponentGenerators(newComponents); + override fun addComponentGenerators( + newComponents: List + ) { + delegate.addComponentGenerators(newComponents) } - @Override public boolean canGenerateForParametersOfTypes( - List> typeParameters) { - - return delegate.canGenerateForParametersOfTypes(typeParameters); + override fun canGenerateForParametersOfTypes(typeParameters: List>): Boolean { + return delegate.canGenerateForParametersOfTypes(typeParameters) } - @Override public void configure(AnnotatedType annotatedType) { - Optional.ofNullable(annotatedType.getAnnotation(NullAllowed.class)) - .ifPresent(this::configure); - - delegate.configure(annotatedType); + override fun configure(annotatedType: AnnotatedType?) { + Optional.ofNullable(annotatedType!!.getAnnotation(NullAllowed::class.java)) + .ifPresent { allowed: NullAllowed -> this.configure(allowed) } + delegate.configure(annotatedType) } - @Override public void configure(AnnotatedElement element) { - delegate.configure(element); + override fun configure(element: AnnotatedElement?) { + delegate.configure(element) } - @Override public void provide(Generators provided) { - delegate.provide(provided); + override fun provide(provided: Generators) { + delegate.provide(provided) } - private void configure(NullAllowed allowed) { - if (allowed.probability() >= 0 && allowed.probability() <= 1) { - this.probabilityOfNull = allowed.probability(); + private fun configure(allowed: NullAllowed) { + if (allowed.probability >= 0 && allowed.probability <= 1) { + probabilityOfNull = allowed.probability } else { - throw new IllegalArgumentException( - "NullAllowed probability must be in the range [0, 1]"); + throw IllegalArgumentException( + "NullAllowed probability must be in the range [0, 1]" + ) } } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt index 74ab5a2e0e..765b00ef1f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt @@ -1,23 +1,14 @@ - - -package org.utbot.quickcheck.internal.generator; - -import org.utbot.quickcheck.internal.GeometricDistribution; -import org.utbot.quickcheck.random.SourceOfRandomness; - -public class SimpleGenerationStatus extends org.utbot.quickcheck.internal.generator.AbstractGenerationStatus { - private final int attempts; - - public SimpleGenerationStatus( - GeometricDistribution distro, - SourceOfRandomness random, - int attempts) { - - super(distro, random); - this.attempts = attempts; - } - - @Override public int attempts() { - return attempts; +package org.utbot.quickcheck.internal.generator + +import org.utbot.quickcheck.internal.GeometricDistribution +import org.utbot.quickcheck.random.SourceOfRandomness + +class SimpleGenerationStatus( + distro: GeometricDistribution, + random: SourceOfRandomness, + private val attempts: Int +) : AbstractGenerationStatus(distro, random) { + override fun attempts(): Int { + return attempts } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt index a42a5d6d28..be41083f09 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt @@ -1,25 +1,18 @@ +package org.utbot.quickcheck.internal.generator +import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.internal.Zilch +import org.utbot.quickcheck.random.SourceOfRandomness -package org.utbot.quickcheck.internal.generator; - -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator; -import org.utbot.framework.plugin.api.UtModel; -import org.utbot.quickcheck.generator.GenerationStatus; -import org.utbot.quickcheck.generator.Generator; -import org.utbot.quickcheck.internal.Zilch; -import org.utbot.quickcheck.random.SourceOfRandomness; - -import static org.utbot.external.api.UtModelFactoryKt.classIdForType; - -public class ZilchGenerator extends Generator { - public ZilchGenerator() { - super(Zilch.class); - } - - @Override public UtModel generate( - SourceOfRandomness random, - GenerationStatus status) { - - return UtModelGenerator.getUtModelConstructor().construct(Zilch.INSTANCE, classIdForType(Zilch.class)); +class ZilchGenerator : Generator(Zilch::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return utModelConstructor.construct(Zilch, classIdForType(Zilch::class.java)) } -} +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt index dbab5da57c..edaa8a87ee 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt @@ -1,32 +1,26 @@ - - -package org.utbot.quickcheck.random; - -import org.utbot.quickcheck.internal.Items; -import org.utbot.quickcheck.internal.Ranges; - -import java.io.*; -import java.math.BigInteger; -import java.time.Duration; -import java.time.Instant; -import java.util.Collection; -import java.util.Random; - -import static org.utbot.quickcheck.internal.Ranges.checkRange; -import static java.util.concurrent.TimeUnit.SECONDS; +package org.utbot.quickcheck.random + +import org.utbot.quickcheck.internal.Items +import org.utbot.quickcheck.internal.Ranges +import java.io.ByteArrayInputStream +import java.io.ByteArrayOutputStream +import java.io.IOException +import java.io.ObjectInputStream +import java.io.ObjectOutputStream +import java.math.BigInteger +import java.time.Duration +import java.time.Instant +import java.util.Random +import java.util.concurrent.TimeUnit /** * A source of randomness, fed to - * {@linkplain org.utbot.quickcheck.generator.Generator generators} + * [generators][org.utbot.quickcheck.generator.Generator] * so they can produce random values for property parameters. */ -public class SourceOfRandomness { - private static final BigInteger NANOS_PER_SECOND = - BigInteger.valueOf(SECONDS.toNanos(1)); - - private final Random delegate; - - private long seed; +class SourceOfRandomness(delegate: Random) { + private val delegate: Random + private var seed: Long /** * Makes a new source of randomness. @@ -34,54 +28,50 @@ public class SourceOfRandomness { * @param delegate a JDK source of randomness, to which the new instance * will delegate */ - - public SourceOfRandomness(Random delegate) { - seed = delegate.nextLong(); - this.delegate = delegate; - delegate.setSeed(seed); + init { + seed = delegate.nextLong() + this.delegate = delegate + delegate.setSeed(seed) } /** - *

Gives a JDK source of randomness, with the same internal state as - * this source of randomness.

+ * + * Gives a JDK source of randomness, with the same internal state as + * this source of randomness. * * @return a JDK "clone" of self */ - public Random toJDKRandom() { - ByteArrayOutputStream bytesOut = new ByteArrayOutputStream(); - - try (ObjectOutputStream objectOut = new ObjectOutputStream(bytesOut)) { - objectOut.writeObject(delegate); - } catch (IOException ex) { - throw new IllegalStateException(ex); + fun toJDKRandom(): Random { + val bytesOut = ByteArrayOutputStream() + try { + ObjectOutputStream(bytesOut).use { objectOut -> objectOut.writeObject(delegate) } + } catch (ex: IOException) { + throw IllegalStateException(ex) } - - ByteArrayInputStream bytesIn = - new ByteArrayInputStream(bytesOut.toByteArray()); - - try (ObjectInputStream objectIn = new ObjectInputStream(bytesIn)) { - return (Random) objectIn.readObject(); - } catch (IOException ex) { - throw new IllegalStateException(ex); - } catch (ClassNotFoundException shouldNeverHappen) { - throw new AssertionError(shouldNeverHappen); + val bytesIn = ByteArrayInputStream(bytesOut.toByteArray()) + try { + ObjectInputStream(bytesIn).use { objectIn -> return objectIn.readObject() as Random } + } catch (ex: IOException) { + throw IllegalStateException(ex) + } catch (shouldNeverHappen: ClassNotFoundException) { + throw AssertionError(shouldNeverHappen) } } /** * @return a uniformly distributed boolean value - * @see Random#nextBoolean() + * @see Random.nextBoolean */ - public boolean nextBoolean() { - return delegate.nextBoolean(); + fun nextBoolean(): Boolean { + return delegate.nextBoolean() } /** * @param bytes a byte array to fill with random values - * @see Random#nextBytes(byte[]) + * @see Random.nextBytes */ - public void nextBytes(byte[] bytes) { - delegate.nextBytes(bytes); + fun nextBytes(bytes: ByteArray?) { + delegate.nextBytes(bytes) } /** @@ -89,238 +79,232 @@ public class SourceOfRandomness { * * @param count the desired length of the random byte array * @return random bytes - * @see Random#nextBytes(byte[]) + * @see Random.nextBytes */ - public byte[] nextBytes(int count) { - byte[] buffer = new byte[count]; - delegate.nextBytes(buffer); - return buffer; + fun nextBytes(count: Int): ByteArray { + val buffer = ByteArray(count) + delegate.nextBytes(buffer) + return buffer } /** - * @return a uniformly distributed random {@code double} value in the - * interval {@code [0.0, 1.0)} - * @see Random#nextDouble() + * @return a uniformly distributed random `double` value in the + * interval `[0.0, 1.0)` + * @see Random.nextDouble */ - public double nextDouble() { - return delegate.nextDouble(); + fun nextDouble(): Double { + return delegate.nextDouble() } /** - * @return a uniformly distributed random {@code float} value in the - * interval {@code [0.0, 1.0)} - * @see Random#nextFloat() + * @return a uniformly distributed random `float` value in the + * interval `[0.0, 1.0)` + * @see Random.nextFloat */ - public float nextFloat() { - return delegate.nextFloat(); + fun nextFloat(): Float { + return delegate.nextFloat() } /** * @return a Gaussian-distributed random double value - * @see Random#nextGaussian() + * @see Random.nextGaussian */ - public double nextGaussian() { - return delegate.nextGaussian(); + fun nextGaussian(): Double { + return delegate.nextGaussian() } /** - * @return a uniformly distributed random {@code int} value - * @see Random#nextInt() + * @return a uniformly distributed random `int` value + * @see Random.nextInt */ - public int nextInt() { - return delegate.nextInt(); + fun nextInt(): Int { + return delegate.nextInt() } /** * @param n upper bound - * @return a uniformly distributed random {@code int} value in the interval - * {@code [0, n)} - * @see Random#nextInt(int) + * @return a uniformly distributed random `int` value in the interval + * `[0, n)` + * @see Random.nextInt */ - public int nextInt(int n) { - return delegate.nextInt(n); + fun nextInt(n: Int): Int { + return delegate.nextInt(n) } /** - * @return a uniformly distributed random {@code long} value - * @see Random#nextLong() + * @return a uniformly distributed random `long` value + * @see Random.nextLong */ - public long nextLong() { - return delegate.nextLong(); + fun nextLong(): Long { + return delegate.nextLong() } /** * @param seed value with which to seed this source of randomness - * @see Random#setSeed(long) + * @see Random.setSeed */ - public void setSeed(long seed) { - this.seed = seed; - delegate.setSeed(seed); + fun setSeed(seed: Long) { + this.seed = seed + delegate.setSeed(seed) } /** * @return the value used to initially seed this source of randomness */ - public long seed() { - return seed; + fun seed(): Long { + return seed } /** - * Gives a random {@code byte} value, uniformly distributed across the - * interval {@code [min, max]}. + * Gives a random `byte` value, uniformly distributed across the + * interval `[min, max]`. * * @param min lower bound of the desired interval * @param max upper bound of the desired interval * @return a random value */ - public byte nextByte(byte min, byte max) { - return (byte) nextLong(min, max); + fun nextByte(min: Byte, max: Byte): Byte { + return nextLong(min.toLong(), max.toLong()).toByte() } /** - * Gives a random {@code char} value, uniformly distributed across the - * interval {@code [min, max]}. + * Gives a random `char` value, uniformly distributed across the + * interval `[min, max]`. * * @param min lower bound of the desired interval * @param max upper bound of the desired interval * @return a random value */ - public char nextChar(char min, char max) { - checkRange(Ranges.Type.CHARACTER, min, max); - - return (char) nextLong(min, max); + fun nextChar(min: Char, max: Char): Char { + Ranges.checkRange(Ranges.Type.CHARACTER, min, max) + return Char(nextLong(min.code.toLong(), max.code.toLong()).toUShort()) } /** - *

Gives a random {@code double} value in the interval - * {@code [min, max)}.

* - *

This naive implementation takes a random {@code double} value from - * {@link Random#nextDouble()} and scales/shifts the value into the desired - * interval. This may give surprising results for large ranges.

+ * Gives a random `double` value in the interval + * `[min, max)`. + * + * + * This naive implementation takes a random `double` value from + * [Random.nextDouble] and scales/shifts the value into the desired + * interval. This may give surprising results for large ranges. * * @param min lower bound of the desired interval * @param max upper bound of the desired interval * @return a random value */ - public double nextDouble(double min, double max) { - int comparison = checkRange(Ranges.Type.FLOAT, min, max); - return comparison == 0 ? min : min + (max - min) * nextDouble(); + fun nextDouble(min: Double, max: Double): Double { + val comparison = Ranges.checkRange(Ranges.Type.FLOAT, min, max) + return if (comparison == 0) min else min + (max - min) * nextDouble() } /** - *

Gives a random {@code float} value in the interval - * {@code [min, max)}.

* - *

This naive implementation takes a random {@code float} value from - * {@link Random#nextFloat()} and scales/shifts the value into the desired - * interval. This may give surprising results for large ranges.

+ * Gives a random `float` value in the interval + * `[min, max)`. + * + * + * This naive implementation takes a random `float` value from + * [Random.nextFloat] and scales/shifts the value into the desired + * interval. This may give surprising results for large ranges. * * @param min lower bound of the desired interval * @param max upper bound of the desired interval * @return a random value */ - public float nextFloat(float min, float max) { - int comparison = checkRange(Ranges.Type.FLOAT, min, max); - return comparison == 0 ? min : min + (max - min) * nextFloat(); + fun nextFloat(min: Float, max: Float): Float { + val comparison = Ranges.checkRange(Ranges.Type.FLOAT, min, max) + return if (comparison == 0) min else min + (max - min) * nextFloat() } /** - * Gives a random {@code int} value, uniformly distributed across the - * interval {@code [min, max]}. + * Gives a random `int` value, uniformly distributed across the + * interval `[min, max]`. * * @param min lower bound of the desired interval * @param max upper bound of the desired interval * @return a random value */ - public int nextInt(int min, int max) { - return (int) nextLong(min, max); + fun nextInt(min: Int, max: Int): Int { + return nextLong(min.toLong(), max.toLong()).toInt() } /** - * Gives a random {@code long} value, uniformly distributed across the - * interval {@code [min, max]}. + * Gives a random `long` value, uniformly distributed across the + * interval `[min, max]`. * * @param min lower bound of the desired interval * @param max upper bound of the desired interval * @return a random value */ - public long nextLong(long min, long max) { - int comparison = checkRange(Ranges.Type.INTEGRAL, min, max); - if (comparison == 0) - return min; - - return Ranges.choose(this, min, max); + fun nextLong(min: Long, max: Long): Long { + val comparison = Ranges.checkRange(Ranges.Type.INTEGRAL, min, max) + return if (comparison == 0) min else Ranges.choose(this, min, max) } /** - * Gives a random {@code short} value, uniformly distributed across the - * interval {@code [min, max]}. + * Gives a random `short` value, uniformly distributed across the + * interval `[min, max]`. * * @param min lower bound of the desired interval * @param max upper bound of the desired interval * @return a random value */ - public short nextShort(short min, short max) { - return (short) nextLong(min, max); + fun nextShort(min: Short, max: Short): Short { + return nextLong(min.toLong(), max.toLong()).toShort() } /** - * Gives a random {@code BigInteger} representable by the given number + * Gives a random `BigInteger` representable by the given number * of bits. * * @param numberOfBits the desired number of bits - * @return a random {@code BigInteger} - * @see BigInteger#BigInteger(int, Random) + * @return a random `BigInteger` + * @see BigInteger.BigInteger */ - public BigInteger nextBigInteger(int numberOfBits) { - return new BigInteger(numberOfBits, delegate); + fun nextBigInteger(numberOfBits: Int): BigInteger { + return BigInteger(numberOfBits, delegate) } /** - * Gives a random {@code Instant} value, uniformly distributed across the - * interval {@code [min, max]}. + * Gives a random `Instant` value, uniformly distributed across the + * interval `[min, max]`. * * @param min lower bound of the desired interval * @param max upper bound of the desired interval * @return a random value */ - public Instant nextInstant(Instant min, Instant max) { - int comparison = checkRange(Ranges.Type.STRING, min, max); - if (comparison == 0) - return min; - - long[] next = - nextSecondsAndNanos( - min.getEpochSecond(), - min.getNano(), - max.getEpochSecond(), - max.getNano()); - - return Instant.ofEpochSecond(next[0], next[1]); + fun nextInstant(min: Instant, max: Instant): Instant { + val comparison = Ranges.checkRange(Ranges.Type.STRING, min, max) + if (comparison == 0) return min + val next = nextSecondsAndNanos( + min.epochSecond, + min.nano.toLong(), + max.epochSecond, + max.nano.toLong() + ) + return Instant.ofEpochSecond(next[0], next[1]) } /** - * Gives a random {@code Duration} value, uniformly distributed across the - * interval {@code [min, max]}. + * Gives a random `Duration` value, uniformly distributed across the + * interval `[min, max]`. * * @param min lower bound of the desired interval * @param max upper bound of the desired interval * @return a random value */ - public Duration nextDuration(Duration min, Duration max) { - int comparison = checkRange(Ranges.Type.STRING, min, max); - if (comparison == 0) - return min; - - long[] next = - nextSecondsAndNanos( - min.getSeconds(), - min.getNano(), - max.getSeconds(), - max.getNano()); - - return Duration.ofSeconds(next[0], next[1]); + fun nextDuration(min: Duration, max: Duration): Duration { + val comparison = Ranges.checkRange(Ranges.Type.STRING, min, max) + if (comparison == 0) return min + val next = nextSecondsAndNanos( + min.seconds, + min.nano.toLong(), + max.seconds, + max.nano.toLong() + ) + return Duration.ofSeconds(next[0], next[1]) } /** @@ -329,9 +313,9 @@ public class SourceOfRandomness { * @param type of items in the collection * @param items a collection * @return a randomly chosen element from the collection - */ - public T choose(Collection items) { - return Items.choose(items, this); + */ + fun choose(items: Collection): T { + return Items.choose(items, this) } /** @@ -340,9 +324,9 @@ public class SourceOfRandomness { * @param type of items in the array * @param items an array * @return a randomly chosen element from the array - */ - public T choose(T[] items) { - return items[nextInt(items.length)]; + */ + fun choose(items: Array): T { + return items[nextInt(items.size)] } /** @@ -351,29 +335,28 @@ public class SourceOfRandomness { * * @return the JDK-random delegate */ - protected final Random delegate() { - return delegate; + protected fun delegate(): Random { + return delegate } - private long[] nextSecondsAndNanos( - long minSeconds, - long minNanos, - long maxSeconds, - long maxNanos) { - - BigInteger nanoMin = - BigInteger.valueOf(minSeconds) - .multiply(NANOS_PER_SECOND) - .add(BigInteger.valueOf(minNanos)); - BigInteger nanoMax = - BigInteger.valueOf(maxSeconds) - .multiply(NANOS_PER_SECOND) - .add(BigInteger.valueOf(maxNanos)); - - BigInteger[] generated = - Ranges.choose(this, nanoMin, nanoMax) - .divideAndRemainder(NANOS_PER_SECOND); + private fun nextSecondsAndNanos( + minSeconds: Long, + minNanos: Long, + maxSeconds: Long, + maxNanos: Long + ): LongArray { + val nanoMin = BigInteger.valueOf(minSeconds) + .multiply(NANOS_PER_SECOND) + .add(BigInteger.valueOf(minNanos)) + val nanoMax = BigInteger.valueOf(maxSeconds) + .multiply(NANOS_PER_SECOND) + .add(BigInteger.valueOf(maxNanos)) + val generated = Ranges.choose(this, nanoMin, nanoMax) + .divideAndRemainder(NANOS_PER_SECOND) + return longArrayOf(generated[0].toLong(), generated[1].toLong()) + } - return new long[] { generated[0].longValue(), generated[1].longValue() }; + companion object { + private val NANOS_PER_SECOND = BigInteger.valueOf(TimeUnit.SECONDS.toNanos(1)) } -} +} \ No newline at end of file From 854c790df3498edf72ee53ec1b093e11f90b51db Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 15 Nov 2022 19:18:17 +0300 Subject: [PATCH 06/30] Rename .java to .kt --- .../quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename utbot-framework/src/main/{java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.java => kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt} (100%) diff --git a/utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.java b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt similarity index 100% rename from utbot-framework/src/main/java/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.java rename to utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt From 4d374c7d8ed064029cea01e2671b344076260d56 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 15 Nov 2022 19:18:17 +0300 Subject: [PATCH 07/30] this instance rewriting --- .../org/utbot/framework/plugin/api/Api.kt | 3 +- .../engine/greyboxfuzzer/GreyBoxFuzzer.kt | 149 +++++++++--------- .../greyboxfuzzer/generator/DataGenerator.kt | 59 +++++-- .../greyboxfuzzer/generator/FParameter.kt | 1 + .../generator/FakeAnnotatedTypeFactory.kt | 74 --------- .../generator/GeneratorConfigurator.kt | 11 +- .../generator/QuickCheckExtensions.kt | 7 +- .../generator/UTGeneratorRepository.kt | 16 +- .../generator/ClassesInstanceGenerator.kt | 5 +- .../ConstructorBasedInstanceGenerator.kt | 2 +- ...terfaceImplementationsInstanceGenerator.kt | 106 +++++++++++-- .../userclasses/generator/ObjectGenerator.kt | 32 +++- .../StaticsFieldBasedInstanceGenerator.kt | 2 +- .../StaticsMethodBasedInstanceGenerator.kt | 2 +- .../engine/greyboxfuzzer/mutator/Mutator.kt | 53 ++++--- .../engine/greyboxfuzzer/mutator/Seed.kt | 3 +- .../engine/greyboxfuzzer/util/UtBotUtils.kt | 4 +- .../generator/java/lang/BooleanGenerator.kt | 2 +- .../generator/java/lang/ByteGenerator.kt | 2 +- .../generator/java/lang/CharacterGenerator.kt | 2 +- .../generator/java/lang/DoubleGenerator.kt | 2 +- .../generator/java/lang/FloatGenerator.kt | 2 +- .../generator/java/lang/IntegerGenerator.kt | 2 +- .../generator/java/lang/LongGenerator.kt | 2 +- .../generator/java/lang/ShortGenerator.kt | 2 +- .../generator/java/lang/StringGenerator.kt | 24 ++- .../FakeAnnotatedTypeFactoryWithType.kt | 99 +++++------- .../internal/ParameterTypeContext.kt | 37 ++--- .../internal/generator/ArrayGenerator.kt | 2 +- .../internal/generator/GeneratorRepository.kt | 6 +- .../internal/generator/ZilchGenerator.kt | 4 +- 31 files changed, 414 insertions(+), 303 deletions(-) delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FakeAnnotatedTypeFactory.kt diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 639305b29a..b3799f47ba 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -485,8 +485,7 @@ data class UtAssembleModel constructor( override val classId: ClassId, override val modelName: String, val instantiationCall: UtExecutableCallModel, - //TODO: get rid of var - var modificationsChain: List, + val modificationsChain: List, val origin: UtCompositeModel? ) : UtReferenceModel(id, classId, modelName) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt index 754ddc2783..5ec5b17dcb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -23,9 +23,8 @@ class GreyBoxFuzzer( ) { private val seeds = SeedCollector() - private val explorationStageIterations = 100 + private val explorationStageIterations = 50 private val exploitationStageIterations = 100 - private var thisInstance: UtModel? = null //TODO make it return Sequence suspend fun fuzz(): Sequence { @@ -65,62 +64,68 @@ class GreyBoxFuzzer( prevMethodCoverage: Set ) { val parametersToGenericsReplacer = method.parameters.map { it to GenericsReplacer() } + val thisInstancesHistory = ArrayDeque() repeat(numberOfIterations) { iterationNumber -> - logger.debug { "Iteration number $iterationNumber" } - if (!methodUnderTest.isStatic && thisInstance == null) { - thisInstance = generateThisInstance(methodUnderTest.classId.jClass) - } - if (thisInstance != null && iterationNumber != 0) { - if (Random.getTrue(20)) { - logger.debug { "Trying to regenerate this instance" } - generateThisInstance(clazz)?.let { thisInstance = it } - } else if (Random.getTrue(50) && thisInstance is UtAssembleModel) { - thisInstance = - Mutator.regenerateFields( - clazz, - thisInstance as UtAssembleModel, - classFieldsUsedByFunc.toList() - ) + try { + logger.debug { "Iteration number $iterationNumber" } + while (thisInstancesHistory.size > 1) { + thisInstancesHistory.removeLast() } - } - /** - * Replacing unresolved generics to random compatible to bounds type - */ - when { - Random.getTrue(10) -> parametersToGenericsReplacer.map { it.second.revert() } - Random.getTrue(50) -> parametersToGenericsReplacer.map { - it.second.replaceUnresolvedGenericsToRandomTypes( - it.first - ) + if (thisInstancesHistory.isEmpty()) { + thisInstancesHistory += generateThisInstance(methodUnderTest.classId) } - } - val generatedParameters = - method.parameters.mapIndexed { index, parameter -> - DataGenerator.generate( - parameter, - index, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus - ) + if (iterationNumber != 0) { + if (Random.getTrue(20)) { + logger.debug { "Trying to regenerate this instance" } + thisInstancesHistory.clear() + thisInstancesHistory += generateThisInstance(methodUnderTest.classId) + } else if (Random.getTrue(50)) { + thisInstancesHistory += Mutator.mutateThisInstance(thisInstancesHistory.last(), classFieldsUsedByFunc.toList()) + } } - logger.debug { "Generated params = $generatedParameters" } - logger.debug { "This instance = $thisInstance" } - val stateBefore = - EnvironmentModels(thisInstance, generatedParameters.map { it.utModel }, mapOf()) - try { - val executionResult = execute(stateBefore, methodUnderTest) ?: return@repeat - logger.debug { "Execution result: $executionResult" } - val seedScore = - handleCoverage( - executionResult, - prevMethodCoverage, - methodLinesToCover - ) - seeds.addSeed(Seed(thisInstance, generatedParameters, seedScore.toDouble())) - logger.debug { "Execution result: ${executionResult.result}" } - } catch (e: Throwable) { - logger.debug(e) { "Exception while execution :(" } - return@repeat + /** + * Replacing unresolved generics to random compatible to bounds type + */ + when { + Random.getTrue(10) -> parametersToGenericsReplacer.map { it.second.revert() } + Random.getTrue(50) -> parametersToGenericsReplacer.map { + it.second.replaceUnresolvedGenericsToRandomTypes( + it.first + ) + } + } + val thisInstance = thisInstancesHistory.last() + val generatedParameters = + method.parameters.mapIndexed { index, parameter -> + DataGenerator.generate( + parameter, + index, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus + ) + } + logger.debug { "Generated params = $generatedParameters" } + logger.debug { "This instance = $thisInstance" } + val stateBefore = + EnvironmentModels(thisInstance.utModelForExecution, generatedParameters.map { it.utModel }, mapOf()) + try { + val executionResult = execute(stateBefore, methodUnderTest) + logger.debug { "Execution result: $executionResult" } + val seedScore = + handleCoverage( + executionResult, + prevMethodCoverage, + methodLinesToCover + ) + seeds.addSeed(Seed(thisInstance, generatedParameters, seedScore.toDouble())) + logger.debug { "Execution result: ${executionResult.result}" } + } catch (e: Throwable) { + logger.debug(e) { "Exception while execution :(" } + thisInstancesHistory.clear() + return@repeat + } + } catch (e: FuzzerIllegalStateException) { + logger.error(e) { "Something wrong in the fuzzing process" } } } } @@ -225,32 +230,26 @@ class GreyBoxFuzzer( private suspend fun execute( stateBefore: EnvironmentModels, methodUnderTest: ExecutableId - ): UtFuzzingConcreteExecutionResult? = - try { - val executor = - ConcreteExecutor( - UtFuzzingExecutionInstrumentation, - pathsToUserClasses, - pathsToDependencyClasses - ).apply { this.classLoader = utContext.classLoader } - executor.executeConcretely(methodUnderTest, stateBefore, listOf()) - } catch (e: Throwable) { - logger.debug { "Exception in $methodUnderTest :( $e" } - null - } + ): UtFuzzingConcreteExecutionResult = run { + val executor = + ConcreteExecutor( + UtFuzzingExecutionInstrumentation, + pathsToUserClasses, + pathsToDependencyClasses + ).apply { this.classLoader = utContext.classLoader } + executor.executeConcretely(methodUnderTest, stateBefore, listOf()) + } + - private fun generateThisInstance(clazz: Class<*>) = - try { + private fun generateThisInstance(classId: ClassId): ThisInstance = if (!methodUnderTest.isStatic) { - DataGenerator.generate( - clazz, + DataGenerator.generateThis( + classId, GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus ) } else { - null + StaticMethodThisInstance } - } catch (_: Throwable) { - null - } + } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt index d1470178ab..e0b267d358 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt @@ -1,13 +1,16 @@ package org.utbot.engine.greyboxfuzzer.generator +import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.quickcheck.generator.GenerationStatus import org.utbot.quickcheck.generator.Generator import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness import org.utbot.engine.logger import org.utbot.external.api.classIdForType +import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.jClass import soot.SootMethod import java.lang.reflect.Parameter @@ -45,6 +48,46 @@ object DataGenerator { return generate(generator, parameter, random, status) } + fun generateThis( + classId: ClassId, + random: SourceOfRandomness, + status: GenerationStatus + ): NormalMethodThisInstance { + val generator = + generatorRepository.getOrProduceGenerator(classId.jClass) + return generateThis(generator, classId, random, status) + } + + private fun generateThis( + generator: Generator?, + classId: ClassId, + random: SourceOfRandomness, + status: GenerationStatus, + numberOfTries: Int = 3 + ): NormalMethodThisInstance { + logger.debug { "Trying to generate this instance of type ${classId.name} $numberOfTries times" } + generatorRepository.removeGeneratorForObjectClass() + if (generator == null) { + throw FuzzerIllegalStateException("Can't find generator for ${classId.name}") + } + var generatedValue: UtModel + repeat(numberOfTries) { + logger.debug { "Try $it" } + try { + generatedValue = generator.generate(random, status) + return NormalMethodThisInstance( + generatedValue, + generator, + classId + ) + } catch (e: Throwable) { + logger.error(e) { "Exception while generation :(" } + return@repeat + } + } + throw FuzzerIllegalStateException("Can't generate for ${classId.name}") + } + fun generate( generator: Generator?, parameter: Parameter, @@ -63,15 +106,13 @@ object DataGenerator { logger.debug { "Try $it" } try { generatedValue = generator.generate(random, status) - if (generatedValue != null) { - return FParameter( - parameter, - null, - generatedValue!!, - generator, - emptyList() - ) - } + return FParameter( + parameter, + null, + generatedValue!!, + generator, + emptyList() + ) } catch (e: Throwable) { logger.error(e) { "Exception while generation :(" } return@repeat diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt index 65b2bb652d..8328b8c4c7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt @@ -14,6 +14,7 @@ import java.lang.reflect.Parameter data class FParameter( val parameter: Parameter, val value: Any?, + //TODO make it val var utModel: UtModel, val generator: Generator?, val classId: ClassId, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FakeAnnotatedTypeFactory.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FakeAnnotatedTypeFactory.kt deleted file mode 100644 index c36253d03b..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FakeAnnotatedTypeFactory.kt +++ /dev/null @@ -1,74 +0,0 @@ -package org.utbot.engine.greyboxfuzzer.generator - -import java.lang.reflect.AnnotatedArrayType -import java.lang.reflect.AnnotatedType -import java.lang.reflect.Type - - -internal class FakeAnnotatedTypeFactory private constructor() { - - companion object { - fun makeFrom(clazz: Class<*>): AnnotatedType { - return if (clazz.isArray) makeArrayType(clazz) else makePlainType(clazz) - } - - private fun makeArrayType(type: Class<*>): AnnotatedArrayType { - return FakeAnnotatedArrayType(type) - } - - private fun makePlainType(type: Class<*>): AnnotatedType { - return FakeAnnotatedType(type) - } - } - - private class FakeAnnotatedArrayType internal constructor(private val type: Class<*>) : AnnotatedArrayType { - override fun getAnnotatedGenericComponentType(): AnnotatedType { - return makeFrom(type.componentType) - } - - // Not introduced until JDK 9 -- not marking as... - // @Override - override fun getAnnotatedOwnerType(): AnnotatedType? { - return null - } - - override fun getType(): Type { - return type - } - - override fun getAnnotation( - annotationClass: Class - ): T? { - return null - } - - override fun getAnnotations(): Array { - return arrayOfNulls(0) - } - - override fun getDeclaredAnnotations(): Array { - return arrayOfNulls(0) - } - } - - private class FakeAnnotatedType internal constructor(private val type: Class<*>) : AnnotatedType { - override fun getType(): Type { - return type - } - - override fun getAnnotation( - annotationClass: Class - ): T? { - return null - } - - override fun getAnnotations(): Array { - return arrayOfNulls(0) - } - - override fun getDeclaredAnnotations(): Array { - return arrayOfNulls(0) - } - } - -} diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt index 88a57a7f46..a2ccccd2c1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt @@ -30,8 +30,8 @@ object GeneratorConfigurator { val minCollectionSize: Int = 1 val maxCollectionSize: Int = 5 - private val sizeAnnotationInstance: Size - private val inRangeAnnotationInstance: InRange + val sizeAnnotationInstance: Size + val inRangeAnnotationInstance: InRange init { val sizeAnnotationParams = @@ -90,6 +90,13 @@ object GeneratorConfigurator { is CollectionGenerator -> generator.configure(sizeAnnotationInstance) is ArrayGenerator -> generator.configure(sizeAnnotationInstance) is MapGenerator -> generator.configure(sizeAnnotationInstance) + is StringGenerator -> generator.configure( + if (Random.getTrue(50)) { + setOf('a'.code..'z'.code) + } else { + setOf(' '.code..'~'.code) + } + ) else -> Unit } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt index 8fa7aad37f..0d276063a0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -14,6 +14,7 @@ import org.utbot.engine.logger import org.utbot.engine.rawType import org.utbot.quickcheck.generator.ComponentizedGenerator import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.internal.generator.ArrayGenerator import org.utbot.quickcheck.internal.generator.GeneratorRepository @@ -90,9 +91,9 @@ fun GeneratorRepository.getOrProduceGenerator( } finally { producedUserClassesGenerators.forEach { removeGenerator(it.parameterTypeContext!!.resolved.rawClass) } } - (listOf(generator) + generator.getAllComponents()).forEach { - GeneratorConfigurator.configureGenerator(it, 85) - } +// (listOf(generator) + generator.getAllComponents()).forEach { +// GeneratorConfigurator.configureGenerator(it, 85) +// } return generator } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt index 994d1140b7..bd8335a8fe 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt @@ -2,27 +2,31 @@ package org.utbot.engine.greyboxfuzzer.generator import org.utbot.quickcheck.generator.Generator import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.internal.generator.GeneratorRepository -import org.utbot.quickcheck.internal.generator.LambdaGenerator -import org.utbot.quickcheck.internal.generator.MarkerInterfaceGenerator import org.utbot.quickcheck.random.SourceOfRandomness import org.utbot.engine.logger import org.utbot.quickcheck.internal.Zilch +import org.utbot.quickcheck.internal.generator.* class UTGeneratorRepository(random: SourceOfRandomness) : GeneratorRepository(random) { override fun generatorFor(parameter: ParameterTypeContext): Generator { logger.debug { "TRYING TO GET GENERATOR FOR ${parameter.resolved}" } - if (parameter.resolved.name == Zilch::class.java.name) return TODO("null") + if (parameter.resolved.name == Zilch::class.java.name) return ZilchGenerator() val generator = super.generatorFor(parameter) if (generator is MarkerInterfaceGenerator) { throw IllegalArgumentException( "Cannot find generator for " + parameter.name() + " of type " + parameter.type().typeName ) - } else if (generator is LambdaGenerator<*>) { - return TODO("null") } return generator } + + override fun generatorsFor(parameter: ParameterTypeContext) = + super.generatorsFor(parameter).onEach { GeneratorConfigurator.configureGenerator(it, 85) } + + override fun generatorForArrayType(parameter: ParameterTypeContext) = + super.generatorForArrayType(parameter).also { GeneratorConfigurator.configureGenerator(it, 85) } + + } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt index d342d28f00..a197e63488 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt @@ -3,6 +3,7 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.logger import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext @@ -23,7 +24,7 @@ class ClassesInstanceGenerator( else -> mutableListOf('c', 'c', 's') } while (typeOfGenerations.isNotEmpty()) { - val randomTypeOfGeneration = typeOfGenerations.randomOrNull() ?: return TODO("null") + val randomTypeOfGeneration = typeOfGenerations.randomOrNull() ?: return UtNullModel(clazz.id) logger.debug { "Type of generation: $randomTypeOfGeneration" } val generatedInstance = when (randomTypeOfGeneration) { @@ -50,6 +51,6 @@ class ClassesInstanceGenerator( return generatedInstance } } - return TODO("null") + return UtNullModel(clazz.id) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt index 5fa31432b1..e5ba9b835c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt @@ -23,7 +23,7 @@ class ConstructorBasedInstanceGenerator( ): InstanceGenerator { override fun generate(): UtModel { - val constructor = chooseRandomConstructor(clazz) ?: return TODO("null") + val constructor = chooseRandomConstructor(clazz) ?: return UtNullModel(clazz.id) val resolvedConstructor = //In case if we can not resolve constructor gctx.constructor(constructor).let { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt index 62d028b022..173448cdf1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt @@ -1,14 +1,22 @@ @file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") + package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +import org.utbot.common.isAbstract +import org.utbot.engine.greyboxfuzzer.generator.DataGenerator import org.utbot.engine.greyboxfuzzer.util.* -import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.objectClassId import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import ru.vyarus.java.generics.resolver.context.GenericsInfo import java.lang.reflect.Type import kotlin.random.Random +import kotlin.system.exitProcess class InterfaceImplementationsInstanceGenerator( private val resolvedType: Type, @@ -19,7 +27,7 @@ class InterfaceImplementationsInstanceGenerator( ) : InstanceGenerator { override fun generate(): UtModel { //Try to generate with statics with some probability - val clazz = resolvedType.toClass() ?: return TODO("null") + val clazz = resolvedType.toClass() ?: return UtNullModel(objectClassId) if (Random.getTrue(50)) { StaticsBasedInstanceGenerator( clazz, @@ -27,11 +35,11 @@ class InterfaceImplementationsInstanceGenerator( sourceOfRandomness, generationStatus, depth - ).generate()?.let { + ).generate().let { return it } } - val genericsContext = getRandomImplementerGenericContext(clazz, resolvedType) ?: return TODO("null") + val genericsContext = getRandomImplementerGenericContext(clazz, resolvedType) ?: return generateMock(clazz, resolvedType, typeContext) return ClassesInstanceGenerator( genericsContext.currentClass(), genericsContext, @@ -40,7 +48,48 @@ class InterfaceImplementationsInstanceGenerator( sourceOfRandomness, generationStatus, depth - ).generate() + ).generate().let { + if (it is UtNullModel && Random.getTrue(50)) generateMock(clazz, resolvedType, typeContext) else it + } + } + + private fun generateMock(clazz: Class<*>, resolvedType: Type, typeContext: GenericsContext): UtModel { + if (!clazz.isInterface) return UtNullModel(clazz.id) + val sootClazz = clazz.toSootClass() ?: return UtNullModel(clazz.id) + val constructor = UtModelGenerator.utModelConstructor + val allNeededInterfaces = clazz.methods.map { it.declaringClass }.filter { it != clazz }.toSet() + val chainToGenericsContext = allNeededInterfaces.map { cl -> + val chain = cl.toSootClass() + ?.getImplementersOfWithChain() + ?.filter { it.contains(sootClazz) } + ?.map { it.dropLastWhile { it != sootClazz } } + ?.minByOrNull { it.size } + ?.map { it.toJavaClass() } + if (chain == null || chain.any { it == null }) { + null + } else { + cl to buildGenericsContextForInterfaceParent(resolvedType, clazz, chain.map { it!! }.reversed().drop(1)) + } + } + val allChainToGenericsContext = chainToGenericsContext + (clazz to typeContext) + val mocks = clazz.methods + .filter { it.isAbstract } + .associateTo(mutableMapOf()) { method -> + val genericsContextForMethod = allChainToGenericsContext.find { it!!.first == method.declaringClass }?.second + val methodReturnType = + if (genericsContextForMethod != null) { + genericsContextForMethod.method(method).resolveReturnType().let { + if (it.toClass() == null) method.returnType else it + } + } else { + method.returnType + } + val parameterTypeContext = ParameterTypeContext.forType(methodReturnType, genericsContextForMethod) + val generatedUtModelWithReturnType = + DataGenerator.generate(parameterTypeContext, sourceOfRandomness, generationStatus) ?: UtNullModel(methodReturnType.toClass()!!.id) + method.executableId as ExecutableId to listOf(generatedUtModelWithReturnType) + } + return UtCompositeModel(constructor.computeUnusedIdAndUpdate(), clazz.id, isMock = true, mocks = mocks) } private fun getRandomImplementerGenericContext(clazz: Class<*>, resolvedType: Type): GenericsContext? { @@ -57,14 +106,14 @@ class InterfaceImplementationsInstanceGenerator( } ?: return null //Deal with generics val generics = mutableListOf>>() - var prevImplementer = sootClass.toJavaClass() + var prevImplementer = clazz resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> if (prevImplementer.toClass() != null) { generics.add(typeVariable to mutableListOf(prevImplementer.toClass()!!.typeParameters[index])) } } for (implementer in randomImplementersChain) { - val javaImplementer = implementer.toJavaClass() + val javaImplementer = implementer.toJavaClass() ?: return null val extendType = javaImplementer.let { it.genericInterfaces + it.genericSuperclass } .find { it.toClass() == prevImplementer } val tp = prevImplementer.typeParameters @@ -79,10 +128,49 @@ class InterfaceImplementationsInstanceGenerator( } } } - val g = prevImplementer.typeParameters.map { tp -> tp.name to generics.find { it.second.last() == tp }?.first }.toMap() + val g = + prevImplementer.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } val gm = LinkedHashMap() - g.forEach { gm[it.key] = it.value!! } + g.forEach { + if (it.value != null) { + gm[it.key] = it.value!! + } + } val m = mutableMapOf(prevImplementer to gm) return GenericsContext(GenericsInfo(prevImplementer, m), prevImplementer) } + + private fun buildGenericsContextForInterfaceParent(resolvedType: Type, clazz: Class<*>, parentChain: List>): GenericsContext? { + val generics = mutableListOf>>() + var curClass = clazz + resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> + if (curClass.toClass() != null) { + generics.add(typeVariable to mutableListOf(curClass.toClass()!!.typeParameters[index])) + } + } + for (parent in parentChain) { + val parentType = curClass.let { it.genericInterfaces.toList() + listOf(it.genericSuperclass) } + .find { it.toClass() == parent } + val tp = curClass.typeParameters + curClass = parent + if (tp.isEmpty()) continue + val newTp = parentType?.getActualTypeArguments()?.ifEmpty { return null } ?: return null + tp.mapIndexed { index, typeVariable -> typeVariable to newTp[index] } + .forEach { typeVar -> + val indexOfTypeParam = generics.indexOfFirst { it.second.last() == typeVar.first } + if (indexOfTypeParam != -1) { + generics[indexOfTypeParam].second.add(curClass.typeParameters[indexOfTypeParam]) + } + } + } + val g = curClass.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } + val gm = LinkedHashMap() + g.forEach { + if (it.value != null) { + gm[it.key] = it.value!! + } + } + val m = mutableMapOf(curClass to gm) + return GenericsContext(GenericsInfo(curClass, m), curClass) + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt index 31c48ff782..6453164454 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt @@ -1,20 +1,44 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGenerators +import org.utbot.engine.greyboxfuzzer.generator.getOrProduceGenerator +import org.utbot.engine.greyboxfuzzer.util.getAllTypesFromCastAndInstanceOfInstructions +import org.utbot.engine.greyboxfuzzer.util.getTrue +import org.utbot.engine.greyboxfuzzer.util.toJavaClass +import org.utbot.engine.greyboxfuzzer.util.toSootMethod import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.MethodGenericsContext +import kotlin.random.Random class ObjectGenerator( + private val parameterTypeContext: ParameterTypeContext, private val sourceOfRandomness: SourceOfRandomness, private val generationStatus: GenerationStatus -): InstanceGenerator { - override fun generate(): UtModel = - GreyBoxFuzzerGenerators.generatorRepository +) : InstanceGenerator { + override fun generate(): UtModel { + val currentSootMethod = + (parameterTypeContext.generics as? MethodGenericsContext)?.currentMethod()?.toSootMethod() + val potentialUsefulClasses = + currentSootMethod?.getAllTypesFromCastAndInstanceOfInstructions()?.mapNotNull { it.toJavaClass() } + val potentialInterestingObjectReplacement = + if (potentialUsefulClasses?.isNotEmpty() == true && Random.getTrue(50)) { + val randomClass = potentialUsefulClasses.random() + GreyBoxFuzzerGenerators.generatorRepository + .getOrProduceGenerator(randomClass) + ?.generate(sourceOfRandomness, generationStatus) + } else null + potentialInterestingObjectReplacement?.let { return it } + return GreyBoxFuzzerGenerators.generatorRepository .getGenerators() .toList() .flatMap { it.second } .filter { !it.hasComponents() } .randomOrNull() - ?.generate(sourceOfRandomness, generationStatus) ?: TODO("null") + ?.generate(sourceOfRandomness, generationStatus) ?: UtNullModel(parameterTypeContext.rawClass.id) + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt index 86487c7218..aace2ec21f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt @@ -24,7 +24,7 @@ internal class StaticsFieldBasedInstanceGenerator( override fun generate(): UtModel = getRandomStaticToProduceInstanceUsingSoot()?.let { fieldToProvideInstance -> createUtModelForStaticFieldInvocation(UtModelGenerator.utModelConstructor, fieldToProvideInstance) - } ?: TODO("null") + } ?: UtNullModel(clazz.id) //In case of no Soot private fun getStaticFieldToProduceInstance(): Field? { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt index 5dac847814..d760c90539 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt @@ -37,7 +37,7 @@ internal class StaticsMethodBasedInstanceGenerator( generationStatus, depth ).invoke() - } ?: TODO("null") + } ?: UtNullModel(clazz.id) //In case of no Soot private fun getRandomStaticToProduceInstance(): Method? = diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt index 6cd36eee39..0bd4883594 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt @@ -1,16 +1,14 @@ package org.utbot.engine.greyboxfuzzer.mutator import org.javaruntype.type.Types -import org.utbot.engine.greyboxfuzzer.generator.DataGenerator -import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGenerators -import org.utbot.engine.greyboxfuzzer.generator.FParameter -import org.utbot.engine.greyboxfuzzer.generator.getOrProduceGenerator +import org.utbot.engine.greyboxfuzzer.generator.* import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.engine.logger import org.utbot.external.api.classIdForType import org.utbot.framework.concrete.UtModelConstructor import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.fieldId +import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.method import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.internal.generator.GeneratorRepository @@ -35,29 +33,28 @@ object Mutator { return fParameter } - fun regenerateFields(clazz: Class<*>, classInstance: UtAssembleModel, fieldsToRegenerate: List): UtModel { + fun regenerateFields( + clazz: Class<*>, + classInstance: UtAssembleModel, + fieldsToRegenerate: List + ): UtModel { val parameterTypeContext = ParameterTypeContext.forClass(clazz) - var resUtModel = classInstance - for (field in fieldsToRegenerate) { - resUtModel = setNewFieldValue(field, parameterTypeContext, resUtModel) - } - return resUtModel + val modifications = fieldsToRegenerate.mapNotNull { setNewFieldValue(it, parameterTypeContext, classInstance) } + return classInstance.addModification(modifications) } private fun setNewFieldValue( field: Field, parameterTypeContext: ParameterTypeContext, clazzInstance: UtAssembleModel - ): UtAssembleModel { - field.isAccessible = true - val oldFieldValue = field.getFieldValue(clazzInstance) + ): UtStatementModel? { if (field.hasAtLeastOneOfModifiers( Modifier.STATIC, Modifier.FINAL - ) && oldFieldValue != null - ) return clazzInstance + ) + ) return null val fieldType = parameterTypeContext.generics.resolveFieldType(field) - logger.debug { "F = $field TYPE = $fieldType OLDVALUE = $oldFieldValue" } + logger.debug { "F = $field TYPE = $fieldType" } val parameterTypeContextForResolvedType = ParameterTypeContext( field.name, field.annotatedType, @@ -72,12 +69,27 @@ object Mutator { ) logger.debug { "NEW FIELD VALUE = $newFieldValue" } if (newFieldValue != null) { - return clazzInstance.addModification(UtDirectSetFieldModel(clazzInstance, field.fieldId, newFieldValue)) + return UtDirectSetFieldModel(clazzInstance, field.fieldId, newFieldValue) } - return clazzInstance + return null } + fun mutateThisInstance( + thisInstance: ThisInstance, + fieldsToRegenerate: List + ): ThisInstance { + if (thisInstance !is NormalMethodThisInstance) return thisInstance + val thisInstanceAsUtModel = thisInstance.utModel as UtAssembleModel + val mutationResult = + regenerateFields( + thisInstance.classId.jClass, + thisInstanceAsUtModel, + fieldsToRegenerate + ) + return NormalMethodThisInstance(mutationResult, thisInstance.generator, thisInstance.classId) + } + fun mutateParameter( fParameter: FParameter ): FParameter { @@ -107,8 +119,9 @@ object Mutator { GreyBoxFuzzerGenerators.genStatus ).utModel } - val callModel = UtExecutableCallModel(fParameter.utModel as UtReferenceModel, randomMethod, parametersForMethodInvocation) - (originalUtModel as UtAssembleModel).addModification(callModel) + val callModel = + UtExecutableCallModel(fParameter.utModel as UtReferenceModel, randomMethod, parametersForMethodInvocation) + (originalUtModel as UtAssembleModel).addModification(listOf(callModel)) return FParameter(originalParameter, null, fParameter.utModel, fParameter.generator, fParameter.fields) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt index ea6ddcf8e8..afcad6a248 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt @@ -1,10 +1,11 @@ package org.utbot.engine.greyboxfuzzer.mutator import org.utbot.engine.greyboxfuzzer.generator.FParameter +import org.utbot.engine.greyboxfuzzer.generator.ThisInstance import org.utbot.framework.plugin.api.ClassId data class Seed( - val thisInstance: Any?, + val thisInstance: ThisInstance, val arguments: List, val priority: Double = 0.0 ) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt index fb10a25a3f..2fcb22419c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt @@ -9,13 +9,13 @@ import java.lang.reflect.Method import java.lang.reflect.Parameter -fun UtAssembleModel.addModification(modification: UtStatementModel) = +fun UtAssembleModel.addModification(modifications: List) = UtAssembleModel( this.id, this.classId, "${this.classId.name}#" + this.id?.toString(16), this.instantiationCall, - this.modificationsChain + modification, + this.modificationsChain + modifications, this.origin ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt index 7f7f29b05b..43c7e0549b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt @@ -12,7 +12,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness */ class BooleanGenerator : Generator( listOf( - Boolean::class.java + Boolean::class.javaObjectType ) ) { override fun generate( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt index 1d4b99f6fa..a0c7a98edf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt @@ -13,7 +13,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness /** * Produces values of type `byte` or [Byte]. */ -class ByteGenerator : IntegralGenerator(listOf(Byte::class.java)) { +class ByteGenerator : IntegralGenerator(listOf(Byte::class.javaObjectType)) { private var min = Reflection.defaultValueOf(InRange::class.java, "minByte") as Byte private var max = Reflection.defaultValueOf(InRange::class.java, "maxByte") as Byte diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt index 9eced4f0ae..034ba18538 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt @@ -14,7 +14,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness */ class CharacterGenerator : Generator( listOf( - Char::class.java + Char::class.javaObjectType ) ) { private var min = Reflection.defaultValueOf(InRange::class.java, "minChar") as Char diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt index 33ad67cbb2..608b81651b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt @@ -13,7 +13,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness * Produces values for property parameters of type `double` or * [Double]. */ -class DoubleGenerator : DecimalGenerator(listOf(Double::class.java)) { +class DoubleGenerator : DecimalGenerator(listOf(Double::class.javaObjectType)) { private var min = Reflection.defaultValueOf(InRange::class.java, "minDouble") as Double private var max = Reflection.defaultValueOf(InRange::class.java, "maxDouble") as Double diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt index cb4cf6115f..ee91888093 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt @@ -12,7 +12,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness /** * Produces values of type `float` or [Float]. */ -class FloatGenerator : DecimalGenerator(listOf(Float::class.java)) { +class FloatGenerator : DecimalGenerator(listOf(Float::class.javaObjectType)) { private var min = Reflection.defaultValueOf(InRange::class.java, "minFloat") as Float private var max = Reflection.defaultValueOf(InRange::class.java, "maxFloat") as Float diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt index fa68e70b05..064683e292 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt @@ -12,7 +12,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness /** * Produces values of type `int` or [Integer]. */ -class IntegerGenerator : IntegralGenerator(listOf(Int::class.java)) { +class IntegerGenerator : IntegralGenerator(listOf(Int::class.javaObjectType)) { private var min = Reflection.defaultValueOf(InRange::class.java, "minInt") as Int private var max = Reflection.defaultValueOf(InRange::class.java, "maxInt") as Int diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt index 2a44892f30..02f14a0a23 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt @@ -12,7 +12,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness /** * Produces values of type `long` or [Long]. */ -class LongGenerator : IntegralGenerator(listOf(Long::class.java)) { +class LongGenerator : IntegralGenerator(listOf(Long::class.javaObjectType)) { private var min = Reflection.defaultValueOf(InRange::class.java, "minLong") as Long private var max = Reflection.defaultValueOf(InRange::class.java, "maxLong") as Long diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt index 0d30ad243a..003a4c4bd1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt @@ -12,7 +12,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness /** * Produces values of type `short` or [Short]. */ -class ShortGenerator : IntegralGenerator(listOf(Short::class.java)) { +class ShortGenerator : IntegralGenerator(listOf(Short::class.javaObjectType)) { private var min = Reflection.defaultValueOf(InRange::class.java, "minShort") as Short private var max = Reflection.defaultValueOf(InRange::class.java, "maxShort") as Short diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt index e76e31b3c8..be1490c796 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt @@ -1,6 +1,7 @@ package org.utbot.quickcheck.generator.java.lang import org.utbot.quickcheck.random.SourceOfRandomness +import kotlin.random.Random /** * @@ -8,7 +9,28 @@ import org.utbot.quickcheck.random.SourceOfRandomness * `[0x0000, 0xD7FF]`. */ class StringGenerator : AbstractStringGenerator() { + + private var codePoints = setOf(0 until Character.MIN_SURROGATE.code) + override fun nextCodePoint(random: SourceOfRandomness): Int { - return random.nextInt(0, Character.MIN_SURROGATE.code - 1) + val codePoint = chooseRandomCodePoint() + return codePoint.random() + } + + private fun chooseRandomCodePoint(): IntRange { + val size = codePoints.sumOf { it.last - it.first } + val randomIntToSize = Random.nextInt(size) + var curSum = 0 + for (codePoint in codePoints) { + val codePointSize = codePoint.last - codePoint.first + curSum += codePointSize + if (curSum >= randomIntToSize) { + return codePoint + } + } + return codePoints.random() + } + fun configure(codePoints: Set) { + this.codePoints = codePoints } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt index 5d45e6963a..996624472d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt @@ -22,90 +22,71 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +package org.utbot.quickcheck.internal -package org.utbot.quickcheck.internal; +import java.lang.reflect.AnnotatedArrayType +import java.lang.reflect.AnnotatedType +import java.lang.reflect.Type -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedArrayType; -import java.lang.reflect.AnnotatedType; -import java.lang.reflect.Type; +object FakeAnnotatedTypeFactoryWithType { -final class FakeAnnotatedTypeFactoryWithType { - private FakeAnnotatedTypeFactoryWithType() { - throw new UnsupportedOperationException(); - } - - static AnnotatedType makeFrom(Type type) { - return type.getClass().isArray() ? makeArrayType(type) : makePlainType(type); - } - - private static AnnotatedArrayType makeArrayType(Type type) { - return new FakeAnnotatedArrayType(type); - } - - private static AnnotatedType makePlainType(Type type) { - return new FakeAnnotatedType(type); - } - - private static final class FakeAnnotatedArrayType - implements AnnotatedArrayType { - - private final Type type; - - FakeAnnotatedArrayType(Type type) { - this.type = type; - } - @Override public AnnotatedType getAnnotatedGenericComponentType() { - return makeFrom(type.getClass().getComponentType()); + private class FakeAnnotatedArrayType internal constructor(private val type: Type) : AnnotatedArrayType { + override fun getAnnotatedGenericComponentType(): AnnotatedType { + return makeFrom(type.javaClass.componentType) } // Not introduced until JDK 9 -- not marking as... // @Override - public AnnotatedType getAnnotatedOwnerType() { - return null; + override fun getAnnotatedOwnerType(): AnnotatedType? { + return null } - @Override public Type getType() { - return type; + override fun getType(): Type { + return type } - @Override public T getAnnotation(Class annotationClass) { - - return null; + override fun getAnnotation(annotationClass: Class): T? { + return null } - @Override public Annotation[] getAnnotations() { - return new Annotation[0]; + override fun getAnnotations(): Array { + return arrayOfNulls(0) } - @Override public Annotation[] getDeclaredAnnotations() { - return new Annotation[0]; + override fun getDeclaredAnnotations(): Array { + return arrayOfNulls(0) } } - private static final class FakeAnnotatedType implements AnnotatedType { - private final Type type; - - FakeAnnotatedType(Type type) { - this.type = type; + private class FakeAnnotatedType internal constructor(private val type: Type) : AnnotatedType { + override fun getType(): Type { + return type } - @Override public Type getType() { - return type; + override fun getAnnotation(annotationClass: Class): T? { + return null } - @Override public T getAnnotation(Class annotationClass) { - - return null; + override fun getAnnotations(): Array { + return arrayOfNulls(0) } - @Override public Annotation[] getAnnotations() { - return new Annotation[0]; + override fun getDeclaredAnnotations(): Array { + return arrayOfNulls(0) } + } - @Override public Annotation[] getDeclaredAnnotations() { - return new Annotation[0]; - } + fun makeFrom(type: Type): AnnotatedType { + return if (type.javaClass.isArray) makeArrayType(type) else makePlainType(type) } -} + + private fun makeArrayType(type: Type): AnnotatedArrayType { + return FakeAnnotatedArrayType(type) + } + + private fun makePlainType(type: Type): AnnotatedType { + return FakeAnnotatedType(type) + } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt index 1d25b177d1..d023ff18fb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt @@ -1,11 +1,7 @@ package org.utbot.quickcheck.internal -import org.javaruntype.type.ExtendsTypeParameter -import org.javaruntype.type.StandardTypeParameter +import org.javaruntype.type.* import org.javaruntype.type.Type -import org.javaruntype.type.TypeParameter -import org.javaruntype.type.Types -import org.javaruntype.type.WildcardTypeParameter import org.utbot.quickcheck.generator.Generator import org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom import org.utbot.quickcheck.internal.Items.choose @@ -13,21 +9,12 @@ import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.GenericsResolver import ru.vyarus.java.generics.resolver.context.GenericsContext import ru.vyarus.java.generics.resolver.context.MethodGenericsContext -import java.lang.reflect.AnnotatedArrayType -import java.lang.reflect.AnnotatedElement -import java.lang.reflect.AnnotatedType -import java.lang.reflect.Constructor -import java.lang.reflect.Executable -import java.lang.reflect.Field -import java.lang.reflect.Method -import java.lang.reflect.Parameter -import java.lang.reflect.ParameterizedType -import java.lang.reflect.TypeVariable +import java.lang.reflect.* class ParameterTypeContext( private val parameterName: String, private val parameterType: AnnotatedType, - private val declarerName: String, + internal val declarerName: String, val resolved: Type<*>, val generics: GenericsContext, private val parameterIndex: Int = -1 @@ -146,7 +133,6 @@ class ParameterTypeContext( val deque = ArrayDeque() if (isArray) { addParameterTypeContextToDeque(deque, arrayComponentContext()) - deque.add(arrayComponentContext()) } typeParameterContexts(sourceOfRandomness).forEach { ptx: ParameterTypeContext -> addParameterTypeContextToDeque(deque, ptx) @@ -284,6 +270,21 @@ class ParameterTypeContext( @JvmStatic private val zilch: Zilch = Zilch + fun forType(type: java.lang.reflect.Type): ParameterTypeContext { + return forType(type, null) + } + + fun forType(type: java.lang.reflect.Type, generics: GenericsContext?): ParameterTypeContext { + val gctx: GenericsContext = generics ?: GenericsResolver.resolve(type.javaClass) + return ParameterTypeContext( + type.typeName, + FakeAnnotatedTypeFactoryWithType.makeFrom(type), + type.typeName, + Types.forJavaLangReflectType(type), + gctx + ) + } + fun forClass(clazz: Class<*>): ParameterTypeContext { return ParameterTypeContext( clazz.typeName, @@ -375,7 +376,7 @@ class ParameterTypeContext( private fun zilch(): AnnotatedType { return try { - Companion::class.java.getDeclaredField("zilch").annotatedType + ParameterTypeContext::class.java.getDeclaredField("zilch").annotatedType } catch (e: NoSuchFieldException) { throw AssertionError(e) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt index 38b140186d..072fc90299 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt @@ -76,7 +76,7 @@ class ArrayGenerator(private val componentType: Class<*>, val component: Generat Float::class.javaPrimitiveType -> floatArrayClassId Long::class.javaPrimitiveType -> longArrayClassId Short::class.javaPrimitiveType -> shortArrayClassId - else -> objectArrayClassId + else -> ClassId("[L", classIdForType(componentType)) } override fun provide(provided: Generators) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt index b03ce61713..5a97f8eeaf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt @@ -120,9 +120,9 @@ open class GeneratorRepository private constructor( } } - private fun generatorForArrayType( + open fun generatorForArrayType( parameter: ParameterTypeContext - ): Generator { + ): ArrayGenerator { val component = parameter.arrayComponentContext() return ArrayGenerator(component.rawClass, generatorFor(component)) } @@ -249,7 +249,7 @@ open class GeneratorRepository private constructor( } } - private fun generatorsFor(parameter: ParameterTypeContext): List { + open fun generatorsFor(parameter: ParameterTypeContext): List { var matches = generators[parameter.rawClass] ?: error("No generator for type: ${parameter.rawClass}") if (!parameter.allowMixedTypes()) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt index be41083f09..1cb7e61572 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt @@ -3,6 +3,8 @@ package org.utbot.quickcheck.internal.generator import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.objectClassId import org.utbot.quickcheck.generator.GenerationStatus import org.utbot.quickcheck.generator.Generator import org.utbot.quickcheck.internal.Zilch @@ -13,6 +15,6 @@ class ZilchGenerator : Generator(Zilch::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(Zilch, classIdForType(Zilch::class.java)) + return UtNullModel(objectClassId)//utModelConstructor.construct(Zilch, classIdForType(Zilch::class.java)) } } \ No newline at end of file From 3157025dbd93496823bca998ad1ab4e7c430e728 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 22 Nov 2022 18:01:18 +0300 Subject: [PATCH 08/30] Added mutations --- .../engine/greyboxfuzzer/GreyBoxFuzzer.kt | 62 ++- .../greyboxfuzzer/generator/DataGenerator.kt | 11 +- .../greyboxfuzzer/generator/FParameter.kt | 21 + .../greyboxfuzzer/generator/FThisInstance.kt | 33 ++ .../generator/QuickCheckExtensions.kt | 142 +++-- .../generator/UTGeneratorRepository.kt | 10 +- .../generator/map/HashMapGenerator.kt | 9 - .../generator/map/HashtableGenerator.kt | 9 - .../generator/map/LinkedHashMapGenerator.kt | 7 - .../generator/map/MapGenerator.kt | 60 -- .../generator/set/HashSetGenerator.kt | 5 - .../generator/set/LinkedHashSetGenerator.kt | 3 - .../generator/set/SetGenerator.kt | 43 -- .../userclasses/InstancesGenerator.kt | 521 ------------------ .../userclasses/UserClassGenerator.kt | 85 ++- ...terfaceImplementationsInstanceGenerator.kt | 119 ++-- .../userclasses/generator/ObjectGenerator.kt | 4 +- .../engine/greyboxfuzzer/mutator/Mutator.kt | 71 ++- .../engine/greyboxfuzzer/mutator/Seed.kt | 25 +- .../greyboxfuzzer/mutator/SeedCollector.kt | 10 +- .../util/FuzzerIllegalStateException.kt | 3 + .../engine/greyboxfuzzer/util/SootUtils.kt | 6 +- .../engine/greyboxfuzzer/util/UtBotUtils.kt | 43 ++ .../framework/plugin/api/TestCaseGenerator.kt | 2 +- .../generator/ComponentizedGenerator.kt | 22 + .../quickcheck/generator/GenerationState.kt | 5 + .../utbot/quickcheck/generator/Generator.kt | 95 +++- .../org/utbot/quickcheck/generator/Lambdas.kt | 3 +- .../generator/java/lang/IntegerGenerator.kt | 5 +- .../java/util/CollectionGenerator.kt | 60 +- .../generator/java/util/MapGenerator.kt | 67 ++- .../generator/java/util/OptionalGenerator.kt | 4 +- .../java/util/OptionalIntGenerator.kt | 2 +- .../java/util/PropertiesGenerator.kt | 4 +- .../java/util/concurrent/CallableGenerator.kt | 4 + .../java/util/function/BiFunctionGenerator.kt | 5 + .../util/function/BiPredicateGenerator.kt | 5 + .../util/function/BinaryOperatorGenerator.kt | 5 + .../util/function/DoubleFunctionGenerator.kt | 5 + .../java/util/function/FunctionGenerator.kt | 5 + .../util/function/IntFunctionGenerator.kt | 4 + .../util/function/LongFunctionGenerator.kt | 5 + .../java/util/function/PredicateGenerator.kt | 5 + .../java/util/function/SupplierGenerator.kt | 5 + .../function/ToDoubleBiFunctionGenerator.kt | 5 + .../function/ToDoubleFunctionGenerator.kt | 5 + .../util/function/ToIntBiFunctionGenerator.kt | 5 + .../util/function/ToIntFunctionGenerator.kt | 4 + .../function/ToLongBiFunctionGenerator.kt | 5 + .../util/function/ToLongFunctionGenerator.kt | 5 + .../util/function/UnaryOperatorGenerator.kt | 5 + .../internal/ParameterTypeContext.kt | 10 +- .../internal/generator/ArrayGenerator.kt | 86 ++- .../internal/generator/CompositeGenerator.kt | 51 +- .../internal/generator/NullableGenerator.kt | 2 +- 55 files changed, 888 insertions(+), 914 deletions(-) create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashMapGenerator.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashtableGenerator.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/LinkedHashMapGenerator.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/MapGenerator.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/LinkedHashSetGenerator.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/SetGenerator.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/InstancesGenerator.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/FuzzerIllegalStateException.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationState.kt diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt index 5ec5b17dcb..ea6f173ac8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -13,7 +13,6 @@ import org.utbot.framework.util.sootMethod import org.utbot.instrumentation.ConcreteExecutor import java.lang.reflect.Field import java.lang.reflect.Method -import java.lang.reflect.Modifier import kotlin.random.Random class GreyBoxFuzzer( @@ -23,15 +22,15 @@ class GreyBoxFuzzer( ) { private val seeds = SeedCollector() - private val explorationStageIterations = 50 + private val explorationStageIterations = 100 private val exploitationStageIterations = 100 //TODO make it return Sequence suspend fun fuzz(): Sequence { logger.debug { "Started to fuzz ${methodUnderTest.name}" } val javaClazz = methodUnderTest.classId.jClass - val javaMethod = methodUnderTest.sootMethod.toJavaMethod()!! val sootMethod = methodUnderTest.sootMethod + val javaMethod = sootMethod.toJavaMethod()!! val classFieldsUsedByFunc = sootMethod.getClassFieldsUsedByFunc(javaClazz) val methodLines = sootMethod.activeBody.units.map { it.javaSourceStartLineNumber }.filter { it != -1 }.toSet() val currentCoverageByLines = CoverageCollector.coverage @@ -43,13 +42,12 @@ class GreyBoxFuzzer( javaMethod, explorationStageIterations, methodLines, - javaClazz, classFieldsUsedByFunc, methodUnderTest, currentCoverageByLines ) logger.debug { "SEEDS AFTER EXPLORATION STAGE = ${seeds.seedsSize()}" } - //exploitationStage(exploitationStageIterations, javaClazz, methodLines, currentCoverageByLines) + exploitationStage(exploitationStageIterations, javaClazz, methodLines, currentCoverageByLines) //UtModelGenerator.reset() return sequenceOf() } @@ -58,11 +56,32 @@ class GreyBoxFuzzer( method: Method, numberOfIterations: Int, methodLinesToCover: Set, - clazz: Class<*>, classFieldsUsedByFunc: Set, methodUnderTest: ExecutableId, prevMethodCoverage: Set ) { +// val param = method.parameters.first() +// val firstGenerator = GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(param, 0)!! +// var generator = firstGenerator +// println("GENERATOR = $generator") +// val generatedValue = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) +// println("GENERATED VALUE = $generatedValue") +// generator.generationState = GenerationState.CACHE +// val valueFromCache = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) +// println("VALUE FROM CACHE = $valueFromCache") +// //generator = firstGenerator.copy() +// generator.generationState = GenerationState.MODIFY +// val modifiedValue = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) +// println("MODIFIED VALUE = $modifiedValue") +// //generator = firstGenerator.copy() +// generator.generationState = GenerationState.MODIFY +// val modifiedValue2 = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) +// println("MODIFIED VALUE = $modifiedValue2") +// //generator = firstGenerator.copy() +// generator.generationState = GenerationState.MODIFY +// val modifiedValue3 = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) +// println("MODIFIED VALUE = $modifiedValue3") +// exitProcess(0) val parametersToGenericsReplacer = method.parameters.map { it to GenericsReplacer() } val thisInstancesHistory = ArrayDeque() repeat(numberOfIterations) { iterationNumber -> @@ -119,6 +138,7 @@ class GreyBoxFuzzer( ) seeds.addSeed(Seed(thisInstance, generatedParameters, seedScore.toDouble())) logger.debug { "Execution result: ${executionResult.result}" } + logger.debug { "Seed score = $seedScore" } } catch (e: Throwable) { logger.debug(e) { "Exception while execution :(" } thisInstancesHistory.clear() @@ -140,13 +160,14 @@ class GreyBoxFuzzer( .map { it.lineNumber } //.filter { it in currentMethodLines } .toSet() + val currentMethodCoverage = coverage.filter { it in currentMethodLines } executionResult.coverage.coveredInstructions.forEach { CoverageCollector.coverage.add(it) } - return (coverage - prevMethodCoverage).size + return (currentMethodCoverage - prevMethodCoverage).size } //TODO under construction - private fun exploitationStage( + private suspend fun exploitationStage( numberOfIterations: Int, clazz: Class<*>, methodLinesToCover: Set, @@ -154,10 +175,29 @@ class GreyBoxFuzzer( ) { logger.debug { "Exploitation began" } repeat(numberOfIterations) { + logger.debug { "Mutation iteration $it" } val randomSeed = seeds.getRandomWeightedSeed() ?: return@repeat - val randomSeedArgs = randomSeed.arguments.toMutableList() - val randomParameter = randomSeedArgs.random() - Mutator.mutateParameter(randomParameter) + logger.debug { "Random seed params = ${randomSeed.parameters}" } + val mutatedSeed = Mutator.mutateSeed(randomSeed, GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) + logger.debug { "Mutated params = ${mutatedSeed.parameters}" } + val stateBefore = mutatedSeed.createEnvironmentModels() + try { + val executionResult = execute(stateBefore, methodUnderTest) + logger.debug { "Execution result: $executionResult" } + val seedScore = + handleCoverage( + executionResult, + prevMethodCoverage, + methodLinesToCover + ) + mutatedSeed.score = seedScore.toDouble() + seeds.addSeed(mutatedSeed) + logger.debug { "Execution result: ${executionResult.result}" } + logger.debug { "Seed score = $seedScore" } + } catch (e: Throwable) { + logger.debug(e) { "Exception while execution :(" } + return@repeat + } } } // private suspend fun exploitationStage( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt index e0b267d358..b86ac46dd9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt @@ -11,7 +11,6 @@ import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.jClass -import soot.SootMethod import java.lang.reflect.Parameter object DataGenerator { @@ -22,20 +21,20 @@ object DataGenerator { clazz: Class<*>, random: SourceOfRandomness, status: GenerationStatus - ): UtModel? = generatorRepository.getOrProduceGenerator(clazz)?.generate(random, status) + ): UtModel? = generatorRepository.getOrProduceGenerator(clazz)?.generateImpl(random, status) fun generate( parameterTypeContext: ParameterTypeContext, random: SourceOfRandomness, status: GenerationStatus - ): UtModel? = generatorRepository.getOrProduceGenerator(parameterTypeContext, 0)?.generate(random, status) + ): UtModel? = generatorRepository.getOrProduceGenerator(parameterTypeContext, 0)?.generateImpl(random, status) fun generate( parameterTypeContext: ParameterTypeContext, random: SourceOfRandomness, status: GenerationStatus, depth: Int - ): UtModel? = generatorRepository.getOrProduceGenerator(parameterTypeContext, depth)?.generate(random, status) + ): UtModel? = generatorRepository.getOrProduceGenerator(parameterTypeContext, depth)?.generateImpl(random, status) fun generate( parameter: Parameter, @@ -74,7 +73,7 @@ object DataGenerator { repeat(numberOfTries) { logger.debug { "Try $it" } try { - generatedValue = generator.generate(random, status) + generatedValue = generator.generateImpl(random, status) return NormalMethodThisInstance( generatedValue, generator, @@ -105,7 +104,7 @@ object DataGenerator { repeat(numberOfTries) { logger.debug { "Try $it" } try { - generatedValue = generator.generate(random, status) + generatedValue = generator.generateImpl(random, status) return FParameter( parameter, null, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt index 8328b8c4c7..8a102976b3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt @@ -1,11 +1,13 @@ package org.utbot.engine.greyboxfuzzer.generator import org.utbot.engine.greyboxfuzzer.mutator.Mutator +import org.utbot.engine.greyboxfuzzer.util.copy import org.utbot.engine.greyboxfuzzer.util.getAllDeclaredFields import org.utbot.quickcheck.generator.Generator import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtCompositeModel import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.jClass import java.lang.reflect.Field @@ -51,10 +53,29 @@ data class FParameter( fun regenerateFields() { regenerateFields(classId.jClass.getAllDeclaredFields()) } + fun regenerateFields(fieldsToRegenerate: List) { if (utModel is UtAssembleModel) { utModel = Mutator.regenerateFields(classId.jClass, utModel as UtAssembleModel, fieldsToRegenerate) } } + fun copy(): FParameter = FParameter( + parameter, + value, + utModel.copy(), + generator?.copy(), + classId, + fields + ) + + fun replaceUtModel(newUtModel: UtModel): FParameter = FParameter( + parameter, + value, + newUtModel, + generator?.copy(), + classId, + fields + ) + } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt new file mode 100644 index 0000000000..e89f785a29 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt @@ -0,0 +1,33 @@ +package org.utbot.engine.greyboxfuzzer.generator + +import org.utbot.engine.greyboxfuzzer.util.copy +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtModel +import org.utbot.quickcheck.generator.Generator + +sealed interface ThisInstance { + val utModelForExecution: UtModel? + fun copy(): ThisInstance +} + +data class NormalMethodThisInstance( + val utModel: UtModel, + val generator: Generator, + val classId: ClassId +): ThisInstance { + override val utModelForExecution = utModel + override fun copy(): ThisInstance { + return NormalMethodThisInstance( + utModel.copy(), + generator.copy(), + classId + ) + } +} + +object StaticMethodThisInstance: ThisInstance { + override val utModelForExecution = null + override fun copy(): ThisInstance { + return StaticMethodThisInstance + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt index 0d276063a0..5acc8286e1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -7,9 +7,7 @@ import org.javaruntype.type.StandardTypeParameter import org.javaruntype.type.Types import org.utbot.common.withAccessibility import org.utbot.engine.greyboxfuzzer.generator.userclasses.UserClassGenerator -import org.utbot.engine.greyboxfuzzer.util.ReflectionUtils -import org.utbot.engine.greyboxfuzzer.util.getActualTypeArguments -import org.utbot.engine.greyboxfuzzer.util.toClass +import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.engine.logger import org.utbot.engine.rawType import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -24,6 +22,7 @@ import ru.vyarus.java.generics.resolver.context.GenericsContext import ru.vyarus.java.generics.resolver.context.GenericsInfo import ru.vyarus.java.generics.resolver.context.MethodGenericsContext import java.lang.reflect.* +import kotlin.random.Random fun Generator.getAllComponents(): List { @@ -216,59 +215,86 @@ private fun createStandardTypeParameter(type: org.javaruntype.type.Type<*>): Sta } } -//fun ParameterizedType.buildGenericsContext(): GenericsContext { -// val clazz = this.toClass()!! -// val klassTypeParams = clazz.typeParameters?.map { it.name } -// val gm = LinkedHashMap() -// klassTypeParams?.zip(this.actualTypeArguments)?.forEach { gm[it.first] = it.second } -// val m = mutableMapOf(clazz to gm) -// val genericsInfo = GenericsInfo(clazz, m) -// return GenericsContext(genericsInfo, clazz) -//} - -//fun Field.resolveFieldType(originalType: ParameterizedType): Type { -// return originalType.buildGenericsContext().resolveFieldType(this) -//} -// -//fun Field.resolveFieldType(genericsContext: GenericsContext): Type? = -// try { -// genericsContext.resolveFieldType(this) -// } catch (_: Throwable) { -// null -// } +object QuickCheckExtensions { -//fun Field.buildParameterContext(originalType: ParameterizedType): ParameterTypeContext { -// val ctx = originalType.buildGenericsContext() -// return createParameterTypeContext( -// this.name, -// this.annotatedType, -// this.declaringClass.name, -// Types.forJavaLangReflectType(ctx.resolveFieldType(this)), -// ctx -// ) -//} - -//fun Field.buildParameterContext(genericsContext: GenericsContext): ParameterTypeContext { -// return createParameterTypeContext( -// this.name, -// this.annotatedType, -// this.declaringClass.name, -// Types.forJavaLangReflectType(genericsContext.resolveFieldType(this)), -// genericsContext -// ) -//} -//@Deprecated("Not implemented") -//fun Type.buildParameterContext(): ParameterTypeContext? { -// val clazz = this.toClass() ?: return null -// return if (this is ParameterizedType) { -// buildParameterContext() -// } else { -// createParameterTypeContext( -// clazz.typeName, -// FakeAnnotatedTypeFactory.makeFrom(clazz), -// clazz.typeName, -// Types.forJavaLangReflectType(this), -// GenericsResolver.resolve(clazz) -// ) -// } -//} \ No newline at end of file + fun getRandomImplementerGenericContext(clazz: Class<*>, resolvedType: Type): GenericsContext? { + val sootClass = clazz.toSootClass() ?: return null + val implementers = + sootClass.getImplementersOfWithChain() + .filter { it.all { !it.toString().contains("$") } } + .filter { it.last().isConcrete } + val randomImplementersChain = + if (Random.getTrue(75)) { + implementers.shuffled().minByOrNull { it.size }?.drop(1) + } else { + implementers.randomOrNull()?.drop(1) + } ?: return null + //Deal with generics + val generics = mutableListOf>>() + var prevImplementer = clazz + resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> + if (prevImplementer.toClass() != null) { + generics.add(typeVariable to mutableListOf(prevImplementer.toClass()!!.typeParameters[index])) + } + } + for (implementer in randomImplementersChain) { + val javaImplementer = implementer.toJavaClass() ?: return null + val extendType = javaImplementer.let { it.genericInterfaces + it.genericSuperclass } + .find { it.toClass() == prevImplementer } + val tp = prevImplementer.typeParameters + prevImplementer = javaImplementer + if (tp.isEmpty()) continue + val newTp = extendType?.getActualTypeArguments()?.ifEmpty { return null } ?: return null + tp.mapIndexed { index, typeVariable -> typeVariable to newTp[index] } + .forEach { typeVar -> + val indexOfTypeParam = generics.indexOfFirst { it.second.last() == typeVar.first } + if (indexOfTypeParam != -1) { + generics[indexOfTypeParam].second.add(typeVar.second) + } + } + } + val g = + prevImplementer.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } + val gm = LinkedHashMap() + g.forEach { + if (it.value != null) { + gm[it.key] = it.value!! + } + } + val m = mutableMapOf(prevImplementer to gm) + return GenericsContext(GenericsInfo(prevImplementer, m), prevImplementer) + } + fun buildGenericsContextForInterfaceParent(resolvedType: Type, clazz: Class<*>, parentChain: List>): GenericsContext? { + val generics = mutableListOf>>() + var curClass = clazz + resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> + if (curClass.toClass() != null) { + generics.add(typeVariable to mutableListOf(curClass.toClass()!!.typeParameters[index])) + } + } + for (parent in parentChain) { + val parentType = curClass.let { it.genericInterfaces.toList() + listOf(it.genericSuperclass) } + .find { it.toClass() == parent } + val tp = curClass.typeParameters + curClass = parent + if (tp.isEmpty()) continue + val newTp = parentType?.getActualTypeArguments()?.ifEmpty { return null } ?: return null + tp.mapIndexed { index, typeVariable -> typeVariable to newTp[index] } + .forEach { typeVar -> + val indexOfTypeParam = generics.indexOfFirst { it.second.last() == typeVar.first } + if (indexOfTypeParam != -1) { + generics[indexOfTypeParam].second.add(curClass.typeParameters[indexOfTypeParam]) + } + } + } + val g = curClass.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } + val gm = LinkedHashMap() + g.forEach { + if (it.value != null) { + gm[it.key] = it.value!! + } + } + val m = mutableMapOf(curClass to gm) + return GenericsContext(GenericsInfo(curClass, m), curClass) + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt index bd8335a8fe..41a66f6cba 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt @@ -22,11 +22,11 @@ class UTGeneratorRepository(random: SourceOfRandomness) : GeneratorRepository(ra return generator } - override fun generatorsFor(parameter: ParameterTypeContext) = - super.generatorsFor(parameter).onEach { GeneratorConfigurator.configureGenerator(it, 85) } - - override fun generatorForArrayType(parameter: ParameterTypeContext) = - super.generatorForArrayType(parameter).also { GeneratorConfigurator.configureGenerator(it, 85) } +// override fun generatorsFor(parameter: ParameterTypeContext) = +// super.generatorsFor(parameter)//.onEach { GeneratorConfigurator.configureGenerator(it, 85) } +// +// override fun generatorForArrayType(parameter: ParameterTypeContext) = +// super.generatorForArrayType(parameter)//.also { GeneratorConfigurator.configureGenerator(it, 85) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashMapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashMapGenerator.kt deleted file mode 100644 index 480eab9a9c..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashMapGenerator.kt +++ /dev/null @@ -1,9 +0,0 @@ -//package org.utbot.engine.greyboxfuzzer.generator.map -// -//import java.util.* -// -//class HashMapGenerator : MapGenerator>(HashMap::class.java) { -// override fun okToAdd(key: Any?, value: Any?): Boolean { -// return key != null && value != null -// } -//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashtableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashtableGenerator.kt deleted file mode 100644 index 8ad61b5138..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/HashtableGenerator.kt +++ /dev/null @@ -1,9 +0,0 @@ -//package org.utbot.engine.greyboxfuzzer.generator.map -// -//import java.util.* -// -//class HashtableGenerator : MapGenerator>(Hashtable::class.java) { -// override fun okToAdd(key: Any?, value: Any?): Boolean { -// return key != null && value != null -// } -//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/LinkedHashMapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/LinkedHashMapGenerator.kt deleted file mode 100644 index b881f2f31e..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/LinkedHashMapGenerator.kt +++ /dev/null @@ -1,7 +0,0 @@ -//package org.utbot.engine.greyboxfuzzer.generator.map -// -//class LinkedHashMapGenerator : MapGenerator>(LinkedHashMap::class.java) { -// override fun okToAdd(key: Any?, value: Any?): Boolean { -// return key != null && value != null -// } -//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/MapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/MapGenerator.kt deleted file mode 100644 index 27cbd7dc63..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/map/MapGenerator.kt +++ /dev/null @@ -1,60 +0,0 @@ -//package org.utbot.engine.greyboxfuzzer.generator.map -// -//import org.utbot.quickcheck.generator.ComponentizedGenerator -//import org.utbot.quickcheck.generator.Distinct -//import org.utbot.quickcheck.generator.GenerationStatus -//import org.utbot.quickcheck.generator.Size -//import org.utbot.quickcheck.internal.Reflection -//import org.utbot.quickcheck.random.SourceOfRandomness -//import org.javaruntype.type.TypeParameter -//import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator -//import kotlin.random.Random -//import kotlin.system.exitProcess -// -//abstract class MapGenerator>(type: Class) : ComponentizedGenerator(type) { -// -// private var sizeRange: Size? = null -// private var distinct = false -// -// open fun configure(size: Size) { -// sizeRange = size -// } -// open fun configure(distinct: Distinct?) { -// this.distinct = distinct != null -// } -// -// override fun generate(random: SourceOfRandomness?, status: GenerationStatus?): T { -// val items = empty() -// val minSize = sizeRange?.min ?: GeneratorConfigurator.minCollectionSize -// val maxSize = sizeRange?.max ?: GeneratorConfigurator.maxCollectionSize -// val size = Random.nextInt(minSize, maxSize) -// val keyGenerator = componentGenerators().first() -// val valueGenerator = componentGenerators().last() -// repeat(size) { -// val key = keyGenerator.generate(random, status) -// val value = valueGenerator.generate(random, status) -// if (okToAdd(key, value)) { -// items[key] = value -// } -// } -// return items as T -// } -// -// override fun canGenerateForParametersOfTypes( -// typeParameters: List?> -// ): Boolean { -// return true -// } -// -// override fun numberOfNeededComponents(): Int { -// return 2 -// } -// -// protected fun empty(): MutableMap { -// return Reflection.instantiate(Reflection.findConstructor(types()[0])) as MutableMap -// } -// -// protected open fun okToAdd(key: Any?, value: Any?): Boolean { -// return true -// } -//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt deleted file mode 100644 index fd593a6a73..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/HashSetGenerator.kt +++ /dev/null @@ -1,5 +0,0 @@ -package org.utbot.engine.greyboxfuzzer.generator.set - -import org.utbot.quickcheck.generator.java.util.SetGenerator - -class HashSetGenerator: SetGenerator(HashSet::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/LinkedHashSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/LinkedHashSetGenerator.kt deleted file mode 100644 index ee2871e244..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/LinkedHashSetGenerator.kt +++ /dev/null @@ -1,3 +0,0 @@ -//package org.utbot.engine.greyboxfuzzer.generator.set -// -//class LinkedHashSetGenerator: SetGenerator>(LinkedHashSet::class.java) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/SetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/SetGenerator.kt deleted file mode 100644 index df6ce0f375..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/set/SetGenerator.kt +++ /dev/null @@ -1,43 +0,0 @@ -//package org.utbot.engine.greyboxfuzzer.generator.set -// -//import org.utbot.quickcheck.generator.GenerationStatus -//import org.utbot.quickcheck.generator.Size -//import org.utbot.quickcheck.generator.java.util.CollectionGenerator -//import org.utbot.quickcheck.internal.Reflection -//import org.utbot.quickcheck.random.SourceOfRandomness -//import org.javaruntype.type.TypeParameter -//import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator -//import kotlin.random.Random -// -//abstract class SetGenerator>(type: Class) : CollectionGenerator(type) { -// override fun configure(size: Size?) { -// super.configure(size) -// } -// -// override fun generate(random: SourceOfRandomness?, status: GenerationStatus?): T { -// val minSize = GeneratorConfigurator.minCollectionSize -// val maxSize = GeneratorConfigurator.maxCollectionSize -// val size = Random.nextInt(minSize, maxSize) -// val set = createSet() -// val valueGenerator = componentGenerators().first() -// repeat(size) { -// valueGenerator.generate(random, status)?.let { set.add(it) } -// } -// return set as T -// } -// -// override fun canGenerateForParametersOfTypes( -// typeParameters: List?> -// ): Boolean { -// return true -// } -// -// override fun numberOfNeededComponents(): Int { -// return 1 -// } -// -// fun createSet(): MutableSet { -// return Reflection.instantiate(Reflection.findConstructor(types()[0])) as MutableSet -// } -// -//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/InstancesGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/InstancesGenerator.kt deleted file mode 100644 index 8f170ea0c7..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/InstancesGenerator.kt +++ /dev/null @@ -1,521 +0,0 @@ -//@file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") -// -//package org.utbot.engine.greyboxfuzzer.generator.userclasses -// -//import org.utbot.quickcheck.internal.ParameterTypeContext -//import org.javaruntype.type.Types -//import org.utbot.engine.greyboxfuzzer.generator.DataGenerator -//import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGenerators -//import org.utbot.engine.greyboxfuzzer.generator.createParameterContextForParameter -//import org.utbot.engine.greyboxfuzzer.generator.getOrProduceGenerator -//import org.utbot.engine.greyboxfuzzer.util.* -//import org.utbot.engine.isPublic -//import org.utbot.external.api.classIdForType -//import org.utbot.framework.plugin.api.* -//import org.utbot.framework.plugin.api.util.* -//import ru.vyarus.java.generics.resolver.context.GenericsContext -//import ru.vyarus.java.generics.resolver.util.GenericsUtils -//import soot.Scene -//import sun.reflect.annotation.AnnotatedTypeFactory -//import sun.reflect.annotation.TypeAnnotation -//import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl -//import java.lang.reflect.* -//import java.util.* -//import kotlin.collections.LinkedHashMap -//import kotlin.random.Random -//import ru.vyarus.java.generics.resolver.context.container.ParameterizedTypeImpl as GParameterizedTypeImpl -// -//object InstancesGenerator { -// -// fun generateInstanceUsingConstructor( -// clazz: Class<*>, -// gctx: GenericsContext, -// initGenericContext: GenericsContext, -// depth: Int -// ): UtModel? { -// val randomPublicConstructor = -// try { -// clazz.declaredConstructors -// .filter { -// it.isPublic || !it.hasAtLeastOneOfModifiers( -// Modifier.PROTECTED, -// Modifier.PRIVATE -// ) -// } -// //Avoiding recursion -// .filter { it.parameterTypes.all { !it.name.contains(clazz.name) } } -// .chooseRandomConstructor() -// } catch (_: Throwable) { -// null -// } -// val randomConstructor = -// try { -// clazz.declaredConstructors -// .filter { it.parameterTypes.all { !it.name.contains(clazz.name) } } -// .toList().chooseRandomConstructor() -// } catch (_: Throwable) { -// null -// } -// val constructor = if (Random.getTrue(75)) randomPublicConstructor ?: randomConstructor else randomConstructor -// constructor ?: return null -// constructor.isAccessible = true -// val resolvedConstructor = -// gctx.constructor(constructor).let { -// try { -// it.toString() -// it -// } catch (_: Throwable) { -// initGenericContext.constructor(constructor) -// } -// } -// val parameterValues = constructor.parameters.withIndex().map { indexedParameter -> -// val parameterContext = -// createParameterContextForParameter(indexedParameter.value, indexedParameter.index, resolvedConstructor) -// val generator = GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator( -// parameterContext, -// depth -// ) -// println("GOT A GENERATOR $generator") -// try { -// generator?.generate(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) -// } catch (e: Exception) { -// null -// } -// } -// if (parameterValues.any { it == null }) { -// return UtNullModel(classIdForType(clazz)) -// } -// return UtModelGenerator.utModelConstructor.constructAssembleModelUsingMethodInvocation( -// clazz, -// constructor.executableId, -// parameterValues.filterNotNull() -// ) -//// return try { -//// //constructor.newInstance(*parameterValues.toTypedArray()) -//// UtNullModel(classIdForType(clazz)) -//// } catch (e: Exception) { -//// null -//// } catch (e: Error) { -//// null -//// } -// } -// -// //TODO rewrite this -// fun generateInstanceUsingStatics( -// resolvedType: org.javaruntype.type.Type<*>, -// gctx: GenericsContext, -// parameterTypeContext: ParameterTypeContext, -// depth: Int -// ): UtModel? { -// println("VIA STATIC FIELD") -// if (depth > GreyBoxFuzzerGenerators.maxDepthOfGeneration) return null -// //TODO filter not suitable methods with generics with bad bounds -// //TODO make it work for subtypes -// val resolvedStaticMethods = -// try { -// resolvedType.componentClass.declaredMethods.filter { it.hasModifiers(Modifier.STATIC, Modifier.PUBLIC) } -// .map { it to gctx.method(it).resolveReturnType() } -// .filter { it.first.returnType.toClass() == resolvedType.componentClass } -// .filter { it.first.parameterTypes.all { !it.name.contains(resolvedType.componentClass.name) } } -// } catch (e: Error) { -// listOf() -// } -// val resolvedStaticFields = -// try { -// resolvedType.componentClass.declaredFields.filter { it.hasModifiers(Modifier.STATIC, Modifier.PUBLIC) } -// .map { it to gctx.resolveFieldType(it) } -// .filter { it.first.type.toClass() == resolvedType.componentClass } -// } catch (e: Error) { -// listOf() -// } -// //println("FIELD = $resolvedStaticFields") -// val (fieldOrMethodToProvideInstance, typeToGenerate) = -// if (Random.nextBoolean()) { -// resolvedStaticFields.randomOrNull() ?: resolvedStaticMethods.randomOrNull() -// } else { -// resolvedStaticMethods.randomOrNull() ?: resolvedStaticFields.randomOrNull() -// } ?: return null -// val fieldValue = when (fieldOrMethodToProvideInstance) { -// is Field -> with(UtModelGenerator.utModelConstructor){ -// val generatedModelId = computeUnusedIdAndUpdate() -// val instantiationChain = mutableListOf() -// val generatedModel = UtAssembleModel( -// id = generatedModelId, -// classId = classIdForType(fieldOrMethodToProvideInstance.type), -// modelName = "xxx_$generatedModelId", -// instantiationChain = instantiationChain -// ) -// -// val fieldModelId = computeUnusedIdAndUpdate() -// val fieldModel = UtCompositeModel(fieldModelId, Field::class.java.id, isMock = false) -// -// val classModelId = computeUnusedIdAndUpdate() -// val classModel = UtCompositeModel(classModelId, Class::class.java.id, isMock = false) -// -// val classInstanceModel = construct(resolvedType.rawClass, classClassId) as UtReferenceModel -// -// instantiationChain += UtExecutableCallModel( -// instance = null, -// executable = methodId(Objects::class.java.id, "requireNonNull", objectClassId, objectClassId), -// params = listOf(classInstanceModel), -// returnValue = classModel -// ) -// -// instantiationChain += UtExecutableCallModel( -// classModel, -// Class<*>::getField.executableId, -// listOf(construct(fieldOrMethodToProvideInstance.name, stringClassId)), -// returnValue = fieldModel -// ) -// -// instantiationChain += UtExecutableCallModel( -// fieldModel, -// Field::get.executableId, -// listOf(UtNullModel(resolvedType.rawClass.id)), -// returnValue = generatedModel -// ) -// -// generatedModel -// -//// fieldOrMethodToProvideInstance.getFieldValue(null)?.let { -//// UtModelGenerator.utModelConstructor.construct(it, classIdForType(it::class.java)) -//// } ?: return null -// } -// is Method -> { -// val parameterValues = -// if (fieldOrMethodToProvideInstance.typeParameters.isNotEmpty()) { -// generateParameterValuesToFunctionsWithGenerics( -// fieldOrMethodToProvideInstance, -// gctx, -// resolvedType, -// parameterTypeContext, -// depth -// ) -// } else { -// fieldOrMethodToProvideInstance.parameters.map { parameter -> -// generateParameterValue( -// parameter, -// resolvedType.componentClass.name, -// gctx, -// false, -// null, -// depth -// ) -// } -// } -// fieldOrMethodToProvideInstance.isAccessible = true -// UtModelGenerator.utModelConstructor.constructAssembleModelUsingMethodInvocation( -// resolvedType.rawClass, -// fieldOrMethodToProvideInstance.executableId, -// parameterValues.filterNotNull() -// ) -// } -// else -> return null -// } -// return fieldValue -// } -// -// fun generateInterfaceInstanceViaStaticCall( -// method: Method, -// parameterTypeContext: ParameterTypeContext, -// depth: Int -// ): UtModel? { -// return try { -// val methodReturnTypeAsParameterizedType = method.genericReturnType as? ParameterizedType -// val actualTypeArguments = methodReturnTypeAsParameterizedType?.actualTypeArguments?.toList() ?: emptyList() -// val (generics, gctx) = method.resolveMethod(parameterTypeContext, actualTypeArguments) -// val args = method.parameters.mapIndexed { index, parameter -> -// val resolvedParameterType = GenericsUtils.resolveTypeVariables(parameter.parameterizedType, generics) -// createParameterContextForParameter(parameter, index, gctx, resolvedParameterType).let { ptx -> -// val generator = GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(ptx, depth) -// generator?.generate(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) -// } -// } -// method.isAccessible = true -// //method.invoke(null, *args.toTypedArray()) -// val clazzAsClass = method.genericReturnType.toClass() ?: return null -// UtModelGenerator.utModelConstructor.constructAssembleModelUsingMethodInvocation( -// clazzAsClass, -// method.executableId, -// args.filterNotNull() -// ) -// } catch (e: Throwable) { -// null -// } -// } -// -// //TODO finish someday -// fun generateFunctionalInterface( -// parameterTypeContext: ParameterTypeContext, -// depth: Int -// ): Any? { -// val clazz = parameterTypeContext.type().toClass() ?: return null -// val methodToImplement = clazz.methods.filterNot { -// it.hasModifiers(Modifier.STATIC) || it.toGenericString() -// .contains(" default ") || it.name == "equals" || it.name == "toString" || it.name == "hashCode" -// }.first() -// val (generics, gctx) = methodToImplement.resolveMethod(parameterTypeContext, clazz.typeParameters.toList()) -// val resolvedTypes = -// methodToImplement.parameters.mapIndexed { index, parameter -> -// val resolvedParameterType = GenericsUtils.resolveTypeVariables(parameter.parameterizedType, generics) -// createParameterContextForParameter(parameter, index, gctx, resolvedParameterType).resolved -// } -// val resolvedReturnType = gctx.method(methodToImplement).resolveReturnType() -// val methodToRef = Scene.v().classes.flatMap { it.methods } -// .filter { it.isStatic && it.returnType.toString() == resolvedReturnType.toString() } -// .filter { -// it.parameterTypes.joinToString() == resolvedTypes.map { it.convertToPrimitiveIfPossible() } -// .joinToString() -// } -// return null -// } -// -// private fun generateParameterValuesToFunctionsWithGenerics( -// method: Method, -// gctx: GenericsContext, -// resolvedType: org.javaruntype.type.Type<*>, -// parameterTypeContext: ParameterTypeContext, -// depth: Int -// ): List { -// val parameterType = parameterTypeContext.generics.resolveType(parameterTypeContext.type()) -// val generics = LinkedHashMap() -// (method.genericReturnType as? ParameterizedTypeImpl)?.actualTypeArguments?.forEachIndexed { index, typeVariable -> -// val actualTypeArg = (parameterType as? GParameterizedTypeImpl)?.actualTypeArguments?.get(index) -// if (actualTypeArg != null) { -// generics[typeVariable.typeName] = actualTypeArg -// } -// } -// gctx.method(method).methodGenericsMap().forEach { (s, type) -> generics.getOrPut(s) { type } } -// return method.parameters.map { parameter -> -// println("OLD TYPE = ${parameter.type}") -// val resolvedParameterType = GenericsUtils.resolveTypeVariables(parameter.parameterizedType, generics) -// println("NEW TYPE = ${resolvedParameterType}") -// val value = -// generateParameterValue( -// parameter, -// resolvedType.componentClass.name, -// gctx, -// false, -// resolvedParameterType, -// depth -// ) -// println("GENERATED VALUE = $value") -// value -// } -// } -// -// -// fun generateValueOfType( -// fieldOrParameterForGeneration: Any, -// gctx: GenericsContext, -// name: String, -// annotatedType: AnnotatedType, -// declaringTypeName: String, -// alternativeTypeContext: ParameterTypeContext, -// setAllObjectsToNull: Boolean, -// resolvedType: Type? = null, -// depth: Int -// ): UtModel? { -// //TODO!!!!!!! Make it work for inner classes -// if (fieldOrParameterForGeneration.toString().contains("$")) return null -// -// var clazz: Class<*>? -// val context = -// try { -// val finallyResolvedType = when (fieldOrParameterForGeneration) { -// is Field -> { -// clazz = fieldOrParameterForGeneration.type -// gctx.resolveFieldType(fieldOrParameterForGeneration) -// } -// is Parameter -> { -// clazz = fieldOrParameterForGeneration.type -// resolvedType ?: gctx.resolveType(fieldOrParameterForGeneration.parameterizedType) -// } -// else -> return null -// } -// ParameterTypeContext( -// name, -// AnnotatedTypeFactory.buildAnnotatedType( -// finallyResolvedType, -// TypeAnnotation.LocationInfo.BASE_LOCATION, -// arrayOf(), -// arrayOf(), -// null -// ), -// //annotatedType, -// declaringTypeName, -// Types.forJavaLangReflectType(finallyResolvedType), -// gctx -// ) -// } catch (e: java.lang.IllegalArgumentException) { -// clazz = alternativeTypeContext.type().toClass() -// alternativeTypeContext -// } -// if (!clazz!!.isPrimitive && setAllObjectsToNull) -// return null -// -// val generator = GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(context, depth) -// //generator.generate(DataGeneratorSettings.sourceOfRandomness, DataGeneratorSettings.genStatus) -// return generator?.generate(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) -// } -// -// private fun generateParameterValue( -// parameter: Parameter, -// clazzName: String, -// gctx: GenericsContext, -// setAllObjectsToNull: Boolean, -// resolvedType: Type? = null, -// depth: Int -// ): UtModel? = -// generateValueOfType( -// parameter, -// gctx, -// parameter.name, -// //parameter.declaringExecutable.let { it.declaringClass.name + '.' + it.name }, -// parameter.annotatedType, -// clazzName, -// ParameterTypeContext.forParameter(parameter), -// setAllObjectsToNull, -// resolvedType, -// depth -// ) -// -// // fun regenerateRandomFields(clazz: Class<*>, classInstance: Any, numOfFields: Int): Any? { -//// -//// } -//// fun regenerateRandomFields(clazz: Class<*>, classInstance: Any) { -//// val parameterTypeContext = ParameterTypeContext.forClass(clazz) -//// val fields = clazz.getAllDeclaredFields() -//// .filterNot { it.hasModifiers(Modifier.STATIC, Modifier.FINAL) } -//// .toMutableList() -//// repeat(Random.nextInt(0, 10)) { -//// val randomField = fields.randomOrNull() ?: return@repeat -//// if (Random.getTrue(20)) { -//// randomField.setDefaultValue(classInstance) -//// } else { -//// setNewFieldValue(randomField, parameterTypeContext, classInstance, 0, false) -//// } -//// fields.remove(randomField) -//// } -//// } -// -// fun regenerateFields(clazz: Class<*>, classInstance: UtAssembleModel, fieldsToRegenerate: List): UtModel { -// val parameterTypeContext = ParameterTypeContext.forClass(clazz) -// var resUtModel = classInstance -// for (field in fieldsToRegenerate) { -// resUtModel = setNewFieldValue(field, parameterTypeContext, resUtModel) -// } -// return resUtModel -// } -// -// private fun setNewFieldValue( -// field: Field, -// parameterTypeContext: ParameterTypeContext, -// clazzInstance: UtAssembleModel -// ): UtAssembleModel { -// field.isAccessible = true -// val oldFieldValue = field.getFieldValue(clazzInstance) -// if (field.hasAtLeastOneOfModifiers(Modifier.STATIC, Modifier.FINAL) && oldFieldValue != null) return clazzInstance -// val fieldType = parameterTypeContext.generics.resolveFieldType(field) -// println("F = $field TYPE = $fieldType OLDVALUE = $oldFieldValue") -// val parameterTypeContextForResolvedType = ParameterTypeContext( -// field.name, -// field.annotatedType, -// field.declaringClass.name, -// Types.forJavaLangReflectType(fieldType), -// parameterTypeContext.generics -// ) -// val newFieldValue = DataGenerator.generate( -// parameterTypeContextForResolvedType, -// GreyBoxFuzzerGenerators.sourceOfRandomness, -// GreyBoxFuzzerGenerators.genStatus -// ) -// println("NEW FIELD VALUE = $newFieldValue") -// if (newFieldValue != null) { -// return clazzInstance.addModification(UtDirectSetFieldModel(clazzInstance, field.fieldId, newFieldValue)) -// } -// return clazzInstance -//// val generator = DataGeneratorSettings.generatorRepository.getOrProduceGenerator( -//// parameterTypeContextForResolvedType, -//// 0 -//// ) ?: return null -//// if (isRecursiveWithUnsafe) { -//// (listOf(generator) + generator.getAllComponents()).forEach { -//// if (it is UserClassesGenerator) it.generationMethod = GenerationMethod.UNSAFE -//// } -//// } -//// println("I GOT GENERATOR!! $generator") -//// var newFieldValue: Any? = null -//// repeat(3) { -//// try { -//// if (newFieldValue == null) { -//// newFieldValue = -//// generator.generate(DataGeneratorSettings.sourceOfRandomness, DataGeneratorSettings.genStatus) -//// } -//// } catch (e: Exception) { -//// return@repeat -//// } -//// } -//// println("NEW VALUE GENERATED!!") -//// if (newFieldValue != null) { -//// try { -//// println("NEW VALUE = ${newFieldValue} CLASS ${newFieldValue!!::class.java}") -//// } catch (e: Throwable) { -//// println("NEW VALUE OF CLASS ${newFieldValue!!::class.java} generated") -//// } -//// } -//// if (newFieldValue != null) { -//// field.setFieldValue(clazzInstance, newFieldValue) -//// } -//// return newFieldValue -// } -// -//// fun generateInstanceWithUnsafe( -//// clazz: Class<*>, -//// depth: Int, -//// isRecursiveWithUnsafe: Boolean, -//// genericsContext: GenericsContext? -//// ): UtModel? { -//// println("TRYING TO GENERATE ${clazz.name} instance") -//// if (depth >= DataGeneratorSettings.maxDepthOfGeneration) return null -//// val clazzInstance = -//// try { -//// InstancesGenerator.generateInstanceViaConstructor( -//// resolvedJavaType.toClass()!!, -//// gctx, -//// parameterTypeContext!!.getGenericContext(), -//// depth -//// ) -//// val defaultConstructor = clazz.constructors.minByOrNull { it.parameterCount } ?: return null -//// } catch (e: Exception) { -//// return null -//// } catch (e: Error) { -//// return null -//// } -//// clazz.getAllDeclaredFields().forEach { field -> -//// try { -//// val ptx = genericsContext?.let { field.buildParameterContext(genericsContext) } -//// ?: ParameterTypeContext.forField(field) -//// val newFieldValue = setNewFieldValue(field, ptx, clazzInstance, depth, isRecursiveWithUnsafe) -//// println("SET ${field.name} value of type ${ptx.resolved} to $newFieldValue") -//// } catch (_: Throwable) { -//// println("CANT SET FIELD ${field.name}") -//// } -//// } -//// return UtNullModel(classIdForType(clazz)) -//// } -// -//// fun generateInstanceWithDefaultConstructorOrUnsafe(clazz: Class<*>): Any? { -//// val defaultConstructor = clazz.constructors.find { it.parameterCount == 0 } -//// return if (defaultConstructor != null) { -//// defaultConstructor.newInstance() -//// } else { -//// try { -//// UserClassesGenerator.UNSAFE.allocateInstance(clazz) -//// } catch (e: Throwable) { -//// null -//// } -//// } -//// } -// -//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt index 64e0299a12..5a74016470 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt @@ -10,12 +10,18 @@ import org.utbot.quickcheck.random.SourceOfRandomness import org.javaruntype.type.TypeParameter import org.utbot.engine.greyboxfuzzer.generator.* import org.utbot.engine.greyboxfuzzer.generator.userclasses.generator.* +import org.utbot.engine.greyboxfuzzer.mutator.Mutator import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.engine.logger +import org.utbot.framework.plugin.api.UtAssembleModel +import org.utbot.framework.plugin.api.UtDirectSetFieldModel import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.fieldId import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GenerationState import java.lang.reflect.* +import kotlin.random.Random class UserClassGenerator : ComponentizedGenerator(Any::class.java) { @@ -23,12 +29,15 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { var parameterTypeContext: ParameterTypeContext? = null var depth = 0 var generationMethod = GenerationMethod.ANY + private val mutatedFields = mutableMapOf() override fun copy(): Generator { return UserClassGenerator().also { it.clazz = clazz it.depth = depth it.parameterTypeContext = parameterTypeContext + it.generationMethod = generationMethod + it.mutatedFields.putAll(mutatedFields) } } @@ -42,10 +51,10 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { fun generate(random: SourceOfRandomness, status: GenerationStatus, generationMethod: GenerationMethod): UtModel? { this.generationMethod = generationMethod - return generate(random, status) + return generateImpl(random, status) } - override fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel { + private fun regenerate(random: SourceOfRandomness, status: GenerationStatus): UtModel { logger.debug { "Trying to generate ${parameterTypeContext!!.resolved}. Current depth depth: $depth" } if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return TODO("null") val immutableClazz = clazz!! @@ -76,4 +85,76 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { depth ).generate() } + + override fun modify(random: SourceOfRandomness, status: GenerationStatus): UtModel { + val cachedUtModel = + generatedUtModel as? UtAssembleModel ?: throw FuzzerIllegalStateException("Nothing to modify") + return if (Random.getTrue(80) && mutatedFields.isNotEmpty()) { + regenerateField(random, status, cachedUtModel) + } else { + setField(cachedUtModel) + } + } + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return modify(random, status) + } + + private fun regenerateField( + random: SourceOfRandomness, + status: GenerationStatus, + cachedUtModel: UtAssembleModel + ): UtModel { + val randomMutatedField = mutatedFields.keys.random() + val randomMutatedFieldGenerator = mutatedFields[randomMutatedField]!! + randomMutatedFieldGenerator.generationState = GenerationState.MODIFY + val newFieldValue = randomMutatedFieldGenerator.generateImpl(random, status) + val newModification = UtDirectSetFieldModel(cachedUtModel, randomMutatedField.fieldId, newFieldValue) + return cachedUtModel.addOrReplaceModification(newModification) + } + + private fun setField(cachedUtModel: UtAssembleModel): UtModel { + val sootClazz = clazz!!.toSootClass() ?: throw FuzzerIllegalStateException("Can't find soot class") + val randomField = clazz!!.getAllDeclaredFields().randomOrNull() ?: return cachedUtModel + val randomFieldDeclaringClass = randomField.declaringClass + val resolvedJavaType = parameterTypeContext!!.generics.resolveType(parameterTypeContext!!.type()) + val gctx = resolvedJavaType.createGenericsContext(clazz!!) + if (clazz == randomFieldDeclaringClass) { + return Mutator.regenerateFieldWithContext(gctx, cachedUtModel, randomField)?.let { + mutatedFields[randomField] = it.second + it.first + } ?: cachedUtModel + } else { + val chain = randomFieldDeclaringClass.toSootClass() + ?.getImplementersOfWithChain() + ?.filter { it.contains(sootClazz) } + ?.map { it.dropLastWhile { it != sootClazz } } + ?.minByOrNull { it.size } + ?.map { it.toJavaClass() } + if (chain == null || chain.isEmpty()) { + return cachedUtModel + } + val genericsContext = + QuickCheckExtensions.buildGenericsContextForInterfaceParent( + resolvedJavaType, + clazz!!, + chain.map { it!! }.reversed().drop(1) + ) ?: return cachedUtModel + return Mutator.regenerateFieldWithContext(genericsContext, cachedUtModel, randomField)?.let { + mutatedFields[randomField] = it.second + it.first + } ?: cachedUtModel + } + } + + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return if (generationState == GenerationState.MODIFY) { + modify(random, status) + } else { + regenerate(random, status) + }.also { generatedUtModel = it } + } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt index 173448cdf1..6edf453c5b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt @@ -4,6 +4,7 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.common.isAbstract import org.utbot.engine.greyboxfuzzer.generator.DataGenerator +import org.utbot.engine.greyboxfuzzer.generator.QuickCheckExtensions import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.executableId @@ -39,7 +40,7 @@ class InterfaceImplementationsInstanceGenerator( return it } } - val genericsContext = getRandomImplementerGenericContext(clazz, resolvedType) ?: return generateMock(clazz, resolvedType, typeContext) + val genericsContext = QuickCheckExtensions.getRandomImplementerGenericContext(clazz, resolvedType) ?: return generateMock(clazz, resolvedType, typeContext) return ClassesInstanceGenerator( genericsContext.currentClass(), genericsContext, @@ -68,7 +69,7 @@ class InterfaceImplementationsInstanceGenerator( if (chain == null || chain.any { it == null }) { null } else { - cl to buildGenericsContextForInterfaceParent(resolvedType, clazz, chain.map { it!! }.reversed().drop(1)) + cl to QuickCheckExtensions.buildGenericsContextForInterfaceParent(resolvedType, clazz, chain.map { it!! }.reversed().drop(1)) } } val allChainToGenericsContext = chainToGenericsContext + (clazz to typeContext) @@ -92,85 +93,37 @@ class InterfaceImplementationsInstanceGenerator( return UtCompositeModel(constructor.computeUnusedIdAndUpdate(), clazz.id, isMock = true, mocks = mocks) } - private fun getRandomImplementerGenericContext(clazz: Class<*>, resolvedType: Type): GenericsContext? { - val sootClass = clazz.toSootClass() ?: return null - val implementers = - sootClass.getImplementersOfWithChain() - .filter { it.all { !it.toString().contains("$") } } - .filter { it.last().isConcrete } - val randomImplementersChain = - if (Random.getTrue(75)) { - implementers.shuffled().minByOrNull { it.size }?.drop(1) - } else { - implementers.randomOrNull()?.drop(1) - } ?: return null - //Deal with generics - val generics = mutableListOf>>() - var prevImplementer = clazz - resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> - if (prevImplementer.toClass() != null) { - generics.add(typeVariable to mutableListOf(prevImplementer.toClass()!!.typeParameters[index])) - } - } - for (implementer in randomImplementersChain) { - val javaImplementer = implementer.toJavaClass() ?: return null - val extendType = javaImplementer.let { it.genericInterfaces + it.genericSuperclass } - .find { it.toClass() == prevImplementer } - val tp = prevImplementer.typeParameters - prevImplementer = javaImplementer - if (tp.isEmpty()) continue - val newTp = extendType?.getActualTypeArguments()?.ifEmpty { return null } ?: return null - tp.mapIndexed { index, typeVariable -> typeVariable to newTp[index] } - .forEach { typeVar -> - val indexOfTypeParam = generics.indexOfFirst { it.second.last() == typeVar.first } - if (indexOfTypeParam != -1) { - generics[indexOfTypeParam].second.add(typeVar.second) - } - } - } - val g = - prevImplementer.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } - val gm = LinkedHashMap() - g.forEach { - if (it.value != null) { - gm[it.key] = it.value!! - } - } - val m = mutableMapOf(prevImplementer to gm) - return GenericsContext(GenericsInfo(prevImplementer, m), prevImplementer) - } - - private fun buildGenericsContextForInterfaceParent(resolvedType: Type, clazz: Class<*>, parentChain: List>): GenericsContext? { - val generics = mutableListOf>>() - var curClass = clazz - resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> - if (curClass.toClass() != null) { - generics.add(typeVariable to mutableListOf(curClass.toClass()!!.typeParameters[index])) - } - } - for (parent in parentChain) { - val parentType = curClass.let { it.genericInterfaces.toList() + listOf(it.genericSuperclass) } - .find { it.toClass() == parent } - val tp = curClass.typeParameters - curClass = parent - if (tp.isEmpty()) continue - val newTp = parentType?.getActualTypeArguments()?.ifEmpty { return null } ?: return null - tp.mapIndexed { index, typeVariable -> typeVariable to newTp[index] } - .forEach { typeVar -> - val indexOfTypeParam = generics.indexOfFirst { it.second.last() == typeVar.first } - if (indexOfTypeParam != -1) { - generics[indexOfTypeParam].second.add(curClass.typeParameters[indexOfTypeParam]) - } - } - } - val g = curClass.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } - val gm = LinkedHashMap() - g.forEach { - if (it.value != null) { - gm[it.key] = it.value!! - } - } - val m = mutableMapOf(curClass to gm) - return GenericsContext(GenericsInfo(curClass, m), curClass) - } +// private fun buildGenericsContextForInterfaceParent(resolvedType: Type, clazz: Class<*>, parentChain: List>): GenericsContext? { +// val generics = mutableListOf>>() +// var curClass = clazz +// resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> +// if (curClass.toClass() != null) { +// generics.add(typeVariable to mutableListOf(curClass.toClass()!!.typeParameters[index])) +// } +// } +// for (parent in parentChain) { +// val parentType = curClass.let { it.genericInterfaces.toList() + listOf(it.genericSuperclass) } +// .find { it.toClass() == parent } +// val tp = curClass.typeParameters +// curClass = parent +// if (tp.isEmpty()) continue +// val newTp = parentType?.getActualTypeArguments()?.ifEmpty { return null } ?: return null +// tp.mapIndexed { index, typeVariable -> typeVariable to newTp[index] } +// .forEach { typeVar -> +// val indexOfTypeParam = generics.indexOfFirst { it.second.last() == typeVar.first } +// if (indexOfTypeParam != -1) { +// generics[indexOfTypeParam].second.add(curClass.typeParameters[indexOfTypeParam]) +// } +// } +// } +// val g = curClass.typeParameters.associate { tp -> tp.name to generics.find { it.second.last() == tp }?.first } +// val gm = LinkedHashMap() +// g.forEach { +// if (it.value != null) { +// gm[it.key] = it.value!! +// } +// } +// val m = mutableMapOf(curClass to gm) +// return GenericsContext(GenericsInfo(curClass, m), curClass) +// } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt index 6453164454..1b7b75c0d5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt @@ -30,7 +30,7 @@ class ObjectGenerator( val randomClass = potentialUsefulClasses.random() GreyBoxFuzzerGenerators.generatorRepository .getOrProduceGenerator(randomClass) - ?.generate(sourceOfRandomness, generationStatus) + ?.generateImpl(sourceOfRandomness, generationStatus) } else null potentialInterestingObjectReplacement?.let { return it } return GreyBoxFuzzerGenerators.generatorRepository @@ -39,6 +39,6 @@ class ObjectGenerator( .flatMap { it.second } .filter { !it.hasComponents() } .randomOrNull() - ?.generate(sourceOfRandomness, generationStatus) ?: UtNullModel(parameterTypeContext.rawClass.id) + ?.generateImpl(sourceOfRandomness, generationStatus) ?: UtNullModel(parameterTypeContext.rawClass.id) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt index 0bd4883594..c8b2b5b90a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt @@ -4,18 +4,19 @@ import org.javaruntype.type.Types import org.utbot.engine.greyboxfuzzer.generator.* import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.engine.logger -import org.utbot.external.api.classIdForType -import org.utbot.framework.concrete.UtModelConstructor import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.fieldId import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.method +import org.utbot.quickcheck.generator.GenerationState +import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.Generator import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.internal.generator.GeneratorRepository +import org.utbot.quickcheck.random.SourceOfRandomness +import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Field import java.lang.reflect.Modifier import kotlin.random.Random -import java.util.* object Mutator { @@ -33,47 +34,85 @@ object Mutator { return fParameter } + fun mutateSeed(seed: Seed, sourceOfRandomness: SourceOfRandomness, genStatus: GenerationStatus): Seed { + val seedCopy = seed.copy() + val randomParameterIndex = Random.nextInt(0, seedCopy.parameters.size) + val randomParameter = seedCopy.parameters.getOrNull(randomParameterIndex) ?: return seedCopy + val randomParameterGenerator = randomParameter.generator ?: return seedCopy + randomParameterGenerator.generationState = GenerationState.MODIFY + val newUtModel = randomParameterGenerator.generateImpl(sourceOfRandomness, genStatus) + val newFParameter = randomParameter.replaceUtModel(newUtModel) + return seedCopy.replaceFParameter(randomParameterIndex, newFParameter) + } + fun regenerateFields( clazz: Class<*>, classInstance: UtAssembleModel, fieldsToRegenerate: List ): UtModel { val parameterTypeContext = ParameterTypeContext.forClass(clazz) - val modifications = fieldsToRegenerate.mapNotNull { setNewFieldValue(it, parameterTypeContext, classInstance) } + val modifications = + fieldsToRegenerate.mapNotNull { setNewFieldValue(it, parameterTypeContext.generics, classInstance) } return classInstance.addModification(modifications) } - private fun setNewFieldValue( + fun regenerateFieldsWithContext( + genericsContext: GenericsContext, + classInstance: UtAssembleModel, + fieldsToRegenerate: List + ): UtModel { + val modifications = fieldsToRegenerate.mapNotNull { setNewFieldValue(it, genericsContext, classInstance) } + return classInstance.addModification(modifications) + } + + fun regenerateFieldWithContext( + genericsContext: GenericsContext, + classInstance: UtAssembleModel, + fieldToRegenerate: Field + ): Pair? = + setNewFieldValueWithGenerator( + fieldToRegenerate, + genericsContext, + classInstance + )?.let { (generator, modification) -> + classInstance.addOrReplaceModification(modification) to generator + } + + private fun setNewFieldValueWithGenerator( field: Field, - parameterTypeContext: ParameterTypeContext, + genericsContext: GenericsContext, clazzInstance: UtAssembleModel - ): UtStatementModel? { + ): Pair? { if (field.hasAtLeastOneOfModifiers( Modifier.STATIC, Modifier.FINAL ) ) return null - val fieldType = parameterTypeContext.generics.resolveFieldType(field) + val fieldType = genericsContext.resolveFieldType(field) logger.debug { "F = $field TYPE = $fieldType" } val parameterTypeContextForResolvedType = ParameterTypeContext( field.name, field.annotatedType, field.declaringClass.name, Types.forJavaLangReflectType(fieldType), - parameterTypeContext.generics + genericsContext ) - val newFieldValue = DataGenerator.generate( - parameterTypeContextForResolvedType, + val generatorForField = + GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(parameterTypeContextForResolvedType, 0) + ?: return null + val newFieldValue = generatorForField.generateImpl( GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus ) logger.debug { "NEW FIELD VALUE = $newFieldValue" } - if (newFieldValue != null) { - return UtDirectSetFieldModel(clazzInstance, field.fieldId, newFieldValue) - } - return null + return generatorForField to UtDirectSetFieldModel(clazzInstance, field.fieldId, newFieldValue) } + private fun setNewFieldValue( + field: Field, + genericsContext: GenericsContext, + clazzInstance: UtAssembleModel + ): UtStatementModel? = setNewFieldValueWithGenerator(field, genericsContext, clazzInstance)?.second fun mutateThisInstance( thisInstance: ThisInstance, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt index afcad6a248..eb507b5dc2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt @@ -2,10 +2,27 @@ package org.utbot.engine.greyboxfuzzer.mutator import org.utbot.engine.greyboxfuzzer.generator.FParameter import org.utbot.engine.greyboxfuzzer.generator.ThisInstance -import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.EnvironmentModels data class Seed( val thisInstance: ThisInstance, - val arguments: List, - val priority: Double = 0.0 -) \ No newline at end of file + val parameters: List, + var score: Double = 0.0 +) { + + fun createEnvironmentModels(): EnvironmentModels { + return EnvironmentModels(thisInstance.utModelForExecution, parameters.map { it.utModel }, mapOf()) + } + + fun copy(): Seed { + return Seed(thisInstance.copy(), parameters.map { it.copy() }, score) + } + + fun replaceFParameter(index: Int, newFParameter: FParameter): Seed { + return Seed( + thisInstance.copy(), + parameters.mapIndexed { ind, fParameter -> if (ind == index) newFParameter else fParameter.copy() }, + score + ) + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt index a90d05c909..4eaaa479f6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt @@ -1,17 +1,13 @@ package org.utbot.engine.greyboxfuzzer.mutator import org.utbot.engine.greyboxfuzzer.util.getTrue -import java.util.PriorityQueue -import java.util.TreeSet import kotlin.math.abs -import kotlin.math.exp -import kotlin.math.pow import kotlin.random.Random class SeedCollector(private val maxSize: Int = 50) { private val seeds = sortedSetOf( comparator = - compareByDescending { seed: Seed -> seed.priority }.thenComparator { seed1, seed2 -> if (seed1 === seed2) 0 else 1 } + compareByDescending { seed: Seed -> seed.score }.thenComparator { seed1, seed2 -> if (seed1 === seed2) 0 else 1 } ) fun addSeed(seed: Seed) { @@ -41,8 +37,8 @@ class SeedCollector(private val maxSize: Int = 50) { fun getRandomWeightedSeed() = if (Random.getTrue(75)) { - val bestSeed = getBestSeed().priority - seeds.filter { abs(it.priority - bestSeed) < 1e-5 }.randomOrNull() + val bestSeed = getBestSeed().score + seeds.filter { abs(it.score - bestSeed) < 1e-5 }.randomOrNull() } else { seeds.randomOrNull() } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/FuzzerIllegalStateException.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/FuzzerIllegalStateException.kt new file mode 100644 index 0000000000..618fc7a9e3 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/FuzzerIllegalStateException.kt @@ -0,0 +1,3 @@ +package org.utbot.engine.greyboxfuzzer.util + +class FuzzerIllegalStateException(msg: String): Exception(msg) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt index 9227e35565..93c791f5ed 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt @@ -18,9 +18,9 @@ import kotlin.reflect.jvm.javaMethod fun SootClass.getImplementersOfWithChain(): List> { this.checkLevel(SootClass.HIERARCHY) - if (!this.isInterface && !this.isAbstract) { - throw RuntimeException("interfaced needed; got $this") - } +// if (!this.isInterface && !this.isAbstract) { +// throw RuntimeException("interfaced needed; got $this") +// } val hierarchy = Hierarchy() val res = mutableListOf(mutableListOf(this)) val queue = ArrayDeque() diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt index 2fcb22419c..af147cc9cc 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt @@ -19,6 +19,49 @@ fun UtAssembleModel.addModification(modifications: List) = this.origin ) +fun UtAssembleModel.addOrReplaceModification(newModification: UtStatementModel): UtAssembleModel { + val newModificationChain = + when (newModification) { + is UtDirectSetFieldModel -> { + val oldChain = this.modificationsChain.filterIsInstance().toMutableList() + oldChain.indexOfFirst { newModification.fieldId == it.fieldId }.let { + if (it != -1) oldChain.removeAt(it) + } + oldChain.add(newModification) + oldChain.toList() + } + is UtExecutableCallModel -> { + val oldChain = this.modificationsChain.filterIsInstance().toMutableList() + oldChain.indexOfFirst { newModification.executable == it.executable }.let { + if (it != -1) oldChain.removeAt(it) + } + oldChain.add(newModification) + oldChain.toList() + } + } + + return UtAssembleModel( + this.id, + this.classId, + "${this.classId.name}#" + this.id?.toString(16), + this.instantiationCall, + newModificationChain, + this.origin + ) +} + +fun UtModel.copy(): UtModel = + when (this) { + is UtAssembleModel -> this.copy() + is UtCompositeModel -> this.copy() + is UtArrayModel -> this.copy() + is UtClassRefModel -> this.copy() + is UtPrimitiveModel -> this.copy() + is UtReferenceModel -> this.copy() + else -> this + } + + fun UtModelConstructor.constructAssembleModelUsingMethodInvocation( clazz: Class<*>, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt index fbaae6ca63..cd09d653f9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt @@ -151,7 +151,7 @@ open class TestCaseGenerator( controller.job = launch(currentUtContext) { if (!isActive) return@launch //TODO remove - if (!method.name.contains("readString")) return@launch + if (!method.name.contains("testFunc3")) return@launch try { //yield one to diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt index 10b40152fb..62aa06eaaf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt @@ -1,7 +1,10 @@ package org.utbot.quickcheck.generator import org.javaruntype.type.TypeParameter +import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException +import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.internal.Reflection +import org.utbot.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedType import java.util.Collections @@ -59,6 +62,19 @@ abstract class ComponentizedGenerator constructor(type: Class<*>) : Generator(ty } } + abstract fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel + protected open fun modify( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val cachedModel = generatedUtModel ?: throw FuzzerIllegalStateException("Nothing to modify") + val randomNestedGenerator = nestedGeneratorsRecursiveWithoutThis().randomOrNull() ?: return cachedModel + getAllGeneratorsBetween(this, randomNestedGenerator)?.forEach { + it.generationState = GenerationState.MODIFYING_CHAIN + } + randomNestedGenerator.generationState = GenerationState.REGENERATE + return createModifiedUtModel(random, status) + } override fun configure(annotatedType: AnnotatedType?) { super.configure(annotatedType) val annotatedComponentTypes = Reflection.annotatedComponentTypes(annotatedType) @@ -75,4 +91,10 @@ abstract class ComponentizedGenerator constructor(type: Class<*>) : Generator(ty fun componentGenerators(): List { return Collections.unmodifiableList(components) } + + override fun copy(): Generator { + return (super.copy() as ComponentizedGenerator).also { + it.components.addAll(components.map { it.copy() }) + } + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationState.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationState.kt new file mode 100644 index 0000000000..253c11f705 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationState.kt @@ -0,0 +1,5 @@ +package org.utbot.quickcheck.generator + +enum class GenerationState { + REGENERATE, CACHE, MODIFY, MODIFYING_CHAIN +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt index 6d0cc8435f..2d445af178 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt @@ -3,9 +3,15 @@ package org.utbot.quickcheck.generator import org.javaruntype.type.TypeParameter import org.javaruntype.type.Types import org.javaruntype.type.WildcardTypeParameter +import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator +import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException +import org.utbot.engine.greyboxfuzzer.util.getImplementersOfWithChain +import org.utbot.engine.greyboxfuzzer.util.removeIfAndReturnRemovedElements +import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.internal.Reflection import org.utbot.quickcheck.internal.ReflectionException import org.utbot.quickcheck.random.SourceOfRandomness +import soot.SootClass import java.lang.reflect.AnnotatedElement import java.lang.reflect.AnnotatedType import java.lang.reflect.Method @@ -19,6 +25,83 @@ import java.lang.annotation.Annotation as JavaAnnotation abstract class Generator protected constructor(types: List>) : Gen { private val types: MutableList> = ArrayList() private var repo: Generators? = null + var generatedUtModel: UtModel? = null + var generationState = GenerationState.REGENERATE + var nestedGenerators = mutableListOf() + + open fun generateImpl(random: SourceOfRandomness, status: GenerationStatus): UtModel = + when (generationState) { + GenerationState.REGENERATE -> { + generate(random, status).also { + generatedUtModel = it + nestedGeneratorsRecursive().forEach { + it.generationState = GenerationState.CACHE + } + } + } + GenerationState.CACHE -> { + generatedUtModel ?: throw FuzzerIllegalStateException("No cached model") + } + GenerationState.MODIFY -> { + withModification { + generate(random, status).also { generatedUtModel = it } + } + } + GenerationState.MODIFYING_CHAIN -> { + generate(random, status).also { + generatedUtModel = it + nestedGeneratorsRecursive().forEach { + it.generationState = GenerationState.CACHE + } + } + } + } + + private fun flattenedTo(destination: MutableList) { + destination.add(this) + nestedGenerators.forEach { it.flattenedTo(destination) } + } + + fun nestedGeneratorsRecursive(): List { + val allGenerators = mutableListOf() + this.flattenedTo(allGenerators) + return allGenerators + } + + fun nestedGeneratorsRecursiveWithoutThis() = nestedGeneratorsRecursive().filter { it != this } + + private fun genRandomNestedGenerator(): Generator? { + val queue = ArrayDeque() + val res = mutableListOf() + queue.add(this) + while (queue.isNotEmpty()) { + val el = queue.removeFirst() + res.add(el) + } + return res.randomOrNull() + } + + protected fun getAllGeneratorsBetween(start: Generator, end: Generator): List? { + val res = mutableListOf(mutableListOf(start)) + val queue = ArrayDeque() + queue.add(start) + while (queue.isNotEmpty()) { + val curGenerator = queue.removeFirst() + if (curGenerator == end) break + val nestedGenerators = curGenerator.nestedGenerators + if (nestedGenerators.isEmpty()) continue + val oldLists = res.removeIfAndReturnRemovedElements { it.last() == curGenerator } + for (implementer in nestedGenerators) { + queue.add(implementer) + oldLists.forEach { res.add((it + listOf(implementer)).toMutableList()) } + } + } + return res.find { it.last() == end }?.drop(1)?.dropLast(1) + } + + private fun getAllGeneratorsBetween(currentPath: MutableList, end: Generator) { + + } /** * @param type class token for type of property parameter this generator is @@ -173,7 +256,12 @@ abstract class Generator protected constructor(types: List>) : Gen { * @return a copy of the receiver */ open fun copy(): Generator { - return Reflection.instantiate(javaClass) as Generator + return Reflection.instantiate(javaClass).also { + it.generatedUtModel = generatedUtModel + it.generationState = generationState + it.nestedGenerators = nestedGenerators.map { it.copy() }.toMutableList() + GeneratorConfigurator.configureGenerator(it, 85) + } } /** @@ -248,6 +336,11 @@ abstract class Generator protected constructor(types: List>) : Gen { if (configurer != null) Reflection.invoke(configurer, this, configuration) } + protected fun withModification(block: () -> T): T { + generationState = GenerationState.MODIFY + return block.invoke().also { generationState = GenerationState.CACHE } + } + companion object { /** * @param parameter a generic type parameter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt index 6de2acd24a..44da9484c6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt @@ -8,7 +8,6 @@ import org.utbot.quickcheck.random.SourceOfRandomness import java.lang.reflect.InvocationHandler import java.lang.reflect.Method import java.lang.reflect.Proxy -import java.util.Arrays import java.util.Random /** @@ -40,7 +39,7 @@ class Lambdas private constructor() { source, attempts ) - return returnValueGenerator.generate(source, status) + return returnValueGenerator.generateImpl(source, status) } private fun handleObjectMethod( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt index 064683e292..36cd3d2437 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt @@ -34,12 +34,11 @@ class IntegerGenerator : IntegralGenerator(listOf(Int::class.javaObjectType)) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(generateValue(random, status), intWrapperClassId) + return utModelConstructor.construct(generateValue(random), intWrapperClassId) } fun generateValue( - random: SourceOfRandomness, - status: GenerationStatus? + random: SourceOfRandomness ): Int { return random.nextInt(min, max) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt index dfedb2f3c8..86f80a1aab 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt @@ -1,18 +1,12 @@ package org.utbot.quickcheck.generator.java.util +import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor -import org.utbot.framework.plugin.api.ConstructorId -import org.utbot.framework.plugin.api.MethodId -import org.utbot.framework.plugin.api.UtAssembleModel -import org.utbot.framework.plugin.api.UtExecutableCallModel -import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.booleanClassId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.Distinct -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Size +import org.utbot.quickcheck.generator.* import org.utbot.quickcheck.internal.Ranges import org.utbot.quickcheck.random.SourceOfRandomness @@ -64,13 +58,39 @@ abstract class CollectionGenerator(type: Class<*>) : ComponentizedGenerator(type this.distinct = distinct } - override fun generate( + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + val cachedModel = generatedUtModel ?: throw FuzzerIllegalStateException("Nothing to modify") + val collectionClassId = types().single().id + val collectionConstructorId = ConstructorId(collectionClassId, emptyList()) + val genId = cachedModel.getIdOrThrow() + return UtAssembleModel( + genId, + cachedModel.classId, + collectionConstructorId.name + "#" + genId, + UtExecutableCallModel(null, collectionConstructorId, emptyList()) + ) { + val addMethodId = MethodId(classId, "add", booleanClassId, listOf(objectClassId)) + (0 until nestedGenerators.size).map { ind -> + val generator = nestedGenerators[ind] + val item = generator.generateImpl(random, status) + generator.generationState = GenerationState.CACHE + UtExecutableCallModel( + this, + addMethodId, + listOf(item) + ) + } + } + } + + private fun regenerate( random: SourceOfRandomness, status: GenerationStatus ): UtModel { + nestedGenerators.clear() val collectionClassId = types().single().id val collectionConstructorId = ConstructorId(collectionClassId, emptyList()) - val genId = utModelConstructor.computeUnusedIdAndUpdate() return UtAssembleModel( genId, @@ -78,16 +98,28 @@ abstract class CollectionGenerator(type: Class<*>) : ComponentizedGenerator(type collectionConstructorId.name + "#" + genId, UtExecutableCallModel(null, collectionConstructorId, emptyList()), ) { - val addMethodId = MethodId(classId, "add", booleanClassId, listOf(objectClassId)) val size = size(random, status) - val generator = componentGenerators().first() (0..size).map { - val item = generator.generate(random, status) + val addMethodId = MethodId(classId, "add", booleanClassId, listOf(objectClassId)) + val generator = componentGenerators().first().copy().also { nestedGenerators.add(it) } + val item = generator.generateImpl(random, status) UtExecutableCallModel(this, addMethodId, listOf(item)) } } } + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel = + when (generationState) { + GenerationState.REGENERATE -> regenerate(random, status) + GenerationState.MODIFY -> modify(random, status) + GenerationState.MODIFYING_CHAIN -> createModifiedUtModel(random, status) + GenerationState.CACHE -> generatedUtModel ?: throw FuzzerIllegalStateException("No cached model") + } + + override fun numberOfNeededComponents(): Int { return 1 } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt index affa2d5426..d58ebbff4d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt @@ -1,17 +1,12 @@ package org.utbot.quickcheck.generator.java.util +import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor -import org.utbot.framework.plugin.api.ConstructorId -import org.utbot.framework.plugin.api.MethodId -import org.utbot.framework.plugin.api.UtAssembleModel -import org.utbot.framework.plugin.api.UtExecutableCallModel -import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.booleanClassId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.Distinct -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Size +import org.utbot.quickcheck.generator.* import org.utbot.quickcheck.internal.Ranges import org.utbot.quickcheck.random.SourceOfRandomness @@ -59,17 +54,41 @@ abstract class MapGenerator protected constructor(type: Class<*>) : Componentize this.distinct = distinct != null } - override fun generate( + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + val cachedUtModel = generatedUtModel ?: throw FuzzerIllegalStateException("Nothing to modify") + val size = nestedGenerators.size / 2 + val classId = types().single().id + + val modelId = cachedUtModel.getIdOrThrow() + val constructorId = ConstructorId(classId, emptyList()) + return UtAssembleModel( + modelId, + classId, + constructorId.name + "#" + modelId, + UtExecutableCallModel(null, constructorId, emptyList()), + ) { + val putMethodId = MethodId(classId, "put", objectClassId, listOf(objectClassId, objectClassId)) + (0 until size).map { ind -> + val keyGenerator = nestedGenerators[ind * 2] + val valueGenerator = nestedGenerators[ind * 2 + 1] + val key = keyGenerator.generateImpl(random, status) + val value = valueGenerator.generateImpl(random, status) + keyGenerator.generationState = GenerationState.CACHE + valueGenerator.generationState = GenerationState.CACHE + UtExecutableCallModel(this, putMethodId, listOf(key, value)) + } + } + } + private fun regenerate( random: SourceOfRandomness, status: GenerationStatus ): UtModel { val size = size(random, status) val classId = types().single().id - val keyGenerator = componentGenerators()[0] - val valueGenerator = componentGenerators()[1] val generatedModelId = utModelConstructor.computeUnusedIdAndUpdate() val constructorId = ConstructorId(classId, emptyList()) + nestedGenerators.clear() return UtAssembleModel( generatedModelId, classId, @@ -77,18 +96,28 @@ abstract class MapGenerator protected constructor(type: Class<*>) : Componentize UtExecutableCallModel(null, constructorId, emptyList()), ) { val putMethodId = MethodId(classId, "put", objectClassId, listOf(objectClassId, objectClassId)) - generateSequence { - val key = keyGenerator.generate(random, status) - val value = valueGenerator.generate(random, status) + (0..size).map { + val keyGenerator = componentGenerators()[0].copy().also { nestedGenerators.add(it) } + val valueGenerator = componentGenerators()[1].copy().also { nestedGenerators.add(it) } + val key = keyGenerator.generateImpl(random, status) + val value = valueGenerator.generateImpl(random, status) key to value - }.filter { (key, value) -> - okToAdd(key, value) - }.map { (key, value) -> UtExecutableCallModel(this, putMethodId, listOf(key, value)) - }.take(size).toList() + } } } + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel = + when (generationState) { + GenerationState.REGENERATE -> regenerate(random, status) + GenerationState.MODIFY -> modify(random, status) + GenerationState.MODIFYING_CHAIN -> createModifiedUtModel(random, status) + GenerationState.CACHE -> generatedUtModel ?: throw FuzzerIllegalStateException("No cached model") + } + override fun numberOfNeededComponents(): Int { return 2 } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt index 145c81a245..52a1122e45 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt @@ -28,7 +28,7 @@ class OptionalGenerator : ComponentizedGenerator(Optional::class.java) { classId ) } - val value = componentGenerators().first().generate(random, status) + val value = componentGenerators().first().generateImpl(random, status) val constructorId = methodId(classId, "of", classId, objectClassId) val generatedModelId = utModelConstructor.computeUnusedIdAndUpdate() return UtAssembleModel( @@ -39,6 +39,8 @@ class OptionalGenerator : ComponentizedGenerator(Optional::class.java) { ) } + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel = generate(random, status) + override fun numberOfNeededComponents(): Int { return 1 } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt index ae44fe35a7..e7d0800daa 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt @@ -36,7 +36,7 @@ class OptionalIntGenerator : Generator(OptionalInt::class.java) { ): UtModel { val trial = random.nextDouble() val generated = - if (trial < 0.25) OptionalInt.empty() else OptionalInt.of(integers.generateValue(random, status)) + if (trial < 0.25) OptionalInt.empty() else OptionalInt.of(integers.generateValue(random)) return utModelConstructor.construct(generated, classIdForType(OptionalInt::class.java)) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt index 966622531a..219989a4e5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt @@ -47,8 +47,8 @@ class PropertiesGenerator : Generator(Properties::class.java) { ) { val setPropertyMethodId = methodId(classId, "setProperty", objectClassId, objectClassId, objectClassId) (0..size).map { - val key = stringGenerator.generate(random, status) - val value = stringGenerator.generate(random, status) + val key = stringGenerator.generateImpl(random, status) + val value = stringGenerator.generateImpl(random, status) UtExecutableCallModel(this, setPropertyMethodId, listOf(key, value)) } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt index 0568d602ea..e95a99180a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt @@ -29,6 +29,10 @@ class CallableGenerator : ComponentizedGenerator(Callable::class.java) { ) } + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun numberOfNeededComponents(): Int { return 1 } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt index 6bce20ecc0..791db315c6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt @@ -17,6 +17,11 @@ import java.util.function.BiFunction * @param return type of produced function
*/ class BiFunctionGenerator : ComponentizedGenerator(BiFunction::class.java) { + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt index 36bd48ce17..17029167ff 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt @@ -19,6 +19,11 @@ import java.util.function.BiPredicate
*/ class BiPredicateGenerator : ComponentizedGenerator(BiPredicate::class.java) { private var generator: Generator? = null + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun provide(provided: Generators) { super.provide(provided) generator = gen()!!.type(Boolean::class.javaPrimitiveType!!) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt index 70ce25c141..e3ffca3196 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt @@ -15,6 +15,11 @@ import java.util.function.BinaryOperator * @param parameters type and return type of produced operator */ class BinaryOperatorGenerator : ComponentizedGenerator(BinaryOperator::class.java) { + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt index bd0640ce49..b3ad545ece 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt @@ -15,6 +15,11 @@ import java.util.function.DoubleFunction * @param return type of produced function */ class DoubleFunctionGenerator : ComponentizedGenerator(DoubleFunction::class.java) { + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt index 1fed09b2cf..6ef73fa2b0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt @@ -16,6 +16,11 @@ import java.util.function.Function * @param return type of produced function */ class FunctionGenerator : ComponentizedGenerator(Function::class.java) { + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt index 029f3893c2..bf50202497 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt @@ -15,6 +15,10 @@ import java.util.function.IntFunction * @param return type of produced function */ class IntFunctionGenerator : ComponentizedGenerator(IntFunction::class.java) { + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt index b4bed86de6..211213b141 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt @@ -15,6 +15,11 @@ import java.util.function.LongFunction * @param return type of produced function */ class LongFunctionGenerator : ComponentizedGenerator(LongFunction::class.java) { + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt index 7e13e1743e..ec01e9b9b2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt @@ -18,6 +18,11 @@ import java.util.function.Predicate
*/ class PredicateGenerator : ComponentizedGenerator(Predicate::class.java) { private var generator: Generator? = null + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun provide(provided: Generators) { super.provide(provided) generator = gen()!!.type(Boolean::class.javaPrimitiveType!!) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt index 439a0a9841..92baad9a0c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt @@ -15,6 +15,11 @@ import java.util.function.Supplier * @param the type of the values produced by the generated instances */ class SupplierGenerator : ComponentizedGenerator(Supplier::class.java) { + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt index 1f7623e601..f49ac18fad 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt @@ -19,6 +19,11 @@ import java.util.function.ToDoubleBiFunction */ class ToDoubleBiFunctionGenerator : ComponentizedGenerator(ToDoubleBiFunction::class.java) { private var generator: Generator? = null + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun provide(provided: Generators) { super.provide(provided) generator = gen()!!.type(Double::class.javaPrimitiveType!!) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt index 1dedf3a68f..c55a1ac1ab 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt @@ -18,6 +18,11 @@ import java.util.function.ToDoubleFunction */ class ToDoubleFunctionGenerator : ComponentizedGenerator(ToDoubleFunction::class.java) { private var generator: Generator? = null + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun provide(provided: Generators) { super.provide(provided) generator = gen()!!.type(Double::class.javaPrimitiveType!!) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt index f42f0b4a25..435bc2119a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt @@ -19,6 +19,11 @@ import java.util.function.ToIntBiFunction */ class ToIntBiFunctionGenerator : ComponentizedGenerator(ToIntBiFunction::class.java) { private var generator: Generator? = null + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun provide(provided: Generators) { super.provide(provided) generator = gen()!!.type(Int::class.javaPrimitiveType!!) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt index 19a66a881e..186bd712bd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt @@ -23,6 +23,10 @@ class ToIntFunctionGenerator : ComponentizedGenerator(ToIntFunction::class.ja generator = gen()!!.type(Int::class.javaPrimitiveType!!) } + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt index ff4a80d08d..13925ddcfb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt @@ -19,6 +19,11 @@ import java.util.function.ToLongBiFunction */ class ToLongBiFunctionGenerator : ComponentizedGenerator(ToLongBiFunction::class.java) { private var generator: Generator? = null + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun provide(provided: Generators) { super.provide(provided) generator = gen()!!.type(Long::class.javaPrimitiveType!!) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt index 50515db607..f1a8b0f883 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt @@ -18,6 +18,11 @@ import java.util.function.ToLongFunction
*/ class ToLongFunctionGenerator : ComponentizedGenerator(ToLongFunction::class.java) { private var generator: Generator? = null + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun provide(provided: Generators) { super.provide(provided) generator = gen()!!.type(Long::class.javaPrimitiveType!!) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt index 0d5ee7f5fd..9d3f4589ea 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt @@ -15,6 +15,11 @@ import java.util.function.UnaryOperator * @param type of parameter and return type of produced operator */ class UnaryOperatorGenerator : ComponentizedGenerator(UnaryOperator::class.java) { + + override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { + return generate(random, status) + } + override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt index d023ff18fb..39cb99e9d0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt @@ -305,7 +305,15 @@ class ParameterTypeContext( generics ) } - + fun forField(field: Field, generics: GenericsContext): ParameterTypeContext { + return ParameterTypeContext( + field.name, + field.annotatedType, + field.declaringClass.name, + Types.forJavaLangReflectType(generics.resolveFieldType(field)), + generics + ) + } fun forParameter(parameter: Parameter): ParameterTypeContext { val exec = parameter.declaringExecutable val clazz = exec.declaringClass diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt index 072fc90299..2f1a5cfb94 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt @@ -1,10 +1,13 @@ package org.utbot.quickcheck.internal.generator +import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator +import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtArrayModel import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.getIdOrThrow import org.utbot.framework.plugin.api.util.booleanArrayClassId import org.utbot.framework.plugin.api.util.byteArrayClassId import org.utbot.framework.plugin.api.util.charArrayClassId @@ -13,13 +16,8 @@ import org.utbot.framework.plugin.api.util.doubleArrayClassId import org.utbot.framework.plugin.api.util.floatArrayClassId import org.utbot.framework.plugin.api.util.intArrayClassId import org.utbot.framework.plugin.api.util.longArrayClassId -import org.utbot.framework.plugin.api.util.objectArrayClassId import org.utbot.framework.plugin.api.util.shortArrayClassId -import org.utbot.quickcheck.generator.Distinct -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.Size +import org.utbot.quickcheck.generator.* import org.utbot.quickcheck.internal.Ranges import org.utbot.quickcheck.internal.Reflection import org.utbot.quickcheck.random.SourceOfRandomness @@ -51,10 +49,46 @@ class ArrayGenerator(private val componentType: Class<*>, val component: Generat this.distinct = distinct != null } - override fun generate( + private fun modify( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val cachedModel = generatedUtModel ?: throw FuzzerIllegalStateException("Nothing to modify") + val randomNestedGenerator = nestedGeneratorsRecursiveWithoutThis().randomOrNull() ?: return cachedModel + getAllGeneratorsBetween(this, randomNestedGenerator)?.forEach { + it.generationState = GenerationState.MODIFYING_CHAIN + } + randomNestedGenerator.generationState = GenerationState.REGENERATE + return createModifiedUtModel(random, status) + } + + private fun createModifiedUtModel( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val cachedModel = generatedUtModel ?: throw FuzzerIllegalStateException("Nothing to modify") + val length = nestedGenerators.size + val componentTypeId = classIdForType(componentType) + val modelId = cachedModel.getIdOrThrow() + return UtArrayModel( + modelId, + getClassIdForArrayType(componentType), + length, + componentTypeId.defaultValueModel(), + (0 until length).associateWithTo(hashMapOf()) { ind -> + val generator = nestedGenerators[ind] + val item = generator.generateImpl(random, status) + generator.generationState = GenerationState.CACHE + item + } + ) + } + + private fun regenerate( random: SourceOfRandomness, status: GenerationStatus ): UtModel { + nestedGenerators.clear() val length = length(random, status) val componentTypeId = classIdForType(componentType) val modelId = utModelConstructor.computeUnusedIdAndUpdate() @@ -63,10 +97,36 @@ class ArrayGenerator(private val componentType: Class<*>, val component: Generat getClassIdForArrayType(componentType), length, componentTypeId.defaultValueModel(), - (0 until length).associateWithTo(hashMapOf()) { component.generate(random, status) } + (0 until length).associateWithTo(hashMapOf()) { + val generator = component.copy() + nestedGenerators.add(generator) + generator.generateImpl(random, status) + } ) } + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel = + when (generationState) { + GenerationState.REGENERATE -> regenerate(random, status) + GenerationState.MODIFY -> modify(random, status) + GenerationState.MODIFYING_CHAIN -> createModifiedUtModel(random, status) + GenerationState.CACHE -> generatedUtModel ?: throw FuzzerIllegalStateException("No cached model") + } + +// override fun generate( +// random: SourceOfRandomness, +// status: GenerationStatus +// ): UtModel { +// return if (generationState == GenerationState.MODIFY) { +// modify(random, status) +// } else { +// regenerate(random, status) +// } +// } + private fun getClassIdForArrayType(componentType: Class<*>): ClassId = when (componentType) { Int::class.javaPrimitiveType -> intArrayClassId Boolean::class.javaPrimitiveType -> booleanArrayClassId @@ -95,4 +155,14 @@ class ArrayGenerator(private val componentType: Class<*>, val component: Generat private fun length(random: SourceOfRandomness, status: GenerationStatus): Int { return if (lengthRange != null) random.nextInt(lengthRange!!.min, lengthRange!!.max) else status.size() } + + override fun copy(): Generator { + val gen = Reflection.instantiate(ArrayGenerator::class.java.constructors.first(), componentType, component.copy()) as Generator + return gen.also { + it.generatedUtModel = generatedUtModel + it.generationState = generationState + it.nestedGenerators = nestedGenerators.map { it.copy() }.toMutableList() + GeneratorConfigurator.configureGenerator(it, 85) + } + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt index f7808b3a6b..f71a55c5fa 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt @@ -1,11 +1,11 @@ package org.utbot.quickcheck.internal.generator +import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator +import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.GeneratorConfigurationException -import org.utbot.quickcheck.generator.Generators +import org.utbot.quickcheck.generator.* import org.utbot.quickcheck.internal.Items +import org.utbot.quickcheck.internal.Reflection import org.utbot.quickcheck.internal.Weighted import org.utbot.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedElement @@ -13,17 +13,38 @@ import java.lang.reflect.AnnotatedType class CompositeGenerator(composed: List>) : Generator(Any::class.java) { private val composed: MutableList> + private var previousChosenGenerator: Generator? = null init { this.composed = ArrayList(composed) } - override fun generate( + private fun regenerate( random: SourceOfRandomness, status: GenerationStatus ): UtModel { val choice = Items.chooseWeighted(composed, random) - return choice.generate(random, status) + previousChosenGenerator = choice + return choice.generateImpl(random, status) + } + + private fun modify( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + previousChosenGenerator ?: throw FuzzerIllegalStateException("Nothing to modify") + return previousChosenGenerator!!.generateImpl(random, status) + } + + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return if (generationState == GenerationState.MODIFY) { + modify(random, status) + } else { + regenerate(random, status) + } } fun composed(index: Int): Generator { @@ -92,6 +113,24 @@ class CompositeGenerator(composed: List>) : Generator(Any::c return composed.joinToString { it.item.javaClass.name } } +// override fun copy(): Generator { +// return (super.copy() as CompositeGenerator).also { +// it.previousChosenGenerator = previousChosenGenerator +// it.composed.addAll(composed) +// } +// } + + override fun copy(): Generator { + val composedCopies = composed.map { Weighted(it.item.copy(), it.weight) }.toMutableList() + val gen = Reflection.instantiate(CompositeGenerator::class.java.constructors.first(), composedCopies) as Generator + return gen.also { + it.generatedUtModel = generatedUtModel + it.generationState = generationState + it.nestedGenerators = nestedGenerators.map { it.copy() }.toMutableList() + GeneratorConfigurator.configureGenerator(it, 85) + } + } + companion object { private fun configurationAnnotationNames( element: AnnotatedElement diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt index 844c5a2271..a26716b2c1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt @@ -23,7 +23,7 @@ internal class NullableGenerator(private val delegate: Generator) : Generator(de return if (random.nextFloat(0f, 1f) < probabilityOfNull) { UtNullModel(classIdForType(types()[0])) } else { - delegate.generate(random, status) + delegate.generateImpl(random, status) } } From 14604b4392b3600773ea006106268b15530c2c85 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 22 Nov 2022 18:37:09 +0300 Subject: [PATCH 09/30] minor --- .../kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt index cd09d653f9..84e2a3f917 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt @@ -151,7 +151,7 @@ open class TestCaseGenerator( controller.job = launch(currentUtContext) { if (!isActive) return@launch //TODO remove - if (!method.name.contains("testFunc3")) return@launch + //if (!method.name.contains("testFunc3")) return@launch try { //yield one to From c5f5ae2adad62cabf7004698bfb3ff21597bb934 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 29 Nov 2022 19:35:04 +0300 Subject: [PATCH 10/30] New seed selection strategy and time budget for generation --- .../org/utbot/engine/UtBotSymbolicEngine.kt | 7 +- .../engine/greyboxfuzzer/GreyBoxFuzzer.kt | 245 ++++++++---------- .../greyboxfuzzer/generator/DataGenerator.kt | 214 +++------------ .../greyboxfuzzer/generator/FParameter.kt | 10 - .../generator/GeneratorConfigurator.kt | 10 +- .../generator/GreyBoxFuzzerGenerators.kt | 3 +- .../generator/QuickCheckExtensions.kt | 52 +++- .../userclasses/UserClassGenerator.kt | 41 +-- .../generator/ClassesInstanceGenerator.kt | 42 +-- .../ConstructorBasedInstanceGenerator.kt | 3 + .../generator/ExecutableInvoker.kt | 10 +- ...terfaceImplementationsInstanceGenerator.kt | 56 ++-- .../userclasses/generator/ObjectGenerator.kt | 20 +- .../generator/ReflectionClassGenerator.kt | 32 ++- .../generator/ReflectionTypeGenerator.kt | 53 +++- .../StaticsBasedInstanceGenerator.kt | 6 +- .../StaticsFieldBasedInstanceGenerator.kt | 7 +- .../StaticsMethodBasedInstanceGenerator.kt | 3 + .../engine/greyboxfuzzer/mutator/Mutator.kt | 57 ++-- .../engine/greyboxfuzzer/mutator/Seed.kt | 4 +- .../greyboxfuzzer/mutator/SeedCollector.kt | 80 +++--- .../greyboxfuzzer/util/ReflectionUtils.kt | 17 +- .../engine/greyboxfuzzer/util/SootUtils.kt | 42 ++- .../engine/greyboxfuzzer/util/UtBotUtils.kt | 6 +- .../greyboxfuzzer/util/UtModelGenerator.kt | 20 +- .../utbot/quickcheck/generator/Generator.kt | 17 +- .../quickcheck/generator/GeneratorContext.kt | 21 ++ .../java/lang/AbstractStringGenerator.kt | 9 +- .../generator/java/lang/BooleanGenerator.kt | 4 +- .../generator/java/lang/ByteGenerator.kt | 4 +- .../generator/java/lang/CharacterGenerator.kt | 4 +- .../generator/java/lang/DoubleGenerator.kt | 4 +- .../quickcheck/generator/java/lang/Encoded.kt | 94 +++---- .../generator/java/lang/FloatGenerator.kt | 4 +- .../generator/java/lang/IntegerGenerator.kt | 4 +- .../generator/java/lang/LongGenerator.kt | 4 +- .../java/lang/PrimitiveBooleanGenerator.kt | 4 +- .../java/lang/PrimitiveByteGenerator.kt | 4 +- .../java/lang/PrimitiveCharGenerator.kt | 4 +- .../java/lang/PrimitiveDoubleGenerator.kt | 4 +- .../java/lang/PrimitiveFloatGenerator.kt | 4 +- .../java/lang/PrimitiveIntGenerator.kt | 4 +- .../java/lang/PrimitiveLongGenerator.kt | 4 +- .../java/lang/PrimitiveShortGenerator.kt | 4 +- .../generator/java/lang/ShortGenerator.kt | 4 +- .../generator/java/lang/StringGenerator.kt | 25 +- .../java/math/BigDecimalGenerator.kt | 4 +- .../java/math/BigIntegerGenerator.kt | 6 +- .../java/nio/charset/CharsetGenerator.kt | 6 +- .../generator/java/time/ClockGenerator.kt | 8 +- .../generator/java/time/DurationGenerator.kt | 4 +- .../generator/java/time/InstantGenerator.kt | 4 +- .../generator/java/time/LocalDateGenerator.kt | 4 +- .../java/time/LocalDateTimeGenerator.kt | 4 +- .../generator/java/time/LocalTimeGenerator.kt | 4 +- .../generator/java/time/MonthDayGenerator.kt | 4 +- .../java/time/OffsetDateTimeGenerator.kt | 4 +- .../java/time/OffsetTimeGenerator.kt | 4 +- .../generator/java/time/PeriodGenerator.kt | 4 +- .../generator/java/time/YearGenerator.kt | 4 +- .../generator/java/time/YearMonthGenerator.kt | 4 +- .../generator/java/time/ZoneIdGenerator.kt | 4 +- .../java/time/ZoneOffsetGenerator.kt | 4 +- .../java/time/ZonedDateTimeGenerator.kt | 4 +- .../generator/java/util/BitSetGenerator.kt | 4 +- .../java/util/CollectionGenerator.kt | 4 +- .../generator/java/util/DateGenerator.kt | 4 +- .../generator/java/util/LocaleGenerator.kt | 4 +- .../generator/java/util/MapGenerator.kt | 4 +- .../java/util/OptionalDoubleGenerator.kt | 4 +- .../generator/java/util/OptionalGenerator.kt | 6 +- .../java/util/OptionalIntGenerator.kt | 4 +- .../java/util/OptionalLongGenerator.kt | 4 +- .../java/util/PropertiesGenerator.kt | 18 +- .../quickcheck/generator/java/util/RFC4122.kt | 6 +- .../generator/java/util/TimeZoneGenerator.kt | 4 +- .../java/util/concurrent/CallableGenerator.kt | 4 +- .../java/util/function/BiFunctionGenerator.kt | 4 +- .../util/function/BiPredicateGenerator.kt | 4 +- .../util/function/BinaryOperatorGenerator.kt | 4 +- .../util/function/DoubleFunctionGenerator.kt | 4 +- .../java/util/function/FunctionGenerator.kt | 4 +- .../util/function/IntFunctionGenerator.kt | 4 +- .../util/function/LongFunctionGenerator.kt | 4 +- .../java/util/function/PredicateGenerator.kt | 4 +- .../java/util/function/SupplierGenerator.kt | 4 +- .../function/ToDoubleBiFunctionGenerator.kt | 4 +- .../function/ToDoubleFunctionGenerator.kt | 4 +- .../util/function/ToIntBiFunctionGenerator.kt | 4 +- .../util/function/ToIntFunctionGenerator.kt | 4 +- .../function/ToLongBiFunctionGenerator.kt | 4 +- .../util/function/ToLongFunctionGenerator.kt | 4 +- .../util/function/UnaryOperatorGenerator.kt | 4 +- .../internal/generator/ArrayGenerator.kt | 11 +- .../internal/generator/CompositeGenerator.kt | 2 +- .../internal/generator/EnumGenerator.kt | 4 +- .../internal/generator/GeneratorRepository.kt | 8 +- .../generator/MarkerInterfaceGenerator.kt | 4 +- .../internal/generator/ZilchGenerator.kt | 4 +- .../UtFuzzingExecutionInstrumentation.kt | 17 +- .../process/InstrumentedProcessRunner.kt | 2 + 101 files changed, 813 insertions(+), 723 deletions(-) create mode 100644 utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorContext.kt diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index 730e84d683..7bd55202e3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -431,7 +431,12 @@ class UtBotSymbolicEngine( } try { - GreyBoxFuzzer(concreteExecutor.pathsToUserClasses, concreteExecutor.pathsToDependencyClasses, methodUnderTest).fuzz() + GreyBoxFuzzer( + concreteExecutor.pathsToUserClasses, + concreteExecutor.pathsToDependencyClasses, + methodUnderTest, + 120_000L + ).fuzz() } catch (e: CancellationException) { logger.debug { "Cancelled by timeout" } } catch (e: Throwable) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt index ea6f173ac8..2da0f35adf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -11,6 +11,7 @@ import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* import org.utbot.framework.util.sootMethod import org.utbot.instrumentation.ConcreteExecutor +import org.utbot.quickcheck.generator.GeneratorContext import java.lang.reflect.Field import java.lang.reflect.Method import kotlin.random.Random @@ -19,87 +20,91 @@ class GreyBoxFuzzer( private val pathsToUserClasses: String, private val pathsToDependencyClasses: String, private val methodUnderTest: ExecutableId, + private val timeBudgetInMillis: Long ) { - private val seeds = SeedCollector() - private val explorationStageIterations = 100 - private val exploitationStageIterations = 100 + private val methodLines = + methodUnderTest.sootMethod.activeBody.units + .map { it.javaSourceStartLineNumber } + .filter { it != -1 } + .toSet() + private val seeds = SeedCollector(methodLines = methodLines) + private val timeRemain + get() = timeOfStart + timeBudgetInMillis - System.currentTimeMillis() + private val timeOfStart = System.currentTimeMillis() + private val percentageOfTimeBudgetToChangeMode = 10 //TODO make it return Sequence suspend fun fuzz(): Sequence { logger.debug { "Started to fuzz ${methodUnderTest.name}" } + val generatorContext = GeneratorContext() val javaClazz = methodUnderTest.classId.jClass val sootMethod = methodUnderTest.sootMethod val javaMethod = sootMethod.toJavaMethod()!! val classFieldsUsedByFunc = sootMethod.getClassFieldsUsedByFunc(javaClazz) - val methodLines = sootMethod.activeBody.units.map { it.javaSourceStartLineNumber }.filter { it != -1 }.toSet() val currentCoverageByLines = CoverageCollector.coverage .filter { it.methodSignature == methodUnderTest.signature } .map { it.lineNumber } .toSet() //TODO repeat or while - explorationStage( - javaMethod, - explorationStageIterations, - methodLines, - classFieldsUsedByFunc, - methodUnderTest, - currentCoverageByLines - ) - logger.debug { "SEEDS AFTER EXPLORATION STAGE = ${seeds.seedsSize()}" } - exploitationStage(exploitationStageIterations, javaClazz, methodLines, currentCoverageByLines) + while (timeRemain > 0) { + explorationStage( + javaMethod, + methodLines, + classFieldsUsedByFunc, + methodUnderTest, + currentCoverageByLines, + generatorContext + ) + logger.debug { "SEEDS AFTER EXPLORATION STAGE = ${seeds.seedsSize()}" } + if (timeRemain < 0) break + exploitationStage( + methodLines, + currentCoverageByLines + ) + } //UtModelGenerator.reset() return sequenceOf() } private suspend fun explorationStage( method: Method, - numberOfIterations: Int, methodLinesToCover: Set, classFieldsUsedByFunc: Set, methodUnderTest: ExecutableId, - prevMethodCoverage: Set + prevMethodCoverage: Set, + generatorContext: GeneratorContext ) { -// val param = method.parameters.first() -// val firstGenerator = GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(param, 0)!! -// var generator = firstGenerator -// println("GENERATOR = $generator") -// val generatedValue = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) -// println("GENERATED VALUE = $generatedValue") -// generator.generationState = GenerationState.CACHE -// val valueFromCache = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) -// println("VALUE FROM CACHE = $valueFromCache") -// //generator = firstGenerator.copy() -// generator.generationState = GenerationState.MODIFY -// val modifiedValue = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) -// println("MODIFIED VALUE = $modifiedValue") -// //generator = firstGenerator.copy() -// generator.generationState = GenerationState.MODIFY -// val modifiedValue2 = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) -// println("MODIFIED VALUE = $modifiedValue2") -// //generator = firstGenerator.copy() -// generator.generationState = GenerationState.MODIFY -// val modifiedValue3 = generator.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) -// println("MODIFIED VALUE = $modifiedValue3") -// exitProcess(0) val parametersToGenericsReplacer = method.parameters.map { it to GenericsReplacer() } + var regenerateThis = false val thisInstancesHistory = ArrayDeque() - repeat(numberOfIterations) { iterationNumber -> + val startTime = System.currentTimeMillis() + val endTime = startTime + timeBudgetInMillis / percentageOfTimeBudgetToChangeMode + var iterationNumber = 0 + while (System.currentTimeMillis() < endTime) { try { logger.debug { "Iteration number $iterationNumber" } + if (timeRemain < 0) return + iterationNumber++ + if (isMethodCovered(methodLinesToCover)) return while (thisInstancesHistory.size > 1) { thisInstancesHistory.removeLast() } if (thisInstancesHistory.isEmpty()) { - thisInstancesHistory += generateThisInstance(methodUnderTest.classId) + thisInstancesHistory += generateThisInstance(methodUnderTest.classId, generatorContext) } if (iterationNumber != 0) { - if (Random.getTrue(20)) { + if (regenerateThis || Random.getTrue(30)) { logger.debug { "Trying to regenerate this instance" } thisInstancesHistory.clear() - thisInstancesHistory += generateThisInstance(methodUnderTest.classId) - } else if (Random.getTrue(50)) { - thisInstancesHistory += Mutator.mutateThisInstance(thisInstancesHistory.last(), classFieldsUsedByFunc.toList()) + thisInstancesHistory += generateThisInstance(methodUnderTest.classId, generatorContext) + regenerateThis = false + } else if (Random.getTrue(60)) { + thisInstancesHistory += Mutator.mutateThisInstance( + thisInstancesHistory.last(), + classFieldsUsedByFunc.toList(), + generatorContext + ) } } /** @@ -119,6 +124,7 @@ class GreyBoxFuzzer( DataGenerator.generate( parameter, index, + generatorContext, GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus ) @@ -128,21 +134,26 @@ class GreyBoxFuzzer( val stateBefore = EnvironmentModels(thisInstance.utModelForExecution, generatedParameters.map { it.utModel }, mapOf()) try { + logger.debug { "Execution started" } val executionResult = execute(stateBefore, methodUnderTest) logger.debug { "Execution result: $executionResult" } - val seedScore = + val seedCoverage = handleCoverage( executionResult, prevMethodCoverage, methodLinesToCover ) - seeds.addSeed(Seed(thisInstance, generatedParameters, seedScore.toDouble())) + logger.debug { "Calculating seed score" } + val seedScore = seeds.calcSeedScore(seedCoverage) + logger.debug { "Adding seed" } + seeds.addSeed(Seed(thisInstance, generatedParameters, seedCoverage, seedScore)) logger.debug { "Execution result: ${executionResult.result}" } logger.debug { "Seed score = $seedScore" } } catch (e: Throwable) { logger.debug(e) { "Exception while execution :(" } thisInstancesHistory.clear() - return@repeat + regenerateThis = true + continue } } catch (e: FuzzerIllegalStateException) { logger.error(e) { "Something wrong in the fuzzing process" } @@ -150,35 +161,26 @@ class GreyBoxFuzzer( } } - private fun handleCoverage( - executionResult: UtFuzzingConcreteExecutionResult, - prevMethodCoverage: Set, - currentMethodLines: Set - ): Int { - val coverage = - executionResult.coverage.coveredInstructions - .map { it.lineNumber } - //.filter { it in currentMethodLines } - .toSet() - val currentMethodCoverage = coverage.filter { it in currentMethodLines } - executionResult.coverage.coveredInstructions.forEach { CoverageCollector.coverage.add(it) } - return (currentMethodCoverage - prevMethodCoverage).size - } - - - //TODO under construction private suspend fun exploitationStage( - numberOfIterations: Int, - clazz: Class<*>, methodLinesToCover: Set, prevMethodCoverage: Set ) { logger.debug { "Exploitation began" } - repeat(numberOfIterations) { - logger.debug { "Mutation iteration $it" } - val randomSeed = seeds.getRandomWeightedSeed() ?: return@repeat + val startTime = System.currentTimeMillis() + val endTime = startTime + timeBudgetInMillis / percentageOfTimeBudgetToChangeMode + var iterationNumber = 0 + while (System.currentTimeMillis() < endTime) { + if (timeRemain < 0) return + logger.debug { "Mutation iteration $iterationNumber" } + iterationNumber++ + if (isMethodCovered(methodLinesToCover)) return + val randomSeed = seeds.getRandomWeightedSeed() ?: continue logger.debug { "Random seed params = ${randomSeed.parameters}" } - val mutatedSeed = Mutator.mutateSeed(randomSeed, GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) + val mutatedSeed = Mutator.mutateSeed( + randomSeed, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus + ) logger.debug { "Mutated params = ${mutatedSeed.parameters}" } val stateBefore = mutatedSeed.createEnvironmentModels() try { @@ -190,71 +192,39 @@ class GreyBoxFuzzer( prevMethodCoverage, methodLinesToCover ) - mutatedSeed.score = seedScore.toDouble() + mutatedSeed.score = 0.0 seeds.addSeed(mutatedSeed) logger.debug { "Execution result: ${executionResult.result}" } logger.debug { "Seed score = $seedScore" } } catch (e: Throwable) { logger.debug(e) { "Exception while execution :(" } - return@repeat + continue } } } -// private suspend fun exploitationStage( -// numberOfIterations: Int, -// clazz: Class<*>, -// methodLinesToCover: Set, -// prevMethodCoverage: Set -// ) { -// logger.debug { "Exploitation began" } -// repeat(numberOfIterations) { -// val randomSeed = seeds.getRandomWeightedSeed() ?: return@repeat -// val randomSeedArguments = randomSeed.arguments.toMutableList() -// val m = IdentityHashMap() -// val modelConstructor = UtModelConstructor(m) -// val randomParameterIndex = -// when { -// randomSeedArguments.isEmpty() -> return@repeat -// randomSeedArguments.size == 1 -> 0 -// else -> Random.nextInt(0, randomSeedArguments.size) -// } -// val randomArgument = randomSeedArguments[randomParameterIndex] -// println("BEFORE = ${randomArgument.first!!.utModel}") -// val fRandomArgument = randomArgument.first!! -// val randomSeedArgumentsAsUtModels = -// modelConstructor.constructModelFromValues(randomSeedArguments).toMutableList() -// val initialInstanceForMutation = -// randomSeedArguments[randomParameterIndex].first?.utModel as? UtReferenceModel ?: return@repeat -// val mutatedArgument = -// Mutator.mutateParameter( -// fRandomArgument, -// initialInstanceForMutation, -// modelConstructor -// ) -//// randomSeedArguments[randomParameterIndex] = fRandomArgument to randomArgument.second -// println("AFTER = ${mutatedArgument!!.utModel}") -// if (mutatedArgument?.utModel == null) return@repeat -// randomSeedArgumentsAsUtModels[randomParameterIndex] = mutatedArgument.utModel -// val stateBefore = -// EnvironmentModels(thisInstance, randomSeedArgumentsAsUtModels, mapOf()) -// //println(stateBefore) -// try { -// val executionResult = execute(stateBefore, methodUnderTest) -// val seedScore = -// handleCoverage( -// executionResult!!, -// prevMethodCoverage, -// methodLinesToCover -// ) -// //seeds.addSeed(Seed(thisInstance, generatedParameters, seedScore.toDouble())) -// println("MUTATED SEED SCORE = $seedScore") -// println("Execution result1: ${executionResult.result}") -// println("-----------------------------------------") -// } catch (e: Throwable) { -// return@repeat -// } -// } -// } + + private fun handleCoverage( + executionResult: UtFuzzingConcreteExecutionResult, + prevMethodCoverage: Set, + currentMethodLines: Set + ): Set { + val currentMethodCoverage = executionResult.coverage.coveredInstructions + .asSequence() + .filter { it.methodSignature == methodUnderTest.signature } + .map { it.lineNumber } + .filter { it in currentMethodLines } + .toSet() + logger.debug { "Covered lines $currentMethodCoverage from $currentMethodLines" } + executionResult.coverage.coveredInstructions.forEach { CoverageCollector.coverage.add(it) } + return currentMethodCoverage + } + + private fun isMethodCovered(methodLinesToCover: Set): Boolean { + val coveredLines = + CoverageCollector.coverage.filter { it.methodSignature == methodUnderTest.signature }.map { it.lineNumber } + .toSet() + return coveredLines.containsAll(methodLinesToCover) + } private suspend fun ConcreteExecutor.executeConcretely( methodUnderTest: ExecutableId, @@ -281,15 +251,16 @@ class GreyBoxFuzzer( } - private fun generateThisInstance(classId: ClassId): ThisInstance = - if (!methodUnderTest.isStatic) { - DataGenerator.generateThis( - classId, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus - ) - } else { - StaticMethodThisInstance - } + private fun generateThisInstance(classId: ClassId, generatorContext: GeneratorContext): ThisInstance = + if (!methodUnderTest.isStatic) { + DataGenerator.generateThis( + classId, + generatorContext, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus + ) + } else { + StaticMethodThisInstance + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt index b86ac46dd9..a589ac3d37 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt @@ -10,56 +10,70 @@ import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass +import org.utbot.framework.plugin.api.util.objectClassId +import org.utbot.quickcheck.generator.GenerationState +import org.utbot.quickcheck.generator.GeneratorContext import java.lang.reflect.Parameter object DataGenerator { private val generatorRepository = GreyBoxFuzzerGenerators.generatorRepository - fun generate( - clazz: Class<*>, - random: SourceOfRandomness, - status: GenerationStatus - ): UtModel? = generatorRepository.getOrProduceGenerator(clazz)?.generateImpl(random, status) - - fun generate( + fun generateUtModel( parameterTypeContext: ParameterTypeContext, + depth: Int = 0, + generatorContext: GeneratorContext, random: SourceOfRandomness, status: GenerationStatus - ): UtModel? = generatorRepository.getOrProduceGenerator(parameterTypeContext, 0)?.generateImpl(random, status) - - fun generate( - parameterTypeContext: ParameterTypeContext, - random: SourceOfRandomness, - status: GenerationStatus, - depth: Int - ): UtModel? = generatorRepository.getOrProduceGenerator(parameterTypeContext, depth)?.generateImpl(random, status) + ): UtModel { + logger.debug { "Trying to generate UtModel of type 3 times" } + val classId = parameterTypeContext.rawClass.id + var generatedInstance: UtModel? = null + repeat(3) { + generatedInstance = + try { + val generator = + generatorRepository.getOrProduceGenerator(parameterTypeContext, generatorContext, depth) + ?: return@repeat + generator.generatorContext.startCheckpoint() + generator.generateImpl(random, status) + } catch (_: Throwable) { + null + } + generatedInstance?.let { if (it !is UtNullModel) return it } + } + return UtNullModel(classId) + } fun generate( parameter: Parameter, parameterIndex: Int, + generatorContext: GeneratorContext, random: SourceOfRandomness, status: GenerationStatus ): FParameter { val generator = - generatorRepository.getOrProduceGenerator(parameter, parameterIndex) + generatorRepository.getOrProduceGenerator(parameter, parameterIndex, generatorContext) return generate(generator, parameter, random, status) } fun generateThis( classId: ClassId, + generatorContext: GeneratorContext, random: SourceOfRandomness, status: GenerationStatus ): NormalMethodThisInstance { val generator = - generatorRepository.getOrProduceGenerator(classId.jClass) - return generateThis(generator, classId, random, status) + generatorRepository.getOrProduceGenerator(classId.jClass, generatorContext) + return generateThis(generator, classId, generatorContext, random, status) } private fun generateThis( generator: Generator?, classId: ClassId, + generatorContext: GeneratorContext, random: SourceOfRandomness, status: GenerationStatus, numberOfTries: Int = 3 @@ -70,10 +84,13 @@ object DataGenerator { throw FuzzerIllegalStateException("Can't find generator for ${classId.name}") } var generatedValue: UtModel - repeat(numberOfTries) { - logger.debug { "Try $it" } + repeat(numberOfTries) { iteration -> + logger.debug { "Try $iteration" } try { + generator.generationState = GenerationState.REGENERATE + generator.generatorContext.startCheckpoint() generatedValue = generator.generateImpl(random, status) + if (generatedValue is UtNullModel && iteration != numberOfTries - 1) return@repeat return NormalMethodThisInstance( generatedValue, generator, @@ -104,7 +121,10 @@ object DataGenerator { repeat(numberOfTries) { logger.debug { "Try $it" } try { + generator.generationState = GenerationState.REGENERATE + generator.generatorContext.startCheckpoint() generatedValue = generator.generateImpl(random, status) + if (generatedValue is UtNullModel) return@repeat return FParameter( parameter, null, @@ -120,158 +140,4 @@ object DataGenerator { return FParameter(parameter, null, UtNullModel(classId), generator, classId, listOf()) } -// //TODO Make it work with type parameters -// private fun Type.getFFieldsForClass(value: Any, depth: Int, originalField: Field?): List { -// println("GETTING FFIelds from $value") -// createFFieldFromPrimitivesOrBoxedPrimitives(this, value, originalField)?.let { return listOf(it) } -// val parameterizedType = this as? ParameterizedType -// val genericsContext = -// if (this is GenericArrayTypeImpl) { -// (this.genericComponentType as? ParameterizedType)?.buildGenericsContext() -// } else { -// parameterizedType?.buildGenericsContext() -// } -// if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) { -// return emptyList() -// } -// val subFields = mutableListOf() -// if (this.toClass()?.isArray == true) { -// val arrayContentType = this.toClass()?.componentType ?: return subFields -// getFFieldsFromArray(value, subFields, originalField, this, arrayContentType, depth) -// return subFields -// } -// val classFields = -// this.toClass()?.getAllDeclaredFields()?.filter { !it.hasModifiers(Modifier.FINAL) } ?: emptyList() -// for (field in classFields) { -// val resolvedFieldType = -// if (genericsContext != null) { -// //TODO make it work for subclasses -// parameterizedType.let { field.resolveFieldType(genericsContext) } ?: field.type -// } else { -// field.type -// } -// assert(resolvedFieldType.toClass() != null) -//// if (field.hasModifiers(Modifier.FINAL)) { -//// //subFields.add(FField(field, value)) -//// continue -//// } -// if (resolvedFieldType.toClass()!!.isArray) { -// val arrayOfObjects = field.getFieldValue(value) -// val arrayContentType = -// (resolvedFieldType as? GenericArrayTypeImpl)?.genericComponentType ?: field.type.componentType -// getFFieldsFromArray(arrayOfObjects, subFields, field, resolvedFieldType, arrayContentType, depth) -// //TODO!!!! -// } else { -// field.getFieldValue(value)?.let { fieldValue -> -// try { -// val generatorForField = generatorRepository.getOrProduceGenerator(field) -// if (field.type.isPrimitive) { -// subFields.add(FField(field, fieldValue, resolvedFieldType, generatorForField)) -// } else { -// //println("GETTING SUBFIELDS FOR ${field.type} value = ${fieldValue} DEPTH = $depth") -// //TODO resolve type -// val subFFields = resolvedFieldType.getFFieldsForClass(fieldValue, depth + 1, null) -// subFields.add(FField(field, fieldValue, resolvedFieldType, generatorForField, subFFields)) -// } -// } catch (e: java.lang.IllegalStateException) { -// subFields.add(FField(field, fieldValue, resolvedFieldType, null, listOf())) -// } -// } ?: subFields.add(FField(field, null, resolvedFieldType, null, listOf())) -// } -// } -// return subFields -// } - -// private fun createFFieldFromPrimitivesOrBoxedPrimitives(originalType: Type, value: Any?, field: Field?): FField? { -// val clazz = originalType.toClass() ?: return null -// val listOfPrimitives = listOf( -// Byte::class, -// Short::class, -// Int::class, -// Long::class, -// Float::class, -// Double::class, -// Boolean::class, -// Char::class, -// String::class -// ) -// return if (clazz.kotlin in listOfPrimitives || clazz.isPrimitive) { -// FField(field, value, originalType, getGenerator(originalType)) -// } else null -// } - -// private fun getFFieldsFromArray( -// array: Any?, -// subFields: MutableList, -// field: Field?, -// arrayType: Type, -// arrayContentType: Type, -// depth: Int -// ) { -// val typedArray = -// when (array) { -// is BooleanArray -> { -// array.toList() -// } -// is ByteArray -> { -// array.toList() -// } -// is CharArray -> { -// array.toList() -// } -// is ShortArray -> { -// array.toList() -// } -// is IntArray -> { -// array.toList() -// } -// is LongArray -> { -// array.toList() -// } -// is FloatArray -> { -// array.toList() -// } -// is DoubleArray -> { -// array.toList() -// } -// else -> { -// if (array == null) { -// subFields.add(FField(null, null, arrayContentType, null, listOf())) -// return -// } else { -// (array as Array<*>).toList() -// } -// } -// } -// val generatorOfNeededType = field?.let { getGenerator(it, arrayType) } ?: getGenerator(arrayType) -// val localSubFields = mutableListOf() -// val indexOfLastNotNullElement = typedArray.indexOfLast { it != null } -// val arrayContentGenerator = getGenerator(arrayContentType) -// if (indexOfLastNotNullElement == -1) { -// localSubFields.add(FField(field, null, arrayContentType, arrayContentGenerator)) -// } else { -// typedArray.filterNotNull().map { el -> -// val ssFFields = arrayContentType.getFFieldsForClass(el, depth + 1, null) -// localSubFields.add(FField(field, el, arrayContentType, arrayContentGenerator, ssFFields)) -// } -// } -// subFields.add(FField(field, typedArray, arrayType, generatorOfNeededType, localSubFields)) -// } - -// private fun getGenerator(field: Field, fieldType: Type): Generator<*>? { -// return if (fieldType is ParameterizedType) { -// generatorRepository.getOrProduceGenerator(field.buildParameterContext(fieldType), 0) -// } else { -// generatorRepository.getOrProduceGenerator(field) -// }.let { gen -> -// if (gen is ComponentizedGenerator && gen.getComponents().any { it is ZilchGenerator }) null -// else gen -// } -// } -// private fun getGenerator(resolvedType: Type): Generator<*>? = -// generatorRepository.getOrProduceGenerator(resolvedType).let { gen -> -// if (gen is ComponentizedGenerator && gen.getComponents().any { it is ZilchGenerator }) null -// else gen -// } - } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt index 8a102976b3..30d3ea941f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt @@ -50,16 +50,6 @@ data class FParameter( return res } - fun regenerateFields() { - regenerateFields(classId.jClass.getAllDeclaredFields()) - } - - fun regenerateFields(fieldsToRegenerate: List) { - if (utModel is UtAssembleModel) { - utModel = Mutator.regenerateFields(classId.jClass, utModel as UtAssembleModel, fieldsToRegenerate) - } - } - fun copy(): FParameter = FParameter( parameter, value, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt index a2ccccd2c1..ed7e318081 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt @@ -26,7 +26,7 @@ object GeneratorConfigurator { private val minDouble: Double = -100.0 private val maxDouble: Double = 100.0 private val minStringLength: Int = 1 - private val maxStringLength: Int = 10 + private val maxStringLength: Int = 5 val minCollectionSize: Int = 1 val maxCollectionSize: Int = 5 @@ -92,10 +92,14 @@ object GeneratorConfigurator { is MapGenerator -> generator.configure(sizeAnnotationInstance) is StringGenerator -> generator.configure( if (Random.getTrue(50)) { - setOf('a'.code..'z'.code) + if (Random.getTrue(50)) { + setOf('a'.code..'z'.code) + } else { + setOf('A'.code..'Z'.code) + } } else { setOf(' '.code..'~'.code) - } + }, minStringLength..maxStringLength ) else -> Unit } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt index 54877ac4ce..01a7bb3d7e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt @@ -14,7 +14,7 @@ import java.util.* object GreyBoxFuzzerGenerators { const val seed = 42L - const val maxDepthOfGeneration = 4 + const val maxDepthOfGeneration = 7 val sourceOfRandomness = SourceOfRandomness(Random(seed)) val genStatus = NonTrackingGenerationStatus(sourceOfRandomness) @@ -41,7 +41,6 @@ object GreyBoxFuzzerGenerators { it.register(ShortGenerator()) it.register(BooleanGenerator()) it.register(IntegerGenerator()) - it.register(Encoded()) it.register(ByteGenerator()) it.register(StringGenerator()) it.register(LongGenerator()) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt index 5acc8286e1..316d5757b2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -12,6 +12,7 @@ import org.utbot.engine.logger import org.utbot.engine.rawType import org.utbot.quickcheck.generator.ComponentizedGenerator import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.internal.generator.ArrayGenerator @@ -58,17 +59,31 @@ fun GeneratorRepository.produceUserClassGenerator( return userClassGenerator } -fun GeneratorRepository.getOrProduceGenerator(field: Field, depth: Int = 0): Generator? = - getOrProduceGenerator(ParameterTypeContext.forField(field), depth) +fun GeneratorRepository.getOrProduceGenerator( + field: Field, + generatorContext: GeneratorContext, + depth: Int = 0 +): Generator? = + getOrProduceGenerator(ParameterTypeContext.forField(field), generatorContext, depth) -fun GeneratorRepository.getOrProduceGenerator(param: Parameter, parameterIndex: Int, depth: Int = 0): Generator? = - getOrProduceGenerator(param.createParameterTypeContext(parameterIndex), depth) +fun GeneratorRepository.getOrProduceGenerator( + param: Parameter, + parameterIndex: Int, + generatorContext: GeneratorContext, + depth: Int = 0 +): Generator? = + getOrProduceGenerator(param.createParameterTypeContext(parameterIndex), generatorContext, depth) -fun GeneratorRepository.getOrProduceGenerator(clazz: Class<*>, depth: Int = 0): Generator? = - getOrProduceGenerator(clazz.createParameterTypeContext(), depth) +fun GeneratorRepository.getOrProduceGenerator( + clazz: Class<*>, + generatorContext: GeneratorContext, + depth: Int = 0 +): Generator? = + getOrProduceGenerator(clazz.createParameterTypeContext(), generatorContext, depth) fun GeneratorRepository.getOrProduceGenerator( parameterTypeContext: ParameterTypeContext, + generatorContext: GeneratorContext, depth: Int ): Generator? { val producedUserClassesGenerators = mutableListOf() @@ -78,7 +93,11 @@ fun GeneratorRepository.getOrProduceGenerator( this.produceGenerator(typeContext) //TODO catch specific exception } catch (e: Exception) { - producedUserClassesGenerators += produceUserClassGenerator(typeContext.rawClass, typeContext, depth + 1) + producedUserClassesGenerators += produceUserClassGenerator( + typeContext.rawClass, + typeContext, + depth + 1 + ) } } val generator = @@ -90,9 +109,9 @@ fun GeneratorRepository.getOrProduceGenerator( } finally { producedUserClassesGenerators.forEach { removeGenerator(it.parameterTypeContext!!.resolved.rawClass) } } -// (listOf(generator) + generator.getAllComponents()).forEach { -// GeneratorConfigurator.configureGenerator(it, 85) -// } + (listOf(generator) + generator.getAllComponents()).forEach { + it.generatorContext = generatorContext + } return generator } @@ -152,7 +171,11 @@ fun Class<*>.createParameterTypeContext(): ParameterTypeContext { val generics = GenericsResolver.resolve(this) val resolvedGenerics = generics.resolveTypeGenerics(this).map { createStandardTypeParameter(Types.forJavaLangReflectType(it)) } - val resolvedType = Types.forClass(this, *resolvedGenerics.toTypedArray()) + val resolvedType = try { + Types.forClass(this, *resolvedGenerics.toTypedArray()) + } catch (e: Throwable) { + Types.forClass(this) + } return ParameterTypeContext( this.typeName, FakeAnnotatedTypeFactory.makeFrom(this), @@ -264,7 +287,12 @@ object QuickCheckExtensions { val m = mutableMapOf(prevImplementer to gm) return GenericsContext(GenericsInfo(prevImplementer, m), prevImplementer) } - fun buildGenericsContextForInterfaceParent(resolvedType: Type, clazz: Class<*>, parentChain: List>): GenericsContext? { + + fun buildGenericsContextForInterfaceParent( + resolvedType: Type, + clazz: Class<*>, + parentChain: List> + ): GenericsContext? { val generics = mutableListOf>>() var curClass = clazz resolvedType.getActualTypeArguments().forEachIndexed { index, typeVariable -> diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt index 5a74016470..3b1589c928 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt @@ -2,9 +2,6 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness import org.javaruntype.type.TypeParameter @@ -13,13 +10,11 @@ import org.utbot.engine.greyboxfuzzer.generator.userclasses.generator.* import org.utbot.engine.greyboxfuzzer.mutator.Mutator import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.engine.logger -import org.utbot.framework.plugin.api.UtAssembleModel -import org.utbot.framework.plugin.api.UtDirectSetFieldModel -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.fieldClassId import org.utbot.framework.plugin.api.util.fieldId import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationState +import org.utbot.quickcheck.generator.* import java.lang.reflect.* import kotlin.random.Random @@ -37,7 +32,12 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { it.depth = depth it.parameterTypeContext = parameterTypeContext it.generationMethod = generationMethod - it.mutatedFields.putAll(mutatedFields) + it.generatedUtModel = generatedUtModel + it.generationState = generationState + if (isGeneratorContextInitialized()) { + it.generatorContext = generatorContext + } + it.mutatedFields.putAll(mutatedFields.entries.map { it.key to it.value.copy() }) } } @@ -49,17 +49,22 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { return parameterTypeContext?.resolved?.typeParameters?.size ?: 0 } - fun generate(random: SourceOfRandomness, status: GenerationStatus, generationMethod: GenerationMethod): UtModel? { + fun generate(random: SourceOfRandomness, status: GenerationStatus, generationMethod: GenerationMethod): UtModel { this.generationMethod = generationMethod return generateImpl(random, status) } private fun regenerate(random: SourceOfRandomness, status: GenerationStatus): UtModel { logger.debug { "Trying to generate ${parameterTypeContext!!.resolved}. Current depth depth: $depth" } - if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return TODO("null") + if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return UtNullModel(clazz!!.id) val immutableClazz = clazz!! - if (immutableClazz == Any::class.java) return ObjectGenerator(random, status).generate() - if (immutableClazz == Class::class.java) return ReflectionClassGenerator(parameterTypeContext!!).generate() + when (immutableClazz) { + Any::class.java -> return ObjectGenerator(parameterTypeContext!!, random, status, generatorContext).generate() + Class::class.java -> return ReflectionClassGenerator(parameterTypeContext!!, generatorContext).generate() + Type::class.java -> return ReflectionTypeGenerator(parameterTypeContext!!, generatorContext).generate() + //TODO implement field generator + Field::class.java -> return UtNullModel(fieldClassId) + } //TODO! generate inner classes instances if (immutableClazz.declaringClass != null && !immutableClazz.hasModifiers(Modifier.STATIC)) { return UtNullModel(immutableClazz.id) @@ -72,6 +77,7 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { gctx, GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus, + generatorContext, depth ).generate() } @@ -82,13 +88,14 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { generationMethod, GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus, + generatorContext, depth ).generate() } override fun modify(random: SourceOfRandomness, status: GenerationStatus): UtModel { - val cachedUtModel = - generatedUtModel as? UtAssembleModel ?: throw FuzzerIllegalStateException("Nothing to modify") + generatedUtModel ?: throw FuzzerIllegalStateException("Nothing to modify") + val cachedUtModel = generatedUtModel as? UtAssembleModel ?: return generatedUtModel!!.copy() return if (Random.getTrue(80) && mutatedFields.isNotEmpty()) { regenerateField(random, status, cachedUtModel) } else { @@ -120,7 +127,7 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { val resolvedJavaType = parameterTypeContext!!.generics.resolveType(parameterTypeContext!!.type()) val gctx = resolvedJavaType.createGenericsContext(clazz!!) if (clazz == randomFieldDeclaringClass) { - return Mutator.regenerateFieldWithContext(gctx, cachedUtModel, randomField)?.let { + return Mutator.regenerateFieldWithContext(gctx, cachedUtModel, randomField, generatorContext)?.let { mutatedFields[randomField] = it.second it.first } ?: cachedUtModel @@ -140,7 +147,7 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { clazz!!, chain.map { it!! }.reversed().drop(1) ) ?: return cachedUtModel - return Mutator.regenerateFieldWithContext(genericsContext, cachedUtModel, randomField)?.let { + return Mutator.regenerateFieldWithContext(genericsContext, cachedUtModel, randomField, generatorContext)?.let { mutatedFields[randomField] = it.second it.first } ?: cachedUtModel diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt index a197e63488..e272f43237 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt @@ -5,6 +5,7 @@ import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext @@ -15,6 +16,7 @@ class ClassesInstanceGenerator( private val generationMethod: GenerationMethod, private val sourceOfRandomness: SourceOfRandomness, private val genStatus: GenerationStatus, + private val generatorContext: GeneratorContext, private val depth: Int ): InstanceGenerator { override fun generate(): UtModel { @@ -27,23 +29,29 @@ class ClassesInstanceGenerator( val randomTypeOfGeneration = typeOfGenerations.randomOrNull() ?: return UtNullModel(clazz.id) logger.debug { "Type of generation: $randomTypeOfGeneration" } val generatedInstance = - when (randomTypeOfGeneration) { - 'c' -> ConstructorBasedInstanceGenerator( - clazz, - gctx, - initialContext, - sourceOfRandomness, - genStatus, - depth - ).generate() - 's' -> StaticsBasedInstanceGenerator( - clazz, - gctx, - sourceOfRandomness, - genStatus, - depth - ).generate() - else -> null + try { + when (randomTypeOfGeneration) { + 'c' -> ConstructorBasedInstanceGenerator( + clazz, + gctx, + initialContext, + sourceOfRandomness, + genStatus, + generatorContext, + depth + ).generate() + 's' -> StaticsBasedInstanceGenerator( + clazz, + gctx, + sourceOfRandomness, + genStatus, + generatorContext, + depth + ).generate() + else -> null + } + } catch (_: Throwable) { + null } if (generatedInstance == null || generatedInstance is UtNullModel) { typeOfGenerations.remove(randomTypeOfGeneration) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt index e5ba9b835c..972d8c572a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt @@ -7,6 +7,7 @@ import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Constructor @@ -19,6 +20,7 @@ class ConstructorBasedInstanceGenerator( private val initialGenericContext: GenericsContext?, private val sourceOfRandomness: SourceOfRandomness, private val generationStatus: GenerationStatus, + private val generatorContext: GeneratorContext, private val depth: Int ): InstanceGenerator { @@ -45,6 +47,7 @@ class ConstructorBasedInstanceGenerator( resolvedConstructor, sourceOfRandomness, generationStatus, + generatorContext, depth ).invoke() } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt index f6ecbe6bcd..cd650a8f4c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt @@ -2,13 +2,13 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.greyboxfuzzer.generator.DataGenerator import org.utbot.engine.greyboxfuzzer.generator.createParameterContextForParameter -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator import org.utbot.engine.greyboxfuzzer.util.constructAssembleModelUsingMethodInvocation import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext @@ -21,6 +21,7 @@ class ExecutableInvoker( private val genericsContext: GenericsContext?, private val sourceOfRandomness: SourceOfRandomness, private val generationStatus: GenerationStatus, + private val generatorContext: GeneratorContext, private val depth: Int ) { fun invoke(): UtModel { @@ -31,12 +32,13 @@ class ExecutableInvoker( } else { ParameterTypeContext.forParameter(indexedParameter.value) } - DataGenerator.generate(parameterContext, sourceOfRandomness, generationStatus, depth)?: UtNullModel(parameterContext.rawClass.id) + DataGenerator.generateUtModel(parameterContext, depth, generatorContext, sourceOfRandomness, generationStatus) } - return UtModelGenerator.utModelConstructor.constructAssembleModelUsingMethodInvocation( + return generatorContext.utModelConstructor.constructAssembleModelUsingMethodInvocation( clazz, executableId, - parameterValues + parameterValues, + generatorContext ) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt index 6edf453c5b..d2196d2671 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt @@ -6,41 +6,53 @@ import org.utbot.common.isAbstract import org.utbot.engine.greyboxfuzzer.generator.DataGenerator import org.utbot.engine.greyboxfuzzer.generator.QuickCheckExtensions import org.utbot.engine.greyboxfuzzer.util.* +import org.utbot.engine.logger import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.objectClassId import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext -import ru.vyarus.java.generics.resolver.context.GenericsInfo import java.lang.reflect.Type import kotlin.random.Random -import kotlin.system.exitProcess class InterfaceImplementationsInstanceGenerator( private val resolvedType: Type, private val typeContext: GenericsContext, private val sourceOfRandomness: SourceOfRandomness, private val generationStatus: GenerationStatus, + private val generatorContext: GeneratorContext, private val depth: Int ) : InstanceGenerator { override fun generate(): UtModel { //Try to generate with statics with some probability val clazz = resolvedType.toClass() ?: return UtNullModel(objectClassId) if (Random.getTrue(50)) { - StaticsBasedInstanceGenerator( - clazz, - typeContext, - sourceOfRandomness, - generationStatus, - depth - ).generate().let { - return it + try { + StaticsBasedInstanceGenerator( + clazz, + typeContext, + sourceOfRandomness, + generationStatus, + generatorContext, + depth + ).generate().let { + if (it !is UtNullModel) return it + } + } catch (e: Throwable) { + logger.error { "Something wrong during StaticsBasedInstanceGenerator work" } } } - val genericsContext = QuickCheckExtensions.getRandomImplementerGenericContext(clazz, resolvedType) ?: return generateMock(clazz, resolvedType, typeContext) + val genericsContext = + QuickCheckExtensions.getRandomImplementerGenericContext(clazz, resolvedType) ?: return generateMock( + clazz, + resolvedType, + typeContext, + generatorContext + ) return ClassesInstanceGenerator( genericsContext.currentClass(), genericsContext, @@ -48,16 +60,17 @@ class InterfaceImplementationsInstanceGenerator( GenerationMethod.ANY, sourceOfRandomness, generationStatus, + generatorContext, depth ).generate().let { - if (it is UtNullModel && Random.getTrue(50)) generateMock(clazz, resolvedType, typeContext) else it + if (it is UtNullModel && Random.getTrue(50)) generateMock(clazz, resolvedType, typeContext, generatorContext) else it } } - private fun generateMock(clazz: Class<*>, resolvedType: Type, typeContext: GenericsContext): UtModel { + private fun generateMock(clazz: Class<*>, resolvedType: Type, typeContext: GenericsContext, generatorContext: GeneratorContext,): UtModel { if (!clazz.isInterface) return UtNullModel(clazz.id) val sootClazz = clazz.toSootClass() ?: return UtNullModel(clazz.id) - val constructor = UtModelGenerator.utModelConstructor + val constructor = generatorContext.utModelConstructor val allNeededInterfaces = clazz.methods.map { it.declaringClass }.filter { it != clazz }.toSet() val chainToGenericsContext = allNeededInterfaces.map { cl -> val chain = cl.toSootClass() @@ -69,14 +82,19 @@ class InterfaceImplementationsInstanceGenerator( if (chain == null || chain.any { it == null }) { null } else { - cl to QuickCheckExtensions.buildGenericsContextForInterfaceParent(resolvedType, clazz, chain.map { it!! }.reversed().drop(1)) + cl to QuickCheckExtensions.buildGenericsContextForInterfaceParent( + resolvedType, + clazz, + chain.map { it!! }.reversed().drop(1) + ) } } val allChainToGenericsContext = chainToGenericsContext + (clazz to typeContext) val mocks = clazz.methods .filter { it.isAbstract } .associateTo(mutableMapOf()) { method -> - val genericsContextForMethod = allChainToGenericsContext.find { it!!.first == method.declaringClass }?.second + val genericsContextForMethod = + allChainToGenericsContext.find { it!!.first == method.declaringClass }?.second val methodReturnType = if (genericsContextForMethod != null) { genericsContextForMethod.method(method).resolveReturnType().let { @@ -87,7 +105,11 @@ class InterfaceImplementationsInstanceGenerator( } val parameterTypeContext = ParameterTypeContext.forType(methodReturnType, genericsContextForMethod) val generatedUtModelWithReturnType = - DataGenerator.generate(parameterTypeContext, sourceOfRandomness, generationStatus) ?: UtNullModel(methodReturnType.toClass()!!.id) + try { + DataGenerator.generateUtModel(parameterTypeContext, depth, generatorContext, sourceOfRandomness, generationStatus) + } catch (_: Throwable) { + UtNullModel(methodReturnType.toClass()!!.id) + } method.executableId as ExecutableId to listOf(generatedUtModelWithReturnType) } return UtCompositeModel(constructor.computeUnusedIdAndUpdate(), clazz.id, isMock = true, mocks = mocks) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt index 1b7b75c0d5..841742f51a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt @@ -10,6 +10,7 @@ import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.MethodGenericsContext @@ -18,27 +19,30 @@ import kotlin.random.Random class ObjectGenerator( private val parameterTypeContext: ParameterTypeContext, private val sourceOfRandomness: SourceOfRandomness, - private val generationStatus: GenerationStatus + private val generationStatus: GenerationStatus, + private val generatorContext: GeneratorContext ) : InstanceGenerator { override fun generate(): UtModel { val currentSootMethod = (parameterTypeContext.generics as? MethodGenericsContext)?.currentMethod()?.toSootMethod() val potentialUsefulClasses = - currentSootMethod?.getAllTypesFromCastAndInstanceOfInstructions()?.mapNotNull { it.toJavaClass() } + currentSootMethod?.getAllTypesFromCastAndInstanceOfInstructions() val potentialInterestingObjectReplacement = - if (potentialUsefulClasses?.isNotEmpty() == true && Random.getTrue(50)) { + if (potentialUsefulClasses?.isNotEmpty() == true && Random.getTrue(70)) { val randomClass = potentialUsefulClasses.random() - GreyBoxFuzzerGenerators.generatorRepository - .getOrProduceGenerator(randomClass) - ?.generateImpl(sourceOfRandomness, generationStatus) + val generator = GreyBoxFuzzerGenerators.generatorRepository + .getOrProduceGenerator(randomClass, generatorContext) + generator?.generatorContext?.startCheckpoint() + generator?.generateImpl(sourceOfRandomness, generationStatus) } else null potentialInterestingObjectReplacement?.let { return it } - return GreyBoxFuzzerGenerators.generatorRepository + val generator = GreyBoxFuzzerGenerators.generatorRepository .getGenerators() .toList() .flatMap { it.second } .filter { !it.hasComponents() } .randomOrNull() - ?.generateImpl(sourceOfRandomness, generationStatus) ?: UtNullModel(parameterTypeContext.rawClass.id) + generator?.generatorContext?.startCheckpoint() + return generator?.generateImpl(sourceOfRandomness, generationStatus) ?: UtNullModel(parameterTypeContext.rawClass.id) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt index c4e0856d94..a6aa8896d7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt @@ -1,15 +1,35 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator +import org.utbot.engine.greyboxfuzzer.util.getTrue +import org.utbot.engine.greyboxfuzzer.util.toJavaClass import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.internal.ParameterTypeContext +import soot.Scene +import java.lang.reflect.Type +import kotlin.random.Random class ReflectionClassGenerator( - private val parameterTypeContext: ParameterTypeContext + private val parameterTypeContext: ParameterTypeContext, + private val generatorContext: GeneratorContext ) : InstanceGenerator { - override fun generate(): UtModel = - parameterTypeContext.resolved.typeParameters.randomOrNull()?.type?.componentClass?.let { - UtModelGenerator.utModelConstructor.construct(it, Class::class.java.id) - } ?: TODO("null") + override fun generate(): UtModel { + val packageName = parameterTypeContext.declarerName.substringBeforeLast('.') + val randomClassFromSamePackage = + Scene.v().classes + .filter { it.name.startsWith(packageName) } + .filterNot { it.isInnerClass } + .mapNotNull { it.toJavaClass() } + .randomOrNull() + if (randomClassFromSamePackage != null && Random.getTrue(50)) { + return generatorContext.utModelConstructor.construct(randomClassFromSamePackage, Class::class.java.id) + } + Scene.v().classes.randomOrNull()?.toJavaClass()?.let { + if (Random.getTrue(75)) { + return generatorContext.utModelConstructor.construct(it, Class::class.java.id) + } + } + return generatorContext.utModelConstructor.construct(Any::class.java, Class::class.java.id) + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt index 7aa714906d..34b8bf7e72 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt @@ -1,17 +1,46 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator import org.utbot.engine.greyboxfuzzer.util.getTrue import org.utbot.engine.greyboxfuzzer.util.toJavaClass +import org.utbot.engine.greyboxfuzzer.util.toSootMethod import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.classId import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.jClass +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.internal.ParameterTypeContext +import ru.vyarus.java.generics.resolver.context.MethodGenericsContext +import soot.NullType import soot.Scene +import soot.jimple.Stmt import java.lang.reflect.Type import kotlin.random.Random -class ReflectionTypeGenerator(private val parameterTypeContext: ParameterTypeContext) : InstanceGenerator { +class ReflectionTypeGenerator( + private val parameterTypeContext: ParameterTypeContext, + private val generatorContext: GeneratorContext + ) : InstanceGenerator { + override fun generate(): UtModel { + //Take random class in function + val currentSootMethod = + (parameterTypeContext.generics as? MethodGenericsContext)?.currentMethod()?.toSootMethod() + val randomTypeFromMethod = + currentSootMethod?.activeBody?.units?.filterIsInstance() + ?.flatMap { it.useBoxes.map { it.value.type } } + ?.filter { it !is NullType } + ?.toSet() + ?.mapNotNull { + try { + it.classId.jClass + } catch (e: Throwable) { + null + } + }?.randomOrNull() + if (Random.getTrue(70) && randomTypeFromMethod != null) { + return generatorContext.utModelConstructor.construct(randomTypeFromMethod, Type::class.java.id) + } + val packageName = parameterTypeContext.declarerName.substringBeforeLast('.') val randomClassFromSamePackage = Scene.v().classes @@ -19,16 +48,16 @@ class ReflectionTypeGenerator(private val parameterTypeContext: ParameterTypeCon .filterNot { it.isInnerClass } .mapNotNull { it.toJavaClass() } .randomOrNull() - if (randomClassFromSamePackage != null && Random.getTrue(50)) { - return UtModelGenerator.utModelConstructor.construct(randomClassFromSamePackage, Type::class.java.id) + if (randomClassFromSamePackage != null && Random.getTrue(25)) { + return generatorContext.utModelConstructor.construct(randomClassFromSamePackage, Type::class.java.id) } - Scene.v().classes.randomOrNull()?.toJavaClass()?.let { - return UtModelGenerator.utModelConstructor.construct(it, Type::class.java.id) + try { + Scene.v().classes.randomOrNull()?.toJavaClass()?.let { + return generatorContext.utModelConstructor.construct(it, Type::class.java.id) + } + } catch (e: Throwable) { + return generatorContext.utModelConstructor.construct(Any::class.java, Type::class.java.id) } - return UtModelGenerator.utModelConstructor.construct(Any::class.java, Type::class.java.id) + return generatorContext.utModelConstructor.construct(Any::class.java, Type::class.java.id) } -} - -//val packageName = parameterTypeContext.declarerName.substringBeforeLast('.') -//Scene.v().classes.filter { it.name.startsWith("com.alibaba.fastjson.util") } -////parameterTypeContext.declarerName \ No newline at end of file +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt index 6732f7e5c5..00ddaf642b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt @@ -2,6 +2,7 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import kotlin.random.Random @@ -11,13 +12,14 @@ open class StaticsBasedInstanceGenerator( private val gctx: GenericsContext, private val sourceOfRandomness: SourceOfRandomness, private val generationStatus: GenerationStatus, + private val generatorContext: GeneratorContext, private val depth: Int ) : InstanceGenerator { override fun generate(): UtModel { val staticMethodBasedGenerator = - StaticsMethodBasedInstanceGenerator(clazz, gctx, sourceOfRandomness, generationStatus, depth) + StaticsMethodBasedInstanceGenerator(clazz, gctx, sourceOfRandomness, generationStatus, generatorContext, depth) val staticFieldBasedGenerator = - StaticsFieldBasedInstanceGenerator(clazz, gctx) + StaticsFieldBasedInstanceGenerator(clazz, gctx, generatorContext) //TODO: repair StaticFieldBasedGenerator return if (true) { staticMethodBasedGenerator.generate() ?: staticFieldBasedGenerator.generate() diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt index aace2ec21f..daf33962ce 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt @@ -1,7 +1,7 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.greyboxfuzzer.util.SootStaticsCollector -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.engine.greyboxfuzzer.util.hasModifiers import org.utbot.engine.greyboxfuzzer.util.toClass import org.utbot.external.api.classIdForType @@ -19,11 +19,12 @@ import java.util.* internal class StaticsFieldBasedInstanceGenerator( private val clazz: Class<*>, - private val gctx: GenericsContext + private val gctx: GenericsContext, + private val generatorContext: GeneratorContext ) : InstanceGenerator { override fun generate(): UtModel = getRandomStaticToProduceInstanceUsingSoot()?.let { fieldToProvideInstance -> - createUtModelForStaticFieldInvocation(UtModelGenerator.utModelConstructor, fieldToProvideInstance) + createUtModelForStaticFieldInvocation(generatorContext.utModelConstructor, fieldToProvideInstance) } ?: UtNullModel(clazz.id) //In case of no Soot diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt index d760c90539..33a8cf452a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt @@ -6,6 +6,7 @@ import org.utbot.engine.greyboxfuzzer.util.toClass import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* import org.utbot.quickcheck.generator.GenerationStatus +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Method @@ -18,6 +19,7 @@ internal class StaticsMethodBasedInstanceGenerator( private val gctx: GenericsContext, private val sourceOfRandomness: SourceOfRandomness, private val generationStatus: GenerationStatus, + private val generatorContext: GeneratorContext, private val depth: Int ) : InstanceGenerator { override fun generate(): UtModel = @@ -35,6 +37,7 @@ internal class StaticsMethodBasedInstanceGenerator( resolvedMethodContext, sourceOfRandomness, generationStatus, + generatorContext, depth ).invoke() } ?: UtNullModel(clazz.id) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt index c8b2b5b90a..6d45632e13 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt @@ -6,11 +6,13 @@ import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.engine.logger import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.fieldId +import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.method import org.utbot.quickcheck.generator.GenerationState import org.utbot.quickcheck.generator.GenerationStatus import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.quickcheck.internal.ParameterTypeContext import org.utbot.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext @@ -40,6 +42,7 @@ object Mutator { val randomParameter = seedCopy.parameters.getOrNull(randomParameterIndex) ?: return seedCopy val randomParameterGenerator = randomParameter.generator ?: return seedCopy randomParameterGenerator.generationState = GenerationState.MODIFY + randomParameterGenerator.generatorContext.startCheckpoint() val newUtModel = randomParameterGenerator.generateImpl(sourceOfRandomness, genStatus) val newFParameter = randomParameter.replaceUtModel(newUtModel) return seedCopy.replaceFParameter(randomParameterIndex, newFParameter) @@ -48,32 +51,36 @@ object Mutator { fun regenerateFields( clazz: Class<*>, classInstance: UtAssembleModel, - fieldsToRegenerate: List + fieldsToRegenerate: List, + generatorContext: GeneratorContext ): UtModel { val parameterTypeContext = ParameterTypeContext.forClass(clazz) val modifications = - fieldsToRegenerate.mapNotNull { setNewFieldValue(it, parameterTypeContext.generics, classInstance) } + fieldsToRegenerate.mapNotNull { setNewFieldValue(it, parameterTypeContext.generics, classInstance, generatorContext) } return classInstance.addModification(modifications) } fun regenerateFieldsWithContext( genericsContext: GenericsContext, classInstance: UtAssembleModel, - fieldsToRegenerate: List + fieldsToRegenerate: List, + generatorContext: GeneratorContext ): UtModel { - val modifications = fieldsToRegenerate.mapNotNull { setNewFieldValue(it, genericsContext, classInstance) } + val modifications = fieldsToRegenerate.mapNotNull { setNewFieldValue(it, genericsContext, classInstance, generatorContext) } return classInstance.addModification(modifications) } fun regenerateFieldWithContext( genericsContext: GenericsContext, classInstance: UtAssembleModel, - fieldToRegenerate: Field + fieldToRegenerate: Field, + generatorContext: GeneratorContext, ): Pair? = setNewFieldValueWithGenerator( fieldToRegenerate, genericsContext, - classInstance + classInstance, + generatorContext )?.let { (generator, modification) -> classInstance.addOrReplaceModification(modification) to generator } @@ -81,9 +88,10 @@ object Mutator { private fun setNewFieldValueWithGenerator( field: Field, genericsContext: GenericsContext, - clazzInstance: UtAssembleModel + clazzInstance: UtAssembleModel, + generatorContext: GeneratorContext, ): Pair? { - if (field.hasAtLeastOneOfModifiers( + if (field.hasModifiers( Modifier.STATIC, Modifier.FINAL ) @@ -98,12 +106,19 @@ object Mutator { genericsContext ) val generatorForField = - GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(parameterTypeContextForResolvedType, 0) + GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(parameterTypeContextForResolvedType, generatorContext, 0) ?: return null - val newFieldValue = generatorForField.generateImpl( - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus - ) + var newFieldValue: UtModel = UtNullModel(parameterTypeContextForResolvedType.rawClass.id) + for (i in 0 until 3) { + try { + generatorForField.generationState = GenerationState.REGENERATE + generatorForField.generatorContext.startCheckpoint() + newFieldValue = generatorForField.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) + if (newFieldValue !is UtNullModel) break + } catch (e: Throwable) { + continue + } + } logger.debug { "NEW FIELD VALUE = $newFieldValue" } return generatorForField to UtDirectSetFieldModel(clazzInstance, field.fieldId, newFieldValue) } @@ -111,12 +126,14 @@ object Mutator { private fun setNewFieldValue( field: Field, genericsContext: GenericsContext, - clazzInstance: UtAssembleModel - ): UtStatementModel? = setNewFieldValueWithGenerator(field, genericsContext, clazzInstance)?.second + clazzInstance: UtAssembleModel, + generatorContext: GeneratorContext, + ): UtStatementModel? = setNewFieldValueWithGenerator(field, genericsContext, clazzInstance, generatorContext)?.second fun mutateThisInstance( thisInstance: ThisInstance, - fieldsToRegenerate: List + fieldsToRegenerate: List, + generatorContext: GeneratorContext ): ThisInstance { if (thisInstance !is NormalMethodThisInstance) return thisInstance val thisInstanceAsUtModel = thisInstance.utModel as UtAssembleModel @@ -124,13 +141,15 @@ object Mutator { regenerateFields( thisInstance.classId.jClass, thisInstanceAsUtModel, - fieldsToRegenerate + fieldsToRegenerate, + generatorContext ) return NormalMethodThisInstance(mutationResult, thisInstance.generator, thisInstance.classId) } fun mutateParameter( - fParameter: FParameter + fParameter: FParameter, + generatorContext: GeneratorContext, ): FParameter { val originalParameter = fParameter.parameter val originalUtModel = fParameter.utModel @@ -149,7 +168,7 @@ object Mutator { val resolvedParameterCtx = originalParameter.resolveParameterTypeAndBuildParameterContext(index, randomMethod.method) val generatorForParameter = - GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(resolvedParameterCtx, 0) + GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(resolvedParameterCtx, generatorContext, 0) ?: return fParameter DataGenerator.generate( generatorForParameter, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt index eb507b5dc2..fa43ffc4e2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt @@ -7,6 +7,7 @@ import org.utbot.framework.plugin.api.EnvironmentModels data class Seed( val thisInstance: ThisInstance, val parameters: List, + val lineCoverage: Set, var score: Double = 0.0 ) { @@ -15,13 +16,14 @@ data class Seed( } fun copy(): Seed { - return Seed(thisInstance.copy(), parameters.map { it.copy() }, score) + return Seed(thisInstance.copy(), parameters.map { it.copy() }, lineCoverage.toSet(), score) } fun replaceFParameter(index: Int, newFParameter: FParameter): Seed { return Seed( thisInstance.copy(), parameters.mapIndexed { ind, fParameter -> if (ind == index) newFParameter else fParameter.copy() }, + lineCoverage.toSet(), score ) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt index 4eaaa479f6..73a2c244ee 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt @@ -4,44 +4,62 @@ import org.utbot.engine.greyboxfuzzer.util.getTrue import kotlin.math.abs import kotlin.random.Random -class SeedCollector(private val maxSize: Int = 50) { - private val seeds = sortedSetOf( - comparator = - compareByDescending { seed: Seed -> seed.score }.thenComparator { seed1, seed2 -> if (seed1 === seed2) 0 else 1 } - ) +class SeedCollector(private val maxSize: Int = 50, private val methodLines: Set) { + private val seeds = ArrayList(maxSize) +// sortedSetOf( +// comparator = +// compareByDescending { seed: Seed -> seed.score }.thenComparator { seed1, seed2 -> if (seed1 === seed2) 0 else 1 } +// ) + fun calcSeedScore(coverage: Set): Double = + coverage.sumOf { line -> + val numOfSeedCoveredLine = seeds.count { it.lineCoverage.contains(line) } + if (numOfSeedCoveredLine == 0) { + Double.MAX_VALUE + } else { + 1.0 / numOfSeedCoveredLine + } + } + + private fun recalculateSeedScores() { + seeds.forEach { seed -> + seed.score = calcSeedScore(seed.lineCoverage) + } + } + + // fun addSeed(seed: Seed) { - seeds.add(seed) + if (seeds.isEmpty()) { + seeds.add(seed) + return + } + val indexToInsert = seeds.indexOfFirst { it.score <= seed.score } + if (indexToInsert == -1 && seeds.size < maxSize - 1) { + seeds.add(seed) + recalculateSeedScores() + seeds.sortByDescending { it.score } + return + } + seeds.add(indexToInsert, seed) + recalculateSeedScores() + seeds.sortByDescending { it.score } while (seeds.size >= maxSize) { - seeds.remove(seeds.last()) + seeds.removeLast() } } -// fun getRandomWeightedSeed(): Seed { -// val priorityWeightedFunction = { a: Double -> exp(a).pow(2) } -// val minPriority = seeds.last().priority -// val maxPriority = seeds.first().priority -// val priorityDiffs = if (maxPriority == minPriority) 1.0 else maxPriority - minPriority -// val normalizedSeeds = seeds.map { it to (it.priority - minPriority) / priorityDiffs } -// val sumOfSeedPriorities = normalizedSeeds.sumOf { priorityWeightedFunction.invoke(it.second) } -// val randomSeedPriority = Random.nextDouble(0.0, sumOfSeedPriorities) -// var priorityCounter = 0.0 -// normalizedSeeds.forEach { (seed, priority) -> -// priorityCounter += priorityWeightedFunction.invoke(priority) -// if (priorityCounter >= randomSeedPriority) { -// return seed -// } -// } -// return seeds.first() -// } - - fun getRandomWeightedSeed() = - if (Random.getTrue(75)) { - val bestSeed = getBestSeed().score - seeds.filter { abs(it.score - bestSeed) < 1e-5 }.randomOrNull() - } else { - seeds.randomOrNull() + fun getRandomWeightedSeed(): Seed { + val scoreSum = seeds.sumOf { it.score } + val randomScore = Random.nextDouble(0.0, scoreSum) + var scoreCounter = 0.0 + seeds.forEach { seed -> + scoreCounter += seed.score + if (scoreCounter >= randomScore) { + return seed + } } + return seeds.first() + } fun getBestSeed() = seeds.first() fun removeSeed(seed: Seed) = seeds.remove(seed) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt index 6912e3e3e9..c4ac95ad2a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt @@ -166,12 +166,7 @@ fun ru.vyarus.java.generics.resolver.context.container.ParameterizedTypeImpl.get } fun List>.chooseRandomConstructor() = - if (Random.getTrue(75)) { - this.shuffled().minByOrNull { it.parameterCount } - } else this.randomOrNull() - -fun List.chooseRandomMethodToGenerateInstance() = - if (Random.getTrue(75)) { + if (Random.getTrue(60)) { this.shuffled().minByOrNull { it.parameterCount } } else this.randomOrNull() @@ -201,7 +196,15 @@ object ReflectionUtils { Any::class.java.rawType } } else type - return Types.forJavaLangReflectType(safeType) + return try { + Types.forJavaLangReflectType(safeType) + } catch (e: Throwable) { + try { + Types.forJavaLangReflectType(safeType.toClass()) + } catch (e: Throwable) { + Types.forJavaLangReflectType(Any::class.java) + } + } } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt index 93c791f5ed..2ba92e75e9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt @@ -1,6 +1,7 @@ package org.utbot.engine.greyboxfuzzer.util import org.utbot.framework.plugin.api.util.signature +import soot.ArrayType import soot.Hierarchy import soot.RefType import soot.Scene @@ -47,14 +48,49 @@ fun SootClass.getImplementersOfWithChain(): List> { return res } -fun SootMethod.getAllTypesFromCastAndInstanceOfInstructions(): Set = +fun SootMethod.getAllTypesFromCastAndInstanceOfInstructions(): Set> = this.activeBody.units.asSequence().filterIsInstance() .map { it.rightOp } .filter { it is JCastExpr || it is JInstanceOfExpr } .mapNotNull { when (it) { - is JCastExpr -> (it.type as? RefType)?.sootClass - else -> ((it as JInstanceOfExpr).checkType as? RefType)?.sootClass + is JCastExpr -> { + val type = it.type + when (type) { + is RefType -> type.sootClass?.toJavaClass() + is ArrayType -> { + if (type.elementType is RefType) { + try { + Class.forName("[L${type.elementType};") + } catch (e: Throwable) { + null + } + } else { + null + } + } + else -> null + } + //(it.type as? RefType)?.sootClass?.toJavaClass() + } + else -> { + val type = (it as JInstanceOfExpr).checkType + when (type) { + is RefType -> type.sootClass?.toJavaClass() + is ArrayType -> { + if (type.elementType is RefType) { + try { + Class.forName("[L${type.elementType};") + } catch (e: Throwable) { + null + } + } else { + null + } + } + else -> null + } + } } }.toSet() diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt index af147cc9cc..2d4ec5619e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt @@ -5,6 +5,7 @@ import org.utbot.engine.greyboxfuzzer.generator.* import org.utbot.external.api.classIdForType import org.utbot.framework.concrete.UtModelConstructor import org.utbot.framework.plugin.api.* +import org.utbot.quickcheck.generator.GeneratorContext import java.lang.reflect.Method import java.lang.reflect.Parameter @@ -66,9 +67,10 @@ fun UtModel.copy(): UtModel = fun UtModelConstructor.constructAssembleModelUsingMethodInvocation( clazz: Class<*>, methodExecutableId: ExecutableId, - parameterValues: List + parameterValues: List, + generatorContext: GeneratorContext ): UtAssembleModel { - val genId = UtModelGenerator.utModelConstructor.computeUnusedIdAndUpdate() + val genId = generatorContext.utModelConstructor.computeUnusedIdAndUpdate() return UtAssembleModel( genId, classIdForType(clazz), diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt index cd6c88fed8..409e5e2c43 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt @@ -4,13 +4,13 @@ import org.utbot.framework.concrete.UtModelConstructor import org.utbot.framework.plugin.api.UtModel import java.util.* -object UtModelGenerator { - - @JvmStatic - var utModelConstructor = UtModelConstructor(IdentityHashMap()) - - fun reset() { - utModelConstructor = UtModelConstructor(IdentityHashMap()) - } - -} \ No newline at end of file +//object UtModelGenerator { +// +// @JvmStatic +// var utModelConstructor = UtModelConstructor(IdentityHashMap()) +// +// fun reset() { +// utModelConstructor = UtModelConstructor(IdentityHashMap()) +// } +// +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt index 2d445af178..4ce7a00637 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt @@ -8,6 +8,8 @@ import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.engine.greyboxfuzzer.util.getImplementersOfWithChain import org.utbot.engine.greyboxfuzzer.util.removeIfAndReturnRemovedElements import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.objectClassId import org.utbot.quickcheck.internal.Reflection import org.utbot.quickcheck.internal.ReflectionException import org.utbot.quickcheck.random.SourceOfRandomness @@ -28,9 +30,13 @@ abstract class Generator protected constructor(types: List>) : Gen { var generatedUtModel: UtModel? = null var generationState = GenerationState.REGENERATE var nestedGenerators = mutableListOf() + lateinit var generatorContext: GeneratorContext - open fun generateImpl(random: SourceOfRandomness, status: GenerationStatus): UtModel = - when (generationState) { + open fun generateImpl(random: SourceOfRandomness, status: GenerationStatus): UtModel { + if (generatorContext.checkPoint()) { + return UtNullModel(objectClassId) + } + return when (generationState) { GenerationState.REGENERATE -> { generate(random, status).also { generatedUtModel = it @@ -56,6 +62,7 @@ abstract class Generator protected constructor(types: List>) : Gen { } } } + } private fun flattenedTo(destination: MutableList) { destination.add(this) @@ -250,6 +257,7 @@ abstract class Generator protected constructor(types: List>) : Gen { repo = provided } + fun isGeneratorContextInitialized() = this::generatorContext.isInitialized /** * Used by the framework to make a copy of the receiver. * @@ -260,7 +268,10 @@ abstract class Generator protected constructor(types: List>) : Gen { it.generatedUtModel = generatedUtModel it.generationState = generationState it.nestedGenerators = nestedGenerators.map { it.copy() }.toMutableList() - GeneratorConfigurator.configureGenerator(it, 85) + if (isGeneratorContextInitialized()) { + it.generatorContext = generatorContext + } + GeneratorConfigurator.configureGenerator(it, 95) } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorContext.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorContext.kt new file mode 100644 index 0000000000..0f5c49f35f --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorContext.kt @@ -0,0 +1,21 @@ +package org.utbot.quickcheck.generator + +import org.utbot.framework.concrete.UtModelConstructor +import java.util.* + +data class GeneratorContext( + val utModelConstructor: UtModelConstructor = UtModelConstructor(IdentityHashMap()), + val timeoutInMillis: Long = 5000L +) { + var timeOfGenerationStart = 0L + var timeToFinishGeneration = 0L + + fun startCheckpoint() { + timeOfGenerationStart = System.currentTimeMillis() + timeToFinishGeneration = timeOfGenerationStart + timeoutInMillis + } + + fun checkPoint(): Boolean { + return System.currentTimeMillis() > timeToFinishGeneration + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt index a2ad748b2c..111c37ea28 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt @@ -1,10 +1,11 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.stringClassId import org.utbot.quickcheck.generator.GenerationStatus import org.utbot.quickcheck.generator.Generator +import org.utbot.quickcheck.generator.Size import org.utbot.quickcheck.random.SourceOfRandomness /** @@ -16,18 +17,20 @@ import org.utbot.quickcheck.random.SourceOfRandomness * [GenerationStatus.size]. */ abstract class AbstractStringGenerator : Generator(String::class.java) { + protected open var lengthRange: IntRange? = null + override fun generate( random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(generateValue(random, status), stringClassId) + return generatorContext.utModelConstructor.construct(generateValue(random, status), stringClassId) } fun generateValue( random: SourceOfRandomness, status: GenerationStatus ): String { - val codePoints = IntArray(status.size()) + val codePoints = IntArray(lengthRange?.randomOrNull() ?: status.size()) for (i in codePoints.indices) codePoints[i] = nextCodePoint(random) return String(codePoints, 0, codePoints.size) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt index 43c7e0549b..2ed537c243 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.booleanWrapperClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -19,6 +19,6 @@ class BooleanGenerator : Generator( random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextBoolean(), booleanWrapperClassId) + return generatorContext.utModelConstructor.construct(random.nextBoolean(), booleanWrapperClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt index a0c7a98edf..1d9736a188 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.byteWrapperClassId @@ -35,6 +35,6 @@ class ByteGenerator : IntegralGenerator(listOf(Byte::class.javaObjectType)) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextByte(min, max), byteWrapperClassId) + return generatorContext.utModelConstructor.construct(random.nextByte(min, max), byteWrapperClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt index 034ba18538..f730c59657 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.charWrapperClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -38,6 +38,6 @@ class CharacterGenerator : Generator( random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextChar(min, max), charWrapperClassId) + return generatorContext.utModelConstructor.construct(random.nextChar(min, max), charWrapperClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt index 608b81651b..bb4a458388 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.doubleWrapperClassId import org.utbot.quickcheck.generator.DecimalGenerator @@ -36,7 +36,7 @@ class DoubleGenerator : DecimalGenerator(listOf(Double::class.javaObjectType)) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(generateValue(random, status), doubleWrapperClassId) + return generatorContext.utModelConstructor.construct(generateValue(random, status), doubleWrapperClassId) } fun generateValue( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt index e1e4b4641b..5e5a873601 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt @@ -1,47 +1,47 @@ -package org.utbot.quickcheck.generator.java.lang - -import org.utbot.quickcheck.generator.GeneratorConfiguration -import org.utbot.quickcheck.generator.java.lang.strings.CodePoints -import org.utbot.quickcheck.generator.java.lang.strings.CodePoints.Companion.forCharset -import org.utbot.quickcheck.random.SourceOfRandomness -import java.nio.charset.Charset - -/** - * - * Produces [String]s whose code points correspond to code points in - * a given [Charset] - * ([by default][Charset.defaultCharset]). - */ -class Encoded : AbstractStringGenerator() { - private var charsetPoints: CodePoints? = null - - init { - initialize(Charset.defaultCharset()) - } - - /** - * Tells this generator to emit strings in the given charset. - * - * @param charset a charset to use as the source for characters of - * generated strings - */ - fun configure(charset: InCharset) { - initialize(Charset.forName(charset.value)) - } - - private fun initialize(charset: Charset) { - charsetPoints = forCharset(charset) - } - - override fun nextCodePoint(random: SourceOfRandomness): Int { - return charsetPoints!!.at(random.nextInt(0, charsetPoints!!.size() - 1)) - } - - /** - * Names a [Charset]. - */ - @Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.TYPE) - @Retention(AnnotationRetention.RUNTIME) - @GeneratorConfiguration - annotation class InCharset(val value: String) -} \ No newline at end of file +//package org.utbot.quickcheck.generator.java.lang +// +//import org.utbot.quickcheck.generator.GeneratorConfiguration +//import org.utbot.quickcheck.generator.java.lang.strings.CodePoints +//import org.utbot.quickcheck.generator.java.lang.strings.CodePoints.Companion.forCharset +//import org.utbot.quickcheck.random.SourceOfRandomness +//import java.nio.charset.Charset +// +///** +// * +// * Produces [String]s whose code points correspond to code points in +// * a given [Charset] +// * ([by default][Charset.defaultCharset]). +// */ +//class Encoded : AbstractStringGenerator() { +// private var charsetPoints: CodePoints? = null +// +// init { +// initialize(Charset.defaultCharset()) +// } +// +// /** +// * Tells this generator to emit strings in the given charset. +// * +// * @param charset a charset to use as the source for characters of +// * generated strings +// */ +// fun configure(charset: InCharset) { +// initialize(Charset.forName(charset.value)) +// } +// +// private fun initialize(charset: Charset) { +// charsetPoints = forCharset(charset) +// } +// +// override fun nextCodePoint(random: SourceOfRandomness): Int { +// return charsetPoints!!.at(random.nextInt(0, charsetPoints!!.size() - 1)) +// } +// +// /** +// * Names a [Charset]. +// */ +// @Target(AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.FIELD, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.TYPE) +// @Retention(AnnotationRetention.RUNTIME) +// @GeneratorConfiguration +// annotation class InCharset(val value: String) +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt index ee91888093..d099753758 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.floatWrapperClassId import org.utbot.quickcheck.generator.DecimalGenerator @@ -34,6 +34,6 @@ class FloatGenerator : DecimalGenerator(listOf(Float::class.javaObjectType)) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextFloat(min, max), floatWrapperClassId) + return generatorContext.utModelConstructor.construct(random.nextFloat(min, max), floatWrapperClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt index 36cd3d2437..17342c0bb4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.intWrapperClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -34,7 +34,7 @@ class IntegerGenerator : IntegralGenerator(listOf(Int::class.javaObjectType)) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(generateValue(random), intWrapperClassId) + return generatorContext.utModelConstructor.construct(generateValue(random), intWrapperClassId) } fun generateValue( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt index 02f14a0a23..60f3c78845 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.longWrapperClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -34,7 +34,7 @@ class LongGenerator : IntegralGenerator(listOf(Long::class.javaObjectType)) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(generateValue(random, status), longWrapperClassId) + return generatorContext.utModelConstructor.construct(generateValue(random, status), longWrapperClassId) } fun generateValue( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt index a57ab68a86..f72d068748 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.booleanClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -15,6 +15,6 @@ class PrimitiveBooleanGenerator : Generator(listOf(Boolean::class.javaPrimitiveT random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextBoolean(), booleanClassId) + return generatorContext.utModelConstructor.construct(random.nextBoolean(), booleanClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt index dd94281b31..b4327f174c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.byteClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -34,6 +34,6 @@ class PrimitiveByteGenerator : IntegralGenerator(listOf(Byte::class.javaPrimitiv random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextByte(min, max), byteClassId) + return generatorContext.utModelConstructor.construct(random.nextByte(min, max), byteClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt index 43db91f4b0..d8046b4e22 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.charClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -34,7 +34,7 @@ class PrimitiveCharGenerator : Generator(listOf(Char::class.javaPrimitiveType!!) random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextChar(min, max), charClassId) + return generatorContext.utModelConstructor.construct(random.nextChar(min, max), charClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt index 1235302a24..a155316448 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.doubleClassId import org.utbot.quickcheck.generator.DecimalGenerator @@ -36,7 +36,7 @@ class PrimitiveDoubleGenerator : DecimalGenerator(listOf(Double::class.javaPrimi random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(generateValue(random, status), doubleClassId) + return generatorContext.utModelConstructor.construct(generateValue(random, status), doubleClassId) } fun generateValue( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt index 6b7ddb17a7..af5145460c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.floatClassId import org.utbot.quickcheck.generator.DecimalGenerator @@ -34,6 +34,6 @@ class PrimitiveFloatGenerator : DecimalGenerator(listOf(Float::class.javaPrimiti random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextFloat(min, max), floatClassId) + return generatorContext.utModelConstructor.construct(random.nextFloat(min, max), floatClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt index e8029e4101..3ffea266f9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.intClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -34,7 +34,7 @@ class PrimitiveIntGenerator : IntegralGenerator(listOf(Int::class.javaPrimitiveT random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(generateValue(random, status), intClassId) + return generatorContext.utModelConstructor.construct(generateValue(random, status), intClassId) } fun generateValue( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt index 75617c02fc..34cb27bf0f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.longClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -34,7 +34,7 @@ class PrimitiveLongGenerator : IntegralGenerator(listOf(Long::class.javaPrimitiv random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(generateValue(random, status), longClassId) + return generatorContext.utModelConstructor.construct(generateValue(random, status), longClassId) } fun generateValue( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt index ba5cb4fa03..2123d0a54d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.shortClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -34,6 +34,6 @@ class PrimitiveShortGenerator : IntegralGenerator(listOf(Short::class.javaPrimit random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextShort(min, max), shortClassId) + return generatorContext.utModelConstructor.construct(random.nextShort(min, max), shortClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt index 003a4c4bd1..5155652f7e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.shortWrapperClassId import org.utbot.quickcheck.generator.GenerationStatus @@ -34,6 +34,6 @@ class ShortGenerator : IntegralGenerator(listOf(Short::class.javaObjectType)) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextShort(min, max), shortWrapperClassId) + return generatorContext.utModelConstructor.construct(random.nextShort(min, max), shortWrapperClassId) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt index be1490c796..e16a0cbf7d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt @@ -11,26 +11,29 @@ import kotlin.random.Random class StringGenerator : AbstractStringGenerator() { private var codePoints = setOf(0 until Character.MIN_SURROGATE.code) + override var lengthRange: IntRange? = null override fun nextCodePoint(random: SourceOfRandomness): Int { + return codePoints.random().random() val codePoint = chooseRandomCodePoint() return codePoint.random() } private fun chooseRandomCodePoint(): IntRange { - val size = codePoints.sumOf { it.last - it.first } - val randomIntToSize = Random.nextInt(size) - var curSum = 0 - for (codePoint in codePoints) { - val codePointSize = codePoint.last - codePoint.first - curSum += codePointSize - if (curSum >= randomIntToSize) { - return codePoint - } - } +// val size = codePoints.sumOf { it.last - it.first } +// val randomIntToSize = Random.nextInt(size) +// var curSum = 0 +// for (codePoint in codePoints) { +// val codePointSize = codePoint.last - codePoint.first +// curSum += codePointSize +// if (curSum >= randomIntToSize) { +// return codePoint +// } +// } return codePoints.random() } - fun configure(codePoints: Set) { + fun configure(codePoints: Set, lengthRange: IntRange) { this.codePoints = codePoints + this.lengthRange = lengthRange } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt index ce69bdb8a0..92845aed83 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.math -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.DecimalGenerator @@ -91,7 +91,7 @@ class BigDecimalGenerator : DecimalGenerator(BigDecimal::class.java) { generated = random.nextBigInteger(range.bitLength()) } while (generated >= range) - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( minShifted.add(BigDecimal(generated)).movePointLeft(scale), BigDecimal::class.id ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt index 337a5aa483..a84d55df4e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.math -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -50,14 +50,14 @@ class BigIntegerGenerator : IntegralGenerator(BigInteger::class.java) { ): UtModel { val numberOfBits = status.size() + 1 if (min == null && max == null) - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( random.nextBigInteger(numberOfBits), BigInteger::class.id ) val minToUse = min ?: max!!.subtract(BigInteger.TEN.pow(numberOfBits)) val maxToUse = max ?: minToUse.add(BigInteger.TEN.pow(numberOfBits)) - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( Ranges.choose(random, minToUse, maxToUse), BigInteger::class.id ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt index c897af04c0..3814951298 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.nio.charset -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtModel @@ -21,9 +21,9 @@ class CharsetGenerator : Generator(Charset::class.java) { status: GenerationStatus ): UtModel { val charsetName = random.choose(Charset.availableCharsets().keys) - val charsetNameModel = utModelConstructor.construct(charsetName, stringClassId) + val charsetNameModel = generatorContext.utModelConstructor.construct(charsetName, stringClassId) val charsetForNameId = Charset::forName.executableId - val modelId = utModelConstructor.computeUnusedIdAndUpdate() + val modelId = generatorContext.utModelConstructor.computeUnusedIdAndUpdate() return UtAssembleModel( modelId, Charset::class.id, diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt index a2ceb0c34a..4d1b4093c8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtModel @@ -55,9 +55,9 @@ class ClockGenerator : Generator(Clock::class.java) { ): UtModel { val instant = random.nextInstant(min, max) val zoneId = UTC_ZONE_ID - val instantModel = utModelConstructor.construct(instant, Instant::class.id) - val zoneIdModel = utModelConstructor.construct(zoneId, ZoneId::class.id) - val modelId = utModelConstructor.computeUnusedIdAndUpdate() + val instantModel = generatorContext.utModelConstructor.construct(instant, Instant::class.id) + val zoneIdModel = generatorContext.utModelConstructor.construct(zoneId, ZoneId::class.id) + val modelId = generatorContext.utModelConstructor.computeUnusedIdAndUpdate() val constructorId = Clock::fixed.executableId return UtAssembleModel( id = modelId, diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt index 3c41cb7bc4..6bbe0e11e4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -44,6 +44,6 @@ class DurationGenerator : Generator(Duration::class.java) { } override fun generate(random: SourceOfRandomness, status: GenerationStatus): UtModel { - return utModelConstructor.construct(random.nextDuration(min, max), Duration::class.id) + return generatorContext.utModelConstructor.construct(random.nextDuration(min, max), Duration::class.id) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt index d73eb2d22e..acab0320d8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -44,6 +44,6 @@ class InstantGenerator : Generator(Instant::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct(random.nextInstant(min, max), Instant::class.id) + return generatorContext.utModelConstructor.construct(random.nextInstant(min, max), Instant::class.id) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt index 828aa6faed..71b4a9fe6f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -47,7 +47,7 @@ class LocalDateGenerator : Generator(LocalDate::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( LocalDate.ofEpochDay( random.nextLong(min.toEpochDay(), max.toEpochDay()) ), diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt index af2c171080..4384b5af9e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -54,7 +54,7 @@ class LocalDateTimeGenerator : Generator( /* Project the LocalDateTime to an Instant for easy long-based generation. Any zone id will do as long as we use the same one throughout. */ - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( LocalDateTime.ofInstant( random.nextInstant( min.atZone(UTC_ZONE_ID).toInstant(), diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt index 58f2c87d02..8377ff7c6b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -48,7 +48,7 @@ class LocalTimeGenerator : Generator(LocalTime::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( LocalTime.ofNanoOfDay( random.nextLong(min.toNanoOfDay(), max.toNanoOfDay()) ), diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt index fc670ae5dd..9cfbf6e273 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -54,7 +54,7 @@ class MonthDayGenerator : Generator(MonthDay::class.java) { val minEpochDay = min.atYear(2000).toEpochDay() val maxEpochDay = max.atYear(2000).toEpochDay() val date = LocalDate.ofEpochDay(random.nextLong(minEpochDay, maxEpochDay)) - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( MonthDay.of(date.monthValue, date.dayOfMonth), MonthDay::class.id ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt index 95c56cc99d..ddaa38a5dc 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -53,7 +53,7 @@ class OffsetDateTimeGenerator : Generator( ): UtModel { // Project the OffsetDateTime to an Instant for easy long-based generation. - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( OffsetDateTime.ofInstant( random.nextInstant(min.toInstant(), max.toInstant()), UTC_ZONE_ID diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt index 6ead6bd49a..a882ad6801 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -60,7 +60,7 @@ class OffsetTimeGenerator : Generator(OffsetTime::class.java) { .toNanoOfDay() ) ) - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( OffsetTime.of(time, ZoneOffset.UTC), OffsetTime::class.id ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt index 4b08170460..635d9ac4ff 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -48,7 +48,7 @@ class PeriodGenerator : Generator(Period::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( fromBigInteger( Ranges.choose(random, toBigInteger(min), toBigInteger(max)) ), diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt index 766512c4c5..bf3522713d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -45,7 +45,7 @@ class YearGenerator : Generator(Year::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( Year.of(random.nextInt(min.value, max.value)), Year::class.id ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt index 8cb0427246..8bda750a6a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -53,7 +53,7 @@ class YearMonthGenerator : Generator(YearMonth::class.java) { min.year * 12L + min.monthValue - 1, max.year * 12L + max.monthValue - 1 ) - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( YearMonth.of( (generated / 12).toInt(), abs(generated % 12).toInt() + 1 diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt index bc0a86dad7..d6c303c6d8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -16,7 +16,7 @@ class ZoneIdGenerator : Generator(ZoneId::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( ZoneId.of(random.choose(ZoneId.getAvailableZoneIds())), ZoneId::class.id ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt index f5b93fe6bd..4b2d1990ed 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -50,7 +50,7 @@ class ZoneOffsetGenerator : Generator(ZoneOffset::class.java) { val minSeconds = min.totalSeconds val maxSeconds = max.totalSeconds - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( ZoneOffset.ofTotalSeconds( if (minSeconds <= maxSeconds) random.nextInt(minSeconds, maxSeconds) else random.nextInt( maxSeconds, diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt index d4ea76d080..eaf09d596f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -59,7 +59,7 @@ class ZonedDateTimeGenerator : Generator(ZonedDateTime::class.java) { // Project the ZonedDateTime to an Instant for easy long-based // generation. - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( ZonedDateTime.ofInstant( random.nextInstant(min.toInstant(), max.toInstant()), UTC_ZONE_ID diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt index f83a3589a2..34347a6ed5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -21,6 +21,6 @@ class BitSetGenerator : Generator(BitSet::class.java) { for (i in 0 until size) { bits[i] = random.nextBoolean() } - return utModelConstructor.construct(bits, BitSet::class.id) + return generatorContext.utModelConstructor.construct(bits, BitSet::class.id) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt index 86f80a1aab..70165873f8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt @@ -1,7 +1,7 @@ package org.utbot.quickcheck.generator.java.util import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.booleanClassId import org.utbot.framework.plugin.api.util.id @@ -91,7 +91,7 @@ abstract class CollectionGenerator(type: Class<*>) : ComponentizedGenerator(type nestedGenerators.clear() val collectionClassId = types().single().id val collectionConstructorId = ConstructorId(collectionClassId, emptyList()) - val genId = utModelConstructor.computeUnusedIdAndUpdate() + val genId = generatorContext.utModelConstructor.computeUnusedIdAndUpdate() return UtAssembleModel( genId, collectionClassId, diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt index 6b4aaa54a4..2f02922e33 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus @@ -52,7 +52,7 @@ class DateGenerator : Generator(Date::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( Date(random.nextLong(min.time, max.time)), classIdForType(Date::class.java) ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt index 9235d95bbd..2a9ea589e4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus @@ -16,7 +16,7 @@ class LocaleGenerator : Generator(Locale::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( random.choose(AVAILABLE_LOCALES), classIdForType(Locale::class.java) ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt index d58ebbff4d..b4c39ecc76 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt @@ -1,7 +1,7 @@ package org.utbot.quickcheck.generator.java.util import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.booleanClassId import org.utbot.framework.plugin.api.util.id @@ -86,7 +86,7 @@ abstract class MapGenerator protected constructor(type: Class<*>) : Componentize val size = size(random, status) val classId = types().single().id - val generatedModelId = utModelConstructor.computeUnusedIdAndUpdate() + val generatedModelId = generatorContext.utModelConstructor.computeUnusedIdAndUpdate() val constructorId = ConstructorId(classId, emptyList()) nestedGenerators.clear() return UtAssembleModel( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt index 429290e1b4..b300e24c4c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus @@ -38,6 +38,6 @@ class OptionalDoubleGenerator : Generator(OptionalDouble::class.java) { val trial = random.nextDouble() val generated = if (trial < 0.25) OptionalDouble.empty() else OptionalDouble.of(doubles.generateValue(random, status)) - return utModelConstructor.construct(generated, classIdForType(OptionalDouble::class.java)) + return generatorContext.utModelConstructor.construct(generated, classIdForType(OptionalDouble::class.java)) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt index 52a1122e45..34faaf15b1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtModel @@ -23,14 +23,14 @@ class OptionalGenerator : ComponentizedGenerator(Optional::class.java) { val trial = random.nextDouble() val classId = Optional::class.id if (trial < 0.25) { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( Optional.empty(), classId ) } val value = componentGenerators().first().generateImpl(random, status) val constructorId = methodId(classId, "of", classId, objectClassId) - val generatedModelId = utModelConstructor.computeUnusedIdAndUpdate() + val generatedModelId = generatorContext.utModelConstructor.computeUnusedIdAndUpdate() return UtAssembleModel( generatedModelId, classId, diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt index e7d0800daa..bbf290df7f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus @@ -37,6 +37,6 @@ class OptionalIntGenerator : Generator(OptionalInt::class.java) { val trial = random.nextDouble() val generated = if (trial < 0.25) OptionalInt.empty() else OptionalInt.of(integers.generateValue(random)) - return utModelConstructor.construct(generated, classIdForType(OptionalInt::class.java)) + return generatorContext.utModelConstructor.construct(generated, classIdForType(OptionalInt::class.java)) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt index 5ddda35c3a..b1cc5ef592 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus @@ -36,6 +36,6 @@ class OptionalLongGenerator : Generator(OptionalLong::class.java) { ): UtModel { val trial = random.nextDouble() val generated = if (trial < 0.25) OptionalLong.empty() else OptionalLong.of(longs.generateValue(random, status)) - return utModelConstructor.construct(generated, classIdForType(OptionalLong::class.java)) + return generatorContext.utModelConstructor.construct(generated, classIdForType(OptionalLong::class.java)) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt index 219989a4e5..58f3acc684 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.ConstructorId import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel @@ -11,8 +11,6 @@ import org.utbot.framework.plugin.api.util.objectClassId import org.utbot.quickcheck.generator.GenerationStatus import org.utbot.quickcheck.generator.Generator import org.utbot.quickcheck.generator.java.lang.AbstractStringGenerator -import org.utbot.quickcheck.generator.java.lang.Encoded -import org.utbot.quickcheck.generator.java.lang.Encoded.InCharset import org.utbot.quickcheck.generator.java.lang.StringGenerator import org.utbot.quickcheck.random.SourceOfRandomness import java.util.Dictionary @@ -23,12 +21,12 @@ import java.util.Properties * Produces values of type [Properties]. */ class PropertiesGenerator : Generator(Properties::class.java) { - private var stringGenerator: AbstractStringGenerator = StringGenerator() - fun configure(charset: InCharset?) { - val encoded = Encoded() - encoded.configure(charset!!) - stringGenerator = encoded - } + private var stringGenerator: StringGenerator = StringGenerator() +// fun configure(charset: InCharset?) { +// val encoded = Encoded() +// encoded.configure(charset!!) +// stringGenerator = encoded +// } override fun generate( random: SourceOfRandomness, @@ -37,7 +35,7 @@ class PropertiesGenerator : Generator(Properties::class.java) { val size = status.size() val classId = Properties::class.id - val generatedModelId = utModelConstructor.computeUnusedIdAndUpdate() + val generatedModelId = generatorContext.utModelConstructor.computeUnusedIdAndUpdate() val constructorId = ConstructorId(classId, emptyList()) return UtAssembleModel( generatedModelId, diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt index 00ac0a4842..3b9e2d578a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus @@ -62,7 +62,7 @@ object RFC4122 { setVersion(hash, versionMask.toByte()) setVariant(hash) val generatedUUID = newUUID(hash) - return utModelConstructor.construct(generatedUUID, classIdForType(UUID::class.java)) + return generatorContext.utModelConstructor.construct(generatedUUID, classIdForType(UUID::class.java)) } protected fun setNamespace(namespace: Namespace?) { @@ -115,7 +115,7 @@ object RFC4122 { setVersion(bytes, 0x40.toByte()) setVariant(bytes) val generatedUUID = newUUID(bytes) - return utModelConstructor.construct(generatedUUID, classIdForType(UUID::class.java)) + return generatorContext.utModelConstructor.construct(generatedUUID, classIdForType(UUID::class.java)) } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt index 15767e8ba3..dc2cc3f5b8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus @@ -16,7 +16,7 @@ class TimeZoneGenerator : Generator(TimeZone::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( TimeZone.getTimeZone(random.choose(AVAILABLE_IDS)), classIdForType(TimeZone::class.java) ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt index e95a99180a..0d2ed999bf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.concurrent -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -19,7 +19,7 @@ class CallableGenerator : ComponentizedGenerator(Callable::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( Callable::class.java, componentGenerators()[0], diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt index 791db315c6..f3f08e1a6d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -26,7 +26,7 @@ class BiFunctionGenerator : ComponentizedGenerator(BiFunction::class.ja random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( BiFunction::class.java, componentGenerators()[2], diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt index 17029167ff..d8af09312b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -33,7 +33,7 @@ class BiPredicateGenerator : ComponentizedGenerator(BiPredicate::class.jav random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda(BiPredicate::class.java, generator!!, status), classIdForType(BiPredicate::class.java) ) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt index e3ffca3196..e47952aafb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -24,7 +24,7 @@ class BinaryOperatorGenerator : ComponentizedGenerator(BinaryOperator::class. random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( BinaryOperator::class.java, componentGenerators()[0], diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt index b3ad545ece..77a2d434f4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -24,7 +24,7 @@ class DoubleFunctionGenerator : ComponentizedGenerator(DoubleFunction::class. random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( DoubleFunction::class.java, componentGenerators()[0], diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt index 6ef73fa2b0..151ca39ee2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -25,7 +25,7 @@ class FunctionGenerator : ComponentizedGenerator(Function::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( Function::class.java, componentGenerators()[1], diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt index bf50202497..77cd7e967b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -23,7 +23,7 @@ class IntFunctionGenerator : ComponentizedGenerator(IntFunction::class.java) random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( IntFunction::class.java, componentGenerators()[0], diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt index 211213b141..b074b306c4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -24,7 +24,7 @@ class LongFunctionGenerator : ComponentizedGenerator(LongFunction::class.java random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( LongFunction::class.java, componentGenerators()[0], diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt index ec01e9b9b2..580864be89 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -32,7 +32,7 @@ class PredicateGenerator : ComponentizedGenerator(Predicate::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( Predicate::class.java, generator!!, status ), diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt index 92baad9a0c..f81d12b639 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -24,7 +24,7 @@ class SupplierGenerator : ComponentizedGenerator(Supplier::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( Supplier::class.java, componentGenerators()[0], diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt index f49ac18fad..fb3b957ff8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -33,7 +33,7 @@ class ToDoubleBiFunctionGenerator : ComponentizedGenerator(ToDoubleBiFunct random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( ToDoubleBiFunction::class.java, generator!!, status ), classIdForType(ToDoubleBiFunction::class.java) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt index c55a1ac1ab..cf3c259ba5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -32,7 +32,7 @@ class ToDoubleFunctionGenerator : ComponentizedGenerator(ToDoubleFunction::cl random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( ToDoubleFunction::class.java, generator!!, status ), classIdForType(ToDoubleFunction::class.java) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt index 435bc2119a..3588ac24d4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -33,7 +33,7 @@ class ToIntBiFunctionGenerator : ComponentizedGenerator(ToIntBiFunction::c random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( ToIntBiFunction::class.java, generator!!, status ), classIdForType(ToIntBiFunction::class.java) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt index 186bd712bd..226f3a8c72 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -31,7 +31,7 @@ class ToIntFunctionGenerator : ComponentizedGenerator(ToIntFunction::class.ja random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( ToIntFunction::class.java, generator!!, status ), classIdForType(ToIntFunction::class.java) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt index 13925ddcfb..bd8c67a680 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -33,7 +33,7 @@ class ToLongBiFunctionGenerator : ComponentizedGenerator(ToLongBiFunction: random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( ToLongBiFunction::class.java, generator!!, status ), classIdForType(ToLongBiFunction::class.java) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt index f1a8b0f883..89baabe41e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -32,7 +32,7 @@ class ToLongFunctionGenerator : ComponentizedGenerator(ToLongFunction::class. random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( ToLongFunction::class.java, generator!!, status ), classIdForType(ToLongFunction::class.java) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt index 9d3f4589ea..aad0a8c29c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.ComponentizedGenerator @@ -24,7 +24,7 @@ class UnaryOperatorGenerator : ComponentizedGenerator(UnaryOperator::class.ja random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( makeLambda( UnaryOperator::class.java, componentGenerators()[0], diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt index 2f1a5cfb94..4b0814f1fe 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt @@ -2,7 +2,7 @@ package org.utbot.quickcheck.internal.generator import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtArrayModel @@ -91,7 +91,7 @@ class ArrayGenerator(private val componentType: Class<*>, val component: Generat nestedGenerators.clear() val length = length(random, status) val componentTypeId = classIdForType(componentType) - val modelId = utModelConstructor.computeUnusedIdAndUpdate() + val modelId = generatorContext.utModelConstructor.computeUnusedIdAndUpdate() return UtArrayModel( modelId, getClassIdForArrayType(componentType), @@ -157,12 +157,15 @@ class ArrayGenerator(private val componentType: Class<*>, val component: Generat } override fun copy(): Generator { - val gen = Reflection.instantiate(ArrayGenerator::class.java.constructors.first(), componentType, component.copy()) as Generator + val gen = Reflection.instantiate(ArrayGenerator::class.java.constructors.first(), componentType, component.copy()) as ArrayGenerator return gen.also { it.generatedUtModel = generatedUtModel it.generationState = generationState + if (isGeneratorContextInitialized()) { + it.generatorContext = generatorContext + } it.nestedGenerators = nestedGenerators.map { it.copy() }.toMutableList() - GeneratorConfigurator.configureGenerator(it, 85) + GeneratorConfigurator.configureGenerator(it, 100) } } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt index f71a55c5fa..b2939f707e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt @@ -127,7 +127,7 @@ class CompositeGenerator(composed: List>) : Generator(Any::c it.generatedUtModel = generatedUtModel it.generationState = generationState it.nestedGenerators = nestedGenerators.map { it.copy() }.toMutableList() - GeneratorConfigurator.configureGenerator(it, 85) + GeneratorConfigurator.configureGenerator(it, 100) } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt index 322ddcc2b7..280bc54dcb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.internal.generator -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.quickcheck.generator.GenerationStatus @@ -14,6 +14,6 @@ class EnumGenerator(private val enumType: Class<*>) : Generator(Enum::class.java ): UtModel { val values = enumType.enumConstants val index = random.nextInt(0, values.size - 1) - return utModelConstructor.construct(values[index], Enum::class.id) + return generatorContext.utModelConstructor.construct(values[index], Enum::class.id) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt index 5a97f8eeaf..97d08b9f7e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt @@ -103,8 +103,8 @@ open class GeneratorRepository private constructor( generator = NullableGenerator(generator) } generator.provide(this) - generator.configure(parameter.annotatedType()) - if (parameter.topLevel()) generator.configure(parameter.annotatedElement()) + //generator.configure(parameter.annotatedType()) + //if (parameter.topLevel()) generator.configure(parameter.annotatedElement()) return generator } @@ -124,7 +124,7 @@ open class GeneratorRepository private constructor( parameter: ParameterTypeContext ): ArrayGenerator { val component = parameter.arrayComponentContext() - return ArrayGenerator(component.rawClass, generatorFor(component)) + return ArrayGenerator(component.rawClass, generatorFor(component)).copy() as ArrayGenerator } private fun matchingGenerators( @@ -182,7 +182,7 @@ open class GeneratorRepository private constructor( if (method != null) { val returnType = parameter.methodReturnTypeContext(method) val returnTypeGenerator = generatorFor(returnType) - matches += LambdaGenerator(parameter.rawClass, returnTypeGenerator) + matches += LambdaGenerator(parameter.rawClass, returnTypeGenerator).copy() as LambdaGenerator<*> } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt index 3aa867bd97..0bbfa75e49 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.internal.generator -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.quickcheck.generator.GenerationStatus @@ -16,7 +16,7 @@ class MarkerInterfaceGenerator(private val markerType: Class<*>) : Generator(mar random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return utModelConstructor.construct( + return generatorContext.utModelConstructor.construct( markerType.cast( Proxy.newProxyInstance( markerType.classLoader, arrayOf(markerType), diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt index 1cb7e61572..8da78a7b0a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt @@ -1,6 +1,6 @@ package org.utbot.quickcheck.internal.generator -import org.utbot.engine.greyboxfuzzer.util.UtModelGenerator.utModelConstructor +import org.utbot.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel @@ -15,6 +15,6 @@ class ZilchGenerator : Generator(Zilch::class.java) { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - return UtNullModel(objectClassId)//utModelConstructor.construct(Zilch, classIdForType(Zilch::class.java)) + return UtNullModel(objectClassId)// generatorContext.utModelConstructor.construct(Zilch, classIdForType(Zilch::class.java)) } } \ No newline at end of file diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt index bcaa281e9e..609023835c 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt @@ -77,11 +77,16 @@ object UtFuzzingExecutionInstrumentation : Instrumentation ?: Result.failure(TimeoutException("Timeout $timeout elapsed")) + } catch (e: Throwable) { + null } - }?.getOrThrow() as? Result<*> ?: Result.failure(TimeoutException("Timeout $timeout elapsed")) val traceList = traceHandler.computeInstructionList() val cache = constructor.objectToModelCache @@ -89,11 +94,11 @@ object UtFuzzingExecutionInstrumentation : Instrumentation by lazy { val debugCmd = listOfNotNull(DEBUG_RUN_CMD.takeIf { UtSettings.runInstrumentedProcessWithDebug }) val javaVersionSpecificArguments = OpenModulesContainer.javaVersionSpecificArguments + val memoryLimit = listOf("-Xmx1g") val pathToJava = JdkInfoService.provide().path listOf(pathToJava.resolve("bin${File.separatorChar}${osSpecificJavaExecutable()}").toString()) + debugCmd + javaVersionSpecificArguments + + memoryLimit + listOf("-javaagent:$jarFile", "-ea", "-jar", "$jarFile") } From 1dbcde789064ed5ee948636e71e6f03d334f3ad9 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Thu, 1 Dec 2022 18:06:13 +0300 Subject: [PATCH 11/30] refactoring and fixes --- utbot-framework/build.gradle | 7 ++ .../engine/greyboxfuzzer/GreyBoxFuzzer.kt | 110 +++++++++--------- .../greyboxfuzzer/generator/DataGenerator.kt | 16 +-- .../engine/greyboxfuzzer/generator/FField.kt | 2 +- .../greyboxfuzzer/generator/FParameter.kt | 2 +- .../greyboxfuzzer/generator/FThisInstance.kt | 2 +- .../generator/GeneratorConfigurator.kt | 14 +-- .../generator/GreyBoxFuzzerGenerators.kt | 19 +-- .../generator/QuickCheckExtensions.kt | 16 +-- .../generator/UTGeneratorRepository.kt | 10 +- .../userclasses/UserClassGenerator.kt | 17 ++- .../generator/ClassesInstanceGenerator.kt | 6 +- .../ConstructorBasedInstanceGenerator.kt | 6 +- .../generator/ExecutableInvoker.kt | 10 +- ...terfaceImplementationsInstanceGenerator.kt | 40 ++++--- .../userclasses/generator/ObjectGenerator.kt | 12 +- .../generator/ReflectionClassGenerator.kt | 4 +- .../generator/ReflectionTypeGenerator.kt | 4 +- .../StaticsBasedInstanceGenerator.kt | 6 +- .../StaticsFieldBasedInstanceGenerator.kt | 6 +- .../StaticsMethodBasedInstanceGenerator.kt | 6 +- .../engine/greyboxfuzzer/mutator/Mutator.kt | 33 ++---- .../greyboxfuzzer/mutator/SeedCollector.kt | 51 +++++--- .../quickcheck/NonTrackingGenerationStatus.kt | 10 +- .../generator/ComponentizedGenerator.kt | 29 ++--- .../quickcheck/generator/DecimalGenerator.kt | 2 +- .../quickcheck/generator/Distinct.kt | 2 +- .../quickcheck/generator/Gen.kt | 4 +- .../quickcheck/generator/GenerationState.kt | 2 +- .../quickcheck/generator/GenerationStatus.kt | 2 +- .../quickcheck/generator/Generator.kt | 8 +- .../generator/GeneratorConfiguration.kt | 2 +- .../GeneratorConfigurationException.kt | 2 +- .../quickcheck/generator/GeneratorContext.kt | 2 +- .../quickcheck/generator/Generators.kt | 4 +- .../quickcheck/generator/InRange.kt | 2 +- .../quickcheck/generator/IntegralGenerator.kt | 2 +- .../quickcheck/generator/Lambdas.kt | 12 +- .../quickcheck/generator/NullAllowed.kt | 2 +- .../quickcheck/generator/Precision.kt | 2 +- .../quickcheck/generator/Size.kt | 2 +- .../quickcheck/generator/VoidGenerator.kt | 4 +- .../java/lang/AbstractStringGenerator.kt | 12 +- .../generator/java/lang/BooleanGenerator.kt | 10 +- .../generator/java/lang/ByteGenerator.kt | 14 +-- .../generator/java/lang/CharacterGenerator.kt | 14 +-- .../generator/java/lang/DoubleGenerator.kt | 14 +-- .../quickcheck/generator/java/lang/Encoded.kt | 8 +- .../generator/java/lang/FloatGenerator.kt | 14 +-- .../generator/java/lang/IntegerGenerator.kt | 14 +-- .../generator/java/lang/LongGenerator.kt | 14 +-- .../java/lang/PrimitiveBooleanGenerator.kt | 10 +- .../java/lang/PrimitiveByteGenerator.kt | 14 +-- .../java/lang/PrimitiveCharGenerator.kt | 14 +-- .../java/lang/PrimitiveDoubleGenerator.kt | 14 +-- .../java/lang/PrimitiveFloatGenerator.kt | 14 +-- .../java/lang/PrimitiveIntGenerator.kt | 14 +-- .../java/lang/PrimitiveLongGenerator.kt | 14 +-- .../java/lang/PrimitiveShortGenerator.kt | 14 +-- .../generator/java/lang/ShortGenerator.kt | 14 +-- .../generator/java/lang/StringGenerator.kt | 4 +- .../generator/java/lang/strings/CodePoints.kt | 2 +- .../java/math/BigDecimalGenerator.kt | 18 +-- .../java/math/BigIntegerGenerator.kt | 16 +-- .../java/nio/charset/CharsetGenerator.kt | 10 +- .../generator/java/time/ClockGenerator.kt | 14 +-- .../generator/java/time/DurationGenerator.kt | 14 +-- .../generator/java/time/InstantGenerator.kt | 14 +-- .../generator/java/time/LocalDateGenerator.kt | 14 +-- .../java/time/LocalDateTimeGenerator.kt | 14 +-- .../generator/java/time/LocalTimeGenerator.kt | 14 +-- .../generator/java/time/MonthDayGenerator.kt | 14 +-- .../java/time/OffsetDateTimeGenerator.kt | 14 +-- .../java/time/OffsetTimeGenerator.kt | 14 +-- .../generator/java/time/PeriodGenerator.kt | 16 +-- .../generator/java/time/YearGenerator.kt | 14 +-- .../generator/java/time/YearMonthGenerator.kt | 14 +-- .../generator/java/time/ZoneIdGenerator.kt | 10 +- .../java/time/ZoneOffsetGenerator.kt | 14 +-- .../java/time/ZonedDateTimeGenerator.kt | 14 +-- .../generator/java/util/ArrayListGenerator.kt | 2 +- .../generator/java/util/BitSetGenerator.kt | 10 +- .../java/util/CollectionGenerator.kt | 12 +- .../generator/java/util/DateGenerator.kt | 14 +-- .../generator/java/util/HashMapGenerator.kt | 2 +- .../generator/java/util/HashSetGenerator.kt | 2 +- .../generator/java/util/HashtableGenerator.kt | 2 +- .../java/util/LinkedHashMapGenerator.kt | 2 +- .../java/util/LinkedHashSetGenerator.kt | 2 +- .../java/util/LinkedListGenerator.kt | 2 +- .../generator/java/util/ListGenerator.kt | 2 +- .../generator/java/util/LocaleGenerator.kt | 10 +- .../generator/java/util/MapGenerator.kt | 12 +- .../java/util/OptionalDoubleGenerator.kt | 14 +-- .../generator/java/util/OptionalGenerator.kt | 12 +- .../java/util/OptionalIntGenerator.kt | 14 +-- .../java/util/OptionalLongGenerator.kt | 14 +-- .../java/util/PropertiesGenerator.kt | 14 +-- .../quickcheck/generator/java/util/RFC4122.kt | 14 +-- .../generator/java/util/SetGenerator.kt | 4 +- .../generator/java/util/StackGenerator.kt | 2 +- .../generator/java/util/TimeZoneGenerator.kt | 10 +- .../generator/java/util/VectorGenerator.kt | 2 +- .../java/util/concurrent/CallableGenerator.kt | 14 +-- .../java/util/function/BiFunctionGenerator.kt | 14 +-- .../util/function/BiPredicateGenerator.kt | 18 +-- .../util/function/BinaryOperatorGenerator.kt | 14 +-- .../util/function/DoubleFunctionGenerator.kt | 14 +-- .../java/util/function/FunctionGenerator.kt | 14 +-- .../util/function/IntFunctionGenerator.kt | 14 +-- .../util/function/LongFunctionGenerator.kt | 14 +-- .../java/util/function/PredicateGenerator.kt | 18 +-- .../java/util/function/SupplierGenerator.kt | 14 +-- .../function/ToDoubleBiFunctionGenerator.kt | 18 +-- .../function/ToDoubleFunctionGenerator.kt | 18 +-- .../util/function/ToIntBiFunctionGenerator.kt | 18 +-- .../util/function/ToIntFunctionGenerator.kt | 18 +-- .../function/ToLongBiFunctionGenerator.kt | 18 +-- .../util/function/ToLongFunctionGenerator.kt | 18 +-- .../util/function/UnaryOperatorGenerator.kt | 14 +-- .../internal/DefaultMethodHandleMaker.kt | 2 +- .../internal/FakeAnnotatedTypeFactory.kt | 2 +- .../FakeAnnotatedTypeFactoryWithType.kt | 2 +- .../internal/GeometricDistribution.kt | 4 +- .../quickcheck/internal/Items.kt | 4 +- .../internal/ParameterTypeContext.kt | 10 +- .../quickcheck/internal/Ranges.kt | 4 +- .../quickcheck/internal/Reflection.kt | 2 +- .../internal/ReflectionException.kt | 2 +- .../quickcheck/internal/Weighted.kt | 2 +- .../quickcheck/internal/Zilch.kt | 3 + .../generator/AbstractGenerationStatus.kt | 8 +- .../internal/generator/ArrayGenerator.kt | 12 +- .../internal/generator/CompositeGenerator.kt | 12 +- .../internal/generator/EnumGenerator.kt | 32 +++++ .../internal/generator/GeneratorRepository.kt | 22 ++-- .../internal/generator/LambdaGenerator.kt | 8 +- .../generator/MarkerInterfaceGenerator.kt | 12 +- .../internal/generator/NullableGenerator.kt | 14 +-- .../generator/SimpleGenerationStatus.kt | 6 +- .../internal/generator/ZilchGenerator.kt | 12 +- .../quickcheck/random/SourceOfRandomness.kt | 6 +- .../greyboxfuzzer/util/ReflectionUtils.kt | 2 +- .../engine/greyboxfuzzer/util/UtBotUtils.kt | 5 +- .../util/UtGreyBoxFuzzedExecution.kt | 31 +++++ .../org/utbot/quickcheck/internal/Zilch.kt | 3 - .../internal/generator/EnumGenerator.kt | 19 --- 147 files changed, 875 insertions(+), 798 deletions(-) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/NonTrackingGenerationStatus.kt (61%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/ComponentizedGenerator.kt (67%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/DecimalGenerator.kt (86%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/Distinct.kt (90%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/Gen.kt (83%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/GenerationState.kt (56%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/GenerationStatus.kt (90%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/Generator.kt (97%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/GeneratorConfiguration.kt (92%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/GeneratorConfigurationException.kt (87%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/GeneratorContext.kt (90%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/Generators.kt (93%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/InRange.kt (97%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/IntegralGenerator.kt (86%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/Lambdas.kt (90%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/NullAllowed.kt (89%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/Precision.kt (89%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/Size.kt (89%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/VoidGenerator.kt (81%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/AbstractStringGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/BooleanGenerator.kt (57%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/ByteGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/CharacterGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/DoubleGenerator.kt (73%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/Encoded.kt (78%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/FloatGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/IntegerGenerator.kt (71%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/LongGenerator.kt (72%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt (56%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt (73%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt (72%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt (72%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/ShortGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/StringGenerator.kt (88%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/lang/strings/CodePoints.kt (98%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/math/BigDecimalGenerator.kt (84%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/math/BigIntegerGenerator.kt (77%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/nio/charset/CharsetGenerator.kt (75%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/ClockGenerator.kt (83%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/DurationGenerator.kt (76%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/InstantGenerator.kt (74%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/LocalDateGenerator.kt (77%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/LocalDateTimeGenerator.kt (81%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/LocalTimeGenerator.kt (77%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/MonthDayGenerator.kt (79%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt (80%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/OffsetTimeGenerator.kt (80%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/PeriodGenerator.kt (82%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/YearGenerator.kt (76%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/YearMonthGenerator.kt (79%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/ZoneIdGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/ZoneOffsetGenerator.kt (79%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt (82%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/ArrayListGenerator.kt (61%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/BitSetGenerator.kt (61%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/CollectionGenerator.kt (90%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/DateGenerator.kt (78%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/HashMapGenerator.kt (60%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/HashSetGenerator.kt (60%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/HashtableGenerator.kt (78%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/LinkedHashMapGenerator.kt (63%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/LinkedHashSetGenerator.kt (63%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/LinkedListGenerator.kt (67%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/ListGenerator.kt (73%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/LocaleGenerator.kt (62%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/MapGenerator.kt (91%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/OptionalDoubleGenerator.kt (70%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/OptionalGenerator.kt (74%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/OptionalIntGenerator.kt (69%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/OptionalLongGenerator.kt (69%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/PropertiesGenerator.kt (79%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/RFC4122.kt (91%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/SetGenerator.kt (64%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/StackGenerator.kt (63%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/TimeZoneGenerator.kt (63%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/VectorGenerator.kt (64%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/concurrent/CallableGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/BiFunctionGenerator.kt (61%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/BiPredicateGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/FunctionGenerator.kt (59%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/IntFunctionGenerator.kt (57%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/LongFunctionGenerator.kt (57%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/PredicateGenerator.kt (57%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/SupplierGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt (57%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt (57%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt (57%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt (58%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/DefaultMethodHandleMaker.kt (96%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/FakeAnnotatedTypeFactory.kt (96%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt (98%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/GeometricDistribution.kt (84%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/Items.kt (89%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/ParameterTypeContext.kt (97%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/Ranges.kt (95%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/Reflection.kt (99%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/ReflectionException.kt (72%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/Weighted.kt (78%) create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Zilch.kt rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/generator/AbstractGenerationStatus.kt (53%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/generator/ArrayGenerator.kt (94%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/generator/CompositeGenerator.kt (91%) create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/generator/GeneratorRepository.kt (93%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/generator/LambdaGenerator.kt (65%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/generator/MarkerInterfaceGenerator.kt (81%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/generator/NullableGenerator.kt (81%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/generator/SimpleGenerationStatus.kt (51%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/internal/generator/ZilchGenerator.kt (54%) rename utbot-framework/src/main/kotlin/org/utbot/{ => engine/greyboxfuzzer}/quickcheck/random/SourceOfRandomness.kt (98%) create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt diff --git a/utbot-framework/build.gradle b/utbot-framework/build.gradle index 7401500d4e..8e992886d2 100644 --- a/utbot-framework/build.gradle +++ b/utbot-framework/build.gradle @@ -6,6 +6,7 @@ repositories { configurations { z3native + fetchInstrumentationJar } dependencies { @@ -49,6 +50,9 @@ dependencies { z3native group: 'com.microsoft.z3', name: 'z3-native-win64', version: z3Version, ext: 'zip' z3native group: 'com.microsoft.z3', name: 'z3-native-linux64', version: z3Version, ext: 'zip' z3native group: 'com.microsoft.z3', name: 'z3-native-osx', version: z3Version, ext: 'zip' + + //For my tests + fetchInstrumentationJar project(path: ':utbot-instrumentation', configuration:'instrumentationArchive') } processResources { @@ -57,4 +61,7 @@ processResources { into "lib/x64" } } + from(configurations.fetchInstrumentationJar) { + into "lib" + } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt index 2da0f35adf..d4e725e21a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -11,10 +11,11 @@ import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* import org.utbot.framework.util.sootMethod import org.utbot.instrumentation.ConcreteExecutor -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import java.lang.reflect.Field import java.lang.reflect.Method import kotlin.random.Random +import kotlin.system.exitProcess class GreyBoxFuzzer( private val pathsToUserClasses: String, @@ -29,6 +30,7 @@ class GreyBoxFuzzer( .filter { it != -1 } .toSet() private val seeds = SeedCollector(methodLines = methodLines) + private val succeededExecutions = mutableListOf() private val timeRemain get() = timeOfStart + timeBudgetInMillis - System.currentTimeMillis() private val timeOfStart = System.currentTimeMillis() @@ -42,37 +44,26 @@ class GreyBoxFuzzer( val sootMethod = methodUnderTest.sootMethod val javaMethod = sootMethod.toJavaMethod()!! val classFieldsUsedByFunc = sootMethod.getClassFieldsUsedByFunc(javaClazz) - val currentCoverageByLines = CoverageCollector.coverage - .filter { it.methodSignature == methodUnderTest.signature } - .map { it.lineNumber } - .toSet() - //TODO repeat or while - while (timeRemain > 0) { + while (timeRemain > 0 || !isMethodCovered()) { explorationStage( javaMethod, - methodLines, classFieldsUsedByFunc, methodUnderTest, - currentCoverageByLines, generatorContext ) logger.debug { "SEEDS AFTER EXPLORATION STAGE = ${seeds.seedsSize()}" } - if (timeRemain < 0) break - exploitationStage( - methodLines, - currentCoverageByLines - ) + if (timeRemain < 0 || isMethodCovered()) break + exploitationStage() } + seeds.getBestSeed() //UtModelGenerator.reset() return sequenceOf() } private suspend fun explorationStage( method: Method, - methodLinesToCover: Set, classFieldsUsedByFunc: Set, methodUnderTest: ExecutableId, - prevMethodCoverage: Set, generatorContext: GeneratorContext ) { val parametersToGenericsReplacer = method.parameters.map { it to GenericsReplacer() } @@ -83,10 +74,9 @@ class GreyBoxFuzzer( var iterationNumber = 0 while (System.currentTimeMillis() < endTime) { try { - logger.debug { "Iteration number $iterationNumber" } - if (timeRemain < 0) return + if (timeRemain < 0 || isMethodCovered()) return + logger.debug { "Func: ${methodUnderTest.name} Iteration number $iterationNumber" } iterationNumber++ - if (isMethodCovered(methodLinesToCover)) return while (thisInstancesHistory.size > 1) { thisInstancesHistory.removeLast() } @@ -137,16 +127,22 @@ class GreyBoxFuzzer( logger.debug { "Execution started" } val executionResult = execute(stateBefore, methodUnderTest) logger.debug { "Execution result: $executionResult" } - val seedCoverage = - handleCoverage( - executionResult, - prevMethodCoverage, - methodLinesToCover - ) + val seedCoverage = getCoverage(executionResult) logger.debug { "Calculating seed score" } val seedScore = seeds.calcSeedScore(seedCoverage) logger.debug { "Adding seed" } - seeds.addSeed(Seed(thisInstance, generatedParameters, seedCoverage, seedScore)) + val seed = Seed(thisInstance, generatedParameters, seedCoverage, seedScore) + if (seeds.isSeedOpensNewCoverage(seed)) { + succeededExecutions.add( + UtGreyBoxFuzzedExecution( + stateBefore, + executionResult.result, + coverage = executionResult.coverage, + testMethodName = methodUnderTest.name + ) + ) + } + seeds.addSeed(seed) logger.debug { "Execution result: ${executionResult.result}" } logger.debug { "Seed score = $seedScore" } } catch (e: Throwable) { @@ -161,38 +157,48 @@ class GreyBoxFuzzer( } } - private suspend fun exploitationStage( - methodLinesToCover: Set, - prevMethodCoverage: Set - ) { + private suspend fun exploitationStage() { logger.debug { "Exploitation began" } + if (seeds.seedsSize() == 0) return + if (seeds.all { it.parameters.isEmpty() }) return val startTime = System.currentTimeMillis() val endTime = startTime + timeBudgetInMillis / percentageOfTimeBudgetToChangeMode var iterationNumber = 0 while (System.currentTimeMillis() < endTime) { - if (timeRemain < 0) return - logger.debug { "Mutation iteration $iterationNumber" } + if (timeRemain < 0 || isMethodCovered()) return + //Infinite cycle of cant mutate seed + if (iterationNumber > 30_000) return + logger.debug { "Func: ${methodUnderTest.name} Mutation iteration number $iterationNumber" } iterationNumber++ - if (isMethodCovered(methodLinesToCover)) return - val randomSeed = seeds.getRandomWeightedSeed() ?: continue + val randomSeed = seeds.getRandomWeightedSeed() logger.debug { "Random seed params = ${randomSeed.parameters}" } - val mutatedSeed = Mutator.mutateSeed( - randomSeed, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus - ) + val mutatedSeed = + Mutator.mutateSeed( + randomSeed, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus + ) + if (mutatedSeed == randomSeed) { + logger.debug { "Cant mutate seed" } + continue + } logger.debug { "Mutated params = ${mutatedSeed.parameters}" } val stateBefore = mutatedSeed.createEnvironmentModels() try { val executionResult = execute(stateBefore, methodUnderTest) logger.debug { "Execution result: $executionResult" } - val seedScore = - handleCoverage( - executionResult, - prevMethodCoverage, - methodLinesToCover - ) + val seedScore = getCoverage(executionResult) mutatedSeed.score = 0.0 + if (seeds.isSeedOpensNewCoverage(mutatedSeed)) { + succeededExecutions.add( + UtGreyBoxFuzzedExecution( + stateBefore, + executionResult.result, + coverage = executionResult.coverage, + testMethodName = methodUnderTest.name + ) + ) + } seeds.addSeed(mutatedSeed) logger.debug { "Execution result: ${executionResult.result}" } logger.debug { "Seed score = $seedScore" } @@ -203,27 +209,25 @@ class GreyBoxFuzzer( } } - private fun handleCoverage( - executionResult: UtFuzzingConcreteExecutionResult, - prevMethodCoverage: Set, - currentMethodLines: Set + private fun getCoverage( + executionResult: UtFuzzingConcreteExecutionResult ): Set { val currentMethodCoverage = executionResult.coverage.coveredInstructions .asSequence() .filter { it.methodSignature == methodUnderTest.signature } .map { it.lineNumber } - .filter { it in currentMethodLines } + .filter { it in methodLines } .toSet() - logger.debug { "Covered lines $currentMethodCoverage from $currentMethodLines" } + logger.debug { "Covered lines $currentMethodCoverage from $methodLines" } executionResult.coverage.coveredInstructions.forEach { CoverageCollector.coverage.add(it) } return currentMethodCoverage } - private fun isMethodCovered(methodLinesToCover: Set): Boolean { + private fun isMethodCovered(): Boolean { val coveredLines = CoverageCollector.coverage.filter { it.methodSignature == methodUnderTest.signature }.map { it.lineNumber } .toSet() - return coveredLines.containsAll(methodLinesToCover) + return coveredLines.containsAll(methodLines) } private suspend fun ConcreteExecutor.executeConcretely( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt index a589ac3d37..15c611a650 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt @@ -1,10 +1,10 @@ package org.utbot.engine.greyboxfuzzer.generator import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import org.utbot.engine.logger import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.ClassId @@ -13,8 +13,8 @@ import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.GenerationState -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationState +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import java.lang.reflect.Parameter object DataGenerator { @@ -28,8 +28,8 @@ object DataGenerator { random: SourceOfRandomness, status: GenerationStatus ): UtModel { - logger.debug { "Trying to generate UtModel of type 3 times" } val classId = parameterTypeContext.rawClass.id + logger.debug { "Trying to generate UtModel of type ${classId.name} 3 times" } var generatedInstance: UtModel? = null repeat(3) { generatedInstance = @@ -37,7 +37,7 @@ object DataGenerator { val generator = generatorRepository.getOrProduceGenerator(parameterTypeContext, generatorContext, depth) ?: return@repeat - generator.generatorContext.startCheckpoint() + //generator.generatorContext.startCheckpoint() generator.generateImpl(random, status) } catch (_: Throwable) { null diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt index 50bdbba9e1..577b05f916 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt @@ -1,6 +1,6 @@ package org.utbot.engine.greyboxfuzzer.generator -import org.utbot.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator import org.utbot.engine.greyboxfuzzer.util.toClass import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.ClassId diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt index 30d3ea941f..ff74cea6db 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt @@ -3,7 +3,7 @@ package org.utbot.engine.greyboxfuzzer.generator import org.utbot.engine.greyboxfuzzer.mutator.Mutator import org.utbot.engine.greyboxfuzzer.util.copy import org.utbot.engine.greyboxfuzzer.util.getAllDeclaredFields -import org.utbot.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtAssembleModel diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt index e89f785a29..f3d1a1507f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt @@ -3,7 +3,7 @@ package org.utbot.engine.greyboxfuzzer.generator import org.utbot.engine.greyboxfuzzer.util.copy import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator sealed interface ThisInstance { val utModelForExecution: UtModel? diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt index ed7e318081..5976e70924 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt @@ -1,13 +1,13 @@ package org.utbot.engine.greyboxfuzzer.generator -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.Size -import org.utbot.quickcheck.generator.java.util.CollectionGenerator -import org.utbot.quickcheck.generator.java.util.MapGenerator -import org.utbot.quickcheck.internal.generator.ArrayGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Size +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.CollectionGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.MapGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.ArrayGenerator import org.utbot.engine.greyboxfuzzer.util.getTrue -import org.utbot.quickcheck.generator.java.lang.* +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.* import kotlin.random.Random object GeneratorConfigurator { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt index 01a7bb3d7e..fbd6abc1e6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt @@ -1,20 +1,21 @@ package org.utbot.engine.greyboxfuzzer.generator -import org.utbot.quickcheck.NonTrackingGenerationStatus -import org.utbot.quickcheck.generator.* -import org.utbot.quickcheck.generator.java.time.* -import org.utbot.quickcheck.generator.java.util.* -import org.utbot.quickcheck.generator.java.lang.* -import org.utbot.quickcheck.generator.java.math.* -import org.utbot.quickcheck.generator.java.nio.charset.CharsetGenerator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.NonTrackingGenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time.* +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.* +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.* +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.math.* +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.nio.charset.CharsetGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.* +import java.util.concurrent.atomic.AtomicInteger object GreyBoxFuzzerGenerators { const val seed = 42L - const val maxDepthOfGeneration = 7 + val maxDepthOfGeneration = AtomicInteger(5) val sourceOfRandomness = SourceOfRandomness(Random(seed)) val genStatus = NonTrackingGenerationStatus(sourceOfRandomness) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt index 316d5757b2..eb68375bc0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -10,13 +10,13 @@ import org.utbot.engine.greyboxfuzzer.generator.userclasses.UserClassGenerator import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.engine.logger import org.utbot.engine.rawType -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory -import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.internal.generator.ArrayGenerator -import org.utbot.quickcheck.internal.generator.GeneratorRepository +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.FakeAnnotatedTypeFactory +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.ArrayGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.GeneratorRepository import ru.vyarus.java.generics.resolver.GenericsResolver import ru.vyarus.java.generics.resolver.context.ConstructorGenericsContext import ru.vyarus.java.generics.resolver.context.GenericsContext @@ -40,7 +40,7 @@ fun Generator.getAllComponents(): List { fun Generator.getComponents(): List = when (this) { - is ComponentizedGenerator -> this.componentGenerators() + is org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -> this.componentGenerators() is ArrayGenerator -> listOf(this.component) else -> emptyList() } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt index 41a66f6cba..d4e79ff8f0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt @@ -1,11 +1,11 @@ package org.utbot.engine.greyboxfuzzer.generator -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import org.utbot.engine.logger -import org.utbot.quickcheck.internal.Zilch -import org.utbot.quickcheck.internal.generator.* +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Zilch +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.* class UTGeneratorRepository(random: SourceOfRandomness) : GeneratorRepository(random) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt index 3b1589c928..5089ca4d93 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt @@ -2,8 +2,8 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses -import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import org.javaruntype.type.TypeParameter import org.utbot.engine.greyboxfuzzer.generator.* import org.utbot.engine.greyboxfuzzer.generator.userclasses.generator.* @@ -14,7 +14,7 @@ import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.fieldClassId import org.utbot.framework.plugin.api.util.fieldId import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.* +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* import java.lang.reflect.* import kotlin.random.Random @@ -55,8 +55,11 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { } private fun regenerate(random: SourceOfRandomness, status: GenerationStatus): UtModel { - logger.debug { "Trying to generate ${parameterTypeContext!!.resolved}. Current depth depth: $depth" } - if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration) return UtNullModel(clazz!!.id) + logger.debug { "Trying to generate ${parameterTypeContext!!.resolved}. Current depth: $depth" } + if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration.toInt()) { + logger.debug { "Depth more than maxDepth ${GreyBoxFuzzerGenerators.maxDepthOfGeneration.toInt()}. Return UtNullModel" } + return UtNullModel(clazz!!.id) + } val immutableClazz = clazz!! when (immutableClazz) { Any::class.java -> return ObjectGenerator(parameterTypeContext!!, random, status, generatorContext).generate() @@ -94,7 +97,9 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { } override fun modify(random: SourceOfRandomness, status: GenerationStatus): UtModel { - generatedUtModel ?: throw FuzzerIllegalStateException("Nothing to modify") + if (generatedUtModel == null) { + return regenerate(random, status) + } val cachedUtModel = generatedUtModel as? UtAssembleModel ?: return generatedUtModel!!.copy() return if (Random.getTrue(80) && mutatedFields.isNotEmpty()) { regenerateField(random, status, cachedUtModel) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt index e272f43237..5fd3df1059 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt @@ -4,9 +4,9 @@ import org.utbot.engine.logger import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext class ClassesInstanceGenerator( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt index 972d8c572a..b4ca5c2418 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt @@ -6,9 +6,9 @@ import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Constructor import java.lang.reflect.Modifier diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt index cd650a8f4c..f954127a8b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt @@ -5,12 +5,10 @@ import org.utbot.engine.greyboxfuzzer.generator.createParameterContextForParamet import org.utbot.engine.greyboxfuzzer.util.constructAssembleModelUsingMethodInvocation import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Executable diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt index d2196d2671..b2802ee89d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt @@ -11,10 +11,10 @@ import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Type import kotlin.random.Random @@ -47,12 +47,10 @@ class InterfaceImplementationsInstanceGenerator( } } val genericsContext = - QuickCheckExtensions.getRandomImplementerGenericContext(clazz, resolvedType) ?: return generateMock( - clazz, - resolvedType, - typeContext, - generatorContext - ) + QuickCheckExtensions.getRandomImplementerGenericContext(clazz, resolvedType) + if (genericsContext == null || Random.getTrue(30)) { + return generateMock(clazz, resolvedType, typeContext, generatorContext) + } return ClassesInstanceGenerator( genericsContext.currentClass(), genericsContext, @@ -63,11 +61,21 @@ class InterfaceImplementationsInstanceGenerator( generatorContext, depth ).generate().let { - if (it is UtNullModel && Random.getTrue(50)) generateMock(clazz, resolvedType, typeContext, generatorContext) else it + if (it is UtNullModel && Random.getTrue(50)) generateMock( + clazz, + resolvedType, + typeContext, + generatorContext + ) else it } } - private fun generateMock(clazz: Class<*>, resolvedType: Type, typeContext: GenericsContext, generatorContext: GeneratorContext,): UtModel { + private fun generateMock( + clazz: Class<*>, + resolvedType: Type, + typeContext: GenericsContext, + generatorContext: GeneratorContext + ): UtModel { if (!clazz.isInterface) return UtNullModel(clazz.id) val sootClazz = clazz.toSootClass() ?: return UtNullModel(clazz.id) val constructor = generatorContext.utModelConstructor @@ -106,7 +114,13 @@ class InterfaceImplementationsInstanceGenerator( val parameterTypeContext = ParameterTypeContext.forType(methodReturnType, genericsContextForMethod) val generatedUtModelWithReturnType = try { - DataGenerator.generateUtModel(parameterTypeContext, depth, generatorContext, sourceOfRandomness, generationStatus) + DataGenerator.generateUtModel( + parameterTypeContext, + depth, + generatorContext, + sourceOfRandomness, + generationStatus + ) } catch (_: Throwable) { UtNullModel(methodReturnType.toClass()!!.id) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt index 841742f51a..18c840218e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt @@ -9,10 +9,10 @@ import org.utbot.engine.greyboxfuzzer.util.toSootMethod import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.MethodGenericsContext import kotlin.random.Random @@ -32,7 +32,7 @@ class ObjectGenerator( val randomClass = potentialUsefulClasses.random() val generator = GreyBoxFuzzerGenerators.generatorRepository .getOrProduceGenerator(randomClass, generatorContext) - generator?.generatorContext?.startCheckpoint() + ?.also { it.generatorContext = generatorContext } generator?.generateImpl(sourceOfRandomness, generationStatus) } else null potentialInterestingObjectReplacement?.let { return it } @@ -42,7 +42,7 @@ class ObjectGenerator( .flatMap { it.second } .filter { !it.hasComponents() } .randomOrNull() - generator?.generatorContext?.startCheckpoint() + ?.also { it.generatorContext = generatorContext } return generator?.generateImpl(sourceOfRandomness, generationStatus) ?: UtNullModel(parameterTypeContext.rawClass.id) } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt index a6aa8896d7..4f3e661d57 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt @@ -4,8 +4,8 @@ import org.utbot.engine.greyboxfuzzer.util.getTrue import org.utbot.engine.greyboxfuzzer.util.toJavaClass import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext import soot.Scene import java.lang.reflect.Type import kotlin.random.Random diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt index 34b8bf7e72..38771ceee5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt @@ -7,8 +7,8 @@ import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.classId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext import ru.vyarus.java.generics.resolver.context.MethodGenericsContext import soot.NullType import soot.Scene diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt index 00ddaf642b..890ae1c64b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt @@ -1,9 +1,9 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import kotlin.random.Random diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt index daf33962ce..dbf53a0706 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt @@ -1,7 +1,7 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator import org.utbot.engine.greyboxfuzzer.util.SootStaticsCollector -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.engine.greyboxfuzzer.util.hasModifiers import org.utbot.engine.greyboxfuzzer.util.toClass import org.utbot.external.api.classIdForType @@ -9,8 +9,8 @@ import org.utbot.framework.codegen.model.constructor.builtin.setAccessible import org.utbot.framework.concrete.UtModelConstructor import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Field import java.lang.reflect.Method diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt index 33a8cf452a..9d87174481 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt @@ -5,9 +5,9 @@ import org.utbot.engine.greyboxfuzzer.util.hasModifiers import org.utbot.engine.greyboxfuzzer.util.toClass import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Method import java.lang.reflect.Modifier diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt index 6d45632e13..a377d667d4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt @@ -9,12 +9,12 @@ import org.utbot.framework.plugin.api.util.fieldId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.method -import org.utbot.quickcheck.generator.GenerationState -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationState +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Field import java.lang.reflect.Modifier @@ -22,25 +22,14 @@ import kotlin.random.Random object Mutator { - /** - * Mean number of mutations to perform in each round. - */ - private val MEAN_MUTATION_COUNT = 8.0 - - /** - * Mean number of contiguous bytes to mutate in each mutation. - */ - private val MEAN_MUTATION_SIZE = 4.0 // Bytes - - private fun regenerateRandomParameter(fParameter: FParameter): FParameter? { - return fParameter - } - fun mutateSeed(seed: Seed, sourceOfRandomness: SourceOfRandomness, genStatus: GenerationStatus): Seed { val seedCopy = seed.copy() + //If seed is empty mutate this + if (seedCopy.parameters.isEmpty()) return seed + val randomParameterIndex = Random.nextInt(0, seedCopy.parameters.size) - val randomParameter = seedCopy.parameters.getOrNull(randomParameterIndex) ?: return seedCopy - val randomParameterGenerator = randomParameter.generator ?: return seedCopy + val randomParameter = seedCopy.parameters.getOrNull(randomParameterIndex) ?: return seed + val randomParameterGenerator = randomParameter.generator ?: return seed randomParameterGenerator.generationState = GenerationState.MODIFY randomParameterGenerator.generatorContext.startCheckpoint() val newUtModel = randomParameterGenerator.generateImpl(sourceOfRandomness, genStatus) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt index 73a2c244ee..3cf4481df2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt @@ -6,10 +6,6 @@ import kotlin.random.Random class SeedCollector(private val maxSize: Int = 50, private val methodLines: Set) { private val seeds = ArrayList(maxSize) -// sortedSetOf( -// comparator = -// compareByDescending { seed: Seed -> seed.score }.thenComparator { seed1, seed2 -> if (seed1 === seed2) 0 else 1 } -// ) fun calcSeedScore(coverage: Set): Double = coverage.sumOf { line -> @@ -27,17 +23,23 @@ class SeedCollector(private val maxSize: Int = 50, private val methodLines: Set< } } - // + fun isSeedOpensNewCoverage(seed: Seed): Boolean { + val oldCoverage = seeds.flatMap { it.lineCoverage }.toSet() + return seed.lineCoverage.any { !oldCoverage.contains(it) } + } + fun addSeed(seed: Seed) { if (seeds.isEmpty()) { seeds.add(seed) return } val indexToInsert = seeds.indexOfFirst { it.score <= seed.score } - if (indexToInsert == -1 && seeds.size < maxSize - 1) { - seeds.add(seed) - recalculateSeedScores() - seeds.sortByDescending { it.score } + if (indexToInsert == -1) { + if (seeds.size < maxSize - 1) { + seeds.add(seed) + recalculateSeedScores() + seeds.sortByDescending { it.score } + } return } seeds.add(indexToInsert, seed) @@ -49,18 +51,31 @@ class SeedCollector(private val maxSize: Int = 50, private val methodLines: Set< } fun getRandomWeightedSeed(): Seed { - val scoreSum = seeds.sumOf { it.score } - val randomScore = Random.nextDouble(0.0, scoreSum) - var scoreCounter = 0.0 - seeds.forEach { seed -> - scoreCounter += seed.score - if (scoreCounter >= randomScore) { - return seed - } + val topN = when (Random.nextInt(0, 100)) { + in 0..30 -> 1 + in 30..60 -> 3 + in 60..80 -> 5 + in 80..90 -> 10 + else -> maxSize } - return seeds.first() + return seeds.take(topN).random() } + fun all(f: (Seed) -> Boolean) = seeds.all(f) + +// fun getRandomWeightedSeed(): Seed { +// val scoreSum = seeds.sumOf { it.score } +// val randomScore = Random.nextDouble(0.0, scoreSum) +// var scoreCounter = 0.0 +// seeds.forEach { seed -> +// scoreCounter += seed.score +// if (scoreCounter >= randomScore) { +// return seed +// } +// } +// return seeds.first() +// } + fun getBestSeed() = seeds.first() fun removeSeed(seed: Seed) = seeds.remove(seed) fun seedsSize() = seeds.size diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt similarity index 61% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt index ec4fcfe5c6..048e5fc8bc 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/NonTrackingGenerationStatus.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt @@ -1,8 +1,8 @@ -package org.utbot.quickcheck +package org.utbot.engine.greyboxfuzzer.quickcheck -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.internal.GeometricDistribution -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.GeometricDistribution +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Provides a generation status that does not track the number of trials @@ -14,7 +14,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness class NonTrackingGenerationStatus(private val random: SourceOfRandomness) : GenerationStatus { private val geometric = GeometricDistribution() override fun size(): Int { - return geometric.sampleWithMean(MEAN_SIZE.toDouble(), random) + return geometric.sampleWithMean(org.utbot.engine.greyboxfuzzer.quickcheck.NonTrackingGenerationStatus.Companion.MEAN_SIZE.toDouble(), random) } override fun attempts(): Int { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt similarity index 67% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt index 62aa06eaaf..2ede4df522 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/ComponentizedGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt @@ -1,10 +1,10 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator import org.javaruntype.type.TypeParameter import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedType import java.util.Collections @@ -16,8 +16,8 @@ import java.util.Collections * @param type class token for type of property parameter this generator * is applicable to */ -abstract class ComponentizedGenerator constructor(type: Class<*>) : Generator(type) { - private val components: MutableList = ArrayList() +abstract class ComponentizedGenerator constructor(type: Class<*>) : org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator(type) { + private val components: MutableList = ArrayList() /** * {@inheritDoc} @@ -35,7 +35,7 @@ abstract class ComponentizedGenerator constructor(type: Class<*>) : Generator(ty } override fun addComponentGenerators( - newComponents: List + newComponents: List ) { require(newComponents.size == numberOfNeededComponents()) { String.format( @@ -55,24 +55,25 @@ abstract class ComponentizedGenerator constructor(type: Class<*>) : Generator(ty return numberOfNeededComponents() == typeParameters.size } - override fun provide(provided: Generators) { + override fun provide(provided: org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators) { super.provide(provided) for (each in components) { each.provide(provided) } } - abstract fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel + abstract fun createModifiedUtModel(random: SourceOfRandomness, status: org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus): UtModel protected open fun modify( random: SourceOfRandomness, - status: GenerationStatus + status: org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus ): UtModel { val cachedModel = generatedUtModel ?: throw FuzzerIllegalStateException("Nothing to modify") val randomNestedGenerator = nestedGeneratorsRecursiveWithoutThis().randomOrNull() ?: return cachedModel getAllGeneratorsBetween(this, randomNestedGenerator)?.forEach { - it.generationState = GenerationState.MODIFYING_CHAIN + it.generationState = org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationState.MODIFYING_CHAIN } - randomNestedGenerator.generationState = GenerationState.REGENERATE + randomNestedGenerator.generationState = + org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationState.REGENERATE return createModifiedUtModel(random, status) } override fun configure(annotatedType: AnnotatedType?) { @@ -88,12 +89,12 @@ abstract class ComponentizedGenerator constructor(type: Class<*>) : Generator(ty /** * @return this generator's component generators */ - fun componentGenerators(): List { + fun componentGenerators(): List { return Collections.unmodifiableList(components) } - override fun copy(): Generator { - return (super.copy() as ComponentizedGenerator).also { + override fun copy(): org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator { + return (super.copy() as org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator).also { it.components.addAll(components.map { it.copy() }) } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt similarity index 86% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt index 977f2f91ca..c5731f0238 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/DecimalGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * Base class for generators of decimal types, such as `double` and diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Distinct.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Distinct.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Distinct.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Distinct.kt index 3ece9eb43c..d794da570d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Distinct.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Distinct.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Gen.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Gen.kt similarity index 83% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Gen.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Gen.kt index 5e07e2baf6..f09366e5d3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Gen.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Gen.kt @@ -1,7 +1,7 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Represents a strategy for generating random values. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationState.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationState.kt similarity index 56% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationState.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationState.kt index 253c11f705..ca3cb89aac 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationState.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationState.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator enum class GenerationState { REGENERATE, CACHE, MODIFY, MODIFYING_CHAIN diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt index 642323507c..e65f0430c2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GenerationStatus.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * [Generator]s are fed instances of this interface on each generation diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt similarity index 97% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt index 4ce7a00637..3c5fbb93ae 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator import org.javaruntype.type.TypeParameter import org.javaruntype.type.Types @@ -10,9 +10,9 @@ import org.utbot.engine.greyboxfuzzer.util.removeIfAndReturnRemovedElements import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.internal.ReflectionException -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ReflectionException +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import soot.SootClass import java.lang.reflect.AnnotatedElement import java.lang.reflect.AnnotatedType diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt similarity index 92% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt index f595967ee1..ff74d8273c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfiguration.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt similarity index 87% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt index 80c1cc2542..f80f5bf90a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorConfigurationException.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * Raised if a problem arises when attempting to configure a generator with diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorContext.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorContext.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt index 0f5c49f35f..bb772dae50 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/GeneratorContext.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator import org.utbot.framework.concrete.UtModelConstructor import java.util.* diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generators.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generators.kt similarity index 93% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generators.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generators.kt index 09bed76c5e..47c702e711 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Generators.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generators.kt @@ -1,6 +1,6 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.Field import java.lang.reflect.Parameter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/InRange.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/InRange.kt similarity index 97% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/InRange.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/InRange.kt index 0506d16190..d73d0b98e8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/InRange.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/InRange.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt similarity index 86% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt index 8c632a4083..4a43a78c19 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/IntegralGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * Base class for generators of integral types, such as `int` and diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Lambdas.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Lambdas.kt index 44da9484c6..fe094e335a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Lambdas.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Lambdas.kt @@ -1,10 +1,10 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator -import org.utbot.quickcheck.internal.DefaultMethodHandleMaker -import org.utbot.quickcheck.internal.GeometricDistribution -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.internal.generator.SimpleGenerationStatus -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.DefaultMethodHandleMaker +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.GeometricDistribution +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.SimpleGenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.InvocationHandler import java.lang.reflect.Method import java.lang.reflect.Proxy diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/NullAllowed.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/NullAllowed.kt similarity index 89% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/NullAllowed.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/NullAllowed.kt index 58f03ef534..552008de29 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/NullAllowed.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/NullAllowed.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Precision.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Precision.kt similarity index 89% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Precision.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Precision.kt index cfb8b895f9..3a44054ab1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Precision.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Precision.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Size.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Size.kt similarity index 89% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Size.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Size.kt index 94f3b31fa1..6392f22b3d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/Size.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Size.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt similarity index 81% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt index b842d64c13..02431efe87 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/VoidGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt @@ -1,9 +1,9 @@ -package org.utbot.quickcheck.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.generator import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values for property parameters of type `void` or diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt index 111c37ea28..7fcde92839 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/AbstractStringGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.stringClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Size -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Size +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt similarity index 57% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt index 2ed537c243..7c2b42aaef 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/BooleanGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.booleanWrapperClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `boolean` or [Boolean]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt index 1d9736a188..616de4f8bc 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ByteGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.byteWrapperClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.IntegralGenerator -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `byte` or [Byte]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt index f730c59657..1143f6299c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/CharacterGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.charWrapperClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `char` or [Character]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt similarity index 73% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt index bb4a458388..82710c5529 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/DoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.doubleWrapperClassId -import org.utbot.quickcheck.generator.DecimalGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values for property parameters of type `double` or diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt similarity index 78% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt index 5e5a873601..3fa37ad396 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/Encoded.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt @@ -1,9 +1,9 @@ //package org.utbot.quickcheck.generator.java.lang // -//import org.utbot.quickcheck.generator.GeneratorConfiguration -//import org.utbot.quickcheck.generator.java.lang.strings.CodePoints -//import org.utbot.quickcheck.generator.java.lang.strings.CodePoints.Companion.forCharset -//import org.utbot.quickcheck.random.SourceOfRandomness +//import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorConfiguration +//import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.strings.CodePoints +//import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.strings.CodePoints.Companion.forCharset +//import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness //import java.nio.charset.Charset // ///** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt index d099753758..20ed203993 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/FloatGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.floatWrapperClassId -import org.utbot.quickcheck.generator.DecimalGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `float` or [Float]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt similarity index 71% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt index 17342c0bb4..b1f5afe938 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/IntegerGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.intWrapperClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.IntegralGenerator -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `int` or [Integer]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt similarity index 72% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt index 60f3c78845..a0c4fc432d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/LongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.longWrapperClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.IntegralGenerator -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `long` or [Long]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt similarity index 56% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt index f72d068748..0358888dae 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.booleanClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `boolean` or [Boolean]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt index b4327f174c..83f93aa383 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.byteClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.IntegralGenerator -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `byte` or [Byte]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt index d8046b4e22..e6a59ec24b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.charClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `char` or [Character]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt similarity index 73% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt index a155316448..a137bd5dc0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.doubleClassId -import org.utbot.quickcheck.generator.DecimalGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values for property parameters of type `double` or diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt index af5145460c..b9fb202b24 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.floatClassId -import org.utbot.quickcheck.generator.DecimalGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `float` or [Float]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt similarity index 72% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt index 3ffea266f9..a788e4583b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.intClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.IntegralGenerator -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `int` or [Integer]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt similarity index 72% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt index 34cb27bf0f..67a4426e25 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.longClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.IntegralGenerator -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `long` or [Long]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt index 2123d0a54d..57f256fbe3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.shortClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.IntegralGenerator -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `short` or [Short]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt index 5155652f7e..7c76baaf24 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/ShortGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.shortWrapperClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.IntegralGenerator -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `short` or [Short]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt similarity index 88% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt index e16a0cbf7d..8defb8a2b8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/StringGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt @@ -1,6 +1,6 @@ -package org.utbot.quickcheck.generator.java.lang +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import kotlin.random.Random /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt index bebb799fcc..64b7773afe 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/lang/strings/CodePoints.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.lang.strings +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.strings import java.nio.charset.Charset import java.nio.charset.CharsetEncoder diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt similarity index 84% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt index 92845aed83..b7654dfc44 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigDecimalGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt @@ -1,15 +1,15 @@ -package org.utbot.quickcheck.generator.java.math +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.math -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.DecimalGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.Precision -import org.utbot.quickcheck.internal.Ranges -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Precision +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.math.BigDecimal import java.math.BigInteger diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt similarity index 77% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt index a84d55df4e..9adb9de954 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/math/BigIntegerGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.math +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.math -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.IntegralGenerator -import org.utbot.quickcheck.internal.Ranges -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.math.BigInteger /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt similarity index 75% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt index 3814951298..907082c679 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/nio/charset/CharsetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt @@ -1,15 +1,15 @@ -package org.utbot.quickcheck.generator.java.nio.charset +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.nio.charset -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.stringClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.nio.charset.Charset /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt similarity index 83% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt index 4d1b4093c8..171def0d1e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ClockGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt @@ -1,16 +1,16 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Clock import java.time.Instant import java.time.ZoneId diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt similarity index 76% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt index 6bbe0e11e4..604af12d67 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/DurationGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Duration /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt similarity index 74% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt index acab0320d8..edf5b6c0f9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/InstantGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Instant /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt similarity index 77% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt index 71b4a9fe6f..fbd6ac8fc3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalDate import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt similarity index 81% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt index 4384b5af9e..1287209869 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalDateTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalDateTime import java.time.ZoneId import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt similarity index 77% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt index 8377ff7c6b..19ac9d0e6f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/LocalTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalTime import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt similarity index 79% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt index 9cfbf6e273..7c5784688f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/MonthDayGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalDate import java.time.MonthDay import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt similarity index 80% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt index ddaa38a5dc..898763ef41 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.OffsetDateTime import java.time.ZoneId import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt similarity index 80% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt index a882ad6801..616a0f16be 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/OffsetTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalTime import java.time.OffsetTime import java.time.ZoneOffset diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt similarity index 82% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt index 635d9ac4ff..1b9b7e9ae1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/PeriodGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Ranges -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.math.BigInteger import java.time.Period import java.time.Year diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt similarity index 76% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt index bf3522713d..66a97b3e4f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Year import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt similarity index 79% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt index 8bda750a6a..4efa1e6f43 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/YearMonthGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Year import java.time.YearMonth import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt index d6c303c6d8..a431da2bb6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneIdGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.ZoneId /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt similarity index 79% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt index 4b2d1990ed..db5e492dc7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZoneOffsetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.ZoneOffset /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt similarity index 82% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt index eaf09d596f..2786dfc151 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.time +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Year import java.time.ZoneId import java.time.ZonedDateTime diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt similarity index 61% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt index 7d006faa1f..ac2fe2ca82 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ArrayListGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [ArrayList]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt similarity index 61% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt index 34347a6ed5..facb65b610 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/BitSetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.BitSet /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt index 70165873f8..3ed0cda21e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/CollectionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.booleanClassId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.* -import org.utbot.quickcheck.internal.Ranges -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * @@ -22,7 +22,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness * * @param the type of collection generated */ -abstract class CollectionGenerator(type: Class<*>) : ComponentizedGenerator(type) { +abstract class CollectionGenerator(type: Class<*>) : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(type) { private var sizeRange: Size? = null private var distinct = false diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt similarity index 78% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt index 2f02922e33..e8acfb0281 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/DateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.text.ParseException import java.text.SimpleDateFormat import java.util.Date diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt similarity index 60% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt index 3cadfd559a..9477c0d1e4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashMapGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [HashMap]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt similarity index 60% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt index 176607dd8b..55e80df390 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashSetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [HashSet]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt similarity index 78% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt index c1beb5a60b..ce5d186df6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/HashtableGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util import java.util.Hashtable diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt similarity index 63% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt index 551c1ff466..4e7094326a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashMapGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [LinkedHashMap]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt similarity index 63% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt index 8f72a9e941..4b7291aa9b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedHashSetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [LinkedHashSet]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt similarity index 67% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt index a084b8ed1d..e42fc229e6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LinkedListGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util import java.util.LinkedList diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt similarity index 73% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt index 66deab14a2..ac7a6bfc56 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/ListGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util /** * Base class for generators of [List]s. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt similarity index 62% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt index 2a9ea589e4..36257e62c1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/LocaleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.Locale /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt similarity index 91% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt index b4c39ecc76..3a17334085 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/MapGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.booleanClassId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.* -import org.utbot.quickcheck.internal.Ranges -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * @@ -22,7 +22,7 @@ import org.utbot.quickcheck.random.SourceOfRandomness * * @param the type of map generated */ -abstract class MapGenerator protected constructor(type: Class<*>) : ComponentizedGenerator(type) { +abstract class MapGenerator protected constructor(type: Class<*>) : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(type) { private var sizeRange: Size? = null private var distinct = false diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt index b300e24c4c..be11e0e89e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalDoubleGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.java.lang.DoubleGenerator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.DoubleGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.OptionalDouble /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt similarity index 74% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt index 34faaf15b1..8465642972 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt @@ -1,21 +1,21 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.methodId import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.Optional /** * Produces values of type [Optional]. */ -class OptionalGenerator : ComponentizedGenerator(Optional::class.java) { +class OptionalGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Optional::class.java) { override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt similarity index 69% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt index bbf290df7f..ba83f9405d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalIntGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.java.lang.IntegerGenerator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.IntegerGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.OptionalInt /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt similarity index 69% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt index b1cc5ef592..1ad1a8a218 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/OptionalLongGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.InRange -import org.utbot.quickcheck.generator.java.lang.LongGenerator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.LongGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.OptionalLong /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt similarity index 79% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt index 58f3acc684..fe5b39b7a0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/PropertiesGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt @@ -1,6 +1,6 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.ConstructorId import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel @@ -8,11 +8,11 @@ import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.methodId import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.java.lang.AbstractStringGenerator -import org.utbot.quickcheck.generator.java.lang.StringGenerator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.AbstractStringGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.StringGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.Dictionary import java.util.Hashtable import java.util.Properties diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt similarity index 91% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt index 3b9e2d578a..71ed0c5571 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/RFC4122.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.GeneratorConfiguration -import org.utbot.quickcheck.generator.java.lang.StringGenerator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorConfiguration +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.StringGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.nio.ByteBuffer import java.nio.charset.StandardCharsets import java.security.MessageDigest diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt similarity index 64% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt index e8d6d0b1b8..f1cc2417f5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/SetGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt @@ -1,6 +1,6 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.Size +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Size /** * Base class for generators of [Set]s. diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt similarity index 63% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt index 7280630eb0..6d33652fc2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/StackGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util import java.util.Stack diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt similarity index 63% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt index dc2cc3f5b8..7d9a50229e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/TimeZoneGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.TimeZone /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt similarity index 64% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt index e6c32ba018..6a70668eed 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/VectorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.generator.java.util +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util import java.util.Vector diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt index 0d2ed999bf..45193fe665 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/concurrent/CallableGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.util.concurrent +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.concurrent -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.concurrent.Callable /** @@ -14,7 +14,7 @@ import java.util.concurrent.Callable * * @param the type of the values produced by the generated instances */ -class CallableGenerator : ComponentizedGenerator(Callable::class.java) { +class CallableGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Callable::class.java) { override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt similarity index 61% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt index f3f08e1a6d..96382601c4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.BiFunction /** @@ -16,7 +16,7 @@ import java.util.function.BiFunction * @param type of second parameter of produced function * @param return type of produced function */ -class BiFunctionGenerator : ComponentizedGenerator(BiFunction::class.java) { +class BiFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(BiFunction::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt index d8af09312b..c9c7ddbe7b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BiPredicateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.BiPredicate /** @@ -17,7 +17,7 @@ import java.util.function.BiPredicate * @param type of first parameter of produced predicate * @param type of second parameter of produced predicate */ -class BiPredicateGenerator : ComponentizedGenerator(BiPredicate::class.java) { +class BiPredicateGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(BiPredicate::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt index e47952aafb..cc58473432 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.BinaryOperator /** @@ -14,7 +14,7 @@ import java.util.function.BinaryOperator * * @param parameters type and return type of produced operator */ -class BinaryOperatorGenerator : ComponentizedGenerator(BinaryOperator::class.java) { +class BinaryOperatorGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(BinaryOperator::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt index 77a2d434f4..82f6a07b4f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.DoubleFunction /** @@ -14,7 +14,7 @@ import java.util.function.DoubleFunction * * @param return type of produced function */ -class DoubleFunctionGenerator : ComponentizedGenerator(DoubleFunction::class.java) { +class DoubleFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(DoubleFunction::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt similarity index 59% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt index 151ca39ee2..2a2b199ea9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/FunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.Function /** @@ -15,7 +15,7 @@ import java.util.function.Function * @param type of parameter of produced function * @param return type of produced function */ -class FunctionGenerator : ComponentizedGenerator(Function::class.java) { +class FunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Function::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt similarity index 57% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt index 77cd7e967b..a81797b918 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/IntFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.IntFunction /** @@ -14,7 +14,7 @@ import java.util.function.IntFunction * * @param return type of produced function */ -class IntFunctionGenerator : ComponentizedGenerator(IntFunction::class.java) { +class IntFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(IntFunction::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt similarity index 57% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt index b074b306c4..1500a5e299 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/LongFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.LongFunction /** @@ -14,7 +14,7 @@ import java.util.function.LongFunction * * @param return type of produced function */ -class LongFunctionGenerator : ComponentizedGenerator(LongFunction::class.java) { +class LongFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(LongFunction::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt similarity index 57% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt index 580864be89..523e0d60f7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/PredicateGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.Predicate /** @@ -16,7 +16,7 @@ import java.util.function.Predicate * * @param type of parameter of produced predicate */ -class PredicateGenerator : ComponentizedGenerator(Predicate::class.java) { +class PredicateGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Predicate::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt index f81d12b639..39fe55ea9f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/SupplierGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.Supplier /** @@ -14,7 +14,7 @@ import java.util.function.Supplier * * @param the type of the values produced by the generated instances */ -class SupplierGenerator : ComponentizedGenerator(Supplier::class.java) { +class SupplierGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Supplier::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt index fb3b957ff8..4109c68a8b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToDoubleBiFunction /** @@ -17,7 +17,7 @@ import java.util.function.ToDoubleBiFunction * @param type of first parameter of produced function * @param type of second parameter of produced function */ -class ToDoubleBiFunctionGenerator : ComponentizedGenerator(ToDoubleBiFunction::class.java) { +class ToDoubleBiFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToDoubleBiFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt similarity index 57% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt index cf3c259ba5..7c88de5e2b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToDoubleFunction /** @@ -16,7 +16,7 @@ import java.util.function.ToDoubleFunction * * @param type of parameter of produced function */ -class ToDoubleFunctionGenerator : ComponentizedGenerator(ToDoubleFunction::class.java) { +class ToDoubleFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToDoubleFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt index 3588ac24d4..82b6e30c4f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToIntBiFunction /** @@ -17,7 +17,7 @@ import java.util.function.ToIntBiFunction * @param type of first parameter of produced function * @param type of second parameter of produced function */ -class ToIntBiFunctionGenerator : ComponentizedGenerator(ToIntBiFunction::class.java) { +class ToIntBiFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToIntBiFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt similarity index 57% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt index 226f3a8c72..d6bd9e84ae 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToIntFunction /** @@ -16,7 +16,7 @@ import java.util.function.ToIntFunction * * @param type of parameter of produced function */ -class ToIntFunctionGenerator : ComponentizedGenerator(ToIntFunction::class.java) { +class ToIntFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToIntFunction::class.java) { private var generator: Generator? = null override fun provide(provided: Generators) { super.provide(provided) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt index bd8c67a680..7910fbe16f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToLongBiFunction /** @@ -17,7 +17,7 @@ import java.util.function.ToLongBiFunction * @param type of first parameter of produced function * @param type of second parameter of produced function */ -class ToLongBiFunctionGenerator : ComponentizedGenerator(ToLongBiFunction::class.java) { +class ToLongBiFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToLongBiFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt similarity index 57% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt index 89baabe41e..109fa2b96f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToLongFunction /** @@ -16,7 +16,7 @@ import java.util.function.ToLongFunction * * @param type of parameter of produced function */ -class ToLongFunctionGenerator : ComponentizedGenerator(ToLongFunction::class.java) { +class ToLongFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToLongFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt index aad0a8c29c..2a93548da9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.generator.java.util.function +package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.ComponentizedGenerator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.UnaryOperator /** @@ -14,7 +14,7 @@ import java.util.function.UnaryOperator * * @param type of parameter and return type of produced operator */ -class UnaryOperatorGenerator : ComponentizedGenerator(UnaryOperator::class.java) { +class UnaryOperatorGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(UnaryOperator::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt similarity index 96% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt index d8e68d72a1..25be2fd324 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/DefaultMethodHandleMaker.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal import java.lang.invoke.MethodHandle import java.lang.invoke.MethodHandles diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt similarity index 96% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt index 10c32735b6..8a0ab1d03c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactory.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal import java.lang.reflect.AnnotatedArrayType import java.lang.reflect.AnnotatedType diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt index 996624472d..0f35242917 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt @@ -22,7 +22,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal import java.lang.reflect.AnnotatedArrayType import java.lang.reflect.AnnotatedType diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt similarity index 84% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt index 918b2a771b..b3660cd9fa 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/GeometricDistribution.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt @@ -1,6 +1,6 @@ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import kotlin.math.ceil import kotlin.math.ln diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Items.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Items.kt similarity index 89% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Items.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Items.kt index aef85ec297..8324aaab76 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Items.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Items.kt @@ -1,6 +1,6 @@ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness object Items { @JvmStatic diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt similarity index 97% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt index 39cb99e9d0..5fecaa60db 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ParameterTypeContext.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt @@ -1,11 +1,11 @@ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal import org.javaruntype.type.* import org.javaruntype.type.Type -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom -import org.utbot.quickcheck.internal.Items.choose -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Items.choose +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.GenericsResolver import ru.vyarus.java.generics.resolver.context.GenericsContext import ru.vyarus.java.generics.resolver.context.MethodGenericsContext diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Ranges.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Ranges.kt similarity index 95% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Ranges.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Ranges.kt index b32a422368..138c4683d6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Ranges.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Ranges.kt @@ -1,6 +1,6 @@ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.math.BigInteger object Ranges { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Reflection.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Reflection.kt similarity index 99% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Reflection.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Reflection.kt index b9040cf8b5..b392f58bfe 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Reflection.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Reflection.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal import org.javaruntype.type.Type import java.lang.reflect.AnnotatedArrayType diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ReflectionException.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ReflectionException.kt similarity index 72% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ReflectionException.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ReflectionException.kt index 9a7e687daf..38f459b385 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/ReflectionException.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ReflectionException.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal class ReflectionException : RuntimeException { constructor(message: String) : super(message) diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Weighted.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Weighted.kt similarity index 78% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Weighted.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Weighted.kt index 1f9e6a2de4..b59b45b8e6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Weighted.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Weighted.kt @@ -1,4 +1,4 @@ -package org.utbot.quickcheck.internal +package org.utbot.engine.greyboxfuzzer.quickcheck.internal class Weighted(item: T, weight: Int) { val item: T diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Zilch.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Zilch.kt new file mode 100644 index 0000000000..a17f62896a --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Zilch.kt @@ -0,0 +1,3 @@ +package org.utbot.engine.greyboxfuzzer.quickcheck.internal + +object Zilch diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt similarity index 53% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt index 7ed7ebc341..b3980c3420 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/AbstractGenerationStatus.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt @@ -1,8 +1,8 @@ -package org.utbot.quickcheck.internal.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.internal.GeometricDistribution -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.GeometricDistribution +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness abstract class AbstractGenerationStatus( private val distro: GeometricDistribution, diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt similarity index 94% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt index 4b0814f1fe..e75e5a1409 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ArrayGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt @@ -1,8 +1,8 @@ -package org.utbot.quickcheck.internal.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtArrayModel @@ -17,10 +17,10 @@ import org.utbot.framework.plugin.api.util.floatArrayClassId import org.utbot.framework.plugin.api.util.intArrayClassId import org.utbot.framework.plugin.api.util.longArrayClassId import org.utbot.framework.plugin.api.util.shortArrayClassId -import org.utbot.quickcheck.generator.* -import org.utbot.quickcheck.internal.Ranges -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedType class ArrayGenerator(private val componentType: Class<*>, val component: Generator) : Generator(Any::class.java) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt similarity index 91% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt index b2939f707e..593a410231 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/CompositeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.quickcheck.internal.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.* -import org.utbot.quickcheck.internal.Items -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.internal.Weighted -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Items +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Weighted +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedElement import java.lang.reflect.AnnotatedType diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt new file mode 100644 index 0000000000..b5b0d1c312 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt @@ -0,0 +1,32 @@ +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator + +import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.id +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness + +class EnumGenerator(private val enumType: Class<*>) : Generator(Enum::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + val values = enumType.enumConstants + val index = random.nextInt(0, values.size - 1) + return generatorContext.utModelConstructor.construct(values[index], Enum::class.id) + } + + override fun copy(): Generator { + return EnumGenerator(enumType).also { + it.generatedUtModel = generatedUtModel + it.generationState = generationState + it.nestedGenerators = nestedGenerators.map { it.copy() }.toMutableList() + if (isGeneratorContextInitialized()) { + it.generatorContext = generatorContext + } + GeneratorConfigurator.configureGenerator(it, 95) + } + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt similarity index 93% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt index 97d08b9f7e..2a5cffde73 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/GeneratorRepository.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.internal.generator - -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.NullAllowed -import org.utbot.quickcheck.internal.Items.choose -import org.utbot.quickcheck.internal.ParameterTypeContext -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.internal.Weighted -import org.utbot.quickcheck.internal.Zilch -import org.utbot.quickcheck.random.SourceOfRandomness +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator + +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.NullAllowed +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Items.choose +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Weighted +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Zilch +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedElement import java.lang.reflect.Field import java.lang.reflect.Parameter diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt similarity index 65% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt index 68d87c8b79..540f65a934 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/LambdaGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.quickcheck.internal.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness class LambdaGenerator internal constructor( private val lambdaType: Class, diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt similarity index 81% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt index 0bbfa75e49..8564f33e4d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/MarkerInterfaceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.quickcheck.internal.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.internal.DefaultMethodHandleMaker -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.DefaultMethodHandleMaker +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.InvocationHandler import java.lang.reflect.Method import java.lang.reflect.Proxy diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt similarity index 81% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt index a26716b2c1..42da983a3e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/NullableGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt @@ -1,15 +1,15 @@ -package org.utbot.quickcheck.internal.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator import org.javaruntype.type.TypeParameter import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.generator.Generators -import org.utbot.quickcheck.generator.NullAllowed -import org.utbot.quickcheck.internal.Reflection -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.NullAllowed +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedElement import java.lang.reflect.AnnotatedType import java.util.Optional diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt similarity index 51% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt index 765b00ef1f..b9d166989b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/SimpleGenerationStatus.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt @@ -1,7 +1,7 @@ -package org.utbot.quickcheck.internal.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.quickcheck.internal.GeometricDistribution -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.GeometricDistribution +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness class SimpleGenerationStatus( distro: GeometricDistribution, diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt similarity index 54% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt index 8da78a7b0a..df5180e7d7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/ZilchGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.quickcheck.internal.generator +package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.internal.Zilch -import org.utbot.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Zilch +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness class ZilchGenerator : Generator(Zilch::class.java) { override fun generate( diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt index edaa8a87ee..e379a84856 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/random/SourceOfRandomness.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt @@ -1,7 +1,7 @@ -package org.utbot.quickcheck.random +package org.utbot.engine.greyboxfuzzer.quickcheck.random -import org.utbot.quickcheck.internal.Items -import org.utbot.quickcheck.internal.Ranges +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Items +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.IOException diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt index c4ac95ad2a..f2f25939ed 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt @@ -2,7 +2,7 @@ package org.utbot.engine.greyboxfuzzer.util -import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext import org.javaruntype.type.Types import org.utbot.common.withAccessibility import org.utbot.engine.rawType diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt index 2d4ec5619e..0b5928451d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt @@ -1,11 +1,11 @@ package org.utbot.engine.greyboxfuzzer.util -import org.utbot.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext import org.utbot.engine.greyboxfuzzer.generator.* import org.utbot.external.api.classIdForType import org.utbot.framework.concrete.UtModelConstructor import org.utbot.framework.plugin.api.* -import org.utbot.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import java.lang.reflect.Method import java.lang.reflect.Parameter @@ -58,7 +58,6 @@ fun UtModel.copy(): UtModel = is UtArrayModel -> this.copy() is UtClassRefModel -> this.copy() is UtPrimitiveModel -> this.copy() - is UtReferenceModel -> this.copy() else -> this } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt new file mode 100644 index 0000000000..c5e7cc2c59 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt @@ -0,0 +1,31 @@ +package org.utbot.engine.greyboxfuzzer.util + +import org.utbot.framework.plugin.api.* + +class UtGreyBoxFuzzedExecution( + stateBefore: EnvironmentModels, + result: UtExecutionResult, + stateAfter: EnvironmentModels = stateBefore, + coverage: Coverage? = null, + summary: List? = null, + testMethodName: String? = null, + displayName: String? = null +): UtExecution(stateBefore, stateAfter, result, coverage, summary, testMethodName, displayName) { + + override fun toString(): String = buildString { + append("UtGreyBoxFuzzedExecution(") + appendLine() + + append(":") + appendLine() + append(stateBefore) + appendLine() + + append(":") + appendLine() + append(result) + append(")") + } + + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt deleted file mode 100644 index 845fdaf54f..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/Zilch.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.utbot.quickcheck.internal - -object Zilch diff --git a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt deleted file mode 100644 index 280bc54dcb..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/quickcheck/internal/generator/EnumGenerator.kt +++ /dev/null @@ -1,19 +0,0 @@ -package org.utbot.quickcheck.internal.generator - -import org.utbot.quickcheck.generator.GeneratorContext -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.util.id -import org.utbot.quickcheck.generator.GenerationStatus -import org.utbot.quickcheck.generator.Generator -import org.utbot.quickcheck.random.SourceOfRandomness - -class EnumGenerator(private val enumType: Class<*>) : Generator(Enum::class.java) { - override fun generate( - random: SourceOfRandomness, - status: GenerationStatus - ): UtModel { - val values = enumType.enumConstants - val index = random.nextInt(0, values.size - 1) - return generatorContext.utModelConstructor.construct(values[index], Enum::class.id) - } -} \ No newline at end of file From 3452621ab1a9589cea641a74a584d6183ed1b076 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Thu, 1 Dec 2022 18:08:30 +0300 Subject: [PATCH 12/30] m --- utbot-framework/build.gradle | 7 ------- 1 file changed, 7 deletions(-) diff --git a/utbot-framework/build.gradle b/utbot-framework/build.gradle index 8e992886d2..7401500d4e 100644 --- a/utbot-framework/build.gradle +++ b/utbot-framework/build.gradle @@ -6,7 +6,6 @@ repositories { configurations { z3native - fetchInstrumentationJar } dependencies { @@ -50,9 +49,6 @@ dependencies { z3native group: 'com.microsoft.z3', name: 'z3-native-win64', version: z3Version, ext: 'zip' z3native group: 'com.microsoft.z3', name: 'z3-native-linux64', version: z3Version, ext: 'zip' z3native group: 'com.microsoft.z3', name: 'z3-native-osx', version: z3Version, ext: 'zip' - - //For my tests - fetchInstrumentationJar project(path: ':utbot-instrumentation', configuration:'instrumentationArchive') } processResources { @@ -61,7 +57,4 @@ processResources { into "lib/x64" } } - from(configurations.fetchInstrumentationJar) { - into "lib" - } } From 82405543eb15e89bc34d2f379cdf13d1c799fbbb Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 6 Dec 2022 16:28:41 +0300 Subject: [PATCH 13/30] UnsafeBasedInstanceGenerator done --- .../kotlin/org/utbot/common/KClassUtil.kt | 8 +- .../kotlin/org/utbot/framework/UtSettings.kt | 7 +- .../engine/greyboxfuzzer/GreyBoxFuzzer.kt | 7 +- .../userclasses/UserClassGenerator.kt | 46 ++++++++-- .../generator/UnsafeBasedInstanceGenerator.kt | 85 +++++++++++++++++++ .../engine/greyboxfuzzer/mutator/Mutator.kt | 4 +- .../constructors/MockValueConstructor.kt | 34 +++++--- 7 files changed, 164 insertions(+), 27 deletions(-) create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt diff --git a/utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt b/utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt index 92e4d8d398..69b14167f7 100644 --- a/utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt +++ b/utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt @@ -8,8 +8,12 @@ import java.lang.reflect.Method * NOTE: vararg parameters must be passed as an array of the corresponding type. */ fun Method.invokeCatching(obj: Any?, args: List) = try { - val invocation = invoke(obj, *args.toTypedArray()) - + val invocation = + try { + invoke(obj, *args.toTypedArray()) + } catch (e: Throwable) { + null + } Result.success(invocation) } catch (e: InvocationTargetException) { Result.failure(e.targetException) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt index d5d73e208f..9e19806096 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt @@ -243,10 +243,15 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS var useFuzzing: Boolean by getBooleanProperty(false) /** - * Set to true to start grey-box fuzzing + * Set to true to use grey-box fuzzing */ var useGreyBoxFuzzing: Boolean by getBooleanProperty(true) + /** + * Set to true to use UtCompositeModels in grey-box fuzzing process + */ + var useCompositeModelsInGreyBoxFuzzing: Boolean by getBooleanProperty(true) + /** * Set the total attempts to improve coverage by fuzzer. */ diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt index d4e725e21a..ea62a23a72 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -15,7 +15,6 @@ import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import java.lang.reflect.Field import java.lang.reflect.Method import kotlin.random.Random -import kotlin.system.exitProcess class GreyBoxFuzzer( private val pathsToUserClasses: String, @@ -36,7 +35,6 @@ class GreyBoxFuzzer( private val timeOfStart = System.currentTimeMillis() private val percentageOfTimeBudgetToChangeMode = 10 - //TODO make it return Sequence suspend fun fuzz(): Sequence { logger.debug { "Started to fuzz ${methodUnderTest.name}" } val generatorContext = GeneratorContext() @@ -55,9 +53,7 @@ class GreyBoxFuzzer( if (timeRemain < 0 || isMethodCovered()) break exploitationStage() } - seeds.getBestSeed() - //UtModelGenerator.reset() - return sequenceOf() + return succeededExecutions.asSequence() } private suspend fun explorationStage( @@ -90,6 +86,7 @@ class GreyBoxFuzzer( thisInstancesHistory += generateThisInstance(methodUnderTest.classId, generatorContext) regenerateThis = false } else if (Random.getTrue(60)) { + logger.debug { "Trying to mutate this instance" } thisInstancesHistory += Mutator.mutateThisInstance( thisInstancesHistory.last(), classFieldsUsedByFunc.toList(), diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt index 5089ca4d93..3d718f3f0f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt @@ -15,6 +15,7 @@ import org.utbot.framework.plugin.api.util.fieldClassId import org.utbot.framework.plugin.api.util.fieldId import org.utbot.framework.plugin.api.util.id import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* +import org.utbot.framework.UtSettings import java.lang.reflect.* import kotlin.random.Random @@ -56,13 +57,22 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { private fun regenerate(random: SourceOfRandomness, status: GenerationStatus): UtModel { logger.debug { "Trying to generate ${parameterTypeContext!!.resolved}. Current depth: $depth" } + if (Random.getTrue(5)) { + return UtNullModel(clazz!!.id) + } if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration.toInt()) { logger.debug { "Depth more than maxDepth ${GreyBoxFuzzerGenerators.maxDepthOfGeneration.toInt()}. Return UtNullModel" } return UtNullModel(clazz!!.id) } val immutableClazz = clazz!! + //TODO make this generators as usual generators when (immutableClazz) { - Any::class.java -> return ObjectGenerator(parameterTypeContext!!, random, status, generatorContext).generate() + Any::class.java -> return ObjectGenerator( + parameterTypeContext!!, + random, + status, + generatorContext + ).generate() Class::class.java -> return ReflectionClassGenerator(parameterTypeContext!!, generatorContext).generate() Type::class.java -> return ReflectionTypeGenerator(parameterTypeContext!!, generatorContext).generate() //TODO implement field generator @@ -73,7 +83,12 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { return UtNullModel(immutableClazz.id) } val resolvedJavaType = parameterTypeContext!!.generics.resolveType(parameterTypeContext!!.type()) - val gctx = resolvedJavaType.createGenericsContext(immutableClazz) + val gctx = + if (resolvedJavaType is Class<*>) { + parameterTypeContext!!.generics + } else { + resolvedJavaType.createGenericsContext(immutableClazz) + } if (!immutableClazz.canBeInstantiated()) { return InterfaceImplementationsInstanceGenerator( resolvedJavaType, @@ -84,7 +99,19 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { depth ).generate() } - return ClassesInstanceGenerator( + val unsafeGenerator = UnsafeBasedInstanceGenerator( + clazz!!, + gctx, + resolvedJavaType, + GreyBoxFuzzerGenerators.sourceOfRandomness, + GreyBoxFuzzerGenerators.genStatus, + generatorContext, + depth + ) + if (Random.getTrue(10) && UtSettings.useCompositeModelsInGreyBoxFuzzing) { + return unsafeGenerator.generate() + } + val generatedObject = ClassesInstanceGenerator( clazz!!, gctx, parameterTypeContext!!.generics, @@ -94,6 +121,10 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { generatorContext, depth ).generate() + if (generatedObject is UtNullModel && Random.getTrue(75) && UtSettings.useCompositeModelsInGreyBoxFuzzing) { + return unsafeGenerator.generate() + } + return generatedObject } override fun modify(random: SourceOfRandomness, status: GenerationStatus): UtModel { @@ -152,10 +183,11 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { clazz!!, chain.map { it!! }.reversed().drop(1) ) ?: return cachedUtModel - return Mutator.regenerateFieldWithContext(genericsContext, cachedUtModel, randomField, generatorContext)?.let { - mutatedFields[randomField] = it.second - it.first - } ?: cachedUtModel + return Mutator.regenerateFieldWithContext(genericsContext, cachedUtModel, randomField, generatorContext) + ?.let { + mutatedFields[randomField] = it.second + it.first + } ?: cachedUtModel } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt new file mode 100644 index 0000000000..2d66211df8 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt @@ -0,0 +1,85 @@ +package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator + +import org.utbot.engine.greyboxfuzzer.generator.DataGenerator +import org.utbot.engine.greyboxfuzzer.generator.QuickCheckExtensions +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.engine.greyboxfuzzer.util.* +import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.api.UtCompositeModel +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.fieldId +import org.utbot.framework.plugin.api.util.id +import ru.vyarus.java.generics.resolver.context.GenericsContext +import java.lang.reflect.Modifier +import java.lang.reflect.Type + +class UnsafeBasedInstanceGenerator( + private val clazz: Class<*>, + private val typeContext: GenericsContext, + private val resolvedType: Type, + private val sourceOfRandomness: SourceOfRandomness, + private val generationStatus: GenerationStatus, + private val generatorContext: GeneratorContext, + private val depth: Int +) : InstanceGenerator { + override fun generate(): UtModel { + val fields = clazz.getAllDeclaredFields() + .filterNot { it.hasModifiers(Modifier.FINAL, Modifier.STATIC) || it.hasModifiers(Modifier.STATIC) } + val sootClazz = clazz.toSootClass() ?: return UtNullModel(clazz.id) + val constructor = generatorContext.utModelConstructor + val allNeededContexts = fields.map { it.declaringClass }.filter { it != clazz }.toSet() + val chainToGenericsContext = allNeededContexts.map { cl -> + val chain = cl.toSootClass() + ?.getImplementersOfWithChain() + ?.filter { it.contains(sootClazz) } + ?.map { it.dropLastWhile { it != sootClazz } } + ?.minByOrNull { it.size } + ?.map { it.toJavaClass() } + if (chain == null || chain.any { it == null }) { + null + } else { + cl to QuickCheckExtensions.buildGenericsContextForInterfaceParent( + resolvedType, + clazz, + chain.map { it!! }.reversed().drop(1) + ) + } + } + val allChainToGenericsContext = chainToGenericsContext + (clazz to typeContext) + val fieldsMocks = fields + .associateTo(mutableMapOf()) { field -> + val genericsContextForField = + allChainToGenericsContext.find { it!!.first == field.declaringClass }?.second + val fieldType = + if (genericsContextForField != null) { + genericsContextForField.resolveFieldType(field).let { + if (it.toClass() == null) field.type else it + } + } else { + field.type + } + val parameterTypeContext = ParameterTypeContext.forType(fieldType, genericsContextForField) + val generatedUtModelWithReturnType = + try { + DataGenerator.generateUtModel( + parameterTypeContext, + depth, + generatorContext, + sourceOfRandomness, + generationStatus + ) + } catch (_: Throwable) { + UtNullModel(fieldType.toClass()!!.id) + } + field.fieldId to generatedUtModelWithReturnType + } + return UtCompositeModel(constructor.computeUnusedIdAndUpdate(), clazz.id, isMock = true, fields = fieldsMocks) + } + + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt index a377d667d4..7f890cc3c2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt @@ -125,7 +125,7 @@ object Mutator { generatorContext: GeneratorContext ): ThisInstance { if (thisInstance !is NormalMethodThisInstance) return thisInstance - val thisInstanceAsUtModel = thisInstance.utModel as UtAssembleModel + val thisInstanceAsUtModel = thisInstance.utModel as? UtAssembleModel ?: return thisInstance val mutationResult = regenerateFields( thisInstance.classId.jClass, @@ -168,7 +168,7 @@ object Mutator { } val callModel = UtExecutableCallModel(fParameter.utModel as UtReferenceModel, randomMethod, parametersForMethodInvocation) - (originalUtModel as UtAssembleModel).addModification(listOf(callModel)) + (originalUtModel as? UtAssembleModel)?.addModification(listOf(callModel)) return FParameter(originalParameter, null, fParameter.utModel, fParameter.generator, fParameter.fields) } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/MockValueConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/MockValueConstructor.kt index ba6f49c717..b881f055bc 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/MockValueConstructor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/MockValueConstructor.kt @@ -82,7 +82,7 @@ class MockValueConstructor( } // TODO: JIRA:1379 -- replace UtReferenceModel with Int - private val constructedObjects = HashMap() + private val constructedObjects = HashMap() private val mockInfo = mutableListOf() private var mockTarget: MockTarget? = null private var mockCounter = 0 @@ -196,7 +196,12 @@ class MockValueConstructor( check(Reflection.isModifiersAccessible()) val target = mockTarget(fieldModel) { - FieldMockTarget(fieldModel.classId.name, model.classId.name, UtConcreteValue(classInstance), fieldId.name) + FieldMockTarget( + fieldModel.classId.name, + model.classId.name, + UtConcreteValue(classInstance), + fieldId.name + ) } val value = construct(fieldModel, target).value val instance = if (Modifier.isStatic(declaredField.modifiers)) null else classInstance @@ -345,9 +350,10 @@ class MockValueConstructor( val value = construct(elementModel, null).value try { java.lang.reflect.Array.set(instance, i, value) - } catch (iae:IllegalArgumentException) { + } catch (iae: IllegalArgumentException) { throw IllegalArgumentException( - iae.message + " array: ${instance.javaClass.name}; value: ${value?.javaClass?.name}" , iae + iae.message + " array: ${instance.javaClass.name}; value: ${value?.javaClass?.name}", + iae ) } } @@ -360,15 +366,18 @@ class MockValueConstructor( /** * Constructs object with [UtAssembleModel]. */ - private fun constructFromAssembleModel(assembleModel: UtAssembleModel): Any { + private fun constructFromAssembleModel(assembleModel: UtAssembleModel): Any? { constructedObjects[assembleModel]?.let { return it } val instantiationExecutableCall = assembleModel.instantiationCall val result = updateWithExecutableCallModel(instantiationExecutableCall) - checkNotNull(result) { - "Tracked instance can't be null for call ${instantiationExecutableCall.executable} in model $assembleModel" - } +// checkNotNull(result) { +// "Tracked instance can't be null for call ${instantiationExecutableCall.executable} in model $assembleModel" +// } constructedObjects[assembleModel] = result + if (result == null) { + return null + } assembleModel.modificationsChain.forEach { statementModel -> when (statementModel) { @@ -484,8 +493,13 @@ class MockValueConstructor( } private fun ConstructorId.call(args: List): Any? = - constructor.runSandbox { - newInstance(*args.toTypedArray()) + try { + constructor.runSandbox { + this.isAccessible = true + newInstance(*args.toTypedArray()) + } + } catch (e: Throwable) { + null } /** From ad5af5d6a8526175d975e7f17988360139b59689 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 6 Dec 2022 16:31:30 +0300 Subject: [PATCH 14/30] Mutator refactorings --- .../engine/greyboxfuzzer/mutator/Mutator.kt | 59 ------------------- 1 file changed, 59 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt index 7f890cc3c2..ad30363051 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt @@ -142,15 +142,6 @@ object Mutator { ): FParameter { val originalParameter = fParameter.parameter val originalUtModel = fParameter.utModel -// if (Random.getTrue(100)) { -// return regenerateRandomParameter(fParameter) -// } -// val randomMethod = initialInstance.classId.allMethods -// .filter { !it.name.startsWith("get") && !it.name.startsWith("to")} -// .filter { it.classId.name != "java.lang.Object" } -// .filter { it.parameters.all { !it.name.startsWith("java.util.function") } } -// .toList() -// .randomOrNull() ?: return null val randomMethod = fParameter.classId.allMethods.toList().randomOrNull() ?: return fParameter val parametersForMethodInvocation = randomMethod.method.parameters.mapIndexed { index, parameter -> @@ -171,54 +162,4 @@ object Mutator { (originalUtModel as? UtAssembleModel)?.addModification(listOf(callModel)) return FParameter(originalParameter, null, fParameter.utModel, fParameter.generator, fParameter.fields) } - - -// private fun mutateInput(oldData: Any, sourceOfRandomness: SourceOfRandomness): Any { -// val castedData = oldData as LongArray -// print("BEFORE = ") -// castedData.forEach { print("$it ") } -// println() -// // Clone this input to create initial version of new child -// //val newInput = LinearInput(this) -// val bos = ByteArrayOutputStream(); -// val oos = ObjectOutputStream(bos); -// oos.writeObject(oldData); -// oos.flush(); -// val data = bos.toByteArray() -// val random = java.util.Random()//sourceOfRandomness.toJDKRandom() -// -// // Stack a bunch of mutations -// val numMutations = 3//ZestGuidance.Input.sampleGeometric(random, MEAN_MUTATION_COUNT) -// println("mutations = $numMutations") -// //newInput.desc += ",havoc:$numMutations" -// val setToZero = random.nextDouble() < 0.1 // one out of 10 times -// for (mutation in 1..numMutations) { -// -// // Select a random offset and size -// val offset = random.nextInt(data.size) -// val mutationSize = ZestGuidance.Input.sampleGeometric(random, MEAN_MUTATION_SIZE) -// -// // desc += String.format(":%d@%d", mutationSize, idx); -// -// // Mutate a contiguous set of bytes from offset -// for (i in offset until offset + mutationSize) { -// // Don't go past end of list -// if (i >= data.size) { -// break -// } -// -// // Otherwise, apply a random mutation -// val mutatedValue = if (setToZero) 0 else random.nextInt(256) -// data[i] = mutatedValue.toByte() -// } -// } -// val `in` = ByteArrayInputStream(data) -// val `is` = ObjectInputStream(`in`) -// val afterMutationData = `is`.readObject() as LongArray -// print("AFTER = ") -// afterMutationData.forEach { print("$it ") } -// println() -// return data -// } - } \ No newline at end of file From 9e0ac7021fd507cc8eac5c0d59eecad217e35e4b Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 6 Dec 2022 16:53:28 +0300 Subject: [PATCH 15/30] minor --- .../kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt | 2 -- 1 file changed, 2 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt index 84e2a3f917..e7247e98f8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt @@ -150,8 +150,6 @@ open class TestCaseGenerator( for ((method, controller) in method2controller) { controller.job = launch(currentUtContext) { if (!isActive) return@launch - //TODO remove - //if (!method.name.contains("testFunc3")) return@launch try { //yield one to From 09343b0ee762c86a75bf136b982ff270581d686b Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Mon, 19 Dec 2022 16:12:23 +0300 Subject: [PATCH 16/30] Contest mode is done --- .../framework/plugin/api/UtExecutionResult.kt | 6 - .../api/util/constructor/ValueConstructor.kt | 2 - .../org/utbot/engine/UtBotSymbolicEngine.kt | 18 +- .../engine/greyboxfuzzer/GreyBoxFuzzer.kt | 95 ++++----- .../greyboxfuzzer/generator/DataGenerator.kt | 3 +- ... => GreyBoxFuzzerGeneratorsAndSettings.kt} | 2 +- .../generator/QuickCheckExtensions.kt | 3 +- .../userclasses/UserClassGenerator.kt | 18 +- .../userclasses/generator/ObjectGenerator.kt | 7 +- .../StaticsFieldBasedInstanceGenerator.kt | 4 - .../engine/greyboxfuzzer/mutator/Mutator.kt | 46 +++-- .../engine/greyboxfuzzer/mutator/Seed.kt | 6 +- .../greyboxfuzzer/mutator/SeedCollector.kt | 20 +- .../greyboxfuzzer/util/CoverageCollector.kt | 19 +- .../util/GreyBoxFuzzingStatisticPrinter.kt | 43 ++-- .../greyboxfuzzer/util/ReflectionUtils.kt | 6 +- .../engine/greyboxfuzzer/util/SootUtils.kt | 7 +- .../util/UtGreyBoxFuzzedExecution.kt | 5 +- .../codegen/tree/CgMethodConstructor.kt | 6 +- .../framework/plugin/api/TestCaseGenerator.kt | 2 +- .../utbot/framework/plugin/api/TestFlow.kt | 2 +- .../instrumentation/et/TraceHandler.kt | 8 +- .../instrumentation/et/TraceListStrategy.kt | 2 +- .../UtFuzzingExecutionInstrumentation.kt | 22 ++- .../instrumentation/mock/MockClassVisitor.kt | 60 +++--- .../main/kotlin/org/utbot/contest/Contest.kt | 37 ++-- .../org/utbot/contest/GreyBoxFuzzerContest.kt | 186 ++++++++++++++++++ .../kotlin/org/utbot/summary/TagGenerator.kt | 2 - 28 files changed, 436 insertions(+), 201 deletions(-) rename utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/{GreyBoxFuzzerGenerators.kt => GreyBoxFuzzerGeneratorsAndSettings.kt} (98%) create mode 100644 utbot-junit-contest/src/main/kotlin/org/utbot/contest/GreyBoxFuzzerContest.kt diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt index 260d905359..ed10c005ef 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt @@ -22,10 +22,6 @@ sealed class UtExecutionFailure : UtExecutionResult() { get() = exception } -data class UtExecutionSuccessConcrete(val result: Any?) : UtExecutionResult() { - override fun toString() = "$result" -} - data class UtOverflowFailure( override val exception: Throwable, ) : UtExecutionFailure() @@ -110,11 +106,9 @@ inline fun UtExecutionResult.onFailure(action: (exception: Throwable) -> Unit): fun UtExecutionResult.getOrThrow(): UtModel = when (this) { is UtExecutionSuccess -> model is UtExecutionFailure -> throw exception - is UtExecutionSuccessConcrete -> UtNullModel(objectClassId) } fun UtExecutionResult.exceptionOrNull(): Throwable? = when (this) { is UtExecutionFailure -> rootCauseException is UtExecutionSuccess -> null - is UtExecutionSuccessConcrete -> null } diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/constructor/ValueConstructor.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/constructor/ValueConstructor.kt index b3df2a59ea..f845801f83 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/constructor/ValueConstructor.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/util/constructor/ValueConstructor.kt @@ -26,7 +26,6 @@ import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.UtExecutionFailure import org.utbot.framework.plugin.api.UtExecutionResult import org.utbot.framework.plugin.api.UtExecutionSuccess -import org.utbot.framework.plugin.api.UtExecutionSuccessConcrete import org.utbot.framework.plugin.api.UtLambdaModel import org.utbot.framework.plugin.api.UtMockValue import org.utbot.framework.plugin.api.UtModel @@ -494,7 +493,6 @@ class ValueConstructor { private fun UtExecutionResult.map(transform: (model: UtModel) -> R): Result = when (this) { is UtExecutionSuccess -> Result.success(transform(model)) is UtExecutionFailure -> Result.failure(exception) - is UtExecutionSuccessConcrete -> Result.success(transform(UtNullModel(Any::class.java.id))) } /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index 7bd55202e3..15cb9fd877 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -420,8 +420,8 @@ class UtBotSymbolicEngine( } //Simple fuzzing - fun greyBoxFuzzing(until: Long = Long.MAX_VALUE) = - flow { + fun greyBoxFuzzing(timeBudget: Long = Long.MAX_VALUE) = + flow { GenericsInfoFactory.disableCache() val isFuzzable = methodUnderTest.parameters.all { classId -> classId != Method::class.java.id // causes the child process crash at invocation @@ -431,12 +431,14 @@ class UtBotSymbolicEngine( } try { - GreyBoxFuzzer( - concreteExecutor.pathsToUserClasses, - concreteExecutor.pathsToDependencyClasses, - methodUnderTest, - 120_000L - ).fuzz() + emitAll( + GreyBoxFuzzer( + concreteExecutor.pathsToUserClasses, + concreteExecutor.pathsToDependencyClasses, + methodUnderTest, + timeBudget + ).fuzz() + ) } catch (e: CancellationException) { logger.debug { "Cancelled by timeout" } } catch (e: Throwable) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt index ea62a23a72..efa0af64fc 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -1,5 +1,7 @@ package org.utbot.engine.greyboxfuzzer +import kotlinx.coroutines.flow.FlowCollector +import kotlinx.coroutines.flow.flow import org.utbot.engine.* import org.utbot.engine.greyboxfuzzer.generator.* import org.utbot.engine.greyboxfuzzer.mutator.Mutator @@ -12,8 +14,8 @@ import org.utbot.framework.plugin.api.util.* import org.utbot.framework.util.sootMethod import org.utbot.instrumentation.ConcreteExecutor import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import java.lang.reflect.Executable import java.lang.reflect.Field -import java.lang.reflect.Method import kotlin.random.Random class GreyBoxFuzzer( @@ -23,24 +25,19 @@ class GreyBoxFuzzer( private val timeBudgetInMillis: Long ) { - private val methodLines = - methodUnderTest.sootMethod.activeBody.units - .map { it.javaSourceStartLineNumber } - .filter { it != -1 } - .toSet() - private val seeds = SeedCollector(methodLines = methodLines) - private val succeededExecutions = mutableListOf() + private var methodInstructionsIds: Set? = null + private var seeds: SeedCollector? = null private val timeRemain get() = timeOfStart + timeBudgetInMillis - System.currentTimeMillis() private val timeOfStart = System.currentTimeMillis() - private val percentageOfTimeBudgetToChangeMode = 10 + private val percentageOfTimeBudgetToChangeMode = 25 - suspend fun fuzz(): Sequence { + suspend fun fuzz() = flow { logger.debug { "Started to fuzz ${methodUnderTest.name}" } val generatorContext = GeneratorContext() val javaClazz = methodUnderTest.classId.jClass val sootMethod = methodUnderTest.sootMethod - val javaMethod = sootMethod.toJavaMethod()!! + val javaMethod = sootMethod.toJavaMethod() ?: return@flow val classFieldsUsedByFunc = sootMethod.getClassFieldsUsedByFunc(javaClazz) while (timeRemain > 0 || !isMethodCovered()) { explorationStage( @@ -49,15 +46,14 @@ class GreyBoxFuzzer( methodUnderTest, generatorContext ) - logger.debug { "SEEDS AFTER EXPLORATION STAGE = ${seeds.seedsSize()}" } + logger.debug { "SEEDS AFTER EXPLORATION STAGE = ${seeds?.seedsSize()}" } if (timeRemain < 0 || isMethodCovered()) break exploitationStage() } - return succeededExecutions.asSequence() } - private suspend fun explorationStage( - method: Method, + private suspend fun FlowCollector.explorationStage( + method: Executable, classFieldsUsedByFunc: Set, methodUnderTest: ExecutableId, generatorContext: GeneratorContext @@ -112,8 +108,8 @@ class GreyBoxFuzzer( parameter, index, generatorContext, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus + GreyBoxFuzzerGeneratorsAndSettings.sourceOfRandomness, + GreyBoxFuzzerGeneratorsAndSettings.genStatus ) } logger.debug { "Generated params = $generatedParameters" } @@ -123,23 +119,27 @@ class GreyBoxFuzzer( try { logger.debug { "Execution started" } val executionResult = execute(stateBefore, methodUnderTest) + if (methodInstructionsIds == null) { + methodInstructionsIds = executionResult.methodInstructionsIds + seeds = SeedCollector(methodInstructionsIds = methodInstructionsIds!!) + } + seeds ?: continue logger.debug { "Execution result: $executionResult" } val seedCoverage = getCoverage(executionResult) logger.debug { "Calculating seed score" } - val seedScore = seeds.calcSeedScore(seedCoverage) + val seedScore = seeds!!.calcSeedScore(seedCoverage) logger.debug { "Adding seed" } val seed = Seed(thisInstance, generatedParameters, seedCoverage, seedScore) - if (seeds.isSeedOpensNewCoverage(seed)) { - succeededExecutions.add( + if (seeds!!.isSeedOpensNewCoverage(seed)) { + emit( UtGreyBoxFuzzedExecution( stateBefore, - executionResult.result, - coverage = executionResult.coverage, - testMethodName = methodUnderTest.name + executionResult, + coverage = executionResult.coverage ) ) } - seeds.addSeed(seed) + seeds!!.addSeed(seed) logger.debug { "Execution result: ${executionResult.result}" } logger.debug { "Seed score = $seedScore" } } catch (e: Throwable) { @@ -154,10 +154,10 @@ class GreyBoxFuzzer( } } - private suspend fun exploitationStage() { + private suspend fun FlowCollector.exploitationStage() { logger.debug { "Exploitation began" } - if (seeds.seedsSize() == 0) return - if (seeds.all { it.parameters.isEmpty() }) return + if (seeds == null || seeds!!.seedsSize() == 0) return + if (seeds!!.all { it.parameters.isEmpty() }) return val startTime = System.currentTimeMillis() val endTime = startTime + timeBudgetInMillis / percentageOfTimeBudgetToChangeMode var iterationNumber = 0 @@ -167,13 +167,13 @@ class GreyBoxFuzzer( if (iterationNumber > 30_000) return logger.debug { "Func: ${methodUnderTest.name} Mutation iteration number $iterationNumber" } iterationNumber++ - val randomSeed = seeds.getRandomWeightedSeed() + val randomSeed = seeds!!.getRandomWeightedSeed() logger.debug { "Random seed params = ${randomSeed.parameters}" } val mutatedSeed = Mutator.mutateSeed( randomSeed, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus + GreyBoxFuzzerGeneratorsAndSettings.sourceOfRandomness, + GreyBoxFuzzerGeneratorsAndSettings.genStatus ) if (mutatedSeed == randomSeed) { logger.debug { "Cant mutate seed" } @@ -186,17 +186,16 @@ class GreyBoxFuzzer( logger.debug { "Execution result: $executionResult" } val seedScore = getCoverage(executionResult) mutatedSeed.score = 0.0 - if (seeds.isSeedOpensNewCoverage(mutatedSeed)) { - succeededExecutions.add( + if (seeds!!.isSeedOpensNewCoverage(mutatedSeed)) { + emit( UtGreyBoxFuzzedExecution( stateBefore, - executionResult.result, - coverage = executionResult.coverage, - testMethodName = methodUnderTest.name + executionResult, + coverage = executionResult.coverage ) ) } - seeds.addSeed(mutatedSeed) + seeds!!.addSeed(mutatedSeed) logger.debug { "Execution result: ${executionResult.result}" } logger.debug { "Seed score = $seedScore" } } catch (e: Throwable) { @@ -208,23 +207,25 @@ class GreyBoxFuzzer( private fun getCoverage( executionResult: UtFuzzingConcreteExecutionResult - ): Set { + ): Set { val currentMethodCoverage = executionResult.coverage.coveredInstructions .asSequence() + .filter { it.className == methodUnderTest.classId.name.replace('.', '/') } .filter { it.methodSignature == methodUnderTest.signature } - .map { it.lineNumber } - .filter { it in methodLines } + .map { it.id } + .filter { it in methodInstructionsIds!! } .toSet() - logger.debug { "Covered lines $currentMethodCoverage from $methodLines" } - executionResult.coverage.coveredInstructions.forEach { CoverageCollector.coverage.add(it) } + logger.debug { "Covered instructions ${currentMethodCoverage.count()} from ${methodInstructionsIds!!.size}" } + executionResult.coverage.coveredInstructions.forEach { CoverageCollector.addCoverage(it) } return currentMethodCoverage } private fun isMethodCovered(): Boolean { - val coveredLines = - CoverageCollector.coverage.filter { it.methodSignature == methodUnderTest.signature }.map { it.lineNumber } + methodInstructionsIds ?: return false + val coveredInstructions = + CoverageCollector.coverage.filter { it.methodSignature == methodUnderTest.signature }.map { it.id } .toSet() - return coveredLines.containsAll(methodLines) + return coveredInstructions.containsAll(methodInstructionsIds!!) } private suspend fun ConcreteExecutor.executeConcretely( @@ -253,12 +254,12 @@ class GreyBoxFuzzer( private fun generateThisInstance(classId: ClassId, generatorContext: GeneratorContext): ThisInstance = - if (!methodUnderTest.isStatic) { + if (!methodUnderTest.isStatic && !methodUnderTest.isConstructor) { DataGenerator.generateThis( classId, generatorContext, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus + GreyBoxFuzzerGeneratorsAndSettings.sourceOfRandomness, + GreyBoxFuzzerGeneratorsAndSettings.genStatus ) } else { StaticMethodThisInstance diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt index 15c611a650..10a4ea5dc9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt @@ -12,14 +12,13 @@ import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass -import org.utbot.framework.plugin.api.util.objectClassId import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationState import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import java.lang.reflect.Parameter object DataGenerator { - private val generatorRepository = GreyBoxFuzzerGenerators.generatorRepository + private val generatorRepository = GreyBoxFuzzerGeneratorsAndSettings.generatorRepository fun generateUtModel( parameterTypeContext: ParameterTypeContext, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt rename to utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt index fbd6abc1e6..c9b3d5930f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGenerators.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt @@ -12,7 +12,7 @@ import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.* import java.util.concurrent.atomic.AtomicInteger -object GreyBoxFuzzerGenerators { +object GreyBoxFuzzerGeneratorsAndSettings { const val seed = 42L val maxDepthOfGeneration = AtomicInteger(5) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt index eb68375bc0..8cacf90e02 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -10,7 +10,6 @@ import org.utbot.engine.greyboxfuzzer.generator.userclasses.UserClassGenerator import org.utbot.engine.greyboxfuzzer.util.* import org.utbot.engine.logger import org.utbot.engine.rawType -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.engine.greyboxfuzzer.quickcheck.internal.FakeAnnotatedTypeFactory @@ -87,7 +86,7 @@ fun GeneratorRepository.getOrProduceGenerator( depth: Int ): Generator? { val producedUserClassesGenerators = mutableListOf() - parameterTypeContext.getAllSubParameterTypeContexts(GreyBoxFuzzerGenerators.sourceOfRandomness).reversed() + parameterTypeContext.getAllSubParameterTypeContexts(GreyBoxFuzzerGeneratorsAndSettings.sourceOfRandomness).reversed() .forEach { typeContext -> try { this.produceGenerator(typeContext) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt index 3d718f3f0f..e13ab87473 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt @@ -60,8 +60,8 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { if (Random.getTrue(5)) { return UtNullModel(clazz!!.id) } - if (depth >= GreyBoxFuzzerGenerators.maxDepthOfGeneration.toInt()) { - logger.debug { "Depth more than maxDepth ${GreyBoxFuzzerGenerators.maxDepthOfGeneration.toInt()}. Return UtNullModel" } + if (depth >= GreyBoxFuzzerGeneratorsAndSettings.maxDepthOfGeneration.toInt()) { + logger.debug { "Depth more than maxDepth ${GreyBoxFuzzerGeneratorsAndSettings.maxDepthOfGeneration.toInt()}. Return UtNullModel" } return UtNullModel(clazz!!.id) } val immutableClazz = clazz!! @@ -84,7 +84,7 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { } val resolvedJavaType = parameterTypeContext!!.generics.resolveType(parameterTypeContext!!.type()) val gctx = - if (resolvedJavaType is Class<*>) { + if (resolvedJavaType is Class<*> && parameterTypeContext!!.generics.genericsInfo.rootClass == immutableClazz) { parameterTypeContext!!.generics } else { resolvedJavaType.createGenericsContext(immutableClazz) @@ -93,8 +93,8 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { return InterfaceImplementationsInstanceGenerator( resolvedJavaType, gctx, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus, + GreyBoxFuzzerGeneratorsAndSettings.sourceOfRandomness, + GreyBoxFuzzerGeneratorsAndSettings.genStatus, generatorContext, depth ).generate() @@ -103,8 +103,8 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { clazz!!, gctx, resolvedJavaType, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus, + GreyBoxFuzzerGeneratorsAndSettings.sourceOfRandomness, + GreyBoxFuzzerGeneratorsAndSettings.genStatus, generatorContext, depth ) @@ -116,8 +116,8 @@ class UserClassGenerator : ComponentizedGenerator(Any::class.java) { gctx, parameterTypeContext!!.generics, generationMethod, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus, + GreyBoxFuzzerGeneratorsAndSettings.sourceOfRandomness, + GreyBoxFuzzerGeneratorsAndSettings.genStatus, generatorContext, depth ).generate() diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt index 18c840218e..3317f766ab 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt @@ -1,10 +1,9 @@ package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGenerators +import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGeneratorsAndSettings import org.utbot.engine.greyboxfuzzer.generator.getOrProduceGenerator import org.utbot.engine.greyboxfuzzer.util.getAllTypesFromCastAndInstanceOfInstructions import org.utbot.engine.greyboxfuzzer.util.getTrue -import org.utbot.engine.greyboxfuzzer.util.toJavaClass import org.utbot.engine.greyboxfuzzer.util.toSootMethod import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel @@ -30,13 +29,13 @@ class ObjectGenerator( val potentialInterestingObjectReplacement = if (potentialUsefulClasses?.isNotEmpty() == true && Random.getTrue(70)) { val randomClass = potentialUsefulClasses.random() - val generator = GreyBoxFuzzerGenerators.generatorRepository + val generator = GreyBoxFuzzerGeneratorsAndSettings.generatorRepository .getOrProduceGenerator(randomClass, generatorContext) ?.also { it.generatorContext = generatorContext } generator?.generateImpl(sourceOfRandomness, generationStatus) } else null potentialInterestingObjectReplacement?.let { return it } - val generator = GreyBoxFuzzerGenerators.generatorRepository + val generator = GreyBoxFuzzerGeneratorsAndSettings.generatorRepository .getGenerators() .toList() .flatMap { it.second } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt index dbf53a0706..26010c200b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt @@ -5,15 +5,11 @@ import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.engine.greyboxfuzzer.util.hasModifiers import org.utbot.engine.greyboxfuzzer.util.toClass import org.utbot.external.api.classIdForType -import org.utbot.framework.codegen.model.constructor.builtin.setAccessible import org.utbot.framework.concrete.UtModelConstructor import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Field -import java.lang.reflect.Method import java.lang.reflect.Modifier import java.util.* diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt index ad30363051..98add8002d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt @@ -37,15 +37,26 @@ object Mutator { return seedCopy.replaceFParameter(randomParameterIndex, newFParameter) } - fun regenerateFields( + private fun regenerateFields( clazz: Class<*>, classInstance: UtAssembleModel, fieldsToRegenerate: List, generatorContext: GeneratorContext ): UtModel { - val parameterTypeContext = ParameterTypeContext.forClass(clazz) - val modifications = - fieldsToRegenerate.mapNotNull { setNewFieldValue(it, parameterTypeContext.generics, classInstance, generatorContext) } + val modifications = mutableListOf() + try { + val parameterTypeContext = ParameterTypeContext.forClass(clazz) + fieldsToRegenerate.mapNotNull { + setNewFieldValue( + it, + parameterTypeContext.generics, + classInstance, + generatorContext + ) + }.forEach { modifications.add(it) } + } catch (e: Throwable) { + logger.debug { "Exception while mutation: ${e.stackTrace.joinToString("\n")}" } + } return classInstance.addModification(modifications) } @@ -55,7 +66,8 @@ object Mutator { fieldsToRegenerate: List, generatorContext: GeneratorContext ): UtModel { - val modifications = fieldsToRegenerate.mapNotNull { setNewFieldValue(it, genericsContext, classInstance, generatorContext) } + val modifications = + fieldsToRegenerate.mapNotNull { setNewFieldValue(it, genericsContext, classInstance, generatorContext) } return classInstance.addModification(modifications) } @@ -95,14 +107,21 @@ object Mutator { genericsContext ) val generatorForField = - GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(parameterTypeContextForResolvedType, generatorContext, 0) + GreyBoxFuzzerGeneratorsAndSettings.generatorRepository.getOrProduceGenerator( + parameterTypeContextForResolvedType, + generatorContext, + 0 + ) ?: return null var newFieldValue: UtModel = UtNullModel(parameterTypeContextForResolvedType.rawClass.id) for (i in 0 until 3) { try { generatorForField.generationState = GenerationState.REGENERATE generatorForField.generatorContext.startCheckpoint() - newFieldValue = generatorForField.generateImpl(GreyBoxFuzzerGenerators.sourceOfRandomness, GreyBoxFuzzerGenerators.genStatus) + newFieldValue = generatorForField.generateImpl( + GreyBoxFuzzerGeneratorsAndSettings.sourceOfRandomness, + GreyBoxFuzzerGeneratorsAndSettings.genStatus + ) if (newFieldValue !is UtNullModel) break } catch (e: Throwable) { continue @@ -117,7 +136,8 @@ object Mutator { genericsContext: GenericsContext, clazzInstance: UtAssembleModel, generatorContext: GeneratorContext, - ): UtStatementModel? = setNewFieldValueWithGenerator(field, genericsContext, clazzInstance, generatorContext)?.second + ): UtStatementModel? = + setNewFieldValueWithGenerator(field, genericsContext, clazzInstance, generatorContext)?.second fun mutateThisInstance( thisInstance: ThisInstance, @@ -148,13 +168,17 @@ object Mutator { val resolvedParameterCtx = originalParameter.resolveParameterTypeAndBuildParameterContext(index, randomMethod.method) val generatorForParameter = - GreyBoxFuzzerGenerators.generatorRepository.getOrProduceGenerator(resolvedParameterCtx, generatorContext, 0) + GreyBoxFuzzerGeneratorsAndSettings.generatorRepository.getOrProduceGenerator( + resolvedParameterCtx, + generatorContext, + 0 + ) ?: return fParameter DataGenerator.generate( generatorForParameter, parameter, - GreyBoxFuzzerGenerators.sourceOfRandomness, - GreyBoxFuzzerGenerators.genStatus + GreyBoxFuzzerGeneratorsAndSettings.sourceOfRandomness, + GreyBoxFuzzerGeneratorsAndSettings.genStatus ).utModel } val callModel = diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt index fa43ffc4e2..59b7cdf649 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt @@ -7,7 +7,7 @@ import org.utbot.framework.plugin.api.EnvironmentModels data class Seed( val thisInstance: ThisInstance, val parameters: List, - val lineCoverage: Set, + val instructionCoverage: Set, var score: Double = 0.0 ) { @@ -16,14 +16,14 @@ data class Seed( } fun copy(): Seed { - return Seed(thisInstance.copy(), parameters.map { it.copy() }, lineCoverage.toSet(), score) + return Seed(thisInstance.copy(), parameters.map { it.copy() }, instructionCoverage.toSet(), score) } fun replaceFParameter(index: Int, newFParameter: FParameter): Seed { return Seed( thisInstance.copy(), parameters.mapIndexed { ind, fParameter -> if (ind == index) newFParameter else fParameter.copy() }, - lineCoverage.toSet(), + instructionCoverage.toSet(), score ) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt index 3cf4481df2..6c57002766 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt @@ -1,31 +1,29 @@ package org.utbot.engine.greyboxfuzzer.mutator -import org.utbot.engine.greyboxfuzzer.util.getTrue -import kotlin.math.abs import kotlin.random.Random -class SeedCollector(private val maxSize: Int = 50, private val methodLines: Set) { +class SeedCollector(private val maxSize: Int = 50, private val methodInstructionsIds: Set) { private val seeds = ArrayList(maxSize) - fun calcSeedScore(coverage: Set): Double = - coverage.sumOf { line -> - val numOfSeedCoveredLine = seeds.count { it.lineCoverage.contains(line) } - if (numOfSeedCoveredLine == 0) { + fun calcSeedScore(coverage: Set): Double = + coverage.sumOf { instruction -> + val numOfSeedCoveredInstructions = seeds.count { it.instructionCoverage.contains(instruction) } + if (numOfSeedCoveredInstructions == 0) { Double.MAX_VALUE } else { - 1.0 / numOfSeedCoveredLine + 1.0 / numOfSeedCoveredInstructions } } private fun recalculateSeedScores() { seeds.forEach { seed -> - seed.score = calcSeedScore(seed.lineCoverage) + seed.score = calcSeedScore(seed.instructionCoverage) } } fun isSeedOpensNewCoverage(seed: Seed): Boolean { - val oldCoverage = seeds.flatMap { it.lineCoverage }.toSet() - return seed.lineCoverage.any { !oldCoverage.contains(it) } + val oldCoverage = seeds.flatMap { it.instructionCoverage }.toSet() + return seed.instructionCoverage.any { !oldCoverage.contains(it) } } fun addSeed(seed: Seed) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt index 719ef087ef..8b8efdcd85 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt @@ -1,9 +1,24 @@ package org.utbot.engine.greyboxfuzzer.util import org.utbot.framework.plugin.api.Instruction -import java.util.concurrent.CopyOnWriteArraySet +import java.util.concurrent.ConcurrentHashMap object CoverageCollector { - val coverage = CopyOnWriteArraySet() + private object Covered + private val coveredInstructions = ConcurrentHashMap() + val coverage: Set + get() = coveredInstructions.keys + + fun addCoverage(coverage: Set) { + this.coveredInstructions.putAll(coverage.map { it to Covered }) + } + + fun addCoverage(instruction: Instruction) { + this.coveredInstructions[instruction] = Covered + } + + fun clear() { + coveredInstructions.clear() + } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt index f5c85559ca..5dd531b86a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt @@ -1,54 +1,51 @@ package org.utbot.engine.greyboxfuzzer.util import org.utbot.engine.logger +import org.utbot.framework.concrete.UtFuzzingConcreteExecutionResult import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.api.UtExecution import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.signature +import org.utbot.framework.util.sootMethod import soot.Scene +import kotlin.io.path.appendText import kotlin.reflect.jvm.jvmName import kotlin.reflect.jvm.kotlinFunction object GreyBoxFuzzingStatisticPrinter { - fun printFuzzingStats(methods: List) { + fun printFuzzingStats(methods2executions: Map>) { // //Printing to console - val clazz = methods.first().classId - val sootClazz = Scene.v().classes.find { it.name == clazz.name }!! - val methodsToLineNumbers = sootClazz.methods.mapNotNull { sootMethod -> - val javaMethod = sootMethod.toJavaMethod() - if (javaMethod?.kotlinFunction != null) { - javaMethod to sootMethod.activeBody.units - .map { it.javaSourceStartLineNumber } - .filter { it != -1 } - .toSet() - } else { - null - } + val clazz = methods2executions.keys.first().classId + val methodsToInstructionsNumbers = methods2executions.entries.map { (method, executions) -> + val methodInstructions = + (executions.firstOrNull() as? UtGreyBoxFuzzedExecution)?.fuzzingResult?.methodInstructionsIds ?: setOf() + method to methodInstructions } logger.debug { "OVERALL RESULTS:" } logger.debug { "------------------------------------------" } - for ((method, lines) in methodsToLineNumbers) { + for ((method, instructions) in methodsToInstructionsNumbers) { val coveredMethodInstructions = CoverageCollector.coverage .filter { it.methodSignature == method.signature } - .map { it.lineNumber } + .map { it.id } .toSet() - .filter { it in lines } + .filter { it in instructions } logger.debug { "METHOD: ${method.name}" } - logger.debug { "COVERED: ${coveredMethodInstructions.size} from ${lines.size} ${coveredMethodInstructions.size.toDouble() / lines.size * 100}%" } + logger.debug { "COVERED: ${coveredMethodInstructions.size} from ${instructions.size} ${coveredMethodInstructions.size.toDouble() / instructions.size * 100}%" } logger.debug { "COVERED: ${coveredMethodInstructions.sorted()}" } - logger.debug { "NOT COVERED: ${lines.filter { it !in coveredMethodInstructions }.sorted()}" } + logger.debug { "NOT COVERED: ${instructions.filter { it !in coveredMethodInstructions }.sorted()}" } logger.debug { "------------------" } } logger.debug { "------------------------------------------" } - val allLinesToCover = methodsToLineNumbers.flatMap { it.second }.toSet() - val allLinesToCoverSize = allLinesToCover.size + val allInstructionsToCover = methodsToInstructionsNumbers.flatMap { it.second }.toSet() + val allInstructionsToCoverSize = allInstructionsToCover.size val allCoveredLines = CoverageCollector.coverage .filter { it.className.replace('/', '.') == clazz.name } - .map { it.lineNumber }.toSet() - .filter { it in allLinesToCover } + .map { it.id }.toSet() + .filter { it in allInstructionsToCover } .size - logger.debug { "FINALLY COVERED $allCoveredLines from $allLinesToCoverSize ${allCoveredLines.toDouble() / allLinesToCoverSize * 100}%" } + logger.debug { "FINALLY COVERED $allCoveredLines from $allInstructionsToCoverSize ${allCoveredLines.toDouble() / allInstructionsToCoverSize * 100}%" } logger.debug { "------------------------------------------" } } } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt index f2f25939ed..4891d32694 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt @@ -11,7 +11,6 @@ import ru.vyarus.java.generics.resolver.context.GenericsInfo import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl import java.lang.reflect.* -import java.lang.reflect.Array as RArray import kotlin.random.Random fun Class<*>.getAllDeclaredFields(): List { @@ -28,8 +27,9 @@ fun Class<*>.getAllDeclaredFields(): List { return res } -fun Class<*>.getAllDeclaredMethods(): List { - val res = mutableListOf() +fun Class<*>.getAllDeclaredMethodsAndConstructors(): List { + val res = mutableListOf() + res.addAll(declaredConstructors) var current: Class<*>? = this while (current != null) { res.addAll(current.declaredMethods) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt index 2ba92e75e9..c5f7a0169f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt @@ -12,6 +12,7 @@ import soot.jimple.internal.JAssignStmt import soot.jimple.internal.JCastExpr import soot.jimple.internal.JInstanceFieldRef import soot.jimple.internal.JInstanceOfExpr +import java.lang.reflect.Executable import java.lang.reflect.Field import java.lang.reflect.Method import kotlin.reflect.KFunction @@ -126,8 +127,8 @@ fun Method.toSootMethod(): SootMethod? { } } -fun SootMethod.toJavaMethod(): Method? = - declaringClass.toJavaClass()?.getAllDeclaredMethods()?.find { +fun SootMethod.toJavaMethod(): Executable? = + declaringClass.toJavaClass()?.getAllDeclaredMethodsAndConstructors()?.find { it.signature == this.bytecodeSignature.drop(1).dropLast(1).substringAfter("${declaringClass.name}: ") } @@ -181,7 +182,7 @@ object SootStaticsCollector { .filter { !it.toString().contains('$') } .toList() } - val javaMethodsToProvideInstance = sootMethodsToProvideInstance.mapNotNull { it.toJavaMethod() } + val javaMethodsToProvideInstance = sootMethodsToProvideInstance.mapNotNull { it.toJavaMethod() as? Method } classToStaticMethodsInstanceProviders[clazz] = javaMethodsToProvideInstance return javaMethodsToProvideInstance } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt index c5e7cc2c59..b312c3fd7e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt @@ -1,16 +1,17 @@ package org.utbot.engine.greyboxfuzzer.util +import org.utbot.framework.concrete.UtFuzzingConcreteExecutionResult import org.utbot.framework.plugin.api.* class UtGreyBoxFuzzedExecution( stateBefore: EnvironmentModels, - result: UtExecutionResult, + val fuzzingResult: UtFuzzingConcreteExecutionResult, stateAfter: EnvironmentModels = stateBefore, coverage: Coverage? = null, summary: List? = null, testMethodName: String? = null, displayName: String? = null -): UtExecution(stateBefore, stateAfter, result, coverage, summary, testMethodName, displayName) { +): UtExecution(stateBefore, stateAfter, fuzzingResult.result, coverage, summary, testMethodName, displayName) { override fun toString(): String = buildString { append("UtGreyBoxFuzzedExecution(") diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt index ebc78ea8e2..05fd15fcba 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt @@ -5,6 +5,8 @@ import org.utbot.common.WorkaroundReason import org.utbot.common.isStatic import org.utbot.common.workaround import org.utbot.engine.ArtificialError +import org.utbot.engine.OverflowDetectionError +import org.utbot.greyboxfuzzer.util.UtGreyBoxFuzzedExecution import org.utbot.framework.assemble.assemble import org.utbot.framework.codegen.domain.ForceStaticMocking import org.utbot.framework.codegen.domain.ParametrizedTestSource @@ -317,7 +319,9 @@ open class CgMethodConstructor(val context: CgContext) : CgContextOwner by conte } else { this.resultModel = resultModel val expected = variableConstructor.getOrCreateVariable(resultModel, "expected") - assertEquality(expected, actual) + if (currentExecution !is UtGreyBoxFuzzedExecution) { + assertEquality(expected, actual) + } } } .onFailure { exception -> processExecutionFailure(exception, executionResult) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt index e7247e98f8..7b20a293fe 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt @@ -232,7 +232,7 @@ open class TestCaseGenerator( forceStaticMockListener.detach(this, forceStaticMockListener) if (UtSettings.useGreyBoxFuzzing) { - GreyBoxFuzzingStatisticPrinter.printFuzzingStats(methods) + GreyBoxFuzzingStatisticPrinter.printFuzzingStats(method2executions) } return methods.map { method -> UtMethodTestSet( diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt index 12e672a995..f05c018a4a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt @@ -61,7 +61,7 @@ class TestFlow internal constructor(block: TestFlow.() -> Unit) { fun build(engine: UtBotSymbolicEngine): Flow { return when { generationTimeout == 0L -> emptyFlow() - isGreyBoxFuzzingEnabled -> engine.greyBoxFuzzing(System.currentTimeMillis() + generationTimeout) + isGreyBoxFuzzingEnabled -> engine.greyBoxFuzzing(generationTimeout) isFuzzingEnabled -> { when (val value = if (isSymbolicEngineEnabled) (fuzzingValue * generationTimeout).toLong() else generationTimeout) { 0L -> engine.traverse() diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt index 6676be0da4..d6a9b0a962 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt @@ -62,7 +62,7 @@ class ProcessingStorage { private val classMethodToId = mutableMapOf() private val idToClassMethod = mutableMapOf() - private val instructionsData = mutableMapOf() + val instructionsData = mutableMapOf() private val classToInstructionsCount = mutableMapOf() fun addClass(className: String): Int { @@ -220,6 +220,12 @@ class TraceHandler { return instructionsList!! } + fun getMethodInstructions(className: String, methodSignature: String) = + processingStorage.instructionsData.entries.filter { + val insClassName = processingStorage.computeClassNameAndLocalId(it.key).first + insClassName == className && it.value.methodSignature == methodSignature + } + fun computePutStatics(): List = computeInstructionList().map { it.instructionData } .filterIsInstance() diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt index 157ea89605..6ffd449bb6 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceListStrategy.kt @@ -10,7 +10,7 @@ import org.objectweb.asm.commons.LocalVariablesSorter class TraceListStrategy( private val className: String, - private val storage: ProcessingStorage, + val storage: ProcessingStorage, private val inserter: TraceInstructionBytecodeInserter ) : IInstructionVisitor { var currentLine: Int = 0 diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt index 609023835c..7ef51ea1b6 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt @@ -22,7 +22,8 @@ import kotlin.reflect.jvm.javaMethod class UtFuzzingConcreteExecutionResult( val result: UtExecutionResult, - val coverage: Coverage + val coverage: Coverage, + val methodInstructionsIds: Set ) {} @@ -95,17 +96,22 @@ object UtFuzzingExecutionInstrumentation : Instrumentation = mutableListOf() - override fun visitTypeInsn(opcode: Int, type: String?) { - if (opcode == NEW) { - val afterLabel = Label() - afterLabels.add(afterLabel) - val newLabel = Label() - - // if (callSiteCheck(type, class)) - push(type) - push(internalClassName) - invokeStatic(callSiteCheckerOwner, callSiteCheckerMethod) - ifZCmp(IFEQ, newLabel) - - // if (hasMock(null, type.)) - visitInsn(ACONST_NULL) - push("$type.") - invokeStatic(hasMockOwner, hasMockMethod) - ifZCmp(IFEQ, newLabel) - - // getMock(null, type.) - visitInsn(ACONST_NULL) - push("$type.") - invokeStatic(mockGetterOwner, mockGetterMethod) - visitTypeInsn(CHECKCAST, type) - goTo(afterLabel) - - // else - visitLabel(newLabel) - } - super.visitTypeInsn(opcode, type) - } +// override fun visitTypeInsn(opcode: Int, type: String?) { +// if (opcode == NEW) { +// val afterLabel = Label() +// afterLabels.add(afterLabel) +// val newLabel = Label() +// +// // if (callSiteCheck(type, class)) +// push(type) +// push(internalClassName) +// invokeStatic(callSiteCheckerOwner, callSiteCheckerMethod) +// ifZCmp(IFEQ, newLabel) +// +// // if (hasMock(null, type.)) +// visitInsn(ACONST_NULL) +// push("$type.") +// invokeStatic(hasMockOwner, hasMockMethod) +// ifZCmp(IFEQ, newLabel) +// +// // getMock(null, type.) +// visitInsn(ACONST_NULL) +// push("$type.") +// invokeStatic(mockGetterOwner, mockGetterMethod) +// visitTypeInsn(CHECKCAST, type) +// goTo(afterLabel) +// +// // else +// visitLabel(newLabel) +// } +// super.visitTypeInsn(opcode, type) +// } override fun visitMethodInsn( opcodeAndSource: Int, diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt index 3cf98d97ba..8e5f4f8167 100644 --- a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/Contest.kt @@ -147,15 +147,27 @@ fun main(args: Array) { val timeBudgetSec = cmd[2].toLong() val cut = ClassUnderTest(classLoader.loadClass(classUnderTestName).id, outputDir, classfileDir.toFile()) - runGeneration( - project = "Contest", - cut, - timeBudgetSec, - fuzzingRatio = 0.1, - classpathString, - runFromEstimator = false, - methodNameFilter = null - ) + if (UtSettings.useGreyBoxFuzzing) { + GreyBoxFuzzerContest().runGeneration( + project = "GreyBoxFuzzingContest", + cut, + timeBudgetSec, + fuzzingRatio = 0.1, + classpathString, + runFromEstimator = false, + methodNameFilter = null + ) + } else { + runGeneration( + project = "Contest", + cut, + timeBudgetSec, + fuzzingRatio = 0.1, + classpathString, + runFromEstimator = false, + methodNameFilter = null + ) + } println("${ContestMessage.READY}") } } @@ -165,7 +177,6 @@ fun main(args: Array) { fun setOptions() { Settings.defaultConcreteExecutorPoolSize = 1 UtSettings.useFuzzing = true - UtSettings.useGreyBoxFuzzing = false UtSettings.classfilesCanChange = false // We need to use assemble model generator to increase readability UtSettings.useAssembleModelGenerator = true @@ -267,7 +278,7 @@ fun runGeneration( val methodJob = currentCoroutineContext().job logger.debug { " ... " } - val statsForMethod = StatsForMethod("${method.classId.simpleName}#${method.name}") + val statsForMethod = StatsForMethod("${method.classId.simpleName}#${method.name}#${method.signature}", Type.getInternalName(method.classId.jClass)) statsForClass.statsForMethods.add(statsForMethod) @@ -416,7 +427,7 @@ fun runGeneration( statsForClass } -private fun prepareClass(javaClazz: Class<*>, methodNameFilter: String?): List { +internal fun prepareClass(javaClazz: Class<*>, methodNameFilter: String?): List { //1. all methods from cut val methods = javaClazz.declaredMethods .filterNot { it.isAbstract } @@ -494,7 +505,7 @@ internal val Method.isVisibleFromGeneratedTest: Boolean get() = (this.modifiers and Modifier.ABSTRACT) == 0 && (this.modifiers and Modifier.NATIVE) == 0 -private fun StatsForClass.updateCoverage(newCoverage: Coverage, isNewClass: Boolean, fromFuzzing: Boolean) { +internal fun StatsForClass.updateCoverage(newCoverage: Coverage, isNewClass: Boolean, fromFuzzing: Boolean) { coverage.update(newCoverage, isNewClass) // other coverage type updates by empty coverage to respect new class val emptyCoverage = newCoverage.copy( diff --git a/utbot-junit-contest/src/main/kotlin/org/utbot/contest/GreyBoxFuzzerContest.kt b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/GreyBoxFuzzerContest.kt new file mode 100644 index 0000000000..514fb30c1a --- /dev/null +++ b/utbot-junit-contest/src/main/kotlin/org/utbot/contest/GreyBoxFuzzerContest.kt @@ -0,0 +1,186 @@ +package org.utbot.contest + +import mu.KotlinLogging +import org.objectweb.asm.Type +import org.utbot.common.FileUtil +import org.utbot.common.bracket +import org.utbot.common.filterWhen +import org.utbot.common.info +import org.utbot.common.isAbstract +import org.utbot.engine.EngineController +import org.utbot.framework.TestSelectionStrategyType +import org.utbot.framework.UtSettings +import org.utbot.framework.codegen.domain.ForceStaticMocking +import org.utbot.framework.codegen.domain.StaticsMocking +import org.utbot.framework.codegen.domain.junitByVersion +import org.utbot.framework.codegen.CodeGenerator +import org.utbot.framework.plugin.api.util.UtContext +import org.utbot.framework.plugin.api.util.executableId +import org.utbot.framework.plugin.api.util.id +import org.utbot.framework.plugin.api.util.jClass +import org.utbot.framework.plugin.api.util.utContext +import org.utbot.framework.plugin.api.util.withUtContext +import org.utbot.framework.plugin.services.JdkInfoService +import org.utbot.framework.util.isKnownImplicitlyDeclaredMethod +import org.utbot.fuzzer.UtFuzzedExecution +import org.utbot.instrumentation.ConcreteExecutor +import org.utbot.instrumentation.ConcreteExecutorPool +import org.utbot.instrumentation.Settings +import org.utbot.instrumentation.warmup.Warmup +import java.io.File +import java.lang.reflect.Method +import java.lang.reflect.Modifier +import java.net.URL +import java.net.URLClassLoader +import java.nio.file.Paths +import kotlin.concurrent.thread +import kotlin.math.max +import kotlin.math.min +import kotlin.reflect.KCallable +import kotlin.reflect.jvm.isAccessible +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.ObsoleteCoroutinesApi +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.currentCoroutineContext +import kotlinx.coroutines.delay +import kotlinx.coroutines.isActive +import kotlinx.coroutines.job +import kotlinx.coroutines.launch +import kotlinx.coroutines.newSingleThreadContext +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withTimeoutOrNull +import kotlinx.coroutines.yield +import org.utbot.engine.Mocker +import org.utbot.engine.greyboxfuzzer.util.CoverageCollector +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.isSynthetic +import java.util.concurrent.atomic.AtomicInteger +import kotlin.io.path.appendText + + +class GreyBoxFuzzerContest { + + private val logger = KotlinLogging.logger {} + + @ObsoleteCoroutinesApi + @SuppressWarnings + fun runGeneration( + project: String, + cut: ClassUnderTest, + timeLimitSec: Long, + fuzzingRatio: Double, + classpathString: String, + runFromEstimator: Boolean, + methodNameFilter: String? = null // For debug purposes you can specify method name + ): StatsForClass = runBlocking { + CoverageCollector.clear() + val timeBudgetMs = timeLimitSec * 1000 + val generationTimeout: Long = + timeBudgetMs - timeBudgetMs * 15 / 100 // 4000 ms for terminate all activities and finalize code in file + + logger.debug { "-----------------------------------------------------------------------------" } + logger.info( + "Contest.runGeneration: Time budget: $timeBudgetMs ms, Generation timeout=$generationTimeout ms, " + + "classpath=$classpathString, methodNameFilter=$methodNameFilter" + ) + + if (runFromEstimator) { + setOptions() + //will not be executed in real contest + logger.info() + .bracket("warmup: 1st optional soot initialization and executor warmup (not to be counted in time budget)") { + TestCaseGenerator( + listOf(cut.classfileDir.toPath()), + classpathString, + dependencyPath, + JdkInfoService.provide() + ) + } + logger.info().bracket("warmup (first): kotlin reflection :: init") { + prepareClass(ConcreteExecutorPool::class.java, "") + prepareClass(Warmup::class.java, "") + } + } + + logger.info("$cut") + + if (cut.classLoader.javaClass != URLClassLoader::class.java) { + logger.error("Seems like classloader for cut not valid (maybe it was backported to system): ${cut.classLoader}") + } + + val statsForClass = StatsForClass(project, cut.fqn) + + val codeGenerator = CodeGenerator( + cut.classId, + testFramework = junitByVersion(junitVersion), + staticsMocking = staticsMocking, + forceStaticMocking = forceStaticMocking, + generateWarningsForStaticMocking = false + ) + + logger.info().bracket("class ${cut.fqn}", { statsForClass }) { + + val filteredMethods = logger.info().bracket("preparation class ${cut.clazz}: kotlin reflection :: run") { + prepareClass(cut.clazz, methodNameFilter) + } + + statsForClass.methodsCount = filteredMethods.size + + // nothing to process further + if (filteredMethods.isEmpty()) return@runBlocking statsForClass + + val testCaseGenerator = + logger.info().bracket("2nd optional soot initialization") { + TestCaseGenerator( + listOf(cut.classfileDir.toPath()), + classpathString, + dependencyPath, + JdkInfoService.provide() + ) + } + + val testSet = testCaseGenerator.generate( + filteredMethods, + MockStrategyApi.NO_MOCKS, + methodsGenerationTimeout = generationTimeout + ) + + var testsCounter = 0 + for (test in testSet) { + val method = test.method + val statsForMethod = StatsForMethod( + "${method.classId.simpleName}#${method.name}#${method.signature}", + Type.getInternalName(method.classId.jClass) + ) + statsForClass.statsForMethods.add(statsForMethod) + for (result in test.executions) { + try { + val testMethodName = testMethodName(method.toString(), ++testsCounter) + val className = Type.getInternalName(method.classId.jClass) + logger.debug { "--new testCase collected, to generate: $testMethodName" } + statsForMethod.testsGeneratedCount++ + result.coverage?.let { + statsForClass.updateCoverage( + newCoverage = it, + isNewClass = !statsForClass.testedClassNames.contains(className), + fromFuzzing = result is UtFuzzedExecution + ) + } + statsForClass.testedClassNames.add(className) + } catch (e: Throwable) { + //Here we need isolation + logger.error(e) { "Code generation failed" } + } + } + } + + logger.info().bracket("Flushing tests for [${cut.simpleName}] on disk") { + writeTestClass(cut, codeGenerator.generateAsString(testSet)) + } + } + statsForClass + } + +} \ No newline at end of file diff --git a/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt b/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt index 8a5a1ff902..9a42bae1d7 100644 --- a/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt +++ b/utbot-summary/src/main/kotlin/org/utbot/summary/TagGenerator.kt @@ -12,7 +12,6 @@ import org.utbot.framework.plugin.api.UtOverflowFailure import org.utbot.framework.plugin.api.UtSandboxFailure import org.utbot.framework.plugin.api.UtStreamConsumingFailure import org.utbot.framework.plugin.api.UtSymbolicExecution -import org.utbot.framework.plugin.api.UtExecutionSuccessConcrete import org.utbot.framework.plugin.api.UtTimeoutException import org.utbot.framework.plugin.api.util.humanReadableName import org.utbot.framework.plugin.api.util.isCheckedException @@ -221,7 +220,6 @@ private fun UtExecutionResult.clusterKind() = when (this) { is UtTimeoutException -> ExecutionGroup.TIMEOUTS is UtConcreteExecutionFailure -> ExecutionGroup.CRASH_SUITE is UtSandboxFailure -> ExecutionGroup.SECURITY - is UtExecutionSuccessConcrete -> ExecutionGroup.SUCCESSFUL_EXECUTIONS } /** From 3a86fd6fa93fe85515c8b6ffa94429ad5b74986e Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Mon, 19 Dec 2022 16:49:37 +0300 Subject: [PATCH 17/30] merge --- .../generator/ThisInstanceGenerator.kt | 18 ------------------ .../StaticsFieldBasedInstanceGenerator.kt | 2 +- .../quickcheck/generator/GeneratorContext.kt | 2 +- .../engine/greyboxfuzzer/util/UtBotUtils.kt | 2 +- .../greyboxfuzzer/util/UtModelGenerator.kt | 16 ---------------- .../execution/BigNumberConstructor.kt | 3 +++ .../execution/BitSetConstructor.kt | 3 +++ .../execution/DateTimeConstructors.kt | 3 +++ .../execution/LocaleConstructor.kt | 3 +++ .../execution/UUIDConstructor.kt | 3 +++ .../UtFuzzingExecutionInstrumentation.kt | 5 ++++- .../UtAssembleModelConstructors.kt | 1 + 12 files changed, 23 insertions(+), 38 deletions(-) delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/ThisInstanceGenerator.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/ThisInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/ThisInstanceGenerator.kt deleted file mode 100644 index 4a518716d9..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/ThisInstanceGenerator.kt +++ /dev/null @@ -1,18 +0,0 @@ -package org.utbot.engine.greyboxfuzzer.generator - -import org.utbot.external.api.classIdForType -import org.utbot.framework.concrete.UtModelConstructor -import org.utbot.framework.plugin.api.UtModel -import java.util.* - -//object ThisInstanceGenerator { -// -// var utModelThisInstance: UtModel? = null -// -// fun generateThis(clazz: Class<*>) { -// utModelThisInstance = InstancesGenerator.generateInstanceWithUnsafe(clazz, 0, true, null)?.let { -// UtModelConstructor(IdentityHashMap()).construct(it, classIdForType(clazz)) -// } -// } -// -//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt index 26010c200b..7637cb0b7c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt @@ -5,7 +5,7 @@ import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.engine.greyboxfuzzer.util.hasModifiers import org.utbot.engine.greyboxfuzzer.util.toClass import org.utbot.external.api.classIdForType -import org.utbot.framework.concrete.UtModelConstructor +import org.utbot.framework.concrete.constructors.UtModelConstructor import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* import ru.vyarus.java.generics.resolver.context.GenericsContext diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt index bb772dae50..ace7687638 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt @@ -1,6 +1,6 @@ package org.utbot.engine.greyboxfuzzer.quickcheck.generator -import org.utbot.framework.concrete.UtModelConstructor +import org.utbot.framework.concrete.constructors.UtModelConstructor import java.util.* data class GeneratorContext( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt index 0b5928451d..231fdf19ad 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt @@ -3,7 +3,7 @@ package org.utbot.engine.greyboxfuzzer.util import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext import org.utbot.engine.greyboxfuzzer.generator.* import org.utbot.external.api.classIdForType -import org.utbot.framework.concrete.UtModelConstructor +import org.utbot.framework.concrete.constructors.UtModelConstructor import org.utbot.framework.plugin.api.* import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import java.lang.reflect.Method diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt deleted file mode 100644 index 409e5e2c43..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtModelGenerator.kt +++ /dev/null @@ -1,16 +0,0 @@ -package org.utbot.engine.greyboxfuzzer.util - -import org.utbot.framework.concrete.UtModelConstructor -import org.utbot.framework.plugin.api.UtModel -import java.util.* - -//object UtModelGenerator { -// -// @JvmStatic -// var utModelConstructor = UtModelConstructor(IdentityHashMap()) -// -// fun reset() { -// utModelConstructor = UtModelConstructor(IdentityHashMap()) -// } -// -//} \ No newline at end of file diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BigNumberConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BigNumberConstructor.kt index 8b6a6318f0..1735b2b468 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BigNumberConstructor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BigNumberConstructor.kt @@ -1,5 +1,8 @@ package org.utbot.framework.concrete +import org.utbot.framework.concrete.constructors.UtAssembleModelConstructorBase +import org.utbot.framework.concrete.constructors.UtModelConstructorInterface +import org.utbot.framework.concrete.constructors.checkClassCast import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BitSetConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BitSetConstructor.kt index d1c7327f7a..d1360f6728 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BitSetConstructor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/BitSetConstructor.kt @@ -1,5 +1,8 @@ package org.utbot.framework.concrete +import org.utbot.framework.concrete.constructors.UtAssembleModelConstructorBase +import org.utbot.framework.concrete.constructors.UtModelConstructorInterface +import org.utbot.framework.concrete.constructors.checkClassCast import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/DateTimeConstructors.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/DateTimeConstructors.kt index a28a678264..588ae22435 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/DateTimeConstructors.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/DateTimeConstructors.kt @@ -1,5 +1,8 @@ package org.utbot.framework.concrete +import org.utbot.framework.concrete.constructors.UtAssembleModelConstructorBase +import org.utbot.framework.concrete.constructors.UtModelConstructorInterface +import org.utbot.framework.concrete.constructors.checkClassCast import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/LocaleConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/LocaleConstructor.kt index debee9aa67..fd5a38ae40 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/LocaleConstructor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/LocaleConstructor.kt @@ -1,5 +1,8 @@ package org.utbot.framework.concrete +import org.utbot.framework.concrete.constructors.UtAssembleModelConstructorBase +import org.utbot.framework.concrete.constructors.UtModelConstructorInterface +import org.utbot.framework.concrete.constructors.checkClassCast import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UUIDConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UUIDConstructor.kt index c97058e748..d21962a44d 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UUIDConstructor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UUIDConstructor.kt @@ -1,5 +1,8 @@ package org.utbot.framework.concrete +import org.utbot.framework.concrete.constructors.UtAssembleModelConstructorBase +import org.utbot.framework.concrete.constructors.UtModelConstructorInterface +import org.utbot.framework.concrete.constructors.checkClassCast import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt index 7ef51ea1b6..c078c533ce 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt @@ -4,7 +4,10 @@ import org.objectweb.asm.Type import org.utbot.common.StopWatch import org.utbot.common.ThreadBasedExecutor import org.utbot.common.withAccessibility -import org.utbot.framework.assemble.AssembleModelGenerator +import org.utbot.framework.concrete.constructors.ConstructOnlyUserClassesOrCachedObjectsStrategy +import org.utbot.framework.concrete.constructors.MockValueConstructor +import org.utbot.framework.concrete.constructors.UtModelConstructor +import org.utbot.framework.concrete.mock.InstrumentationContext import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* import org.utbot.framework.util.isInaccessibleViaReflection diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtAssembleModelConstructors.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtAssembleModelConstructors.kt index 2850cf5632..d758d1ac81 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtAssembleModelConstructors.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/UtAssembleModelConstructors.kt @@ -1,5 +1,6 @@ package org.utbot.instrumentation.instrumentation.execution.constructors +import org.utbot.framework.concrete.* import java.util.stream.BaseStream import java.util.stream.DoubleStream import java.util.stream.IntStream From 1de5db528ee07e5f92a25e931715a614f39a4afb Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Mon, 19 Dec 2022 19:35:16 +0300 Subject: [PATCH 18/30] constants collector --- .../src/main/java/org/utbot/examples/A.java | 67 +++ .../src/main/java/org/utbot/examples/B.java | 30 ++ .../java/org/utbot/examples/ByteVector.java | 203 +++++++ .../src/main/java/org/utbot/examples/C.java | 7 + .../org/utbot/examples/CalendarLogic.java | 42 ++ .../src/main/java/org/utbot/examples/D.java | 4 + .../main/java/org/utbot/examples/GrAlh.java | 5 + .../main/java/org/utbot/examples/Graph.java | 70 +++ .../org/utbot/examples/GraphAlgorithms.java | 260 +++++++++ .../src/main/java/org/utbot/examples/H.java | 32 ++ .../src/main/java/org/utbot/examples/I.java | 5 + .../src/main/java/org/utbot/examples/I1.java | 10 + .../src/main/java/org/utbot/examples/I2.java | 8 + .../src/main/java/org/utbot/examples/L.java | 9 + .../java/org/utbot/examples/ListImpl.java | 131 +++++ .../org/utbot/examples/PrimitiveFields.java | 21 + .../engine/greyboxfuzzer/FuzzerExecutor.kt | 311 +++++++++++ .../engine/greyboxfuzzer/GreyBoxFuzzer.kt | 3 +- .../greyboxfuzzer/coverage/GlobalCoverage.kt | 11 + .../quickcheck/generator/Generator.kt | 39 +- .../quickcheck/generator/GeneratorContext.kt | 5 +- .../greyboxfuzzer/util/CustomClassLoader.kt | 4 +- .../engine/greyboxfuzzer/util/KotlinUtils.kt | 16 + .../engine/greyboxfuzzer/util/SootUtils.kt | 48 +- .../plugin/api/UtBotTestCaseGenerator.kt | 495 ++++++++++++++++++ utbot-framework/src/main/resources/log4j2.xml | 23 + 26 files changed, 1847 insertions(+), 12 deletions(-) create mode 100644 utbot-framework/src/main/java/org/utbot/examples/A.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/B.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/ByteVector.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/C.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/CalendarLogic.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/D.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/GrAlh.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/Graph.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/GraphAlgorithms.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/H.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/I.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/I1.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/I2.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/L.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/ListImpl.java create mode 100644 utbot-framework/src/main/java/org/utbot/examples/PrimitiveFields.java create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/FuzzerExecutor.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/coverage/GlobalCoverage.kt create mode 100644 utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/UtBotTestCaseGenerator.kt create mode 100644 utbot-framework/src/main/resources/log4j2.xml diff --git a/utbot-framework/src/main/java/org/utbot/examples/A.java b/utbot-framework/src/main/java/org/utbot/examples/A.java new file mode 100644 index 0000000000..89c4a80e00 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/A.java @@ -0,0 +1,67 @@ +package org.utbot.examples; + +import java.lang.reflect.Field; + +class A { + + public C c = new C(); + + public int getCLol3() { + return c.h.lol3(); + } +// public A(int a, R at) { +// this.a = a; +// this.at = at; +// } + +// public class Lil { +// int a = 1; +// +// Lil(int a) { +// this.a = a; +// } +// } + +// int a = 1; +// int c; +// R at; +// final int b = 1; + +// public static A produceA(int a, Number b) { +// return new A(777, b); +// } + //public static A aInstance = new A(777, 13.0); + +// public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException { +// Field f = A.class.getField("aInstance"); +// System.out.println(f.get(null)); +// } + + //public int lol(R a, ArrayList arr); +// public static A getInstance1(R a, ArrayList arr) { +// return new B(a, 777, arr); +// } + + + // public static final A numberA = new A(1, 3L, null); +// public static final A intA = new A(1, 2, null); +// public static final A strA = new A(1, "a", null); +// +// public static A getInstance() { +// return new A(1, null, null); +// } + + //public static A getIntegerInstance() { +// return new A(1, 3); +// } +// public static A getIntegerInstance(Integer a, B bInstance) { +// return new A(a, 3, bInstance); +// } + + // private A() {} +// public A(int a, R ba, R e, B bInstance) { +// this.e = e; +// this.a = a; +// this.bInstance = bInstance; +// } +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/B.java b/utbot-framework/src/main/java/org/utbot/examples/B.java new file mode 100644 index 0000000000..9914498ab6 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/B.java @@ -0,0 +1,30 @@ +package org.utbot.examples; + +public class B { + + R[] arr; +// int a; +// String b; +// +// public B(int a, String b) { +// this.a = a; +// this.b = b; +// } +} +//public class B implements A { +// +// public T a; +// public int b; +// public ArrayList c; +// +// public B(T a, int b, ArrayList c) { +// this.a = a; +// this.b = b; +// this.c = c; +// } +// +// @Override +// public int lol(T a, ArrayList arr) { +// return 0; +// } +//} diff --git a/utbot-framework/src/main/java/org/utbot/examples/ByteVector.java b/utbot-framework/src/main/java/org/utbot/examples/ByteVector.java new file mode 100644 index 0000000000..040246ef77 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/ByteVector.java @@ -0,0 +1,203 @@ +package org.utbot.examples; + +/** + * A dynamically extensible vector of bytes. This class is roughly equivalent to + * a DataOutputStream on top of a ByteArrayOutputStream, but is more efficient. + * + * @author Eric Bruneton + */ +public class ByteVector { + + /** + * The content of this vector. + */ + public byte[] data; + + /** + * Actual number of bytes in this vector. + */ + public int length; + + /** + * Constructs a new {@link ByteVector ByteVector} with a default initial size. + */ + public ByteVector() { + data = new byte[64]; + } + + /** + * Constructs a new {@link ByteVector ByteVector} with the given initial size. + * + * @param initialSize the initial size of the byte vector to be constructed. + */ + public ByteVector(final int initialSize) { + data = new byte[initialSize]; + } + + /** + * Puts a byte into this byte vector. The byte vector is automatically enlarged + * if necessary. + * + * @param b a byte. + * @return this byte vector. + */ + public ByteVector putByte(final int b) { + int length = this.length; + if (length + 1 > data.length) { + enlarge(1); + } + data[length++] = (byte) b; + this.length = length; + return this; + } + + /** + * Puts two bytes into this byte vector. The byte vector is automatically + * enlarged if necessary. + * + * @param b1 a byte. + * @param b2 another byte. + * @return this byte vector. + */ + ByteVector put11(final int b1, final int b2) { + int length = this.length; + if (length + 2 > data.length) { + enlarge(2); + } + final byte[] data = this.data; + data[length++] = (byte) b1; + data[length++] = (byte) b2; + this.length = length; + return this; + } + + /** + * Puts a short into this byte vector. The byte vector is automatically enlarged + * if necessary. + * + * @param s a short. + * @return this byte vector. + */ + public ByteVector putShort(final int s) { + int length = this.length; + if (length + 2 > data.length) { + enlarge(2); + } + final byte[] data = this.data; + data[length++] = (byte) (s >>> 8); + data[length++] = (byte) s; + this.length = length; + return this; + } + + /** + * Puts a byte and a short into this byte vector. The byte vector is + * automatically enlarged if necessary. + * + * @param b a byte. + * @param s a short. + * @return this byte vector. + */ + public ByteVector put12(final int b, final int s) { + int length = this.length; + if (length + 3 > data.length) { + enlarge(3); + } + final byte[] data = this.data; + data[length++] = (byte) b; + data[length++] = (byte) (s >>> 8); + data[length++] = (byte) s; + this.length = length; + return this; + } + + /** + * Puts an int into this byte vector. The byte vector is automatically enlarged + * if necessary. + * + * @param i an int. + * @return this byte vector. + */ + public ByteVector putInt(final int i) { + int length = this.length; + if (length + 4 > data.length) { + enlarge(4); + } + final byte[] data = this.data; + data[length++] = (byte) (i >>> 24); + data[length++] = (byte) (i >>> 16); + data[length++] = (byte) (i >>> 8); + data[length++] = (byte) i; + this.length = length; + return this; + } + + /** + * Puts an UTF8 string into this byte vector. The byte vector is automatically + * enlarged if necessary. + * + * @param s a String. + * @return this byte vector. + */ + public ByteVector putUTF8(final String s) { + final int charLength = s.length(); + int len = length; + if (len + 2 + charLength > data.length) { + enlarge(2 + charLength); + } + final byte[] data = this.data; + // optimistic algorithm: instead of computing the byte length and then + // serializing the string (which requires two loops), we assume the byte + // length is equal to char length (which is the most frequent case), and + // we start serializing the string right away. During the serialization, + // if we find that this assumption is wrong, we continue with the + // general method. + data[len++] = (byte) (charLength >>> 8); + data[len++] = (byte) charLength; + for (int i = 0; i < charLength; ++i) { + final char c = s.charAt(i); + if ((c >= '\001' && c <= '\177') || (c >= '\u4E00' && c <= '\u9FFF')) { + data[len++] = (byte) c; + } else { + throw new UnsupportedOperationException(); + } + } + length = len; + return this; + } + + /** + * Puts an array of bytes into this byte vector. The byte vector is + * automatically enlarged if necessary. + * + * @param b an array of bytes. May be null to put len null + * bytes into this byte vector. + * @param off index of the fist byte of b that must be copied. + * @param len number of bytes of b that must be copied. + * @return this byte vector. + */ + public ByteVector putByteArray(final byte[] b, final int off, final int len) { + if (length + len > data.length) { + enlarge(len); + } + if (b != null) { + System.arraycopy(b, off, data, length, len); + } + length += len; + return this; + } + + /** + * Enlarge this byte vector so that it can receive n more bytes. + * + * @param size number of additional bytes that this byte vector should be able + * to receive. + */ + private void enlarge(final int size) { + final int length1 = 2 * data.length; + final int length2 = length + size; + final byte[] newData = new byte[length1 > length2 ? length1 : length2]; + System.arraycopy(data, 0, newData, 0, length); + data = newData; + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/java/org/utbot/examples/C.java b/utbot-framework/src/main/java/org/utbot/examples/C.java new file mode 100644 index 0000000000..d6845998d0 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/C.java @@ -0,0 +1,7 @@ +package org.utbot.examples; + +public class C { + + H h = new H(); + +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/CalendarLogic.java b/utbot-framework/src/main/java/org/utbot/examples/CalendarLogic.java new file mode 100644 index 0000000000..a7abda2fcd --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/CalendarLogic.java @@ -0,0 +1,42 @@ +package org.utbot.examples; + +import java.util.GregorianCalendar; + +import static java.util.Calendar.*; + +/* Application logic */ +public class CalendarLogic { + // Returns true iff cal is in a leap year + public static boolean isLeapYear(GregorianCalendar cal) { + int year = cal.get(YEAR); + if (year % 4 == 0) { + return year % 100 != 0; + } + return false; + } + + // Returns either of -1, 0, 1 depending on whether c1 is <, =, > than c2 + public static int compare(GregorianCalendar c1, GregorianCalendar c2) { + int cmp; + cmp = Integer.compare(c1.get(YEAR), c2.get(YEAR)); + if (cmp == 0) { + cmp = Integer.compare(c1.get(MONTH), c2.get(MONTH)); + if (cmp == 0) { + cmp = Integer.compare(c1.get(DAY_OF_MONTH), c2.get(DAY_OF_MONTH)); + if (cmp == 0) { + cmp = Integer.compare(c1.get(HOUR), c2.get(HOUR)); + if (cmp == 0) { + cmp = Integer.compare(c1.get(MINUTE), c2.get(MINUTE)); + if (cmp == 0) { + cmp = Integer.compare(c1.get(SECOND), c2.get(SECOND)); + if (cmp == 0) { + cmp = Integer.compare(c1.get(MILLISECOND), c2.get(MILLISECOND)); + } + } + } + } + } + } + return cmp; + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/java/org/utbot/examples/D.java b/utbot-framework/src/main/java/org/utbot/examples/D.java new file mode 100644 index 0000000000..b345d3faf6 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/D.java @@ -0,0 +1,4 @@ +package org.utbot.examples; + +public interface D { +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/GrAlh.java b/utbot-framework/src/main/java/org/utbot/examples/GrAlh.java new file mode 100644 index 0000000000..b00d489eac --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/GrAlh.java @@ -0,0 +1,5 @@ +package org.utbot.examples; + +public class GrAlh { + int a = 1; +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/Graph.java b/utbot-framework/src/main/java/org/utbot/examples/Graph.java new file mode 100644 index 0000000000..c829460d09 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/Graph.java @@ -0,0 +1,70 @@ +package org.utbot.examples; + +import java.util.Arrays; + +public class Graph { + private int size; + private int[][] adj; + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } + + public int[][] getAdj() { + return adj; + } + + public void setAdj(int[][] adj) { + this.adj = adj; + } + + public int[] getChildrenOf(int node) { + if (node < 0 && node >= size) { + throw new IllegalArgumentException("Number of node out of bounds"); + } + return Arrays.stream(adj[node]).filter(i -> i != 0).toArray(); + } + + private boolean isCyclic(int i, boolean[] visited, boolean[] recStack) { + if (recStack[i]) + return true; + + if (visited[i]) + return false; + + visited[i] = true; + + recStack[i] = true; + int[] children = adj[i]; + + for (Integer c : children) + if (c == 1) { + if (isCyclic(c, visited, recStack)) { + return true; + } + } + + recStack[i] = false; + + return false; + } + + public void addEdge(int source, int dest) { + adj[source][dest] = 1; + } + + public boolean isCyclic() { + boolean[] visited = new boolean[size]; + boolean[] recStack = new boolean[size]; + + for (int i = 0; i < size; i++) + if (isCyclic(i, visited, recStack)) + return true; + + return false; + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/java/org/utbot/examples/GraphAlgorithms.java b/utbot-framework/src/main/java/org/utbot/examples/GraphAlgorithms.java new file mode 100644 index 0000000000..f2bc4860e3 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/GraphAlgorithms.java @@ -0,0 +1,260 @@ +package org.utbot.examples; + +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.util.*; + +public class GraphAlgorithms { +// public GraphAlgorithms(T lol) { +// this.lol = lol; +// } + + private class GraphAlgorithms1 { + T a; + R b; + int c; + + GraphAlgorithms1(T a, R b, int c) { + this.a = a; + this.b = b; + this.c = c; + } + } + public static GraphAlgorithms GRAPH = new GraphAlgorithms(1, null); + public GraphAlgorithms(int a, T lol) { + this.a = a; + this.lol = lol; + } + int a; + public T lol; + + int[] array = {1, 2, 3}; +// ArrayList arr2; + +// public boolean bfs(Graph graph, int startNodeNumber, int goalNodeNumber) { +// Deque queue = new LinkedList<>();//(graph.getSize()); +// boolean[] visited = new boolean[graph.getSize()]; +// queue.push(startNodeNumber); +// visited[startNodeNumber] = true; +// while (!queue.isEmpty()) { +// int curNodeNumber = queue.pop(); +// if (curNodeNumber == goalNodeNumber) return true; +// for (int child : graph.getChildrenOf(curNodeNumber)) { +// if (!visited[child]) { +// queue.push(child); +// visited[child] = true; +// } +// } +// } +// return true; +// } +// +// public boolean testFunc(ArrayList> array) { +// for (int i = 0; i < array.size() - 1; i++) { +// if (array.get(i).get(i) > array.get(i + 1).get(i + 1)) { +// return true; +// } +// } +// return false; +// } +// +// public boolean testFunc1(ArrayList array) { +// for (int i = 0; i < array.size() - 1; i++) { +// if (array.get(i) > array.get(i + 1)) { +// return true; +// } +// } +// return false; +// } +// +// public boolean testFunc2(long[] array) { +// for (int i = 0; i < array.length - 1; i++) { +// if (array[i] > array[i + 1]) { +// return true; +// } +// } +// return false; +// } + + +// public Object testFunc3(ArrayList> a) { +// if (a.get(0) == null) { +// return null; +// } +// return a.get(a.size() - 1); +// } + +// public static Number testFunc3(Map>, T[]> arr) { +// return arr.entrySet().iterator().next().getKey().get(0).arr[0]; +// } + + public static int testFunc3(int[] matrix, String s) { + if (matrix[0] == 0) { + if (matrix[1] == 1) { + if (matrix[2] == 2 && s.equals("lol")) { + return 123; + } + } + } + return matrix[0]; + } + + + public static void test(String s) { + if (s.charAt(0) == "b".charAt(0)) { + if (s.charAt(1) == "a".charAt(0)) { + if (s.charAt(2) == "d".charAt(0)) { + if (s.charAt(3) == "!".charAt(0)) { + throw new IllegalArgumentException(); + } + } + } + } + } + + // should try to find the string with size 6 and with "!" in the end + public static void testStrRem(String str) { + if (!"world???".equals(str) && str.charAt(5) == '!' && str.length() == 6) { + throw new RuntimeException(); + } + } + + + public static int floatToInt(float x) { + if (x < 0) { + if ((int) x < 0) { + return 1; + } + return 2; // smth small to int zero + } + return 3; + } + + // should find all branches that return -2, -1, 0, 1, 2. + public static int numberOfRootsInSquareFunction(double a, double b, double c) { + if (!Double.isFinite(a) || !Double.isFinite(b) || !Double.isFinite(c)) return -1; + if (a == 0.0 || b == 0.0 || c == 0.0) return -2; + double result = b * b - 4 * a * c; + if (result > 0) { + return 2; + } else if (result == 0) { + return 1; + } + return 0; + } + + // will never be succeeded to find the value because of floating precision + public static void floatEq(float v) { + if (v == 28.7) { + throw new IllegalArgumentException(); + } + } + + // should generate double for constant float that equals to 28.700000762939453 + public static void floatEq(double v) { + if (v == 28.7f) { + throw new IllegalArgumentException(); + } + } + + public static void diff(int a) { + a = Math.abs(a); + while (a > 0) { + a = a % 2; + } + if (a < 0) { + throw new IllegalArgumentException(); + } + throw new RuntimeException(); + } + + // should cover 100% and better when values are close to constants, + // also should generate "this" empty object + public static String extent(int a) { + if (a < -2.0) { + return "-1"; + } + if (a > 5) { + return "-2"; + } + if (a == 3) { + return "-3"; + } + if (4L < a) { + return "-4"; + } + return "0"; + } + + // should cover 100% with 3 tests + public static boolean isGreater(long a, short b, int c) { + if (b > a && a < c) { + return true; + } + return false; + } + + // should find a bad value with integer overflow + public static boolean unreachable(int x) { + int y = x * x - 2 * x + 1; + if (y < 0) throw new IllegalArgumentException(); + return true; + } + + public static boolean chars(char a) { + if (a >= 'a' && a <= 'z') { + return true; + } + return false; + } + + + +// fun propagateHandshakes(friends: Map>): Map> { +// val b = mutableMapOf>() +// val c = mutableSetOf() +// for (j in friends.values) c += j +// for ((i, j) in friends) +// for (k in j) { +// b.getOrPut(i, ::mutableSetOf).add(k) +// friends[k]?.let { b[i]?.plusAssign(it) } +// } +// for (i in c) +// if (!b.keys.contains(i)) b.getOrPut(i) { mutableSetOf() } +// for ((i, j) in b) { +// val k = j.toMutableSet() +// if (k.contains(i)) k.remove(i) +// b[i] = k +// } +// return b +// } + +// public static int testFunc3(ArrayList> arr) { +// if (arr.get(0).a == 0) { +// if (arr.get(1).a == 1) { +// return 777; +// } +// } +// return 0; +// } + +// public boolean testFunc3(java.util.concurrent.BlockingQueue a) { +// for (int i = 0; i < array.size() - 1; i++) { +// if (array.get(i).a > array.get(i + 1).a) { +// return true; +// } +// } +// return false; +// } + +// public boolean testFunc3(A a) { +//// for (int i = 0; i < array.size() - 1; i++) { +//// if (array.get(i).a > array.get(i + 1).a) { +//// return true; +//// } +//// } +// return false; +// } + +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/H.java b/utbot-framework/src/main/java/org/utbot/examples/H.java new file mode 100644 index 0000000000..c545e52660 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/H.java @@ -0,0 +1,32 @@ +package org.utbot.examples; + +import java.util.ArrayList; + +public class H implements I { + + + @Override + public int lol2() { + return 123; + } + + @Override + public int lol3() { + return I.super.lol3(); + } + + @Override + public void lol4() { + System.out.println("LOL"); + } + + @Override + public ArrayList lol5(Object r) { + return new ArrayList(15); + } + + @Override + public int lol() { + return 777; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/I.java b/utbot-framework/src/main/java/org/utbot/examples/I.java new file mode 100644 index 0000000000..c138714f55 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/I.java @@ -0,0 +1,5 @@ +package org.utbot.examples; + +public interface I extends I1 { + int lol(); +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/I1.java b/utbot-framework/src/main/java/org/utbot/examples/I1.java new file mode 100644 index 0000000000..4dc282a0e6 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/I1.java @@ -0,0 +1,10 @@ +package org.utbot.examples; + +public interface I1 extends I2 { + int lol2(); + default int lol3() { + return 3; + } + + void lol4(); +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/I2.java b/utbot-framework/src/main/java/org/utbot/examples/I2.java new file mode 100644 index 0000000000..4e7691ae47 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/I2.java @@ -0,0 +1,8 @@ +package org.utbot.examples; + +import java.util.ArrayList; + +public interface I2 { + ArrayList lol5(K r); + +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/L.java b/utbot-framework/src/main/java/org/utbot/examples/L.java new file mode 100644 index 0000000000..7e4abde76c --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/L.java @@ -0,0 +1,9 @@ +package org.utbot.examples; + +public class L { + int a = 1; + + public L(int a) { + this.a = a; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/ListImpl.java b/utbot-framework/src/main/java/org/utbot/examples/ListImpl.java new file mode 100644 index 0000000000..d1e7e34be3 --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/ListImpl.java @@ -0,0 +1,131 @@ +package org.utbot.examples; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.ListIterator; + +public class ListImpl implements List { + @Override + public int size() { + return 0; + } + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public boolean contains(Object o) { + return false; + } + + @NotNull + @Override + public Iterator iterator() { + return null; + } + + @NotNull + @Override + public Object[] toArray() { + return new Object[0]; + } + + @NotNull + @Override + public T1[] toArray(@NotNull T1[] t1s) { + return null; + } + + @Override + public boolean add(T t) { + return false; + } + + @Override + public boolean remove(Object o) { + return false; + } + + @Override + public boolean containsAll(@NotNull Collection collection) { + return false; + } + + @Override + public boolean addAll(@NotNull Collection collection) { + return false; + } + + @Override + public boolean addAll(int i, @NotNull Collection collection) { + return false; + } + + @Override + public boolean removeAll(@NotNull Collection collection) { + return false; + } + + @Override + public boolean retainAll(@NotNull Collection collection) { + return false; + } + + @Override + public void clear() { + + } + + @Override + public T get(int i) { + return null; + } + + @Override + public T set(int i, T t) { + return null; + } + + @Override + public void add(int i, T t) { + + } + + @Override + public T remove(int i) { + return null; + } + + @Override + public int indexOf(Object o) { + return 0; + } + + @Override + public int lastIndexOf(Object o) { + return 0; + } + + @NotNull + @Override + public ListIterator listIterator() { + return null; + } + + @NotNull + @Override + public ListIterator listIterator(int i) { + return null; + } + + @NotNull + @Override + public List subList(int i, int i1) { + return null; + } +} diff --git a/utbot-framework/src/main/java/org/utbot/examples/PrimitiveFields.java b/utbot-framework/src/main/java/org/utbot/examples/PrimitiveFields.java new file mode 100644 index 0000000000..9d55af247b --- /dev/null +++ b/utbot-framework/src/main/java/org/utbot/examples/PrimitiveFields.java @@ -0,0 +1,21 @@ +package org.utbot.examples; + +/** + * A class with private fields of primitive type + * having default constructor, setters and direct accessors for them. + */ +public class PrimitiveFields { + private int a; + protected int b; + + public PrimitiveFields() { + } + + public void setA(int a) { + this.a = a; + } + + public int getB() { + return b; + } +} diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/FuzzerExecutor.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/FuzzerExecutor.kt new file mode 100644 index 0000000000..3248e690c3 --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/FuzzerExecutor.kt @@ -0,0 +1,311 @@ +package org.utbot.engine.greyboxfuzzer + +import org.junit.jupiter.api.Assertions +import org.utbot.common.FileUtil +import org.utbot.common.PathUtil.getUrlsFromClassLoader +import org.utbot.engine.greyboxfuzzer.PredefinedGeneratorParameters.getMethodByName +import org.utbot.examples.GraphAlgorithms +import org.utbot.external.api.* +import org.utbot.external.api.UtBotJavaApi.fuzzingTestSets +import org.utbot.external.api.UtBotJavaApi.stopConcreteExecutorOnExit +import org.utbot.framework.plugin.api.* +import org.utbot.framework.plugin.api.util.UtContext +import org.utbot.framework.plugin.api.util.UtContext.Companion.setUtContext +import org.utbot.framework.plugin.services.JdkInfoDefaultProvider +import java.io.File +import java.lang.reflect.Method +import java.net.URISyntaxException +import java.net.URL +import java.nio.file.Path +import java.util.* +import java.util.stream.Collectors +import kotlin.io.path.ExperimentalPathApi +import kotlin.system.exitProcess + +class FuzzerExecutor { + + private val context: AutoCloseable + private val modelFactory: UtModelFactory + + init { + SootUtils.runSoot(GraphAlgorithms::class.java) + context = setUtContext(UtContext(GraphAlgorithms::class.java.classLoader)) + modelFactory = UtModelFactory() + } + + fun testSimpleFuzzing(clazz: Class<*>) { + //runSoot(StringSwitchExample::class.java) + stopConcreteExecutorOnExit = false + + val classpath = getClassPath(clazz) + val dependencyClassPath = getDependencyClassPath() + + val classUnderTestModel = modelFactory.produceCompositeModel( + classIdForType(clazz) + ) + + val methodsUnderTest = clazz.declaredMethods + val methodsInfo = methodsUnderTest.map { methodUnderTest -> + val models = modelFactory.produceAssembleModel( + methodUnderTest, + clazz, listOf(classUnderTestModel) + ) + + val methodState = EnvironmentModels( + models[classUnderTestModel], + Arrays.asList(UtPrimitiveModel("initial model"), UtPrimitiveModel(-10), UtPrimitiveModel(0)), emptyMap() + ) + TestMethodInfo( + methodUnderTest, + methodState + ) + } + + val testSets1: List = fuzzingTestSets( + methodsForAutomaticGeneration = methodsInfo, + classUnderTest = clazz, + classpath = classpath, + dependencyClassPath = dependencyClassPath!!, + mockStrategyApi = MockStrategyApi.OTHER_PACKAGES, + generationTimeoutInMillis = 100000L, + isGreyBoxFuzzing = true + ) { type: Class<*> -> + if (Int::class.javaPrimitiveType == type || Int::class.java == type) { + return@fuzzingTestSets Arrays.asList( + 0, + Int.MIN_VALUE, + Int.MAX_VALUE + ) + } + null + } + +// val generate = generate( +// listOf(methodInfo), +// testSets1, +// org.utbot.examples.manual.PredefinedGeneratorParameters.destinationClassName, +// classpath, +// dependencyClassPath!!, +// StringSwitchExample::class.java +// ) + exitProcess(0) + } + fun testSimpleFuzzing(clazz: Class<*>, funName: String) { + + + //runSoot(StringSwitchExample::class.java) + stopConcreteExecutorOnExit = false + + val classpath = getClassPath(clazz) + val dependencyClassPath = getDependencyClassPath() + + val classUnderTestModel = modelFactory.produceCompositeModel( + classIdForType(clazz) + ) + + val methodUnderTest: Method = getMethodByName( + clazz, funName + ) + + val models = modelFactory.produceAssembleModel( + methodUnderTest, + clazz, listOf(classUnderTestModel) + ) + + val methodState = EnvironmentModels( + models[classUnderTestModel], + Arrays.asList(UtPrimitiveModel("initial model"), UtPrimitiveModel(-10), UtPrimitiveModel(0)), emptyMap() + ) + + val methodInfo = TestMethodInfo( + methodUnderTest, + methodState + ) + + val testSets1: List = fuzzingTestSets( + methodsForAutomaticGeneration = listOf(methodInfo), + classUnderTest = clazz, + classpath = classpath, + dependencyClassPath = dependencyClassPath!!, + mockStrategyApi = MockStrategyApi.OTHER_PACKAGES, + generationTimeoutInMillis = 100000L, + isGreyBoxFuzzing = true + ) { type: Class<*> -> + if (Int::class.javaPrimitiveType == type || Int::class.java == type) { + return@fuzzingTestSets Arrays.asList( + 0, + Int.MIN_VALUE, + Int.MAX_VALUE + ) + } + null + } + +// val generate = generate( +// listOf(methodInfo), +// testSets1, +// org.utbot.examples.manual.PredefinedGeneratorParameters.destinationClassName, +// classpath, +// dependencyClassPath!!, +// StringSwitchExample::class.java +// ) + exitProcess(0) +// stopConcreteExecutorOnExit = false +// val classpath: String = getClassPath(clazz) +// val dependencyClassPath: String = getDependencyClassPath()!! +// val classUnderTestModel: UtCompositeModel = modelFactory.produceCompositeModel( +// classIdForType(clazz) +// ) +// val methodUnderTest = PredefinedGeneratorParameters.getMethodByName( +// clazz, funName +// ) +// val models: IdentityHashMap = modelFactory.produceAssembleModel( +// methodUnderTest, +// clazz, listOf(classUnderTestModel) +// ) +// val methodState = EnvironmentModels( +// models[classUnderTestModel], +// Arrays.asList(UtPrimitiveModel("initial model"), UtPrimitiveModel(-10), UtPrimitiveModel(0)), emptyMap() +// ) +// val methodInfo = TestMethodInfo( +// methodUnderTest, +// methodState +// ) +// val testSets: List = fuzzingTestSets( +// listOf(methodInfo), +// clazz, +// classpath, +// dependencyClassPath, +// MockStrategyApi.OTHER_PACKAGES, +// 3000L +// ) +// exitProcess(0) +// val utTestCases1: List = fuzzingTestCases( +// listOf( +// methodInfo +// ), +// clazz, +// classpath, +// dependencyClassPath, +// MockStrategyApi.OTHER_PACKAGES, +// 100000L +// ) { type: Class<*> -> +// if (Int::class.javaPrimitiveType == type || Int::class.java == type) { +// return@fuzzingTestCases Arrays.asList( +// 0, +// Int.MIN_VALUE, +// Int.MAX_VALUE +// ) +// } +// null +// } + +// generate( +// listOf(methodInfo), +// testSets, +// PredefinedGeneratorParameters.destinationClassName, +// classpath, +// dependencyClassPath, +// clazz +// ) +// val snippet2 = Snippet(CodegenLanguage.JAVA, generate) +// compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2) + } + + private fun getClassPath(clazz: Class<*>): String { + return clazz.protectionDomain.codeSource.location.path + } + + private fun getDependencyClassPath(): String? { + val contextClassLoader = Thread.currentThread().contextClassLoader + val urls = getUrlsFromClassLoader(contextClassLoader) + return Arrays.stream(urls).map { url: URL -> + try { + return@map File(url.toURI()).toString() + } catch (e: URISyntaxException) { + Assertions.fail(e) + } + throw RuntimeException() + }.collect(Collectors.joining(File.pathSeparator)) + } +} + +internal object PredefinedGeneratorParameters { + var destinationClassName = "GeneratedTest" + fun getMethodByName(clazz: Class<*>, name: String): Method { + return clazz.declaredMethods.first { it.name == name } + } +} + + +object SootUtils { + @JvmStatic + fun runSoot(clazz: Class<*>) { + val buildDir = FileUtil.locateClassPath(clazz) ?: FileUtil.isolateClassFiles(clazz) + val buildDirPath = buildDir.toPath() + + if (buildDirPath != previousBuildDir) { + org.utbot.framework.util.SootUtils.runSoot(listOf(buildDirPath), null, true, JdkInfoDefaultProvider().info) + previousBuildDir = buildDirPath + } + } + + private var previousBuildDir: Path? = null +} + +fun fields( + classId: ClassId, + vararg fields: Pair +): MutableMap { + return fields + .associate { + val fieldId = FieldId(classId, it.first) + val fieldValue = when (val value = it.second) { + is UtModel -> value + else -> UtPrimitiveModel(value) + } + fieldId to fieldValue + } + .toMutableMap() +} + +@OptIn(ExperimentalPathApi::class) +fun main() { +// val random = GreyBoxFuzzerGenerators.sourceOfRandomness +// val status = GreyBoxFuzzerGenerators.genStatus +// withUtContext(UtContext(GraphAlgorithms::class.java.classLoader)) { +// val gen = IntegerGenerator() +// val generatedInt = gen.generateWithState(random, status) +// println(generatedInt) +// gen.generationState = GenerationState.CACHE +// println(gen.generateWithState(random, status)) +// } +// +// exitProcess(0) +// val cl = Files.walk(Paths.get("utbot-framework/src/main/java/org/utbot/example/")).toList() +// .filter { it!!.name.endsWith(".java") } +// .map { it.toFile().absolutePath.substringAfterLast("java/").replace('/', '.').substringBeforeLast(".java") } +// .map { Class.forName(it) } +//// //114!! +// var i = 0 +// for (c in cl) { +// ++i +// //if (c.name != "org.utbot.example.casts.GenericCastExample") continue +// //if (i < 169) continue +// val methods = c.declaredMethods.filter { it.parameters.isNotEmpty() }.filter { !it.name.contains('$') } +// for (m in methods) { +// println("$i CLASS = ${c.name} from ${cl.size} method = ${m.name}") +// try { +// FuzzerExecutor().testSimpleFuzzing(c, m.name) +// } catch (e: RuntimeException) { +// println("No method source") +// } +// } +// } + + repeat(1) { + FuzzerExecutor().testSimpleFuzzing(GraphAlgorithms::class.java, "testFunc3") + //FuzzerExecutor().testSimpleFuzzing(GraphAlgorithms::class.java) + } + //FuzzerExecutor().testSimpleFuzzing(DateFormatterTest::class.java, "testLocalDateTimeSerialization") +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt index efa0af64fc..a211d18924 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -34,10 +34,11 @@ class GreyBoxFuzzer( suspend fun fuzz() = flow { logger.debug { "Started to fuzz ${methodUnderTest.name}" } - val generatorContext = GeneratorContext() val javaClazz = methodUnderTest.classId.jClass val sootMethod = methodUnderTest.sootMethod val javaMethod = sootMethod.toJavaMethod() ?: return@flow + val generatorContext = GeneratorContext() + .also { it.constants.putAll(sootMethod.collectConstants(it.utModelConstructor)) } val classFieldsUsedByFunc = sootMethod.getClassFieldsUsedByFunc(javaClazz) while (timeRemain > 0 || !isMethodCovered()) { explorationStage( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/coverage/GlobalCoverage.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/coverage/GlobalCoverage.kt new file mode 100644 index 0000000000..40ef4b3d0b --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/coverage/GlobalCoverage.kt @@ -0,0 +1,11 @@ +package org.utbot.engine.greyboxfuzzer.coverage + +import org.utbot.framework.plugin.api.Instruction + +data class GlobalCoverage(val coveredInstructions: MutableSet) { + + fun addInstructions(instructions: List) { + instructions.forEach { coveredInstructions.add(it) } + } + +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt index 3c5fbb93ae..a311a36bb4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt @@ -4,20 +4,21 @@ import org.javaruntype.type.TypeParameter import org.javaruntype.type.Types import org.javaruntype.type.WildcardTypeParameter import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.* import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.engine.greyboxfuzzer.util.getImplementersOfWithChain import org.utbot.engine.greyboxfuzzer.util.removeIfAndReturnRemovedElements import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.framework.plugin.api.util.objectClassId import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ReflectionException import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness -import soot.SootClass +import org.utbot.engine.greyboxfuzzer.util.getTrue +import org.utbot.framework.plugin.api.util.* import java.lang.reflect.AnnotatedElement import java.lang.reflect.AnnotatedType import java.lang.reflect.Method import java.util.Collections +import kotlin.random.Random import java.lang.annotation.Annotation as JavaAnnotation /** @@ -38,21 +39,28 @@ abstract class Generator protected constructor(types: List>) : Gen { } return when (generationState) { GenerationState.REGENERATE -> { - generate(random, status).also { + val possibleConstant = + if (Random.getTrue(20)) { + getConstant() + } else null + (possibleConstant ?: generate(random, status)).also { generatedUtModel = it nestedGeneratorsRecursive().forEach { it.generationState = GenerationState.CACHE } } } + GenerationState.CACHE -> { generatedUtModel ?: throw FuzzerIllegalStateException("No cached model") } + GenerationState.MODIFY -> { withModification { generate(random, status).also { generatedUtModel = it } } } + GenerationState.MODIFYING_CHAIN -> { generate(random, status).also { generatedUtModel = it @@ -64,6 +72,28 @@ abstract class Generator protected constructor(types: List>) : Gen { } } + private fun getConstant(): UtModel? = + if (isGeneratorContextInitialized()) { + when (this) { + is IntegerGenerator -> generatorContext.constants[intWrapperClassId]?.randomOrNull() + is PrimitiveIntGenerator -> generatorContext.constants[intClassId]?.randomOrNull() + is ByteGenerator -> generatorContext.constants[byteWrapperClassId]?.randomOrNull() + is PrimitiveByteGenerator -> generatorContext.constants[byteClassId]?.randomOrNull() + is CharacterGenerator -> generatorContext.constants[charWrapperClassId]?.randomOrNull() + is PrimitiveCharGenerator -> generatorContext.constants[charClassId]?.randomOrNull() + is DoubleGenerator -> generatorContext.constants[doubleWrapperClassId]?.randomOrNull() + is PrimitiveDoubleGenerator -> generatorContext.constants[doubleClassId]?.randomOrNull() + is LongGenerator -> generatorContext.constants[longWrapperClassId]?.randomOrNull() + is PrimitiveLongGenerator -> generatorContext.constants[longClassId]?.randomOrNull() + is FloatGenerator -> generatorContext.constants[floatWrapperClassId]?.randomOrNull() + is PrimitiveFloatGenerator -> generatorContext.constants[floatClassId]?.randomOrNull() + is ShortGenerator -> generatorContext.constants[shortWrapperClassId]?.randomOrNull() + is PrimitiveShortGenerator -> generatorContext.constants[shortClassId]?.randomOrNull() + is StringGenerator -> generatorContext.constants[stringClassId]?.randomOrNull() + else -> null + } + } else null + private fun flattenedTo(destination: MutableList) { destination.add(this) nestedGenerators.forEach { it.flattenedTo(destination) } @@ -258,6 +288,7 @@ abstract class Generator protected constructor(types: List>) : Gen { } fun isGeneratorContextInitialized() = this::generatorContext.isInitialized + /** * Used by the framework to make a copy of the receiver. * diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt index ace7687638..91a6d13afd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt @@ -1,11 +1,14 @@ package org.utbot.engine.greyboxfuzzer.quickcheck.generator import org.utbot.framework.concrete.constructors.UtModelConstructor +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtModel import java.util.* data class GeneratorContext( val utModelConstructor: UtModelConstructor = UtModelConstructor(IdentityHashMap()), - val timeoutInMillis: Long = 5000L + val timeoutInMillis: Long = 5000L, + val constants: MutableMap> = mutableMapOf() ) { var timeOfGenerationStart = 0L var timeToFinishGeneration = 0L diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt index 19d40f1ff6..31b2d6a357 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt @@ -3,5 +3,7 @@ package org.utbot.engine.greyboxfuzzer.util import java.net.URLClassLoader object CustomClassLoader { - lateinit var classLoader: URLClassLoader + lateinit var classLoader: ClassLoader + + fun isClassLoaderInitialized() = this::classLoader.isInitialized } \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt index 92a96f6b8c..3564133913 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt @@ -11,6 +11,22 @@ fun List.sublistBeforeLast(element: T): List = else this.subList(0, lastIndex) } +fun Iterable.filterDuplicates(comparator: Comparator): List { + val res = mutableListOf() + this.forEach { el -> if (res.all { comparator.compare(it, el) != 0 }) res.add(el) } + return res +} + +fun Collection.filterDuplicatesBy(f: (T) -> R): List { + val list1 = this.zip(this.map(f)) + val res = mutableListOf>() + for (i in indices) { + val item = list1[i].second + if (res.all { it.second != item }) res.add(list1[i]) + } + return res.map { it.first } +} + fun MutableList.removeIfAndReturnRemovedElements(cond: (T) -> Boolean): List { val res = mutableListOf() val iterator = this.iterator() diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt index c5f7a0169f..5eb8052b38 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt @@ -1,6 +1,12 @@ package org.utbot.engine.greyboxfuzzer.util -import org.utbot.framework.plugin.api.util.signature +import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.* +import org.utbot.framework.concrete.constructors.UtModelConstructor +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.util.* +import org.utbot.fuzzer.FuzzedConcreteValue +import org.utbot.fuzzer.collectConstantsForFuzzer import soot.ArrayType import soot.Hierarchy import soot.RefType @@ -8,10 +14,9 @@ import soot.Scene import soot.SootClass import soot.SootField import soot.SootMethod -import soot.jimple.internal.JAssignStmt -import soot.jimple.internal.JCastExpr -import soot.jimple.internal.JInstanceFieldRef -import soot.jimple.internal.JInstanceOfExpr +import soot.jimple.Constant +import soot.jimple.internal.* +import soot.toolkits.graph.ExceptionalUnitGraph import java.lang.reflect.Executable import java.lang.reflect.Field import java.lang.reflect.Method @@ -70,10 +75,12 @@ fun SootMethod.getAllTypesFromCastAndInstanceOfInstructions(): Set> = null } } + else -> null } //(it.type as? RefType)?.sootClass?.toJavaClass() } + else -> { val type = (it as JInstanceOfExpr).checkType when (type) { @@ -89,6 +96,7 @@ fun SootMethod.getAllTypesFromCastAndInstanceOfInstructions(): Set> = null } } + else -> null } } @@ -119,6 +127,7 @@ fun KFunction<*>.toSootMethod(): SootMethod? = this.javaMethod?.toSootMethod() fun Class<*>.toSootClass() = Scene.v().classes.find { it.name == this.name } + fun Method.toSootMethod(): SootMethod? { val cl = declaringClass.toSootClass() ?: return null return cl.methods.find { @@ -138,6 +147,35 @@ fun SootField.toJavaField(): Field? = fun Field.toSootField(): SootField? = declaringClass.toSootClass()?.fields?.find { it.name == name } +fun SootMethod.collectConstants(utModelConstructor: UtModelConstructor): Map> { + val sootGraph = ExceptionalUnitGraph(activeBody) + + fun generateConstantsForBothPrimitives(classId: ClassId, value: Any, utModelConstructor: UtModelConstructor) = + when (classId) { + intWrapperClassId -> listOf(intClassId to utModelConstructor.construct(value, intClassId)) + intClassId -> listOf(intWrapperClassId to utModelConstructor.construct(value, intWrapperClassId)) + byteWrapperClassId -> listOf(byteClassId to utModelConstructor.construct(value, byteClassId)) + byteClassId -> listOf(byteWrapperClassId to utModelConstructor.construct(value, byteWrapperClassId)) + charWrapperClassId -> listOf(charClassId to utModelConstructor.construct(value, charClassId)) + charClassId -> listOf(charWrapperClassId to utModelConstructor.construct(value, charWrapperClassId)) + doubleWrapperClassId -> listOf(doubleClassId to utModelConstructor.construct(value, doubleClassId)) + doubleClassId -> listOf(doubleWrapperClassId to utModelConstructor.construct(value, doubleWrapperClassId)) + longWrapperClassId -> listOf(longClassId to utModelConstructor.construct(value, longClassId)) + longClassId -> listOf(longWrapperClassId to utModelConstructor.construct(value, longWrapperClassId)) + floatWrapperClassId -> listOf(floatClassId to utModelConstructor.construct(value, floatClassId)) + floatClassId -> listOf(floatWrapperClassId to utModelConstructor.construct(value, floatWrapperClassId)) + shortWrapperClassId -> listOf(shortClassId to utModelConstructor.construct(value, shortClassId)) + shortClassId -> listOf(shortWrapperClassId to utModelConstructor.construct(value, shortWrapperClassId)) + stringClassId -> listOf() + else -> null + }?.let { it + listOf(classId to utModelConstructor.construct(value, classId)) } ?: listOf() + + return collectConstantsForFuzzer(sootGraph) + .filterDuplicatesBy { it.value } + .flatMap { generateConstantsForBothPrimitives(it.classId, it.value, utModelConstructor) } + .groupBy({ it.first }, { it.second }) +} + fun SootClass.getAllAncestors(): List { val queue = ArrayDeque() val res = mutableSetOf() diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/UtBotTestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/UtBotTestCaseGenerator.kt new file mode 100644 index 0000000000..4dfd9b27ac --- /dev/null +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/UtBotTestCaseGenerator.kt @@ -0,0 +1,495 @@ +//package org.utbot.framework.plugin.api +// +//import kotlinx.coroutines.* +//import org.utbot.common.FileUtil +//import org.utbot.common.bracket +//import org.utbot.common.runBlockingWithCancellationPredicate +//import org.utbot.common.runIgnoringCancellationException +//import org.utbot.common.trace +//import org.utbot.framework.TestSelectionStrategyType +//import org.utbot.framework.UtSettings +//import org.utbot.framework.UtSettings.checkSolverTimeoutMillis +//import org.utbot.framework.UtSettings.disableCoroutinesDebug +//import org.utbot.framework.UtSettings.utBotGenerationTimeoutInMillis +//import org.utbot.framework.UtSettings.warmupConcreteExecution +//import org.utbot.framework.codegen.model.util.checkFrameworkDependencies +//import org.utbot.framework.concrete.UtConcreteExecutionData +//import org.utbot.framework.concrete.UtExecutionInstrumentation +//import org.utbot.framework.concrete.constructors.UtModelConstructor +//import org.utbot.framework.minimization.minimizeTestCase +//import org.utbot.framework.plugin.api.util.UtContext +//import org.utbot.framework.plugin.api.util.id +//import org.utbot.framework.plugin.api.util.intArrayClassId +//import org.utbot.framework.plugin.api.util.signature +//import org.utbot.framework.plugin.api.util.utContext +//import org.utbot.framework.plugin.api.util.withUtContext +//import org.utbot.instrumentation.ConcreteExecutor +//import org.utbot.instrumentation.warmup.Warmup +//import java.io.File +//import java.nio.file.Path +//import java.util.IdentityHashMap +//import kotlin.coroutines.cancellation.CancellationException +//import kotlin.math.min +//import kotlin.reflect.KCallable +//import kotlinx.coroutines.flow.Flow +//import kotlinx.coroutines.flow.collect +//import kotlinx.coroutines.flow.flattenConcat +//import kotlinx.coroutines.flow.flowOf +//import mu.KotlinLogging +//import org.utbot.engine.* +//import org.utbot.engine.greyboxfuzzer.generator.ThisInstanceGenerator +//import org.utbot.engine.greyboxfuzzer.util.CoverageCollector +//import org.utbot.engine.greyboxfuzzer.util.CustomClassLoader +//import soot.Scene +//import soot.jimple.JimpleBody +//import soot.toolkits.graph.ExceptionalUnitGraph +//import java.net.URL +//import java.net.URLClassLoader +//import java.time.Duration +//import java.util.jar.JarFile +//import kotlin.reflect.jvm.jvmName +//import kotlin.reflect.jvm.kotlinFunction +//import kotlin.system.exitProcess +// +//object UtBotTestCaseGenerator : TestCaseGenerator { +// +// private val logger = KotlinLogging.logger {} +// private val timeoutLogger = KotlinLogging.logger(logger.name + ".timeout") +// +// lateinit var isCanceled: () -> Boolean +// +// //properties to save time on soot initialization +// private var previousBuildDir: Path? = null +// private var previousClasspath: String? = null +// private var previousTimestamp: Long? = null +// private var dependencyPaths: String = "" +// +// override fun init( +// buildDir: Path, +// classpath: String?, +// dependencyPaths: String, +// isCanceled: () -> Boolean +// ) { +// this.isCanceled = isCanceled +// if (isCanceled()) return +// +// checkFrameworkDependencies(dependencyPaths) +// +// logger.trace("Initializing ${this.javaClass.name} with buildDir = $buildDir, classpath = $classpath") +// +// //optimization: maxLastModifiedRecursivelyMillis can take time +// val timestamp = if (UtSettings.classfilesCanChange) maxLastModifiedRecursivelyMillis(buildDir, classpath) else 0 +// +// if (buildDir == previousBuildDir && classpath == previousClasspath && timestamp == previousTimestamp) { +// logger.info { "Ignoring soot initialization because parameters are the same as on previous initialization" } +// return +// } +// +// if (disableCoroutinesDebug) { +// System.setProperty(kotlinx.coroutines.DEBUG_PROPERTY_NAME, kotlinx.coroutines.DEBUG_PROPERTY_VALUE_OFF) +// } +// +// +// +// +// timeoutLogger.trace().bracket("Soot initialization") { +// val jarsPaths = classpath!!.split(":").filter { it.endsWith(".jar") } +// for (jarPath in jarsPaths) { +// val jarFile = JarFile(jarPath) +// for (jarEntry in jarFile.entries()) { +// if (jarEntry.name.endsWith(".class")) { +// val className = jarEntry.name.dropLast(6).replace('/', '.') +// SootUtils.libraryClassesToLoad.add(className) +// } +// } +// } +// SootUtils.runSoot(buildDir, classpath) +// } +// +// previousBuildDir = buildDir +// previousClasspath = classpath +// previousTimestamp = timestamp +// this.dependencyPaths = dependencyPaths +// +// //warmup +// if (warmupConcreteExecution) { +// ConcreteExecutor( +// UtExecutionInstrumentation, +// classpathForEngine, +// dependencyPaths +// ).apply { +// classLoader = utContext.classLoader +// withUtContext(UtContext(Warmup::class.java.classLoader)) { +// runBlocking { +// constructExecutionsForWarmup().forEach { (method, data) -> +// executeAsync(method, emptyArray(), data) +// } +// } +// } +// warmup() +// } +// } +// } +// +// private fun constructExecutionsForWarmup(): Sequence, UtConcreteExecutionData>> = +// UtModelConstructor(IdentityHashMap()).run { +// sequenceOf( +// Warmup::doWarmup1 to UtConcreteExecutionData( +// EnvironmentModels( +// construct(Warmup(5), Warmup::class.java.id), +// listOf(construct(Warmup(1), Warmup::class.java.id)), +// emptyMap() +// ), emptyList() +// ), +// Warmup::doWarmup2 to UtConcreteExecutionData( +// EnvironmentModels( +// construct(Warmup(1), Warmup::class.java.id), +// listOf(construct(intArrayOf(1, 2, 3), intArrayClassId)), +// emptyMap() +// ), emptyList() +// ), +// Warmup::doWarmup2 to UtConcreteExecutionData( +// EnvironmentModels( +// construct(Warmup(1), Warmup::class.java.id), +// listOf(construct(intArrayOf(1, 2, 3, 4, 5, 6), intArrayClassId)), +// emptyMap() +// ), emptyList() +// ), +// ) +// } +// +// private val classpathForEngine: String +// get() = previousBuildDir!!.toString() + (previousClasspath?.let { File.pathSeparator + it } ?: "") +// +// private fun maxLastModifiedRecursivelyMillis(buildDir: Path, classpath: String?): Long { +// val paths = mutableListOf() +// paths += buildDir.toFile() +// if (classpath != null) { +// paths += classpath.split(File.pathSeparatorChar).map { File(it) } +// } +// return FileUtil.maxLastModifiedRecursivelyMillis(paths) +// } +// +// @Throws(CancellationException::class) +// fun generateAsync( +// controller: EngineController, +// method: UtMethod<*>, +// mockStrategy: MockStrategyApi, +// chosenClassesToMockAlways: Set = Mocker.javaDefaultClasses.mapTo(mutableSetOf()) { it.id }, +// executionTimeEstimator: ExecutionTimeEstimator = ExecutionTimeEstimator(utBotGenerationTimeoutInMillis, 1) +// ): Flow { +// val engine = createSymbolicEngine( +// controller, +// method, +// mockStrategy, +// chosenClassesToMockAlways, +// executionTimeEstimator +// ) +// return createDefaultFlow(engine) +// } +// +// private fun createSymbolicEngine( +// controller: EngineController, +// method: UtMethod<*>, +// mockStrategy: MockStrategyApi, +// chosenClassesToMockAlways: Set, +// executionTimeEstimator: ExecutionTimeEstimator +// ): UtBotSymbolicEngine { +// // TODO: create classLoader from buildDir/classpath and migrate from UtMethod to MethodId? +// logger.debug("Starting symbolic execution for $method --$mockStrategy--") +// val graph = graph(method) +// +// return UtBotSymbolicEngine( +// controller, +// method, +// graph, +// classpathForEngine, +// dependencyPaths = dependencyPaths, +// mockStrategy = apiToModel(mockStrategy), +// chosenClassesToMockAlways = chosenClassesToMockAlways, +// solverTimeoutInMillis = executionTimeEstimator.updatedSolverCheckTimeoutMillis +// ) +// } +// +// private fun createDefaultFlow(engine: UtBotSymbolicEngine): Flow { +// return flowOf(engine.fuzzing()).flattenConcat() +// exitProcess(0) +// var flow = engine.traverse() +// if (UtSettings.useFuzzing) { +// flow = flowOf(flow, engine.fuzzing()).flattenConcat() +// } +// return flow +// } +// +// // CONFLUENCE:The+UtBot+Java+timeouts +// +// class ExecutionTimeEstimator(val userTimeout: Long, methodsUnderTestNumber: Int) { +// // Cut the timeout from the user in two halves +// private val halfTimeUserExpectsToWaitInMillis = userTimeout / 2 +// +// // If the half is too much for concrete execution, decrease the concrete timeout +// var concreteExecutionBudgetInMillis = +// min(halfTimeUserExpectsToWaitInMillis, 300L * methodsUnderTestNumber) +// +// // The symbolic execution time is the reminder but not longer than checkSolverTimeoutMillis times methods number +// val symbolicExecutionTimeout = userTimeout - concreteExecutionBudgetInMillis +// +// //Allow traverse at least one method for the symbolic execution timeout +// val timeslotForOneToplevelMethodTraversalInMillis = +// symbolicExecutionTimeout / (methodsUnderTestNumber * 2) +// +// // Axillary field +// private val symbolicExecutionTimePerMethod = (symbolicExecutionTimeout / methodsUnderTestNumber).toInt() +// +// // Now we calculate the solver timeout. Each method is supposed to get some time in worst-case scenario +// val updatedSolverCheckTimeoutMillis = if (symbolicExecutionTimePerMethod < checkSolverTimeoutMillis) +// symbolicExecutionTimePerMethod else checkSolverTimeoutMillis +// +// init { +// // Update the concrete execution time, if symbolic execution time is small +// // because of UtSettings.checkSolverTimeoutMillis +// concreteExecutionBudgetInMillis = userTimeout - symbolicExecutionTimeout +// require(symbolicExecutionTimeout > 10) +// require(concreteExecutionBudgetInMillis > 10) +// } +// } +// +// fun generateForSeveralMethods( +// methods: List>, +// mockStrategy: MockStrategyApi, +// chosenClassesToMockAlways: Set = Mocker.javaDefaultClasses.mapTo(mutableSetOf()) { it.id }, +// methodsGenerationTimeout: Long = utBotGenerationTimeoutInMillis, +// generate: (engine: UtBotSymbolicEngine) -> Flow = ::createDefaultFlow +// ): List { +// if (isCanceled()) return methods.map { UtTestCase(it) } +// +// val executionStartInMillis = System.currentTimeMillis() +// val executionTimeEstimator = ExecutionTimeEstimator(methodsGenerationTimeout, methods.size) +// +// val currentUtContext = utContext +// +// val method2controller = methods.associateWith { EngineController() } +// val method2executions = methods.associateWith { mutableListOf() } +// val method2errors = methods.associateWith { mutableMapOf() } +// //Init this +// //ThisInstanceGenerator.generateThis(methods.first().clazz.java) +// +// runIgnoringCancellationException { +// runBlockingWithCancellationPredicate(isCanceled) { +// for ((method, controller) in method2controller) { +// controller.job = launch(currentUtContext) { +// if (!isActive) return@launch +// //TODO!! DO NOT FORGET TO REMOVE IT +// //if (!method.displayName.contains("decodeUTF8")) return@launch +// //yield one to +// yield() +// +// generate( +// createSymbolicEngine( +// controller, +// method, +// mockStrategy, +// chosenClassesToMockAlways, +// executionTimeEstimator +// ) +// ).collect { +// when (it) { +// is UtExecution -> method2executions.getValue(method) += it +// is UtError -> method2errors.getValue(method).merge(it.description, 1, Int::plus) +// } +// } +//// generate( +//// createSymbolicEngine( +//// controller, +//// method, +//// mockStrategy, +//// chosenClassesToMockAlways, +//// executionTimeEstimator +//// ) +//// ).collect { +//// when (it) { +//// is UtExecution -> method2executions.getValue(method) += it +//// is UtError -> method2errors.getValue(method).merge(it.description, 1, Int::plus) +//// } +//// } +// } +// controller.paused = true +// } +// +// // All jobs are in the method2controller now (paused). execute them with timeout +// +// GlobalScope.launch { +// while (isActive) { +// var activeCount = 0 +// for ((method, controller) in method2controller) { +// if (!controller.job!!.isActive) continue +// activeCount++ +// +// method2controller.values.forEach { it.paused = true } +// controller.paused = false +// +// logger.info { "|> Resuming method $method" } +// val startTime = System.currentTimeMillis() +// while (controller.job!!.isActive && +// (System.currentTimeMillis() - startTime) < executionTimeEstimator.timeslotForOneToplevelMethodTraversalInMillis +// ) { +// updateLifecycle( +// executionStartInMillis, +// executionTimeEstimator, +// method2controller.values, +// this +// ) +// yield() +// } +// } +// if (activeCount == 0) break +// } +// } +// } +// } +// ConcreteExecutor.defaultPool.close() // TODO: think on appropriate way to close child processes +// +// //Printing to console +// val clazz = methods.first().clazz +// val sootClazz = Scene.v().classes.find { it.name == clazz.jvmName }!! +// val methodsToLineNumbers = sootClazz.methods.mapNotNull { +// val sig = it.bytecodeSignature.drop(1).dropLast(1).substringAfter("${clazz.jvmName}: ") +// val (sootMethod, javaMethod) = it to clazz.java.declaredMethods.find { it.signature == sig } +// if (javaMethod?.kotlinFunction != null) { +// javaMethod to sootMethod.activeBody.units +// .map { it.javaSourceStartLineNumber } +// .filter { it != -1 } +// .toSet() +// } else { +// null +// } +// } +// println("OVERALL RESULTS:") +// println("------------------------------------------") +// for ((method, lines) in methodsToLineNumbers) { +// val coveredMethodInstructions = CoverageCollector.coverage +// .filter { it.methodSignature == method.signature } +// .map { it.lineNumber } +// .toSet() +// println("METHOD: ${method.name}") +// println("COVERED: ${coveredMethodInstructions.size} from ${lines.size} ${coveredMethodInstructions.size.toDouble() / lines.size * 100}%") +// println("COVERED: ${coveredMethodInstructions.sorted()}") +// println("NOT COVERED: ${lines.filter { it !in coveredMethodInstructions }.sorted()}") +// println("------------------") +// } +// println("------------------------------------------") +// val allLinesToCover = methodsToLineNumbers.flatMap { it.second }.toSet() +// val allLinesToCoverSize = allLinesToCover.size +// val allCoveredLines = CoverageCollector.coverage +// .filter { it.className.replace('/', '.') == clazz.jvmName } +// .map { it.lineNumber }.toSet() +// .filter { it in allLinesToCover } +// .size +// println("FINALLY COVERED $allCoveredLines from $allLinesToCoverSize ${allCoveredLines.toDouble() / allLinesToCoverSize * 100}%") +// println("------------------------------------------") +// return methods.map { method -> +// UtTestCase( +// method, +// minimizeExecutions(method2executions.getValue(method)), +// jimpleBody(method), +// method2errors.getValue(method) +// ) +// } +// } +// +// private fun updateLifecycle( +// executionStartInMillis: Long, +// executionTimeEstimator: ExecutionTimeEstimator, +// controllers: Collection, +// timeoutCheckerCoroutine: CoroutineScope +// ) { +// val timePassed = System.currentTimeMillis() - executionStartInMillis +// +// if (timePassed > executionTimeEstimator.userTimeout) { +// timeoutLogger.trace { +// "Out of concrete execution time limit (" + +// "$timePassed > ${executionTimeEstimator.userTimeout}" + +// "). Cancelling coroutines" +// } +// controllers.forEach { it.job!!.cancel("Timeout") } +// timeoutCheckerCoroutine.cancel("Timeout") +// } else if (!controllers.firstOrNull()!!.executeConcretely && +// timePassed > executionTimeEstimator.symbolicExecutionTimeout +// ) { +// timeoutLogger.trace { +// "We are out of time (" + +// "$timePassed > ${executionTimeEstimator.symbolicExecutionTimeout}" + +// "). Switching to the concrete execution (extra ${executionTimeEstimator.concreteExecutionBudgetInMillis} ms)" +// } +// controllers.forEach { it.executeConcretely = true } +// } +// } +// +// override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtTestCase { +// logger.trace { "UtSettings:${System.lineSeparator()}" + UtSettings.toString() } +// +// if (isCanceled()) return UtTestCase(method) +// +// val executions = mutableListOf() +// val errors = mutableMapOf() +// +// +// runIgnoringCancellationException { +// runBlockingWithCancellationPredicate(isCanceled) { +// generateAsync(EngineController(), method, mockStrategy).collect { +// when (it) { +// is UtExecution -> executions += it +// is UtError -> errors.merge(it.description, 1, Int::plus) +// } +// } +// } +// } +// +// val minimizedExecutions = minimizeExecutions(executions) +// return UtTestCase(method, minimizedExecutions, jimpleBody(method), errors) +// } +// +// +// private fun minimizeExecutions(executions: List): List = +// if (UtSettings.testMinimizationStrategyType == TestSelectionStrategyType.DO_NOT_MINIMIZE_STRATEGY) { +// executions +// } else { +// minimizeTestCase(executions) { it.result::class.java } +// } +// +// +// fun apiToModel(mockStrategyApi: MockStrategyApi): MockStrategy = +// when (mockStrategyApi) { +// MockStrategyApi.NO_MOCKS -> MockStrategy.NO_MOCKS +// MockStrategyApi.OTHER_PACKAGES -> MockStrategy.OTHER_PACKAGES +// MockStrategyApi.OTHER_CLASSES -> MockStrategy.OTHER_CLASSES +// else -> error("Cannot map API Mock Strategy model to Engine model: $mockStrategyApi") +// } +// +// private fun graph(method: UtMethod<*>): ExceptionalUnitGraph { +// val className = method.clazz.java.name +// val clazz = Scene.v().classes.singleOrNull { it.name == className } +// ?: error("No such $className found in the Scene") +// val signature = method.callable.signature +// val sootMethod = clazz.methods.singleOrNull { it.pureJavaSignature == signature } +// ?: error("No such $signature found") +// +// val methodBody = sootMethod.jimpleBody() +// val graph = methodBody.graph() +// +// logger.trace { "JIMPLE for $method:\n${methodBody}" } +// +// return graph +// } +// +// fun jimpleBody(method: UtMethod<*>): JimpleBody { +// val clazz = Scene.v().classes.single { it.name == method.clazz.java.name } +// val signature = method.callable.signature +// val sootMethod = clazz.methods.single { it.pureJavaSignature == signature } +// +// return sootMethod.jimpleBody() +// } +//} +// +//fun JimpleBody.graph() = ExceptionalUnitGraph(this) +// diff --git a/utbot-framework/src/main/resources/log4j2.xml b/utbot-framework/src/main/resources/log4j2.xml new file mode 100644 index 0000000000..37bf0ab411 --- /dev/null +++ b/utbot-framework/src/main/resources/log4j2.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From 5fb10908c9a5e733b0281afdaef241ca88796819 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Mon, 19 Dec 2022 19:47:10 +0300 Subject: [PATCH 19/30] removed unnecessary files --- .../src/main/java/org/utbot/examples/A.java | 67 ----- .../src/main/java/org/utbot/examples/B.java | 30 -- .../java/org/utbot/examples/ByteVector.java | 203 -------------- .../src/main/java/org/utbot/examples/C.java | 7 - .../org/utbot/examples/CalendarLogic.java | 42 --- .../src/main/java/org/utbot/examples/D.java | 4 - .../main/java/org/utbot/examples/GrAlh.java | 5 - .../main/java/org/utbot/examples/Graph.java | 70 ----- .../org/utbot/examples/GraphAlgorithms.java | 260 ------------------ .../src/main/java/org/utbot/examples/H.java | 32 --- .../src/main/java/org/utbot/examples/I.java | 5 - .../src/main/java/org/utbot/examples/I1.java | 10 - .../src/main/java/org/utbot/examples/I2.java | 8 - .../src/main/java/org/utbot/examples/L.java | 9 - .../java/org/utbot/examples/ListImpl.java | 131 --------- .../org/utbot/examples/PrimitiveFields.java | 21 -- 16 files changed, 904 deletions(-) delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/A.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/B.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/ByteVector.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/C.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/CalendarLogic.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/D.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/GrAlh.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/Graph.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/GraphAlgorithms.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/H.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/I.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/I1.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/I2.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/L.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/ListImpl.java delete mode 100644 utbot-framework/src/main/java/org/utbot/examples/PrimitiveFields.java diff --git a/utbot-framework/src/main/java/org/utbot/examples/A.java b/utbot-framework/src/main/java/org/utbot/examples/A.java deleted file mode 100644 index 89c4a80e00..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/A.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.utbot.examples; - -import java.lang.reflect.Field; - -class A { - - public C c = new C(); - - public int getCLol3() { - return c.h.lol3(); - } -// public A(int a, R at) { -// this.a = a; -// this.at = at; -// } - -// public class Lil { -// int a = 1; -// -// Lil(int a) { -// this.a = a; -// } -// } - -// int a = 1; -// int c; -// R at; -// final int b = 1; - -// public static A produceA(int a, Number b) { -// return new A(777, b); -// } - //public static A aInstance = new A(777, 13.0); - -// public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException { -// Field f = A.class.getField("aInstance"); -// System.out.println(f.get(null)); -// } - - //public int lol(R a, ArrayList arr); -// public static A getInstance1(R a, ArrayList arr) { -// return new B(a, 777, arr); -// } - - - // public static final A numberA = new A(1, 3L, null); -// public static final A intA = new A(1, 2, null); -// public static final A strA = new A(1, "a", null); -// -// public static A getInstance() { -// return new A(1, null, null); -// } - - //public static A getIntegerInstance() { -// return new A(1, 3); -// } -// public static A getIntegerInstance(Integer a, B bInstance) { -// return new A(a, 3, bInstance); -// } - - // private A() {} -// public A(int a, R ba, R e, B bInstance) { -// this.e = e; -// this.a = a; -// this.bInstance = bInstance; -// } -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/B.java b/utbot-framework/src/main/java/org/utbot/examples/B.java deleted file mode 100644 index 9914498ab6..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/B.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.utbot.examples; - -public class B { - - R[] arr; -// int a; -// String b; -// -// public B(int a, String b) { -// this.a = a; -// this.b = b; -// } -} -//public class B implements A { -// -// public T a; -// public int b; -// public ArrayList c; -// -// public B(T a, int b, ArrayList c) { -// this.a = a; -// this.b = b; -// this.c = c; -// } -// -// @Override -// public int lol(T a, ArrayList arr) { -// return 0; -// } -//} diff --git a/utbot-framework/src/main/java/org/utbot/examples/ByteVector.java b/utbot-framework/src/main/java/org/utbot/examples/ByteVector.java deleted file mode 100644 index 040246ef77..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/ByteVector.java +++ /dev/null @@ -1,203 +0,0 @@ -package org.utbot.examples; - -/** - * A dynamically extensible vector of bytes. This class is roughly equivalent to - * a DataOutputStream on top of a ByteArrayOutputStream, but is more efficient. - * - * @author Eric Bruneton - */ -public class ByteVector { - - /** - * The content of this vector. - */ - public byte[] data; - - /** - * Actual number of bytes in this vector. - */ - public int length; - - /** - * Constructs a new {@link ByteVector ByteVector} with a default initial size. - */ - public ByteVector() { - data = new byte[64]; - } - - /** - * Constructs a new {@link ByteVector ByteVector} with the given initial size. - * - * @param initialSize the initial size of the byte vector to be constructed. - */ - public ByteVector(final int initialSize) { - data = new byte[initialSize]; - } - - /** - * Puts a byte into this byte vector. The byte vector is automatically enlarged - * if necessary. - * - * @param b a byte. - * @return this byte vector. - */ - public ByteVector putByte(final int b) { - int length = this.length; - if (length + 1 > data.length) { - enlarge(1); - } - data[length++] = (byte) b; - this.length = length; - return this; - } - - /** - * Puts two bytes into this byte vector. The byte vector is automatically - * enlarged if necessary. - * - * @param b1 a byte. - * @param b2 another byte. - * @return this byte vector. - */ - ByteVector put11(final int b1, final int b2) { - int length = this.length; - if (length + 2 > data.length) { - enlarge(2); - } - final byte[] data = this.data; - data[length++] = (byte) b1; - data[length++] = (byte) b2; - this.length = length; - return this; - } - - /** - * Puts a short into this byte vector. The byte vector is automatically enlarged - * if necessary. - * - * @param s a short. - * @return this byte vector. - */ - public ByteVector putShort(final int s) { - int length = this.length; - if (length + 2 > data.length) { - enlarge(2); - } - final byte[] data = this.data; - data[length++] = (byte) (s >>> 8); - data[length++] = (byte) s; - this.length = length; - return this; - } - - /** - * Puts a byte and a short into this byte vector. The byte vector is - * automatically enlarged if necessary. - * - * @param b a byte. - * @param s a short. - * @return this byte vector. - */ - public ByteVector put12(final int b, final int s) { - int length = this.length; - if (length + 3 > data.length) { - enlarge(3); - } - final byte[] data = this.data; - data[length++] = (byte) b; - data[length++] = (byte) (s >>> 8); - data[length++] = (byte) s; - this.length = length; - return this; - } - - /** - * Puts an int into this byte vector. The byte vector is automatically enlarged - * if necessary. - * - * @param i an int. - * @return this byte vector. - */ - public ByteVector putInt(final int i) { - int length = this.length; - if (length + 4 > data.length) { - enlarge(4); - } - final byte[] data = this.data; - data[length++] = (byte) (i >>> 24); - data[length++] = (byte) (i >>> 16); - data[length++] = (byte) (i >>> 8); - data[length++] = (byte) i; - this.length = length; - return this; - } - - /** - * Puts an UTF8 string into this byte vector. The byte vector is automatically - * enlarged if necessary. - * - * @param s a String. - * @return this byte vector. - */ - public ByteVector putUTF8(final String s) { - final int charLength = s.length(); - int len = length; - if (len + 2 + charLength > data.length) { - enlarge(2 + charLength); - } - final byte[] data = this.data; - // optimistic algorithm: instead of computing the byte length and then - // serializing the string (which requires two loops), we assume the byte - // length is equal to char length (which is the most frequent case), and - // we start serializing the string right away. During the serialization, - // if we find that this assumption is wrong, we continue with the - // general method. - data[len++] = (byte) (charLength >>> 8); - data[len++] = (byte) charLength; - for (int i = 0; i < charLength; ++i) { - final char c = s.charAt(i); - if ((c >= '\001' && c <= '\177') || (c >= '\u4E00' && c <= '\u9FFF')) { - data[len++] = (byte) c; - } else { - throw new UnsupportedOperationException(); - } - } - length = len; - return this; - } - - /** - * Puts an array of bytes into this byte vector. The byte vector is - * automatically enlarged if necessary. - * - * @param b an array of bytes. May be null to put len null - * bytes into this byte vector. - * @param off index of the fist byte of b that must be copied. - * @param len number of bytes of b that must be copied. - * @return this byte vector. - */ - public ByteVector putByteArray(final byte[] b, final int off, final int len) { - if (length + len > data.length) { - enlarge(len); - } - if (b != null) { - System.arraycopy(b, off, data, length, len); - } - length += len; - return this; - } - - /** - * Enlarge this byte vector so that it can receive n more bytes. - * - * @param size number of additional bytes that this byte vector should be able - * to receive. - */ - private void enlarge(final int size) { - final int length1 = 2 * data.length; - final int length2 = length + size; - final byte[] newData = new byte[length1 > length2 ? length1 : length2]; - System.arraycopy(data, 0, newData, 0, length); - data = newData; - } -} \ No newline at end of file diff --git a/utbot-framework/src/main/java/org/utbot/examples/C.java b/utbot-framework/src/main/java/org/utbot/examples/C.java deleted file mode 100644 index d6845998d0..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/C.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.utbot.examples; - -public class C { - - H h = new H(); - -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/CalendarLogic.java b/utbot-framework/src/main/java/org/utbot/examples/CalendarLogic.java deleted file mode 100644 index a7abda2fcd..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/CalendarLogic.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.utbot.examples; - -import java.util.GregorianCalendar; - -import static java.util.Calendar.*; - -/* Application logic */ -public class CalendarLogic { - // Returns true iff cal is in a leap year - public static boolean isLeapYear(GregorianCalendar cal) { - int year = cal.get(YEAR); - if (year % 4 == 0) { - return year % 100 != 0; - } - return false; - } - - // Returns either of -1, 0, 1 depending on whether c1 is <, =, > than c2 - public static int compare(GregorianCalendar c1, GregorianCalendar c2) { - int cmp; - cmp = Integer.compare(c1.get(YEAR), c2.get(YEAR)); - if (cmp == 0) { - cmp = Integer.compare(c1.get(MONTH), c2.get(MONTH)); - if (cmp == 0) { - cmp = Integer.compare(c1.get(DAY_OF_MONTH), c2.get(DAY_OF_MONTH)); - if (cmp == 0) { - cmp = Integer.compare(c1.get(HOUR), c2.get(HOUR)); - if (cmp == 0) { - cmp = Integer.compare(c1.get(MINUTE), c2.get(MINUTE)); - if (cmp == 0) { - cmp = Integer.compare(c1.get(SECOND), c2.get(SECOND)); - if (cmp == 0) { - cmp = Integer.compare(c1.get(MILLISECOND), c2.get(MILLISECOND)); - } - } - } - } - } - } - return cmp; - } -} \ No newline at end of file diff --git a/utbot-framework/src/main/java/org/utbot/examples/D.java b/utbot-framework/src/main/java/org/utbot/examples/D.java deleted file mode 100644 index b345d3faf6..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/D.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.utbot.examples; - -public interface D { -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/GrAlh.java b/utbot-framework/src/main/java/org/utbot/examples/GrAlh.java deleted file mode 100644 index b00d489eac..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/GrAlh.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.utbot.examples; - -public class GrAlh { - int a = 1; -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/Graph.java b/utbot-framework/src/main/java/org/utbot/examples/Graph.java deleted file mode 100644 index c829460d09..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/Graph.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.utbot.examples; - -import java.util.Arrays; - -public class Graph { - private int size; - private int[][] adj; - - public int getSize() { - return size; - } - - public void setSize(int size) { - this.size = size; - } - - public int[][] getAdj() { - return adj; - } - - public void setAdj(int[][] adj) { - this.adj = adj; - } - - public int[] getChildrenOf(int node) { - if (node < 0 && node >= size) { - throw new IllegalArgumentException("Number of node out of bounds"); - } - return Arrays.stream(adj[node]).filter(i -> i != 0).toArray(); - } - - private boolean isCyclic(int i, boolean[] visited, boolean[] recStack) { - if (recStack[i]) - return true; - - if (visited[i]) - return false; - - visited[i] = true; - - recStack[i] = true; - int[] children = adj[i]; - - for (Integer c : children) - if (c == 1) { - if (isCyclic(c, visited, recStack)) { - return true; - } - } - - recStack[i] = false; - - return false; - } - - public void addEdge(int source, int dest) { - adj[source][dest] = 1; - } - - public boolean isCyclic() { - boolean[] visited = new boolean[size]; - boolean[] recStack = new boolean[size]; - - for (int i = 0; i < size; i++) - if (isCyclic(i, visited, recStack)) - return true; - - return false; - } -} \ No newline at end of file diff --git a/utbot-framework/src/main/java/org/utbot/examples/GraphAlgorithms.java b/utbot-framework/src/main/java/org/utbot/examples/GraphAlgorithms.java deleted file mode 100644 index f2bc4860e3..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/GraphAlgorithms.java +++ /dev/null @@ -1,260 +0,0 @@ -package org.utbot.examples; - -import java.io.OutputStream; -import java.io.Reader; -import java.io.Writer; -import java.util.*; - -public class GraphAlgorithms { -// public GraphAlgorithms(T lol) { -// this.lol = lol; -// } - - private class GraphAlgorithms1 { - T a; - R b; - int c; - - GraphAlgorithms1(T a, R b, int c) { - this.a = a; - this.b = b; - this.c = c; - } - } - public static GraphAlgorithms GRAPH = new GraphAlgorithms(1, null); - public GraphAlgorithms(int a, T lol) { - this.a = a; - this.lol = lol; - } - int a; - public T lol; - - int[] array = {1, 2, 3}; -// ArrayList arr2; - -// public boolean bfs(Graph graph, int startNodeNumber, int goalNodeNumber) { -// Deque queue = new LinkedList<>();//(graph.getSize()); -// boolean[] visited = new boolean[graph.getSize()]; -// queue.push(startNodeNumber); -// visited[startNodeNumber] = true; -// while (!queue.isEmpty()) { -// int curNodeNumber = queue.pop(); -// if (curNodeNumber == goalNodeNumber) return true; -// for (int child : graph.getChildrenOf(curNodeNumber)) { -// if (!visited[child]) { -// queue.push(child); -// visited[child] = true; -// } -// } -// } -// return true; -// } -// -// public boolean testFunc(ArrayList> array) { -// for (int i = 0; i < array.size() - 1; i++) { -// if (array.get(i).get(i) > array.get(i + 1).get(i + 1)) { -// return true; -// } -// } -// return false; -// } -// -// public boolean testFunc1(ArrayList array) { -// for (int i = 0; i < array.size() - 1; i++) { -// if (array.get(i) > array.get(i + 1)) { -// return true; -// } -// } -// return false; -// } -// -// public boolean testFunc2(long[] array) { -// for (int i = 0; i < array.length - 1; i++) { -// if (array[i] > array[i + 1]) { -// return true; -// } -// } -// return false; -// } - - -// public Object testFunc3(ArrayList> a) { -// if (a.get(0) == null) { -// return null; -// } -// return a.get(a.size() - 1); -// } - -// public static Number testFunc3(Map>, T[]> arr) { -// return arr.entrySet().iterator().next().getKey().get(0).arr[0]; -// } - - public static int testFunc3(int[] matrix, String s) { - if (matrix[0] == 0) { - if (matrix[1] == 1) { - if (matrix[2] == 2 && s.equals("lol")) { - return 123; - } - } - } - return matrix[0]; - } - - - public static void test(String s) { - if (s.charAt(0) == "b".charAt(0)) { - if (s.charAt(1) == "a".charAt(0)) { - if (s.charAt(2) == "d".charAt(0)) { - if (s.charAt(3) == "!".charAt(0)) { - throw new IllegalArgumentException(); - } - } - } - } - } - - // should try to find the string with size 6 and with "!" in the end - public static void testStrRem(String str) { - if (!"world???".equals(str) && str.charAt(5) == '!' && str.length() == 6) { - throw new RuntimeException(); - } - } - - - public static int floatToInt(float x) { - if (x < 0) { - if ((int) x < 0) { - return 1; - } - return 2; // smth small to int zero - } - return 3; - } - - // should find all branches that return -2, -1, 0, 1, 2. - public static int numberOfRootsInSquareFunction(double a, double b, double c) { - if (!Double.isFinite(a) || !Double.isFinite(b) || !Double.isFinite(c)) return -1; - if (a == 0.0 || b == 0.0 || c == 0.0) return -2; - double result = b * b - 4 * a * c; - if (result > 0) { - return 2; - } else if (result == 0) { - return 1; - } - return 0; - } - - // will never be succeeded to find the value because of floating precision - public static void floatEq(float v) { - if (v == 28.7) { - throw new IllegalArgumentException(); - } - } - - // should generate double for constant float that equals to 28.700000762939453 - public static void floatEq(double v) { - if (v == 28.7f) { - throw new IllegalArgumentException(); - } - } - - public static void diff(int a) { - a = Math.abs(a); - while (a > 0) { - a = a % 2; - } - if (a < 0) { - throw new IllegalArgumentException(); - } - throw new RuntimeException(); - } - - // should cover 100% and better when values are close to constants, - // also should generate "this" empty object - public static String extent(int a) { - if (a < -2.0) { - return "-1"; - } - if (a > 5) { - return "-2"; - } - if (a == 3) { - return "-3"; - } - if (4L < a) { - return "-4"; - } - return "0"; - } - - // should cover 100% with 3 tests - public static boolean isGreater(long a, short b, int c) { - if (b > a && a < c) { - return true; - } - return false; - } - - // should find a bad value with integer overflow - public static boolean unreachable(int x) { - int y = x * x - 2 * x + 1; - if (y < 0) throw new IllegalArgumentException(); - return true; - } - - public static boolean chars(char a) { - if (a >= 'a' && a <= 'z') { - return true; - } - return false; - } - - - -// fun propagateHandshakes(friends: Map>): Map> { -// val b = mutableMapOf>() -// val c = mutableSetOf() -// for (j in friends.values) c += j -// for ((i, j) in friends) -// for (k in j) { -// b.getOrPut(i, ::mutableSetOf).add(k) -// friends[k]?.let { b[i]?.plusAssign(it) } -// } -// for (i in c) -// if (!b.keys.contains(i)) b.getOrPut(i) { mutableSetOf() } -// for ((i, j) in b) { -// val k = j.toMutableSet() -// if (k.contains(i)) k.remove(i) -// b[i] = k -// } -// return b -// } - -// public static int testFunc3(ArrayList> arr) { -// if (arr.get(0).a == 0) { -// if (arr.get(1).a == 1) { -// return 777; -// } -// } -// return 0; -// } - -// public boolean testFunc3(java.util.concurrent.BlockingQueue a) { -// for (int i = 0; i < array.size() - 1; i++) { -// if (array.get(i).a > array.get(i + 1).a) { -// return true; -// } -// } -// return false; -// } - -// public boolean testFunc3(A a) { -//// for (int i = 0; i < array.size() - 1; i++) { -//// if (array.get(i).a > array.get(i + 1).a) { -//// return true; -//// } -//// } -// return false; -// } - -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/H.java b/utbot-framework/src/main/java/org/utbot/examples/H.java deleted file mode 100644 index c545e52660..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/H.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.utbot.examples; - -import java.util.ArrayList; - -public class H implements I { - - - @Override - public int lol2() { - return 123; - } - - @Override - public int lol3() { - return I.super.lol3(); - } - - @Override - public void lol4() { - System.out.println("LOL"); - } - - @Override - public ArrayList lol5(Object r) { - return new ArrayList(15); - } - - @Override - public int lol() { - return 777; - } -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/I.java b/utbot-framework/src/main/java/org/utbot/examples/I.java deleted file mode 100644 index c138714f55..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/I.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.utbot.examples; - -public interface I extends I1 { - int lol(); -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/I1.java b/utbot-framework/src/main/java/org/utbot/examples/I1.java deleted file mode 100644 index 4dc282a0e6..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/I1.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.utbot.examples; - -public interface I1 extends I2 { - int lol2(); - default int lol3() { - return 3; - } - - void lol4(); -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/I2.java b/utbot-framework/src/main/java/org/utbot/examples/I2.java deleted file mode 100644 index 4e7691ae47..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/I2.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.utbot.examples; - -import java.util.ArrayList; - -public interface I2 { - ArrayList lol5(K r); - -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/L.java b/utbot-framework/src/main/java/org/utbot/examples/L.java deleted file mode 100644 index 7e4abde76c..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/L.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.utbot.examples; - -public class L { - int a = 1; - - public L(int a) { - this.a = a; - } -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/ListImpl.java b/utbot-framework/src/main/java/org/utbot/examples/ListImpl.java deleted file mode 100644 index d1e7e34be3..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/ListImpl.java +++ /dev/null @@ -1,131 +0,0 @@ -package org.utbot.examples; - -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -public class ListImpl implements List { - @Override - public int size() { - return 0; - } - - @Override - public boolean isEmpty() { - return false; - } - - @Override - public boolean contains(Object o) { - return false; - } - - @NotNull - @Override - public Iterator iterator() { - return null; - } - - @NotNull - @Override - public Object[] toArray() { - return new Object[0]; - } - - @NotNull - @Override - public T1[] toArray(@NotNull T1[] t1s) { - return null; - } - - @Override - public boolean add(T t) { - return false; - } - - @Override - public boolean remove(Object o) { - return false; - } - - @Override - public boolean containsAll(@NotNull Collection collection) { - return false; - } - - @Override - public boolean addAll(@NotNull Collection collection) { - return false; - } - - @Override - public boolean addAll(int i, @NotNull Collection collection) { - return false; - } - - @Override - public boolean removeAll(@NotNull Collection collection) { - return false; - } - - @Override - public boolean retainAll(@NotNull Collection collection) { - return false; - } - - @Override - public void clear() { - - } - - @Override - public T get(int i) { - return null; - } - - @Override - public T set(int i, T t) { - return null; - } - - @Override - public void add(int i, T t) { - - } - - @Override - public T remove(int i) { - return null; - } - - @Override - public int indexOf(Object o) { - return 0; - } - - @Override - public int lastIndexOf(Object o) { - return 0; - } - - @NotNull - @Override - public ListIterator listIterator() { - return null; - } - - @NotNull - @Override - public ListIterator listIterator(int i) { - return null; - } - - @NotNull - @Override - public List subList(int i, int i1) { - return null; - } -} diff --git a/utbot-framework/src/main/java/org/utbot/examples/PrimitiveFields.java b/utbot-framework/src/main/java/org/utbot/examples/PrimitiveFields.java deleted file mode 100644 index 9d55af247b..0000000000 --- a/utbot-framework/src/main/java/org/utbot/examples/PrimitiveFields.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.utbot.examples; - -/** - * A class with private fields of primitive type - * having default constructor, setters and direct accessors for them. - */ -public class PrimitiveFields { - private int a; - protected int b; - - public PrimitiveFields() { - } - - public void setA(int a) { - this.a = a; - } - - public int getB() { - return b; - } -} From 1cc03c3c2173dad1ed6d80815c2fe6dd61c59928 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 20 Dec 2022 18:43:24 +0300 Subject: [PATCH 20/30] bug fixes --- .../org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt | 4 ++-- .../greyboxfuzzer/generator/GeneratorConfigurator.kt | 2 +- .../greyboxfuzzer/generator/QuickCheckExtensions.kt | 2 ++ .../engine/greyboxfuzzer/mutator/SeedCollector.kt | 2 +- .../quickcheck/generator/ComponentizedGenerator.kt | 12 ++++++------ .../greyboxfuzzer/quickcheck/generator/Generator.kt | 2 +- .../generator/java/util/CollectionGenerator.kt | 2 +- .../internal/generator/CompositeGenerator.kt | 5 +++-- .../kotlin/org/utbot/external/api/UtBotJavaApi.kt | 2 +- 9 files changed, 18 insertions(+), 15 deletions(-) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt index a211d18924..edd387c762 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt @@ -63,7 +63,7 @@ class GreyBoxFuzzer( var regenerateThis = false val thisInstancesHistory = ArrayDeque() val startTime = System.currentTimeMillis() - val endTime = startTime + timeBudgetInMillis / percentageOfTimeBudgetToChangeMode + val endTime = startTime + timeBudgetInMillis / (100L / percentageOfTimeBudgetToChangeMode) var iterationNumber = 0 while (System.currentTimeMillis() < endTime) { try { @@ -160,7 +160,7 @@ class GreyBoxFuzzer( if (seeds == null || seeds!!.seedsSize() == 0) return if (seeds!!.all { it.parameters.isEmpty() }) return val startTime = System.currentTimeMillis() - val endTime = startTime + timeBudgetInMillis / percentageOfTimeBudgetToChangeMode + val endTime = startTime + timeBudgetInMillis / (100L / percentageOfTimeBudgetToChangeMode) var iterationNumber = 0 while (System.currentTimeMillis() < endTime) { if (timeRemain < 0 || isMethodCovered()) return diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt index 5976e70924..5f6731e694 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt @@ -27,7 +27,7 @@ object GeneratorConfigurator { private val maxDouble: Double = 100.0 private val minStringLength: Int = 1 private val maxStringLength: Int = 5 - val minCollectionSize: Int = 1 + val minCollectionSize: Int = 0 val maxCollectionSize: Int = 5 val sizeAnnotationInstance: Size diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt index 8cacf90e02..74742f6ba3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -15,6 +15,7 @@ import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.engine.greyboxfuzzer.quickcheck.internal.FakeAnnotatedTypeFactory import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.ArrayGenerator +import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.CompositeGenerator import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.GeneratorRepository import ru.vyarus.java.generics.resolver.GenericsResolver import ru.vyarus.java.generics.resolver.context.ConstructorGenericsContext @@ -41,6 +42,7 @@ fun Generator.getComponents(): List = when (this) { is org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -> this.componentGenerators() is ArrayGenerator -> listOf(this.component) + is CompositeGenerator -> this.composed.map { it.item } else -> emptyList() } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt index 6c57002766..9cf8897317 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt @@ -2,7 +2,7 @@ package org.utbot.engine.greyboxfuzzer.mutator import kotlin.random.Random -class SeedCollector(private val maxSize: Int = 50, private val methodInstructionsIds: Set) { +class SeedCollector(private val maxSize: Int = 100, private val methodInstructionsIds: Set) { private val seeds = ArrayList(maxSize) fun calcSeedScore(coverage: Set): Double = diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt index 2ede4df522..ef3f18c8a0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt @@ -16,8 +16,8 @@ import java.util.Collections * @param type class token for type of property parameter this generator * is applicable to */ -abstract class ComponentizedGenerator constructor(type: Class<*>) : org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator(type) { - private val components: MutableList = ArrayList() +abstract class ComponentizedGenerator constructor(type: Class<*>) : Generator(type) { + private val components: MutableList = ArrayList() /** * {@inheritDoc} @@ -35,7 +35,7 @@ abstract class ComponentizedGenerator constructor(type: Class<*>) : org.utbot.en } override fun addComponentGenerators( - newComponents: List + newComponents: List ) { require(newComponents.size == numberOfNeededComponents()) { String.format( @@ -89,12 +89,12 @@ abstract class ComponentizedGenerator constructor(type: Class<*>) : org.utbot.en /** * @return this generator's component generators */ - fun componentGenerators(): List { + fun componentGenerators(): List { return Collections.unmodifiableList(components) } - override fun copy(): org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator { - return (super.copy() as org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator).also { + override fun copy(): Generator { + return (super.copy() as ComponentizedGenerator).also { it.components.addAll(components.map { it.copy() }) } } diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt index a311a36bb4..20784172ec 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt @@ -40,7 +40,7 @@ abstract class Generator protected constructor(types: List>) : Gen { return when (generationState) { GenerationState.REGENERATE -> { val possibleConstant = - if (Random.getTrue(20)) { + if (Random.getTrue(25)) { getConstant() } else null (possibleConstant ?: generate(random, status)).also { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt index 3ed0cda21e..b9e399d392 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt @@ -22,7 +22,7 @@ import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness * * @param the type of collection generated */ -abstract class CollectionGenerator(type: Class<*>) : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(type) { +abstract class CollectionGenerator(type: Class<*>) : ComponentizedGenerator(type) { private var sizeRange: Size? = null private var distinct = false diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt index 593a410231..99283dec0a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt @@ -12,7 +12,7 @@ import java.lang.reflect.AnnotatedElement import java.lang.reflect.AnnotatedType class CompositeGenerator(composed: List>) : Generator(Any::class.java) { - private val composed: MutableList> + val composed: MutableList> private var previousChosenGenerator: Generator? = null init { @@ -122,10 +122,11 @@ class CompositeGenerator(composed: List>) : Generator(Any::c override fun copy(): Generator { val composedCopies = composed.map { Weighted(it.item.copy(), it.weight) }.toMutableList() - val gen = Reflection.instantiate(CompositeGenerator::class.java.constructors.first(), composedCopies) as Generator + val gen = Reflection.instantiate(CompositeGenerator::class.java.constructors.first(), composedCopies) as CompositeGenerator return gen.also { it.generatedUtModel = generatedUtModel it.generationState = generationState + it.generatorContext = generatorContext it.nestedGenerators = nestedGenerators.map { it.copy() }.toMutableList() GeneratorConfigurator.configureGenerator(it, 100) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt index 4dbaf06fe0..0112b6aae0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/external/api/UtBotJavaApi.kt @@ -184,7 +184,7 @@ object UtBotJavaApi { generationTimeoutInMillis, generate = { symbolicEngine -> if (isGreyBoxFuzzing) { - symbolicEngine.greyBoxFuzzing() + symbolicEngine.greyBoxFuzzing(generationTimeoutInMillis) } else { symbolicEngine.fuzzing { defaultModelProvider -> customModelProvider.withFallback(defaultModelProvider) From 7eab043422a17f4993188090992160bbaa5a39f8 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Tue, 20 Dec 2022 18:46:14 +0300 Subject: [PATCH 21/30] removing fuzzer executor --- .../engine/greyboxfuzzer/FuzzerExecutor.kt | 311 ------------------ 1 file changed, 311 deletions(-) delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/FuzzerExecutor.kt diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/FuzzerExecutor.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/FuzzerExecutor.kt deleted file mode 100644 index 3248e690c3..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/FuzzerExecutor.kt +++ /dev/null @@ -1,311 +0,0 @@ -package org.utbot.engine.greyboxfuzzer - -import org.junit.jupiter.api.Assertions -import org.utbot.common.FileUtil -import org.utbot.common.PathUtil.getUrlsFromClassLoader -import org.utbot.engine.greyboxfuzzer.PredefinedGeneratorParameters.getMethodByName -import org.utbot.examples.GraphAlgorithms -import org.utbot.external.api.* -import org.utbot.external.api.UtBotJavaApi.fuzzingTestSets -import org.utbot.external.api.UtBotJavaApi.stopConcreteExecutorOnExit -import org.utbot.framework.plugin.api.* -import org.utbot.framework.plugin.api.util.UtContext -import org.utbot.framework.plugin.api.util.UtContext.Companion.setUtContext -import org.utbot.framework.plugin.services.JdkInfoDefaultProvider -import java.io.File -import java.lang.reflect.Method -import java.net.URISyntaxException -import java.net.URL -import java.nio.file.Path -import java.util.* -import java.util.stream.Collectors -import kotlin.io.path.ExperimentalPathApi -import kotlin.system.exitProcess - -class FuzzerExecutor { - - private val context: AutoCloseable - private val modelFactory: UtModelFactory - - init { - SootUtils.runSoot(GraphAlgorithms::class.java) - context = setUtContext(UtContext(GraphAlgorithms::class.java.classLoader)) - modelFactory = UtModelFactory() - } - - fun testSimpleFuzzing(clazz: Class<*>) { - //runSoot(StringSwitchExample::class.java) - stopConcreteExecutorOnExit = false - - val classpath = getClassPath(clazz) - val dependencyClassPath = getDependencyClassPath() - - val classUnderTestModel = modelFactory.produceCompositeModel( - classIdForType(clazz) - ) - - val methodsUnderTest = clazz.declaredMethods - val methodsInfo = methodsUnderTest.map { methodUnderTest -> - val models = modelFactory.produceAssembleModel( - methodUnderTest, - clazz, listOf(classUnderTestModel) - ) - - val methodState = EnvironmentModels( - models[classUnderTestModel], - Arrays.asList(UtPrimitiveModel("initial model"), UtPrimitiveModel(-10), UtPrimitiveModel(0)), emptyMap() - ) - TestMethodInfo( - methodUnderTest, - methodState - ) - } - - val testSets1: List = fuzzingTestSets( - methodsForAutomaticGeneration = methodsInfo, - classUnderTest = clazz, - classpath = classpath, - dependencyClassPath = dependencyClassPath!!, - mockStrategyApi = MockStrategyApi.OTHER_PACKAGES, - generationTimeoutInMillis = 100000L, - isGreyBoxFuzzing = true - ) { type: Class<*> -> - if (Int::class.javaPrimitiveType == type || Int::class.java == type) { - return@fuzzingTestSets Arrays.asList( - 0, - Int.MIN_VALUE, - Int.MAX_VALUE - ) - } - null - } - -// val generate = generate( -// listOf(methodInfo), -// testSets1, -// org.utbot.examples.manual.PredefinedGeneratorParameters.destinationClassName, -// classpath, -// dependencyClassPath!!, -// StringSwitchExample::class.java -// ) - exitProcess(0) - } - fun testSimpleFuzzing(clazz: Class<*>, funName: String) { - - - //runSoot(StringSwitchExample::class.java) - stopConcreteExecutorOnExit = false - - val classpath = getClassPath(clazz) - val dependencyClassPath = getDependencyClassPath() - - val classUnderTestModel = modelFactory.produceCompositeModel( - classIdForType(clazz) - ) - - val methodUnderTest: Method = getMethodByName( - clazz, funName - ) - - val models = modelFactory.produceAssembleModel( - methodUnderTest, - clazz, listOf(classUnderTestModel) - ) - - val methodState = EnvironmentModels( - models[classUnderTestModel], - Arrays.asList(UtPrimitiveModel("initial model"), UtPrimitiveModel(-10), UtPrimitiveModel(0)), emptyMap() - ) - - val methodInfo = TestMethodInfo( - methodUnderTest, - methodState - ) - - val testSets1: List = fuzzingTestSets( - methodsForAutomaticGeneration = listOf(methodInfo), - classUnderTest = clazz, - classpath = classpath, - dependencyClassPath = dependencyClassPath!!, - mockStrategyApi = MockStrategyApi.OTHER_PACKAGES, - generationTimeoutInMillis = 100000L, - isGreyBoxFuzzing = true - ) { type: Class<*> -> - if (Int::class.javaPrimitiveType == type || Int::class.java == type) { - return@fuzzingTestSets Arrays.asList( - 0, - Int.MIN_VALUE, - Int.MAX_VALUE - ) - } - null - } - -// val generate = generate( -// listOf(methodInfo), -// testSets1, -// org.utbot.examples.manual.PredefinedGeneratorParameters.destinationClassName, -// classpath, -// dependencyClassPath!!, -// StringSwitchExample::class.java -// ) - exitProcess(0) -// stopConcreteExecutorOnExit = false -// val classpath: String = getClassPath(clazz) -// val dependencyClassPath: String = getDependencyClassPath()!! -// val classUnderTestModel: UtCompositeModel = modelFactory.produceCompositeModel( -// classIdForType(clazz) -// ) -// val methodUnderTest = PredefinedGeneratorParameters.getMethodByName( -// clazz, funName -// ) -// val models: IdentityHashMap = modelFactory.produceAssembleModel( -// methodUnderTest, -// clazz, listOf(classUnderTestModel) -// ) -// val methodState = EnvironmentModels( -// models[classUnderTestModel], -// Arrays.asList(UtPrimitiveModel("initial model"), UtPrimitiveModel(-10), UtPrimitiveModel(0)), emptyMap() -// ) -// val methodInfo = TestMethodInfo( -// methodUnderTest, -// methodState -// ) -// val testSets: List = fuzzingTestSets( -// listOf(methodInfo), -// clazz, -// classpath, -// dependencyClassPath, -// MockStrategyApi.OTHER_PACKAGES, -// 3000L -// ) -// exitProcess(0) -// val utTestCases1: List = fuzzingTestCases( -// listOf( -// methodInfo -// ), -// clazz, -// classpath, -// dependencyClassPath, -// MockStrategyApi.OTHER_PACKAGES, -// 100000L -// ) { type: Class<*> -> -// if (Int::class.javaPrimitiveType == type || Int::class.java == type) { -// return@fuzzingTestCases Arrays.asList( -// 0, -// Int.MIN_VALUE, -// Int.MAX_VALUE -// ) -// } -// null -// } - -// generate( -// listOf(methodInfo), -// testSets, -// PredefinedGeneratorParameters.destinationClassName, -// classpath, -// dependencyClassPath, -// clazz -// ) -// val snippet2 = Snippet(CodegenLanguage.JAVA, generate) -// compileClassFile(PredefinedGeneratorParameters.destinationClassName, snippet2) - } - - private fun getClassPath(clazz: Class<*>): String { - return clazz.protectionDomain.codeSource.location.path - } - - private fun getDependencyClassPath(): String? { - val contextClassLoader = Thread.currentThread().contextClassLoader - val urls = getUrlsFromClassLoader(contextClassLoader) - return Arrays.stream(urls).map { url: URL -> - try { - return@map File(url.toURI()).toString() - } catch (e: URISyntaxException) { - Assertions.fail(e) - } - throw RuntimeException() - }.collect(Collectors.joining(File.pathSeparator)) - } -} - -internal object PredefinedGeneratorParameters { - var destinationClassName = "GeneratedTest" - fun getMethodByName(clazz: Class<*>, name: String): Method { - return clazz.declaredMethods.first { it.name == name } - } -} - - -object SootUtils { - @JvmStatic - fun runSoot(clazz: Class<*>) { - val buildDir = FileUtil.locateClassPath(clazz) ?: FileUtil.isolateClassFiles(clazz) - val buildDirPath = buildDir.toPath() - - if (buildDirPath != previousBuildDir) { - org.utbot.framework.util.SootUtils.runSoot(listOf(buildDirPath), null, true, JdkInfoDefaultProvider().info) - previousBuildDir = buildDirPath - } - } - - private var previousBuildDir: Path? = null -} - -fun fields( - classId: ClassId, - vararg fields: Pair -): MutableMap { - return fields - .associate { - val fieldId = FieldId(classId, it.first) - val fieldValue = when (val value = it.second) { - is UtModel -> value - else -> UtPrimitiveModel(value) - } - fieldId to fieldValue - } - .toMutableMap() -} - -@OptIn(ExperimentalPathApi::class) -fun main() { -// val random = GreyBoxFuzzerGenerators.sourceOfRandomness -// val status = GreyBoxFuzzerGenerators.genStatus -// withUtContext(UtContext(GraphAlgorithms::class.java.classLoader)) { -// val gen = IntegerGenerator() -// val generatedInt = gen.generateWithState(random, status) -// println(generatedInt) -// gen.generationState = GenerationState.CACHE -// println(gen.generateWithState(random, status)) -// } -// -// exitProcess(0) -// val cl = Files.walk(Paths.get("utbot-framework/src/main/java/org/utbot/example/")).toList() -// .filter { it!!.name.endsWith(".java") } -// .map { it.toFile().absolutePath.substringAfterLast("java/").replace('/', '.').substringBeforeLast(".java") } -// .map { Class.forName(it) } -//// //114!! -// var i = 0 -// for (c in cl) { -// ++i -// //if (c.name != "org.utbot.example.casts.GenericCastExample") continue -// //if (i < 169) continue -// val methods = c.declaredMethods.filter { it.parameters.isNotEmpty() }.filter { !it.name.contains('$') } -// for (m in methods) { -// println("$i CLASS = ${c.name} from ${cl.size} method = ${m.name}") -// try { -// FuzzerExecutor().testSimpleFuzzing(c, m.name) -// } catch (e: RuntimeException) { -// println("No method source") -// } -// } -// } - - repeat(1) { - FuzzerExecutor().testSimpleFuzzing(GraphAlgorithms::class.java, "testFunc3") - //FuzzerExecutor().testSimpleFuzzing(GraphAlgorithms::class.java) - } - //FuzzerExecutor().testSimpleFuzzing(DateFormatterTest::class.java, "testLocalDateTimeSerialization") -} \ No newline at end of file From 3018dd75bbbafa6bc6370a9b0862261496d09562 Mon Sep 17 00:00:00 2001 From: DaniilStepanov Date: Wed, 28 Dec 2022 18:29:04 +0300 Subject: [PATCH 22/30] Global refactorings --- settings.gradle.kts | 1 + .../utbot/cli/GenerateTestsAbstractCommand.kt | 17 +- .../kotlin/org/utbot/common/KClassUtil.kt | 7 +- .../kotlin/org/utbot/framework/UtSettings.kt | 7 +- .../org/utbot/framework/plugin/api/Api.kt | 2 +- .../framework/plugin/api/UtExecutionResult.kt | 8 +- utbot-framework/build.gradle | 1 + .../org/utbot/engine/UtBotSymbolicEngine.kt | 26 +- .../quickcheck/internal/Zilch.kt | 3 - .../internal/generator/ZilchGenerator.kt | 20 - .../greyboxfuzzer/util/CustomClassLoader.kt | 9 - .../util/GreyBoxFuzzingStatisticPrinter.kt | 51 -- .../codegen/tree/CgMethodConstructor.kt | 1 + .../framework/plugin/api/TestCaseGenerator.kt | 3 + .../utbot/framework/plugin/api/TestFlow.kt | 2 + .../plugin/api/UtBotTestCaseGenerator.kt | 495 ------------------ .../framework/process/EngineProcessMain.kt | 1 + .../generated/EngineProcessModel.Generated.kt | 93 ++-- .../generated/EngineProcessRoot.Generated.kt | 2 +- .../RdInstrumenterAdapter.Generated.kt | 4 +- .../RdSourceFindingStrategy.Generated.kt | 4 +- .../org/utbot/framework/util/SootUtils.kt | 25 - .../org/utbot/fuzzer/FuzzerFunctions.kt | 57 +- utbot-greyboxfuzzer/build.gradle | 37 ++ .../org/utbot}/greyboxfuzzer/GreyBoxFuzzer.kt | 169 +++--- .../greyboxfuzzer/coverage/GlobalCoverage.kt | 2 +- .../greyboxfuzzer/generator/DataGenerator.kt | 20 +- .../utbot}/greyboxfuzzer/generator/FField.kt | 8 +- .../greyboxfuzzer/generator/FParameter.kt | 12 +- .../greyboxfuzzer/generator/FThisInstance.kt | 6 +- .../generator/GeneratorConfigurator.kt | 22 +- .../GreyBoxFuzzerGeneratorsAndSettings.kt | 18 +- .../generator/QuickCheckExtensions.kt | 25 +- .../generator/UTGeneratorRepository.kt | 14 +- .../userclasses/UserClassGenerator.kt | 19 +- .../generator/ClassesInstanceGenerator.kt | 10 +- .../ConstructorBasedInstanceGenerator.kt | 10 +- .../generator/ExecutableInvoker.kt | 16 +- .../userclasses/generator/GenerationMethod.kt | 2 +- .../generator/InstanceGenerator.kt | 2 +- ...terfaceImplementationsInstanceGenerator.kt | 18 +- .../userclasses/generator/ObjectGenerator.kt | 20 +- .../generator/ReflectionClassGenerator.kt | 12 +- .../generator/ReflectionTypeGenerator.kt | 12 +- .../StaticsBasedInstanceGenerator.kt | 8 +- .../StaticsFieldBasedInstanceGenerator.kt | 12 +- .../StaticsMethodBasedInstanceGenerator.kt | 14 +- .../generator/UnsafeBasedInstanceGenerator.kt | 16 +- .../utbot}/greyboxfuzzer/mutator/Mutator.kt | 20 +- .../greyboxfuzzer/mutator/ObjectMerger.kt | 4 +- .../org/utbot}/greyboxfuzzer/mutator/Seed.kt | 9 +- .../greyboxfuzzer/mutator/SeedCollector.kt | 7 +- .../quickcheck/NonTrackingGenerationStatus.kt | 10 +- .../generator/ComponentizedGenerator.kt | 18 +- .../quickcheck/generator/DecimalGenerator.kt | 2 +- .../quickcheck/generator/Distinct.kt | 2 +- .../greyboxfuzzer/quickcheck/generator/Gen.kt | 4 +- .../quickcheck/generator/GenerationState.kt | 2 +- .../quickcheck/generator/GenerationStatus.kt | 2 +- .../quickcheck/generator/Generator.kt | 18 +- .../generator/GeneratorConfiguration.kt | 2 +- .../GeneratorConfigurationException.kt | 2 +- .../quickcheck/generator/GeneratorContext.kt | 9 +- .../quickcheck/generator/Generators.kt | 4 +- .../quickcheck/generator/InRange.kt | 2 +- .../quickcheck/generator/IntegralGenerator.kt | 2 +- .../quickcheck/generator/Lambdas.kt | 12 +- .../quickcheck/generator/NullAllowed.kt | 2 +- .../quickcheck/generator/Precision.kt | 2 +- .../quickcheck/generator/Size.kt | 2 +- .../quickcheck/generator/VoidGenerator.kt | 6 +- .../java/lang/AbstractStringGenerator.kt | 12 +- .../generator/java/lang/BooleanGenerator.kt | 10 +- .../generator/java/lang/ByteGenerator.kt | 14 +- .../generator/java/lang/CharacterGenerator.kt | 14 +- .../generator/java/lang/DoubleGenerator.kt | 14 +- .../quickcheck/generator/java/lang/Encoded.kt | 8 +- .../generator/java/lang/FloatGenerator.kt | 14 +- .../generator/java/lang/IntegerGenerator.kt | 14 +- .../generator/java/lang/LongGenerator.kt | 14 +- .../java/lang/PrimitiveBooleanGenerator.kt | 10 +- .../java/lang/PrimitiveByteGenerator.kt | 14 +- .../java/lang/PrimitiveCharGenerator.kt | 14 +- .../java/lang/PrimitiveDoubleGenerator.kt | 14 +- .../java/lang/PrimitiveFloatGenerator.kt | 14 +- .../java/lang/PrimitiveIntGenerator.kt | 14 +- .../java/lang/PrimitiveLongGenerator.kt | 14 +- .../java/lang/PrimitiveShortGenerator.kt | 14 +- .../generator/java/lang/ShortGenerator.kt | 14 +- .../generator/java/lang/StringGenerator.kt | 4 +- .../generator/java/lang/strings/CodePoints.kt | 2 +- .../java/math/BigDecimalGenerator.kt | 18 +- .../java/math/BigIntegerGenerator.kt | 16 +- .../java/nio/charset/CharsetGenerator.kt | 10 +- .../generator/java/time/ClockGenerator.kt | 14 +- .../generator/java/time/DurationGenerator.kt | 14 +- .../generator/java/time/InstantGenerator.kt | 14 +- .../generator/java/time/LocalDateGenerator.kt | 14 +- .../java/time/LocalDateTimeGenerator.kt | 14 +- .../generator/java/time/LocalTimeGenerator.kt | 14 +- .../generator/java/time/MonthDayGenerator.kt | 14 +- .../java/time/OffsetDateTimeGenerator.kt | 14 +- .../java/time/OffsetTimeGenerator.kt | 14 +- .../generator/java/time/PeriodGenerator.kt | 16 +- .../generator/java/time/YearGenerator.kt | 14 +- .../generator/java/time/YearMonthGenerator.kt | 14 +- .../generator/java/time/ZoneIdGenerator.kt | 10 +- .../java/time/ZoneOffsetGenerator.kt | 14 +- .../java/time/ZonedDateTimeGenerator.kt | 14 +- .../generator/java/util/ArrayListGenerator.kt | 2 +- .../generator/java/util/BitSetGenerator.kt | 10 +- .../java/util/CollectionGenerator.kt | 12 +- .../generator/java/util/DateGenerator.kt | 16 +- .../generator/java/util/HashMapGenerator.kt | 2 +- .../generator/java/util/HashSetGenerator.kt | 2 +- .../generator/java/util/HashtableGenerator.kt | 2 +- .../java/util/LinkedHashMapGenerator.kt | 2 +- .../java/util/LinkedHashSetGenerator.kt | 2 +- .../java/util/LinkedListGenerator.kt | 2 +- .../generator/java/util/ListGenerator.kt | 2 +- .../generator/java/util/LocaleGenerator.kt | 12 +- .../generator/java/util/MapGenerator.kt | 14 +- .../java/util/OptionalDoubleGenerator.kt | 16 +- .../generator/java/util/OptionalGenerator.kt | 12 +- .../java/util/OptionalIntGenerator.kt | 16 +- .../java/util/OptionalLongGenerator.kt | 16 +- .../java/util/PropertiesGenerator.kt | 14 +- .../quickcheck/generator/java/util/RFC4122.kt | 16 +- .../generator/java/util/SetGenerator.kt | 4 +- .../generator/java/util/StackGenerator.kt | 2 +- .../generator/java/util/TimeZoneGenerator.kt | 12 +- .../generator/java/util/VectorGenerator.kt | 2 +- .../java/util/concurrent/CallableGenerator.kt | 14 +- .../java/util/function/BiFunctionGenerator.kt | 16 +- .../util/function/BiPredicateGenerator.kt | 20 +- .../util/function/BinaryOperatorGenerator.kt | 16 +- .../util/function/DoubleFunctionGenerator.kt | 16 +- .../java/util/function/FunctionGenerator.kt | 16 +- .../util/function/IntFunctionGenerator.kt | 16 +- .../util/function/LongFunctionGenerator.kt | 16 +- .../java/util/function/PredicateGenerator.kt | 20 +- .../java/util/function/SupplierGenerator.kt | 16 +- .../function/ToDoubleBiFunctionGenerator.kt | 20 +- .../function/ToDoubleFunctionGenerator.kt | 20 +- .../util/function/ToIntBiFunctionGenerator.kt | 20 +- .../util/function/ToIntFunctionGenerator.kt | 20 +- .../function/ToLongBiFunctionGenerator.kt | 20 +- .../util/function/ToLongFunctionGenerator.kt | 20 +- .../util/function/UnaryOperatorGenerator.kt | 16 +- .../internal/DefaultMethodHandleMaker.kt | 2 +- .../internal/FakeAnnotatedTypeFactory.kt | 2 +- .../FakeAnnotatedTypeFactoryWithType.kt | 2 +- .../internal/GeometricDistribution.kt | 4 +- .../quickcheck/internal/Items.kt | 4 +- .../internal/ParameterTypeContext.kt | 10 +- .../quickcheck/internal/Ranges.kt | 4 +- .../quickcheck/internal/Reflection.kt | 2 +- .../internal/ReflectionException.kt | 2 +- .../quickcheck/internal/Weighted.kt | 2 +- .../quickcheck/internal/Zilch.kt | 3 + .../generator/AbstractGenerationStatus.kt | 8 +- .../internal/generator/ArrayGenerator.kt | 18 +- .../internal/generator/CompositeGenerator.kt | 16 +- .../internal/generator/EnumGenerator.kt | 11 +- .../internal/generator/GeneratorRepository.kt | 22 +- .../internal/generator/LambdaGenerator.kt | 8 +- .../generator/MarkerInterfaceGenerator.kt | 14 +- .../internal/generator/NullableGenerator.kt | 16 +- .../generator/SimpleGenerationStatus.kt | 6 +- .../internal/generator/ZilchGenerator.kt | 18 + .../quickcheck/random/SourceOfRandomness.kt | 6 +- .../greyboxfuzzer/util/CoverageCollector.kt | 2 +- .../greyboxfuzzer/util/CustomClassLoader.kt | 9 + .../util/FuzzerIllegalStateException.kt | 2 +- .../util/FuzzerUtModelConstructor.kt | 9 + .../greyboxfuzzer/util/GenericsReplacer.kt | 2 +- .../util/GreyBoxFuzzingStatisticPrinter.kt | 51 ++ .../utbot}/greyboxfuzzer/util/KotlinUtils.kt | 21 +- .../org/utbot/greyboxfuzzer/util/Logger.kt | 6 + .../greyboxfuzzer/util/ReflectionUtils.kt | 7 +- .../utbot}/greyboxfuzzer/util/SootUtils.kt | 49 +- .../utbot}/greyboxfuzzer/util/UtBotUtils.kt | 30 +- .../util/UtGreyBoxFuzzedExecution.kt | 12 +- .../greyboxfuzzer/util/kcheck/Common.kt | 2 +- .../greyboxfuzzer/util/kcheck/RandomEx.kt | 2 +- .../instrumentation/et/TraceHandler.kt | 21 +- .../execution/FuzzerConcreteExecutor.kt | 91 ++++ ...utionInstrumentationWithStatsCollection.kt | 94 ++++ .../UtFuzzingExecutionInstrumentation.kt | 310 +++++------ .../constructors/MockValueConstructor.kt | 43 +- .../execution/phases/PhasesController.kt | 23 +- .../phases/ValueConstructionContext.kt | 5 +- .../instrumentation/mock/MockClassVisitor.kt | 60 +-- .../generator/UtTestsDialogProcessor.kt | 1 + .../intellij/plugin/process/EngineProcess.kt | 2 + .../main/kotlin/org/utbot/contest/Contest.kt | 1 - .../org/utbot/contest/GreyBoxFuzzerContest.kt | 47 +- .../org/utbot/rd/models/EngineProcessModel.kt | 1 + 198 files changed, 1629 insertions(+), 1926 deletions(-) delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Zilch.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt delete mode 100644 utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/UtBotTestCaseGenerator.kt create mode 100644 utbot-greyboxfuzzer/build.gradle rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/GreyBoxFuzzer.kt (64%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/coverage/GlobalCoverage.kt (84%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/DataGenerator.kt (88%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/FField.kt (87%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/FParameter.kt (83%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/FThisInstance.kt (81%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/GeneratorConfigurator.kt (85%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt (82%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/QuickCheckExtensions.kt (93%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/UTGeneratorRepository.kt (70%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt (93%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt (87%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt (89%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt (69%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt (51%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt (60%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt (92%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt (71%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt (76%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt (86%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt (78%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt (83%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt (81%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt (86%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/mutator/Mutator.kt (92%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/mutator/ObjectMerger.kt (72%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/mutator/Seed.kt (76%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/mutator/SeedCollector.kt (91%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt (61%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt (80%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt (86%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/Distinct.kt (90%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/Gen.kt (83%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/GenerationState.kt (56%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt (90%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/Generator.kt (95%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt (92%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt (87%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt (62%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/Generators.kt (93%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/InRange.kt (97%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt (86%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/Lambdas.kt (90%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/NullAllowed.kt (89%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/Precision.kt (89%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/Size.kt (89%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt (74%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt (70%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt (57%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt (68%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt (70%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt (73%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt (78%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt (70%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt (71%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt (72%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt (56%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt (70%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt (70%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt (73%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt (70%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt (72%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt (72%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt (70%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt (70%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt (88%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt (98%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt (84%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt (77%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt (75%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt (83%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt (76%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt (74%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt (77%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt (81%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt (77%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt (79%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt (80%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt (80%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt (82%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt (76%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt (79%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt (58%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt (79%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt (82%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt (61%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt (61%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt (91%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt (76%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt (60%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt (60%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt (78%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt (63%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt (63%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt (67%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt (73%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt (57%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt (90%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt (67%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt (74%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt (66%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt (66%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt (79%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt (90%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt (64%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt (63%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt (58%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt (64%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt (58%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt (58%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt (55%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt (55%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt (54%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt (56%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt (54%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt (54%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt (54%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt (55%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt (56%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt (54%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt (56%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt (54%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt (56%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt (54%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt (55%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt (96%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt (96%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt (98%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt (84%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/Items.kt (89%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt (97%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/Ranges.kt (95%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/Reflection.kt (99%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/ReflectionException.kt (72%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/Weighted.kt (78%) create mode 100644 utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Zilch.kt rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt (53%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt (91%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt (88%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt (68%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt (93%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt (65%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt (79%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt (80%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt (51%) create mode 100644 utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt (98%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/CoverageCollector.kt (93%) create mode 100644 utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/CustomClassLoader.kt rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/FuzzerIllegalStateException.kt (58%) create mode 100644 utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/FuzzerUtModelConstructor.kt rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/GenericsReplacer.kt (98%) create mode 100644 utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/KotlinUtils.kt (63%) create mode 100644 utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/Logger.kt rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/ReflectionUtils.kt (98%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/SootUtils.kt (75%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/UtBotUtils.kt (84%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt (73%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/kcheck/Common.kt (98%) rename {utbot-framework/src/main/kotlin/org/utbot/engine => utbot-greyboxfuzzer/src/main/kotlin/org/utbot}/greyboxfuzzer/util/kcheck/RandomEx.kt (98%) create mode 100644 utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/FuzzerConcreteExecutor.kt create mode 100644 utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentationWithStatsCollection.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index 3480b63ceb..7a0ec3e3c4 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,6 +23,7 @@ include("utbot-intellij") include("utbot-sample") include("utbot-fuzzers") include("utbot-fuzzing") +include("utbot-greyboxfuzzer") include("utbot-junit-contest") include("utbot-analytics") include("utbot-analytics-torch") diff --git a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt index 1cd2cf42fb..ca9a5b1ca2 100644 --- a/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt +++ b/utbot-cli/src/main/kotlin/org/utbot/cli/GenerateTestsAbstractCommand.kt @@ -40,7 +40,6 @@ import java.nio.file.Path import java.nio.file.Paths import java.time.LocalDateTime import java.time.temporal.ChronoUnit -import org.utbot.engine.greyboxfuzzer.util.CustomClassLoader private const val LONG_GENERATION_TIMEOUT = 1_200_000L @@ -146,11 +145,16 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : val classRelativePath = classFqnToPath(classFqn) + ".class" val classAbsoluteURL = classLoader.getResource(classRelativePath) ?: return null val classAbsolutePath = - if (classAbsoluteURL.toURI().scheme == "jar") { - replaceSeparator(classAbsoluteURL.file.removePrefix("file:")) - .removeSuffix(classRelativePath) - .removeSuffix("/") - .removeSuffix("!") + if (UtSettings.useGreyBoxFuzzing) { + if (classAbsoluteURL.toURI().scheme == "jar") { + replaceSeparator(classAbsoluteURL.file.removePrefix("file:")) + .removeSuffix(classRelativePath) + .removeSuffix("/") + .removeSuffix("!") + } else { + replaceSeparator(classAbsoluteURL.toPath().toString()) + .removeSuffix(classRelativePath) + } } else { replaceSeparator(classAbsoluteURL.toPath().toString()) .removeSuffix(classRelativePath) @@ -165,7 +169,6 @@ abstract class GenerateTestsAbstractCommand(name: String, help: String) : searchDirectory: Path, chosenClassesToMockAlways: Set ): List { - CustomClassLoader.classLoader = classLoader return testCaseGenerator.generate( targetMethods, mockStrategy, diff --git a/utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt b/utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt index 69b14167f7..6030b9a106 100644 --- a/utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt +++ b/utbot-core/src/main/kotlin/org/utbot/common/KClassUtil.kt @@ -8,12 +8,7 @@ import java.lang.reflect.Method * NOTE: vararg parameters must be passed as an array of the corresponding type. */ fun Method.invokeCatching(obj: Any?, args: List) = try { - val invocation = - try { - invoke(obj, *args.toTypedArray()) - } catch (e: Throwable) { - null - } + val invocation = invoke(obj, *args.toTypedArray()) Result.success(invocation) } catch (e: InvocationTargetException) { Result.failure(e.targetException) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt index 9e19806096..6cb12e536c 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt @@ -245,7 +245,12 @@ object UtSettings : AbstractSettings(logger, defaultKeyForSettingsPath, defaultS /** * Set to true to use grey-box fuzzing */ - var useGreyBoxFuzzing: Boolean by getBooleanProperty(true) + var useGreyBoxFuzzing: Boolean by getBooleanProperty(false) + + /** + * Set to true to use grey-box fuzzing in competition mode (without asserts generation) + */ + var greyBoxFuzzingCompetitionMode: Boolean by getBooleanProperty(false) /** * Set to true to use UtCompositeModels in grey-box fuzzing process diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index b3799f47ba..1813769347 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -480,7 +480,7 @@ data class UtArrayModel( * @param instantiationCall is an [UtExecutableCallModel] to instantiate represented object. It **must** not return `null`. * @param modificationsChain is a chain of [UtStatementModel] to construct object state. */ -data class UtAssembleModel constructor( +data class UtAssembleModel private constructor( override val id: Int?, override val classId: ClassId, override val modelName: String, diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt index ed10c005ef..da5208d0de 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/UtExecutionResult.kt @@ -70,6 +70,9 @@ class ConcreteExecutionFailureException(cause: Throwable, errorFile: File, val p appendLine("Cause:\n${cause.message}") appendLine("Last 1000 lines of the error log ${errorFile.absolutePath}:") appendLine("----------------------------------------") + if (!errorFile.exists()) { + errorFile.createNewFile() + } errorFile.useLines { lines -> val lastLines = LinkedList() for (line in lines) { @@ -103,11 +106,6 @@ inline fun UtExecutionResult.onFailure(action: (exception: Throwable) -> Unit): return this } -fun UtExecutionResult.getOrThrow(): UtModel = when (this) { - is UtExecutionSuccess -> model - is UtExecutionFailure -> throw exception -} - fun UtExecutionResult.exceptionOrNull(): Throwable? = when (this) { is UtExecutionFailure -> rootCauseException is UtExecutionSuccess -> null diff --git a/utbot-framework/build.gradle b/utbot-framework/build.gradle index 7401500d4e..ea69a853d5 100644 --- a/utbot-framework/build.gradle +++ b/utbot-framework/build.gradle @@ -15,6 +15,7 @@ dependencies { api project(':utbot-summary') api project(':utbot-framework-api') api project(':utbot-rd') + api project(':utbot-greyboxfuzzer') implementation group: 'com.jetbrains.rd', name: 'rd-framework', version: rdVersion implementation group: 'com.jetbrains.rd', name: 'rd-core', version: rdVersion diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt index 15cb9fd877..57253dc4b5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/engine/UtBotSymbolicEngine.kt @@ -11,7 +11,6 @@ import org.utbot.api.exception.UtMockAssumptionViolatedException import org.utbot.common.bracket import org.utbot.common.debug import org.utbot.engine.MockStrategy.NO_MOCKS -import org.utbot.engine.greyboxfuzzer.GreyBoxFuzzer import org.utbot.engine.pc.* import org.utbot.engine.selectors.* import org.utbot.engine.selectors.nurs.NonUniformRandomSearch @@ -33,9 +32,8 @@ import org.utbot.framework.UtSettings.pathSelectorStepsLimit import org.utbot.framework.UtSettings.pathSelectorType import org.utbot.framework.UtSettings.processUnknownStatesDuringConcreteExecution import org.utbot.framework.UtSettings.useDebugVisualization -import org.utbot.framework.concrete.UtConcreteExecutionData -import org.utbot.framework.concrete.UtConcreteExecutionResult -import org.utbot.framework.concrete.UtExecutionInstrumentation +import org.utbot.framework.concrete.* +import org.utbot.framework.concrete.constructors.UtModelConstructor import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.Step import org.utbot.framework.plugin.api.util.* @@ -44,6 +42,8 @@ import org.utbot.framework.util.sootMethod import org.utbot.fuzzer.* import org.utbot.fuzzing.* import org.utbot.fuzzing.utils.Trie +import org.utbot.greyboxfuzzer.GreyBoxFuzzer +import org.utbot.greyboxfuzzer.util.FuzzerUtModelConstructor import org.utbot.instrumentation.ConcreteExecutor import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionData import org.utbot.instrumentation.instrumentation.execution.UtConcreteExecutionResult @@ -51,6 +51,7 @@ import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrument import soot.jimple.Stmt import soot.tagkit.ParamNamesTag import java.lang.reflect.Method +import java.util.* import kotlin.system.measureTimeMillis val logger = KotlinLogging.logger {} @@ -337,7 +338,7 @@ class UtBotSymbolicEngine( fun fuzzing(until: Long = Long.MAX_VALUE, transform: (JavaValueProvider) -> JavaValueProvider = { it }) = flow { val isFuzzable = methodUnderTest.parameters.all { classId -> classId != Method::class.java.id && // causes the instrumented process crash at invocation - classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method) + classId != Class::class.java.id // causes java.lang.IllegalAccessException: java.lang.Class at sun.misc.Unsafe.allocateInstance(Native Method) } val hasMethodUnderTestParametersToFuzz = methodUnderTest.parameters.isNotEmpty() if (!isFuzzable || !hasMethodUnderTestParametersToFuzz && methodUnderTest.isStatic) { @@ -429,13 +430,22 @@ class UtBotSymbolicEngine( if (!isFuzzable) { return@flow } + val utModelConstructor = UtModelConstructor(IdentityHashMap()) + val fuzzerUtModelConstructor = FuzzerUtModelConstructor( + utModelConstructor::construct, + utModelConstructor::computeUnusedIdAndUpdate + ) try { emitAll( GreyBoxFuzzer( - concreteExecutor.pathsToUserClasses, - concreteExecutor.pathsToDependencyClasses, methodUnderTest, + collectConstantsForGreyBoxFuzzer(methodUnderTest.sootMethod, utModelConstructor), + fuzzerUtModelConstructor, + FuzzerConcreteExecutor( + concreteExecutor.pathsToUserClasses, + concreteExecutor.pathsToDependencyClasses + )::execute, timeBudget ).fuzz() ) @@ -587,7 +597,7 @@ private fun ResolvedModels.constructStateForMethod(methodUnderTest: ExecutableId return EnvironmentModels(thisInstanceBefore, paramsBefore, statics) } -private suspend fun ConcreteExecutor.executeConcretely( +internal suspend fun ConcreteExecutor.executeConcretely( methodUnderTest: ExecutableId, stateBefore: EnvironmentModels, instrumentation: List diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Zilch.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Zilch.kt deleted file mode 100644 index a17f62896a..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Zilch.kt +++ /dev/null @@ -1,3 +0,0 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal - -object Zilch diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt deleted file mode 100644 index df5180e7d7..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt +++ /dev/null @@ -1,20 +0,0 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator - -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType -import org.utbot.framework.plugin.api.UtModel -import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Zilch -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness - -class ZilchGenerator : Generator(Zilch::class.java) { - override fun generate( - random: SourceOfRandomness, - status: GenerationStatus - ): UtModel { - return UtNullModel(objectClassId)// generatorContext.utModelConstructor.construct(Zilch, classIdForType(Zilch::class.java)) - } -} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt deleted file mode 100644 index 31b2d6a357..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CustomClassLoader.kt +++ /dev/null @@ -1,9 +0,0 @@ -package org.utbot.engine.greyboxfuzzer.util - -import java.net.URLClassLoader - -object CustomClassLoader { - lateinit var classLoader: ClassLoader - - fun isClassLoaderInitialized() = this::classLoader.isInitialized -} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt b/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt deleted file mode 100644 index 5dd531b86a..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt +++ /dev/null @@ -1,51 +0,0 @@ -package org.utbot.engine.greyboxfuzzer.util - -import org.utbot.engine.logger -import org.utbot.framework.concrete.UtFuzzingConcreteExecutionResult -import org.utbot.framework.plugin.api.ExecutableId -import org.utbot.framework.plugin.api.UtExecution -import org.utbot.framework.plugin.api.util.jClass -import org.utbot.framework.plugin.api.util.signature -import org.utbot.framework.util.sootMethod -import soot.Scene -import kotlin.io.path.appendText -import kotlin.reflect.jvm.jvmName -import kotlin.reflect.jvm.kotlinFunction - -object GreyBoxFuzzingStatisticPrinter { - - fun printFuzzingStats(methods2executions: Map>) { -// //Printing to console - val clazz = methods2executions.keys.first().classId - val methodsToInstructionsNumbers = methods2executions.entries.map { (method, executions) -> - val methodInstructions = - (executions.firstOrNull() as? UtGreyBoxFuzzedExecution)?.fuzzingResult?.methodInstructionsIds ?: setOf() - method to methodInstructions - } - logger.debug { "OVERALL RESULTS:" } - logger.debug { "------------------------------------------" } - for ((method, instructions) in methodsToInstructionsNumbers) { - val coveredMethodInstructions = CoverageCollector.coverage - .filter { it.methodSignature == method.signature } - .map { it.id } - .toSet() - .filter { it in instructions } - - logger.debug { "METHOD: ${method.name}" } - logger.debug { "COVERED: ${coveredMethodInstructions.size} from ${instructions.size} ${coveredMethodInstructions.size.toDouble() / instructions.size * 100}%" } - logger.debug { "COVERED: ${coveredMethodInstructions.sorted()}" } - logger.debug { "NOT COVERED: ${instructions.filter { it !in coveredMethodInstructions }.sorted()}" } - logger.debug { "------------------" } - } - logger.debug { "------------------------------------------" } - val allInstructionsToCover = methodsToInstructionsNumbers.flatMap { it.second }.toSet() - val allInstructionsToCoverSize = allInstructionsToCover.size - val allCoveredLines = CoverageCollector.coverage - .filter { it.className.replace('/', '.') == clazz.name } - .map { it.id }.toSet() - .filter { it in allInstructionsToCover } - .size - logger.debug { "FINALLY COVERED $allCoveredLines from $allInstructionsToCoverSize ${allCoveredLines.toDouble() / allInstructionsToCoverSize * 100}%" } - logger.debug { "------------------------------------------" } - } -} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt index 05fd15fcba..6669fefe75 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/codegen/tree/CgMethodConstructor.kt @@ -159,6 +159,7 @@ import org.utbot.framework.plugin.api.util.longStreamToArrayMethodId import org.utbot.framework.plugin.api.util.streamClassId import org.utbot.framework.plugin.api.util.streamToArrayMethodId import org.utbot.framework.plugin.api.util.isStatic +import org.utbot.greyboxfuzzer.util.UtGreyBoxFuzzedExecution private const val DEEP_EQUALS_MAX_DEPTH = 5 // TODO move it to plugin settings? diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt index 7b20a293fe..ff965e2f96 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestCaseGenerator.kt @@ -36,6 +36,8 @@ import org.utbot.framework.util.ConflictTriggers import org.utbot.framework.util.SootUtils import org.utbot.framework.util.jimpleBody import org.utbot.framework.util.toModel +import org.utbot.greyboxfuzzer.util.CoverageCollector +import org.utbot.greyboxfuzzer.util.GreyBoxFuzzingStatisticPrinter import org.utbot.instrumentation.ConcreteExecutor import org.utbot.instrumentation.instrumentation.execution.UtExecutionInstrumentation import org.utbot.instrumentation.warmup @@ -131,6 +133,7 @@ open class TestCaseGenerator( generate: (engine: UtBotSymbolicEngine) -> Flow = defaultTestFlow(methodsGenerationTimeout) ): List { if (isCanceled()) return methods.map { UtMethodTestSet(it) } + if (UtSettings.useGreyBoxFuzzing) CoverageCollector.clear() val executionStartInMillis = System.currentTimeMillis() val executionTimeEstimator = ExecutionTimeEstimator(methodsGenerationTimeout, methods.size) diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt index f05c018a4a..b4581be513 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/TestFlow.kt @@ -6,6 +6,8 @@ import kotlinx.coroutines.flow.flattenConcat import kotlinx.coroutines.flow.flowOf import org.utbot.engine.UtBotSymbolicEngine import org.utbot.framework.UtSettings +import kotlin.io.path.Path +import kotlin.io.path.appendText /** * Constructs [TestFlow] for customization and creates flow producer. diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/UtBotTestCaseGenerator.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/UtBotTestCaseGenerator.kt deleted file mode 100644 index 4dfd9b27ac..0000000000 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/plugin/api/UtBotTestCaseGenerator.kt +++ /dev/null @@ -1,495 +0,0 @@ -//package org.utbot.framework.plugin.api -// -//import kotlinx.coroutines.* -//import org.utbot.common.FileUtil -//import org.utbot.common.bracket -//import org.utbot.common.runBlockingWithCancellationPredicate -//import org.utbot.common.runIgnoringCancellationException -//import org.utbot.common.trace -//import org.utbot.framework.TestSelectionStrategyType -//import org.utbot.framework.UtSettings -//import org.utbot.framework.UtSettings.checkSolverTimeoutMillis -//import org.utbot.framework.UtSettings.disableCoroutinesDebug -//import org.utbot.framework.UtSettings.utBotGenerationTimeoutInMillis -//import org.utbot.framework.UtSettings.warmupConcreteExecution -//import org.utbot.framework.codegen.model.util.checkFrameworkDependencies -//import org.utbot.framework.concrete.UtConcreteExecutionData -//import org.utbot.framework.concrete.UtExecutionInstrumentation -//import org.utbot.framework.concrete.constructors.UtModelConstructor -//import org.utbot.framework.minimization.minimizeTestCase -//import org.utbot.framework.plugin.api.util.UtContext -//import org.utbot.framework.plugin.api.util.id -//import org.utbot.framework.plugin.api.util.intArrayClassId -//import org.utbot.framework.plugin.api.util.signature -//import org.utbot.framework.plugin.api.util.utContext -//import org.utbot.framework.plugin.api.util.withUtContext -//import org.utbot.instrumentation.ConcreteExecutor -//import org.utbot.instrumentation.warmup.Warmup -//import java.io.File -//import java.nio.file.Path -//import java.util.IdentityHashMap -//import kotlin.coroutines.cancellation.CancellationException -//import kotlin.math.min -//import kotlin.reflect.KCallable -//import kotlinx.coroutines.flow.Flow -//import kotlinx.coroutines.flow.collect -//import kotlinx.coroutines.flow.flattenConcat -//import kotlinx.coroutines.flow.flowOf -//import mu.KotlinLogging -//import org.utbot.engine.* -//import org.utbot.engine.greyboxfuzzer.generator.ThisInstanceGenerator -//import org.utbot.engine.greyboxfuzzer.util.CoverageCollector -//import org.utbot.engine.greyboxfuzzer.util.CustomClassLoader -//import soot.Scene -//import soot.jimple.JimpleBody -//import soot.toolkits.graph.ExceptionalUnitGraph -//import java.net.URL -//import java.net.URLClassLoader -//import java.time.Duration -//import java.util.jar.JarFile -//import kotlin.reflect.jvm.jvmName -//import kotlin.reflect.jvm.kotlinFunction -//import kotlin.system.exitProcess -// -//object UtBotTestCaseGenerator : TestCaseGenerator { -// -// private val logger = KotlinLogging.logger {} -// private val timeoutLogger = KotlinLogging.logger(logger.name + ".timeout") -// -// lateinit var isCanceled: () -> Boolean -// -// //properties to save time on soot initialization -// private var previousBuildDir: Path? = null -// private var previousClasspath: String? = null -// private var previousTimestamp: Long? = null -// private var dependencyPaths: String = "" -// -// override fun init( -// buildDir: Path, -// classpath: String?, -// dependencyPaths: String, -// isCanceled: () -> Boolean -// ) { -// this.isCanceled = isCanceled -// if (isCanceled()) return -// -// checkFrameworkDependencies(dependencyPaths) -// -// logger.trace("Initializing ${this.javaClass.name} with buildDir = $buildDir, classpath = $classpath") -// -// //optimization: maxLastModifiedRecursivelyMillis can take time -// val timestamp = if (UtSettings.classfilesCanChange) maxLastModifiedRecursivelyMillis(buildDir, classpath) else 0 -// -// if (buildDir == previousBuildDir && classpath == previousClasspath && timestamp == previousTimestamp) { -// logger.info { "Ignoring soot initialization because parameters are the same as on previous initialization" } -// return -// } -// -// if (disableCoroutinesDebug) { -// System.setProperty(kotlinx.coroutines.DEBUG_PROPERTY_NAME, kotlinx.coroutines.DEBUG_PROPERTY_VALUE_OFF) -// } -// -// -// -// -// timeoutLogger.trace().bracket("Soot initialization") { -// val jarsPaths = classpath!!.split(":").filter { it.endsWith(".jar") } -// for (jarPath in jarsPaths) { -// val jarFile = JarFile(jarPath) -// for (jarEntry in jarFile.entries()) { -// if (jarEntry.name.endsWith(".class")) { -// val className = jarEntry.name.dropLast(6).replace('/', '.') -// SootUtils.libraryClassesToLoad.add(className) -// } -// } -// } -// SootUtils.runSoot(buildDir, classpath) -// } -// -// previousBuildDir = buildDir -// previousClasspath = classpath -// previousTimestamp = timestamp -// this.dependencyPaths = dependencyPaths -// -// //warmup -// if (warmupConcreteExecution) { -// ConcreteExecutor( -// UtExecutionInstrumentation, -// classpathForEngine, -// dependencyPaths -// ).apply { -// classLoader = utContext.classLoader -// withUtContext(UtContext(Warmup::class.java.classLoader)) { -// runBlocking { -// constructExecutionsForWarmup().forEach { (method, data) -> -// executeAsync(method, emptyArray(), data) -// } -// } -// } -// warmup() -// } -// } -// } -// -// private fun constructExecutionsForWarmup(): Sequence, UtConcreteExecutionData>> = -// UtModelConstructor(IdentityHashMap()).run { -// sequenceOf( -// Warmup::doWarmup1 to UtConcreteExecutionData( -// EnvironmentModels( -// construct(Warmup(5), Warmup::class.java.id), -// listOf(construct(Warmup(1), Warmup::class.java.id)), -// emptyMap() -// ), emptyList() -// ), -// Warmup::doWarmup2 to UtConcreteExecutionData( -// EnvironmentModels( -// construct(Warmup(1), Warmup::class.java.id), -// listOf(construct(intArrayOf(1, 2, 3), intArrayClassId)), -// emptyMap() -// ), emptyList() -// ), -// Warmup::doWarmup2 to UtConcreteExecutionData( -// EnvironmentModels( -// construct(Warmup(1), Warmup::class.java.id), -// listOf(construct(intArrayOf(1, 2, 3, 4, 5, 6), intArrayClassId)), -// emptyMap() -// ), emptyList() -// ), -// ) -// } -// -// private val classpathForEngine: String -// get() = previousBuildDir!!.toString() + (previousClasspath?.let { File.pathSeparator + it } ?: "") -// -// private fun maxLastModifiedRecursivelyMillis(buildDir: Path, classpath: String?): Long { -// val paths = mutableListOf() -// paths += buildDir.toFile() -// if (classpath != null) { -// paths += classpath.split(File.pathSeparatorChar).map { File(it) } -// } -// return FileUtil.maxLastModifiedRecursivelyMillis(paths) -// } -// -// @Throws(CancellationException::class) -// fun generateAsync( -// controller: EngineController, -// method: UtMethod<*>, -// mockStrategy: MockStrategyApi, -// chosenClassesToMockAlways: Set = Mocker.javaDefaultClasses.mapTo(mutableSetOf()) { it.id }, -// executionTimeEstimator: ExecutionTimeEstimator = ExecutionTimeEstimator(utBotGenerationTimeoutInMillis, 1) -// ): Flow { -// val engine = createSymbolicEngine( -// controller, -// method, -// mockStrategy, -// chosenClassesToMockAlways, -// executionTimeEstimator -// ) -// return createDefaultFlow(engine) -// } -// -// private fun createSymbolicEngine( -// controller: EngineController, -// method: UtMethod<*>, -// mockStrategy: MockStrategyApi, -// chosenClassesToMockAlways: Set, -// executionTimeEstimator: ExecutionTimeEstimator -// ): UtBotSymbolicEngine { -// // TODO: create classLoader from buildDir/classpath and migrate from UtMethod to MethodId? -// logger.debug("Starting symbolic execution for $method --$mockStrategy--") -// val graph = graph(method) -// -// return UtBotSymbolicEngine( -// controller, -// method, -// graph, -// classpathForEngine, -// dependencyPaths = dependencyPaths, -// mockStrategy = apiToModel(mockStrategy), -// chosenClassesToMockAlways = chosenClassesToMockAlways, -// solverTimeoutInMillis = executionTimeEstimator.updatedSolverCheckTimeoutMillis -// ) -// } -// -// private fun createDefaultFlow(engine: UtBotSymbolicEngine): Flow { -// return flowOf(engine.fuzzing()).flattenConcat() -// exitProcess(0) -// var flow = engine.traverse() -// if (UtSettings.useFuzzing) { -// flow = flowOf(flow, engine.fuzzing()).flattenConcat() -// } -// return flow -// } -// -// // CONFLUENCE:The+UtBot+Java+timeouts -// -// class ExecutionTimeEstimator(val userTimeout: Long, methodsUnderTestNumber: Int) { -// // Cut the timeout from the user in two halves -// private val halfTimeUserExpectsToWaitInMillis = userTimeout / 2 -// -// // If the half is too much for concrete execution, decrease the concrete timeout -// var concreteExecutionBudgetInMillis = -// min(halfTimeUserExpectsToWaitInMillis, 300L * methodsUnderTestNumber) -// -// // The symbolic execution time is the reminder but not longer than checkSolverTimeoutMillis times methods number -// val symbolicExecutionTimeout = userTimeout - concreteExecutionBudgetInMillis -// -// //Allow traverse at least one method for the symbolic execution timeout -// val timeslotForOneToplevelMethodTraversalInMillis = -// symbolicExecutionTimeout / (methodsUnderTestNumber * 2) -// -// // Axillary field -// private val symbolicExecutionTimePerMethod = (symbolicExecutionTimeout / methodsUnderTestNumber).toInt() -// -// // Now we calculate the solver timeout. Each method is supposed to get some time in worst-case scenario -// val updatedSolverCheckTimeoutMillis = if (symbolicExecutionTimePerMethod < checkSolverTimeoutMillis) -// symbolicExecutionTimePerMethod else checkSolverTimeoutMillis -// -// init { -// // Update the concrete execution time, if symbolic execution time is small -// // because of UtSettings.checkSolverTimeoutMillis -// concreteExecutionBudgetInMillis = userTimeout - symbolicExecutionTimeout -// require(symbolicExecutionTimeout > 10) -// require(concreteExecutionBudgetInMillis > 10) -// } -// } -// -// fun generateForSeveralMethods( -// methods: List>, -// mockStrategy: MockStrategyApi, -// chosenClassesToMockAlways: Set = Mocker.javaDefaultClasses.mapTo(mutableSetOf()) { it.id }, -// methodsGenerationTimeout: Long = utBotGenerationTimeoutInMillis, -// generate: (engine: UtBotSymbolicEngine) -> Flow = ::createDefaultFlow -// ): List { -// if (isCanceled()) return methods.map { UtTestCase(it) } -// -// val executionStartInMillis = System.currentTimeMillis() -// val executionTimeEstimator = ExecutionTimeEstimator(methodsGenerationTimeout, methods.size) -// -// val currentUtContext = utContext -// -// val method2controller = methods.associateWith { EngineController() } -// val method2executions = methods.associateWith { mutableListOf() } -// val method2errors = methods.associateWith { mutableMapOf() } -// //Init this -// //ThisInstanceGenerator.generateThis(methods.first().clazz.java) -// -// runIgnoringCancellationException { -// runBlockingWithCancellationPredicate(isCanceled) { -// for ((method, controller) in method2controller) { -// controller.job = launch(currentUtContext) { -// if (!isActive) return@launch -// //TODO!! DO NOT FORGET TO REMOVE IT -// //if (!method.displayName.contains("decodeUTF8")) return@launch -// //yield one to -// yield() -// -// generate( -// createSymbolicEngine( -// controller, -// method, -// mockStrategy, -// chosenClassesToMockAlways, -// executionTimeEstimator -// ) -// ).collect { -// when (it) { -// is UtExecution -> method2executions.getValue(method) += it -// is UtError -> method2errors.getValue(method).merge(it.description, 1, Int::plus) -// } -// } -//// generate( -//// createSymbolicEngine( -//// controller, -//// method, -//// mockStrategy, -//// chosenClassesToMockAlways, -//// executionTimeEstimator -//// ) -//// ).collect { -//// when (it) { -//// is UtExecution -> method2executions.getValue(method) += it -//// is UtError -> method2errors.getValue(method).merge(it.description, 1, Int::plus) -//// } -//// } -// } -// controller.paused = true -// } -// -// // All jobs are in the method2controller now (paused). execute them with timeout -// -// GlobalScope.launch { -// while (isActive) { -// var activeCount = 0 -// for ((method, controller) in method2controller) { -// if (!controller.job!!.isActive) continue -// activeCount++ -// -// method2controller.values.forEach { it.paused = true } -// controller.paused = false -// -// logger.info { "|> Resuming method $method" } -// val startTime = System.currentTimeMillis() -// while (controller.job!!.isActive && -// (System.currentTimeMillis() - startTime) < executionTimeEstimator.timeslotForOneToplevelMethodTraversalInMillis -// ) { -// updateLifecycle( -// executionStartInMillis, -// executionTimeEstimator, -// method2controller.values, -// this -// ) -// yield() -// } -// } -// if (activeCount == 0) break -// } -// } -// } -// } -// ConcreteExecutor.defaultPool.close() // TODO: think on appropriate way to close child processes -// -// //Printing to console -// val clazz = methods.first().clazz -// val sootClazz = Scene.v().classes.find { it.name == clazz.jvmName }!! -// val methodsToLineNumbers = sootClazz.methods.mapNotNull { -// val sig = it.bytecodeSignature.drop(1).dropLast(1).substringAfter("${clazz.jvmName}: ") -// val (sootMethod, javaMethod) = it to clazz.java.declaredMethods.find { it.signature == sig } -// if (javaMethod?.kotlinFunction != null) { -// javaMethod to sootMethod.activeBody.units -// .map { it.javaSourceStartLineNumber } -// .filter { it != -1 } -// .toSet() -// } else { -// null -// } -// } -// println("OVERALL RESULTS:") -// println("------------------------------------------") -// for ((method, lines) in methodsToLineNumbers) { -// val coveredMethodInstructions = CoverageCollector.coverage -// .filter { it.methodSignature == method.signature } -// .map { it.lineNumber } -// .toSet() -// println("METHOD: ${method.name}") -// println("COVERED: ${coveredMethodInstructions.size} from ${lines.size} ${coveredMethodInstructions.size.toDouble() / lines.size * 100}%") -// println("COVERED: ${coveredMethodInstructions.sorted()}") -// println("NOT COVERED: ${lines.filter { it !in coveredMethodInstructions }.sorted()}") -// println("------------------") -// } -// println("------------------------------------------") -// val allLinesToCover = methodsToLineNumbers.flatMap { it.second }.toSet() -// val allLinesToCoverSize = allLinesToCover.size -// val allCoveredLines = CoverageCollector.coverage -// .filter { it.className.replace('/', '.') == clazz.jvmName } -// .map { it.lineNumber }.toSet() -// .filter { it in allLinesToCover } -// .size -// println("FINALLY COVERED $allCoveredLines from $allLinesToCoverSize ${allCoveredLines.toDouble() / allLinesToCoverSize * 100}%") -// println("------------------------------------------") -// return methods.map { method -> -// UtTestCase( -// method, -// minimizeExecutions(method2executions.getValue(method)), -// jimpleBody(method), -// method2errors.getValue(method) -// ) -// } -// } -// -// private fun updateLifecycle( -// executionStartInMillis: Long, -// executionTimeEstimator: ExecutionTimeEstimator, -// controllers: Collection, -// timeoutCheckerCoroutine: CoroutineScope -// ) { -// val timePassed = System.currentTimeMillis() - executionStartInMillis -// -// if (timePassed > executionTimeEstimator.userTimeout) { -// timeoutLogger.trace { -// "Out of concrete execution time limit (" + -// "$timePassed > ${executionTimeEstimator.userTimeout}" + -// "). Cancelling coroutines" -// } -// controllers.forEach { it.job!!.cancel("Timeout") } -// timeoutCheckerCoroutine.cancel("Timeout") -// } else if (!controllers.firstOrNull()!!.executeConcretely && -// timePassed > executionTimeEstimator.symbolicExecutionTimeout -// ) { -// timeoutLogger.trace { -// "We are out of time (" + -// "$timePassed > ${executionTimeEstimator.symbolicExecutionTimeout}" + -// "). Switching to the concrete execution (extra ${executionTimeEstimator.concreteExecutionBudgetInMillis} ms)" -// } -// controllers.forEach { it.executeConcretely = true } -// } -// } -// -// override fun generate(method: UtMethod<*>, mockStrategy: MockStrategyApi): UtTestCase { -// logger.trace { "UtSettings:${System.lineSeparator()}" + UtSettings.toString() } -// -// if (isCanceled()) return UtTestCase(method) -// -// val executions = mutableListOf() -// val errors = mutableMapOf() -// -// -// runIgnoringCancellationException { -// runBlockingWithCancellationPredicate(isCanceled) { -// generateAsync(EngineController(), method, mockStrategy).collect { -// when (it) { -// is UtExecution -> executions += it -// is UtError -> errors.merge(it.description, 1, Int::plus) -// } -// } -// } -// } -// -// val minimizedExecutions = minimizeExecutions(executions) -// return UtTestCase(method, minimizedExecutions, jimpleBody(method), errors) -// } -// -// -// private fun minimizeExecutions(executions: List): List = -// if (UtSettings.testMinimizationStrategyType == TestSelectionStrategyType.DO_NOT_MINIMIZE_STRATEGY) { -// executions -// } else { -// minimizeTestCase(executions) { it.result::class.java } -// } -// -// -// fun apiToModel(mockStrategyApi: MockStrategyApi): MockStrategy = -// when (mockStrategyApi) { -// MockStrategyApi.NO_MOCKS -> MockStrategy.NO_MOCKS -// MockStrategyApi.OTHER_PACKAGES -> MockStrategy.OTHER_PACKAGES -// MockStrategyApi.OTHER_CLASSES -> MockStrategy.OTHER_CLASSES -// else -> error("Cannot map API Mock Strategy model to Engine model: $mockStrategyApi") -// } -// -// private fun graph(method: UtMethod<*>): ExceptionalUnitGraph { -// val className = method.clazz.java.name -// val clazz = Scene.v().classes.singleOrNull { it.name == className } -// ?: error("No such $className found in the Scene") -// val signature = method.callable.signature -// val sootMethod = clazz.methods.singleOrNull { it.pureJavaSignature == signature } -// ?: error("No such $signature found") -// -// val methodBody = sootMethod.jimpleBody() -// val graph = methodBody.graph() -// -// logger.trace { "JIMPLE for $method:\n${methodBody}" } -// -// return graph -// } -// -// fun jimpleBody(method: UtMethod<*>): JimpleBody { -// val clazz = Scene.v().classes.single { it.name == method.clazz.java.name } -// val signature = method.callable.signature -// val sootMethod = clazz.methods.single { it.pureJavaSignature == signature } -// -// return sootMethod.jimpleBody() -// } -//} -// -//fun JimpleBody.graph() = ExceptionalUnitGraph(this) -// diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt index 01c880caea..40dc120927 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/EngineProcessMain.kt @@ -111,6 +111,7 @@ private fun EngineProcessModel.setup(kryoHelper: KryoHelper, watchdog: IdleWatch isSymbolicEngineEnabled = params.isSymbolicEngineEnabled isFuzzingEnabled = params.isFuzzingEnabled fuzzingValue = params.fuzzingValue + isGreyBoxFuzzingEnabled = params.isGreyBoxFuzzingEnabled }) .apply { logger.info("generation ended, starting summarization, result size: ${this.size}") } .map { it.summarize(Paths.get(params.searchDirectory), sourceFile = null) } diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt index dc49b4d12e..fe18265f32 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessModel.Generated.kt @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic /** - * #### Generated from [EngineProcessModel.kt:30] + * #### Generated from [EngineProcessModel.kt:31] */ class EngineProcessModel private constructor( private val _setupUtContext: RdCall, @@ -71,9 +71,9 @@ class EngineProcessModel private constructor( bind(lifetime, protocol, "EngineProcessModel") } } - - - const val serializationHash = -6219345436129699239L + + + const val serializationHash = -5710118090342998881L } override val serializersOwner: ISerializersOwner get() = EngineProcessModel @@ -180,7 +180,7 @@ val IProtocol.engineProcessModel get() = getOrCreateExtension(EngineProcessModel /** - * #### Generated from [EngineProcessModel.kt:100] + * #### Generated from [EngineProcessModel.kt:102] */ data class FindMethodParamNamesArguments ( val classId: ByteArray, @@ -243,7 +243,7 @@ data class FindMethodParamNamesArguments ( /** - * #### Generated from [EngineProcessModel.kt:104] + * #### Generated from [EngineProcessModel.kt:106] */ data class FindMethodParamNamesResult ( val paramNames: ByteArray @@ -300,7 +300,7 @@ data class FindMethodParamNamesResult ( /** - * #### Generated from [EngineProcessModel.kt:93] + * #### Generated from [EngineProcessModel.kt:95] */ data class FindMethodsInClassMatchingSelectedArguments ( val classId: ByteArray, @@ -312,7 +312,7 @@ data class FindMethodsInClassMatchingSelectedArguments ( override val _type: KClass = FindMethodsInClassMatchingSelectedArguments::class @Suppress("UNCHECKED_CAST") - override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): FindMethodsInClassMatchingSelectedArguments { + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): FindMethodsInClassMatchingSelectedArguments { val classId = buffer.readByteArray() val methodDescriptions = buffer.readList { MethodDescription.read(ctx, buffer) } return FindMethodsInClassMatchingSelectedArguments(classId, methodDescriptions) @@ -335,7 +335,7 @@ data class FindMethodsInClassMatchingSelectedArguments ( if (other == null || other::class != this::class) return false other as FindMethodsInClassMatchingSelectedArguments - + if (!(classId contentEquals other.classId)) return false if (methodDescriptions != other.methodDescriptions) return false @@ -344,8 +344,8 @@ data class FindMethodsInClassMatchingSelectedArguments ( //hash code trait override fun hashCode(): Int { var __r = 0 - __r = __r * 31 + classId.contentHashCode() - __r = __r * 31 + methodDescriptions.hashCode() + __r = __r*31 + classId.contentHashCode() + __r = __r*31 + methodDescriptions.hashCode() return __r } //pretty print @@ -363,7 +363,7 @@ data class FindMethodsInClassMatchingSelectedArguments ( /** - * #### Generated from [EngineProcessModel.kt:97] + * #### Generated from [EngineProcessModel.kt:99] */ data class FindMethodsInClassMatchingSelectedResult ( val executableIds: ByteArray @@ -420,7 +420,7 @@ data class FindMethodsInClassMatchingSelectedResult ( /** - * #### Generated from [EngineProcessModel.kt:42] + * #### Generated from [EngineProcessModel.kt:43] */ data class GenerateParams ( val mockInstalled: Boolean, @@ -434,6 +434,7 @@ data class GenerateParams ( val isSymbolicEngineEnabled: Boolean, val isFuzzingEnabled: Boolean, val fuzzingValue: Double, + val isGreyBoxFuzzingEnabled: Boolean, val searchDirectory: String ) : IPrintable { //companion @@ -454,8 +455,9 @@ data class GenerateParams ( val isSymbolicEngineEnabled = buffer.readBool() val isFuzzingEnabled = buffer.readBool() val fuzzingValue = buffer.readDouble() + val isGreyBoxFuzzingEnabled = buffer.readBool() val searchDirectory = buffer.readString() - return GenerateParams(mockInstalled, staticsMockingIsConfigureda, conflictTriggers, methods, mockStrategy, chosenClassesToMockAlways, timeout, generationTimeout, isSymbolicEngineEnabled, isFuzzingEnabled, fuzzingValue, searchDirectory) + return GenerateParams(mockInstalled, staticsMockingIsConfigureda, conflictTriggers, methods, mockStrategy, chosenClassesToMockAlways, timeout, generationTimeout, isSymbolicEngineEnabled, isFuzzingEnabled, fuzzingValue, isGreyBoxFuzzingEnabled, searchDirectory) } override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: GenerateParams) { @@ -470,6 +472,7 @@ data class GenerateParams ( buffer.writeBool(value.isSymbolicEngineEnabled) buffer.writeBool(value.isFuzzingEnabled) buffer.writeDouble(value.fuzzingValue) + buffer.writeBool(value.isGreyBoxFuzzingEnabled) buffer.writeString(value.searchDirectory) } @@ -497,6 +500,7 @@ data class GenerateParams ( if (isSymbolicEngineEnabled != other.isSymbolicEngineEnabled) return false if (isFuzzingEnabled != other.isFuzzingEnabled) return false if (fuzzingValue != other.fuzzingValue) return false + if (isGreyBoxFuzzingEnabled != other.isGreyBoxFuzzingEnabled) return false if (searchDirectory != other.searchDirectory) return false return true @@ -515,6 +519,7 @@ data class GenerateParams ( __r = __r*31 + isSymbolicEngineEnabled.hashCode() __r = __r*31 + isFuzzingEnabled.hashCode() __r = __r*31 + fuzzingValue.hashCode() + __r = __r*31 + isGreyBoxFuzzingEnabled.hashCode() __r = __r*31 + searchDirectory.hashCode() return __r } @@ -533,6 +538,7 @@ data class GenerateParams ( print("isSymbolicEngineEnabled = "); isSymbolicEngineEnabled.print(printer); println() print("isFuzzingEnabled = "); isFuzzingEnabled.print(printer); println() print("fuzzingValue = "); fuzzingValue.print(printer); println() + print("isGreyBoxFuzzingEnabled = "); isGreyBoxFuzzingEnabled.print(printer); println() print("searchDirectory = "); searchDirectory.print(printer); println() } printer.print(")") @@ -543,7 +549,7 @@ data class GenerateParams ( /** - * #### Generated from [EngineProcessModel.kt:60] + * #### Generated from [EngineProcessModel.kt:62] */ data class GenerateResult ( val notEmptyCases: Int, @@ -606,7 +612,7 @@ data class GenerateResult ( /** - * #### Generated from [EngineProcessModel.kt:112] + * #### Generated from [EngineProcessModel.kt:114] */ data class GenerateTestReportArgs ( val eventLogMessage: String?, @@ -699,7 +705,7 @@ data class GenerateTestReportArgs ( /** - * #### Generated from [EngineProcessModel.kt:121] + * #### Generated from [EngineProcessModel.kt:123] */ data class GenerateTestReportResult ( val notifyMessage: String, @@ -768,7 +774,7 @@ data class GenerateTestReportResult ( /** - * #### Generated from [EngineProcessModel.kt:31] + * #### Generated from [EngineProcessModel.kt:32] */ data class JdkInfo ( val path: String, @@ -831,64 +837,61 @@ data class JdkInfo ( /** - * #### Generated from [EngineProcessModel.kt:88] + * #### Generated from [EngineProcessModel.kt:90] */ -data class MethodDescription( +data class MethodDescription ( val name: String, val containingClass: String?, val parametersTypes: List ) : IPrintable { //companion - + companion object : IMarshaller { override val _type: KClass = MethodDescription::class - + @Suppress("UNCHECKED_CAST") - override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): MethodDescription { + override fun read(ctx: SerializationCtx, buffer: AbstractBuffer): MethodDescription { val name = buffer.readString() val containingClass = buffer.readNullable { buffer.readString() } val parametersTypes = buffer.readList { buffer.readNullable { buffer.readString() } } return MethodDescription(name, containingClass, parametersTypes) } - - override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: MethodDescription) { + + override fun write(ctx: SerializationCtx, buffer: AbstractBuffer, value: MethodDescription) { buffer.writeString(value.name) buffer.writeNullable(value.containingClass) { buffer.writeString(it) } buffer.writeList(value.parametersTypes) { v -> buffer.writeNullable(v) { buffer.writeString(it) } } } - - + + } - //fields //methods //initializer //secondary constructor //equals trait - override fun equals(other: Any?): Boolean { + override fun equals(other: Any?): Boolean { if (this === other) return true if (other == null || other::class != this::class) return false - + other as MethodDescription - + if (name != other.name) return false if (containingClass != other.containingClass) return false if (parametersTypes != other.parametersTypes) return false - + return true } - //hash code trait - override fun hashCode(): Int { + override fun hashCode(): Int { var __r = 0 - __r = __r * 31 + name.hashCode() - __r = __r * 31 + if (containingClass != null) containingClass.hashCode() else 0 - __r = __r * 31 + parametersTypes.hashCode() + __r = __r*31 + name.hashCode() + __r = __r*31 + if (containingClass != null) containingClass.hashCode() else 0 + __r = __r*31 + parametersTypes.hashCode() return __r } - //pretty print - override fun print(printer: PrettyPrinter) { + override fun print(printer: PrettyPrinter) { printer.println("MethodDescription (") printer.indent { print("name = "); name.print(printer); println() @@ -903,9 +906,9 @@ data class MethodDescription( /** - * #### Generated from [EngineProcessModel.kt:64] + * #### Generated from [EngineProcessModel.kt:66] */ -data class RenderParams( +data class RenderParams ( val testSetsId: Long, val classUnderTest: ByteArray, val paramNames: ByteArray, @@ -1044,7 +1047,7 @@ data class RenderParams( /** - * #### Generated from [EngineProcessModel.kt:81] + * #### Generated from [EngineProcessModel.kt:83] */ data class RenderResult ( val generatedCode: String, @@ -1107,7 +1110,7 @@ data class RenderResult ( /** - * #### Generated from [EngineProcessModel.kt:85] + * #### Generated from [EngineProcessModel.kt:87] */ data class SetupContextParams ( val classpathForUrlsClassloader: List @@ -1164,7 +1167,7 @@ data class SetupContextParams ( /** - * #### Generated from [EngineProcessModel.kt:36] + * #### Generated from [EngineProcessModel.kt:37] */ data class TestGeneratorParams ( val buildDir: Array, @@ -1239,7 +1242,7 @@ data class TestGeneratorParams ( /** - * #### Generated from [EngineProcessModel.kt:107] + * #### Generated from [EngineProcessModel.kt:109] */ data class WriteSarifReportArguments ( val testSetsId: Long, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessRoot.Generated.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessRoot.Generated.kt index 0b333c3a50..dd4a221774 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessRoot.Generated.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/EngineProcessRoot.Generated.kt @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic /** - * #### Generated from [EngineProcessModel.kt:5] + * #### Generated from [EngineProcessModel.kt:6] */ class EngineProcessRoot private constructor( ) : RdExtBase() { diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdInstrumenterAdapter.Generated.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdInstrumenterAdapter.Generated.kt index f4fbc6f17d..c9c56ee162 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdInstrumenterAdapter.Generated.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdInstrumenterAdapter.Generated.kt @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic /** - * #### Generated from [EngineProcessModel.kt:7] + * #### Generated from [EngineProcessModel.kt:8] */ class RdInstrumenterAdapter private constructor( private val _computeSourceFileByClass: RdCall @@ -97,7 +97,7 @@ val IProtocol.rdInstrumenterAdapter get() = getOrCreateExtension(RdInstrumenterA /** - * #### Generated from [EngineProcessModel.kt:8] + * #### Generated from [EngineProcessModel.kt:9] */ data class ComputeSourceFileByClassArguments ( val canonicalClassName: String diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt index 598ae1e086..11324e77f2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/process/generated/RdSourceFindingStrategy.Generated.kt @@ -15,7 +15,7 @@ import kotlin.jvm.JvmStatic /** - * #### Generated from [EngineProcessModel.kt:16] + * #### Generated from [EngineProcessModel.kt:17] */ class RdSourceFindingStrategy private constructor( private val _testsRelativePath: RdCall, @@ -111,7 +111,7 @@ val IProtocol.rdSourceFindingStrategy get() = getOrCreateExtension(RdSourceFindi /** - * #### Generated from [EngineProcessModel.kt:17] + * #### Generated from [EngineProcessModel.kt:18] */ data class SourceStrategyMethodArgs ( val testSetId: Long, diff --git a/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt b/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt index 5a02645a50..e49c2b500b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/framework/util/SootUtils.kt @@ -92,8 +92,6 @@ private fun initSoot(buildDirs: List, classpath: String?, jdkInfo: JdkInfo } addBasicClasses(*classesToLoad) - addLibraryClasses(libraryClassesToLoad) - loadJavaStdLibClasses() Scene.v().loadNecessaryClasses() PackManager.v().runPacks() @@ -144,29 +142,6 @@ private fun addBasicClasses(vararg classes: Class<*>) { } } -private fun addLibraryClasses(classesNames: kotlin.collections.List) { - classesNames.forEach { - Scene.v().addBasicClass(it, SootClass.BODIES) - } -} - -private fun loadJavaStdLibClasses() { - val fs = FileSystems.getFileSystem(URI.create("jrt:/")) - val javaUtilsClasses = Files.walk(fs.getPath("modules", "java.base", "java/util")).toList() - val javaLangClasses = Files.walk(fs.getPath("modules", "java.base", "java/lang")).toList() - val classesToLoad = - (javaUtilsClasses + javaLangClasses) - .filter { it.absolutePathString().endsWith(".class") } - .filterNot { it.absolutePathString().contains("$") } - classesToLoad - .map { it.absolutePathString().removePrefix("/modules/java.base/").replace('/', '.') } - .forEach { - Scene.v().addBasicClass(it, SootClass.BODIES) - } -} - -val libraryClassesToLoad = mutableListOf() - private val classesToLoad = arrayOf( org.utbot.engine.overrides.collections.AbstractCollection::class, org.utbot.api.mock.UtMock::class, diff --git a/utbot-framework/src/main/kotlin/org/utbot/fuzzer/FuzzerFunctions.kt b/utbot-framework/src/main/kotlin/org/utbot/fuzzer/FuzzerFunctions.kt index 96fbd4d0d7..630719683d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/fuzzer/FuzzerFunctions.kt +++ b/utbot-framework/src/main/kotlin/org/utbot/fuzzer/FuzzerFunctions.kt @@ -1,29 +1,14 @@ package org.utbot.fuzzer import mu.KotlinLogging +import org.utbot.framework.concrete.constructors.UtModelConstructor +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.classId -import org.utbot.framework.plugin.api.util.booleanClassId -import org.utbot.framework.plugin.api.util.byteClassId -import org.utbot.framework.plugin.api.util.charClassId -import org.utbot.framework.plugin.api.util.doubleClassId -import org.utbot.framework.plugin.api.util.floatClassId -import org.utbot.framework.plugin.api.util.intClassId -import org.utbot.framework.plugin.api.util.longClassId -import org.utbot.framework.plugin.api.util.shortClassId -import org.utbot.framework.plugin.api.util.stringClassId +import org.utbot.framework.plugin.api.util.* import org.utbot.framework.util.executableId -import soot.BooleanType -import soot.ByteType -import soot.CharType -import soot.DoubleType -import soot.FloatType -import soot.IntType -import soot.Local -import soot.LongType -import soot.ShortType +import soot.* import soot.Unit -import soot.Value -import soot.ValueBox import soot.jimple.Constant import soot.jimple.IntConstant import soot.jimple.InvokeExpr @@ -88,13 +73,42 @@ fun collectConstantsForFuzzer(graph: ExceptionalUnitGraph): Set> { + val sootGraph = ExceptionalUnitGraph(sootMethod.activeBody) + + fun generateConstantsForBothPrimitives(classId: ClassId, value: Any, utModelConstructor: UtModelConstructor) = + when (classId) { + intWrapperClassId -> listOf(intClassId to utModelConstructor.construct(value, intClassId)) + intClassId -> listOf(intWrapperClassId to utModelConstructor.construct(value, intWrapperClassId)) + byteWrapperClassId -> listOf(byteClassId to utModelConstructor.construct(value, byteClassId)) + byteClassId -> listOf(byteWrapperClassId to utModelConstructor.construct(value, byteWrapperClassId)) + charWrapperClassId -> listOf(charClassId to utModelConstructor.construct(value, charClassId)) + charClassId -> listOf(charWrapperClassId to utModelConstructor.construct(value, charWrapperClassId)) + doubleWrapperClassId -> listOf(doubleClassId to utModelConstructor.construct(value, doubleClassId)) + doubleClassId -> listOf(doubleWrapperClassId to utModelConstructor.construct(value, doubleWrapperClassId)) + longWrapperClassId -> listOf(longClassId to utModelConstructor.construct(value, longClassId)) + longClassId -> listOf(longWrapperClassId to utModelConstructor.construct(value, longWrapperClassId)) + floatWrapperClassId -> listOf(floatClassId to utModelConstructor.construct(value, floatClassId)) + floatClassId -> listOf(floatWrapperClassId to utModelConstructor.construct(value, floatWrapperClassId)) + shortWrapperClassId -> listOf(shortClassId to utModelConstructor.construct(value, shortClassId)) + shortClassId -> listOf(shortWrapperClassId to utModelConstructor.construct(value, shortWrapperClassId)) + stringClassId -> listOf() + else -> null + }?.let { it + listOf(classId to utModelConstructor.construct(value, classId)) } ?: listOf() + + return collectConstantsForFuzzer(sootGraph) + .distinctBy { it.value } + .flatMap { generateConstantsForBothPrimitives(it.classId, it.value, utModelConstructor) } + .groupBy({ it.first }, { it.second }) +} + private interface ConstantsFinder { fun find(graph: ExceptionalUnitGraph, unit: Unit, value: Value): List } private object ConstantsFromIfStatement: ConstantsFinder { override fun find(graph: ExceptionalUnitGraph, unit: Unit, value: Value): List { - if (value !is Constant || (unit !is JIfStmt && unit !is JAssignStmt)) return emptyList() + if (value !is Constant || value is NullConstant || (unit !is JIfStmt && unit !is JAssignStmt)) return emptyList() var useBoxes: List = emptyList() var ifStatement: JIfStmt? = null @@ -270,7 +284,6 @@ private object ConstantsAsIs: ConstantsFinder { override fun find(graph: ExceptionalUnitGraph, unit: Unit, value: Value): List { if (value !is Constant || value is NullConstant) return emptyList() return listOf(FuzzedConcreteValue(value.type.classId, value.plainValue)) - } } diff --git a/utbot-greyboxfuzzer/build.gradle b/utbot-greyboxfuzzer/build.gradle new file mode 100644 index 0000000000..4618ed3b3a --- /dev/null +++ b/utbot-greyboxfuzzer/build.gradle @@ -0,0 +1,37 @@ +plugins { + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +dependencies { + + api project(':utbot-instrumentation') + api project(':utbot-framework-api') + api project(':utbot-fuzzers') + + + implementation("org.unittestbot.soot:soot-utbot-fork:${sootVersion}") { + exclude group:'com.google.guava', module:'guava' + } + + implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: log4j2Version + implementation group: 'io.github.microutils', name: 'kotlin-logging', version: kotlinLoggingVersion + implementation "org.javaruntype:javaruntype:1.3" + implementation "ru.vyarus:generics-resolver:3.0.3" + implementation "ognl:ognl:3.3.2" + + // we need this for construction mocks from composite models + implementation group: 'org.mockito', name: 'mockito-core', version: '4.2.0' + + // To use JUnit4, comment out JUnit5 and uncomment JUnit4 dependencies here. Please also check "test" section + //implementation group: 'junit', name: 'junit', version: '4.13.1' + implementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: '5.8.1' + implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.8.1' +} + + +shadowJar { + archiveClassifier.set('') + minimize{ + exclude(dependency('org.scala-lang:.*:.*')) + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/GreyBoxFuzzer.kt similarity index 64% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/GreyBoxFuzzer.kt index edd387c762..77b2528b27 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/GreyBoxFuzzer.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/GreyBoxFuzzer.kt @@ -1,44 +1,52 @@ -package org.utbot.engine.greyboxfuzzer +package org.utbot.greyboxfuzzer import kotlinx.coroutines.flow.FlowCollector import kotlinx.coroutines.flow.flow -import org.utbot.engine.* -import org.utbot.engine.greyboxfuzzer.generator.* -import org.utbot.engine.greyboxfuzzer.mutator.Mutator -import org.utbot.engine.greyboxfuzzer.mutator.Seed -import org.utbot.engine.greyboxfuzzer.mutator.SeedCollector -import org.utbot.engine.greyboxfuzzer.util.* -import org.utbot.framework.concrete.* +import mu.KotlinLogging import org.utbot.framework.plugin.api.* -import org.utbot.framework.plugin.api.util.* -import org.utbot.framework.util.sootMethod -import org.utbot.instrumentation.ConcreteExecutor -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.framework.plugin.api.util.isConstructor +import org.utbot.framework.plugin.api.util.isStatic +import org.utbot.framework.plugin.api.util.jClass +import org.utbot.fuzzer.FuzzedMethodDescription +import org.utbot.fuzzer.FuzzedValue +import org.utbot.fuzzer.UtFuzzedExecution +import org.utbot.greyboxfuzzer.generator.DataGenerator +import org.utbot.greyboxfuzzer.generator.GreyBoxFuzzerGeneratorsAndSettings +import org.utbot.greyboxfuzzer.generator.StaticMethodThisInstance +import org.utbot.greyboxfuzzer.generator.ThisInstance +import org.utbot.greyboxfuzzer.mutator.Mutator +import org.utbot.greyboxfuzzer.mutator.Seed +import org.utbot.greyboxfuzzer.mutator.SeedCollector +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.* import java.lang.reflect.Executable import java.lang.reflect.Field import kotlin.random.Random +import kotlin.system.exitProcess class GreyBoxFuzzer( - private val pathsToUserClasses: String, - private val pathsToDependencyClasses: String, private val methodUnderTest: ExecutableId, + private val constants: Map>, + private val fuzzerUtModelConstructor: FuzzerUtModelConstructor, + private val executor: suspend (ExecutableId, EnvironmentModels, List) -> UtFuzzingConcreteExecutionResult, private val timeBudgetInMillis: Long ) { - private var methodInstructionsIds: Set? = null - private var seeds: SeedCollector? = null + private var methodInstructions: Set? = null + private var seeds: SeedCollector = SeedCollector() private val timeRemain get() = timeOfStart + timeBudgetInMillis - System.currentTimeMillis() private val timeOfStart = System.currentTimeMillis() private val percentageOfTimeBudgetToChangeMode = 25 + private val logger = KotlinLogging.logger {} + suspend fun fuzz() = flow { logger.debug { "Started to fuzz ${methodUnderTest.name}" } val javaClazz = methodUnderTest.classId.jClass val sootMethod = methodUnderTest.sootMethod val javaMethod = sootMethod.toJavaMethod() ?: return@flow - val generatorContext = GeneratorContext() - .also { it.constants.putAll(sootMethod.collectConstants(it.utModelConstructor)) } + val generatorContext = GeneratorContext(fuzzerUtModelConstructor, constants) val classFieldsUsedByFunc = sootMethod.getClassFieldsUsedByFunc(javaClazz) while (timeRemain > 0 || !isMethodCovered()) { explorationStage( @@ -47,7 +55,7 @@ class GreyBoxFuzzer( methodUnderTest, generatorContext ) - logger.debug { "SEEDS AFTER EXPLORATION STAGE = ${seeds?.seedsSize()}" } + logger.debug { "SEEDS AFTER EXPLORATION STAGE = ${seeds.seedsSize()}" } if (timeRemain < 0 || isMethodCovered()) break exploitationStage() } @@ -119,32 +127,41 @@ class GreyBoxFuzzer( EnvironmentModels(thisInstance.utModelForExecution, generatedParameters.map { it.utModel }, mapOf()) try { logger.debug { "Execution started" } - val executionResult = execute(stateBefore, methodUnderTest) - if (methodInstructionsIds == null) { - methodInstructionsIds = executionResult.methodInstructionsIds - seeds = SeedCollector(methodInstructionsIds = methodInstructionsIds!!) + val executionResult = (executor::invoke)(methodUnderTest, stateBefore, listOf()) + if (methodInstructions == null && executionResult.methodInstructions != null) { + methodInstructions = executionResult.methodInstructions.toSet() } - seeds ?: continue logger.debug { "Execution result: $executionResult" } - val seedCoverage = getCoverage(executionResult) + val seedCoverage = getCoverage(executionResult.coverage) logger.debug { "Calculating seed score" } - val seedScore = seeds!!.calcSeedScore(seedCoverage) + val seedScore = seeds.calcSeedScore(seedCoverage) logger.debug { "Adding seed" } val seed = Seed(thisInstance, generatedParameters, seedCoverage, seedScore) - if (seeds!!.isSeedOpensNewCoverage(seed)) { + if (seeds.isSeedOpensNewCoverage(seed)) { emit( - UtGreyBoxFuzzedExecution( - stateBefore, - executionResult, - coverage = executionResult.coverage - ) + if (executionResult.stateAfter != null) { + UtFuzzedExecution( + stateBefore = stateBefore, + stateAfter = executionResult.stateAfter, + result = executionResult.result, + coverage = executionResult.coverage, + fuzzingValues = generatedParameters.map { FuzzedValue(it.utModel) }, + fuzzedMethodDescription = FuzzedMethodDescription(methodUnderTest) + ) + } else { + UtGreyBoxFuzzedExecution( + stateBefore, + executionResult, + coverage = executionResult.coverage + ) + } ) } - seeds!!.addSeed(seed) + seeds.addSeed(seed) logger.debug { "Execution result: ${executionResult.result}" } logger.debug { "Seed score = $seedScore" } } catch (e: Throwable) { - logger.debug(e) { "Exception while execution :(" } + logger.debug(e) { "Exception while execution in method ${methodUnderTest.name} of class ${methodUnderTest.classId.name}" } thisInstancesHistory.clear() regenerateThis = true continue @@ -157,8 +174,8 @@ class GreyBoxFuzzer( private suspend fun FlowCollector.exploitationStage() { logger.debug { "Exploitation began" } - if (seeds == null || seeds!!.seedsSize() == 0) return - if (seeds!!.all { it.parameters.isEmpty() }) return + if (seeds.seedsSize() == 0) return + if (seeds.all { it.parameters.isEmpty() }) return val startTime = System.currentTimeMillis() val endTime = startTime + timeBudgetInMillis / (100L / percentageOfTimeBudgetToChangeMode) var iterationNumber = 0 @@ -168,7 +185,7 @@ class GreyBoxFuzzer( if (iterationNumber > 30_000) return logger.debug { "Func: ${methodUnderTest.name} Mutation iteration number $iterationNumber" } iterationNumber++ - val randomSeed = seeds!!.getRandomWeightedSeed() + val randomSeed = seeds.getRandomWeightedSeed() logger.debug { "Random seed params = ${randomSeed.parameters}" } val mutatedSeed = Mutator.mutateSeed( @@ -183,77 +200,65 @@ class GreyBoxFuzzer( logger.debug { "Mutated params = ${mutatedSeed.parameters}" } val stateBefore = mutatedSeed.createEnvironmentModels() try { - val executionResult = execute(stateBefore, methodUnderTest) + val executionResult = (executor::invoke)(methodUnderTest, stateBefore, listOf()) logger.debug { "Execution result: $executionResult" } - val seedScore = getCoverage(executionResult) + val seedScore = getCoverage(executionResult.coverage) mutatedSeed.score = 0.0 - if (seeds!!.isSeedOpensNewCoverage(mutatedSeed)) { + if (seeds.isSeedOpensNewCoverage(mutatedSeed)) { emit( - UtGreyBoxFuzzedExecution( - stateBefore, - executionResult, - coverage = executionResult.coverage - ) + if (executionResult.stateAfter != null) { + UtFuzzedExecution( + stateBefore = stateBefore, + stateAfter = executionResult.stateAfter, + result = executionResult.result, + coverage = executionResult.coverage, + fuzzingValues = mutatedSeed.parameters.map { FuzzedValue(it.utModel) }, + fuzzedMethodDescription = FuzzedMethodDescription(methodUnderTest) + ) + } else { + UtGreyBoxFuzzedExecution( + stateBefore, + executionResult, + coverage = executionResult.coverage + ) + } ) } - seeds!!.addSeed(mutatedSeed) + seeds.addSeed(mutatedSeed) logger.debug { "Execution result: ${executionResult.result}" } logger.debug { "Seed score = $seedScore" } } catch (e: Throwable) { - logger.debug(e) { "Exception while execution :(" } + logger.debug(e) { "Exception while execution in method ${methodUnderTest.name} of class ${methodUnderTest.classId.name}" } continue } } } private fun getCoverage( - executionResult: UtFuzzingConcreteExecutionResult - ): Set { - val currentMethodCoverage = executionResult.coverage.coveredInstructions + coverage: Coverage + ): Set { + val currentMethodCoverage = coverage.coveredInstructions .asSequence() .filter { it.className == methodUnderTest.classId.name.replace('.', '/') } .filter { it.methodSignature == methodUnderTest.signature } - .map { it.id } - .filter { it in methodInstructionsIds!! } +// .map { it.id } + //.filter { it in methodInstructionsIds!! } .toSet() - logger.debug { "Covered instructions ${currentMethodCoverage.count()} from ${methodInstructionsIds!!.size}" } - executionResult.coverage.coveredInstructions.forEach { CoverageCollector.addCoverage(it) } + logger.debug { "Covered instructions ${currentMethodCoverage.count()} from ${methodInstructions?.size}" } + coverage.coveredInstructions.forEach { CoverageCollector.addCoverage(it) } return currentMethodCoverage } private fun isMethodCovered(): Boolean { - methodInstructionsIds ?: return false + methodInstructions ?: return false val coveredInstructions = - CoverageCollector.coverage.filter { it.methodSignature == methodUnderTest.signature }.map { it.id } + CoverageCollector.coverage + .filter { it.className == methodUnderTest.classId.name.replace('.', '/') } + .filter { it.methodSignature == methodUnderTest.signature } .toSet() - return coveredInstructions.containsAll(methodInstructionsIds!!) + return coveredInstructions.containsAll(methodInstructions!!) } - private suspend fun ConcreteExecutor.executeConcretely( - methodUnderTest: ExecutableId, - stateBefore: EnvironmentModels, - instrumentation: List - ): UtFuzzingConcreteExecutionResult = executeAsync( - methodUnderTest.classId.name, - methodUnderTest.signature, - arrayOf(), - parameters = UtConcreteExecutionData(stateBefore, instrumentation) - ) - - private suspend fun execute( - stateBefore: EnvironmentModels, - methodUnderTest: ExecutableId - ): UtFuzzingConcreteExecutionResult = run { - val executor = - ConcreteExecutor( - UtFuzzingExecutionInstrumentation, - pathsToUserClasses, - pathsToDependencyClasses - ).apply { this.classLoader = utContext.classLoader } - executor.executeConcretely(methodUnderTest, stateBefore, listOf()) - } - - private fun generateThisInstance(classId: ClassId, generatorContext: GeneratorContext): ThisInstance = if (!methodUnderTest.isStatic && !methodUnderTest.isConstructor) { DataGenerator.generateThis( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/coverage/GlobalCoverage.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/coverage/GlobalCoverage.kt similarity index 84% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/coverage/GlobalCoverage.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/coverage/GlobalCoverage.kt index 40ef4b3d0b..6f42d490e5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/coverage/GlobalCoverage.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/coverage/GlobalCoverage.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.coverage +package org.utbot.greyboxfuzzer.coverage import org.utbot.framework.plugin.api.Instruction diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/DataGenerator.kt similarity index 88% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/DataGenerator.kt index 10a4ea5dc9..c37101f6ee 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/DataGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/DataGenerator.kt @@ -1,19 +1,19 @@ -package org.utbot.engine.greyboxfuzzer.generator +package org.utbot.greyboxfuzzer.generator -import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness -import org.utbot.engine.logger -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.util.FuzzerIllegalStateException +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.util.logger +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationState -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationState +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import java.lang.reflect.Parameter object DataGenerator { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/FField.kt similarity index 87% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/FField.kt index 577b05f916..80ce70ef52 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FField.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/FField.kt @@ -1,8 +1,8 @@ -package org.utbot.engine.greyboxfuzzer.generator +package org.utbot.greyboxfuzzer.generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.util.toClass -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.util.toClass +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.ClassId import java.lang.reflect.Field import java.lang.reflect.Type diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/FParameter.kt similarity index 83% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/FParameter.kt index ff74cea6db..1fb1a8217e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FParameter.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/FParameter.kt @@ -1,10 +1,10 @@ -package org.utbot.engine.greyboxfuzzer.generator +package org.utbot.greyboxfuzzer.generator -import org.utbot.engine.greyboxfuzzer.mutator.Mutator -import org.utbot.engine.greyboxfuzzer.util.copy -import org.utbot.engine.greyboxfuzzer.util.getAllDeclaredFields -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.mutator.Mutator +import org.utbot.greyboxfuzzer.util.copy +import org.utbot.greyboxfuzzer.util.getAllDeclaredFields +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtCompositeModel diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/FThisInstance.kt similarity index 81% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/FThisInstance.kt index f3d1a1507f..2b6658e508 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/FThisInstance.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/FThisInstance.kt @@ -1,9 +1,9 @@ -package org.utbot.engine.greyboxfuzzer.generator +package org.utbot.greyboxfuzzer.generator -import org.utbot.engine.greyboxfuzzer.util.copy +import org.utbot.greyboxfuzzer.util.copy import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator sealed interface ThisInstance { val utModelForExecution: UtModel? diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/GeneratorConfigurator.kt similarity index 85% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/GeneratorConfigurator.kt index 5f6731e694..855167dbdd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GeneratorConfigurator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/GeneratorConfigurator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.generator +package org.utbot.greyboxfuzzer.generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Size -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.CollectionGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.MapGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.ArrayGenerator -import org.utbot.engine.greyboxfuzzer.util.getTrue -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.* +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.Size +import org.utbot.greyboxfuzzer.quickcheck.generator.java.util.CollectionGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.java.util.MapGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.generator.ArrayGenerator +import org.utbot.greyboxfuzzer.util.getTrue +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.* import kotlin.random.Random object GeneratorConfigurator { @@ -25,8 +25,8 @@ object GeneratorConfigurator { private val maxFloat: Float = 100.0f private val minDouble: Double = -100.0 private val maxDouble: Double = 100.0 - private val minStringLength: Int = 1 - private val maxStringLength: Int = 5 + private val minStringLength: Int = 0 + private val maxStringLength: Int = 10 val minCollectionSize: Int = 0 val maxCollectionSize: Int = 5 diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt similarity index 82% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt index c9b3d5930f..ea75ee807d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/GreyBoxFuzzerGeneratorsAndSettings.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.generator +package org.utbot.greyboxfuzzer.generator -import org.utbot.engine.greyboxfuzzer.quickcheck.NonTrackingGenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time.* -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.* -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.* -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.math.* -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.nio.charset.CharsetGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.NonTrackingGenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.* +import org.utbot.greyboxfuzzer.quickcheck.generator.java.time.* +import org.utbot.greyboxfuzzer.quickcheck.generator.java.util.* +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.* +import org.utbot.greyboxfuzzer.quickcheck.generator.java.math.* +import org.utbot.greyboxfuzzer.quickcheck.generator.java.nio.charset.CharsetGenerator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.* import java.util.concurrent.atomic.AtomicInteger diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/QuickCheckExtensions.kt similarity index 93% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/QuickCheckExtensions.kt index 74742f6ba3..95c6b152b6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/QuickCheckExtensions.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/QuickCheckExtensions.kt @@ -1,22 +1,21 @@ @file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") -package org.utbot.engine.greyboxfuzzer.generator +package org.utbot.greyboxfuzzer.generator import org.javaruntype.exceptions.TypeValidationException import org.javaruntype.type.StandardTypeParameter import org.javaruntype.type.Types import org.utbot.common.withAccessibility -import org.utbot.engine.greyboxfuzzer.generator.userclasses.UserClassGenerator -import org.utbot.engine.greyboxfuzzer.util.* -import org.utbot.engine.logger -import org.utbot.engine.rawType -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.FakeAnnotatedTypeFactory -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.ArrayGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.CompositeGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.GeneratorRepository +import org.utbot.greyboxfuzzer.generator.userclasses.UserClassGenerator +import org.utbot.greyboxfuzzer.util.* +import org.utbot.greyboxfuzzer.util.logger +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.internal.FakeAnnotatedTypeFactory +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.internal.generator.ArrayGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.generator.CompositeGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.generator.GeneratorRepository import ru.vyarus.java.generics.resolver.GenericsResolver import ru.vyarus.java.generics.resolver.context.ConstructorGenericsContext import ru.vyarus.java.generics.resolver.context.GenericsContext @@ -40,7 +39,7 @@ fun Generator.getAllComponents(): List { fun Generator.getComponents(): List = when (this) { - is org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -> this.componentGenerators() + is org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -> this.componentGenerators() is ArrayGenerator -> listOf(this.component) is CompositeGenerator -> this.composed.map { it.item } else -> emptyList() diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/UTGeneratorRepository.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/UTGeneratorRepository.kt index d4e79ff8f0..98ebf65b60 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/UTGeneratorRepository.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/UTGeneratorRepository.kt @@ -1,11 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.generator +package org.utbot.greyboxfuzzer.generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness -import org.utbot.engine.logger -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Zilch -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.* +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.util.logger +import org.utbot.greyboxfuzzer.quickcheck.internal.Zilch +import org.utbot.greyboxfuzzer.quickcheck.internal.generator.* class UTGeneratorRepository(random: SourceOfRandomness) : GeneratorRepository(random) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt similarity index 93% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt index e13ab87473..2a11c8c697 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/UserClassGenerator.kt @@ -1,21 +1,22 @@ @file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") -package org.utbot.engine.greyboxfuzzer.generator.userclasses +package org.utbot.greyboxfuzzer.generator.userclasses -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import org.javaruntype.type.TypeParameter -import org.utbot.engine.greyboxfuzzer.generator.* -import org.utbot.engine.greyboxfuzzer.generator.userclasses.generator.* -import org.utbot.engine.greyboxfuzzer.mutator.Mutator -import org.utbot.engine.greyboxfuzzer.util.* -import org.utbot.engine.logger +import org.utbot.greyboxfuzzer.generator.* +import org.utbot.greyboxfuzzer.generator.userclasses.generator.* +import org.utbot.greyboxfuzzer.mutator.Mutator +import org.utbot.greyboxfuzzer.util.* +import org.utbot.greyboxfuzzer.util.logger import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.fieldClassId import org.utbot.framework.plugin.api.util.fieldId import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* +import org.utbot.greyboxfuzzer.quickcheck.generator.* import org.utbot.framework.UtSettings +import org.utbot.greyboxfuzzer.generator.userclasses.generator.ReflectionClassGenerator import java.lang.reflect.* import kotlin.random.Random diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt similarity index 87% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt index 5fd3df1059..c2bab5e679 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ClassesInstanceGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.logger +import org.utbot.greyboxfuzzer.util.logger import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext class ClassesInstanceGenerator( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt similarity index 89% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt index b4ca5c2418..2dbbdee4ae 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ConstructorBasedInstanceGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator import org.utbot.common.isPublic -import org.utbot.engine.greyboxfuzzer.util.* +import org.utbot.greyboxfuzzer.util.* import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Constructor import java.lang.reflect.Modifier diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt similarity index 69% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt index f954127a8b..e5f1da749b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ExecutableInvoker.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.generator.DataGenerator -import org.utbot.engine.greyboxfuzzer.generator.createParameterContextForParameter -import org.utbot.engine.greyboxfuzzer.util.constructAssembleModelUsingMethodInvocation +import org.utbot.greyboxfuzzer.generator.DataGenerator +import org.utbot.greyboxfuzzer.generator.createParameterContextForParameter +import org.utbot.greyboxfuzzer.util.constructAssembleModelUsingMethodInvocation import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Executable diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt similarity index 51% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt index 648c494b7f..1ce86fbb9b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/GenerationMethod.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator enum class GenerationMethod { CONSTRUCTOR, STATIC, STATIC_EXT, ANY diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt similarity index 60% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt index a4b09f3afd..8c00f12138 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/InstanceGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator import org.utbot.framework.plugin.api.UtModel diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt similarity index 92% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt index b2802ee89d..6817729252 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/InterfaceImplementationsInstanceGenerator.kt @@ -1,20 +1,20 @@ @file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator import org.utbot.common.isAbstract -import org.utbot.engine.greyboxfuzzer.generator.DataGenerator -import org.utbot.engine.greyboxfuzzer.generator.QuickCheckExtensions -import org.utbot.engine.greyboxfuzzer.util.* -import org.utbot.engine.logger +import org.utbot.greyboxfuzzer.generator.DataGenerator +import org.utbot.greyboxfuzzer.generator.QuickCheckExtensions +import org.utbot.greyboxfuzzer.util.* +import org.utbot.greyboxfuzzer.util.logger import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Type import kotlin.random.Random diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt similarity index 71% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt index 3317f766ab..dd7dacb927 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ObjectGenerator.kt @@ -1,17 +1,17 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.generator.GreyBoxFuzzerGeneratorsAndSettings -import org.utbot.engine.greyboxfuzzer.generator.getOrProduceGenerator -import org.utbot.engine.greyboxfuzzer.util.getAllTypesFromCastAndInstanceOfInstructions -import org.utbot.engine.greyboxfuzzer.util.getTrue -import org.utbot.engine.greyboxfuzzer.util.toSootMethod +import org.utbot.greyboxfuzzer.generator.GreyBoxFuzzerGeneratorsAndSettings +import org.utbot.greyboxfuzzer.generator.getOrProduceGenerator +import org.utbot.greyboxfuzzer.util.getAllTypesFromCastAndInstanceOfInstructions +import org.utbot.greyboxfuzzer.util.getTrue +import org.utbot.greyboxfuzzer.util.toSootMethod import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.MethodGenericsContext import kotlin.random.Random diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt similarity index 76% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt index 4f3e661d57..5550943e4f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ReflectionClassGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.util.getTrue -import org.utbot.engine.greyboxfuzzer.util.toJavaClass +import org.utbot.greyboxfuzzer.generator.userclasses.generator.InstanceGenerator +import org.utbot.greyboxfuzzer.util.getTrue +import org.utbot.greyboxfuzzer.util.toJavaClass import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext import soot.Scene -import java.lang.reflect.Type import kotlin.random.Random class ReflectionClassGenerator( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt similarity index 86% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt index 38771ceee5..13914ebadd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/ReflectionTypeGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.util.getTrue -import org.utbot.engine.greyboxfuzzer.util.toJavaClass -import org.utbot.engine.greyboxfuzzer.util.toSootMethod +import org.utbot.greyboxfuzzer.util.getTrue +import org.utbot.greyboxfuzzer.util.toJavaClass +import org.utbot.greyboxfuzzer.util.toSootMethod import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.classId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext import ru.vyarus.java.generics.resolver.context.MethodGenericsContext import soot.NullType import soot.Scene diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt similarity index 78% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt index 890ae1c64b..de5767ac5f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/StaticsBasedInstanceGenerator.kt @@ -1,9 +1,9 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import kotlin.random.Random diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt similarity index 83% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt index 7637cb0b7c..52380ba084 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/StaticsFieldBasedInstanceGenerator.kt @@ -1,13 +1,9 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.util.SootStaticsCollector -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.util.hasModifiers -import org.utbot.engine.greyboxfuzzer.util.toClass -import org.utbot.external.api.classIdForType -import org.utbot.framework.concrete.constructors.UtModelConstructor +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* +import org.utbot.greyboxfuzzer.util.* import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Field import java.lang.reflect.Modifier @@ -40,7 +36,7 @@ internal class StaticsFieldBasedInstanceGenerator( SootStaticsCollector.getStaticFieldsInitializersOf(clazz).randomOrNull() private fun createUtModelForStaticFieldInvocation( - utModelConstructor: UtModelConstructor, + utModelConstructor: FuzzerUtModelConstructor, field: Field ): UtAssembleModel { with(utModelConstructor) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt similarity index 81% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt index 9d87174481..6210e15f3e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/StaticsMethodBasedInstanceGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.util.SootStaticsCollector -import org.utbot.engine.greyboxfuzzer.util.hasModifiers -import org.utbot.engine.greyboxfuzzer.util.toClass +import org.utbot.greyboxfuzzer.util.SootStaticsCollector +import org.utbot.greyboxfuzzer.util.hasModifiers +import org.utbot.greyboxfuzzer.util.toClass import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Method import java.lang.reflect.Modifier diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt similarity index 86% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt index 2d66211df8..4dc159f44e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/generator/userclasses/generator/UnsafeBasedInstanceGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.generator.userclasses.generator +package org.utbot.greyboxfuzzer.generator.userclasses.generator -import org.utbot.engine.greyboxfuzzer.generator.DataGenerator -import org.utbot.engine.greyboxfuzzer.generator.QuickCheckExtensions -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness -import org.utbot.engine.greyboxfuzzer.util.* +import org.utbot.greyboxfuzzer.generator.DataGenerator +import org.utbot.greyboxfuzzer.generator.QuickCheckExtensions +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.util.* import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.UtCompositeModel import org.utbot.framework.plugin.api.UtModel diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/Mutator.kt similarity index 92% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/Mutator.kt index 98add8002d..ba768107ce 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Mutator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/Mutator.kt @@ -1,20 +1,20 @@ -package org.utbot.engine.greyboxfuzzer.mutator +package org.utbot.greyboxfuzzer.mutator import org.javaruntype.type.Types -import org.utbot.engine.greyboxfuzzer.generator.* -import org.utbot.engine.greyboxfuzzer.util.* -import org.utbot.engine.logger +import org.utbot.greyboxfuzzer.generator.* +import org.utbot.greyboxfuzzer.util.* +import org.utbot.greyboxfuzzer.util.logger import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.fieldId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.jClass import org.utbot.framework.plugin.api.util.method -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationState -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationState +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.context.GenericsContext import java.lang.reflect.Field import java.lang.reflect.Modifier diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/ObjectMerger.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/ObjectMerger.kt similarity index 72% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/ObjectMerger.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/ObjectMerger.kt index 22a0e91661..3a6787aa03 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/ObjectMerger.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/ObjectMerger.kt @@ -1,6 +1,6 @@ -package org.utbot.engine.greyboxfuzzer.mutator +package org.utbot.greyboxfuzzer.mutator -import org.utbot.engine.greyboxfuzzer.generator.FParameter +import org.utbot.greyboxfuzzer.generator.FParameter class ObjectMerger { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/Seed.kt similarity index 76% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/Seed.kt index 59b7cdf649..bf57925d9d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/Seed.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/Seed.kt @@ -1,13 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.mutator +package org.utbot.greyboxfuzzer.mutator -import org.utbot.engine.greyboxfuzzer.generator.FParameter -import org.utbot.engine.greyboxfuzzer.generator.ThisInstance +import org.utbot.greyboxfuzzer.generator.FParameter +import org.utbot.greyboxfuzzer.generator.ThisInstance import org.utbot.framework.plugin.api.EnvironmentModels +import org.utbot.framework.plugin.api.Instruction data class Seed( val thisInstance: ThisInstance, val parameters: List, - val instructionCoverage: Set, + val instructionCoverage: Set, var score: Double = 0.0 ) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/SeedCollector.kt similarity index 91% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/SeedCollector.kt index 9cf8897317..aab9696a19 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/mutator/SeedCollector.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/mutator/SeedCollector.kt @@ -1,11 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.mutator +package org.utbot.greyboxfuzzer.mutator +import org.utbot.framework.plugin.api.Instruction import kotlin.random.Random -class SeedCollector(private val maxSize: Int = 100, private val methodInstructionsIds: Set) { +class SeedCollector(private val maxSize: Int = 100) { private val seeds = ArrayList(maxSize) - fun calcSeedScore(coverage: Set): Double = + fun calcSeedScore(coverage: Set): Double = coverage.sumOf { instruction -> val numOfSeedCoveredInstructions = seeds.count { it.instructionCoverage.contains(instruction) } if (numOfSeedCoveredInstructions == 0) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt similarity index 61% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt index 048e5fc8bc..5030482b00 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/NonTrackingGenerationStatus.kt @@ -1,8 +1,8 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck +package org.utbot.greyboxfuzzer.quickcheck -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.GeometricDistribution -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.internal.GeometricDistribution +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Provides a generation status that does not track the number of trials @@ -14,7 +14,7 @@ import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness class NonTrackingGenerationStatus(private val random: SourceOfRandomness) : GenerationStatus { private val geometric = GeometricDistribution() override fun size(): Int { - return geometric.sampleWithMean(org.utbot.engine.greyboxfuzzer.quickcheck.NonTrackingGenerationStatus.Companion.MEAN_SIZE.toDouble(), random) + return geometric.sampleWithMean(org.utbot.greyboxfuzzer.quickcheck.NonTrackingGenerationStatus.Companion.MEAN_SIZE.toDouble(), random) } override fun attempts(): Int { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt similarity index 80% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt index ef3f18c8a0..01b58eb05e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/ComponentizedGenerator.kt @@ -1,10 +1,10 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator import org.javaruntype.type.TypeParameter -import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException +import org.utbot.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedType import java.util.Collections @@ -55,25 +55,25 @@ abstract class ComponentizedGenerator constructor(type: Class<*>) : Generator(ty return numberOfNeededComponents() == typeParameters.size } - override fun provide(provided: org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators) { + override fun provide(provided: org.utbot.greyboxfuzzer.quickcheck.generator.Generators) { super.provide(provided) for (each in components) { each.provide(provided) } } - abstract fun createModifiedUtModel(random: SourceOfRandomness, status: org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus): UtModel + abstract fun createModifiedUtModel(random: SourceOfRandomness, status: org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus): UtModel protected open fun modify( random: SourceOfRandomness, - status: org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus + status: org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus ): UtModel { val cachedModel = generatedUtModel ?: throw FuzzerIllegalStateException("Nothing to modify") val randomNestedGenerator = nestedGeneratorsRecursiveWithoutThis().randomOrNull() ?: return cachedModel getAllGeneratorsBetween(this, randomNestedGenerator)?.forEach { - it.generationState = org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationState.MODIFYING_CHAIN + it.generationState = org.utbot.greyboxfuzzer.quickcheck.generator.GenerationState.MODIFYING_CHAIN } randomNestedGenerator.generationState = - org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationState.REGENERATE + org.utbot.greyboxfuzzer.quickcheck.generator.GenerationState.REGENERATE return createModifiedUtModel(random, status) } override fun configure(annotatedType: AnnotatedType?) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt similarity index 86% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt index c5731f0238..f2b28a1f4b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/DecimalGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * Base class for generators of decimal types, such as `double` and diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Distinct.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Distinct.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Distinct.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Distinct.kt index d794da570d..3200d7c25a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Distinct.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Distinct.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Gen.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Gen.kt similarity index 83% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Gen.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Gen.kt index f09366e5d3..6545212577 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Gen.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Gen.kt @@ -1,7 +1,7 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Represents a strategy for generating random values. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationState.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GenerationState.kt similarity index 56% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationState.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GenerationState.kt index ca3cb89aac..ed13bc3530 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationState.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GenerationState.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator enum class GenerationState { REGENERATE, CACHE, MODIFY, MODIFYING_CHAIN diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt index e65f0430c2..0b6e0d6c73 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GenerationStatus.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * [Generator]s are fed instances of this interface on each generation diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Generator.kt similarity index 95% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Generator.kt index 20784172ec..95752eb109 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Generator.kt @@ -1,18 +1,18 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator import org.javaruntype.type.TypeParameter import org.javaruntype.type.Types import org.javaruntype.type.WildcardTypeParameter -import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.* -import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.engine.greyboxfuzzer.util.removeIfAndReturnRemovedElements +import org.utbot.greyboxfuzzer.generator.GeneratorConfigurator +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.* +import org.utbot.greyboxfuzzer.util.FuzzerIllegalStateException +import org.utbot.greyboxfuzzer.util.removeIfAndReturnRemovedElements import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ReflectionException -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness -import org.utbot.engine.greyboxfuzzer.util.getTrue +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.internal.ReflectionException +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.util.getTrue import org.utbot.framework.plugin.api.util.* import java.lang.reflect.AnnotatedElement import java.lang.reflect.AnnotatedType diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt similarity index 92% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt index ff74d8273c..f34a8adde0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GeneratorConfiguration.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt similarity index 87% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt index f80f5bf90a..78511ddda3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GeneratorConfigurationException.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * Raised if a problem arises when attempting to configure a generator with diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt similarity index 62% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt index 91a6d13afd..dac79dcfc7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/GeneratorContext.kt @@ -1,14 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator -import org.utbot.framework.concrete.constructors.UtModelConstructor import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtModel -import java.util.* +import org.utbot.greyboxfuzzer.util.FuzzerUtModelConstructor data class GeneratorContext( - val utModelConstructor: UtModelConstructor = UtModelConstructor(IdentityHashMap()), + val utModelConstructor: FuzzerUtModelConstructor, + val constants: Map>, val timeoutInMillis: Long = 5000L, - val constants: MutableMap> = mutableMapOf() ) { var timeOfGenerationStart = 0L var timeToFinishGeneration = 0L diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generators.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Generators.kt similarity index 93% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generators.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Generators.kt index 47c702e711..40598f6850 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Generators.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Generators.kt @@ -1,6 +1,6 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.Field import java.lang.reflect.Parameter diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/InRange.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/InRange.kt similarity index 97% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/InRange.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/InRange.kt index d73d0b98e8..02402b0b06 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/InRange.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/InRange.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt similarity index 86% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt index 4a43a78c19..04a1aaf042 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/IntegralGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * Base class for generators of integral types, such as `int` and diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Lambdas.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Lambdas.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Lambdas.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Lambdas.kt index fe094e335a..f537fbbd65 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Lambdas.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Lambdas.kt @@ -1,10 +1,10 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.DefaultMethodHandleMaker -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.GeometricDistribution -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator.SimpleGenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.internal.DefaultMethodHandleMaker +import org.utbot.greyboxfuzzer.quickcheck.internal.GeometricDistribution +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.internal.generator.SimpleGenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.InvocationHandler import java.lang.reflect.Method import java.lang.reflect.Proxy diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/NullAllowed.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/NullAllowed.kt similarity index 89% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/NullAllowed.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/NullAllowed.kt index 552008de29..53bf5b8f9a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/NullAllowed.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/NullAllowed.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Precision.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Precision.kt similarity index 89% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Precision.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Precision.kt index 3a44054ab1..34cfbd4ec0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Precision.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Precision.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Size.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Size.kt similarity index 89% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Size.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Size.kt index 6392f22b3d..d9d0f84f32 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/Size.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/Size.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt similarity index 74% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt index 02431efe87..e49a3722e4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/VoidGenerator.kt @@ -1,9 +1,9 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator +package org.utbot.greyboxfuzzer.quickcheck.generator -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values for property parameters of type `void` or diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt index 7fcde92839..85f6e5663f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/AbstractStringGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.stringClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Size -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Size +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt similarity index 57% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt index 7c2b42aaef..81527d1a4c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/BooleanGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.booleanWrapperClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `boolean` or [Boolean]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt similarity index 68% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt index 616de4f8bc..cf1cc84631 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/ByteGenerator.kt @@ -1,14 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.byteWrapperClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `byte` or [Byte]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt index 1143f6299c..5889a2c5ba 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/CharacterGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.charWrapperClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `char` or [Character]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt similarity index 73% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt index 82710c5529..4c068ae990 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/DoubleGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.doubleWrapperClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values for property parameters of type `double` or diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt similarity index 78% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt index 3fa37ad396..49e75641ee 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/Encoded.kt @@ -1,9 +1,9 @@ //package org.utbot.quickcheck.generator.java.lang // -//import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorConfiguration -//import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.strings.CodePoints -//import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.strings.CodePoints.Companion.forCharset -//import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +//import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorConfiguration +//import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.strings.CodePoints +//import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.strings.CodePoints.Companion.forCharset +//import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness //import java.nio.charset.Charset // ///** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt index 20ed203993..0c2b53452f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/FloatGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.floatWrapperClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `float` or [Float]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt similarity index 71% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt index b1f5afe938..0656adad90 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/IntegerGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.intWrapperClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `int` or [Integer]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt similarity index 72% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt index a0c4fc432d..9bd7ed8d84 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/LongGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.longWrapperClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `long` or [Long]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt similarity index 56% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt index 0358888dae..9b97d38e58 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveBooleanGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.booleanClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `boolean` or [Boolean]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt index 83f93aa383..aaf749bc4a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveByteGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.byteClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `byte` or [Byte]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt index e6a59ec24b..7dc2202725 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveCharGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.charClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `char` or [Character]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt similarity index 73% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt index a137bd5dc0..b50f44d3cb 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveDoubleGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.doubleClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values for property parameters of type `double` or diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt index b9fb202b24..e55130c32c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveFloatGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.floatClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `float` or [Float]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt similarity index 72% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt index a788e4583b..d0e9600315 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveIntGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.intClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `int` or [Integer]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt similarity index 72% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt index 67a4426e25..88a7754e98 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveLongGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.longClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `long` or [Long]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt index 57f256fbe3..b22c9dbe92 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/PrimitiveShortGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.shortClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `short` or [Short]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt similarity index 70% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt index 7c76baaf24..78b3529761 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/ShortGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.shortWrapperClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * Produces values of type `short` or [Short]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt similarity index 88% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt index 8defb8a2b8..d4e62457ce 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/StringGenerator.kt @@ -1,6 +1,6 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import kotlin.random.Random /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt index 64b7773afe..0761c36a1e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/lang/strings/CodePoints.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.strings +package org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.strings import java.nio.charset.Charset import java.nio.charset.CharsetEncoder diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt similarity index 84% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt index b7654dfc44..056acd3d31 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/math/BigDecimalGenerator.kt @@ -1,15 +1,15 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.math +package org.utbot.greyboxfuzzer.quickcheck.generator.java.math -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.DecimalGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Precision -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.DecimalGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.Precision +import org.utbot.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.math.BigDecimal import java.math.BigInteger diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt similarity index 77% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt index 9adb9de954..2c8822e113 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/math/BigIntegerGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.math +package org.utbot.greyboxfuzzer.quickcheck.generator.java.math -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.IntegralGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.IntegralGenerator +import org.utbot.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.math.BigInteger /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt similarity index 75% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt index 907082c679..6cb06f878a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/nio/charset/CharsetGenerator.kt @@ -1,15 +1,15 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.nio.charset +package org.utbot.greyboxfuzzer.quickcheck.generator.java.nio.charset -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.stringClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.nio.charset.Charset /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt similarity index 83% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt index 171def0d1e..9c558290cf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ClockGenerator.kt @@ -1,16 +1,16 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.executableId import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Clock import java.time.Instant import java.time.ZoneId diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt similarity index 76% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt index 604af12d67..8ec6950cbe 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/DurationGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Duration /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt similarity index 74% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt index edf5b6c0f9..5aa2145117 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/InstantGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Instant /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt similarity index 77% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt index fbd6ac8fc3..79e73c0072 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/LocalDateGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalDate import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt similarity index 81% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt index 1287209869..836203a8a4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/LocalDateTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalDateTime import java.time.ZoneId import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt similarity index 77% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt index 19ac9d0e6f..e1f93aade3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/LocalTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalTime import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt similarity index 79% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt index 7c5784688f..66d5c44d2a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/MonthDayGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalDate import java.time.MonthDay import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt similarity index 80% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt index 898763ef41..54a46785e3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/OffsetDateTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.OffsetDateTime import java.time.ZoneId import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt similarity index 80% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt index 616a0f16be..0a20bb983b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/OffsetTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.LocalTime import java.time.OffsetTime import java.time.ZoneOffset diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt similarity index 82% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt index 1b9b7e9ae1..17881d428b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/PeriodGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.math.BigInteger import java.time.Period import java.time.Year diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt similarity index 76% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt index 66a97b3e4f..ed0d66a66a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/YearGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Year import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt similarity index 79% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt index 4efa1e6f43..f4a32e3554 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/YearMonthGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Year import java.time.YearMonth import java.time.format.DateTimeFormatter diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt index a431da2bb6..b51eacda26 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ZoneIdGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.ZoneId /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt similarity index 79% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt index db5e492dc7..112d047831 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ZoneOffsetGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.ZoneOffset /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt similarity index 82% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt index 2786dfc151..8f3c99f81f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/time/ZonedDateTimeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.time +package org.utbot.greyboxfuzzer.quickcheck.generator.java.time -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.time.Year import java.time.ZoneId import java.time.ZonedDateTime diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt similarity index 61% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt index ac2fe2ca82..295a36c4ed 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/ArrayListGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [ArrayList]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt similarity index 61% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt index facb65b610..a81931d74e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/BitSetGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.BitSet /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt similarity index 91% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt index b9e399d392..5cf42cfe92 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/CollectionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.FuzzerIllegalStateException +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.booleanClassId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.* +import org.utbot.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt similarity index 76% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt index e8acfb0281..d5077b66f8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/DateGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.text.ParseException import java.text.SimpleDateFormat import java.util.Date diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt similarity index 60% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt index 9477c0d1e4..2269d06745 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/HashMapGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [HashMap]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt similarity index 60% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt index 55e80df390..13d0a41d5d 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/HashSetGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [HashSet]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt similarity index 78% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt index ce5d186df6..7484022431 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/HashtableGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util import java.util.Hashtable diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt similarity index 63% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt index 4e7094326a..d957087fd3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashMapGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [LinkedHashMap]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt similarity index 63% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt index 4b7291aa9b..957d5b1ee0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LinkedHashSetGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util /** * Produces values of type [LinkedHashSet]. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt similarity index 67% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt index e42fc229e6..3b833c9a90 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LinkedListGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util import java.util.LinkedList diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt similarity index 73% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt index ac7a6bfc56..bf5d1195fc 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/ListGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util /** * Base class for generators of [List]s. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt similarity index 57% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt index 36257e62c1..b282d28cb1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/LocaleGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.Locale /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt index 3a17334085..a691b2f840 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/MapGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.FuzzerIllegalStateException +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.booleanClassId import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.* +import org.utbot.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness /** * @@ -22,7 +22,7 @@ import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness * * @param the type of map generated */ -abstract class MapGenerator protected constructor(type: Class<*>) : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(type) { +abstract class MapGenerator protected constructor(type: Class<*>) : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(type) { private var sizeRange: Size? = null private var distinct = false diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt similarity index 67% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt index be11e0e89e..d3871d1eb7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalDoubleGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.DoubleGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.DoubleGenerator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.OptionalDouble /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt similarity index 74% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt index 8465642972..e2db35a95f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalGenerator.kt @@ -1,21 +1,21 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.methodId import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.Optional /** * Produces values of type [Optional]. */ -class OptionalGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Optional::class.java) { +class OptionalGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Optional::class.java) { override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt similarity index 66% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt index ba83f9405d..3e501500f0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalIntGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.IntegerGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.IntegerGenerator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.OptionalInt /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt similarity index 66% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt index 1ad1a8a218..28c1437fb4 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/OptionalLongGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.InRange -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.LongGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.InRange +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.LongGenerator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.OptionalLong /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt similarity index 79% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt index fe5b39b7a0..ea5a769949 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/PropertiesGenerator.kt @@ -1,6 +1,6 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.ConstructorId import org.utbot.framework.plugin.api.UtAssembleModel import org.utbot.framework.plugin.api.UtExecutableCallModel @@ -8,11 +8,11 @@ import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id import org.utbot.framework.plugin.api.util.methodId import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.AbstractStringGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.StringGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.AbstractStringGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.StringGenerator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.Dictionary import java.util.Hashtable import java.util.Properties diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt similarity index 90% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt index 71ed0c5571..1a1928d9e2 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/RFC4122.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorConfiguration -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.StringGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorConfiguration +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.StringGenerator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.nio.ByteBuffer import java.nio.charset.StandardCharsets import java.security.MessageDigest diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt similarity index 64% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt index f1cc2417f5..b11357905c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/SetGenerator.kt @@ -1,6 +1,6 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Size +import org.utbot.greyboxfuzzer.quickcheck.generator.Size /** * Base class for generators of [Set]s. diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt similarity index 63% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt index 6d33652fc2..466a1d6597 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/StackGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util import java.util.Stack diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt index 7d9a50229e..89936c6a76 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/TimeZoneGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.TimeZone /** diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt similarity index 64% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt index 6a70668eed..b7af182a04 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/VectorGenerator.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util import java.util.Vector diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt index 45193fe665..e591313fe6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/concurrent/CallableGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.concurrent +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.concurrent -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.concurrent.Callable /** @@ -14,7 +14,7 @@ import java.util.concurrent.Callable * * @param the type of the values produced by the generated instances */ -class CallableGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Callable::class.java) { +class CallableGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Callable::class.java) { override fun generate( random: SourceOfRandomness, status: GenerationStatus diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt index 96382601c4..f447989cb6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/BiFunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.BiFunction /** @@ -16,7 +16,7 @@ import java.util.function.BiFunction * @param type of second parameter of produced function * @param return type of produced function */ -class BiFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(BiFunction::class.java) { +class BiFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(BiFunction::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt similarity index 55% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt index c9c7ddbe7b..e729c93517 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/BiPredicateGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.BiPredicate /** @@ -17,7 +17,7 @@ import java.util.function.BiPredicate * @param type of first parameter of produced predicate * @param type of second parameter of produced predicate */ -class BiPredicateGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(BiPredicate::class.java) { +class BiPredicateGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(BiPredicate::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt similarity index 55% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt index cc58473432..6147bf71f7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/BinaryOperatorGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.BinaryOperator /** @@ -14,7 +14,7 @@ import java.util.function.BinaryOperator * * @param parameters type and return type of produced operator */ -class BinaryOperatorGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(BinaryOperator::class.java) { +class BinaryOperatorGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(BinaryOperator::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt similarity index 54% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt index 82f6a07b4f..27be498699 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/DoubleFunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.DoubleFunction /** @@ -14,7 +14,7 @@ import java.util.function.DoubleFunction * * @param return type of produced function */ -class DoubleFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(DoubleFunction::class.java) { +class DoubleFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(DoubleFunction::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt similarity index 56% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt index 2a2b199ea9..714980ff70 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/FunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.Function /** @@ -15,7 +15,7 @@ import java.util.function.Function * @param type of parameter of produced function * @param return type of produced function */ -class FunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Function::class.java) { +class FunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Function::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt similarity index 54% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt index a81797b918..d29c87975a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/IntFunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.IntFunction /** @@ -14,7 +14,7 @@ import java.util.function.IntFunction * * @param return type of produced function */ -class IntFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(IntFunction::class.java) { +class IntFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(IntFunction::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt similarity index 54% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt index 1500a5e299..cb102b9b50 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/LongFunctionGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.LongFunction /** @@ -14,7 +14,7 @@ import java.util.function.LongFunction * * @param return type of produced function */ -class LongFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(LongFunction::class.java) { +class LongFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(LongFunction::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt similarity index 54% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt index 523e0d60f7..fdc222b24c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/PredicateGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.Predicate /** @@ -16,7 +16,7 @@ import java.util.function.Predicate * * @param type of parameter of produced predicate */ -class PredicateGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Predicate::class.java) { +class PredicateGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Predicate::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt similarity index 55% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt index 39fe55ea9f..4dae9e940f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/SupplierGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.Supplier /** @@ -14,7 +14,7 @@ import java.util.function.Supplier * * @param the type of the values produced by the generated instances */ -class SupplierGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Supplier::class.java) { +class SupplierGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(Supplier::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt similarity index 56% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt index 4109c68a8b..0fff3f8557 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleBiFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToDoubleBiFunction /** @@ -17,7 +17,7 @@ import java.util.function.ToDoubleBiFunction * @param type of first parameter of produced function * @param type of second parameter of produced function */ -class ToDoubleBiFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToDoubleBiFunction::class.java) { +class ToDoubleBiFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToDoubleBiFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt similarity index 54% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt index 7c88de5e2b..6f9b322a83 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToDoubleFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToDoubleFunction /** @@ -16,7 +16,7 @@ import java.util.function.ToDoubleFunction * * @param type of parameter of produced function */ -class ToDoubleFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToDoubleFunction::class.java) { +class ToDoubleFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToDoubleFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt similarity index 56% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt index 82b6e30c4f..8ebe58fe64 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntBiFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToIntBiFunction /** @@ -17,7 +17,7 @@ import java.util.function.ToIntBiFunction * @param type of first parameter of produced function * @param type of second parameter of produced function */ -class ToIntBiFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToIntBiFunction::class.java) { +class ToIntBiFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToIntBiFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt similarity index 54% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt index d6bd9e84ae..744e34f96b 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToIntFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToIntFunction /** @@ -16,7 +16,7 @@ import java.util.function.ToIntFunction * * @param type of parameter of produced function */ -class ToIntFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToIntFunction::class.java) { +class ToIntFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToIntFunction::class.java) { private var generator: Generator? = null override fun provide(provided: Generators) { super.provide(provided) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt similarity index 56% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt index 7910fbe16f..de8d07607c 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongBiFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToLongBiFunction /** @@ -17,7 +17,7 @@ import java.util.function.ToLongBiFunction * @param type of first parameter of produced function * @param type of second parameter of produced function */ -class ToLongBiFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToLongBiFunction::class.java) { +class ToLongBiFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToLongBiFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt similarity index 54% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt index 109fa2b96f..7bfb920203 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/ToLongFunctionGenerator.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.ToLongFunction /** @@ -16,7 +16,7 @@ import java.util.function.ToLongFunction * * @param type of parameter of produced function */ -class ToLongFunctionGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToLongFunction::class.java) { +class ToLongFunctionGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(ToLongFunction::class.java) { private var generator: Generator? = null override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt similarity index 55% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt index 2a93548da9..361c405e28 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/generator/java/util/function/UnaryOperatorGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.util.function +package org.utbot.greyboxfuzzer.quickcheck.generator.java.util.function -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Lambdas.Companion.makeLambda +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.util.function.UnaryOperator /** @@ -14,7 +14,7 @@ import java.util.function.UnaryOperator * * @param type of parameter and return type of produced operator */ -class UnaryOperatorGenerator : org.utbot.engine.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(UnaryOperator::class.java) { +class UnaryOperatorGenerator : org.utbot.greyboxfuzzer.quickcheck.generator.ComponentizedGenerator(UnaryOperator::class.java) { override fun createModifiedUtModel(random: SourceOfRandomness, status: GenerationStatus): UtModel { return generate(random, status) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt similarity index 96% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt index 25be2fd324..6b4da66459 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/DefaultMethodHandleMaker.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal import java.lang.invoke.MethodHandle import java.lang.invoke.MethodHandles diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt similarity index 96% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt index 8a0ab1d03c..c5f9eef9df 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactory.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal import java.lang.reflect.AnnotatedArrayType import java.lang.reflect.AnnotatedType diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt index 0f35242917..fc56e6eed7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/FakeAnnotatedTypeFactoryWithType.kt @@ -22,7 +22,7 @@ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal import java.lang.reflect.AnnotatedArrayType import java.lang.reflect.AnnotatedType diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt similarity index 84% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt index b3660cd9fa..c571b250ef 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/GeometricDistribution.kt @@ -1,6 +1,6 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import kotlin.math.ceil import kotlin.math.ln diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Items.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Items.kt similarity index 89% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Items.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Items.kt index 8324aaab76..995fd28877 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Items.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Items.kt @@ -1,6 +1,6 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness object Items { @JvmStatic diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt similarity index 97% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt index 5fecaa60db..7e372e3063 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/ParameterTypeContext.kt @@ -1,11 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal import org.javaruntype.type.* import org.javaruntype.type.Type -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Items.choose -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.internal.FakeAnnotatedTypeFactory.makeFrom +import org.utbot.greyboxfuzzer.quickcheck.internal.Items.choose +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import ru.vyarus.java.generics.resolver.GenericsResolver import ru.vyarus.java.generics.resolver.context.GenericsContext import ru.vyarus.java.generics.resolver.context.MethodGenericsContext diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Ranges.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Ranges.kt similarity index 95% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Ranges.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Ranges.kt index 138c4683d6..bbc5c1f1e1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Ranges.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Ranges.kt @@ -1,6 +1,6 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.math.BigInteger object Ranges { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Reflection.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Reflection.kt similarity index 99% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Reflection.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Reflection.kt index b392f58bfe..44b8010a1e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Reflection.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Reflection.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal import org.javaruntype.type.Type import java.lang.reflect.AnnotatedArrayType diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ReflectionException.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/ReflectionException.kt similarity index 72% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ReflectionException.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/ReflectionException.kt index 38f459b385..da1e3f164a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/ReflectionException.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/ReflectionException.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal class ReflectionException : RuntimeException { constructor(message: String) : super(message) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Weighted.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Weighted.kt similarity index 78% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Weighted.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Weighted.kt index b59b45b8e6..bf87843ae5 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/Weighted.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Weighted.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal +package org.utbot.greyboxfuzzer.quickcheck.internal class Weighted(item: T, weight: Int) { val item: T diff --git a/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Zilch.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Zilch.kt new file mode 100644 index 0000000000..84ee41ba05 --- /dev/null +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/Zilch.kt @@ -0,0 +1,3 @@ +package org.utbot.greyboxfuzzer.quickcheck.internal + +object Zilch diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt similarity index 53% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt index b3980c3420..bfd8e5dadf 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/AbstractGenerationStatus.kt @@ -1,8 +1,8 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator +package org.utbot.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.GeometricDistribution -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.internal.GeometricDistribution +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness abstract class AbstractGenerationStatus( private val distro: GeometricDistribution, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt similarity index 91% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt index e75e5a1409..233db2736f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/ArrayGenerator.kt @@ -1,9 +1,9 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator +package org.utbot.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator -import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.generator.GeneratorConfigurator +import org.utbot.greyboxfuzzer.util.FuzzerIllegalStateException +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.ClassId import org.utbot.framework.plugin.api.UtArrayModel import org.utbot.framework.plugin.api.UtModel @@ -17,10 +17,10 @@ import org.utbot.framework.plugin.api.util.floatArrayClassId import org.utbot.framework.plugin.api.util.intArrayClassId import org.utbot.framework.plugin.api.util.longArrayClassId import org.utbot.framework.plugin.api.util.shortArrayClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.* +import org.utbot.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedType class ArrayGenerator(private val componentType: Class<*>, val component: Generator) : Generator(Any::class.java) { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt similarity index 88% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt index 99283dec0a..ce8ac5057a 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/CompositeGenerator.kt @@ -1,13 +1,13 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator +package org.utbot.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator -import org.utbot.engine.greyboxfuzzer.util.FuzzerIllegalStateException +import org.utbot.greyboxfuzzer.generator.GeneratorConfigurator +import org.utbot.greyboxfuzzer.util.FuzzerIllegalStateException import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.* -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Items -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Weighted -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.* +import org.utbot.greyboxfuzzer.quickcheck.internal.Items +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.internal.Weighted +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedElement import java.lang.reflect.AnnotatedType diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt similarity index 68% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt index b5b0d1c312..320366933e 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/EnumGenerator.kt @@ -1,12 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator +package org.utbot.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.engine.greyboxfuzzer.generator.GeneratorConfigurator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.generator.GeneratorConfigurator import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.id -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness class EnumGenerator(private val enumType: Class<*>) : Generator(Enum::class.java) { override fun generate( diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt similarity index 93% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt index 2a5cffde73..b23cc061a6 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/GeneratorRepository.kt @@ -1,14 +1,14 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator - -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.NullAllowed -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Items.choose -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Weighted -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Zilch -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +package org.utbot.greyboxfuzzer.quickcheck.internal.generator + +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.NullAllowed +import org.utbot.greyboxfuzzer.quickcheck.internal.Items.choose +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.internal.Weighted +import org.utbot.greyboxfuzzer.quickcheck.internal.Zilch +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.AnnotatedElement import java.lang.reflect.Field import java.lang.reflect.Parameter diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt similarity index 65% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt index 540f65a934..7096b55e4f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/LambdaGenerator.kt @@ -1,11 +1,11 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator +package org.utbot.greyboxfuzzer.quickcheck.internal.generator import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel import org.utbot.framework.plugin.api.util.objectClassId -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness class LambdaGenerator internal constructor( private val lambdaType: Class, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt similarity index 79% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt index 8564f33e4d..9c9bd344fd 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/MarkerInterfaceGenerator.kt @@ -1,12 +1,12 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator +package org.utbot.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext -import org.utbot.external.api.classIdForType +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.greyboxfuzzer.util.classIdForType import org.utbot.framework.plugin.api.UtModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.DefaultMethodHandleMaker -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.internal.DefaultMethodHandleMaker +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness import java.lang.reflect.InvocationHandler import java.lang.reflect.Method import java.lang.reflect.Proxy diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt similarity index 80% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt index 42da983a3e..cf0bdf72c7 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/NullableGenerator.kt @@ -1,15 +1,15 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator +package org.utbot.greyboxfuzzer.quickcheck.internal.generator import org.javaruntype.type.TypeParameter -import org.utbot.external.api.classIdForType import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.UtNullModel -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GenerationStatus -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generator -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.Generators -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.NullAllowed -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Reflection -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.generator.Generators +import org.utbot.greyboxfuzzer.quickcheck.generator.NullAllowed +import org.utbot.greyboxfuzzer.quickcheck.internal.Reflection +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.util.classIdForType import java.lang.reflect.AnnotatedElement import java.lang.reflect.AnnotatedType import java.util.Optional diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt similarity index 51% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt index b9d166989b..1fc51c9533 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/SimpleGenerationStatus.kt @@ -1,7 +1,7 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.internal.generator +package org.utbot.greyboxfuzzer.quickcheck.internal.generator -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.GeometricDistribution -import org.utbot.engine.greyboxfuzzer.quickcheck.random.SourceOfRandomness +import org.utbot.greyboxfuzzer.quickcheck.internal.GeometricDistribution +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness class SimpleGenerationStatus( distro: GeometricDistribution, diff --git a/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt new file mode 100644 index 0000000000..74cb6ece3e --- /dev/null +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/internal/generator/ZilchGenerator.kt @@ -0,0 +1,18 @@ +package org.utbot.greyboxfuzzer.quickcheck.internal.generator + +import org.utbot.framework.plugin.api.UtModel +import org.utbot.framework.plugin.api.UtNullModel +import org.utbot.framework.plugin.api.util.objectClassId +import org.utbot.greyboxfuzzer.quickcheck.generator.GenerationStatus +import org.utbot.greyboxfuzzer.quickcheck.generator.Generator +import org.utbot.greyboxfuzzer.quickcheck.internal.Zilch +import org.utbot.greyboxfuzzer.quickcheck.random.SourceOfRandomness + +class ZilchGenerator : Generator(Zilch::class.java) { + override fun generate( + random: SourceOfRandomness, + status: GenerationStatus + ): UtModel { + return UtNullModel(objectClassId)// generatorContext.utModelConstructor.construct(Zilch, classIdForType(Zilch::class.java)) + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt index e379a84856..9794f47dd8 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/quickcheck/random/SourceOfRandomness.kt @@ -1,7 +1,7 @@ -package org.utbot.engine.greyboxfuzzer.quickcheck.random +package org.utbot.greyboxfuzzer.quickcheck.random -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Items -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.Ranges +import org.utbot.greyboxfuzzer.quickcheck.internal.Items +import org.utbot.greyboxfuzzer.quickcheck.internal.Ranges import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import java.io.IOException diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/CoverageCollector.kt similarity index 93% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/CoverageCollector.kt index 8b8efdcd85..a44decd4be 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/CoverageCollector.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/CoverageCollector.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.util +package org.utbot.greyboxfuzzer.util import org.utbot.framework.plugin.api.Instruction import java.util.concurrent.ConcurrentHashMap diff --git a/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/CustomClassLoader.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/CustomClassLoader.kt new file mode 100644 index 0000000000..2ef7ab914b --- /dev/null +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/CustomClassLoader.kt @@ -0,0 +1,9 @@ +//package org.utbot.greyboxfuzzer.util +// +//import java.net.URLClassLoader +// +//object CustomClassLoader { +// lateinit var classLoader: ClassLoader +// +// fun isClassLoaderInitialized() = this::classLoader.isInitialized +//} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/FuzzerIllegalStateException.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/FuzzerIllegalStateException.kt similarity index 58% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/FuzzerIllegalStateException.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/FuzzerIllegalStateException.kt index 618fc7a9e3..7f2b1a9d4f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/FuzzerIllegalStateException.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/FuzzerIllegalStateException.kt @@ -1,3 +1,3 @@ -package org.utbot.engine.greyboxfuzzer.util +package org.utbot.greyboxfuzzer.util class FuzzerIllegalStateException(msg: String): Exception(msg) \ No newline at end of file diff --git a/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/FuzzerUtModelConstructor.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/FuzzerUtModelConstructor.kt new file mode 100644 index 0000000000..b757ba35f1 --- /dev/null +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/FuzzerUtModelConstructor.kt @@ -0,0 +1,9 @@ +package org.utbot.greyboxfuzzer.util + +import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.UtModel + +data class FuzzerUtModelConstructor( + val construct: (Any?, ClassId) -> UtModel, + val computeUnusedIdAndUpdate: () -> Int +) \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GenericsReplacer.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/GenericsReplacer.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GenericsReplacer.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/GenericsReplacer.kt index af052847d6..d84dfd6250 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/GenericsReplacer.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/GenericsReplacer.kt @@ -1,4 +1,4 @@ -//package org.utbot.engine.greyboxfuzzer.util +//package org.utbot.greyboxfuzzer.util // //import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl //import java.lang.reflect.Parameter diff --git a/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt new file mode 100644 index 0000000000..ee5a63fcf2 --- /dev/null +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/GreyBoxFuzzingStatisticPrinter.kt @@ -0,0 +1,51 @@ +package org.utbot.greyboxfuzzer.util + +import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.api.UtExecution + +object GreyBoxFuzzingStatisticPrinter { + + fun printFuzzingStats(methods2executions: Map>) { + val methodsToInstructionsNumbers = methods2executions.entries.map { (method, executions) -> + val methodInstructions = + (executions.firstOrNull() as? UtGreyBoxFuzzedExecution)?.fuzzingResult?.methodInstructions ?: setOf() + method to methodInstructions + } + logger.debug { "OVERALL RESULTS:" } + logger.debug { "------------------------------------------" } + for ((method, instructions) in methodsToInstructionsNumbers) { + val coveredMethodInstructions = CoverageCollector.coverage + .asSequence() + .filter { it.className == method.classId.name.replace('.', '/') } + .filter { it.methodSignature == method.signature } + .toSet() + val coveredMethodLines = coveredMethodInstructions.map { it.lineNumber }.toSet() + val methodLines = instructions.map { it.lineNumber }.toSet() + + logger.debug { "METHOD: ${method.name}" } + logger.debug { "COVERED INSTRUCTIONS: ${coveredMethodInstructions.size} from ${instructions.size} ${coveredMethodInstructions.size.toDouble() / instructions.size * 100}%" } + logger.debug { "COVERED INSTRUCTIONS: ${coveredMethodInstructions.map { it.id }.sorted()}" } + logger.debug { "NOT COVERED INSTRUCTIONS: ${instructions.filter { it !in coveredMethodInstructions }.map { it.id }.sorted()}" } + logger.debug { "------" } + logger.debug { "COVERED LINES: ${coveredMethodLines.size} from ${methodLines.size} ${coveredMethodLines.size.toDouble() / methodLines.size * 100}%" } + logger.debug { "COVERED LINES: ${coveredMethodLines.sorted()}" } + logger.debug { "NOT COVERED LINES: ${methodLines.filter { it !in coveredMethodLines }.sorted()}" } + logger.debug { "----------------------" } + } + logger.debug { "-----------------------------------------------------" } + val allInstructionsToCover = methodsToInstructionsNumbers.flatMap { it.second }.toSet() + val allClassNames = methodsToInstructionsNumbers.map { it.first.classId }.toSet().map { it.name } + val allInstructionsToCoverSize = allInstructionsToCover.size + val allMethodLineNumbersSize = methodsToInstructionsNumbers.flatMap { it.second.map { it.lineNumber }.toSet() }.size + val coveredInstructions = + CoverageCollector.coverage + .filter { it.className.replace('/', '.') in allClassNames } + .toSet() + .filter { it in allInstructionsToCover } + val numberOfCoveredLines = coveredInstructions.map { it.lineNumber }.toSet().size + val numberOfCoveredInstructions = coveredInstructions.size + logger.debug { "IN INSTRUCTIONS FINALLY COVERED $numberOfCoveredInstructions from $allInstructionsToCoverSize ${numberOfCoveredInstructions.toDouble() / allInstructionsToCoverSize * 100}%" } + logger.debug { "IN LINES FINALLY COVERED $numberOfCoveredLines from $allMethodLineNumbersSize ${numberOfCoveredLines.toDouble() / allMethodLineNumbersSize * 100}%" } + logger.debug { "------------------------------------------" } + } +} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/KotlinUtils.kt similarity index 63% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/KotlinUtils.kt index 3564133913..acf3bfc93f 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/KotlinUtils.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/KotlinUtils.kt @@ -1,6 +1,6 @@ -package org.utbot.engine.greyboxfuzzer.util +package org.utbot.greyboxfuzzer.util -import org.utbot.engine.greyboxfuzzer.util.kcheck.nextInRange +import org.utbot.greyboxfuzzer.util.kcheck.nextInRange import java.util.* fun kotlin.random.Random.getTrue(prob: Int) = Random().nextInRange(0, 100) < prob @@ -10,23 +10,6 @@ fun List.sublistBeforeLast(element: T): List = if (lastIndex == -1) this else this.subList(0, lastIndex) } - -fun Iterable.filterDuplicates(comparator: Comparator): List { - val res = mutableListOf() - this.forEach { el -> if (res.all { comparator.compare(it, el) != 0 }) res.add(el) } - return res -} - -fun Collection.filterDuplicatesBy(f: (T) -> R): List { - val list1 = this.zip(this.map(f)) - val res = mutableListOf>() - for (i in indices) { - val item = list1[i].second - if (res.all { it.second != item }) res.add(list1[i]) - } - return res.map { it.first } -} - fun MutableList.removeIfAndReturnRemovedElements(cond: (T) -> Boolean): List { val res = mutableListOf() val iterator = this.iterator() diff --git a/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/Logger.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/Logger.kt new file mode 100644 index 0000000000..35ead6f59d --- /dev/null +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/Logger.kt @@ -0,0 +1,6 @@ +package org.utbot.greyboxfuzzer.util + +import mu.KotlinLogging + +class Logger +val logger = KotlinLogging.logger {} \ No newline at end of file diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/ReflectionUtils.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/ReflectionUtils.kt index 4891d32694..c248374d13 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/ReflectionUtils.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/ReflectionUtils.kt @@ -1,11 +1,10 @@ @file:Suppress("JAVA_MODULE_DOES_NOT_EXPORT_PACKAGE") -package org.utbot.engine.greyboxfuzzer.util +package org.utbot.greyboxfuzzer.util -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext import org.javaruntype.type.Types import org.utbot.common.withAccessibility -import org.utbot.engine.rawType import ru.vyarus.java.generics.resolver.context.GenericsContext import ru.vyarus.java.generics.resolver.context.GenericsInfo import sun.reflect.generics.reflectiveObjects.GenericArrayTypeImpl @@ -27,6 +26,8 @@ fun Class<*>.getAllDeclaredFields(): List { return res } +val java.lang.reflect.Type.rawType: java.lang.reflect.Type + get() = if (this is ParameterizedType) rawType else this fun Class<*>.getAllDeclaredMethodsAndConstructors(): List { val res = mutableListOf() res.addAll(declaredConstructors) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/SootUtils.kt similarity index 75% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/SootUtils.kt index 5eb8052b38..eed0d641f9 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/SootUtils.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/SootUtils.kt @@ -1,12 +1,10 @@ -package org.utbot.engine.greyboxfuzzer.util +package org.utbot.greyboxfuzzer.util -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.java.lang.* -import org.utbot.framework.concrete.constructors.UtModelConstructor +import org.utbot.greyboxfuzzer.quickcheck.generator.java.lang.* import org.utbot.framework.plugin.api.ClassId +import org.utbot.framework.plugin.api.ExecutableId import org.utbot.framework.plugin.api.UtModel import org.utbot.framework.plugin.api.util.* -import org.utbot.fuzzer.FuzzedConcreteValue -import org.utbot.fuzzer.collectConstantsForFuzzer import soot.ArrayType import soot.Hierarchy import soot.RefType @@ -103,6 +101,15 @@ fun SootMethod.getAllTypesFromCastAndInstanceOfInstructions(): Set> = } }.toSet() +val SootMethod.pureJavaSignature + get() = bytecodeSignature.substringAfter(' ').dropLast(1) + +val ExecutableId.sootMethod: SootMethod + get() { + val clazz = Scene.v().getSootClass(classId.name) + return clazz.methods.single { it.pureJavaSignature == signature } + } + fun SootMethod.getClassFieldsUsedByFunc(clazz: Class<*>) = activeBody.units .asSequence() @@ -117,7 +124,7 @@ fun SootClass.toJavaClass(): Class<*>? = Class.forName(this.name) } catch (e: Throwable) { try { - CustomClassLoader.classLoader.loadClass(this.name) + utContext.classLoader.loadClass(this.name) } catch (e: Throwable) { null } @@ -147,35 +154,6 @@ fun SootField.toJavaField(): Field? = fun Field.toSootField(): SootField? = declaringClass.toSootClass()?.fields?.find { it.name == name } -fun SootMethod.collectConstants(utModelConstructor: UtModelConstructor): Map> { - val sootGraph = ExceptionalUnitGraph(activeBody) - - fun generateConstantsForBothPrimitives(classId: ClassId, value: Any, utModelConstructor: UtModelConstructor) = - when (classId) { - intWrapperClassId -> listOf(intClassId to utModelConstructor.construct(value, intClassId)) - intClassId -> listOf(intWrapperClassId to utModelConstructor.construct(value, intWrapperClassId)) - byteWrapperClassId -> listOf(byteClassId to utModelConstructor.construct(value, byteClassId)) - byteClassId -> listOf(byteWrapperClassId to utModelConstructor.construct(value, byteWrapperClassId)) - charWrapperClassId -> listOf(charClassId to utModelConstructor.construct(value, charClassId)) - charClassId -> listOf(charWrapperClassId to utModelConstructor.construct(value, charWrapperClassId)) - doubleWrapperClassId -> listOf(doubleClassId to utModelConstructor.construct(value, doubleClassId)) - doubleClassId -> listOf(doubleWrapperClassId to utModelConstructor.construct(value, doubleWrapperClassId)) - longWrapperClassId -> listOf(longClassId to utModelConstructor.construct(value, longClassId)) - longClassId -> listOf(longWrapperClassId to utModelConstructor.construct(value, longWrapperClassId)) - floatWrapperClassId -> listOf(floatClassId to utModelConstructor.construct(value, floatClassId)) - floatClassId -> listOf(floatWrapperClassId to utModelConstructor.construct(value, floatWrapperClassId)) - shortWrapperClassId -> listOf(shortClassId to utModelConstructor.construct(value, shortClassId)) - shortClassId -> listOf(shortWrapperClassId to utModelConstructor.construct(value, shortWrapperClassId)) - stringClassId -> listOf() - else -> null - }?.let { it + listOf(classId to utModelConstructor.construct(value, classId)) } ?: listOf() - - return collectConstantsForFuzzer(sootGraph) - .filterDuplicatesBy { it.value } - .flatMap { generateConstantsForBothPrimitives(it.classId, it.value, utModelConstructor) } - .groupBy({ it.first }, { it.second }) -} - fun SootClass.getAllAncestors(): List { val queue = ArrayDeque() val res = mutableSetOf() @@ -204,6 +182,7 @@ val SootClass.superclassOrNull null } + //TODO add stuff with generics object SootStaticsCollector { diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/UtBotUtils.kt similarity index 84% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/UtBotUtils.kt index 231fdf19ad..3983d088a1 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtBotUtils.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/UtBotUtils.kt @@ -1,11 +1,10 @@ -package org.utbot.engine.greyboxfuzzer.util +package org.utbot.greyboxfuzzer.util -import org.utbot.engine.greyboxfuzzer.quickcheck.internal.ParameterTypeContext -import org.utbot.engine.greyboxfuzzer.generator.* -import org.utbot.external.api.classIdForType -import org.utbot.framework.concrete.constructors.UtModelConstructor +import org.utbot.greyboxfuzzer.quickcheck.internal.ParameterTypeContext +import org.utbot.greyboxfuzzer.generator.* import org.utbot.framework.plugin.api.* -import org.utbot.engine.greyboxfuzzer.quickcheck.generator.GeneratorContext +import org.utbot.framework.plugin.api.util.id +import org.utbot.greyboxfuzzer.quickcheck.generator.GeneratorContext import java.lang.reflect.Method import java.lang.reflect.Parameter @@ -16,9 +15,16 @@ fun UtAssembleModel.addModification(modifications: List) = this.classId, "${this.classId.name}#" + this.id?.toString(16), this.instantiationCall, - this.modificationsChain + modifications, this.origin - ) + ) { modificationsChain + modifications } +// UtAssembleModel( +// this.id, +// this.classId, +// "${this.classId.name}#" + this.id?.toString(16), +// this.instantiationCall, +// this.modificationsChain + modifications, +// this.origin +// ) fun UtAssembleModel.addOrReplaceModification(newModification: UtStatementModel): UtAssembleModel { val newModificationChain = @@ -46,9 +52,8 @@ fun UtAssembleModel.addOrReplaceModification(newModification: UtStatementModel): this.classId, "${this.classId.name}#" + this.id?.toString(16), this.instantiationCall, - newModificationChain, this.origin - ) + ) { newModificationChain } } fun UtModel.copy(): UtModel = @@ -63,7 +68,7 @@ fun UtModel.copy(): UtModel = -fun UtModelConstructor.constructAssembleModelUsingMethodInvocation( +fun FuzzerUtModelConstructor.constructAssembleModelUsingMethodInvocation( clazz: Class<*>, methodExecutableId: ExecutableId, parameterValues: List, @@ -82,6 +87,9 @@ fun UtModelConstructor.constructAssembleModelUsingMethodInvocation( ) } +fun classIdForType(clazz: Class<*>): ClassId { + return clazz.id +} //fun UtModelConstructor.constructModelFromValue(value: Any?, classId: ClassId) = // if (value == null) { // UtNullModel(classId) diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt similarity index 73% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt index b312c3fd7e..554a7de385 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/UtGreyBoxFuzzedExecution.kt @@ -1,8 +1,16 @@ -package org.utbot.engine.greyboxfuzzer.util +package org.utbot.greyboxfuzzer.util -import org.utbot.framework.concrete.UtFuzzingConcreteExecutionResult import org.utbot.framework.plugin.api.* +class UtFuzzingConcreteExecutionResult( + val stateAfter: EnvironmentModels?, + val result: UtExecutionResult, + val coverage: Coverage, + val methodInstructions: List? +) + +//class UtFuzzExecutionResult() : UtConcreteExecutionResult + class UtGreyBoxFuzzedExecution( stateBefore: EnvironmentModels, val fuzzingResult: UtFuzzingConcreteExecutionResult, diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/Common.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/kcheck/Common.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/Common.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/kcheck/Common.kt index 4139bed5a7..44b057c4f3 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/Common.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/kcheck/Common.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.util.kcheck +package org.utbot.greyboxfuzzer.util.kcheck import java.util.* diff --git a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/RandomEx.kt b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/kcheck/RandomEx.kt similarity index 98% rename from utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/RandomEx.kt rename to utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/kcheck/RandomEx.kt index 69f7dce847..c8a1a8e6e0 100644 --- a/utbot-framework/src/main/kotlin/org/utbot/engine/greyboxfuzzer/util/kcheck/RandomEx.kt +++ b/utbot-greyboxfuzzer/src/main/kotlin/org/utbot/greyboxfuzzer/util/kcheck/RandomEx.kt @@ -1,4 +1,4 @@ -package org.utbot.engine.greyboxfuzzer.util.kcheck +package org.utbot.greyboxfuzzer.util.kcheck import java.util.* diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt index d6a9b0a962..2f57abebd0 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/et/TraceHandler.kt @@ -11,6 +11,7 @@ import org.objectweb.asm.MethodVisitor import org.objectweb.asm.Opcodes import org.objectweb.asm.Type import org.objectweb.asm.commons.LocalVariablesSorter +import org.utbot.framework.plugin.api.Instruction sealed class InstructionData { abstract val line: Int @@ -62,7 +63,7 @@ class ProcessingStorage { private val classMethodToId = mutableMapOf() private val idToClassMethod = mutableMapOf() - val instructionsData = mutableMapOf() + private val instructionsData = mutableMapOf() private val classToInstructionsCount = mutableMapOf() fun addClass(className: String): Int { @@ -103,6 +104,18 @@ class ProcessingStorage { return instructionsData.getValue(id) } + fun getMethodInstructions(className: String, methodSignature: String): List = + instructionsData + .filter { + val insClassName = computeClassNameAndLocalId(it.key).first + insClassName == className && it.value.methodSignature == methodSignature + }.map { Instruction(className, it.value.methodSignature, it.value.line, it.key % SHIFT) } + + fun convertToLocalInstruction(instruction: Instruction): Instruction = + with (instruction) { + Instruction(className, methodSignature, lineNumber, id % SHIFT) + } + companion object { private const val SHIFT = 1.toLong().shl(32) // 2 ^ 32 } @@ -220,12 +233,6 @@ class TraceHandler { return instructionsList!! } - fun getMethodInstructions(className: String, methodSignature: String) = - processingStorage.instructionsData.entries.filter { - val insClassName = processingStorage.computeClassNameAndLocalId(it.key).first - insClassName == className && it.value.methodSignature == methodSignature - } - fun computePutStatics(): List = computeInstructionList().map { it.instructionData } .filterIsInstance() diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/FuzzerConcreteExecutor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/FuzzerConcreteExecutor.kt new file mode 100644 index 0000000000..95a970011f --- /dev/null +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/FuzzerConcreteExecutor.kt @@ -0,0 +1,91 @@ +package org.utbot.framework.concrete + +import org.utbot.framework.UtSettings +import org.utbot.framework.plugin.api.EnvironmentModels +import org.utbot.framework.plugin.api.ExecutableId +import org.utbot.framework.plugin.api.UtInstrumentation +import org.utbot.framework.plugin.api.util.utContext +import org.utbot.greyboxfuzzer.util.UtFuzzingConcreteExecutionResult +import org.utbot.instrumentation.ConcreteExecutor + +class FuzzerConcreteExecutor( + private val pathsToUserClasses: String, + private val pathsToDependencyClasses: String, +) { + + suspend fun execute( + methodUnderTest: ExecutableId, + stateBefore: EnvironmentModels, + instrumentation: List + ): UtFuzzingConcreteExecutionResult { +// val fuzzingExecutor = +// ConcreteExecutor( +// UtFuzzingExecutionInstrumentation/*(UtSettings.greyBoxFuzzingCompetitionMode)*/, +// pathsToUserClasses, +// pathsToDependencyClasses +// ).apply { this.classLoader = utContext.classLoader } +// val executionResult = fuzzingExecutor.executeConcretelyFuzz(methodUnderTest, stateBefore, instrumentation) +// return UtFuzzingConcreteExecutionResult( +// null, +// executionResult.result, +// executionResult.coverage, +// executionResult.methodInstructionsIds +// ) + return if (UtSettings.greyBoxFuzzingCompetitionMode) { + val fuzzingExecutor = + ConcreteExecutor( + UtFuzzingExecutionInstrumentation, + pathsToUserClasses, + pathsToDependencyClasses + ).apply { this.classLoader = utContext.classLoader } + val executionResult = fuzzingExecutor.executeConcretelyFuzz(methodUnderTest, stateBefore, instrumentation) + UtFuzzingConcreteExecutionResult( + null, + executionResult.result, + executionResult.coverage, + executionResult.methodInstructions + ) + } else { + val fuzzingExecutor = + ConcreteExecutor( + UtFuzzingExecutionInstrumentationWithStateAfterCollection, + pathsToUserClasses, + pathsToDependencyClasses + ).apply { this.classLoader = utContext.classLoader } + val executionResult = fuzzingExecutor.executeConcretelyFuzzWithStateAfterCollection( + methodUnderTest, + stateBefore, + instrumentation + ) + UtFuzzingConcreteExecutionResult( + executionResult.stateAfter, + executionResult.result, + executionResult.coverage, + executionResult.methodInstructions + ) + } + } + + private suspend fun ConcreteExecutor.executeConcretelyFuzz( + methodUnderTest: ExecutableId, + stateBefore: EnvironmentModels, + instrumentation: List + ): UtFuzzingConcreteExecutionResult = executeAsync( + methodUnderTest.classId.name, + methodUnderTest.signature, + arrayOf(), + parameters = UtConcreteExecutionData(stateBefore, instrumentation) + ) + + private suspend fun ConcreteExecutor.executeConcretelyFuzzWithStateAfterCollection( + methodUnderTest: ExecutableId, + stateBefore: EnvironmentModels, + instrumentation: List + ): UtFuzzingConcreteExecutionResult = executeAsync( + methodUnderTest.classId.name, + methodUnderTest.signature, + arrayOf(), + parameters = UtConcreteExecutionData(stateBefore, instrumentation) + ) + +} \ No newline at end of file diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentationWithStatsCollection.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentationWithStatsCollection.kt new file mode 100644 index 0000000000..f608adeb02 --- /dev/null +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtExecutionInstrumentationWithStatsCollection.kt @@ -0,0 +1,94 @@ +package org.utbot.framework.concrete + +import org.utbot.framework.concrete.constructors.ConstructOnlyUserClassesOrCachedObjectsStrategy +import org.utbot.framework.concrete.constructors.UtModelConstructor +import org.utbot.framework.concrete.mock.InstrumentationContext +import org.utbot.framework.plugin.api.* +import org.utbot.greyboxfuzzer.util.UtFuzzingConcreteExecutionResult +import org.utbot.instrumentation.instrumentation.Instrumentation +import org.utbot.instrumentation.instrumentation.InvokeInstrumentation +import org.utbot.instrumentation.instrumentation.et.ExplicitThrowInstruction +import org.utbot.instrumentation.instrumentation.et.TraceHandler +import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter +import org.utbot.instrumentation.instrumentation.mock.MockClassVisitor +import org.utbot.framework.concrete.mock.InstrumentationContext.MockGetter +import java.security.AccessControlException +import java.security.ProtectionDomain +import java.util.* +import kotlin.reflect.jvm.javaMethod + +interface UtExecutionInstrumentationWithStatsCollection : Instrumentation { + + val delegateInstrumentation: InvokeInstrumentation// = InvokeInstrumentation() + + val instrumentationContext: InstrumentationContext// = InstrumentationContext() + + val traceHandler: TraceHandler //= TraceHandler() + val pathsToUserClasses: MutableSet// = mutableSetOf() + override fun init(pathsToUserClasses: Set) { + this.pathsToUserClasses.clear() + this.pathsToUserClasses += pathsToUserClasses + } + + override fun getStaticField(fieldId: FieldId): Result = + delegateInstrumentation.getStaticField(fieldId).map { value -> + val cache = IdentityHashMap() + val strategy = ConstructOnlyUserClassesOrCachedObjectsStrategy( + pathsToUserClasses, cache + ) + UtModelConstructor(cache, strategy).run { + construct(value, fieldId.type) + } + } + + + fun sortOutException(exception: Throwable): UtExecutionFailure { + if (exception is TimeoutException) { + return UtTimeoutException(exception) + } + if (exception is AccessControlException) { + return UtSandboxFailure(exception) + } + val instrs = traceHandler.computeInstructionList() + val isNested = if (instrs.isEmpty()) { + false + } else { + instrs.first().callId != instrs.last().callId + } + return if (instrs.isNotEmpty() && instrs.last().instructionData is ExplicitThrowInstruction) { + UtExplicitlyThrownException(IllegalStateException(exception::javaClass.name), isNested) + } else { + UtImplicitlyThrownException(IllegalStateException(exception::javaClass.name), isNested) + } + + } + + override fun transform( + loader: ClassLoader?, + className: String, + classBeingRedefined: Class<*>?, + protectionDomain: ProtectionDomain, + classfileBuffer: ByteArray + ): ByteArray { + val instrumenter = Instrumenter(classfileBuffer, loader) + + traceHandler.registerClass(className) + instrumenter.visitInstructions(traceHandler.computeInstructionVisitor(className)) + + val mockClassVisitor = instrumenter.visitClass { writer -> + MockClassVisitor( + writer, + MockGetter::getMock.javaMethod!!, + MockGetter::checkCallSite.javaMethod!!, + MockGetter::hasMock.javaMethod!! + ) + } + + mockClassVisitor.signatureToId.forEach { (method, id) -> + instrumentationContext.methodSignatureToId += method to id + } + + return instrumenter.classByteCode + } + +} \ No newline at end of file diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt index c078c533ce..88cf430337 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/UtFuzzingExecutionInstrumentation.kt @@ -1,210 +1,188 @@ package org.utbot.framework.concrete -import org.objectweb.asm.Type -import org.utbot.common.StopWatch -import org.utbot.common.ThreadBasedExecutor -import org.utbot.common.withAccessibility import org.utbot.framework.concrete.constructors.ConstructOnlyUserClassesOrCachedObjectsStrategy -import org.utbot.framework.concrete.constructors.MockValueConstructor -import org.utbot.framework.concrete.constructors.UtModelConstructor import org.utbot.framework.concrete.mock.InstrumentationContext +import org.utbot.framework.concrete.phases.PhasesController +import org.utbot.framework.concrete.phases.start import org.utbot.framework.plugin.api.* import org.utbot.framework.plugin.api.util.* -import org.utbot.framework.util.isInaccessibleViaReflection +import org.utbot.greyboxfuzzer.util.UtFuzzingConcreteExecutionResult import org.utbot.instrumentation.instrumentation.ArgumentList -import org.utbot.instrumentation.instrumentation.Instrumentation import org.utbot.instrumentation.instrumentation.InvokeInstrumentation -import org.utbot.instrumentation.instrumentation.et.ExplicitThrowInstruction import org.utbot.instrumentation.instrumentation.et.TraceHandler -import org.utbot.instrumentation.instrumentation.instrumenter.Instrumenter -import org.utbot.instrumentation.instrumentation.mock.MockClassVisitor -import java.security.AccessControlException -import java.security.ProtectionDomain -import java.util.* -import kotlin.reflect.jvm.javaMethod -class UtFuzzingConcreteExecutionResult( - val result: UtExecutionResult, - val coverage: Coverage, - val methodInstructionsIds: Set -) {} +object UtFuzzingExecutionInstrumentation : UtExecutionInstrumentationWithStatsCollection { + override val delegateInstrumentation: InvokeInstrumentation = InvokeInstrumentation() -object UtFuzzingExecutionInstrumentation : Instrumentation { - private val delegateInstrumentation = InvokeInstrumentation() + override val instrumentationContext: InstrumentationContext = InstrumentationContext() - private val instrumentationContext = InstrumentationContext() - - private val traceHandler = TraceHandler() - private val pathsToUserClasses = mutableSetOf() - - override fun init(pathsToUserClasses: Set) { - this.pathsToUserClasses.clear() - this.pathsToUserClasses += pathsToUserClasses - } - - /** - * Ignores [arguments], because concrete arguments will be constructed - * from models passed via [parameters]. - * - * Argument [parameters] must be of type [UtConcreteExecutionData]. - */ + override val traceHandler: TraceHandler = TraceHandler() + override val pathsToUserClasses: MutableSet = mutableSetOf() override fun invoke( clazz: Class<*>, methodSignature: String, arguments: ArgumentList, parameters: Any? ): UtFuzzingConcreteExecutionResult { - if (parameters !is UtConcreteExecutionData) { throw IllegalArgumentException("Argument parameters must be of type UtConcreteExecutionData, but was: ${parameters?.javaClass}") } val (stateBefore, instrumentations, timeout) = parameters // smart cast to UtConcreteExecutionData - val parametersModels = listOfNotNull(stateBefore.thisInstance) + stateBefore.parameters - traceHandler.resetTrace() - return MockValueConstructor(instrumentationContext).use { constructor -> - val params = constructor.constructMethodParameters(parametersModels) - val staticFields = constructor - .constructStatics( - stateBefore - .statics - .filterKeys { !it.isInaccessibleViaReflection } - ) - .mapValues { (_, value) -> value.value } - - val concreteExecutionResult = withStaticFields(staticFields) { - val staticMethodsInstrumentation = instrumentations.filterIsInstance() - constructor.mockStaticMethods(staticMethodsInstrumentation) - val newInstanceInstrumentation = instrumentations.filterIsInstance() - constructor.mockNewInstances(newInstanceInstrumentation) - - traceHandler.resetTrace() - val stopWatch = StopWatch() - val context = UtContext(utContext.classLoader, stopWatch) - val concreteResult = - try { - ThreadBasedExecutor.threadLocal.invokeWithTimeout(timeout, stopWatch) { - withUtContext(context) { - delegateInstrumentation.invoke(clazz, methodSignature, params.map { it.value }) - } - }?.getOrThrow() as? Result<*> ?: Result.failure(TimeoutException("Timeout $timeout elapsed")) - } catch (e: Throwable) { - null - } - val traceList = traceHandler.computeInstructionList() - - val cache = constructor.objectToModelCache - val utCompositeModelStrategy = - ConstructOnlyUserClassesOrCachedObjectsStrategy(pathsToUserClasses, cache) - val utModelConstructor = UtModelConstructor(cache, utCompositeModelStrategy) - utModelConstructor.run { - val concreteUtModelResult = concreteResult?.fold({ - UtExecutionSuccess(UtNullModel(it?.javaClass?.id ?: objectClassId)) - }) { - sortOutException(it) - } ?: UtExecutionSuccess(UtNullModel(objectClassId)) - val coverage = traceList.toApiCoverage( - traceHandler.processingStorage.getInstructionsCount( - Type.getInternalName(clazz) - ) - ) - val classJVMName = clazz.name.replace('.', '/') - val methodInstructions = traceHandler.getMethodInstructions(classJVMName, methodSignature) - val methodInstructionsIds = methodInstructions.map { it.key }.toSet() - UtFuzzingConcreteExecutionResult( - concreteUtModelResult, - coverage, - methodInstructionsIds - ) - } + return PhasesController( + instrumentationContext, + traceHandler, + delegateInstrumentation, + generateNullOnError = true + ).computeFuzzingConcreteExecutionResult { + // construction + val (params, statics, cache) = valueConstructionContext.start { + val params = constructParameters(stateBefore) + val statics = constructStatics(stateBefore) + + mock(instrumentations) + + Triple(params, statics, getCache()) } - concreteExecutionResult - } + // preparation + val savedStatics = preparationContext.start { + val savedStatics = setStaticFields(statics) + resetTrace() + savedStatics + } - } + try { + // invocation + val concreteResult = invocationContext.start { + invoke(clazz, methodSignature, params.map { it.value }, timeout) + } + + // statistics collection + val coverage = statisticsCollectionContext.start { getCoverage(clazz) }.toLocalCoverage(traceHandler) + val classJVMName = clazz.name.replace('.', '/') + val methodInstructions = + traceHandler.processingStorage.getMethodInstructions(classJVMName, methodSignature) - override fun getStaticField(fieldId: FieldId): Result = - delegateInstrumentation.getStaticField(fieldId).map { value -> - val cache = IdentityHashMap() - val strategy = ConstructOnlyUserClassesOrCachedObjectsStrategy( - pathsToUserClasses, cache - ) - UtModelConstructor(cache, strategy).run { - construct(value, fieldId.type) + val concreteUtModelResult = concreteResult.fold({ + UtExecutionSuccess(UtNullModel(it?.javaClass?.id ?: objectClassId)) + }) { + sortOutException(it) + } + + + UtFuzzingConcreteExecutionResult( + null, + concreteUtModelResult, + coverage, + methodInstructions + ) + + } finally { + // postprocessing + postprocessingContext.start { + resetStaticFields(savedStatics) + } } } + } +} +object UtFuzzingExecutionInstrumentationWithStateAfterCollection : UtExecutionInstrumentationWithStatsCollection { - private fun sortOutException(exception: Throwable): UtExecutionFailure { - if (exception is TimeoutException) { - return UtTimeoutException(exception) - } - if (exception is AccessControlException) { - return UtSandboxFailure(exception) - } - val instrs = traceHandler.computeInstructionList() - val isNested = if (instrs.isEmpty()) { - false - } else { - instrs.first().callId != instrs.last().callId - } - return if (instrs.isNotEmpty() && instrs.last().instructionData is ExplicitThrowInstruction) { - UtExplicitlyThrownException(exception, isNested) - } else { - UtImplicitlyThrownException(exception, isNested) - } + override val delegateInstrumentation: InvokeInstrumentation = InvokeInstrumentation() - } + override val instrumentationContext: InstrumentationContext = InstrumentationContext() - override fun transform( - loader: ClassLoader?, - className: String, - classBeingRedefined: Class<*>?, - protectionDomain: ProtectionDomain, - classfileBuffer: ByteArray - ): ByteArray { - val instrumenter = Instrumenter(classfileBuffer, loader) - - traceHandler.registerClass(className) - instrumenter.visitInstructions(traceHandler.computeInstructionVisitor(className)) - - val mockClassVisitor = instrumenter.visitClass { writer -> - MockClassVisitor( - writer, - InstrumentationContext.MockGetter::getMock.javaMethod!!, - InstrumentationContext.MockGetter::checkCallSite.javaMethod!!, - InstrumentationContext.MockGetter::hasMock.javaMethod!! - ) - } + override val traceHandler: TraceHandler = TraceHandler() + override val pathsToUserClasses: MutableSet = mutableSetOf() - mockClassVisitor.signatureToId.forEach { (method, id) -> - instrumentationContext.methodSignatureToId += method to id + override fun invoke( + clazz: Class<*>, + methodSignature: String, + arguments: ArgumentList, + parameters: Any? + ): UtFuzzingConcreteExecutionResult { + if (parameters !is UtConcreteExecutionData) { + throw IllegalArgumentException("Argument parameters must be of type UtConcreteExecutionData, but was: ${parameters?.javaClass}") } + val (stateBefore, instrumentations, timeout) = parameters // smart cast to UtConcreteExecutionData + return PhasesController( + instrumentationContext, + traceHandler, + delegateInstrumentation, + generateNullOnError = true + ).computeFuzzingConcreteExecutionResult { + // construction + val (params, statics, cache) = valueConstructionContext.start { + val params = constructParameters(stateBefore) + val statics = constructStatics(stateBefore) + + mock(instrumentations) + + Triple(params, statics, getCache()) + } - return instrumenter.classByteCode - } + // preparation + val savedStatics = preparationContext.start { + val savedStatics = setStaticFields(statics) + resetTrace() + savedStatics + } - private fun withStaticFields(staticFields: Map, block: () -> T): T { - val savedFields = mutableMapOf() - try { - staticFields.forEach { (fieldId, value) -> - fieldId.jField.run { - withAccessibility { - savedFields[fieldId] = get(null) - set(null, value) - } + try { + // invocation + val concreteResult = invocationContext.start { + invoke(clazz, methodSignature, params.map { it.value }, timeout) } - } - return block() - } finally { - savedFields.forEach { (fieldId, value) -> - fieldId.jField.run { - withAccessibility { - set(null, value) + + // statistics collection + val coverage = statisticsCollectionContext.start { getCoverage(clazz) }.toLocalCoverage(traceHandler) + val classJVMName = clazz.name.replace('.', '/') + val methodInstructions = + traceHandler.processingStorage.getMethodInstructions(classJVMName, methodSignature) + + val methodId = clazz.singleExecutableId(methodSignature) + val returnClassId = methodId.returnType + // model construction + val (executionResult, stateAfter) = modelConstructionContext.start { + configureConstructor { + this.cache = cache + strategy = ConstructOnlyUserClassesOrCachedObjectsStrategy(pathsToUserClasses, cache) + } + + val executionResult = convertToExecutionResult(concreteResult, returnClassId) + + val stateAfterParametersWithThis = constructParameters(params) + val stateAfterStatics = constructStatics(stateBefore, statics) + val (stateAfterThis, stateAfterParameters) = if (stateBefore.thisInstance == null) { + null to stateAfterParametersWithThis + } else { + stateAfterParametersWithThis.first() to stateAfterParametersWithThis.drop(1) } + val stateAfter = EnvironmentModels(stateAfterThis, stateAfterParameters, stateAfterStatics) + + executionResult to stateAfter + } + UtFuzzingConcreteExecutionResult( + stateAfter, + executionResult, + coverage, + methodInstructions + ) + } finally { + // postprocessing + postprocessingContext.start { + resetStaticFields(savedStatics) } } } } } + +private fun Coverage.toLocalCoverage(traceHandler: TraceHandler) = + Coverage( + coveredInstructions.map { traceHandler.processingStorage.convertToLocalInstruction(it) }, + instructionsCount, + missedInstructions.map { traceHandler.processingStorage.convertToLocalInstruction(it) } + ) diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/MockValueConstructor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/MockValueConstructor.kt index b881f055bc..2b6ce47e44 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/MockValueConstructor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/constructors/MockValueConstructor.kt @@ -67,7 +67,8 @@ import org.utbot.instrumentation.process.runSandbox */ // TODO: JIRA:1379 -- Refactor ValueConstructor and MockValueConstructor class MockValueConstructor( - private val instrumentationContext: InstrumentationContext + private val instrumentationContext: InstrumentationContext, + private val generateNullOnError: Boolean = false ) : Closeable { private val classLoader: ClassLoader get() = utContext.classLoader @@ -82,7 +83,7 @@ class MockValueConstructor( } // TODO: JIRA:1379 -- replace UtReferenceModel with Int - private val constructedObjects = HashMap() + private val constructedObjects = HashMap() private val mockInfo = mutableListOf() private var mockTarget: MockTarget? = null private var mockCounter = 0 @@ -133,7 +134,7 @@ class MockValueConstructor( is UtClassRefModel -> UtConcreteValue(model.value) is UtCompositeModel -> UtConcreteValue(constructObject(model), model.classId.jClass) is UtArrayModel -> UtConcreteValue(constructArray(model)) - is UtAssembleModel -> UtConcreteValue(constructFromAssembleModel(model), model.classId.jClass) + is UtAssembleModel -> constructConcreteValueFromAssembleModel(model) is UtLambdaModel -> UtConcreteValue(constructFromLambdaModel(model)) is UtVoidModel -> UtConcreteValue(Unit) // PythonModel, JsUtModel may be here @@ -141,6 +142,22 @@ class MockValueConstructor( } } + /** + * Constructs Concrete value from Assemble model. + * + * In fuzzing mode we are ignoring exceptions because concrete values as nulls are possible. + */ + private fun constructConcreteValueFromAssembleModel(model: UtAssembleModel): UtConcreteValue<*> = + try { + UtConcreteValue(constructFromAssembleModel(model), model.classId.jClass) + } catch (e: Throwable) { + if (generateNullOnError) { + UtConcreteValue(null, model.classId.jClass) + } else { + throw e + } + } + /** * Constructs an Enum<*> instance by model, uses reference-equality cache. */ @@ -366,18 +383,15 @@ class MockValueConstructor( /** * Constructs object with [UtAssembleModel]. */ - private fun constructFromAssembleModel(assembleModel: UtAssembleModel): Any? { + private fun constructFromAssembleModel(assembleModel: UtAssembleModel): Any { constructedObjects[assembleModel]?.let { return it } val instantiationExecutableCall = assembleModel.instantiationCall val result = updateWithExecutableCallModel(instantiationExecutableCall) -// checkNotNull(result) { -// "Tracked instance can't be null for call ${instantiationExecutableCall.executable} in model $assembleModel" -// } - constructedObjects[assembleModel] = result - if (result == null) { - return null + checkNotNull(result) { + "Tracked instance can't be null for call ${instantiationExecutableCall.executable} in model $assembleModel" } + constructedObjects[assembleModel] = result assembleModel.modificationsChain.forEach { statementModel -> when (statementModel) { @@ -493,13 +507,8 @@ class MockValueConstructor( } private fun ConstructorId.call(args: List): Any? = - try { - constructor.runSandbox { - this.isAccessible = true - newInstance(*args.toTypedArray()) - } - } catch (e: Throwable) { - null + constructor.runSandbox { + newInstance(*args.toTypedArray()) } /** diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt index 58617a3a61..ba706c6a5c 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/PhasesController.kt @@ -7,6 +7,7 @@ import org.utbot.instrumentation.instrumentation.execution.mock.InstrumentationC import org.utbot.framework.plugin.api.Coverage import org.utbot.framework.plugin.api.MissingState import org.utbot.framework.plugin.api.UtSandboxFailure +import org.utbot.greyboxfuzzer.util.UtFuzzingConcreteExecutionResult import org.utbot.instrumentation.instrumentation.Instrumentation import org.utbot.instrumentation.instrumentation.et.TraceHandler @@ -14,9 +15,10 @@ class PhasesController( instrumentationContext: InstrumentationContext, traceHandler: TraceHandler, delegateInstrumentation: Instrumentation>, + generateNullOnError: Boolean = false ) : Closeable { - val valueConstructionContext = ValueConstructionContext(instrumentationContext) + val valueConstructionContext = ValueConstructionContext(instrumentationContext, generateNullOnError) val preparationContext = PreparationContext(traceHandler) @@ -46,6 +48,25 @@ class PhasesController( } } + inline fun computeFuzzingConcreteExecutionResult(block: PhasesController.() -> UtFuzzingConcreteExecutionResult): UtFuzzingConcreteExecutionResult { + return use { + try { + block() + } catch (e: PhaseError) { + if (e.cause.cause is AccessControlException) { + return@use UtFuzzingConcreteExecutionResult( + MissingState, + UtSandboxFailure(e.cause.cause!!), + Coverage(), + null + ) + } + // TODO: make failure results from different phase errors + throw e + } + } + } + override fun close() { valueConstructionContext.close() } diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionContext.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionContext.kt index aaa5732f25..cc46bcc9fe 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionContext.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/execution/phases/ValueConstructionContext.kt @@ -22,13 +22,14 @@ class ValueConstructionPhaseError(cause: Throwable) : PhaseError( * This phase of values instantiation from given models. */ class ValueConstructionContext( - instrumentationContext: InstrumentationContext + instrumentationContext: InstrumentationContext, + generateNullOnError: Boolean = false ) : PhaseContext, Closeable { override fun wrapError(error: Throwable): ValueConstructionPhaseError = ValueConstructionPhaseError(error) - private val constructor = MockValueConstructor(instrumentationContext) + private val constructor = MockValueConstructor(instrumentationContext, generateNullOnError) fun getCache(): IdentityHashMap { return constructor.objectToModelCache diff --git a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/mock/MockClassVisitor.kt b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/mock/MockClassVisitor.kt index 4ce875c12a..ec108974e3 100644 --- a/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/mock/MockClassVisitor.kt +++ b/utbot-instrumentation/src/main/kotlin/org/utbot/instrumentation/instrumentation/mock/MockClassVisitor.kt @@ -96,36 +96,36 @@ class MockClassVisitor( private val afterLabels: MutableList