Debian Codegraph @

test/testHashImporter.cpp

raw symbols SCIP
1 /*
2 * chewing-editor: Chewing userphrase editor
3 * Copyright (C) 2014 Chewing Development Team
4
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #include "gtest/gtest.h"
21
22 #include <QDebug>
23 #include <QDir>
24
25 #include "HashImporter.h"
26
27 class TestHashImporter : public ::testing::Test {
28 protected:
29 TestHashImporter() = default;
30 virtual ~TestHashImporter() = default;
31 virtual void SetUp() {}
32 virtual void TearDown() {}
33 };
34
35 TEST_F(TestHashImporter, ReadUserphrase)
36 {
37 QString path{TESTDATA "/import/uhash.dat/uhash.dat"};
38 HashImporter importer{path};
39
40 EXPECT_TRUE(importer.isSupportedFormat());
41 EXPECT_EQ(QFileInfo{path}.fileName(), importer.getPath());
42
43 auto result = importer.getUserphraseSet();
44
45 EXPECT_EQ(2, result.size());
46
47 EXPECT_EQ(0, QString::compare(
48 QString("\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */),
49 result[0].phrase_));
50
51 EXPECT_EQ(0, QString::compare(
52 QString("\xE3\x84\x98\xE3\x84\x9C\xCB\x8B \xE3\x84\x95\xCB\x8B" /* ㄘㄜˋ ㄕˋ */),
53 result[0].bopomofo_));
54
55 EXPECT_EQ(0, QString::compare(
56 QString("\xE4\xB8\x80\xE4\xB8\x8B" /* 一下 */),
57 result[1].phrase_));
58
59 EXPECT_EQ(0, QString::compare(
60 QString("\xE3\x84\xA7\xCB\x8A \xE3\x84\x92\xE3\x84\xA7\xE3\x84\x9A\xCB\x8B" /* ㄧˊ ㄒㄧㄚˋ */),
61 result[1].bopomofo_));
62 }
63
64 TEST_F(TestHashImporter, ReadBrokenHash)
65 {
66 auto list = QDir{TESTDATA "/import/uhash.dat/broken"}.entryList(QDir::Files);
67
68 ASSERT_GT(list.size(), 0);
69
70 foreach(auto file, list) {
71 auto path = QString("%1/%2").arg(TESTDATA "/import/uhash.dat/broken").arg(file);
72 HashImporter importer{path};
73 EXPECT_FALSE(importer.isSupportedFormat());
74 EXPECT_TRUE(importer.getUserphraseSet().empty());
75 }
76 }
77
78 TEST_F(TestHashImporter, PathError)
79 {
80 HashImporter importer{TESTDATA "/NoSuchPath/uhash.dat"};
81
82 EXPECT_FALSE(importer.isSupportedFormat());
83 EXPECT_TRUE(importer.getUserphraseSet().empty());
84 }