Commit 6b673cb4118b16a77e66a26daf629f41edfc6f0e

Authored by Moritz Wirger
1 parent 62c09fce

Add test for UPnP class

Showing 1 changed file with 27 additions and 0 deletions
hueplusplus/test/test_UPnP.cpp 0 → 100755
  1 +#include <gtest/gtest.h>
  2 +#include <gmock/gmock.h>
  3 +
  4 +#include "../include/json/json.h"
  5 +#include "mocks/mock_HttpHandler.h"
  6 +#include "testhelper.h"
  7 +#include "../include/UPnP.h"
  8 +
  9 +#include "iostream"
  10 +
  11 +const std::vector<std::pair<std::string, std::string>> expected_uplug_dev = {
  12 + {"http://192.168.2.1:1900/gatedesc.xml", "Linux/2.6.36, UPnP/1.0, Portable SDK for UPnP devices/1.6.19"},
  13 + {"http://192.168.2.116:80/description.xml", "Linux/3.14.0 UPnP/1.0 IpBridge/1.21.0"}
  14 +};
  15 +
  16 +TEST(UPnP, getDevices)
  17 +{
  18 + std::shared_ptr<MockHttpHandler> handler = std::make_shared<MockHttpHandler>();
  19 + EXPECT_CALL(*handler, sendMulticast("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nMAN: \"ssdp:discover\"\r\nMX: 5\r\nST: ssdp:all\r\n\r\n", "239.255.255.250", 1900, 5))
  20 + .Times(1)
  21 + .WillRepeatedly(::testing::Return(multicast_reply));
  22 +
  23 + UPnP uplug;
  24 + std::vector<std::pair<std::string, std::string>> foundDevices = uplug.getDevices(handler);
  25 +
  26 + EXPECT_EQ(foundDevices, expected_uplug_dev);
  27 +}