| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Thibaut Oprinsen | ||
| 3 | Mail : thibaut.oprinsen@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "NanobindTraitCheckStream.h" | ||
| 8 | #include "type_utils.h" | ||
| 9 | |||
| 10 | ///Constructor of NanobindTraitCheckStream | ||
| 11 | 1 | NanobindTraitCheckStream::NanobindTraitCheckStream() | |
| 12 | 1 | : PAbstractNanobindTraitBackend() | |
| 13 | 1 | {} | |
| 14 | |||
| 15 | ///Destructor of NanobindTraitCheckStream | ||
| 16 | 2 | NanobindTraitCheckStream::~NanobindTraitCheckStream(){} | |
| 17 | |||
| 18 | ///Registration of static method | ||
| 19 | /// @param fs stream to write to | ||
| 20 | /// @param classConfig config of the class | ||
| 21 | /// @param mode generator mode | ||
| 22 | 4 | void NanobindTraitCheckStream::registerStaticMethod(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 23 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 4 times.
|
4 | if(!mode.enableCheckStream){return;} |
| 24 |
2/2✓ Branch 0 (4→5) taken 4 times.
✓ Branch 2 (5→6) taken 4 times.
|
4 | PString name(classConfig.getName()); |
| 25 |
3/3✓ Branch 0 (6→7) taken 4 times.
✓ Branch 2 (7→8) taken 1 times.
✓ Branch 3 (7→14) taken 3 times.
|
4 | if(classConfig.getIsEnum()){ |
| 26 |
3/3✓ Branch 0 (8→9) taken 1 times.
✓ Branch 2 (9→10) taken 1 times.
✓ Branch 4 (10→11) taken 1 times.
|
1 | name = name + "::" + name; |
| 27 | } | ||
| 28 |
5/5✓ Branch 0 (14→15) taken 4 times.
✓ Branch 2 (15→16) taken 4 times.
✓ Branch 4 (16→17) taken 4 times.
✓ Branch 6 (17→18) taken 4 times.
✓ Branch 8 (18→19) taken 4 times.
|
4 | fs << std::endl << std::endl << "\t\t///Check stream method to compare two " << name << " objects"; |
| 29 |
6/6✓ Branch 0 (19→20) taken 4 times.
✓ Branch 2 (20→21) taken 4 times.
✓ Branch 4 (21→22) taken 4 times.
✓ Branch 6 (22→23) taken 4 times.
✓ Branch 8 (23→24) taken 4 times.
✓ Branch 10 (24→25) taken 4 times.
|
4 | fs << std::endl << "\t\t.def_static(\"check_stream\", [](const std::string & fieldDescription, const " << name << " & data, const " << name << " & reference) -> bool {"; |
| 30 |
2/2✓ Branch 0 (25→26) taken 4 times.
✓ Branch 2 (26→27) taken 4 times.
|
4 | fs << std::endl << "\t\t\tstd::stringstream out;"; |
| 31 |
4/4✓ Branch 0 (27→28) taken 4 times.
✓ Branch 2 (28→29) taken 4 times.
✓ Branch 4 (29→30) taken 4 times.
✓ Branch 6 (30→31) taken 4 times.
|
4 | fs << std::endl << "\t\t\tif(!CheckStream<" << name << ">::check_stream(fieldDescription, data, reference, out)){"; |
| 32 |
2/2✓ Branch 0 (31→32) taken 4 times.
✓ Branch 2 (32→33) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\tthrow nb::value_error(out.str().c_str());"; |
| 33 |
2/2✓ Branch 0 (33→34) taken 4 times.
✓ Branch 2 (34→35) taken 4 times.
|
4 | fs << std::endl << "\t\t\t}"; |
| 34 |
2/2✓ Branch 0 (35→36) taken 4 times.
✓ Branch 2 (36→37) taken 4 times.
|
4 | fs << std::endl << "\t\t\treturn true;"; |
| 35 |
2/2✓ Branch 0 (37→38) taken 4 times.
✓ Branch 2 (38→39) taken 4 times.
|
4 | fs << std::endl << "\t\t}, "; |
| 36 |
2/2✓ Branch 0 (39→40) taken 4 times.
✓ Branch 2 (40→41) taken 4 times.
|
4 | fs << std::endl << "\t\tnb::arg(\"fieldDescription\"), nb::arg(\"data\"), nb::arg(\"reference\"),"; |
| 37 |
6/6✓ Branch 0 (41→42) taken 4 times.
✓ Branch 2 (42→43) taken 4 times.
✓ Branch 4 (43→44) taken 4 times.
✓ Branch 6 (44→45) taken 4 times.
✓ Branch 8 (45→46) taken 4 times.
✓ Branch 10 (46→47) taken 4 times.
|
4 | fs << std::endl << "\t\t\"Check stream for " << name << " (equivalent to CheckStream<" << name << ">::check_stream)\")"; |
| 38 | 4 | } | |
| 39 | |||
| 40 | ///Generate test function for check stream | ||
| 41 | /// @param fs stream to write to | ||
| 42 | /// @param classConfig config of the class | ||
| 43 | /// @param mode generator mode | ||
| 44 | /// @param baseFileName : base name of the configuration | ||
| 45 | 4 | void NanobindTraitCheckStream::testFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode, const PString & baseFileName) const{ | |
| 46 |
2/4✓ Branch 0 (2→3) taken 4 times.
✗ Branch 1 (2→4) not taken.
✗ Branch 2 (3→4) not taken.
✓ Branch 3 (3→5) taken 4 times.
|
4 | if(!mode.enableUnitTest || !mode.enableCheckStream){return;} |
| 47 |
2/2✓ Branch 0 (5→6) taken 4 times.
✓ Branch 2 (6→7) taken 4 times.
|
4 | PString name(classConfig.getName()); |
| 48 |
1/1✓ Branch 0 (7→8) taken 4 times.
|
4 | PString moduleName = baseFileName.toLower(); |
| 49 | |||
| 50 |
2/2✓ Branch 0 (8→9) taken 4 times.
✓ Branch 2 (9→10) taken 4 times.
|
4 | fs << "def test_check_stream():" << std::endl; |
| 51 |
2/2✓ Branch 0 (10→11) taken 4 times.
✓ Branch 2 (11→12) taken 4 times.
|
4 | fs << "\t\"\"\"Test CheckStream functionality\"\"\"" << std::endl; |
| 52 |
1/1✓ Branch 0 (12→13) taken 4 times.
|
4 | fs << std::endl; |
| 53 |
3/3✓ Branch 0 (13→14) taken 4 times.
✓ Branch 2 (14→15) taken 4 times.
✓ Branch 4 (15→16) taken 4 times.
|
4 | fs << "\t# Create two identical " << name << std::endl; |
| 54 |
1/1✓ Branch 0 (16→17) taken 4 times.
|
4 | const PVecClassAttribute & listAttr(classConfig.getListAttribute()); |
| 55 |
3/3✓ Branch 0 (17→18) taken 4 times.
✓ Branch 2 (18→19) taken 1 times.
✓ Branch 3 (18→53) taken 3 times.
|
4 | if(classConfig.getIsEnum()){ |
| 56 |
1/2✓ Branch 0 (20→21) taken 1 times.
✗ Branch 1 (20→39) not taken.
|
1 | if(listAttr.size() != 0lu){ |
| 57 |
8/8✓ Branch 0 (21→22) taken 1 times.
✓ Branch 2 (22→23) taken 1 times.
✓ Branch 4 (23→24) taken 1 times.
✓ Branch 6 (24→25) taken 1 times.
✓ Branch 8 (25→26) taken 1 times.
✓ Branch 10 (27→28) taken 1 times.
✓ Branch 12 (28→29) taken 1 times.
✓ Branch 14 (29→30) taken 1 times.
|
1 | fs << "\ttest_value1 = " << moduleName << "." << name << "." << listAttr.front().getName() << std::endl; |
| 58 |
8/8✓ Branch 0 (30→31) taken 1 times.
✓ Branch 2 (31→32) taken 1 times.
✓ Branch 4 (32→33) taken 1 times.
✓ Branch 6 (33→34) taken 1 times.
✓ Branch 8 (34→35) taken 1 times.
✓ Branch 10 (36→37) taken 1 times.
✓ Branch 12 (37→38) taken 1 times.
✓ Branch 14 (38→39) taken 1 times.
|
1 | fs << "\ttest_value2 = " << moduleName << "." << name << "." << listAttr.front().getName() << std::endl; |
| 59 | } | ||
| 60 |
4/4✓ Branch 0 (39→40) taken 1 times.
✓ Branch 2 (40→41) taken 1 times.
✓ Branch 4 (41→42) taken 1 times.
✓ Branch 6 (42→43) taken 1 times.
|
1 | fs << "\t# Test identical " << name << " - should return True" << std::endl; |
| 61 |
6/6✓ Branch 0 (43→44) taken 1 times.
✓ Branch 2 (44→45) taken 1 times.
✓ Branch 4 (45→46) taken 1 times.
✓ Branch 6 (46→47) taken 1 times.
✓ Branch 8 (47→48) taken 1 times.
✓ Branch 10 (48→49) taken 1 times.
|
1 | fs << "\tresult_identical = " << moduleName << "." << name << ".check_stream(\"Test identical\", test_value1, test_value2)" << std::endl; |
| 62 |
4/4✓ Branch 0 (49→50) taken 1 times.
✓ Branch 2 (50→51) taken 1 times.
✓ Branch 4 (51→52) taken 1 times.
✓ Branch 6 (52→136) taken 1 times.
|
1 | fs << "\tassert result_identical == True, \"CheckStream should return True for identical " << name << "\"" << std::endl; |
| 63 | }else{ | ||
| 64 |
6/6✓ Branch 0 (53→54) taken 3 times.
✓ Branch 2 (54→55) taken 3 times.
✓ Branch 4 (55→56) taken 3 times.
✓ Branch 6 (56→57) taken 3 times.
✓ Branch 8 (57→58) taken 3 times.
✓ Branch 10 (58→59) taken 3 times.
|
3 | fs << "\ttest_value1 = " << moduleName << "." << name << "()" << std::endl; |
| 65 | |||
| 66 |
2/2✓ Branch 0 (85→60) taken 9 times.
✓ Branch 1 (85→86) taken 3 times.
|
24 | for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 67 |
2/2✓ Branch 0 (62→63) taken 9 times.
✓ Branch 2 (63→64) taken 9 times.
|
18 | PString defaultValue = getTestDefaultValueTypeInPython(it->getType()); |
| 68 |
3/3✓ Branch 0 (64→65) taken 9 times.
✓ Branch 2 (65→66) taken 7 times.
✓ Branch 3 (65→74) taken 2 times.
|
9 | if(defaultValue != ""){ |
| 69 |
6/6✓ Branch 0 (66→67) taken 7 times.
✓ Branch 2 (69→70) taken 7 times.
✓ Branch 4 (70→71) taken 7 times.
✓ Branch 6 (71→72) taken 7 times.
✓ Branch 8 (72→73) taken 7 times.
✓ Branch 10 (73→74) taken 7 times.
|
14 | fs << "\ttest_value1." << it->getName() << " = " << defaultValue << std::endl; |
| 70 | } | ||
| 71 | 9 | } | |
| 72 |
1/1✓ Branch 0 (86→87) taken 3 times.
|
3 | fs << std::endl; |
| 73 |
6/6✓ Branch 0 (87→88) taken 3 times.
✓ Branch 2 (88→89) taken 3 times.
✓ Branch 4 (89→90) taken 3 times.
✓ Branch 6 (90→91) taken 3 times.
✓ Branch 8 (91→92) taken 3 times.
✓ Branch 10 (92→93) taken 3 times.
|
3 | fs << "\ttest_value2 = " << moduleName << "." << name << "()" << std::endl; |
| 74 |
2/2✓ Branch 0 (119→94) taken 9 times.
✓ Branch 1 (119→120) taken 3 times.
|
24 | for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 75 |
2/2✓ Branch 0 (96→97) taken 9 times.
✓ Branch 2 (97→98) taken 9 times.
|
18 | PString defaultValue = getTestDefaultValueTypeInPython(it->getType()); |
| 76 |
3/3✓ Branch 0 (98→99) taken 9 times.
✓ Branch 2 (99→100) taken 7 times.
✓ Branch 3 (99→108) taken 2 times.
|
9 | if(defaultValue != ""){ |
| 77 |
6/6✓ Branch 0 (100→101) taken 7 times.
✓ Branch 2 (103→104) taken 7 times.
✓ Branch 4 (104→105) taken 7 times.
✓ Branch 6 (105→106) taken 7 times.
✓ Branch 8 (106→107) taken 7 times.
✓ Branch 10 (107→108) taken 7 times.
|
14 | fs << "\ttest_value2." << it->getName() << " = " << defaultValue << std::endl; |
| 78 | } | ||
| 79 | 9 | } | |
| 80 |
1/1✓ Branch 0 (120→121) taken 3 times.
|
3 | fs << std::endl; |
| 81 |
4/4✓ Branch 0 (121→122) taken 3 times.
✓ Branch 2 (122→123) taken 3 times.
✓ Branch 4 (123→124) taken 3 times.
✓ Branch 6 (124→125) taken 3 times.
|
3 | fs << "\t# Test identical " << name << " - should return True" << std::endl; |
| 82 |
6/6✓ Branch 0 (125→126) taken 3 times.
✓ Branch 2 (126→127) taken 3 times.
✓ Branch 4 (127→128) taken 3 times.
✓ Branch 6 (128→129) taken 3 times.
✓ Branch 8 (129→130) taken 3 times.
✓ Branch 10 (130→131) taken 3 times.
|
3 | fs << "\tresult_identical = " << moduleName << "." << name << ".check_stream(\"Test identical\", test_value1, test_value2)" << std::endl; |
| 83 |
4/4✓ Branch 0 (131→132) taken 3 times.
✓ Branch 2 (132→133) taken 3 times.
✓ Branch 4 (133→134) taken 3 times.
✓ Branch 6 (134→135) taken 3 times.
|
3 | fs << "\tassert result_identical == True, \"CheckStream should return True for identical " << name << "\"" << std::endl; |
| 84 |
1/1✓ Branch 0 (135→136) taken 3 times.
|
3 | fs << std::endl; |
| 85 | } | ||
| 86 | 4 | } | |
| 87 | |||
| 88 | ///Generate test call to check stream function | ||
| 89 | /// @param fs stream to write to | ||
| 90 | /// @param classConfig config of the class | ||
| 91 | /// @param mode generator mode | ||
| 92 | ✗ | void NanobindTraitCheckStream::testCallFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 93 | ✗ | if(!mode.enableUnitTest || !mode.enableCheckStream){return;} | |
| 94 | ✗ | PString name(classConfig.getName()); | |
| 95 | ✗ | fs << "test_check_stream()" << std::endl; | |
| 96 | ✗ | } | |
| 97 |