コード例 #1
0
func (s *ValidationTests) TestValidateInvalidTagNumber(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")

	builder := s.createFIX40NewOrderSingle()
	builder.Header().Set(fix.NewStringField(9999, "hello"))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)
	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonInvalidTagNumber)
	c.Check(*reject.RefTagID(), Equals, fix.Tag(9999))

	builder = s.createFIX40NewOrderSingle()
	builder.Trailer().Set(fix.NewStringField(9999, "hello"))
	msgBytes, _ = builder.Build()
	msg, _ = parseMessage(msgBytes)

	reject = validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonInvalidTagNumber)
	c.Check(*reject.RefTagID(), Equals, fix.Tag(9999))

	builder = s.createFIX40NewOrderSingle()
	builder.Body().Set(fix.NewStringField(9999, "hello"))
	msgBytes, _ = builder.Build()
	msg, _ = parseMessage(msgBytes)

	reject = validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonInvalidTagNumber)
	c.Check(*reject.RefTagID(), Equals, fix.Tag(9999))
}
コード例 #2
0
ファイル: build.go プロジェクト: jarlwolfganger/quickfix
func buildFieldType(xmlField *XMLField) *FieldType {
	field := FieldType{Name: xmlField.Name, Tag: fix.Tag(xmlField.Number), Type: xmlField.Type}

	if len(xmlField.Values) > 0 {
		field.Enums = make(map[string]Enum)

		for _, enum := range xmlField.Values {
			field.Enums[enum.Enum] = Enum{Value: enum.Enum, Description: enum.Description}
		}
	}

	return &field
}
コード例 #3
0
func (s *ValidationTests) TestValidateTagNotDefinedForMessage(c *C) {
	dict, _ := datadictionary.Parse("spec/FIX40.xml")

	builder := s.createFIX40NewOrderSingle()
	builder.Body().Set(fix.NewStringField(41, "hello"))
	msgBytes, _ := builder.Build()
	msg, _ := parseMessage(msgBytes)

	reject := validate(dict, *msg)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonTagNotDefinedForThisMessageType)
	c.Check(*reject.RefTagID(), Equals, fix.Tag(41))
}
コード例 #4
0
func TestFieldBytes_NewField(t *testing.T) {
	f := newFieldBytes(fix.Tag(8), []byte("blahblah"))
	if f == nil {
		t.Error("f should not be nil")
	}

	expectedData := []byte("8=blahblah")
	if !bytes.Equal(f.Data, expectedData) {
		t.Errorf("Expected %v, got %v", expectedData, f.Data)
	}
	expectedValue := []byte("blahblah")
	if !bytes.Equal(f.Value, expectedValue) {
		t.Errorf("Expected %v, got %v", expectedValue, f.Value)
	}
}
コード例 #5
0
ファイル: field_bytes.go プロジェクト: jmptrader/quickfix
func (f *fieldBytes) parseField(rawFieldBytes []byte) (err error) {
	sepIndex := bytes.IndexByte(rawFieldBytes, '=')

	if sepIndex == -1 {
		err = fmt.Errorf("fieldBytes.Parse: No '=' in '%s'", rawFieldBytes)
		return
	}

	parsedTag, err := fix.Atoi(rawFieldBytes[:sepIndex])

	if err != nil {
		err = fmt.Errorf("fieldBytes.Parse: %s", err.Error())
		return
	}

	f.Tag = fix.Tag(parsedTag)
	f.Value = rawFieldBytes[(sepIndex + 1):(len(rawFieldBytes) - 1)]
	f.Data = rawFieldBytes

	return
}
コード例 #6
0
func TestFieldBytes_ParseField(t *testing.T) {
	stringField := "8=FIX.4.0"
	f := fieldBytes{}
	err := f.parseField([]byte(stringField))

	if err != nil {
		t.Error("Unexpected error", err)
	}

	if f.Tag != fix.Tag(8) {
		t.Error("Unexpected tag", f.Tag)
	}

	if !bytes.Equal(f.Data, []byte(stringField)) {
		t.Errorf("Expected %v got %v", stringField, f.Data)
	}

	if !bytes.Equal(f.Value, []byte("FIX.4.0")) {
		t.Error("Unxpected value", f.Value)
	}
}
コード例 #7
0
func (s *ValidationTests) TestValidateVisitFieldGroup(c *C) {
	fieldType1 := &datadictionary.FieldType{Name: "myfield", Tag: fix.Tag(2), Type: "STRING"}
	fieldDef1 := &datadictionary.FieldDef{FieldType: fieldType1, ChildFields: []*datadictionary.FieldDef{}}

	fieldType2 := &datadictionary.FieldType{Name: "myfield", Tag: fix.Tag(3), Type: "STRING"}
	fieldDef2 := &datadictionary.FieldDef{FieldType: fieldType2, ChildFields: []*datadictionary.FieldDef{}}

	groupFieldType := &datadictionary.FieldType{Name: "mygroupfield", Tag: fix.Tag(1), Type: "INT"}
	groupFieldDef := &datadictionary.FieldDef{FieldType: groupFieldType, ChildFields: []*datadictionary.FieldDef{fieldDef1, fieldDef2}}

	repField1 := newFieldBytes(fix.Tag(2), []byte("a"))
	repField2 := newFieldBytes(fix.Tag(3), []byte("a"))

	//non-repeating
	groupID := newFieldBytes(fix.Tag(1), []byte("1"))
	fields := []fieldBytes{*groupID, *repField1}
	remFields, reject := validateVisitGroupField(groupFieldDef, fields)
	c.Check(len(remFields), Equals, 0)
	c.Check(reject, IsNil)

	fields = []fieldBytes{*groupID, *repField1, *repField2}
	remFields, reject = validateVisitGroupField(groupFieldDef, fields)
	c.Check(len(remFields), Equals, 0)
	c.Check(reject, IsNil)

	//test with trailing tag not in group
	otherField := newFieldBytes(fix.Tag(500), []byte("blah"))
	fields = []fieldBytes{*groupID, *repField1, *repField2, *otherField}
	remFields, reject = validateVisitGroupField(groupFieldDef, fields)
	c.Check(len(remFields), Equals, 1)
	c.Check(reject, IsNil)

	//repeats
	groupID = newFieldBytes(fix.Tag(1), []byte("2"))
	fields = []fieldBytes{*groupID, *repField1, *repField2, *repField1, *repField2, *otherField}
	remFields, reject = validateVisitGroupField(groupFieldDef, fields)
	c.Check(len(remFields), Equals, 1)
	c.Check(reject, IsNil)

	groupID = newFieldBytes(fix.Tag(1), []byte("3"))
	fields = []fieldBytes{*groupID, *repField1, *repField2, *repField1, *repField2, *repField1, *repField2, *otherField}
	remFields, reject = validateVisitGroupField(groupFieldDef, fields)
	c.Check(len(remFields), Equals, 1)
	c.Check(reject, IsNil)

	//REJECT: group size declared > actual group size
	groupID = newFieldBytes(fix.Tag(1), []byte("3"))
	fields = []fieldBytes{*groupID, *repField1, *repField2, *repField1, *repField2, *otherField}
	remFields, reject = validateVisitGroupField(groupFieldDef, fields)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonIncorrectNumInGroupCountForRepeatingGroup)

	groupID = newFieldBytes(fix.Tag(1), []byte("3"))
	fields = []fieldBytes{*groupID, *repField1, *repField1, *otherField}
	remFields, reject = validateVisitGroupField(groupFieldDef, fields)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonIncorrectNumInGroupCountForRepeatingGroup)

	//REJECT: group size declared < actual group size
	groupID = newFieldBytes(fix.Tag(1), []byte("1"))
	fields = []fieldBytes{*groupID, *repField1, *repField2, *repField1, *repField2, *otherField}
	remFields, reject = validateVisitGroupField(groupFieldDef, fields)
	c.Check(reject, NotNil)
	c.Check(reject.RejectReason(), Equals, rejectReasonIncorrectNumInGroupCountForRepeatingGroup)
}