Two defects in the test suite, both of the kind that fails on another
machine but not on the one it was written on.
1. Seven tests put their scratch directories below /tmp/opencode --
a directory of the environment they were written in, not of the
system. mkdtemp() returns NULL when the parent is missing, so on a
machine without /tmp/opencode every one of them failed with a "NULL"
check or perror("mkdtemp"), and nothing was wrong with the code under
test. dc_test_tmpdir() (dc_internal.h, instance.c) now uses $TMPDIR,
or /tmp when it is unset or not absolute.
Measured: after renaming /tmp/opencode away (sudo mv), make check in
lib/libDtChat is 24/24; before the change the same run failed on
test_identity, test_pair, test_store, test_instance, test_filexfer,
test_local and test_i18n.
2. test_i18n takes <de.msg> <en.msg> but TESTS runs it without arguments
(f46a914c added it to TESTS without a runner), so `make check' always
reported "FAIL: test_i18n" with the usage line -- measured 2026-11-22
on the merge build, and identically on build/mcde-host, so not a
regression of that merge. tools/mcde-tests.sh names the files and
passes; the test now falls back to $srcdir (which automake's test
driver exports) and finds them itself, the arguments still winning.
Test: make check in lib/libDtChat -> 24/24 PASS (was 23/24). Both call
forms of test_i18n give "test_i18n: all ok": with the two arguments and
without them. With /tmp/opencode renamed away the full check is green as
well, and the seven scratch directories appear under $TMPDIR when set.
138 lines
3.3 KiB
C
138 lines
3.3 KiB
C
/*
|
|
* test_i18n.c -- tests for the dtchat message catalog (T10.4)
|
|
*
|
|
* License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
|
|
*
|
|
* usage: test_i18n <de.msg> <en.msg>
|
|
*
|
|
* Builds both catalogs with gencat into a temporary directory, points NLSPATH
|
|
* at them and checks the ids 2 (File/Datei) and 21 (Send/Senden) plus the
|
|
* fallback for an unknown id. No locale has to be installed: catopen is
|
|
* given a path without %L.
|
|
*/
|
|
#include "dc_internal.h"
|
|
|
|
#include <locale.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/stat.h>
|
|
#include <sys/wait.h>
|
|
#include <unistd.h>
|
|
|
|
static int fails;
|
|
|
|
#define CHECK(cond) do {\
|
|
if (!(cond)) {\
|
|
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__,\
|
|
#cond);\
|
|
fails++;\
|
|
}\
|
|
} while (0)
|
|
|
|
static int
|
|
gencat_to(const char *cat, const char *msg)
|
|
{
|
|
pid_t pid = fork();
|
|
|
|
if (pid == 0) {
|
|
execlp("gencat", "gencat", cat, msg, (char *)NULL);
|
|
_exit(127);
|
|
}
|
|
if (pid < 0)
|
|
return -1;
|
|
{
|
|
int status = 0;
|
|
|
|
if (waitpid(pid, &status, 0) < 0)
|
|
return -1;
|
|
return WIFEXITED(status) && WEXITSTATUS(status) == 0 ? 0 : -1;
|
|
}
|
|
}
|
|
|
|
static void
|
|
use_catalog(const char *dir)
|
|
{
|
|
char path[512];
|
|
|
|
snprintf(path, sizeof(path), "%s/%%N.cat", dir);
|
|
dc_i18n_close();
|
|
(void)setenv("NLSPATH", path, 1);
|
|
dc_i18n_init();
|
|
}
|
|
|
|
int
|
|
main(int argc, char **argv)
|
|
{
|
|
char tmp[64];
|
|
char de[1024], en[1024], cat[1200];
|
|
char *msg_de;
|
|
char *msg_en;
|
|
|
|
/* make check gives no arguments ($srcdir is exported by automake's
|
|
* test driver); tools/mcde-tests.sh names the two files. Both the
|
|
* in-tree build and a VPATH build find them this way. */
|
|
if (argc >= 3) {
|
|
msg_de = argv[1];
|
|
msg_en = argv[2];
|
|
} else {
|
|
const char *srcdir = getenv("srcdir");
|
|
static char bde[1024], ben[1024];
|
|
int n;
|
|
|
|
if (srcdir == NULL || srcdir[0] == '\0')
|
|
srcdir = ".";
|
|
n = snprintf(bde, sizeof(bde), "%s/../../programs/"
|
|
"localized/de_DE.UTF-8/msg/dtchat.msg", srcdir);
|
|
if (n > 0 && (size_t)n < sizeof(bde) &&
|
|
access(bde, R_OK) == 0) {
|
|
msg_de = bde;
|
|
snprintf(ben, sizeof(ben), "%s/../../programs/"
|
|
"dtchat/dtchat.msg", srcdir);
|
|
msg_en = ben;
|
|
} else {
|
|
fprintf(stderr, "usage: %s <de.msg> <en.msg>\n",
|
|
argv[0]);
|
|
return 2;
|
|
}
|
|
}
|
|
CHECK(dc_test_tmpdir(tmp, sizeof tmp, "i18n") == 0);
|
|
snprintf(de, sizeof(de), "%s/de", tmp);
|
|
snprintf(en, sizeof(en), "%s/en", tmp);
|
|
CHECK(mkdir(de, 0700) == 0 || 1);
|
|
CHECK(mkdir(en, 0700) == 0 || 1);
|
|
snprintf(cat, sizeof(cat), "%s/dtchat.cat", de);
|
|
CHECK(gencat_to(cat, msg_de) == 0);
|
|
snprintf(cat, sizeof(cat), "%s/dtchat.cat", en);
|
|
CHECK(gencat_to(cat, msg_en) == 0);
|
|
|
|
(void)setenv("LANG", "C", 1);
|
|
(void)setlocale(LC_ALL, "");
|
|
use_catalog(de);
|
|
CHECK(strcmp(dc_text(2, "x"), "Datei") == 0);
|
|
CHECK(strcmp(dc_text(21, "x"), "Senden") == 0);
|
|
CHECK(strcmp(dc_text(999, "fallback"), "fallback") == 0);
|
|
use_catalog(en);
|
|
CHECK(strcmp(dc_text(2, "x"), "File") == 0);
|
|
CHECK(strcmp(dc_text(21, "x"), "Send") == 0);
|
|
dc_i18n_close();
|
|
|
|
{
|
|
char path[1200];
|
|
|
|
snprintf(path, sizeof(path), "%s/dtchat.cat", de);
|
|
(void)unlink(path);
|
|
snprintf(path, sizeof(path), "%s/dtchat.cat", en);
|
|
(void)unlink(path);
|
|
(void)rmdir(de);
|
|
(void)rmdir(en);
|
|
(void)rmdir(tmp);
|
|
}
|
|
if (fails != 0) {
|
|
fprintf(stderr, "%d test(s) failed\n", fails);
|
|
return 1;
|
|
}
|
|
printf("test_i18n: all ok\n");
|
|
return 0;
|
|
}
|