Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Test Service descriptions

  • Loading branch information...
commit 8b92ee04642ef5636427816666f32ebd0dc6cd05 1 parent 7fcca95
Jacob Rask authored
Showing with 28 additions and 12 deletions.
  1. +28 −10 test/http.coffee
  2. +0 −2  test/ssdp.coffee
38 test/http.coffee
View
@@ -1,23 +1,41 @@
-# vim: ts=2 sw=2 sts=2
-
assert = require 'assert'
http = require 'http'
+{ Parser: XmlParser } = require 'xml2js'
+
upnp = require '../index'
_ = require '../lib/utils'
-{ Parser: XmlParser } = require 'xml2js'
exports['Start an HTTP server'] = (test) ->
deviceName = 'Foo'
device = upnp.createDevice 'MediaServer', deviceName
device.on 'ready', ->
- test.ok _.isString(device.address), "@address should be a string"
- test.ok _.isNumber(device.httpPort), '@httpPort should be a number'
- req = http.get host: device.address, port: device.httpPort, path: '/device/description', (res) ->
- test.equal res.statusCode, 200
+ test.ok _.isString(device.address), "address should be a string"
+ test.ok _.isNumber(device.httpPort), 'httpPort should be a number'
+ http.get host: device.address, port: device.httpPort, path: '/device/description', (res) ->
+ test.equal res.statusCode, 200, "Device description should respond with HTTP 200 OK"
data = ''
res.on 'data', (chunk) -> data += chunk
res.on 'close', (err) -> test.ifError err, "Server error - #{err.message}"
res.on 'end', -> (new XmlParser).parseString data, (err, data) ->
- test.ifError err, "Invalid XML in response"
- test.equal deviceName, data.device.modelName, "modelName should equal name passed to createDevice function"
- test.done()
+ test.ifError err, "Invalid XML in device description"
+ test.equal deviceName,
+ data.device.modelName,
+ "modelName should equal name passed to createDevice function"
+ test.equal Object.keys(device.services).length,
+ data.device.serviceList.service.length,
+ "All device's services should be listed in description."
+ for service in data.device.serviceList.service
+ [serviceType] = /urn:schemas-upnp-org:service:(\w+):(\d)/.exec(service.serviceType)[1..]
+ test.ok serviceType in Object.keys device.services
+ http.get {
+ host: device.address
+ port: device.httpPort
+ path: data.device.serviceList.service[0].SCPDURL },
+ (res) ->
+ test.equal res.statusCode, 200, "Service description should respond with HTTP 200 OK"
+ data = ''
+ res.on 'data', (chunk) -> data += chunk
+ res.on 'close', (err) -> test.ifError err, "Server error - #{err.message}"
+ res.on 'end', -> (new XmlParser).parseString data, (err, data) ->
+ test.ifError err, "Invalid XML in service description"
+ test.done()
2  test/ssdp.coffee
View
@@ -1,5 +1,3 @@
-# vim: ts=2 sw=2 sts=2
-
assert = require 'assert'
dgram = require 'dgram'
upnp = require '../index'
Please sign in to comment.
Something went wrong with that request. Please try again.