Skip to content

Commit 675701c

Browse files
committed
Add CTest on Windows support.
修改: .gitignore 修改: ChangeLog 修改: FILELIST 删除: tests/check-stateful 新文件: tests/check-stateful.cpp 删除: tests/check-stateless 新文件: tests/check-stateless.cpp 删除: tests/cmp.cpp 新文件: tests/data-generator.cpp 新文件: tests/file_utils.hpp 删除: tests/gengb18030z.cpp 删除: tests/genutf8.cpp 删除: tests/reiconv-test.cpp 新文件: tests/reiconv-test.hpp 新文件: tests/sort.cpp 新文件: tests/sort.hpp 删除: tests/table-from.cpp 新文件: tests/table-from.hpp 删除: tests/table-to.cpp 新文件: tests/table-to.hpp 修改: tests/test-shiftseq.cpp 修改: tests/test-to-wchar.cpp 修改: tests/tests.cmake 新文件: tests/throw_error.hpp 删除: tests/uniq-u.cpp 新文件: tests/uniq-u.hpp
1 parent b86c5e4 commit 675701c

26 files changed

+1677
-1129
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ tests/test-shiftseq.exe
4141
tests/uniq-u
4242
tests/uniq-u.exe
4343
tests/tmp-*.TXT
44+
a.out
4445

4546
# Patterns for all subdirectories: all kinds of automatic backup files.
4647
*.orig
@@ -60,6 +61,7 @@ build-aux/
6061
tests/data/UTF-8.TXT
6162
tests/data/GB18030-2005.TXT
6263
tests/data/GB18030-2022.TXT
64+
*.tmp
6365

6466
# Dist directory and temps
6567
cppp-reiconv-v*

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2023-08-23 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
2+
3+
Add CTest on Windows support.
4+
15
2023-07-28 ChenPi11 <wushengwuxi-msctinoulk@outlook.com>
26

37
Finish NLS Translate language maps (en_US, zh_CN).

FILELIST

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -288,15 +288,14 @@ lib/tds565.h
288288
lib/cp932ext.h
289289
lib/gb12345ext.h
290290
lib/loop_wchar.h
291-
tests/table-from.cpp
292-
tests/cmp.cpp
293-
tests/check-stateless
291+
tests/check-stateless.cpp
292+
tests/table-from.hpp
294293
tests/tests.cmake
295-
tests/uniq-u.cpp
296-
tests/reiconv-test.cpp
297-
tests/table-to.cpp
298-
tests/check-stateful
299-
tests/genutf8.cpp
294+
tests/uniq-u.hpp
295+
tests/reiconv-test.hpp
296+
tests/table-to.hpp
297+
tests/check-stateful.cpp
298+
tests/data-generator.cpp
300299
tests/data/IBM-284.TXT
301300
tests/data/IBM-1112.TXT
302301
tests/data/IBM-1146.TXT
@@ -543,7 +542,10 @@ tests/data/IBM-1158.TXT
543542
tests/data/BIG5-2003.IRREVERSIBLE.TXT
544543
tests/test-shiftseq.cpp
545544
tests/test-to-wchar.cpp
546-
tests/gengb18030z.cpp
545+
tests/throw_error.hpp
546+
tests/file_utils.hpp
547+
tests/sort.cpp
548+
tests/sort.hpp
547549
COPYING
548550
Makefile.devel
549551
include/cppp/reiconv.hpp.in

tests/check-stateful

Lines changed: 0 additions & 20 deletions
This file was deleted.

tests/check-stateful.cpp

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (C) 2023 The C++ Plus Project.
3+
* This file is part of the cppp-reiconv Library.
4+
*
5+
* The cppp-reiconv Library is free software; you can redistribute it
6+
* and/or modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either version 3
8+
* of the License, or (at your option) any later version.
9+
*
10+
* The cppp-reiconv Library is distributed in the hope that it will be
11+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with the cppp-reiconv Library; see the file COPYING.
17+
* If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
/*
21+
Simple check of a stateful encoding.
22+
*/
23+
24+
#include <iostream>
25+
#include <cstring>
26+
27+
#include "file_utils.hpp"
28+
#include "reiconv-test.hpp"
29+
30+
31+
std::string replace(const std::string& src, const std::string& from, const std::string& to)
32+
{
33+
std::string result = src;
34+
size_t pos = 0;
35+
36+
while ((pos = result.find(from, pos)) != std::string::npos)
37+
{
38+
result.replace(pos, from.length(), to);
39+
pos += to.length();
40+
}
41+
42+
return result;
43+
}
44+
45+
std::string srcdir, charset;
46+
47+
// Usage: check-stateful SRCDIR CHARSET
48+
int main(int argc, char* argv[])
49+
{
50+
if(argc < 3)
51+
{
52+
std::cerr << "Usage: check-stateful SRCDIR CHARSET\n";
53+
return 1;
54+
}
55+
srcdir = argv[1];
56+
charset = argv[2];
57+
58+
std::string charsetf = replace(charset, ":", "-");
59+
60+
if(file_exists(srcdir + "/" + charsetf + "-snippet.alt"))
61+
{
62+
test::iconv::main(charset, "UTF-8", srcdir + "/" + charsetf + "-snippet.alt", "tmp-snippet");
63+
assert_compare_file(srcdir + "/" + charsetf + "-snippet.UTF-8", "tmp-snippet");
64+
}
65+
66+
test::iconv::main(charset, "UTF-8", srcdir + "/" + charsetf + "-snippet", "tmp-snippet");
67+
assert_compare_file(srcdir + "/" + charsetf + "-snippet.UTF-8", "tmp-snippet");
68+
69+
test::iconv::main("UTF-8", charset, srcdir + "/" + charsetf + "-snippet.UTF-8", "tmp-snippet");
70+
assert_compare_file(srcdir + "/" + charsetf + "-snippet", "tmp-snippet");
71+
72+
remove_file("tmp-snippet");
73+
74+
success("check-stateful", charset + " OK.");
75+
return 0;
76+
}

tests/check-stateless

Lines changed: 0 additions & 36 deletions
This file was deleted.

tests/check-stateless.cpp

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
/*
2+
* Copyright (C) 2023 The C++ Plus Project.
3+
* This file is part of the cppp-reiconv Library.
4+
*
5+
* The cppp-reiconv Library is free software; you can redistribute it
6+
* and/or modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either version 3
8+
* of the License, or (at your option) any later version.
9+
*
10+
* The cppp-reiconv Library is distributed in the hope that it will be
11+
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with the cppp-reiconv Library; see the file COPYING.
17+
* If not, see <https://www.gnu.org/licenses/>.
18+
*/
19+
20+
/*
21+
Complete check of a stateless encoding.
22+
*/
23+
24+
#include <iostream>
25+
#include <cstring>
26+
#include <regex>
27+
28+
#include "file_utils.hpp"
29+
#include "table-from.hpp"
30+
#include "table-to.hpp"
31+
#include "sort.hpp"
32+
#include "uniq-u.hpp"
33+
34+
std::string replace(const std::string& src, const std::string& from, const std::string& to)
35+
{
36+
std::string result = src;
37+
size_t pos = 0;
38+
39+
while ((pos = result.find(from, pos)) != std::string::npos)
40+
{
41+
result.replace(pos, from.length(), to);
42+
pos += to.length();
43+
}
44+
45+
return result;
46+
}
47+
48+
std::string srcdir, charset;
49+
50+
void check2_pre_process(const std::string& input_file_path, const std::string& output_file_path)
51+
{
52+
std::ifstream input_file(input_file_path);
53+
std::ofstream output_file(output_file_path, std::ios::trunc);
54+
55+
if (input_file.is_open() && output_file.is_open())
56+
{
57+
std::string line;
58+
std::regex pattern("\t.* 0x");
59+
60+
while (std::getline(input_file, line))
61+
{
62+
if (!std::regex_search(line, pattern))
63+
{
64+
output_file << line << '\n';
65+
}
66+
}
67+
68+
input_file.close();
69+
output_file.close();
70+
}
71+
else
72+
{
73+
error(input_file_path + " " + output_file_path, "Unable to open file.");
74+
}
75+
}
76+
77+
// Usage: check-stateful SRCDIR CHARSET
78+
int main(int argc, char* argv[])
79+
{
80+
if(argc < 3)
81+
{
82+
std::cerr << "Usage: check-stateful SRCDIR CHARSET\n";
83+
return 1;
84+
}
85+
srcdir = argv[1];
86+
charset = argv[2];
87+
88+
// Charset, modified for use in filenames.
89+
std::string charsetf = replace(charset, ":", "-");
90+
91+
// Iconv in one direction.
92+
test::table_from("tmp-" + charsetf + ".TXT", charset);
93+
94+
// Iconv in the other direction.
95+
test::table_to("tmp-" + charsetf + ".INVERSE.UNSORTED.TXT", charset);
96+
sort_file("tmp-" + charsetf + ".INVERSE.UNSORTED.TXT", "tmp-" + charsetf + ".INVERSE.TXT");
97+
98+
// Check 1: charmap and iconv forward should be identical.
99+
assert_compare_file(srcdir + "/" + charsetf + ".TXT", "tmp-" + charsetf + ".TXT");
100+
101+
// Check 2: the difference between the charmap and iconv backward.
102+
check2_pre_process(srcdir + "/" + charsetf + ".TXT", "tmp-noprecomposed-" + charsetf + ".TXT");
103+
104+
if(file_exists(srcdir + "/" + charsetf + ".IRREVERSIBLE.TXT"))
105+
{
106+
std::vector<std::string> files = { "tmp-noprecomposed-" + charsetf + ".TXT", srcdir + "/" + charsetf + ".IRREVERSIBLE.TXT" };
107+
merge_files(files, "tmp-orig-" + charsetf + ".INVERSE.UNSORTED.TXT");
108+
sort_file("tmp-orig-" + charsetf + ".INVERSE.UNSORTED.TXT", "tmp-orig-" + charsetf + ".INVERSE.UNUNIQUED.TXT");
109+
uniq_u("tmp-orig-" + charsetf + ".INVERSE.UNUNIQUED.TXT", "tmp-orig-" + charsetf + ".INVERSE.TXT");
110+
}
111+
else
112+
{
113+
copy_file("tmp-noprecomposed-" + charsetf + ".TXT", "tmp-orig-" + charsetf + ".INVERSE.TXT");
114+
}
115+
assert_compare_file("tmp-orig-" + charsetf + ".INVERSE.TXT", "tmp-" + charsetf + ".INVERSE.TXT");
116+
117+
remove_file("tmp-" + charsetf + ".TXT");
118+
remove_file("tmp-" + charsetf + ".INVERSE.UNSORTED.TXT");
119+
remove_file("tmp-" + charsetf + ".INVERSE.TXT");
120+
remove_file("tmp-orig-" + charsetf + ".INVERSE.UNSORTED.TXT");
121+
remove_file("tmp-orig-" + charsetf + ".INVERSE.UNUNIQUED.TXT");
122+
remove_file("tmp-orig-" + charsetf + ".INVERSE.TXT");
123+
remove_file("tmp-noprecomposed-" + charsetf + ".TXT");
124+
125+
success("check-stateless", charset + " OK.");
126+
return 0;
127+
}

0 commit comments

Comments
 (0)