Skip to content

Commit

Permalink
Implement unit tests for localization (Issue #58)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed May 30, 2022
1 parent ed5867d commit 289dca2
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions testsuite/testpappl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,20 @@ test_api(pappl_system_t *system) // I - System
size_t get_size, // Size for "get" call
set_size; // Size for ", set" call
pappl_printer_t *printer; // Current printer
pappl_loc_t *loc; // Current localization
_pappl_testprinter_t pdata; // Printer test data
const char *key = "A printer with that name already exists.",
// Key string
*text; // Localized text
static const char * const languages[] =
{
"de",
"en",
"es",
"fr",
"it",
"ja"
};
static const char * const set_locations[10][2] =
{
// Some wonders of the ancient world (all north-eastern portion of globe...)
Expand Down Expand Up @@ -1197,6 +1210,54 @@ test_api(pappl_system_t *system) // I - System
};


for (i = 0; i < (int)(sizeof(languages) / sizeof(languages[0])); i ++)
{
// papplSystemFindLoc
testBegin("api: papplSystemFindLoc('%s')", languages[i]);
if ((loc = papplSystemFindLoc(system, languages[i])) == NULL)
{
testEnd(false);
pass = false;
}
else
testEnd(true);

// papplLocGetString
testBegin("api: papplLocGetString('%s')", key);
if ((text = papplLocGetString(loc, key)) == NULL || text == key)
{
testEndMessage(false, "got %p", text);
pass = false;
}
else if (!strcmp(key, text) && strcmp(languages[i], "en"))
{
testEndMessage(false, "not localized");
pass = false;
}
else
testEndMessage(true, "got '%s'", text);
}

// papplSystemFindLoc
testBegin("api: papplSystemFindLoc('zz')");
if ((loc = papplSystemFindLoc(system, "zz")) != NULL)
{
testEndMessage(false, "got %p");
pass = false;
}
else
testEndMessage(true, "got NULL");

// papplLocGetString
testBegin("api: papplLocGetString('%s')", key);
if ((text = papplLocGetString(loc, key)) != key)
{
testEndMessage(false, "got %p", text);
pass = false;
}
else
testEndMessage(true, "got key string");

// papplSystemGet/SetAdminGroup
testBegin("api: papplSystemGetAdminGroup");
if (papplSystemGetAdminGroup(system, get_str, sizeof(get_str)))
Expand Down

0 comments on commit 289dca2

Please sign in to comment.