| 1 |
""" Test suite for the code in msilib """ |
| 2 |
import unittest |
| 3 |
from test_support import TESTFN, import_module, run_unittest, unlink |
| 4 |
msilib = import_module('msilib') |
| 5 |
import msilib.schema |
| 6 |
|
| 7 |
|
| 8 |
def init_database(): |
| 9 |
path = TESTFN + '.msi' |
| 10 |
db = msilib.init_database( |
| 11 |
path, |
| 12 |
msilib.schema, |
| 13 |
'Python Tests', |
| 14 |
'product_code', |
| 15 |
'1.0', |
| 16 |
'PSF', |
| 17 |
) |
| 18 |
return db, path |
| 19 |
|
| 20 |
|
| 21 |
class MsiDatabaseTestCase(unittest.TestCase): |
| 22 |
|
| 23 |
def test_summaryinfo_getproperty_issue1104(self): |
| 24 |
db, db_path = init_database() |
| 25 |
try: |
| 26 |
sum_info = db.GetSummaryInformation(99) |
| 27 |
title = sum_info.GetProperty(msilib.PID_TITLE) |
| 28 |
self.assertEqual(title, b"Installation Database") |
| 29 |
|
| 30 |
sum_info.SetProperty(msilib.PID_TITLE, "a" * 999) |
| 31 |
title = sum_info.GetProperty(msilib.PID_TITLE) |
| 32 |
self.assertEqual(title, b"a" * 999) |
| 33 |
|
| 34 |
sum_info.SetProperty(msilib.PID_TITLE, "a" * 1000) |
| 35 |
title = sum_info.GetProperty(msilib.PID_TITLE) |
| 36 |
self.assertEqual(title, b"a" * 1000) |
| 37 |
|
| 38 |
sum_info.SetProperty(msilib.PID_TITLE, "a" * 1001) |
| 39 |
title = sum_info.GetProperty(msilib.PID_TITLE) |
| 40 |
self.assertEqual(title, b"a" * 1001) |
| 41 |
finally: |
| 42 |
db = None |
| 43 |
sum_info = None |
| 44 |
unlink(db_path) |
| 45 |
|
| 46 |
def test_directory_start_component_keyfile(self): |
| 47 |
db, db_path = init_database() |
| 48 |
self.addCleanup(msilib._directories.clear) |
| 49 |
feature = msilib.Feature(db, 0, 'Feature', 'A feature', 'Python') |
| 50 |
cab = msilib.CAB('CAB') |
| 51 |
dir = msilib.Directory(db, cab, None, TESTFN, 'TARGETDIR', |
| 52 |
'SourceDir', 0) |
| 53 |
dir.start_component(None, feature, None, 'keyfile') |
| 54 |
|
| 55 |
|
| 56 |
class Test_make_id(unittest.TestCase): |
| 57 |
|
| 58 |
"""The Identifier data type is a text string. Identifiers may contain the |
| 59 |
ASCII characters A-Z (a-z), digits, underscores (_), or periods (.). |
| 60 |
However, every identifier must begin with either a letter or an |
| 61 |
underscore. |
| 62 |
""" |
| 63 |
|
| 64 |
def test_is_no_change_required(self): |
| 65 |
self.assertEqual( |
| 66 |
msilib.make_id("short"), "short") |
| 67 |
self.assertEqual( |
| 68 |
msilib.make_id("nochangerequired"), "nochangerequired") |
| 69 |
self.assertEqual( |
| 70 |
msilib.make_id("one.dot"), "one.dot") |
| 71 |
self.assertEqual( |
| 72 |
msilib.make_id("_"), "_") |
| 73 |
self.assertEqual( |
| 74 |
msilib.make_id("a"), "a") |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
def test_invalid_first_char(self): |
| 79 |
self.assertEqual( |
| 80 |
msilib.make_id("9.short"), "_9.short") |
| 81 |
self.assertEqual( |
| 82 |
msilib.make_id(".short"), "_.short") |
| 83 |
|
| 84 |
def test_invalid_any_char(self): |
| 85 |
self.assertEqual( |
| 86 |
msilib.make_id(".s\x82ort"), "_.s_ort") |
| 87 |
self.assertEqual( |
| 88 |
msilib.make_id(".s\x82o?*+rt"), "_.s_o___rt") |
| 89 |
|
| 90 |
|
| 91 |
def test_main(): |
| 92 |
run_unittest(__name__) |
| 93 |
|
| 94 |
|
| 95 |
if __name__ == '__main__': |
| 96 |
test_main() |