fix 1.12 tests : implement anon fields, set varint test value to 1 for some switch, implement bitfield, don't assume non-anon containers for packets

This commit is contained in:
Romain Beaumont 2017-06-19 14:34:13 +02:00
parent 4e468b09dc
commit d9d1b7a56e
No known key found for this signature in database
GPG key ID: DB60E388B3BCF286

View file

@ -17,7 +17,7 @@ var values = {
'i32': 123456, 'i32': 123456,
'i16': -123, 'i16': -123,
'u16': 123, 'u16': 123,
'varint': 25992, 'varint': 1,
'i8': -10, 'i8': -10,
'u8': 8, 'u8': 8,
'string': "hi hi this is my client string", 'string': "hi hi this is my client string",
@ -42,7 +42,15 @@ var values = {
"..": context "..": context
}; };
Object.keys(typeArgs).forEach(function(index){ Object.keys(typeArgs).forEach(function(index){
results[typeArgs[index].name] = getValue(typeArgs[index].type, results); const v=getValue(typeArgs[index].type, results);
if(typeArgs[index].anon) {
Object.keys(v).forEach(key => {
results[key]=v[key];
})
}
else {
results[typeArgs[index].name] = v;
}
}); });
delete context[".."]; delete context[".."];
return results; return results;
@ -129,6 +137,13 @@ var values = {
}, },
'option': function(typeArgs, context) { 'option': function(typeArgs, context) {
return getValue(typeArgs, context); return getValue(typeArgs, context);
},
'bitfield': function(typeArgs) {
var results={};
Object.keys(typeArgs).forEach(function(index){
results[typeArgs[index].name] = 1;
});
return results;
} }
}; };
@ -178,7 +193,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
Object.keys(packets).filter(function(state){return state!="types"}).forEach(function(state){ Object.keys(packets).filter(function(state){return state!="types"}).forEach(function(state){
Object.keys(packets[state]).forEach(function(direction){ Object.keys(packets[state]).forEach(function(direction){
Object.keys(packets[state][direction].types).filter(function(packetName){return packetName!="packet"}).forEach(function(packetName){ Object.keys(packets[state][direction].types).filter(function(packetName){return packetName!="packet"}).forEach(function(packetName){
packetInfo = packets[state][direction].types[packetName][1]; packetInfo = packets[state][direction].types[packetName];
packetInfo=packetInfo ? packetInfo : null; packetInfo=packetInfo ? packetInfo : null;
it(state + ","+(direction=="toServer" ? "Server" : "Client")+"Bound," + packetName, it(state + ","+(direction=="toServer" ? "Server" : "Client")+"Bound," + packetName,
callTestPacket(packetName.substr(7), packetInfo, state, direction=="toServer" )); callTestPacket(packetName.substr(7), packetInfo, state, direction=="toServer" ));
@ -195,10 +210,7 @@ mc.supportedVersions.forEach(function(supportedVersion,i){
function testPacket(packetName, packetInfo, state, toServer, done) { function testPacket(packetName, packetInfo, state, toServer, done) {
// empty object uses default values // empty object uses default values
var packet = {}; var packet = getValue(packetInfo, {});
packetInfo.forEach(function(field) {
packet[field.name] = getValue(field.type, packet);
});
if(toServer) { if(toServer) {
serverClient.once(packetName, function(receivedPacket) { serverClient.once(packetName, function(receivedPacket) {
try { try {