| 1 |
/** |
| 2 |
* Test text sprites generation |
| 3 |
|
| 4 |
* Copyright (C) 2015 Sylvain Beucler |
| 5 |
|
| 6 |
* This file is part of GNU FreeDink |
| 7 |
|
| 8 |
* GNU FreeDink is free software: you can redistribute it and/or |
| 9 |
* modify it under the terms of the GNU Affero General Public License |
| 10 |
* as published by the Free Software Foundation, either version 3 of |
| 11 |
* the License, or (at your option) any later version. |
| 12 |
|
| 13 |
* GNU FreeDink is distributed in the hope that it will be useful, but |
| 14 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 |
* Affero General Public License for more details. |
| 17 |
|
| 18 |
* You should have received a copy of the GNU Affero General Public |
| 19 |
* License along with GNU FreeDink. If not, see |
| 20 |
* <http://www.gnu.org/licenses/>. |
| 21 |
*/ |
| 22 |
|
| 23 |
#ifdef HAVE_CONFIG_H |
| 24 |
#include <config.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include <cxxtest/TestSuite.h> |
| 28 |
|
| 29 |
#include "gfx_fonts.h" |
| 30 |
#include "FakeIOGfxDisplay.h" |
| 31 |
#include "ImageLoader.h" |
| 32 |
IOGfxSurface *IOGFX_backbuffer = NULL; |
| 33 |
IOGfxDisplay* g_display = new FakeIOGfxDisplay(0, 0, true, 0); |
| 34 |
#include "test_gfx_fonts_libe.h" |
| 35 |
#include <iostream> |
| 36 |
using namespace std; |
| 37 |
|
| 38 |
char* vgasys_fon; |
| 39 |
int truecolor; |
| 40 |
extern TTF_Font *dialog_font; |
| 41 |
extern SDL_Surface* print_text(TTF_Font * font, char *str, SDL_Color color); |
| 42 |
|
| 43 |
class TestGfxFonts : public CxxTest::TestSuite { |
| 44 |
public: |
| 45 |
void setUp() { |
| 46 |
putenv("FREETYPE_PROPERTIES=truetype:interpreter-version=35"); |
| 47 |
TTF_Init(); |
| 48 |
SDL_RWops* rw = SDL_RWFromMem(libe_ttf, libe_ttf_len); |
| 49 |
dialog_font = TTF_OpenFontRW(rw, 1, FONT_SIZE); |
| 50 |
setup_font(dialog_font); |
| 51 |
} |
| 52 |
void tearDown() { |
| 53 |
} |
| 54 |
|
| 55 |
Uint8 getIndexAt(SDL_Surface* img, int x, int y) { |
| 56 |
return ((Uint8*)img->pixels)[x + y*img->pitch]; |
| 57 |
} |
| 58 |
|
| 59 |
void test_print_textTruecolor() { |
| 60 |
truecolor = 1; |
| 61 |
SDL_Color ce; |
| 62 |
Uint32 key; |
| 63 |
|
| 64 |
SDL_Surface* img = print_text(dialog_font, "toto", {255,255,2}); |
| 65 |
TS_ASSERT_EQUALS(img->h, 18); // 19 for SDL_ttf <= 2.0.14, 18 for SDL_ttf >= 2.0.15 |
| 66 |
TS_ASSERT_EQUALS(getIndexAt(img, 0,0), 0); |
| 67 |
TS_ASSERT_EQUALS(getIndexAt(img, 1,4), 1); |
| 68 |
ce = { 255, 255, 2, 255 }; |
| 69 |
TS_ASSERT_SAME_DATA(&img->format->palette->colors[1], &ce, sizeof(SDL_Color)); |
| 70 |
ce = { 255-255, 255-255, 255-2, 0 }; |
| 71 |
TS_ASSERT_SAME_DATA(&img->format->palette->colors[0], &ce, sizeof(SDL_Color)); |
| 72 |
TS_ASSERT_EQUALS(SDL_GetColorKey(img, &key), 0); |
| 73 |
TS_ASSERT_EQUALS(key, 0); |
| 74 |
} |
| 75 |
|
| 76 |
void test_print_text_wrap_getcmdsTruecolor() { |
| 77 |
truecolor = 1; |
| 78 |
ImageLoader::initBlitFormat(SDL_PIXELFORMAT_RGB888); |
| 79 |
std::vector<TextCommand> cmds; |
| 80 |
rect r; |
| 81 |
FONTS_SetTextColor(255, 0, 0); |
| 82 |
r = {0,0, 150,100}; |
| 83 |
TS_ASSERT_EQUALS(print_text_wrap_getcmds("toto", &r, 1, 0, FONT_DIALOG, &cmds), 19); |
| 84 |
TS_ASSERT_EQUALS(cmds.size(), 1); |
| 85 |
FONTS_SetTextColor(0, 0, 0); |
| 86 |
r = {-2,0, 150,100}; |
| 87 |
TS_ASSERT_EQUALS(print_text_wrap_getcmds("toto", &r, 1, 0, FONT_DIALOG, &cmds), 19); |
| 88 |
TS_ASSERT_EQUALS(cmds.size(), 2); |
| 89 |
print_text_flatten_cmds(&cmds); |
| 90 |
TS_ASSERT_EQUALS(cmds.size(), 1); |
| 91 |
} |
| 92 |
}; |