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