Add unit test for sending to a server.
authorCarl Hetherington <cth@carlh.net>
Sun, 23 Sep 2012 13:22:32 +0000 (14:22 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 23 Sep 2012 13:22:32 +0000 (14:22 +0100)
test/test.cc

index f564a8f86cf10126076599c7d9cbc2c58cec287b..06954822d68c5a47214c2b8903dd201007de7761 100644 (file)
 #include "exceptions.h"
 #include "dvd.h"
 #include "delay_line.h"
+#include "image.h"
+#include "log.h"
+#include "dcp_video_frame.h"
+#include "config.h"
+#include "server.h"
 #define BOOST_TEST_DYN_LINK
 #define BOOST_TEST_MODULE dvdomatic_test
 #include <boost/test/unit_test.hpp>
@@ -248,3 +253,47 @@ BOOST_AUTO_TEST_CASE (paths_test)
        s.content = "foo/bar/baz";
        BOOST_CHECK_EQUAL (s.content_path(), "build/test/a/b/c/d/e/foo/bar/baz");
 }
+
+BOOST_AUTO_TEST_CASE (client_server_test)
+{
+       shared_ptr<SimpleImage> image (new SimpleImage (PIX_FMT_RGB24, Size (1998, 1080)));
+       image->set_line_size (0, 1998 * 3);
+
+       uint8_t* p = image->data()[0];
+       
+       for (int y = 0; y < 1080; ++y) {
+               for (int x = 0; x < 1998; ++x) {
+                       *p++ = x % 256;
+                       *p++ = y % 256;
+                       *p++ = (x + y) % 256;
+               }
+       }
+
+       FileLog log ("build/test/client_server_test.log");
+
+       DCPVideoFrame frame (
+               image,
+               Size (1998, 1080),
+               0,
+               Scaler::from_id ("bicubic"),
+               0,
+               24,
+               "",
+               0,
+               200000000,
+               &log
+               );
+
+       shared_ptr<EncodedData> locally_encoded = frame.encode_locally ();
+       
+       Config::instance()->set_server_port (61920);
+       Server server (&log);
+
+       thread t (boost::bind (&Server::run, &server, 1));
+
+       ServerDescription description ("localhost", 1);
+       shared_ptr<EncodedData> remotely_encoded = frame.encode_remotely (&description);
+
+       BOOST_CHECK_EQUAL (locally_encoded->size(), remotely_encoded->size());
+       BOOST_CHECK (memcmp (locally_encoded->data(), remotely_encoded->data(), locally_encoded->size()) == 0);
+}