def TestNamespaceFiles(filter):
    idldir = os.path.split(sys.argv[0])[0]
    idldir = os.path.join(idldir, 'test_namespace', '*.idl')
    filenames = glob.glob(idldir)
    testnames = []

    for filename in filenames:
        if filter and filename not in filter: continue
        testnames.append(filename)

    # If we have no files to test, then skip this test
    if not testnames:
        InfoOut.Log('No files to test for namespace.')
        return 0

    InfoOut.SetConsole(False)
    ast = ParseFiles(testnames)
    InfoOut.SetConsole(True)

    errs = ast.GetProperty('ERRORS')
    if errs:
        ErrOut.Log("Failed namespace test.")
    else:
        InfoOut.Log("Passed namespace test.")
    return errs
Beispiel #2
0
def Main(args):
    global errors
    ParseOptions(args)

    InfoOut.SetConsole(True)

    namespace = IDLNamespace(None)

    FooXX = MockNode('foo', None, None)
    Foo1X = MockNode('foo', 1.0, None)
    Foo2X = MockNode('foo', 2.0, None)
    Foo3X = MockNode('foo', 3.0, None)

    # Verify we succeed with undeprecated adds
    AddOkay(namespace, FooXX)
    AddOkay(namespace, Foo1X)
    AddOkay(namespace, Foo3X)
    # Verify we fail to add a node between undeprecated releases
    AddError(namespace, Foo2X,
             'Overlap in releases: 3.0 vs 2.0 when adding foo (2.0 : None)')

    BarXX = MockNode('bar', None, None)
    Bar12 = MockNode('bar', 1.0, 2.0)
    Bar23 = MockNode('bar', 2.0, 3.0)
    Bar34 = MockNode('bar', 3.0, 4.0)

    # Verify we succeed with fully qualified releases
    namespace = IDLNamespace(namespace)
    AddOkay(namespace, BarXX)
    AddOkay(namespace, Bar12)
    # Verify we warn when detecting a gap
    AddWarn(namespace, Bar34, 'Gap in release numbers.')
    # Verify we fail when inserting into this gap
    # (NOTE: while this could be legal, it is sloppy so we disallow it)
    AddError(namespace, Bar23, 'Declarations out of order.')

    # Verify local namespace
    VerifyFindOne(namespace, 'bar', 0.0, BarXX)
    VerifyFindAll(namespace, 'bar', 0.5, 1.5, [BarXX, Bar12])

    # Verify the correct release of the object is found recursively
    VerifyFindOne(namespace, 'foo', 0.0, FooXX)
    VerifyFindOne(namespace, 'foo', 0.5, FooXX)
    VerifyFindOne(namespace, 'foo', 1.0, Foo1X)
    VerifyFindOne(namespace, 'foo', 1.5, Foo1X)
    VerifyFindOne(namespace, 'foo', 3.0, Foo3X)
    VerifyFindOne(namespace, 'foo', 100.0, Foo3X)

    # Verify the correct range of objects is found
    VerifyFindAll(namespace, 'foo', 0.0, 1.0, [FooXX])
    VerifyFindAll(namespace, 'foo', 0.5, 1.0, [FooXX])
    VerifyFindAll(namespace, 'foo', 1.0, 1.1, [Foo1X])
    VerifyFindAll(namespace, 'foo', 0.5, 1.5, [FooXX, Foo1X])
    VerifyFindAll(namespace, 'foo', 0.0, 3.0, [FooXX, Foo1X])
    VerifyFindAll(namespace, 'foo', 3.0, 100.0, [Foo3X])

    FooBar = MockNode('foobar', 1.0, 2.0)
    namespace = IDLNamespace(namespace)
    AddOkay(namespace, FooBar)

    if errors:
        print 'Test failed with %d errors.' % errors
    else:
        print 'Passed.'
    return errors