mirror of
https://github.com/fmang/opustags.git
synced 2025-01-15 20:53:16 +01:00
t: modernize system.t
This commit is contained in:
parent
2dbba5a23e
commit
cacbd43422
52
t/system.cc
52
t/system.cc
@ -10,56 +10,52 @@ void check_partial_files()
|
||||
std::string name;
|
||||
{
|
||||
ot::partial_file bad_tmp;
|
||||
if (bad_tmp.open("/dev/null") != ot::st::standard_error)
|
||||
throw failure("cannot open a device as a partial file");
|
||||
if (bad_tmp.open(result) != ot::st::ok)
|
||||
throw failure("could not open a simple result file");
|
||||
is(bad_tmp.open("/dev/null"), ot::st::standard_error,
|
||||
"opening a device as a partial file fails");
|
||||
is(bad_tmp.open(result), ot::st::ok,
|
||||
"opening a regular partial file works");
|
||||
name = bad_tmp.name();
|
||||
if (name.size() != strlen(result) + 12 ||
|
||||
name.compare(0, strlen(result), result) != 0)
|
||||
throw failure("the temporary name is surprising: " + name);
|
||||
}
|
||||
if (access(name.c_str(), F_OK) != -1)
|
||||
throw failure("the bad temporary file was not deleted");
|
||||
is(access(name.c_str(), F_OK), -1, "expect the temporary file is deleted");
|
||||
|
||||
ot::partial_file good_tmp;
|
||||
if (good_tmp.open(result) != ot::st::ok)
|
||||
throw failure("could not open the result file");
|
||||
is(good_tmp.open(result), ot::st::ok, "open the partial file");
|
||||
name = good_tmp.name();
|
||||
if (good_tmp.commit() != ot::st::ok)
|
||||
throw failure("could not commit the result file");
|
||||
if (access(name.c_str(), F_OK) != -1)
|
||||
throw failure("the good temporary file was not deleted");
|
||||
if (access(result, F_OK) != 0)
|
||||
throw failure("the final result file is not there");
|
||||
if (remove(result) != 0)
|
||||
throw failure("could not remove the result file");
|
||||
is(good_tmp.commit(), ot::st::ok, "commit the result file");
|
||||
is(access(name.c_str(), F_OK), -1, "expect the temporary file is deleted");
|
||||
is(access(result, F_OK), 0, "expect the final result file");
|
||||
is(remove(result), 0, "remove the result file");
|
||||
}
|
||||
|
||||
void check_converter()
|
||||
{
|
||||
const char* ephemere_iso = "\xc9\x70\x68\xe9\x6d\xe8\x72\x65";
|
||||
ot::encoding_converter to_utf8("ISO-8859-1", "UTF-8");
|
||||
std::string out;
|
||||
ot::status rc = to_utf8(ephemere_iso, out);
|
||||
if (rc != ot::st::ok || out != "Éphémère")
|
||||
throw failure("conversion to UTF-8 should have worked");
|
||||
|
||||
ot::encoding_converter from_utf8("UTF-8", "ISO-8859-1//TRANSLIT");
|
||||
std::string out;
|
||||
|
||||
ot::status rc = to_utf8(ephemere_iso, out);
|
||||
is(rc, ot::st::ok, "conversion to UTF-8 is successful");
|
||||
is(out, "Éphémère", "conversion to UTF-8 is correct");
|
||||
|
||||
rc = from_utf8("Éphémère", out);
|
||||
if (rc != ot::st::ok || out != ephemere_iso)
|
||||
throw failure("conversion from UTF-8 should have worked");
|
||||
is(rc, ot::st::ok, "conversion from UTF-8 is successful");
|
||||
is(out, ephemere_iso, "conversion from UTF-8 is correct");
|
||||
|
||||
rc = from_utf8("\xFF\xFF", out);
|
||||
if (rc != ot::st::badly_encoded)
|
||||
throw failure("conversion from bad UTF-8 should have failed");
|
||||
is(rc, ot::st::badly_encoded, "conversion from bad UTF-8 fails");
|
||||
|
||||
rc = from_utf8("cat 猫 chat", out);
|
||||
if (rc != ot::st::information_lost || out != "cat ? chat")
|
||||
throw failure("lossy conversion from UTF-8 should have worked");
|
||||
is(rc, ot::st::information_lost, "lossy conversion from UTF-8 is detected");
|
||||
is(out, "cat ? chat", "check result of lossy conversion");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::cout << "1..2\n";
|
||||
plan(2);
|
||||
run(check_partial_files, "test partial files");
|
||||
run(check_converter, "test encoding converter");
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user