Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Unified Diff: tools/grit/grit/format/data_pack_unittest.py

Issue 2969123002: Add deduplication logic to .pak files (Closed)
Patch Set: fix resource_sizes computation Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/grit/grit/format/data_pack_unittest.py
diff --git a/tools/grit/grit/format/data_pack_unittest.py b/tools/grit/grit/format/data_pack_unittest.py
index f6e9edcfcb6c99799e76d8c4230c3fddb66793aa..4fae80c7ea8bc85e9bf1e812f1040bfb149dac36 100755
--- a/tools/grit/grit/format/data_pack_unittest.py
+++ b/tools/grit/grit/format/data_pack_unittest.py
@@ -17,8 +17,8 @@ from grit.format import data_pack
class FormatDataPackUnittest(unittest.TestCase):
- def testWriteDataPack(self):
- expected = (
+ def testReadDataPackV4(self):
+ expected_data = (
'\x04\x00\x00\x00' # header(version
'\x04\x00\x00\x00' # no. entries,
'\x01' # encoding)
@@ -28,9 +28,40 @@ class FormatDataPackUnittest(unittest.TestCase):
'\x0a\x00\x3f\x00\x00\x00' # index entry 10
'\x00\x00\x3f\x00\x00\x00' # extra entry for the size of last
'this is id 4this is id 6') # data
- input = {1: '', 4: 'this is id 4', 6: 'this is id 6', 10: ''}
- output = data_pack.WriteDataPackToString(input, data_pack.UTF8)
- self.failUnless(output == expected)
+ expected_resources = {
+ 1: '',
+ 4: 'this is id 4',
+ 6: 'this is id 6',
+ 10: '',
+ }
+ expected_data_pack = data_pack.DataPackContents(
+ expected_resources, data_pack.UTF8)
+ loaded = data_pack.ReadDataPackFromString(expected_data)
+ self.assertEquals(loaded, expected_data_pack)
+
+ def testReadWriteDataPackV5(self):
+ expected_data = (
+ '\x05\x00\x01\x00' # version, encoding
+ '\x03\x00\x01\x00' # resource_count, alias_count,
flackr 2017/07/07 18:54:12 nit: I think the test will read more cleanly with
agrieve 2017/07/07 20:47:08 Done.
+ '\x01\x00\x24\x00\x00\x00' # index entry 1
+ '\x04\x00\x24\x00\x00\x00' # index entry 4
+ '\x06\x00\x30\x00\x00\x00' # index entry 6
+ '\x00\x00\x3c\x00\x00\x00' # extra entry for the size of last
+ '\x0a\x00\x01\x00' # alias table
+ 'this is id 4this is id 6') # data
+ expected_resources = {
+ 1: '',
+ 4: 'this is id 4',
+ 6: 'this is id 6',
+ 10: 'this is id 4',
+ }
+ data = data_pack.WriteDataPackToString(expected_resources, data_pack.UTF8)
+ self.assertEquals(data, expected_data)
+
+ expected_data_pack = data_pack.DataPackContents(
+ expected_resources, data_pack.UTF8)
+ loaded = data_pack.ReadDataPackFromString(expected_data)
+ self.assertEquals(loaded, expected_data_pack)
def testRePackUnittest(self):
expected_with_whitelist = {
@@ -50,12 +81,14 @@ class FormatDataPackUnittest(unittest.TestCase):
in inputs]
# RePack using whitelist
- output, _ = data_pack.RePackFromDataPackStrings(inputs, whitelist)
+ output, _ = data_pack.RePackFromDataPackStrings(
+ inputs, whitelist, suppress_removed_key_output=True)
self.assertDictEqual(expected_with_whitelist, output,
'Incorrect resource output')
# RePack a None whitelist
- output, _ = data_pack.RePackFromDataPackStrings(inputs, None)
+ output, _ = data_pack.RePackFromDataPackStrings(
+ inputs, None, suppress_removed_key_output=True)
self.assertDictEqual(expected_without_whitelist, output,
'Incorrect resource output')

Powered by Google App Engine
This is Rietveld 408576698