LEFT | RIGHT |
(no file at all) | |
1 # -*- coding: utf-8 -*- | 1 # -*- coding: utf-8 -*- |
2 """Tests for shared functionality for dtFabric-based data format parsers.""" | 2 """Tests for shared functionality for dtFabric-based data format parsers.""" |
3 | 3 |
4 from __future__ import unicode_literals | 4 from __future__ import unicode_literals |
5 | 5 |
6 import io | 6 import io |
7 import unittest | 7 import unittest |
8 | 8 |
9 from dtfabric import errors as dtfabric_errors | 9 from dtfabric import errors as dtfabric_errors |
10 from dtfabric.runtime import data_maps as dtfabric_data_maps | 10 from dtfabric.runtime import data_maps as dtfabric_data_maps |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 | 114 |
115 _DATA_TYPE_FABRIC = dtfabric_fabric.DataTypeFabric( | 115 _DATA_TYPE_FABRIC = dtfabric_fabric.DataTypeFabric( |
116 yaml_definition=_DATA_TYPE_FABRIC_DEFINITION) | 116 yaml_definition=_DATA_TYPE_FABRIC_DEFINITION) |
117 | 117 |
118 _POINT3D = _DATA_TYPE_FABRIC.CreateDataTypeMap('point3d') | 118 _POINT3D = _DATA_TYPE_FABRIC.CreateDataTypeMap('point3d') |
119 | 119 |
120 _POINT3D_SIZE = _POINT3D.GetByteSize() | 120 _POINT3D_SIZE = _POINT3D.GetByteSize() |
121 | 121 |
122 _SHAPE3D = _DATA_TYPE_FABRIC.CreateDataTypeMap('shape3d') | 122 _SHAPE3D = _DATA_TYPE_FABRIC.CreateDataTypeMap('shape3d') |
123 | 123 |
| 124 def testFormatPackedIPv4Address(self): |
| 125 """Tests the _FormatPackedIPv4Address function.""" |
| 126 parser = dtfabric_parser.DtFabricBaseParser() |
| 127 |
| 128 ip_address = parser._FormatPackedIPv4Address([0xc0, 0xa8, 0xcc, 0x62]) |
| 129 self.assertEqual(ip_address, '192.168.204.98') |
| 130 |
| 131 def testFormatPackedIPv6Address(self): |
| 132 """Tests the _FormatPackedIPv6Address function.""" |
| 133 parser = dtfabric_parser.DtFabricBaseParser() |
| 134 |
| 135 ip_address = parser._FormatPackedIPv6Address([ |
| 136 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, |
| 137 0x00, 0x42, 0x83, 0x29]) |
| 138 self.assertEqual(ip_address, '2001:0db8:0000:0000:0000:ff00:0042:8329') |
| 139 |
124 # TODO: add tests for _GetDataTypeMap | 140 # TODO: add tests for _GetDataTypeMap |
125 | 141 |
126 def testReadData(self): | 142 def testReadData(self): |
127 """Tests the _ReadData function.""" | 143 """Tests the _ReadData function.""" |
128 parser = dtfabric_parser.DtFabricBaseParser() | 144 parser = dtfabric_parser.DtFabricBaseParser() |
129 | 145 |
130 file_object = io.BytesIO( | 146 file_object = io.BytesIO( |
131 b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00') | 147 b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00') |
132 | 148 |
133 parser._ReadData(file_object, 0, self._POINT3D_SIZE) | 149 parser._ReadData(file_object, 0, self._POINT3D_SIZE) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 b'\x03\x00\x00\x00' | 206 b'\x03\x00\x00\x00' |
191 b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00' | 207 b'\x01\x00\x00\x00\x02\x00\x00\x00\x03\x00\x00\x00' |
192 b'\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00' | 208 b'\x04\x00\x00\x00\x05\x00\x00\x00\x06\x00\x00\x00' |
193 b'\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00') | 209 b'\x06\x00\x00\x00\x07\x00\x00\x00\x08\x00\x00\x00') |
194 | 210 |
195 parser._ReadStructureFromFileObject(file_object, 0, self._SHAPE3D) | 211 parser._ReadStructureFromFileObject(file_object, 0, self._SHAPE3D) |
196 | 212 |
197 | 213 |
198 if __name__ == '__main__': | 214 if __name__ == '__main__': |
199 unittest.main() | 215 unittest.main() |
LEFT | RIGHT |