]> git.proxmox.com Git - mirror_edk2.git/blob - BaseTools/Tests/TianoCompress.py
Sync BaseTool trunk (version r2649) into EDKII BaseTools.
[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 import os
19 import random
20 import sys
21 import unittest
22
23 import TestTools
24
25 class Tests(TestTools.BaseToolsTest):
26
27 def setUp(self):
28 TestTools.BaseToolsTest.setUp(self)
29 self.toolName = 'TianoCompress'
30
31 def testHelp(self):
32 result = self.RunTool('--help', logFile='help')
33 #self.DisplayFile('help')
34 self.assertTrue(result == 0)
35
36 def compressionTestCycle(self, data):
37 path = self.GetTmpFilePath('input')
38 self.WriteTmpFile('input', data)
39 result = self.RunTool(
40 '-e',
41 '-o', self.GetTmpFilePath('output1'),
42 self.GetTmpFilePath('input')
43 )
44 self.assertTrue(result == 0)
45 result = self.RunTool(
46 '-d',
47 '-o', self.GetTmpFilePath('output2'),
48 self.GetTmpFilePath('output1')
49 )
50 self.assertTrue(result == 0)
51 start = self.ReadTmpFile('input')
52 finish = self.ReadTmpFile('output2')
53 startEqualsFinish = start == finish
54 if not startEqualsFinish:
55 print
56 print 'Original data did not match decompress(compress(data))'
57 self.DisplayBinaryData('original data', start)
58 self.DisplayBinaryData('after compression', self.ReadTmpFile('output1'))
59 self.DisplayBinaryData('after decomression', finish)
60 self.assertTrue(startEqualsFinish)
61
62 def testRandomDataCycles(self):
63 for i in range(8):
64 data = self.GetRandomString(1024, 2048)
65 self.compressionTestCycle(data)
66 self.CleanUpTmpDir()
67
68 TheTestSuite = TestTools.MakeTheTestSuite(locals())
69
70 if __name__ == '__main__':
71 allTests = TheTestSuite()
72 unittest.TextTestRunner().run(allTests)
73
74