]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Tests/TianoCompress.py
BaseTools: Various typo
[mirror_edk2.git] / BaseTools / Tests / TianoCompress.py
1 ## @file
2 # Unit tests for TianoCompress utility
3 #
4 # Copyright (c) 2008, Intel Corporation. All rights reserved.<BR>
5 #
6 # This program and the accompanying materials
7 # are licensed and made available under the terms and conditions of the BSD License
8 # which accompanies this distribution. The full text of the license may be found at
9 # http://opensource.org/licenses/bsd-license.php
10 #
11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 #
14
15 ##
16 # Import Modules
17 #
18 from __future__ import print_function
19 import os
20 import random
21 import sys
22 import unittest
23
24 import TestTools
25
26 class Tests(TestTools.BaseToolsTest):
27
28 def setUp(self):
29 TestTools.BaseToolsTest.setUp(self)
30 self.toolName = 'TianoCompress'
31
32 def testHelp(self):
33 result = self.RunTool('--help', logFile='help')
34 #self.DisplayFile('help')
35 self.assertTrue(result == 0)
36
37 def compressionTestCycle(self, data):
38 path = self.GetTmpFilePath('input')
39 self.WriteTmpFile('input', data)
40 result = self.RunTool(
41 '-e',
42 '-o', self.GetTmpFilePath('output1'),
43 self.GetTmpFilePath('input')
44 )
45 self.assertTrue(result == 0)
46 result = self.RunTool(
47 '-d',
48 '-o', self.GetTmpFilePath('output2'),
49 self.GetTmpFilePath('output1')
50 )
51 self.assertTrue(result == 0)
52 start = self.ReadTmpFile('input')
53 finish = self.ReadTmpFile('output2')
54 startEqualsFinish = start == finish
55 if not startEqualsFinish:
56 print()
57 print('Original data did not match decompress(compress(data))')
58 self.DisplayBinaryData('original data', start)
59 self.DisplayBinaryData('after compression', self.ReadTmpFile('output1'))
60 self.DisplayBinaryData('after decompression', finish)
61 self.assertTrue(startEqualsFinish)
62
63 def testRandomDataCycles(self):
64 for i in range(8):
65 data = self.GetRandomString(1024, 2048)
66 self.compressionTestCycle(data)
67 self.CleanUpTmpDir()
68
69 TheTestSuite = TestTools.MakeTheTestSuite(locals())
70
71 if __name__ == '__main__':
72 allTests = TheTestSuite()
73 unittest.TextTestRunner().run(allTests)
74
75