Beispiel #1
0
    def test_glue_basic(self):
        glue = Glue()
        glue.parse(self.get_file('files/Gain.h'))

        self.assertEqual(1, len(glue.blocks))
        block = list(glue.blocks.values())[0]
        self.assertEqual('Gain', block.name)
        self.assertEqual('SomeProject', block.namespace)
        self.assertEqual('signal', block.family)
        self.assertTrue('description' in block.meta)
        self.assertEqual('Some gain', block.meta['description'])
        self.assertTrue('small' in block.meta)
        self.assertEqual(True, block.meta['small'])
        self.assertEqual(3, len(block.fields))
        self.assertTrue('gain' in block.fields)
        self.assertTrue('input' in block.fields)
        self.assertTrue('output' in block.fields)

        gain = block.fields['gain']
        self.assertEqual(['editable', 'input'], gain.attrs)
        self.assertEqual('1.0', gain.default)
        self.assertEqual('float', gain.type)
        self.assertFalse(gain.multiple)

        input = block.fields['input']
        self.assertEqual(['input'], input.attrs)
        self.assertFalse(input.multiple)
        self.assertEqual('float', input.type)

        output = block.fields['output']
        self.assertEqual(['output'], output.attrs)
        self.assertFalse(output.multiple)
        self.assertEqual('getOutput()', output.get())
        self.assertEqual('float', output.type)
Beispiel #2
0
    def test_glue_tick_method(self):
        glue = Glue()
        glue.parse(self.get_file('files/Add.h'))
        self.assertEqual(1, len(glue.blocks))
        block = list(glue.blocks.values())[0]
        self.assertEqual(2, len(block.fields))
        
        events = block.get_event_methods('tick')
        self.assertEqual(['compute'], events)

        self.assertTrue('terms' in block.fields)
        terms = block.fields['terms']
        self.assertTrue(terms.multiple)
        self.assertTrue('extensible' in terms.meta)
        self.assertTrue('resize' in terms.get_prepare('0'))
Beispiel #3
0
    def test_glue_generation_basic(self):
        glue = Glue()
        glue.parse(self.get_file('files/Gain.h'))
        glue.parse(self.get_file('files/Gains.h'))
        glue.parse(self.get_file('files/Add.h'))
        self.generate(glue)

        self.assertTrue(os.path.isdir(self.get_output('glue')))
        self.check_cpp_file('glue/glue.cpp')
        self.check_cpp_file('glue/convert.h')
        self.check_cpp_file('glue/deserialize.h')
        self.check_cpp_file('glue/GlueTypes.h')

        self.check_cpp_file('glue/GlueGain.cpp')
        self.check_cpp_file('glue/GlueGain.h')
        self.check_cpp_file('glue/GlueGains.cpp')
        self.check_cpp_file('glue/GlueGains.h')
        self.check_cpp_file('glue/GlueAdd.h')
        self.check_cpp_file('glue/GlueAdd.cpp')

        self.assertTrue(os.path.isdir(self.get_output('web')))
        self.assertTrue(os.path.isdir(self.get_output('web/blocks.js')))
        self.assertTrue(os.path.isdir(self.get_output('web/js')))
        self.assertTrue(os.path.isfile(self.get_output('web/js/glue_data.js')))
        self.assertTrue(os.path.isfile(self.get_output('web/index.html')))
Beispiel #4
0
    def test_glue_multiple(self):
        glue = Glue()
        glue.parse(self.get_file('files/Gains.h'))
        
        self.assertEqual(1, len(glue.blocks))
        block = list(glue.blocks.values())[0]
        self.assertEqual('Gains', block.name)
        
        self.assertEqual(3, len(block.fields))
        self.assertTrue('gains' in block.fields)
        self.assertTrue('input' in block.fields)
        self.assertTrue('output' in block.fields)

        gains = block.fields['gains']
        self.assertFalse(gains.multiple)
        self.assertEqual('std::vector<float>', gains.type)
        self.assertEqual('[1]', gains.default)
        self.assertEqual(['editable'], gains.attrs)
        self.assertTrue(gains.is_editable())
        self.assertFalse(gains.is_output())

        input = block.fields['input']
        self.assertTrue(input.multiple)
        self.assertTrue('dimension' in input.meta)
        self.assertEqual('gains', input.meta['dimension'])
        self.assertEqual(['input'], input.attrs)
        self.assertEqual('std::vector<float>', input.type)
        self.assertEqual('float', input.accessor_type())
        self.assertTrue(input.is_input())
        self.assertFalse(input.is_editable())

        output = block.fields['output']
        self.assertTrue(output.multiple)
        self.assertEqual('float', output.type)
        self.assertEqual('float', output.accessor_type())
        self.assertEqual(['output'], output.attrs)
        self.assertFalse(output.is_input())
Beispiel #5
0
 def test_glue_errors(self):
     glue = Glue()
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadAnnotation1.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadAnnotation2.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadAnnotation3.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadField1.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadField2.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadField3.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadField4.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadField5.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadField6.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadEvent1.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadEvent2.h')))
     self.assertRaises(GlueException, lambda: glue.parse(self.get_file('files/BadEvent3.h')))
Beispiel #6
0
 def test_glue_dummy(self):
     glue = Glue()
     glue.parse(self.get_file('files/Dummy.h'))
     self.assertEqual(1, len(glue.blocks))
Beispiel #7
0
    output_dir = sys.argv[2]
    if not os.path.isdir(output_dir):
        os.makedirs(output_dir)

    # Getting output directory for web files
    web_dir = sys.argv[3]
    if os.path.isdir(web_dir):
        shutil.rmtree(web_dir)

    # Type compatibilities
    compatibilities = sys.argv[4]
    if compatibilities != ' ':
        glue.set_compatibilities(compatibilities)

    # Additional headers
    headers = sys.argv[5]
    if headers != ' ':
        glue.headers = headers.split(',')

    # Parse the headers
    files = sys.argv[6:]
    for headerFile in files:
        glue.parse(headerFile)

    glue.generate_files(glue_dir, output_dir, web_dir)
except GlueException as e:
    print()
    print('! '+str(e))
    print()
    exit(1)