コード例 #1
0
ファイル: library_test.go プロジェクト: axel-freesp/sge
func TestLibrary(t *testing.T) {
	case1 := []struct {
		library string
	}{
		{`<library xmlns="http://www.freesp.de/xml/freeSP" version="1.0">
   <signal-type name="s1" scope="" mode="" c-type="" message-id=""></signal-type>
   <node-type name="Test">
      <intype port="" type="s1"></intype>
      <outtype port="" type="s1"></outtype>
   </node-type>
</library>
`},
	}

	for i, c := range case1 {
		freesp.Init()
		var l bh.LibraryIf = LibraryNew("test.alml", nil)
		buf := copyBuf(c.library)
		_, err := l.Read(buf)
		if err != nil {
			t.Errorf("Testcase %d: Failed to read from buffer: %v", i, err)
			return
		}
	}
}
コード例 #2
0
ファイル: signalgraph_test.go プロジェクト: axel-freesp/sge
func TestGraph(t *testing.T) {
	case1 := []struct {
		library, graph     string
		nodes, connections int
	}{
		{`<library xmlns="http://www.freesp.de/xml/freeSP" version="1.0">
   <signal-type name="s1" scope="" mode="" c-type="" message-id=""></signal-type>
   <node-type name="Test">
      <intype port="" type="s1"></intype>
      <outtype port="" type="s1"></outtype>
   </node-type>
</library>
`, `<?xml version="1.0" encoding="UTF-8"?>
<signal-graph xmlns="http://www.freesp.de/xml/freeSP" version="1.0">
    <nodes>
        <input name="sensor">
            <outtype type="s1"/>
        </input>
        <output name="actuator">
            <intype type="s1"/>
        </output>
        <processing-node name="test" type="Test"></processing-node>
    </nodes>
    <connections>
        <connect from="sensor" to="test"/>
        <connect from="test" to="actuator"/>
    </connections>
</signal-graph>
`, 3, 2},
	}

	for i, c := range case1 {
		freesp.Init()
		var l bh.LibraryIf = LibraryNew("test.alml", nil)
		buf := copyBuf(c.library)
		_, err := l.Read(buf)
		if err != nil {
			t.Errorf("Testcase %d: Failed to read from buffer: %v", i, err)
			return
		}
		var sg bh.SignalGraphIf = SignalGraphNew("test.sml", nil)
		buf = copyBuf(c.graph)
		_, err = sg.Read(buf)
		if err != nil {
			t.Errorf("Testcase %d: Failed to read from buffer: %v", i, err)
			return
		}
		var st bh.SignalGraphTypeIf = sg.ItsType()
		if len(st.Nodes()) != c.nodes {
			t.Errorf("Testcase %d: NodeIf count mismatch", i)
			return
		}
	}
}
コード例 #3
0
ファイル: signaltype_test.go プロジェクト: axel-freesp/sge
func TestSignalType(t *testing.T) {
	case1 := []struct {
		remove, name, ctype, msgid string
		scope                      bh.Scope
		mode                       bh.Mode
		isLegal                    bool
	}{
		/*
		 *	If 'remove' is not empty, the signal shall be removed
		 * 	(all other fields are irrelevant).
		 * 	If 'remove' is empty, try to register the signal given by
		 * 	all the other definitions.
		 *
		 * 	'isLegal' is the expected behaviour: true: testcase shall
		 * 	be successful, false: testcase shall fail
		 *
		 * 	Compatible duplicates are allowed (all fields identical!),
		 * 	but duplicates are registered only once.
		 *
		 * 	TreeElementIf interface not tested.
		 */
		{"", "s1", "", "", 0, 0, true},
		{"", "s1", "", "", 0, 0, true},        // compatible duplicate
		{"", "s1", "int", "", 0, 0, false},    // incompatible duplicate
		{"", "s2", "int", "ch1", 0, 0, true},  // new
		{"", "s2", "int", "ch1", 0, 1, false}, // incompatible duplicate
		{"", "s2", "int", "ch1", 1, 0, false}, // incompatible duplicate
		{"", "s2", "int", "ch1", 0, 0, true},  // compatible duplicate
		{"s1", "", "", "", 0, 0, true},        // remove
		{"s1", "", "", "", 0, 0, false},       // remove duplicate
		{"s3", "", "", "", 0, 0, false},       // remove non-existing
		{"", "s1", "int", "", 0, 0, true},     // new (after removal)
	}
	freesp.Init()
	for i, c := range case1 {
		if len(c.remove) > 0 {
			s, success := freesp.GetSignalTypeByName(c.remove)
			if success != c.isLegal {
				t.Errorf("TestSignalType testcase %d failed, could not find %s\n", i, c.remove)
			} else if success {
				SignalTypeDestroy(s)
			}
		} else {
			s, err := SignalTypeNew(c.name, c.ctype, c.msgid, c.scope, c.mode)
			success := (err == nil)
			if success != c.isLegal {
				t.Errorf("TestSignalType testcase %d failed, err=%v.\n", i, err)
			} else if success {
				if s.TypeName() != c.name {
					t.Errorf("TestSignalType testcase %d failed, TypeName().\n", i)
				}
				if s.CType() != c.ctype {
					t.Errorf("TestSignalType testcase %d failed, CType().\n", i)
				}
				if s.ChannelId() != c.msgid {
					t.Errorf("TestSignalType testcase %d failed, ChannelId().\n", i)
				}
				if s.Scope() != c.scope {
					t.Errorf("TestSignalType testcase %d failed, Scope().\n", i)
				}
				if s.Mode() != c.mode {
					t.Errorf("TestSignalType testcase %d failed, Mode().\n", i)
				}
			}
		}
	}
}