Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Test Service descriptions

  • Loading branch information...
commit 8b92ee04642ef5636427816666f32ebd0dc6cd05 1 parent 7fcca95
Jacob Rask authored

Showing 2 changed files with 28 additions and 12 deletions. Show diff stats Hide diff stats

  1. +28 10 test/http.coffee
  2. +0 2  test/ssdp.coffee
38 test/http.coffee
... ... @@ -1,23 +1,41 @@
1   -# vim: ts=2 sw=2 sts=2
2   -
3 1 assert = require 'assert'
4 2 http = require 'http'
  3 +{ Parser: XmlParser } = require 'xml2js'
  4 +
5 5 upnp = require '../index'
6 6 _ = require '../lib/utils'
7   -{ Parser: XmlParser } = require 'xml2js'
8 7
9 8 exports['Start an HTTP server'] = (test) ->
10 9 deviceName = 'Foo'
11 10 device = upnp.createDevice 'MediaServer', deviceName
12 11 device.on 'ready', ->
13   - test.ok _.isString(device.address), "@address should be a string"
14   - test.ok _.isNumber(device.httpPort), '@httpPort should be a number'
15   - req = http.get host: device.address, port: device.httpPort, path: '/device/description', (res) ->
16   - test.equal res.statusCode, 200
  12 + test.ok _.isString(device.address), "address should be a string"
  13 + test.ok _.isNumber(device.httpPort), 'httpPort should be a number'
  14 + http.get host: device.address, port: device.httpPort, path: '/device/description', (res) ->
  15 + test.equal res.statusCode, 200, "Device description should respond with HTTP 200 OK"
17 16 data = ''
18 17 res.on 'data', (chunk) -> data += chunk
19 18 res.on 'close', (err) -> test.ifError err, "Server error - #{err.message}"
20 19 res.on 'end', -> (new XmlParser).parseString data, (err, data) ->
21   - test.ifError err, "Invalid XML in response"
22   - test.equal deviceName, data.device.modelName, "modelName should equal name passed to createDevice function"
23   - test.done()
  20 + test.ifError err, "Invalid XML in device description"
  21 + test.equal deviceName,
  22 + data.device.modelName,
  23 + "modelName should equal name passed to createDevice function"
  24 + test.equal Object.keys(device.services).length,
  25 + data.device.serviceList.service.length,
  26 + "All device's services should be listed in description."
  27 + for service in data.device.serviceList.service
  28 + [serviceType] = /urn:schemas-upnp-org:service:(\w+):(\d)/.exec(service.serviceType)[1..]
  29 + test.ok serviceType in Object.keys device.services
  30 + http.get {
  31 + host: device.address
  32 + port: device.httpPort
  33 + path: data.device.serviceList.service[0].SCPDURL },
  34 + (res) ->
  35 + test.equal res.statusCode, 200, "Service description should respond with HTTP 200 OK"
  36 + data = ''
  37 + res.on 'data', (chunk) -> data += chunk
  38 + res.on 'close', (err) -> test.ifError err, "Server error - #{err.message}"
  39 + res.on 'end', -> (new XmlParser).parseString data, (err, data) ->
  40 + test.ifError err, "Invalid XML in service description"
  41 + test.done()
2  test/ssdp.coffee
... ... @@ -1,5 +1,3 @@
1   -# vim: ts=2 sw=2 sts=2
2   -
3 1 assert = require 'assert'
4 2 dgram = require 'dgram'
5 3 upnp = require '../index'

0 comments on commit 8b92ee0

Please sign in to comment.
Something went wrong with that request. Please try again.