Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/words
diff options
context:
space:
mode:
authorAlexander Gusak <alexander.gusak@gmail.com>2011-08-02 02:10:31 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:21:16 +0300
commitb7a2a89fa280b3b74585a3b45b22c4668af803cb (patch)
tree88892ae4e8b8df5944ea2d902900de2ccb591de4 /words
parent89e1bec8eaa35a3db18e050f2044f198b2b2b683 (diff)
Fixed words_tests: one file handle remains open at deletion moment.
Diffstat (limited to 'words')
-rw-r--r--words/words_tests/sorted_index_test.cpp57
1 files changed, 31 insertions, 26 deletions
diff --git a/words/words_tests/sorted_index_test.cpp b/words/words_tests/sorted_index_test.cpp
index 99b47363a7..e61bda6ed4 100644
--- a/words/words_tests/sorted_index_test.cpp
+++ b/words/words_tests/sorted_index_test.cpp
@@ -96,32 +96,37 @@ namespace
UNIT_TEST(SortedIndex_Smoke)
{
string const & filePrefix = "sorted_index_smoke_test";
- DictionaryMock dictionary;
- SetupDictionary(dictionary);
- sl::StrFn strFn = StrFnForTest();
- sl::SortedIndex::Build(dictionary, strFn, filePrefix);
- sl::SortedIndex idx(dictionary, GetPlatform().GetReader(filePrefix + ".idx"), strFn);
- TEST_EQUAL(dictionary.KeyCount(), 5, ());
- TEST_EQUAL(KeyByIndexId(idx, 0), "abc", ());
- TEST_EQUAL(KeyByIndexId(idx, 1), "He", ());
- TEST_EQUAL(KeyByIndexId(idx, 2), "Hello", ());
- TEST_EQUAL(KeyByIndexId(idx, 3), "hello", ());
- TEST_EQUAL(KeyByIndexId(idx, 4), "World", ());
- TEST_EQUAL(ArticleByIndexId(idx, 0), "abc1", ());
- TEST_EQUAL(ArticleByIndexId(idx, 1), "He0", ());
- TEST_EQUAL(ArticleByIndexId(idx, 2), "Hello0", ());
- TEST_EQUAL(ArticleByIndexId(idx, 3), "hello0", ());
- TEST_EQUAL(ArticleByIndexId(idx, 4), "World0", ());
- TEST_EQUAL(idx.PrefixSearch(""), 0, ());
- TEST_EQUAL(idx.PrefixSearch("h"), 1, ());
- TEST_EQUAL(idx.PrefixSearch("H"), 1, ());
- TEST_EQUAL(idx.PrefixSearch("He"), 1, ());
- TEST_EQUAL(idx.PrefixSearch("he"), 1, ());
- TEST_EQUAL(idx.PrefixSearch("hea"), 2, ());
- TEST_EQUAL(idx.PrefixSearch("hel"), 2, ());
- TEST_EQUAL(idx.PrefixSearch("Hello"), 2, ());
- TEST_EQUAL(idx.PrefixSearch("W"), 4, ());
- TEST_EQUAL(idx.PrefixSearch("zzz"), 5, ());
+
+ {
+ // Local scope to be sure all file handles are closed before deletion
+ DictionaryMock dictionary;
+ SetupDictionary(dictionary);
+ sl::StrFn strFn = StrFnForTest();
+ sl::SortedIndex::Build(dictionary, strFn, filePrefix);
+ sl::SortedIndex idx(dictionary, GetPlatform().GetReader(filePrefix + ".idx"), strFn);
+ TEST_EQUAL(dictionary.KeyCount(), 5, ());
+ TEST_EQUAL(KeyByIndexId(idx, 0), "abc", ());
+ TEST_EQUAL(KeyByIndexId(idx, 1), "He", ());
+ TEST_EQUAL(KeyByIndexId(idx, 2), "Hello", ());
+ TEST_EQUAL(KeyByIndexId(idx, 3), "hello", ());
+ TEST_EQUAL(KeyByIndexId(idx, 4), "World", ());
+ TEST_EQUAL(ArticleByIndexId(idx, 0), "abc1", ());
+ TEST_EQUAL(ArticleByIndexId(idx, 1), "He0", ());
+ TEST_EQUAL(ArticleByIndexId(idx, 2), "Hello0", ());
+ TEST_EQUAL(ArticleByIndexId(idx, 3), "hello0", ());
+ TEST_EQUAL(ArticleByIndexId(idx, 4), "World0", ());
+ TEST_EQUAL(idx.PrefixSearch(""), 0, ());
+ TEST_EQUAL(idx.PrefixSearch("h"), 1, ());
+ TEST_EQUAL(idx.PrefixSearch("H"), 1, ());
+ TEST_EQUAL(idx.PrefixSearch("He"), 1, ());
+ TEST_EQUAL(idx.PrefixSearch("he"), 1, ());
+ TEST_EQUAL(idx.PrefixSearch("hea"), 2, ());
+ TEST_EQUAL(idx.PrefixSearch("hel"), 2, ());
+ TEST_EQUAL(idx.PrefixSearch("Hello"), 2, ());
+ TEST_EQUAL(idx.PrefixSearch("W"), 4, ());
+ TEST_EQUAL(idx.PrefixSearch("zzz"), 5, ());
+ }
+
FileWriter::DeleteFileX(GetPlatform().WritablePathForFile(filePrefix + ".idx"));
TEST(g_AllocatedStrSet.empty(), ());
}