Debian Codegraph @

test/testChewingImporter.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 "ChewingImporter.h"
26
27 class TestChewingImporter : public ::testing::Test {
28 protected:
29 TestChewingImporter() = default;
30 virtual ~TestChewingImporter() = default;
31 virtual void SetUp() {}
32 virtual void TearDown() {}
33 };
34
35 TEST_F(TestChewingImporter, ReadNoUserphrase)
36 {
37 auto list = QDir{TESTDATA "/import/json/broken"}.entryList(QDir::Files);
38
39 ASSERT_GT(list.size(), 0);
40
41 foreach(auto file, list) {
42 auto path = QString("%1/%2").arg(TESTDATA "/import/json/broken").arg(file);
43 ChewingImporter importer{path};
44 EXPECT_FALSE(importer.isSupportedFormat());
45 EXPECT_TRUE(importer.getUserphraseSet().empty());
46 }
47 }
48
49 TEST_F(TestChewingImporter, ReadOneUserphrase)
50 {
51 QString path{TESTDATA "/import/json/chewing_one_valid_phrase.json"};
52
53 ChewingImporter importer{path};
54
55 EXPECT_TRUE(importer.isSupportedFormat());
56 EXPECT_EQ(QFileInfo{path}.fileName(), importer.getPath());
57
58 auto result = importer.getUserphraseSet();
59
60 ASSERT_EQ(1, result.size());
61 EXPECT_EQ(0, QString::compare(
62 QString("\xE6\xB8\xAC\xE8\xA9\xA6" /* 測試 */),
63 result[0].phrase_));
64 EXPECT_EQ(0, QString::compare(
65 QString("\xE3\x84\x98\xE3\x84\x9C\xCB\x8B \xE3\x84\x95\xCB\x8B" /* ㄘㄜˋ ㄕˋ */),
66 result[0].bopomofo_));
67 }
68
69 TEST_F(TestChewingImporter, PathError)
70 {
71 ChewingImporter importer{TESTDATA "/NoSuchPath/chewing.json"};
72
73 EXPECT_FALSE(importer.isSupportedFormat());
74 EXPECT_TRUE(importer.getUserphraseSet().empty());
75 }