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