Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests *all* functionality of de::StringPool.
- Loading branch information
1 parent
c6b6a38
commit ff99577
Showing
4 changed files
with
124 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/** | ||
* @file main.cpp | ||
* | ||
* StringPool unit tests. @ingroup tests | ||
* | ||
* @author Copyright © 2010-2012 Daniel Swanson <danij@dengine.net> | ||
* @author Copyright © 2012 Jaakko Keränen <jaakko.keranen@iki.fi> | ||
* | ||
* @par License | ||
* GPL: http://www.gnu.org/licenses/gpl.html | ||
* | ||
* <small>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 (at your | ||
* option) 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, write to the Free | ||
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
* 02110-1301 USA</small> | ||
*/ | ||
|
||
#include <de/StringPool> | ||
#include <QDebug> | ||
|
||
using namespace de; | ||
|
||
int main(int, char**) | ||
{ | ||
try | ||
{ | ||
StringPool p; | ||
|
||
String s = String("Hello"); | ||
DENG2_ASSERT(!p.isInterned(s)); | ||
DENG2_ASSERT(p.empty()); | ||
|
||
// First string. | ||
p.intern(s); | ||
DENG2_ASSERT(p.isInterned(s) == 1); | ||
|
||
// Re-insertion. | ||
DENG2_ASSERT(p.intern(s) == 1); | ||
|
||
// Case insensitivity. | ||
s = String("heLLO"); | ||
DENG2_ASSERT(p.intern(s) == 1); | ||
|
||
// Another string. | ||
s = String("abc"); | ||
String const& is = p.internAndRetrieve(s); | ||
DENG2_ASSERT(!is.compare(s)); | ||
|
||
String s2 = String("ABC"); | ||
String const& is2 = p.internAndRetrieve(s2); | ||
DENG2_ASSERT(!is2.compare(s)); | ||
|
||
DENG2_ASSERT(p.intern(is2) == 2); | ||
|
||
DENG2_ASSERT(p.size() == 2); | ||
//p.print(); | ||
|
||
DENG2_ASSERT(!p.empty()); | ||
|
||
p.setUserValue(1, 1234); | ||
DENG2_ASSERT(p.userValue(1) == 1234); | ||
|
||
DENG2_ASSERT(p.userValue(2) == 0); | ||
|
||
s = String("HELLO"); | ||
p.remove(s); | ||
DENG2_ASSERT(!p.isInterned(s)); | ||
DENG2_ASSERT(p.size() == 1); | ||
DENG2_ASSERT(!p.string(2).compare("abc")); | ||
|
||
s = String("Third!"); | ||
DENG2_ASSERT(p.intern(s) == 1); | ||
DENG2_ASSERT(p.size() == 2); | ||
|
||
s = String("FOUR"); | ||
p.intern(s); | ||
p.removeById(1); // "Third!" | ||
|
||
#if 0 | ||
// Serialize. | ||
Writer* w = Writer_NewWithDynamicBuffer(0); | ||
p.write(w); | ||
|
||
// Deserialize. | ||
Reader* r = Reader_NewWithBuffer(Writer_Data(w), Writer_Size(w)); | ||
StringPool p2; | ||
p2.read(r); | ||
//p2.print(); | ||
DENG2_ASSERT(p2.size() == 2); | ||
DENG2_ASSERT(!p2.string(2).compare("abc")); | ||
DENG2_ASSERT(!p2.string(3).compare("FOUR")); | ||
s = String("hello again"); | ||
DENG2_ASSERT(p2.intern(s) == 1); | ||
|
||
Reader_Delete(r); | ||
Writer_Delete(w); | ||
#endif | ||
|
||
p.clear(); | ||
DENG2_ASSERT(p.empty()); | ||
} | ||
catch(const Error& err) | ||
{ | ||
qWarning() << err.asText() << "\n"; | ||
} | ||
|
||
qDebug() << "Exiting main()...\n"; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
include(../config_test.pri) | ||
|
||
TEMPLATE = app | ||
TARGET = test_stringpool | ||
|
||
SOURCES += main.cpp | ||
|
||
deployTest($$TARGET) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,6 @@ deng_tests: SUBDIRS += \ | |
archive \ | ||
record \ | ||
script \ | ||
stringpool \ | ||
vectors | ||
#basiclink |