blob: 77ef41991ac8dac94e4e46093ef7eb82afa2c962 [file] [log] [blame]
Bill Richardson856e0722011-02-07 15:39:45 -08001#!/usr/bin/python -tt
Bill Richardson794d4d42011-02-10 19:13:10 -08002#
3# Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
Bill Richardson856e0722011-02-07 15:39:45 -08006
7"""Unit tests for bmpblk_utility.
8"""
9
10import os
11import sys
12import subprocess
13import unittest
14
15def runprog(*args):
16 """Runs specified program and args, returns (exitcode, stdout, stderr)."""
17 p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
18 out, err = p.communicate()
19 return (p.returncode, out, err)
20
21
22class TestBmpBlock(unittest.TestCase):
23
24 def testNoArgs(self):
25 """Running with no args should print usage and fail."""
26 rc, out, err = runprog(prog)
27 self.assertNotEqual(0, rc)
Bill Richardson794d4d42011-02-10 19:13:10 -080028 self.assertTrue(err.count("missing BMPBLOCK name"))
29 self.assertTrue(out.count("bmpblk_utility"))
Bill Richardson856e0722011-02-07 15:39:45 -080030
31 def testMissingBmp(self):
32 """Missing a bmp specified in the yaml is an error."""
Bill Richardson794d4d42011-02-10 19:13:10 -080033 rc, out, err = runprog(prog, '-c', 'case_nobmp.yaml', 'FOO')
Bill Richardson856e0722011-02-07 15:39:45 -080034 self.assertNotEqual(0, rc)
35 self.assertTrue(err.count("No such file or directory"))
36
37 def testInvalidBmp(self):
38 """A .bmp file that isn't really a BMP should fail."""
Bill Richardson794d4d42011-02-10 19:13:10 -080039 rc, out, err = runprog(prog, '-c', 'case_badbmp.yaml', 'FOO')
Bill Richardson856e0722011-02-07 15:39:45 -080040 self.assertNotEqual(0, rc)
41 self.assertTrue(err.count("Unsupported image format"))
42
43
44# Run these tests
45if __name__ == '__main__':
46 varname = 'BMPBLK'
47 if varname not in os.environ:
48 print('You must specify the path to bmpblk_utility in the $%s '
49 'environment variable.' % varname)
50 sys.exit(1)
51 prog = os.environ[varname]
52 print "Testing prog...", prog
53 unittest.main()
54