| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*************************************** | ||
| 2 | Auteur : Thibaut Oprinsen | ||
| 3 | Mail : thibaut.oprinsen@lapp.in2p3.fr | ||
| 4 | Licence : CeCILL-C | ||
| 5 | ****************************************/ | ||
| 6 | |||
| 7 | #include "NanobindTraitDataStream.h" | ||
| 8 | |||
| 9 | ///Constructor of NanobindTraitDataStream | ||
| 10 | 1 | NanobindTraitDataStream::NanobindTraitDataStream() | |
| 11 | 1 | : PAbstractNanobindTraitBackend() | |
| 12 | 1 | {} | |
| 13 | |||
| 14 | ///Destructor of NanobindTraitDataStream | ||
| 15 | 2 | NanobindTraitDataStream::~NanobindTraitDataStream(){} | |
| 16 | |||
| 17 | /// @brief registration of serialization methods | ||
| 18 | /// @param fs stream to write to | ||
| 19 | /// @param classConfig config of the class | ||
| 20 | /// @param mode generator mode | ||
| 21 | 4 | void registerDeserializationMethods(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){ | |
| 22 |
2/2✓ Branch 0 (2→3) taken 4 times.
✓ Branch 2 (3→4) taken 4 times.
|
4 | PString name(classConfig.getName()); |
| 23 |
3/3✓ Branch 0 (4→5) taken 4 times.
✓ Branch 2 (5→6) taken 1 times.
✓ Branch 3 (5→12) taken 3 times.
|
4 | if(classConfig.getIsEnum()){ |
| 24 |
3/3✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
✓ Branch 4 (8→9) taken 1 times.
|
1 | name = name + "::" + name; |
| 25 | } | ||
| 26 |
4/4✓ Branch 0 (12→13) taken 4 times.
✓ Branch 2 (13→14) taken 4 times.
✓ Branch 4 (14→15) taken 4 times.
✓ Branch 6 (15→16) taken 4 times.
|
4 | fs << std::endl << std::endl << "\t\t///Deserialization method for " << name; |
| 27 |
4/4✓ Branch 0 (16→17) taken 4 times.
✓ Branch 2 (17→18) taken 4 times.
✓ Branch 4 (18→19) taken 4 times.
✓ Branch 6 (19→20) taken 4 times.
|
4 | fs << std::endl << "\t\t.def_static(\"from_bytes\", [](const nb::bytearray &b) -> " << name << " {"; |
| 28 |
4/4✓ Branch 0 (20→21) taken 4 times.
✓ Branch 2 (21→22) taken 4 times.
✓ Branch 4 (22→23) taken 4 times.
✓ Branch 6 (23→24) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\t" << name << " result;"; |
| 29 |
2/2✓ Branch 0 (24→25) taken 4 times.
✓ Branch 2 (25→26) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\tDataStreamIter iter((DataStreamIter)b.data());"; |
| 30 |
2/2✓ Branch 0 (26→27) taken 4 times.
✓ Branch 2 (27→28) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\tbool res(data_message_load(iter, result));"; |
| 31 |
2/2✓ Branch 0 (28→29) taken 4 times.
✓ Branch 2 (29→30) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\tif(!res){"; |
| 32 |
4/4✓ Branch 0 (30→31) taken 4 times.
✓ Branch 2 (31→32) taken 4 times.
✓ Branch 4 (32→33) taken 4 times.
✓ Branch 6 (33→34) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\t\tthrow nb::buffer_error(\"Failed to deserialize " << name << "\");"; |
| 33 |
2/2✓ Branch 0 (34→35) taken 4 times.
✓ Branch 2 (35→36) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\t}"; |
| 34 |
2/2✓ Branch 0 (36→37) taken 4 times.
✓ Branch 2 (37→38) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\treturn result;"; |
| 35 |
2/2✓ Branch 0 (38→39) taken 4 times.
✓ Branch 2 (39→40) taken 4 times.
|
4 | fs << std::endl << "\t\t\t}, "; |
| 36 |
4/4✓ Branch 0 (40→41) taken 4 times.
✓ Branch 2 (41→42) taken 4 times.
✓ Branch 4 (42→43) taken 4 times.
✓ Branch 6 (43→44) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\"Load a " << name << " from a bytearray\""; |
| 37 |
2/2✓ Branch 0 (44→45) taken 4 times.
✓ Branch 2 (45→46) taken 4 times.
|
4 | fs << std::endl << "\t\t)"; |
| 38 | 4 | } | |
| 39 | |||
| 40 | /// @brief registration of serialization methods | ||
| 41 | /// @param fs stream to write to | ||
| 42 | /// @param classConfig config of the class | ||
| 43 | /// @param mode generator mode | ||
| 44 | 4 | void registerSerializationMethods(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){ | |
| 45 |
2/2✓ Branch 0 (2→3) taken 4 times.
✓ Branch 2 (3→4) taken 4 times.
|
4 | PString name(classConfig.getName()); |
| 46 |
3/3✓ Branch 0 (4→5) taken 4 times.
✓ Branch 2 (5→6) taken 1 times.
✓ Branch 3 (5→12) taken 3 times.
|
4 | if(classConfig.getIsEnum()){ |
| 47 |
3/3✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
✓ Branch 4 (8→9) taken 1 times.
|
1 | name = name + "::" + name; |
| 48 | } | ||
| 49 |
4/4✓ Branch 0 (12→13) taken 4 times.
✓ Branch 2 (13→14) taken 4 times.
✓ Branch 4 (14→15) taken 4 times.
✓ Branch 6 (15→16) taken 4 times.
|
4 | fs << std::endl << std::endl << "\t\t///Serialization method for " << name; |
| 50 |
4/4✓ Branch 0 (16→17) taken 4 times.
✓ Branch 2 (17→18) taken 4 times.
✓ Branch 4 (18→19) taken 4 times.
✓ Branch 6 (19→20) taken 4 times.
|
4 | fs << std::endl << "\t\t.def(\"to_bytes\", [](const " << name << " & self) -> nb::bytearray {"; |
| 51 |
2/2✓ Branch 0 (20→21) taken 4 times.
✓ Branch 2 (21→22) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\tsize_t size = data_size(self);"; |
| 52 |
2/2✓ Branch 0 (22→23) taken 4 times.
✓ Branch 2 (23→24) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\tnb::bytearray msg(NULL, size);"; |
| 53 |
2/2✓ Branch 0 (24→25) taken 4 times.
✓ Branch 2 (25→26) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\tDataStreamIter iter((DataStreamIter)msg.data());"; |
| 54 |
2/2✓ Branch 0 (26→27) taken 4 times.
✓ Branch 2 (27→28) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\tbool success = data_message_save(iter, self);"; |
| 55 |
2/2✓ Branch 0 (28→29) taken 4 times.
✓ Branch 2 (29→30) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\tif(success){"; |
| 56 |
2/2✓ Branch 0 (30→31) taken 4 times.
✓ Branch 2 (31→32) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\t\treturn msg;"; |
| 57 |
2/2✓ Branch 0 (32→33) taken 4 times.
✓ Branch 2 (33→34) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\t}else{"; |
| 58 |
4/4✓ Branch 0 (34→35) taken 4 times.
✓ Branch 2 (35→36) taken 4 times.
✓ Branch 4 (36→37) taken 4 times.
✓ Branch 6 (37→38) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\t\tthrow nb::buffer_error(\"Failed to serialize " << name << "\");"; |
| 59 |
2/2✓ Branch 0 (38→39) taken 4 times.
✓ Branch 2 (39→40) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\t}"; |
| 60 |
2/2✓ Branch 0 (40→41) taken 4 times.
✓ Branch 2 (41→42) taken 4 times.
|
4 | fs << std::endl << "\t\t\t}, "; |
| 61 |
4/4✓ Branch 0 (42→43) taken 4 times.
✓ Branch 2 (43→44) taken 4 times.
✓ Branch 4 (44→45) taken 4 times.
✓ Branch 6 (45→46) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\"Serialize the " << name << " to bytearray\""; |
| 62 |
2/2✓ Branch 0 (46→47) taken 4 times.
✓ Branch 2 (47→48) taken 4 times.
|
4 | fs << std::endl << "\t\t)"; |
| 63 | 4 | } | |
| 64 | |||
| 65 | /// @brief registration of size method | ||
| 66 | /// @param fs stream to write to | ||
| 67 | /// @param classConfig config of the class | ||
| 68 | /// @param mode generator mode | ||
| 69 | 4 | void registerSizeMethod(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode){ | |
| 70 |
2/2✓ Branch 0 (2→3) taken 4 times.
✓ Branch 2 (3→4) taken 4 times.
|
4 | PString name(classConfig.getName()); |
| 71 |
3/3✓ Branch 0 (4→5) taken 4 times.
✓ Branch 2 (5→6) taken 1 times.
✓ Branch 3 (5→12) taken 3 times.
|
4 | if(classConfig.getIsEnum()){ |
| 72 |
3/3✓ Branch 0 (6→7) taken 1 times.
✓ Branch 2 (7→8) taken 1 times.
✓ Branch 4 (8→9) taken 1 times.
|
1 | name = name + "::" + name; |
| 73 | } | ||
| 74 |
4/4✓ Branch 0 (12→13) taken 4 times.
✓ Branch 2 (13→14) taken 4 times.
✓ Branch 4 (14→15) taken 4 times.
✓ Branch 6 (15→16) taken 4 times.
|
4 | fs << std::endl << std::endl << "\t\t///Size method for " << name; |
| 75 |
4/4✓ Branch 0 (16→17) taken 4 times.
✓ Branch 2 (17→18) taken 4 times.
✓ Branch 4 (18→19) taken 4 times.
✓ Branch 6 (19→20) taken 4 times.
|
4 | fs << std::endl << "\t\t.def(\"get_size\", [](const " << name << " & self) -> size_t {"; |
| 76 |
2/2✓ Branch 0 (20→21) taken 4 times.
✓ Branch 2 (21→22) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\treturn data_size(self);"; |
| 77 |
2/2✓ Branch 0 (22→23) taken 4 times.
✓ Branch 2 (23→24) taken 4 times.
|
4 | fs << std::endl << "\t\t\t}, "; |
| 78 |
4/4✓ Branch 0 (24→25) taken 4 times.
✓ Branch 2 (25→26) taken 4 times.
✓ Branch 4 (26→27) taken 4 times.
✓ Branch 6 (27→28) taken 4 times.
|
4 | fs << std::endl << "\t\t\t\"Get the size of the " << name << " in bytes\""; |
| 79 |
2/2✓ Branch 0 (28→29) taken 4 times.
✓ Branch 2 (29→30) taken 4 times.
|
4 | fs << std::endl << "\t\t)"; |
| 80 | 4 | } | |
| 81 | |||
| 82 | ///Registration of static method | ||
| 83 | /// @param fs stream to write to | ||
| 84 | /// @param classConfig config of the class | ||
| 85 | /// @param mode generator mode | ||
| 86 | 4 | void NanobindTraitDataStream::registerMethod(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 87 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 4 times.
|
4 | if(!mode.enableDataStream){return;} |
| 88 |
2/2✓ Branch 0 (4→5) taken 4 times.
✓ Branch 2 (5→6) taken 4 times.
|
4 | PString name(classConfig.getName()); |
| 89 | |||
| 90 |
1/1✓ Branch 0 (6→7) taken 4 times.
|
4 | registerSerializationMethods(fs, classConfig, mode); |
| 91 |
1/1✓ Branch 0 (7→8) taken 4 times.
|
4 | registerDeserializationMethods(fs, classConfig, mode); |
| 92 |
1/1✓ Branch 0 (8→9) taken 4 times.
|
4 | registerSizeMethod(fs, classConfig, mode); |
| 93 | 4 | } | |
| 94 | |||
| 95 | |||
| 96 | ///Test the deserialization of the enum with an invalid value | ||
| 97 | /// @param fs stream to write to | ||
| 98 | /// @param classConfig config of the class | ||
| 99 | /// @param mode generator mode | ||
| 100 | /// @param baseFileName : base name of the configuration | ||
| 101 | 1 | void failed_enum_deserialization(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode, const PString & baseFileName){ | |
| 102 |
2/2✓ Branch 0 (2→3) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
|
1 | PString name(classConfig.getName()); |
| 103 |
1/1✓ Branch 0 (4→5) taken 1 times.
|
1 | PString moduleName = baseFileName.toLower(); |
| 104 |
2/2✓ Branch 0 (5→6) taken 1 times.
✓ Branch 2 (6→7) taken 1 times.
|
1 | fs << "def test_data_stream_deserialization_failed():" << std::endl; |
| 105 |
2/2✓ Branch 0 (7→8) taken 1 times.
✓ Branch 2 (8→9) taken 1 times.
|
1 | fs << "\t\"\"\"Test data stream conversion\"\"\"" << std::endl; |
| 106 |
2/2✓ Branch 0 (9→10) taken 1 times.
✓ Branch 2 (10→11) taken 1 times.
|
1 | fs << "\t#Test with the value 8 even if there are only two values in the enum" << std::endl; |
| 107 |
2/2✓ Branch 0 (11→12) taken 1 times.
✓ Branch 2 (12→13) taken 1 times.
|
1 | fs << "\tdata_stream = bytearray(b'\\x08\\x00\\x00\\x00')" << std::endl; |
| 108 |
4/4✓ Branch 0 (13→14) taken 1 times.
✓ Branch 2 (14→15) taken 1 times.
✓ Branch 4 (15→16) taken 1 times.
✓ Branch 6 (16→17) taken 1 times.
|
1 | fs << "\twith pytest.raises(ValueError, match=\".* is not a valid "<<name<<"\"):" << std::endl; |
| 109 |
6/6✓ Branch 0 (17→18) taken 1 times.
✓ Branch 2 (18→19) taken 1 times.
✓ Branch 4 (19→20) taken 1 times.
✓ Branch 6 (20→21) taken 1 times.
✓ Branch 8 (21→22) taken 1 times.
✓ Branch 10 (22→23) taken 1 times.
|
1 | fs << "\t\ttest_value = " << moduleName << "." << name << ".from_bytes(data_stream)" << std::endl; |
| 110 |
1/1✓ Branch 0 (23→24) taken 1 times.
|
1 | fs << std::endl; |
| 111 | 1 | } | |
| 112 | |||
| 113 | ///Generation of unit test function | ||
| 114 | /// @param fs stream to write to | ||
| 115 | /// @param classConfig config of the class | ||
| 116 | /// @param mode generator mode | ||
| 117 | /// @param baseFileName : base name of the configuration | ||
| 118 | 4 | void NanobindTraitDataStream::testFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode, const PString & baseFileName) const{ | |
| 119 |
1/2✗ Branch 0 (2→3) not taken.
✓ Branch 1 (2→4) taken 4 times.
|
4 | if(!mode.enableDataStream){return;} |
| 120 |
2/2✓ Branch 0 (4→5) taken 4 times.
✓ Branch 2 (5→6) taken 4 times.
|
4 | PString name(classConfig.getName()); |
| 121 |
1/1✓ Branch 0 (6→7) taken 4 times.
|
4 | PString moduleName = baseFileName.toLower(); |
| 122 | ///Test base serialization/deserialization | ||
| 123 |
2/2✓ Branch 0 (7→8) taken 4 times.
✓ Branch 2 (8→9) taken 4 times.
|
4 | fs << "def test_data_stream_conversion():" << std::endl; |
| 124 |
2/2✓ Branch 0 (9→10) taken 4 times.
✓ Branch 2 (10→11) taken 4 times.
|
4 | fs << "\t\"\"\"Test data stream conversion\"\"\"" << std::endl; |
| 125 | |||
| 126 |
1/1✓ Branch 0 (11→12) taken 4 times.
|
4 | const PVecClassAttribute & listAttr(classConfig.getListAttribute()); |
| 127 |
3/3✓ Branch 0 (12→13) taken 4 times.
✓ Branch 2 (13→14) taken 1 times.
✓ Branch 3 (13→41) taken 3 times.
|
4 | if(classConfig.getIsEnum()){ |
| 128 |
1/2✓ Branch 0 (15→16) taken 1 times.
✗ Branch 1 (15→25) not taken.
|
1 | if(listAttr.size() != 0lu){ |
| 129 |
8/8✓ Branch 0 (16→17) taken 1 times.
✓ Branch 2 (17→18) taken 1 times.
✓ Branch 4 (18→19) taken 1 times.
✓ Branch 6 (19→20) taken 1 times.
✓ Branch 8 (20→21) taken 1 times.
✓ Branch 10 (22→23) taken 1 times.
✓ Branch 12 (23→24) taken 1 times.
✓ Branch 14 (24→25) taken 1 times.
|
1 | fs << "\ttest_value1 = " << moduleName << "." << name << "." << listAttr.front().getName() << std::endl; |
| 130 | } | ||
| 131 |
2/2✓ Branch 0 (25→26) taken 1 times.
✓ Branch 2 (26→27) taken 1 times.
|
1 | fs << "\tdata_stream = test_value1.to_bytes()" << std::endl; |
| 132 |
2/2✓ Branch 0 (27→28) taken 1 times.
✓ Branch 2 (28→29) taken 1 times.
|
1 | fs << "\tassert data_stream == bytearray(b'\\x00\\x00\\x00\\x00')" << std::endl; |
| 133 |
6/6✓ Branch 0 (29→30) taken 1 times.
✓ Branch 2 (30→31) taken 1 times.
✓ Branch 4 (31→32) taken 1 times.
✓ Branch 6 (32→33) taken 1 times.
✓ Branch 8 (33→34) taken 1 times.
✓ Branch 10 (34→35) taken 1 times.
|
1 | fs << "\ttest_value2 = " << moduleName << "." << name << ".from_bytes(data_stream)" << std::endl; |
| 134 |
1/1✓ Branch 0 (35→36) taken 1 times.
|
1 | fs << std::endl; |
| 135 |
2/2✓ Branch 0 (36→37) taken 1 times.
✓ Branch 2 (37→38) taken 1 times.
|
1 | fs << "\tassert test_value1.get_size() == 4" << std::endl; |
| 136 |
2/2✓ Branch 0 (38→39) taken 1 times.
✓ Branch 2 (39→40) taken 1 times.
|
1 | fs << "\tassert test_value1 == test_value2" << std::endl; |
| 137 |
1/1✓ Branch 0 (40→189) taken 1 times.
|
1 | fs << std::endl; |
| 138 | }else{ | ||
| 139 |
9/9✓ Branch 0 (41→42) taken 3 times.
✓ Branch 2 (42→43) taken 3 times.
✓ Branch 4 (43→44) taken 3 times.
✓ Branch 6 (44→45) taken 3 times.
✓ Branch 8 (45→46) taken 3 times.
✓ Branch 10 (46→47) taken 3 times.
✓ Branch 12 (47→48) taken 3 times.
✓ Branch 14 (48→49) taken 3 times.
✓ Branch 16 (49→50) taken 3 times.
|
3 | fs << "\t" << name.toLower() << " = " << moduleName << "." << name << "()" << std::endl; |
| 140 |
2/2✓ Branch 0 (51→52) taken 3 times.
✓ Branch 2 (52→53) taken 3 times.
|
3 | fs << "\t# Set some example values" << std::endl; |
| 141 |
2/2✓ Branch 0 (84→54) taken 9 times.
✓ Branch 1 (84→85) taken 3 times.
|
24 | for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 142 |
2/2✓ Branch 0 (56→57) taken 9 times.
✓ Branch 2 (57→58) taken 9 times.
|
18 | PString defaultValue = getTestDefaultValueTypeInPython(it->getType()); |
| 143 |
3/3✓ Branch 0 (58→59) taken 9 times.
✓ Branch 2 (59→60) taken 7 times.
✓ Branch 3 (59→73) taken 2 times.
|
9 | if(defaultValue != ""){ |
| 144 |
9/9✓ Branch 0 (60→61) taken 7 times.
✓ Branch 2 (61→62) taken 7 times.
✓ Branch 4 (62→63) taken 7 times.
✓ Branch 6 (63→64) taken 7 times.
✓ Branch 8 (66→67) taken 7 times.
✓ Branch 10 (67→68) taken 7 times.
✓ Branch 12 (68→69) taken 7 times.
✓ Branch 14 (69→70) taken 7 times.
✓ Branch 16 (70→71) taken 7 times.
|
14 | fs << "\t" << name.toLower() << "." << it->getName() << " = " << defaultValue << std::endl; |
| 145 | } | ||
| 146 | 9 | } | |
| 147 |
1/1✓ Branch 0 (85→86) taken 3 times.
|
3 | fs << std::endl; |
| 148 |
5/5✓ Branch 0 (86→87) taken 3 times.
✓ Branch 2 (87→88) taken 3 times.
✓ Branch 4 (88→89) taken 3 times.
✓ Branch 6 (89→90) taken 3 times.
✓ Branch 8 (90→91) taken 3 times.
|
3 | fs << "\tdata_stream = " << name.toLower() << ".to_bytes()" << std::endl; |
| 149 |
1/1✓ Branch 0 (92→93) taken 3 times.
|
3 | fs << std::endl; |
| 150 |
9/9✓ Branch 0 (93→94) taken 3 times.
✓ Branch 2 (94→95) taken 3 times.
✓ Branch 4 (95→96) taken 3 times.
✓ Branch 6 (96→97) taken 3 times.
✓ Branch 8 (97→98) taken 3 times.
✓ Branch 10 (98→99) taken 3 times.
✓ Branch 12 (99→100) taken 3 times.
✓ Branch 14 (100→101) taken 3 times.
✓ Branch 16 (101→102) taken 3 times.
|
3 | fs << "\tnew_" << name.toLower() << " = " << moduleName << "." << name << "()" << std::endl; |
| 151 |
9/9✓ Branch 0 (103→104) taken 3 times.
✓ Branch 2 (104→105) taken 3 times.
✓ Branch 4 (105→106) taken 3 times.
✓ Branch 6 (106→107) taken 3 times.
✓ Branch 8 (107→108) taken 3 times.
✓ Branch 10 (108→109) taken 3 times.
✓ Branch 12 (109→110) taken 3 times.
✓ Branch 14 (110→111) taken 3 times.
✓ Branch 16 (111→112) taken 3 times.
|
3 | fs << "\tnew_" << name.toLower() << " = " << moduleName << "." << name << ".from_bytes(data_stream)" << std::endl; |
| 152 |
1/1✓ Branch 0 (113→114) taken 3 times.
|
3 | fs << std::endl; |
| 153 |
2/2✓ Branch 0 (145→115) taken 9 times.
✓ Branch 1 (145→146) taken 3 times.
|
24 | for(PVecClassAttribute::const_iterator it(listAttr.begin()); it != listAttr.end(); ++it){ |
| 154 |
2/2✓ Branch 0 (117→118) taken 9 times.
✓ Branch 2 (118→119) taken 9 times.
|
18 | PString defaultValue = getTestDefaultValueTypeInPython(it->getType()); |
| 155 |
3/3✓ Branch 0 (119→120) taken 9 times.
✓ Branch 2 (120→121) taken 7 times.
✓ Branch 3 (120→134) taken 2 times.
|
9 | if(defaultValue != ""){ |
| 156 |
9/9✓ Branch 0 (121→122) taken 7 times.
✓ Branch 2 (122→123) taken 7 times.
✓ Branch 4 (123→124) taken 7 times.
✓ Branch 6 (124→125) taken 7 times.
✓ Branch 8 (127→128) taken 7 times.
✓ Branch 10 (128→129) taken 7 times.
✓ Branch 12 (129→130) taken 7 times.
✓ Branch 14 (130→131) taken 7 times.
✓ Branch 16 (131→132) taken 7 times.
|
14 | fs << "\tassert new_" << name.toLower() << "." << it->getName() << " == " << defaultValue << std::endl; |
| 157 | } | ||
| 158 | 9 | } | |
| 159 | ///Test edge cases for serialization/deserialization | ||
| 160 |
1/1✓ Branch 0 (146→147) taken 3 times.
|
3 | fs << std::endl; |
| 161 |
2/2✓ Branch 0 (147→148) taken 3 times.
✓ Branch 2 (148→149) taken 3 times.
|
3 | fs << "def test_serialization_type_errors():" << std::endl; |
| 162 |
2/2✓ Branch 0 (149→150) taken 3 times.
✓ Branch 2 (150→151) taken 3 times.
|
3 | fs << "\t\"\"\"Test erro types for from_bytes\"\"\"" << std::endl; |
| 163 |
1/1✓ Branch 0 (151→152) taken 3 times.
|
3 | fs << std::endl; |
| 164 |
9/9✓ Branch 0 (152→153) taken 3 times.
✓ Branch 2 (153→154) taken 3 times.
✓ Branch 4 (154→155) taken 3 times.
✓ Branch 6 (155→156) taken 3 times.
✓ Branch 8 (156→157) taken 3 times.
✓ Branch 10 (157→158) taken 3 times.
✓ Branch 12 (158→159) taken 3 times.
✓ Branch 14 (159→160) taken 3 times.
✓ Branch 16 (160→161) taken 3 times.
|
3 | fs << "\t" << name.toLower() << " = " << moduleName << "." << name << "()" << std::endl; |
| 165 |
2/2✓ Branch 0 (162→163) taken 3 times.
✓ Branch 2 (163→164) taken 3 times.
|
3 | fs << "\twith pytest.raises(TypeError, match=\".*from_bytes\\(\\): incompatible function arguments.*\"):" << std::endl; |
| 166 |
5/5✓ Branch 0 (164→165) taken 3 times.
✓ Branch 2 (165→166) taken 3 times.
✓ Branch 4 (166→167) taken 3 times.
✓ Branch 6 (167→168) taken 3 times.
✓ Branch 8 (168→169) taken 3 times.
|
3 | fs << "\t\tresult = " << name.toLower() << ".from_bytes(\"A string is not a bytearray !!!\") # deserialize string instead of bytearray" << std::endl; |
| 167 |
1/1✓ Branch 0 (170→171) taken 3 times.
|
3 | fs << std::endl; |
| 168 |
2/2✓ Branch 0 (171→172) taken 3 times.
✓ Branch 2 (172→173) taken 3 times.
|
3 | fs << "\twith pytest.raises(TypeError, match=\".*from_bytes\\(\\): incompatible function arguments.*\"):" << std::endl; |
| 169 |
5/5✓ Branch 0 (173→174) taken 3 times.
✓ Branch 2 (174→175) taken 3 times.
✓ Branch 4 (175→176) taken 3 times.
✓ Branch 6 (176→177) taken 3 times.
✓ Branch 8 (177→178) taken 3 times.
|
3 | fs << "\t\tresult = " << name.toLower() << ".from_bytes(42) # deserialize instead of bytearray" << std::endl; |
| 170 |
1/1✓ Branch 0 (179→180) taken 3 times.
|
3 | fs << std::endl; |
| 171 |
2/2✓ Branch 0 (180→181) taken 3 times.
✓ Branch 2 (181→182) taken 3 times.
|
3 | fs << "\twith pytest.raises(TypeError, match=\".*from_bytes\\(\\): incompatible function arguments.*\"):" << std::endl; |
| 172 |
5/5✓ Branch 0 (182→183) taken 3 times.
✓ Branch 2 (183→184) taken 3 times.
✓ Branch 4 (184→185) taken 3 times.
✓ Branch 6 (185→186) taken 3 times.
✓ Branch 8 (186→187) taken 3 times.
|
3 | fs << "\t\tresult = " << name.toLower() << ".from_bytes([1, 2, 3, 4]) # deserialize list instead of bytearray" << std::endl; |
| 173 |
1/1✓ Branch 0 (188→189) taken 3 times.
|
3 | fs << std::endl; |
| 174 | } | ||
| 175 |
3/3✓ Branch 0 (189→190) taken 4 times.
✓ Branch 2 (190→191) taken 1 times.
✓ Branch 3 (190→192) taken 3 times.
|
4 | if(classConfig.getIsEnum()){ |
| 176 |
1/1✓ Branch 0 (191→192) taken 1 times.
|
1 | failed_enum_deserialization(fs, classConfig, mode, baseFileName); |
| 177 | } | ||
| 178 | 4 | } | |
| 179 | |||
| 180 | ///Generation of unit test call function | ||
| 181 | /// @param fs stream to write to | ||
| 182 | /// @param classConfig config of the class | ||
| 183 | /// @param mode generator mode | ||
| 184 | ✗ | void NanobindTraitDataStream::testCallFunction(std::ofstream & fs, const PClassConfig & classConfig, const GeneratorMode & mode) const{ | |
| 185 | ✗ | if(!mode.enableDataStream){return;} | |
| 186 | ✗ | PString name(classConfig.getName()); | |
| 187 | ✗ | fs << "\ttest_data_stream_conversion()" << std::endl; | |
| 188 | ✗ | fs << "\ttest_serialization_type_errors()" << std::endl; | |
| 189 | ✗ | } | |
| 190 | |||
| 191 |