summaryrefslogtreecommitdiff
path: root/xmpp/router_test.go
diff options
context:
space:
mode:
authorxengineering <me@xengineering.eu>2023-07-04 22:10:55 +0200
committerxengineering <me@xengineering.eu>2023-07-04 22:15:17 +0200
commit48811e7d2487ebc3db49b8af7e20f57db4ac28f4 (patch)
treea317f8dc44ac9828ae5806e1fa1dee7547118619 /xmpp/router_test.go
parent5570ccd1d6b50042acbf2fad3793afa6dde79ca2 (diff)
parentd9fe0a4360770b1e4b6b4fb3686c3275ad1b6e6e (diff)
downloadlimox-48811e7d2487ebc3db49b8af7e20f57db4ac28f4.tar
limox-48811e7d2487ebc3db49b8af7e20f57db4ac28f4.tar.zst
limox-48811e7d2487ebc3db49b8af7e20f57db4ac28f4.zip
Merge branch 'element-handling'
This moves away from the concept to parse each individual XML token from the token and group them as a []xml.Token slice for further processing. While this is still possible, receiving aswell as sending has switched to define structs with XML tags which can be marshalled and unmarshalled with the xml.Encoder.EncodeElement() and xml.Decoder.DecodeElement() functions. Further documentation can be found at https://pkg.go.dev/encoding/xml#Unmarshal and https://pkg.go.dev/encoding/xml#Marshal. This merge reduces with its changes the number of code lines in the XMPP implementation by around 41 percent!
Diffstat (limited to 'xmpp/router_test.go')
-rw-r--r--xmpp/router_test.go70
1 files changed, 0 insertions, 70 deletions
diff --git a/xmpp/router_test.go b/xmpp/router_test.go
deleted file mode 100644
index b490778..0000000
--- a/xmpp/router_test.go
+++ /dev/null
@@ -1,70 +0,0 @@
-package xmpp
-
-import (
- "encoding/xml"
- "strings"
- "testing"
-)
-
-// routerTest contains a single test case for the xmpp.router. The XML element
-// is given as a string and the value int describes the expected value of a
-// test variable inside the corresponding unit test. See TestRouter for
-// details.
-type routerTest struct {
- xml string
- value int
-}
-
-// TestRouter tests the xmpp/router.go file. The central functionality is the
-// route() function. To test this a fake routing table is created inside this
-// test with XML element handler function produced by the factory function
-// defined below. each handler simply sets the value of the testpoint variable
-// to the value mentioned by the test point. That way the routing can be
-// validated.
-func TestRouter(t *testing.T) {
- var testpoint int
- var s session
-
- factory := func(tp *int, i int) func(*session, []xml.Token) {
- return func(*session, []xml.Token) {
- *tp = i
- }
- }
-
- tests := []routerTest{
- routerTest{`<a></a>`, 1},
- routerTest{`<b></b>`, 2},
- routerTest{`<c></c>`, 3},
- routerTest{`<b xmlns='https://xengineering.eu'></b>`, 4},
- routerTest{`<a xmlns='https://xengineering.eu'></a>`, 5},
- }
-
- testRouting := routingTable{
- {xml.Name{``, `a`}, factory(&testpoint, 1)},
- {xml.Name{``, `b`}, factory(&testpoint, 2)},
- {xml.Name{``, `c`}, factory(&testpoint, 3)},
- {xml.Name{`https://xengineering.eu`, `b`}, factory(&testpoint, 4)},
- {xml.Name{`https://xengineering.eu`, `a`}, factory(&testpoint, 5)},
- }
-
- for _, v := range tests {
- testpoint = 0
-
- r := strings.NewReader(v.xml)
- d := xml.NewDecoder(r)
- tokens := make([]xml.Token, 0)
- for {
- token, err := d.Token()
- if err != nil {
- break
- }
- tokens = append(tokens, xml.CopyToken(token))
- }
-
- route(&s, tokens, testRouting)
-
- if testpoint != v.value {
- t.Fatalf("XML element was not routed correctly!\n")
- }
- }
-}