def test_get_variable_width_object_from_serial_port(self): pn = MockSerialPortNode() #pn.debug = 5 # Initialize some data to be 'read' from our mock serial port node. for x in chr(0x03) + chr(0xAA) + chr(0x03) + chr(0xFF): pn.addbuffer(ord(x)) #print pn.get_buffer_str() conn = gc.FrameworkSerialPortWrapper(pn) lines = "" \ "# Variable Buffer 1 Class\n" \ "class testvbuffer1 {\n" \ " vbuffer1 vbuffer01;\n" \ "}\n" lines = lines.split('\n') pc = ProtoCompiler() pc.parseLines(lines) c = pc.emitCode() pyfilename = os.path.join(properties.TEMP_DIR, "testvbuffer1.py") f = open(pyfilename, 'w') f.write(c) f.close() # Now try to import it. import testvbuffer1 request_obj = testvbuffer1.testvbuffer1() response_obj = testvbuffer1.testvbuffer1() req_vbuffer_obj = request_obj.findChildByName('vbuffer01') # resp_vbuffer_obj = response_obj.findChildByName('vbuffer01') lh = gdlh.SimpleLineHandler(conn) req_vbuffer_obj.setValue("abc") res = lh.send_request_with_response(request_obj, response_obj, 30) assert res == 1, "send_request_with_response() should have returned 1." assert resp_vbuffer_obj.getValue() == chr(0xAA) + chr(0x03) + chr(0xFF), "Did not get expected value." os.remove(pyfilename)
def test_get_variable_width_object_from_serial_port(self): pn = MockSerialPortNode() #pn.debug = 5 # Initialize some data to be 'read' from our mock serial port node. for x in chr(0x03) + chr(0xAA) + chr(0x03) + chr(0xFF): pn.addbuffer(ord(x)) #print pn.get_buffer_str() conn = gc.FrameworkSerialPortWrapper(pn) lines = "" \ "# Variable Buffer 1 Class\n" \ "class testvbuffer1 {\n" \ " vbuffer1 vbuffer01;\n" \ "}\n" lines = lines.split('\n') pc = ProtoCompiler() pc.parseLines(lines) c = pc.emitCode() pyfilename = os.path.join(properties.TEMP_DIR, "testvbuffer1.py") f = open(pyfilename, 'w') f.write(c) f.close() # Now try to import it. import testvbuffer1 request_obj = testvbuffer1.testvbuffer1() response_obj = testvbuffer1.testvbuffer1() req_vbuffer_obj = request_obj.findChildByName('vbuffer01') # resp_vbuffer_obj = response_obj.findChildByName('vbuffer01') lh = gdlh.SimpleLineHandler(conn) req_vbuffer_obj.setValue("abc") res = lh.send_request_with_response(request_obj, response_obj, 30) assert res == 1, "send_request_with_response() should have returned 1." assert resp_vbuffer_obj.getValue( ) == chr(0xAA) + chr(0x03) + chr(0xFF), "Did not get expected value." os.remove(pyfilename)
def test_case_vbuffer1(self): lines = "" \ "# Variable Buffer 1 Class\n" \ "class testvbuffer1 {\n" \ " vbuffer1 vbuffer01;\n" \ "}\n" pc = ProtoCompiler() fname = os.path.join(properties.TEMP_DIR, 'vbuffer1.class') f = open(fname, 'w') f.write(lines) f.close() pc.parseFile(fname) assert pc.classnames == ['testvbuffer1' ], "Classnames != ['testvbuffer1']" my_class = pc._getClass('testvbuffer1') #print 'Got class of %s.' % str(my_class) assert my_class.isPackCompatible( ) == 0, "Class should be not pack compatible." assert my_class.isFixedWidth() == 0, "Width should not be fixed." assert my_class.getWidth( ) == 0, "Width should be 0, got %d." % my_class.getWidth() c = pc.emitCode() pyfilename = os.path.join(properties.TEMP_DIR, "testvbuffer1.py") f = open(pyfilename, 'w') f.write(c) f.close() pyfilename = os.path.join('/tmp', "testvbuffer1.py") f = open(pyfilename, 'w') f.write(c) f.close() # Now try to import it. import testvbuffer1 obj = testvbuffer1.testvbuffer1() assert obj.isFixedWidth() == 0, "isFixedWidth() should be 0" assert obj.isPackCompatible() == 0, "isPackCompatible() should be 0" assert obj.getWidth( ) == 0, "Width should be 0, got %d" % obj.getWidth() assert obj.getNumItems( ) == 1, "NumItems should be 1, got %d" % obj.getNumItems() # Object has only one item, run some tests against that item item_obj = obj.items[0] width = item_obj.getWidth() assert width == 1, "width should be 1, got %s" % str(width)