Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
CTA-LAPP
PHOENIX_LIBS
ParserGenerator
Commits
1daf83dd
Commit
1daf83dd
authored
Jan 12, 2021
by
Pierre Aubert
Browse files
Add genreric operator test
parent
63a788b6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
154 additions
and
114 deletions
+154
-114
TESTS/TEST_OPERATOR/CMakeLists.txt
TESTS/TEST_OPERATOR/CMakeLists.txt
+9
-1
TESTS/TEST_OPERATOR/main_base_test.cpp
TESTS/TEST_OPERATOR/main_base_test.cpp
+124
-0
TESTS/TEST_OPERATOR/main_test.cpp
TESTS/TEST_OPERATOR/main_test.cpp
+10
-113
TESTS/callTestParserDecGenerator.cmake
TESTS/callTestParserDecGenerator.cmake
+11
-0
No files found.
TESTS/TEST_OPERATOR/CMakeLists.txt
View file @
1daf83dd
...
...
@@ -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
}
)
TESTS/TEST_OPERATOR/main_base_test.cpp
0 → 100644
View file @
1daf83dd
/***************************************
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
;}
}
TESTS/TEST_OPERATOR/main_test.cpp
View file @
1daf83dd
...
...
@@ -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
;}
}
...
...
TESTS/callTestParserDecGenerator.cmake
View file @
1daf83dd
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment