fix potential bug in Trie.hpp

This commit is contained in:
wyy 2014-04-10 02:58:04 -07:00
parent 61f542a6b1
commit c04ab76afb
2 changed files with 14 additions and 1 deletions

View File

@ -71,13 +71,16 @@ namespace CppJieba
} }
Trie(const string& filePath) Trie(const string& filePath)
{ {
Trie(); new (this) Trie();
_setInitFlag(init(filePath)); _setInitFlag(init(filePath));
} }
~Trie() ~Trie()
{ {
_deleteNode(_root); _deleteNode(_root);
} }
private:
public: public:
bool init(const string& filePath) bool init(const string& filePath)
{ {

View File

@ -5,8 +5,18 @@ using namespace CppJieba;
static const char* const DICT_FILE = "../dict/extra_dict/jieba.dict.small.utf8"; static const char* const DICT_FILE = "../dict/extra_dict/jieba.dict.small.utf8";
TEST(TrieTest, NewAndDelete)
{
Trie * trie;
trie = new Trie(DICT_FILE);
delete trie;
trie = new Trie();
delete trie;
}
TEST(TrieTest, Test1) TEST(TrieTest, Test1)
{ {
string s1, s2; string s1, s2;
Trie trie; Trie trie;
ASSERT_TRUE(trie.init(DICT_FILE)); ASSERT_TRUE(trie.init(DICT_FILE));