##// END OF EJS Templates

File last commit:

r1211:08e858e2cf84
r1253:c62577560c5b merge
Show More
FuzzingOperations.cpp
74 lines | 2.3 KiB | text/x-c | CppLexer
/ plugins / amda / tests / FuzzingOperations.cpp
Alexandre Leroux
Defines fuzzing operations...
r1202 #include "FuzzingOperations.h"
Alexandre Leroux
Implements "Variable creation" operation (2)
r1208 #include "FuzzingUtils.h"
#include <Data/IDataProvider.h>
Alexandre Leroux
Defines fuzzing operations...
r1202
#include <Variable/Variable.h>
#include <Variable/VariableController.h>
Alexandre Leroux
Implements "Variable creation" operation (2)
r1208 #include <QUuid>
Alexandre Leroux
Defines fuzzing operations...
r1202 Q_LOGGING_CATEGORY(LOG_FuzzingOperations, "FuzzingOperations")
namespace {
struct CreateOperation : public IFuzzingOperation {
Alexandre Leroux
Fixes clang-format for resource files
r1211 bool canExecute(std::shared_ptr<Variable> variable) const override
{
Alexandre Leroux
Implements "Variable creation" operation (2)
r1208 // A variable can be created only if it doesn't exist yet
return variable == nullptr;
Alexandre Leroux
Defines fuzzing operations...
r1202 }
Alexandre Leroux
Fixes clang-format for resource files
r1211 void execute(std::shared_ptr<Variable> &variable, VariableController &variableController,
const Properties &properties) const override
{
// Retrieves metadata pool from properties, and choose one of the metadata entries to
// associate it with the variable
Alexandre Leroux
Implements "Variable creation" operation (2)
r1208 auto metaDataPool = properties.value(METADATA_POOL_PROPERTY).value<MetadataPool>();
auto variableMetadata = RandomGenerator::instance().randomChoice(metaDataPool);
// Retrieves provider
Alexandre Leroux
Fixes clang-format for resource files
r1211 auto variableProvider
= properties.value(PROVIDER_PROPERTY).value<std::shared_ptr<IDataProvider> >();
Alexandre Leroux
Implements "Variable creation" operation (2)
r1208
auto variableName = QString{"Var_%1"}.arg(QUuid::createUuid().toString());
Alexandre Leroux
Fixes clang-format for resource files
r1211 qCInfo(LOG_FuzzingOperations())
<< "Creating variable" << variableName << "(metadata:" << variableMetadata << ")";
Alexandre Leroux
Implements "Variable creation" operation (2)
r1208
Alexandre Leroux
Fixes clang-format for resource files
r1211 auto newVariable
= variableController.createVariable(variableName, variableMetadata, variableProvider);
Alexandre Leroux
Implements "Variable creation" operation (2)
r1208 std::swap(variable, newVariable);
Alexandre Leroux
Defines fuzzing operations...
r1202 }
};
struct UnknownOperation : public IFuzzingOperation {
Alexandre Leroux
Fixes clang-format for resource files
r1211 bool canExecute(std::shared_ptr<Variable> variable) const override
{
Alexandre Leroux
Defines fuzzing operations...
r1202 Q_UNUSED(variable);
return false;
}
Alexandre Leroux
Fixes clang-format for resource files
r1211 void execute(std::shared_ptr<Variable> &variable, VariableController &variableController,
const Properties &properties) const override
{
Alexandre Leroux
Defines fuzzing operations...
r1202 Q_UNUSED(variable);
Q_UNUSED(variableController);
Q_UNUSED(properties);
// Does nothing
}
};
} // namespace
std::unique_ptr<IFuzzingOperation> FuzzingOperationFactory::create(FuzzingOperationType type)
{
switch (type) {
Alexandre Leroux
Fixes clang-format for resource files
r1211 case FuzzingOperationType::CREATE:
return std::make_unique<CreateOperation>();
default:
// Default case returns unknown operation
break;
Alexandre Leroux
Defines fuzzing operations...
r1202 }
return std::make_unique<UnknownOperation>();
}