Mercurial > malikania
view tests/libclient/font/main.cpp @ 43:fabbe1759cec
Misc: switch to mlk namespace, closes #589
author | David Demelier <markand@malikania.fr> |
---|---|
date | Tue, 29 Nov 2016 22:25:17 +0100 |
parents | a47a4477f347 |
children | f30c84b4b9ed |
line wrap: on
line source
/* * main.cpp -- test Font * * Copyright (c) 2013-2016 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 * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include <chrono> #include <thread> #include <gtest/gtest.h> #include <malikania/client_resources_loader.hpp> #include <malikania/color.hpp> #include <malikania/font.hpp> #include <malikania/point.hpp> #include <malikania/resources_locator.hpp> #include <malikania/window.hpp> using namespace std::chrono_literals; namespace { mlk::window window(400, 400); } // !namespace class TestFont : public testing::Test { protected: mlk::directory_resources_locator m_locator; mlk::client_resources_loader m_loader; mlk::font m_font; public: TestFont() : m_locator(SOURCE_DIRECTORY "/resources") , m_loader(m_locator) , m_font(m_loader.load_font("DejaVuSans.ttf", 10)) { window.set_drawing_color(mlk::color("black")); window.clear(); } }; TEST_F(TestFont, topleft) { window.set_drawing_color(mlk::color("white")); window.draw_text("top left", m_font, mlk::point(10, 10)); window.present(); std::this_thread::sleep_for(1s); } TEST_F(TestFont, topright) { auto dim = m_font.clip("top right"); window.set_drawing_color(mlk::color("white")); window.draw_text("top right", m_font, mlk::point(400 - dim.width() - 10, 10)); window.present(); std::this_thread::sleep_for(1s); } TEST_F(TestFont, bottomleft) { auto dim = m_font.clip("bottom left"); window.set_drawing_color(mlk::color("white")); window.draw_text("bottom left", m_font, mlk::point(10, 400 - dim.height() - 10)); window.present(); std::this_thread::sleep_for(1s); } TEST_F(TestFont, bottomright) { auto dim = m_font.clip("bottom right"); window.set_drawing_color(mlk::color("white")); window.draw_text("bottom right", m_font, mlk::point(400 - dim.width() - 10, 400 - dim.height() - 10)); window.present(); std::this_thread::sleep_for(1s); } TEST_F(TestFont, center) { auto dim = m_font.clip("center"); window.set_drawing_color(mlk::color("white")); window.draw_text("center", m_font, mlk::point(200 - (dim.width() / 2), 200 - (dim.height() -2))); window.present(); std::this_thread::sleep_for(1s); } TEST_F(TestFont, center2) { auto dim = m_font.clip("The world is Malikania."); window.set_drawing_color(mlk::color("white")); window.draw_text("The world is Malikania.", m_font, mlk::point(200 - (dim.width() / 2), 200 - (dim.height() -2))); window.present(); std::this_thread::sleep_for(3s); } int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }