Path: blob/master/tests/scene/test_style_box_texture.h
10277 views
/**************************************************************************/1/* test_style_box_texture.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "scene/resources/style_box_texture.h"3334#include "tests/test_macros.h"3536namespace TestStyleBoxTexture {3738TEST_CASE("[StyleBoxTexture] Constructor") {39Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);4041CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);42CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);43CHECK(style_box_texture->is_draw_center_enabled() == true);4445CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 0);46CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 0);47CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 0);48CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 0);4950CHECK(style_box_texture->get_modulate() == Color(1, 1, 1, 1));51CHECK(style_box_texture->get_region_rect() == Rect2(0, 0, 0, 0));52CHECK(style_box_texture->get_texture() == Ref<Texture2D>());5354CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 0);55CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 0);56CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 0);57CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 0);58}5960TEST_CASE("[StyleBoxTexture] set_texture, get_texture") {61Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);62Ref<Texture2D> texture = memnew(Texture2D);6364style_box_texture->set_texture(texture);65CHECK(style_box_texture->get_texture() == texture);66}6768TEST_CASE("[StyleBoxTexture] set_texture_margin, set_texture_margin_all, set_texture_margin_individual, get_texture_margin") {69Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);7071SUBCASE("set_texture_margin, get_texture_margin") {72style_box_texture->set_texture_margin(SIDE_LEFT, 1);73style_box_texture->set_texture_margin(SIDE_TOP, 1);74style_box_texture->set_texture_margin(SIDE_RIGHT, 1);75style_box_texture->set_texture_margin(SIDE_BOTTOM, 1);7677CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 1);78CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 1);79CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 1);80CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 1);81}8283SUBCASE("set_texture_margin_all") {84style_box_texture->set_texture_margin_all(2);8586CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 2);87CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 2);88CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 2);89CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 2);90}9192SUBCASE("set_texture_margin_individual") {93style_box_texture->set_texture_margin_individual(3, 4, 5, 6);9495CHECK(style_box_texture->get_texture_margin(SIDE_LEFT) == 3);96CHECK(style_box_texture->get_texture_margin(SIDE_TOP) == 4);97CHECK(style_box_texture->get_texture_margin(SIDE_RIGHT) == 5);98CHECK(style_box_texture->get_texture_margin(SIDE_BOTTOM) == 6);99}100}101102TEST_CASE("[StyleBoxTexture] set_expand_margin, set_expand_margin_all, set_expand_margin_individual") {103Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);104105SUBCASE("set_expand_margin, get_expand_margin") {106style_box_texture->set_expand_margin(SIDE_LEFT, 1);107style_box_texture->set_expand_margin(SIDE_TOP, 1);108style_box_texture->set_expand_margin(SIDE_RIGHT, 1);109style_box_texture->set_expand_margin(SIDE_BOTTOM, 1);110111CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 1);112CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 1);113CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 1);114CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 1);115}116117SUBCASE("set_expand_margin_all") {118style_box_texture->set_expand_margin_all(2);119120CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 2);121CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 2);122CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 2);123CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 2);124}125126SUBCASE("set_expand_margin_individual") {127style_box_texture->set_expand_margin_individual(3, 4, 5, 6);128129CHECK(style_box_texture->get_expand_margin(SIDE_LEFT) == 3);130CHECK(style_box_texture->get_expand_margin(SIDE_TOP) == 4);131CHECK(style_box_texture->get_expand_margin(SIDE_RIGHT) == 5);132CHECK(style_box_texture->get_expand_margin(SIDE_BOTTOM) == 6);133}134}135136TEST_CASE("[StyleBoxTexture] set_region_rect, get_region_rect") {137Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);138139style_box_texture->set_region_rect(Rect2(1, 1, 1, 1));140CHECK(style_box_texture->get_region_rect() == Rect2(1, 1, 1, 1));141}142143TEST_CASE("[StyleBoxTexture] set_draw_center, get_draw_center") {144Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);145146style_box_texture->set_draw_center(false);147CHECK(style_box_texture->is_draw_center_enabled() == false);148}149150TEST_CASE("[StyleBoxTexture] set_h_axis_stretch_mode, set_v_axis_stretch_mode, get_h_axis_stretch_mode, get_v_axis_stretch_mode") {151Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);152153SUBCASE("set_h_axis_stretch_mode, get_h_axis_stretch_mode") {154style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE);155CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE);156157style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);158CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);159160style_box_texture->set_h_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_STRETCH);161CHECK(style_box_texture->get_h_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);162}163164SUBCASE("set_v_axis_stretch_mode, get_v_axis_stretch_mode") {165style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE);166CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE);167168style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);169CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_TILE_FIT);170171style_box_texture->set_v_axis_stretch_mode(style_box_texture->AXIS_STRETCH_MODE_STRETCH);172CHECK(style_box_texture->get_v_axis_stretch_mode() == style_box_texture->AXIS_STRETCH_MODE_STRETCH);173}174}175176TEST_CASE("[StyleBoxTexture] set_modulate, get_modulate") {177Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);178179style_box_texture->set_modulate(Color(0, 0, 0, 0));180CHECK(style_box_texture->get_modulate() == Color(0, 0, 0, 0));181}182183TEST_CASE("[StyleBoxTexture] get_draw_rect") {184Ref<StyleBoxTexture> style_box_texture = memnew(StyleBoxTexture);185186style_box_texture->set_expand_margin_all(5);187CHECK(style_box_texture->get_draw_rect(Rect2(0, 0, 1, 1)) == Rect2(-5, -5, 11, 11));188}189190} // namespace TestStyleBoxTexture191192193