blob: dd2cdfb68f94d29ef2e7964bcde24f458e784817 [file] [log] [blame]
lgao430fdf112009-07-17 09:10:31 +00001## @file
2# Unit tests for TianoCompress utility
3#
4# Copyright (c) 2008, Intel Corporation
5#
6# All rights reserved. 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#
18import os
19import random
20import sys
21import unittest
22
23import TestTools
24
25class 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
68TheTestSuite = TestTools.MakeTheTestSuite(locals())
69
70if __name__ == '__main__':
71 allTests = TheTestSuite()
72 unittest.TextTestRunner().run(allTests)
73
74