Skip to content

Commit f4191dd

Browse files
committed
More unittests for commdsl2wireshark.
1 parent 271321e commit f4191dd

8 files changed

Lines changed: 67 additions & 9 deletions

File tree

app/commsdsl2wireshark/src/Wireshark.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ const std::string& Wireshark::wiresharkProtocolObjName(const WiresharkGenerator&
5151

5252
std::string Wireshark::wiresharkCreateFieldFuncName(const WiresharkGenerator& generator)
5353
{
54-
return wiresharkLocalNamespaceName(generator) + ".createField";
54+
return wiresharkLocalNamespaceName(generator) + ".create_field";
5555
}
5656

5757
std::string Wireshark::wiresharkCreateExtractorFuncName(const WiresharkGenerator& generator)
5858
{
59-
return wiresharkLocalNamespaceName(generator) + ".createExtractor";
59+
return wiresharkLocalNamespaceName(generator) + ".create_extractor";
6060
}
6161

6262
std::string Wireshark::wiresharkFieldsListName(const WiresharkGenerator& generator)

app/commsdsl2wireshark/src/WiresharkField.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,7 @@ std::string WiresharkField::wiresharkFieldObjNameImpl(const WiresharkField* refF
887887
genField = &(refField->wiresharkGenField());
888888
}
889889
auto& wiresharkGenerator = WiresharkGenerator::wiresharkCast(genField->genGenerator());
890-
auto scope = comms::genScopeFor(*genField, wiresharkGenerator, false);
891-
return Wireshark::wiresharkLocalNamespaceName(wiresharkGenerator) + '.' + util::genStrReplace(scope, "::", "_");
890+
return wiresharkGenerator.wiresharkFuncNameFor(*genField, strings::genEmptyString());
892891
}
893892

894893
std::string WiresharkField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
@@ -1070,7 +1069,8 @@ std::string WiresharkField::wiresharkFieldRefName(const WiresharkField* refField
10701069
}
10711070

10721071
auto& wiresharkGenerator = WiresharkGenerator::wiresharkCast(genField->genGenerator());
1073-
auto scope = comms::genScopeFor(*genField, wiresharkGenerator, false);
1072+
bool addMainNs = &wiresharkGenerator.genSchemaOf(*genField) != &wiresharkGenerator.genProtocolSchema();
1073+
auto scope = comms::genScopeFor(*genField, wiresharkGenerator, addMainNs);
10741074
return Wireshark::wiresharkProtocolObjName(wiresharkGenerator) + '.' + util::genStrReplace(scope, "::", ".");
10751075
}
10761076

app/commsdsl2wireshark/src/WiresharkGenerator.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,8 @@ std::string WiresharkGenerator::wiresharkScopeToName(const std::string& scope) c
198198

199199
std::string WiresharkGenerator::wiresharkFuncNameFor(const GenElem& elem, const std::string& suffix) const
200200
{
201-
auto scope = comms::genScopeFor(elem, *this, false);
201+
bool addMainNs = &genSchemaOf(elem) != &genProtocolSchema();
202+
auto scope = comms::genScopeFor(elem, *this, addMainNs);
202203
auto protName = Wireshark::wiresharkLocalNamespaceName(*this);
203204
return protName + '.' + wiresharkScopeToName(scope) + suffix;
204205
}

app/commsdsl2wireshark/src/WiresharkPayloadLayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ std::string WiresharkPayloadLayer::wiresharkExtraDissectCodeImpl() const
101101
};
102102

103103
if (!parseObj.parseDescription().empty()) {
104-
repl["DESC"] = parseObj.parseDescription();
104+
repl["DESC"] = '\"' + parseObj.parseDescription() + '\"';
105105
}
106106

107107
return util::genProcessTemplate(Templ, repl);

app/commsdsl2wireshark/src/WiresharkRefField.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ std::string WiresharkRefField::wiresharkFieldObjNameImpl(const WiresharkField* r
167167
std::string WiresharkRefField::wiresharkFieldRegistrationImpl(const WiresharkField* refField) const
168168
{
169169
assert(m_wiresharkField != nullptr);
170-
if (m_alias) {
170+
if (m_alias && (refField == nullptr)) {
171171
genGenerator().genLogger().genDebug(genName() + " field is full alias to " + m_wiresharkField->wiresharkGenField().genParseObj().parseExternalRef() + ", not generating registration");
172172
return strings::genEmptyString();
173173
}
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
-- TODO
1+
local short_val = test49_local.field_B1Members_Short_value()
2+
if (short_val ~= 0xff) then
3+
return short_val
4+
end
5+
6+
return test49_local.field_B1Members_LongMembers_ActLong_value()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
3+
from commsdsl_pcap_gen import *
4+
5+
def do_frame(id, payload):
6+
prefix = struct.pack('>B', id)
7+
return prefix + payload
8+
9+
def pcap1(f):
10+
seq = 1000
11+
msg1_payload = struct.pack('>BH3s', 0xff, 3, b"bla")
12+
msg1 = do_frame(1, msg1_payload)
13+
header = commsdsl_create_ethernet_ip_tcp_headers(len(msg1), seq)
14+
commsdsl_write_packet(f, header + msg1, time.time())
15+
16+
def pcap2(f):
17+
seq = 2000
18+
msg1_payload = struct.pack('>B3s', 3, b"abc")
19+
msg1 = do_frame(1, msg1_payload)
20+
header = commsdsl_create_ethernet_ip_tcp_headers(len(msg1), seq)
21+
commsdsl_write_packet(f, header + msg1, time.time())
22+
23+
def main():
24+
with open(sys.argv[1], 'wb') as f:
25+
commsdsl_write_pcap_header(f)
26+
pcap1(f)
27+
pcap2(f)
28+
29+
if __name__ == '__main__':
30+
main()
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
3+
from commsdsl_pcap_gen import *
4+
5+
def do_frame(id, payload):
6+
prefix = struct.pack('>B', id)
7+
return prefix + payload
8+
9+
def pcap1(f):
10+
seq = 1000
11+
msg1_payload = struct.pack('>BB3sB3sBB', 0xaa, 3, b"bla", 3, b"\x01\x02\x03", 0x12, 5)
12+
msg1 = do_frame(1, msg1_payload)
13+
header = commsdsl_create_ethernet_ip_tcp_headers(len(msg1), seq)
14+
commsdsl_write_packet(f, header + msg1, time.time())
15+
16+
def main():
17+
with open(sys.argv[1], 'wb') as f:
18+
commsdsl_write_pcap_header(f)
19+
pcap1(f)
20+
21+
if __name__ == '__main__':
22+
main()

0 commit comments

Comments
 (0)