49 lines
2.1 KiB
Python
49 lines
2.1 KiB
Python
"""Query the compiled 70334 DBReply serializer and decode both localized strings and inline fields."""
|
|
import struct
|
|
import unittest
|
|
from native_codec_driver import codec_library_path, require_optional_file, MODES, load, serialize
|
|
|
|
TABLE = 0x021826BB
|
|
STAMP = 12345
|
|
|
|
|
|
class BroadcastTextDBReply(unittest.TestCase):
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
cls.library = load()
|
|
cls.mode = MODES.index('--native-db-reply-missing')
|
|
|
|
def query(self, table, identity):
|
|
wire = serialize(self.library, self.mode, struct.pack('<III', table, identity, STAMP))
|
|
echoed, record_id, timestamp, status, size = struct.unpack_from('<IIIBI', wire)
|
|
self.assertEqual((echoed, record_id, timestamp, size), (table, identity, STAMP, len(wire)-17))
|
|
return status, wire[17:]
|
|
|
|
def test_known_text_and_fields(self):
|
|
same = 'Greetings, $c. Are you here to learn of the hidden arts?'
|
|
bear = 'What can you tell me about the bear - Ursangous?'
|
|
fixtures = [
|
|
(910210, 'CUSTOM_MERCHANT_TRIGGER', 'CUSTOM_MERCHANT_TRIGGER', 0, 0),
|
|
(16777200, 'Greetings $N', 'Greetings $N', 0, 0),
|
|
(2529, same, same, 1, 0),
|
|
(8229, bear + '\n', bear, 0, 6),
|
|
]
|
|
for identity, male, female, language, emote in fixtures:
|
|
with self.subTest(identity=identity):
|
|
status, data = self.query(TABLE, identity)
|
|
self.assertEqual(status, 0x20)
|
|
text, text1, tail = data.split(b'\0', 2)
|
|
self.assertEqual((text.decode(), text1.decode()), (male, female))
|
|
self.assertEqual(struct.unpack('<IiiHiIi2I3H3H', tail),
|
|
(identity, language, 0, 0, 0, 0, 0, 0, 0, emote, 0, 0, 0, 0, 0))
|
|
|
|
def test_unknown_and_native_owned(self):
|
|
for identity in (0, 2, 316345, 316358, 16777201):
|
|
self.assertEqual(self.query(TABLE, identity), (0x60, b''))
|
|
self.assertEqual(self.query(0xDEAD0042, 910210), (0x60, b''))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
require_optional_file(codec_library_path())
|
|
unittest.main()
|