Commit 1daf83dd authored by Pierre Aubert's avatar Pierre Aubert
Browse files

Add genreric operator test

parent 63a788b6
......@@ -6,6 +6,14 @@ cmake_minimum_required(VERSION 3.0)
# compileMainTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp)
# Only when the test will be OK
compileTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp fileAdd.math)
# compileTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_test.cpp fileAdd.math)
compileBaseTestGenerator(test_math_operator_parser "PTestOperatorParser" parser_operator.pdecparser main_base_test.cpp)
add_executable(test_math_operator_parser_input main_test.cpp)
target_link_libraries(test_math_operator_parser_input test_math_operator_parser_parser phoenix_parser_stmt file_parser option_parser string_utils)
add_test(NAME Test_test_math_operator_parser_input
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/test_math_operator_parser_input -i ${CMAKE_CURRENT_SOURCE_DIR}/fileAdd.math -r "(a+b)"
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
/***************************************
Auteur : Pierre Aubert
Mail : aubertp7@gmail.com
Licence : CeCILL-C
****************************************/
// To get the generated parser
#include "PTestOperatorParserFull.h"
using namespace std;
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAddToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(varA);
PExpr_getVecOperand(exprAdd).push_back(varB);
std::string exprStr = gExprVarName(exprAdd);
std::cout << "testExprAddToString : exprAdd = '"<<exprStr<<"'" << std::endl;
// std::cout << "testExprAddToString : exprAdd ok example :"<< std::endl;
// exprAdd.print();
return exprStr == "(a+b)";
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAdd2ToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAddAB = PExpr_default();
PExpr_setType(exprAddAB, PExprType::ADD);
PExpr_getVecOperand(exprAddAB).push_back(varA);
PExpr_getVecOperand(exprAddAB).push_back(varB);
PExpr varC = PExpr_default();
PExpr_setType(varC, PExprType::VAR);
PExpr_setVarName(varC, "c");
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(exprAddAB);
PExpr_getVecOperand(exprAdd).push_back(varC);
std::string exprStr = gExprVarName(exprAdd);
std::cout << "testExprAdd2ToString : exprAdd = '"<<exprStr<<"'" << std::endl;
return exprStr == "((a+b)+c)";
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAdd3ToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAddAB = PExpr_default();
PExpr_setType(exprAddAB, PExprType::ADD);
PExpr_getVecOperand(exprAddAB).push_back(varA);
PExpr_getVecOperand(exprAddAB).push_back(varB);
PExpr varC = PExpr_default();
PExpr_setType(varC, PExprType::VAR);
PExpr_setVarName(varC, "c");
PExpr varD = PExpr_default();
PExpr_setType(varD, PExprType::VAR);
PExpr_setVarName(varD, "d");
PExpr exprAddCD = PExpr_default();
PExpr_setType(exprAddCD, PExprType::ADD);
PExpr_getVecOperand(exprAddCD).push_back(varC);
PExpr_getVecOperand(exprAddCD).push_back(varD);
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(exprAddAB);
PExpr_getVecOperand(exprAdd).push_back(exprAddCD);
std::string exprStr = gExprVarName(exprAdd);
std::cout << "testExprAdd3ToString : exprAdd = '"<<exprStr<<"'" << std::endl;
return exprStr == "((a+b)+(c+d))";
}
int main(int argc, char** argv){
bool b(testExprAddToString());
b &= testExprAdd2ToString();
b &= testExprAdd3ToString();
if(b){return 0;}
else{return -1;}
}
......@@ -18,120 +18,18 @@ OptionParser createOptionParser(){
parser.setExampleLongOption("use_parser --input=fileName.shadok");
parser.setExampleShortOption("use_parser -i fileName.shadok");
parser.addOption("input", "i", OptionType::FILENAME, true, "input shadok file name");
parser.addOption("input", "i", OptionType::FILENAME, true, "input code file name");
parser.addOption("reference", "r", OptionType::STRING, true, "reference value to be parsed");
return parser;
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAddToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(varA);
PExpr_getVecOperand(exprAdd).push_back(varB);
std::string exprStr = gExprVarName(exprAdd);
std::cout << "testExprAddToString : exprAdd = '"<<exprStr<<"'" << std::endl;
// std::cout << "testExprAddToString : exprAdd ok example :"<< std::endl;
// exprAdd.print();
return exprStr == "(a+b)";
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAdd2ToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAddAB = PExpr_default();
PExpr_setType(exprAddAB, PExprType::ADD);
PExpr_getVecOperand(exprAddAB).push_back(varA);
PExpr_getVecOperand(exprAddAB).push_back(varB);
PExpr varC = PExpr_default();
PExpr_setType(varC, PExprType::VAR);
PExpr_setVarName(varC, "c");
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(exprAddAB);
PExpr_getVecOperand(exprAdd).push_back(varC);
std::string exprStr = gExprVarName(exprAdd);
std::cout << "testExprAdd2ToString : exprAdd = '"<<exprStr<<"'" << std::endl;
return exprStr == "((a+b)+c)";
}
///Test the conversion of and add expression into a string
/** @return true on success, false otherwise
*/
bool testExprAdd3ToString(){
PExpr varA = PExpr_default();
PExpr_setType(varA, PExprType::VAR);
PExpr_setVarName(varA, "a");
PExpr varB = PExpr_default();
PExpr_setType(varB, PExprType::VAR);
PExpr_setVarName(varB, "b");
PExpr exprAddAB = PExpr_default();
PExpr_setType(exprAddAB, PExprType::ADD);
PExpr_getVecOperand(exprAddAB).push_back(varA);
PExpr_getVecOperand(exprAddAB).push_back(varB);
PExpr varC = PExpr_default();
PExpr_setType(varC, PExprType::VAR);
PExpr_setVarName(varC, "c");
PExpr varD = PExpr_default();
PExpr_setType(varD, PExprType::VAR);
PExpr_setVarName(varD, "d");
PExpr exprAddCD = PExpr_default();
PExpr_setType(exprAddCD, PExprType::ADD);
PExpr_getVecOperand(exprAddCD).push_back(varC);
PExpr_getVecOperand(exprAddCD).push_back(varD);
PExpr exprAdd = PExpr_default();
PExpr_setType(exprAdd, PExprType::ADD);
PExpr_getVecOperand(exprAdd).push_back(exprAddAB);
PExpr_getVecOperand(exprAdd).push_back(exprAddCD);
std::string exprStr = gExprVarName(exprAdd);
std::cout << "testExprAdd3ToString : exprAdd = '"<<exprStr<<"'" << std::endl;
return exprStr == "((a+b)+(c+d))";
}
///Parse a source file
/** @param fileName : name of the source file
* @param reference : expeced result of the parsed file
* @return true on success, false otherwise
*/
bool testParseFileName(const std::string & fileName){
bool testParseFileName(const std::string & fileName, const std::string & reference){
//We create the parser
PTestOperatorParser parser;
if(!parser.load(fileName)){
......@@ -145,9 +43,9 @@ bool testParseFileName(const std::string & fileName){
source.print();
std::string exprStr = gExprVarName(source);
std::cout << "testParseFileName : exprStr = '"<<exprStr<<"'" << std::endl;
std::cout << "testParseFileName : exprStr = '"<<exprStr<<"', expected = '"<<reference<<"'" << std::endl;
return exprStr == "(a+b)";
return exprStr == reference;
}
int main(int argc, char** argv){
......@@ -155,13 +53,12 @@ int main(int argc, char** argv){
optionParser.parseArgument(argc, argv);
const OptionMode & defaultMode = optionParser.getDefaultMode();
std::string fileName("");
std::string fileName(""), reference("");
defaultMode.getValue(fileName, "input");
defaultMode.getValue(reference, "reference");
bool b(testExprAddToString());
b &= testExprAdd2ToString();
b &= testExprAdd3ToString();
b &= testParseFileName(fileName);
bool b(true);
b &= testParseFileName(fileName, reference);
if(b){return 0;}
else{return -1;}
}
......
......@@ -56,6 +56,17 @@ function(compileMainTestGenerator createSourceTarget generatedParserName baseInp
target_link_libraries(${createSourceTarget} "${createSourceTarget}_parser" phoenix_parser_stmt file_parser option_parser string_utils)
endfunction(compileMainTestGenerator)
# Create a tests by Calling the phoenix program
# createSourceTarget : target to be created
# generatedParserName : name of the generated parser
# baseInputFile : base of the input file (without directories)
# mainSource : source of the test
function(compileBaseTestGenerator createSourceTarget generatedParserName baseInputFile mainSource)
compileMainTestGenerator(${createSourceTarget} ${generatedParserName} ${baseInputFile} ${mainSource})
add_test(NAME Test_${createSourceTarget}
COMMAND ${createSourceTarget})
endfunction(compileBaseTestGenerator)
# Create a tests by Calling the phoenix program
# createSourceTarget : target to be created
# generatedParserName : name of the generated parser
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment