diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-05-18 12:18:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-05-18 14:52:11 +0300 |
commit | bb9ed14fc1bf7dc20f1e951e67bb359c273033a3 (patch) | |
tree | c46e7e5708d3a2058233a41a08995e6c861703ea /src/gui/fonts | |
parent | 10273bc94e90fefcfe3fc215aaaaafe7e0e96bd4 (diff) | |
download | mv-bb9ed14fc1bf7dc20f1e951e67bb359c273033a3.tar.gz mv-bb9ed14fc1bf7dc20f1e951e67bb359c273033a3.tar.bz2 mv-bb9ed14fc1bf7dc20f1e951e67bb359c273033a3.tar.xz mv-bb9ed14fc1bf7dc20f1e951e67bb359c273033a3.zip |
fix code style.
Diffstat (limited to 'src/gui/fonts')
-rw-r--r-- | src/gui/fonts/font.cpp | 1 | ||||
-rw-r--r-- | src/gui/fonts/font.h | 2 | ||||
-rw-r--r-- | src/gui/fonts/font_unittest.cc | 462 | ||||
-rw-r--r-- | src/gui/fonts/textchunk.cpp | 6 | ||||
-rw-r--r-- | src/gui/fonts/textchunk.h | 2 | ||||
-rw-r--r-- | src/gui/fonts/textchunklist.cpp | 6 | ||||
-rw-r--r-- | src/gui/fonts/textchunksmall.cpp | 1 |
7 files changed, 470 insertions, 10 deletions
diff --git a/src/gui/fonts/font.cpp b/src/gui/fonts/font.cpp index 2edca6b0b..72a047e57 100644 --- a/src/gui/fonts/font.cpp +++ b/src/gui/fonts/font.cpp @@ -67,7 +67,6 @@ #include "gui/fonts/font.h" #include "logger.h" -#include "main.h" #include "gui/fonts/textchunk.h" diff --git a/src/gui/fonts/font.h b/src/gui/fonts/font.h index c8e39fd7c..ebb2d8dcb 100644 --- a/src/gui/fonts/font.h +++ b/src/gui/fonts/font.h @@ -142,7 +142,7 @@ class Font final }; #ifdef UNITTESTS -extern int sdlTextChunkCnt; +extern int textChunkCnt; #endif #endif // GUI_FONTS_FONT_H diff --git a/src/gui/fonts/font_unittest.cc b/src/gui/fonts/font_unittest.cc new file mode 100644 index 000000000..b5b589e72 --- /dev/null +++ b/src/gui/fonts/font_unittest.cc @@ -0,0 +1,462 @@ +/* + * The ManaPlus Client + * Copyright (C) 2013 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "logger.h" + +#include "gui/theme.h" + +#include "gui/fonts/font.h" +#include "gui/fonts/textchunk.h" +#include "gui/fonts/textchunksmall.h" + +#include "gtest/gtest.h" + +#include "debug.h" + +TEST(TextChunkList, empty) +{ + TextChunkList list; + + EXPECT_EQ(0, list.size); + EXPECT_EQ(nullptr, list.start); + EXPECT_EQ(nullptr, list.end); + EXPECT_EQ(0, list.search.size()); + EXPECT_EQ(0, list.searchWidth.size()); +} + +TEST(TextChunkList, add1) +{ + TextChunkList list; + + TextChunk *chunk = new TextChunk("test", + Color(1, 2, 3), Color(2, 3, 4)); + + list.insertFirst(chunk); + + EXPECT_EQ(1, list.size); + EXPECT_EQ(chunk, list.start); + EXPECT_EQ(chunk, list.end); + EXPECT_EQ(nullptr, chunk->prev); + EXPECT_EQ(nullptr, chunk->next); + + EXPECT_EQ(1, list.search.size()); + EXPECT_EQ(chunk, (*list.search.find(TextChunkSmall( + chunk->text, chunk->color, chunk->color2))).second); + + EXPECT_EQ(1, list.searchWidth.size()); + EXPECT_EQ(chunk, (*list.searchWidth.find(chunk->text)).second); +} + +TEST(TextChunkList, add2) +{ + TextChunkList list; + + TextChunk *chunk1 = new TextChunk("test", + Color(1, 2, 3), Color(3, 4, 5)); + TextChunk *chunk2 = new TextChunk("test", + Color(2, 3, 4), Color(4, 5, 6)); + + list.insertFirst(chunk2); + list.insertFirst(chunk1); + + EXPECT_EQ(2, list.size); + EXPECT_EQ(chunk1, list.start); + EXPECT_EQ(chunk2, list.end); + EXPECT_EQ(nullptr, chunk1->prev); + EXPECT_EQ(chunk2, chunk1->next); + EXPECT_EQ(chunk1, chunk2->prev); + EXPECT_EQ(nullptr, chunk2->next); + + EXPECT_EQ(2, list.search.size()); + EXPECT_EQ(chunk1, (*list.search.find(TextChunkSmall( + chunk1->text, chunk1->color, chunk1->color2))).second); + EXPECT_EQ(chunk2, (*list.search.find(TextChunkSmall( + chunk2->text, chunk2->color, chunk2->color2))).second); + + EXPECT_EQ(1, list.searchWidth.size()); + EXPECT_EQ(chunk1, (*list.searchWidth.find(chunk1->text)).second); +} + +TEST(TextChunkList, addRemoveBack1) +{ + TextChunkList list; + + TextChunk *chunk = new TextChunk("test", + Color(1, 2, 3), Color(1, 2, 3)); + + list.insertFirst(chunk); + list.removeBack(); + + EXPECT_EQ(0, list.size); + EXPECT_EQ(nullptr, list.start); + EXPECT_EQ(nullptr, list.end); + EXPECT_EQ(0, list.search.size()); + EXPECT_EQ(0, list.searchWidth.size()); +} + +TEST(TextChunkList, addRemoveBack2) +{ + TextChunkList list; + + TextChunk *chunk1 = new TextChunk("test", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunk *chunk2 = new TextChunk("test2", + Color(1, 2, 4), Color(1, 2, 5)); + + list.insertFirst(chunk2); + list.insertFirst(chunk1); + list.removeBack(); + + EXPECT_EQ(1, list.size); + EXPECT_EQ(chunk1, list.start); + EXPECT_EQ(chunk1, list.end); + EXPECT_EQ(nullptr, chunk1->prev); + EXPECT_EQ(nullptr, chunk1->next); + + EXPECT_EQ(1, list.search.size()); + EXPECT_EQ(chunk1, (*list.search.find(TextChunkSmall( + chunk1->text, chunk1->color, chunk1->color2))).second); + + EXPECT_EQ(1, list.searchWidth.size()); + EXPECT_EQ(chunk1, (*list.searchWidth.find(chunk1->text)).second); +} + +TEST(TextChunkList, addRemoveBack3) +{ + TextChunkList list; + + TextChunk *chunk1 = new TextChunk("test", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunk *chunk2 = new TextChunk("test2", + Color(2, 3, 4), Color(2, 3, 4)); + + list.insertFirst(chunk2); + list.insertFirst(chunk1); + list.removeBack(2); + + EXPECT_EQ(0, list.size); + EXPECT_EQ(nullptr, list.start); + EXPECT_EQ(nullptr, list.end); + + EXPECT_EQ(0, list.search.size()); + EXPECT_EQ(0, list.searchWidth.size()); +} + +TEST(TextChunkList, addRemoveBack4) +{ + TextChunkList list; + + TextChunk *chunk1 = new TextChunk("test", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunk *chunk2 = new TextChunk("test2", + Color(2, 3, 4), Color(2, 3, 4)); + TextChunk *chunk3 = new TextChunk("test", + Color(3, 4, 5), Color(3, 4, 5)); + + list.insertFirst(chunk3); + list.insertFirst(chunk2); + list.insertFirst(chunk1); + list.removeBack(); + list.removeBack(); + + EXPECT_EQ(1, list.size); + EXPECT_EQ(chunk1, list.start); + EXPECT_EQ(chunk1, list.end); + EXPECT_EQ(nullptr, chunk1->prev); + EXPECT_EQ(nullptr, chunk1->next); + + EXPECT_EQ(1, list.search.size()); + EXPECT_EQ(chunk1, (*list.search.find(TextChunkSmall( + chunk1->text, chunk1->color, chunk1->color2))).second); + + EXPECT_EQ(0, list.searchWidth.size()); +} + +TEST(TextChunkList, moveToFirst1) +{ + TextChunkList list; + + TextChunk *chunk = new TextChunk("test", + Color(1, 2, 3), Color(2, 3, 4)); + + list.insertFirst(chunk); + list.moveToFirst(chunk); + + EXPECT_EQ(1, list.size); + EXPECT_EQ(chunk, list.start); + EXPECT_EQ(chunk, list.end); + EXPECT_EQ(nullptr, chunk->prev); + EXPECT_EQ(nullptr, chunk->next); +} + +TEST(TextChunkList, moveToFirst2) +{ + TextChunkList list; + + TextChunk *chunk1 = new TextChunk("test", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunk *chunk2 = new TextChunk("test", + Color(2, 3, 4), Color(1, 2, 3)); + + list.insertFirst(chunk1); + list.insertFirst(chunk2); + list.moveToFirst(chunk1); + + EXPECT_EQ(2, list.size); + EXPECT_EQ(chunk1, list.start); + EXPECT_EQ(chunk2, list.end); + EXPECT_EQ(nullptr, chunk1->prev); + EXPECT_EQ(chunk2, chunk1->next); + EXPECT_EQ(chunk1, chunk2->prev); + EXPECT_EQ(nullptr, chunk2->next); +} + +TEST(TextChunkList, moveToFirst3) +{ + TextChunkList list; + + TextChunk *chunk1 = new TextChunk("test", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunk *chunk2 = new TextChunk("test", + Color(1, 2, 4), Color(1, 2, 3)); + TextChunk *chunk3 = new TextChunk("test", + Color(1, 2, 5), Color(1, 2, 3)); + + list.insertFirst(chunk3); + list.insertFirst(chunk1); + list.insertFirst(chunk2); + list.moveToFirst(chunk1); + + EXPECT_EQ(3, list.size); + EXPECT_EQ(chunk1, list.start); + EXPECT_EQ(chunk3, list.end); + EXPECT_EQ(nullptr, chunk1->prev); + EXPECT_EQ(chunk2, chunk1->next); + EXPECT_EQ(chunk1, chunk2->prev); + EXPECT_EQ(chunk3, chunk2->next); + EXPECT_EQ(chunk2, chunk3->prev); + EXPECT_EQ(nullptr, chunk3->next); +} + +TEST(TextChunkList, moveToFirst4) +{ + TextChunkList list; + + TextChunk *chunk1 = new TextChunk("test", + Color(), Color()); + TextChunk *chunk2 = new TextChunk("test2", + Color(), Color()); + TextChunk *chunk3 = new TextChunk("test3", + Color(), Color()); + + list.insertFirst(chunk1); + list.insertFirst(chunk3); + list.insertFirst(chunk2); + list.moveToFirst(chunk1); + + EXPECT_EQ(3, list.size); + EXPECT_EQ(chunk1, list.start); + EXPECT_EQ(chunk3, list.end); + EXPECT_EQ(nullptr, chunk1->prev); + EXPECT_EQ(chunk2, chunk1->next); + EXPECT_EQ(chunk1, chunk2->prev); + EXPECT_EQ(chunk3, chunk2->next); + EXPECT_EQ(chunk2, chunk3->prev); + EXPECT_EQ(nullptr, chunk3->next); +} + +TEST(TextChunkList, clear1) +{ + TextChunkList list; + int chunksLeft = textChunkCnt; + + TextChunk *chunk = new TextChunk("test", Color(), Color()); + + list.insertFirst(chunk); + list.clear(); + + EXPECT_EQ(0, list.size); + EXPECT_EQ(nullptr, list.start); + EXPECT_EQ(nullptr, list.end); + EXPECT_EQ(chunksLeft, textChunkCnt); + EXPECT_EQ(0, list.search.size()); + EXPECT_EQ(0, list.searchWidth.size()); +} + +TEST(TextChunkList, clear2) +{ + TextChunkList list; + int chunksLeft = textChunkCnt; + + TextChunk *chunk1 = new TextChunk("test", + Color(1, 2, 3), Color(2, 0, 0)); + TextChunk *chunk2 = new TextChunk("test", + Color(1, 2, 3), Color(2, 0, 1)); + TextChunk *chunk3 = new TextChunk("test", + Color(1, 2, 3), Color(2, 0, 2)); + + list.insertFirst(chunk1); + list.insertFirst(chunk2); + list.insertFirst(chunk3); + list.clear(); + + EXPECT_EQ(0, list.size); + EXPECT_EQ(nullptr, list.start); + EXPECT_EQ(nullptr, list.end); + EXPECT_EQ(chunksLeft, textChunkCnt); + EXPECT_EQ(0, list.search.size()); + EXPECT_EQ(0, list.searchWidth.size()); +} + +TEST(TextChunkList, clear3) +{ + TextChunkList list; + int chunksLeft = textChunkCnt; + + TextChunk *chunk1 = new TextChunk("test", + Color(1, 2, 3), Color(2, 0, 0)); + TextChunk *chunk2 = new TextChunk("test", + Color(1, 2, 3), Color(2, 0, 1)); + TextChunk *chunk3 = new TextChunk("test", + Color(1, 2, 3), Color(2, 0, 2)); + + list.insertFirst(chunk1); + list.insertFirst(chunk2); + list.insertFirst(chunk3); + list.moveToFirst(chunk1); + EXPECT_EQ(chunksLeft + 3, textChunkCnt); + EXPECT_EQ(3, list.search.size()); + EXPECT_EQ(1, list.searchWidth.size()); + + list.removeBack(); + EXPECT_EQ(chunksLeft + 2, textChunkCnt); + EXPECT_EQ(2, list.search.size()); + EXPECT_EQ(0, list.searchWidth.size()); + + list.clear(); + EXPECT_EQ(chunksLeft, textChunkCnt); + EXPECT_EQ(0, list.search.size()); + EXPECT_EQ(0, list.searchWidth.size()); +} + +TEST(TextChunkList, clear4) +{ + TextChunkList list; + int chunksLeft = textChunkCnt; + + TextChunk *chunk1 = new TextChunk("test", + Color(1, 2, 3), Color(2, 0, 0)); + TextChunk *chunk2 = new TextChunk("test", + Color(1, 2, 3), Color(2, 0, 1)); + TextChunk *chunk3 = new TextChunk("test3", + Color(1, 2, 3), Color(2, 0, 2)); + + list.insertFirst(chunk1); + list.insertFirst(chunk2); + list.insertFirst(chunk3); + list.moveToFirst(chunk2); + EXPECT_EQ(chunksLeft + 3, textChunkCnt); + EXPECT_EQ(3, list.search.size()); + EXPECT_EQ(2, list.searchWidth.size()); + + list.removeBack(2); + EXPECT_EQ(chunksLeft + 1, textChunkCnt); + EXPECT_EQ(1, list.search.size()); + EXPECT_EQ(0, list.searchWidth.size()); + + list.clear(); + EXPECT_EQ(chunksLeft, textChunkCnt); + EXPECT_EQ(0, list.search.size()); + EXPECT_EQ(0, list.searchWidth.size()); +} + +TEST(TextChunkList, sort1) +{ + TextChunkSmall item1("test line1", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunkSmall item2("test line1", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunkSmall item3("test line2", + Color(1, 2, 3), Color(1, 2, 3)); + EXPECT_EQ(false, item1 < item2); + EXPECT_EQ(false, item2 < item1); + EXPECT_EQ(true, item1 < item3); + EXPECT_EQ(false, item3 < item1); +} + +TEST(TextChunkList, sort2) +{ + TextChunkSmall item1("test line1", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunkSmall item2("test line1", + Color(2, 3, 4), Color(1, 2, 3)); + EXPECT_EQ(true, item1 < item2); + EXPECT_EQ(false, item2 < item1); +} + +TEST(TextChunkList, sort3) +{ + TextChunkSmall item1("test line1", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunkSmall item2("test line1", + Color(1, 3, 4), Color(1, 2, 3)); + EXPECT_EQ(true, item1 < item2); + EXPECT_EQ(false, item2 < item1); +} + +TEST(TextChunkList, sort4) +{ + TextChunkSmall item1("test line1", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunkSmall item2("test line1", + Color(1, 2, 4), Color(1, 2, 3)); + EXPECT_EQ(true, item1 < item2); + EXPECT_EQ(false, item2 < item1); +} + +TEST(TextChunkList, sort5) +{ + TextChunkSmall item1("test line1", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunkSmall item2("test line1", + Color(1, 2, 3), Color(2, 2, 3)); + EXPECT_EQ(true, item1 < item2); + EXPECT_EQ(false, item2 < item1); +} + +TEST(TextChunkList, sort6) +{ + TextChunkSmall item1("test line1", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunkSmall item2("test line1", + Color(1, 2, 3), Color(1, 3, 3)); + EXPECT_EQ(true, item1 < item2); + EXPECT_EQ(false, item2 < item1); +} + +TEST(TextChunkList, sort7) +{ + TextChunkSmall item1("test line1", + Color(1, 2, 3), Color(1, 2, 3)); + TextChunkSmall item2("test line1", + Color(1, 2, 3), Color(1, 2, 4)); + EXPECT_EQ(true, item1 < item2); + EXPECT_EQ(false, item2 < item1); +} diff --git a/src/gui/fonts/textchunk.cpp b/src/gui/fonts/textchunk.cpp index 632dfaf7b..be0509562 100644 --- a/src/gui/fonts/textchunk.cpp +++ b/src/gui/fonts/textchunk.cpp @@ -41,7 +41,7 @@ namespace char *strBuf = nullptr; #ifdef UNITTESTS -int sdlTextChunkCnt = 0; +int textChunkCnt = 0; #endif TextChunk::TextChunk(const std::string &text0, const Color &color0, @@ -54,7 +54,7 @@ TextChunk::TextChunk(const std::string &text0, const Color &color0, next(nullptr) { #ifdef UNITTESTS - sdlTextChunkCnt ++; + textChunkCnt ++; #endif } @@ -62,7 +62,7 @@ TextChunk::~TextChunk() { delete2(img); #ifdef UNITTESTS - sdlTextChunkCnt --; + textChunkCnt --; #endif } diff --git a/src/gui/fonts/textchunk.h b/src/gui/fonts/textchunk.h index 6f124346d..f9aa41406 100644 --- a/src/gui/fonts/textchunk.h +++ b/src/gui/fonts/textchunk.h @@ -58,7 +58,7 @@ class TextChunk final }; #ifdef UNITTESTS -extern int sdlTextChunkCnt; +extern int textChunkCnt; #endif #endif // GUI_FONTS_TEXTCHUNK_H diff --git a/src/gui/fonts/textchunklist.cpp b/src/gui/fonts/textchunklist.cpp index 98d90e23d..ec6083d7d 100644 --- a/src/gui/fonts/textchunklist.cpp +++ b/src/gui/fonts/textchunklist.cpp @@ -54,10 +54,10 @@ void TextChunkList::moveToFirst(TextChunk *const item) if (item == start) return; - TextChunk *oldPrev = item->prev; + TextChunk *const oldPrev = item->prev; if (oldPrev) oldPrev->next = item->next; - TextChunk *oldNext = item->next; + TextChunk *const oldNext = item->next; if (oldNext) oldNext->prev = item->prev; else @@ -121,7 +121,7 @@ void TextChunkList::clear() TextChunk *item = start; while (item) { - TextChunk *item2 = item->next; + TextChunk *const item2 = item->next; delete item; item = item2; } diff --git a/src/gui/fonts/textchunksmall.cpp b/src/gui/fonts/textchunksmall.cpp index 84c1aa378..aa5661dee 100644 --- a/src/gui/fonts/textchunksmall.cpp +++ b/src/gui/fonts/textchunksmall.cpp @@ -72,4 +72,3 @@ bool TextChunkSmall::operator<(const TextChunkSmall &chunk) const return false; } - |