Copy from svn repository.
This commit is contained in:
parent
73d6e6fbd0
commit
ac22dabfe6
34 changed files with 1557 additions and 1 deletions
1
src/tests/.params
Normal file
1
src/tests/.params
Normal file
|
|
@ -0,0 +1 @@
|
|||
c++ tests tests libutf8++
|
||||
3
src/tests/build.default
Normal file
3
src/tests/build.default
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
source src/tests/build.tests
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
43
src/tests/build.tests
Normal file
43
src/tests/build.tests
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
# These are external variables, and shouldn't clash with anything else
|
||||
# tests_BUILT
|
||||
#
|
||||
|
||||
build_target libutf8++ || return 1
|
||||
|
||||
if [ -z ${tests_BUILT} ]
|
||||
then
|
||||
LIBS="${libutf8pp} "
|
||||
EXTRAS=""
|
||||
|
||||
echo "Building test programs..."
|
||||
do_cmd mkdir -p obj/tests || return 1
|
||||
|
||||
for SRC in src/tests/*.cpp
|
||||
do
|
||||
TEST="obj/tests/$(basename ${SRC} | sed -e 's,.cpp$,,')"
|
||||
MODIFIED=0
|
||||
for file in ${LIBS} ${SRC} src/tests/build.tests
|
||||
do
|
||||
if [ ${file} -nt ${TEST} ]
|
||||
then
|
||||
MODIFIED=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ ${MODIFIED} -ne 0 ]
|
||||
then
|
||||
do_cmd ${CXX} -Iobj ${CFLAGS} -o ${TEST} ${SRC} ${LIBS} ${EXTRAS} || return 1
|
||||
print_success "Built ${TEST}"
|
||||
else
|
||||
print_success "${TEST} is up to date"
|
||||
fi
|
||||
done
|
||||
|
||||
print_success "All tests built"
|
||||
|
||||
tests_BUILT=1
|
||||
fi
|
||||
|
||||
# kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
# vim: expandtab:ts=4:sw=4
|
||||
85
src/tests/objects.cpp
Normal file
85
src/tests/objects.cpp
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/* libutf8++/src/tests/objects.cpp
|
||||
*
|
||||
* (c)2006, Laurence Withers. Released under the GNU GPL. See file
|
||||
* COPYING for more information / terms of license.
|
||||
*/
|
||||
|
||||
#include "utf8"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
void make_random(wchar_t* buf, int ch)
|
||||
{
|
||||
int fd = open("/dev/urandom", O_RDONLY);
|
||||
if(fd < 0) {
|
||||
perror("open(\"/dev/urandom\")");
|
||||
throw 1;
|
||||
}
|
||||
ch *= sizeof(wchar_t);
|
||||
if(read(fd, (char*)buf, ch) != ch) {
|
||||
perror("read(\"/dev/urandom\")");
|
||||
throw 1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
ch /= sizeof(wchar_t);
|
||||
while(ch--) {
|
||||
buf[ch] &= 0x7FFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
|
||||
std::cout << "Performs some tests on the Encoder and Decoder objects.\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
try {
|
||||
wchar_t wch[1024];
|
||||
make_random(wch, 1024);
|
||||
|
||||
std::wstring ustr;
|
||||
ustr.assign(wch, 1024);
|
||||
|
||||
utf8::Encoder encoder;
|
||||
utf8::Decoder decoder;
|
||||
|
||||
encoder.encode(ustr);
|
||||
decoder.decode(encoder.encoded);
|
||||
|
||||
if(ustr != decoder.decoded) {
|
||||
std::cerr << "Decoded string does not match original.\n";
|
||||
for(size_t i = 0, end = std::min(ustr.size(), decoder.decoded.size()); i != end; ++i) {
|
||||
if(ustr[i] != decoder.decoded[i]) {
|
||||
std::cerr << std::dec << std::setfill(' ') << std::setw(4) << i
|
||||
<< std::setfill('0') << std::hex << ": 0x"
|
||||
<< std::setw(8) << ustr[i] << " != "
|
||||
<< std::setw(8) << decoder.decoded[i] << "\n";
|
||||
}
|
||||
}
|
||||
std::cerr << "Original size " << std::dec << ustr.size()
|
||||
<< ", decoded size " << decoder.decoded.size() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Success.\n";
|
||||
}
|
||||
catch(utf8::Error& e) {
|
||||
std::cerr << e.reason << std::endl;
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
*/
|
||||
82
src/tests/strings.cpp
Normal file
82
src/tests/strings.cpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/* libutf8++/src/tests/strings.cpp
|
||||
*
|
||||
* (c)2006, Laurence Withers. Released under the GNU GPL. See file
|
||||
* COPYING for more information / terms of license.
|
||||
*/
|
||||
|
||||
#include "utf8"
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
|
||||
void make_random(wchar_t* buf, int ch)
|
||||
{
|
||||
int fd = open("/dev/urandom", O_RDONLY);
|
||||
if(fd < 0) {
|
||||
perror("open(\"/dev/urandom\")");
|
||||
throw 1;
|
||||
}
|
||||
ch *= sizeof(wchar_t);
|
||||
if(read(fd, (char*)buf, ch) != ch) {
|
||||
perror("read(\"/dev/urandom\")");
|
||||
throw 1;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
ch /= sizeof(wchar_t);
|
||||
while(ch--) {
|
||||
buf[ch] &= 0x7FFFFFFF;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
|
||||
std::cout << "Performs some tests on the string encode/decode routines.\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
try {
|
||||
wchar_t wch[1024];
|
||||
make_random(wch, 1024);
|
||||
|
||||
std::wstring ustr1, ustr2;
|
||||
std::string utf8;
|
||||
ustr1.assign(wch, 1024);
|
||||
utf8 = utf8::encode(ustr1);
|
||||
ustr2 = utf8::decode(utf8);
|
||||
|
||||
if(ustr1 != ustr2) {
|
||||
std::cerr << "Decoded string does not match original.\n";
|
||||
for(size_t i = 0, end = std::min(ustr1.size(), ustr2.size()); i != end; ++i) {
|
||||
if(ustr1[i] != ustr2[i]) {
|
||||
std::cerr << std::dec << std::setfill(' ') << std::setw(4) << i
|
||||
<< std::setfill('0') << std::hex << ": 0x"
|
||||
<< std::setw(8) << ustr1[i] << " != "
|
||||
<< std::setw(8) << ustr2[i] << "\n";
|
||||
}
|
||||
}
|
||||
std::cerr << "Original size " << std::dec << ustr1.size()
|
||||
<< ", decoded size " << ustr2.size() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << "Success.\n";
|
||||
}
|
||||
catch(utf8::Error& e) {
|
||||
std::cerr << e.reason << std::endl;
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
*/
|
||||
44
src/tests/template
Normal file
44
src/tests/template
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/* libutf8++/src/tests/???.cpp
|
||||
*
|
||||
* (c)2006, Laurence Withers, <l@lwithers.me.uk>.
|
||||
* Released under the GNU GPLv2. See file COPYING or
|
||||
* http://www.gnu.org/copyleft/gpl.html for details.
|
||||
*/
|
||||
|
||||
#include "utf8"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if(argc == 2 && !strcmp(argv[1], "--print-summary")) {
|
||||
std::cout << "One line summary.\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(argc == 1) {
|
||||
// empty argument list
|
||||
}
|
||||
|
||||
int ret = 0;
|
||||
try {
|
||||
// TODO
|
||||
}
|
||||
catch(std::exception& e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
ret = 1;
|
||||
}
|
||||
catch(...) {
|
||||
std::cerr << "Unknown exception caught." << std::endl;
|
||||
ret = 1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* options for text editors
|
||||
kate: replace-trailing-space-save true; space-indent true; tab-width 4;
|
||||
vim: expandtab:ts=4:sw=4
|
||||
*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue