Mercurial > malikania
diff examples/image/main.cpp @ 80:a162f380f02e
CMake: create examples, closes #615
author | David Demelier <markand@malikania.fr> |
---|---|
date | Sun, 22 Jan 2017 09:59:14 +0100 |
parents | 78de82cc6bde |
children | 301599387b40 |
line wrap: on
line diff
--- a/examples/image/main.cpp Sat Jan 21 14:13:52 2017 +0100 +++ b/examples/image/main.cpp Sun Jan 22 09:59:14 2017 +0100 @@ -1,7 +1,7 @@ /* * main.cpp -- test Image * - * Copyright (c) 2013-2016 Malikania Authors + * Copyright (c) 2013-2017 Malikania Authors * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,9 +19,6 @@ #include <chrono> #include <thread> -#define BOOST_TEST_MODULE "Image" -#include <boost/test/unit_test.hpp> - #include <malikania/client_resources_loader.hpp> #include <malikania/image.hpp> #include <malikania/resources_locator.hpp> @@ -29,72 +26,10 @@ using namespace std::chrono_literals; -namespace { - -mlk::window window(400, 400); - -} // !namespace - -class test_image { -protected: - mlk::directory_resources_locator m_locator; - mlk::client_resources_loader m_loader; - -public: - test_image() - : m_locator(SOURCE_DIRECTORY "/resources") - , m_loader(m_locator) - { - } -}; - -BOOST_FIXTURE_TEST_SUITE(test_image_suite, test_image) - -BOOST_AUTO_TEST_CASE(image100x10) +void draw(mlk::window& window, mlk::client_resources_loader& loader) { try { - auto image = m_loader.load_image("images/100x10.png"); - - BOOST_REQUIRE_EQUAL(100U, image.size().width()); - BOOST_REQUIRE_EQUAL(10U, image.size().height()); - } catch (const std::exception &ex) { - BOOST_FAIL(ex.what()); - } -} - -BOOST_AUTO_TEST_CASE(image16x16) -{ - try { - auto image = m_loader.load_image("images/16x16.png"); - - BOOST_REQUIRE_EQUAL(16U, image.size().width()); - BOOST_REQUIRE_EQUAL(16U, image.size().height()); - } catch (const std::exception &ex) { - BOOST_FAIL(ex.what()); - } -} - -BOOST_AUTO_TEST_CASE(image10x100) -{ - try { - auto image = m_loader.load_image("images/10x100.png"); - - BOOST_REQUIRE_EQUAL(10U, image.size().width()); - BOOST_REQUIRE_EQUAL(100U, image.size().height()); - } catch (const std::exception &ex) { - BOOST_FAIL(ex.what()); - } -} - -BOOST_AUTO_TEST_CASE(notfound) -{ - BOOST_REQUIRE_THROW(m_loader.load_image("image-not-found"), std::exception); -} - -BOOST_AUTO_TEST_CASE(draw) -{ - try { - auto image = m_loader.load_image("images/smiley.png"); + auto image = loader.load_image("images/smiley.png"); auto x = (400 / 2) - (image.size().width() / 2); auto y = (400 / 2) - (image.size().height() / 2); @@ -104,8 +39,21 @@ std::this_thread::sleep_for(3s); } catch (const std::exception &ex) { - BOOST_FAIL(ex.what()); + std::cerr << ex.what() << std::endl; + std::exit(1); } } -BOOST_AUTO_TEST_SUITE_END() +int main() +{ + try { + mlk::window window(400, 400); + mlk::directory_resources_locator locator(SOURCE_DIRECTORY); + mlk::client_resources_loader loader(locator); + + draw(window, loader); + } catch (const std::exception& ex) { + std::cerr << ex.what() << std::endl; + return 1; + } +}