<commit_before>assert = require 'assert'

http = require 'http'
xml2js = require 'xml2js'
xmlServer = require '../lib/xml-server'
parser = new xml2js.Parser()

deviceType = 'MediaServer'
deviceName = '<NAME>'
server = xmlServer.createServer deviceType, deviceName
xmlServer.listen server, (err, httpServer) ->
    host = httpServer.address
    port = httpServer.port
    # test device description
    http.get host: host, port: port, path: '/device/description', (res) ->
        assert.equal res.statusCode, 200
        res.on 'data', (data) ->
            parser.parseString data, (err, result) ->
                assert.equal result.device.deviceType, 'urn:schemas-upnp-org:device:' + deviceType + ':1'
                assert.equal result.device.friendlyName, deviceName<commit_msg>Run test once for each device type in global config<commit_after>assert = require 'assert'

http = require 'http'
xml2js = require 'xml2js'
xmlServer = require '../lib/xml-server'
config = require '../lib/config'
parser = new xml2js.Parser()

testWebServer = (deviceType, deviceName, deviceVersion) ->
    xmlServer.listen xmlServer.createServer(deviceType, deviceName), (err, httpServer) ->
        assert.ok !err
        host = httpServer.address
        port = httpServer.port
        # test device description
        http.get host: host, port: port, path: '/device/description', (res) ->
            assert.equal res.statusCode, 200
            res.on 'data', (data) ->
                parser.parseString data, (err, result) ->
                    assert.ok !err
                    assert.equal result.device.deviceType, "#{config.schemaPrefix}:device:#{deviceType}:#{deviceVersion}"
                    assert.equal result.device.friendlyName, deviceName
                    
for deviceType of config.devices
    testWebServer deviceType, 'Test Device', config.devices[deviceType].version
{'fraction_non_alphanumeric': 0.11861702127659575, 'fraction_numerical': 0.006914893617021276, 'mean_word_length': 2.862422997946612, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 14}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4473778', 'n_tokens_mistral': 527, 'n_tokens_neox': 512, 'n_words': 139}