Skip to content

Commit

Permalink
ICU4C lang names working now... (unicode-org#145)
Browse files Browse the repository at this point in the history
* ICU4C LangNames - almost working

* More updates for CPP lang_names

* More updates for CPP lang_names - add ICU74 data

* CPP Langnames - use getDisplayNames

* CPP Langnames - working

* Fix byte count to extract

* Clean up C++ code and revise testplay error handling

* Fixing failures in testplay
  • Loading branch information
sven-oly authored Dec 18, 2023
1 parent 7fbd3a4 commit c5dde43
Show file tree
Hide file tree
Showing 7 changed files with 194,319 additions and 47 deletions.
2 changes: 1 addition & 1 deletion executors/cpp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
TARGET=executor

# All object files (C or C++)
OBJECTS=main.o coll.o util.o capi.o
OBJECTS=main.o coll.o langnames.o util.o capi.o
# OBJECTS=main.o coll.o numfmt.o util.o langnames.o capi.o

#### rules
Expand Down
41 changes: 24 additions & 17 deletions executors/cpp/langnames.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,45 @@ using std::string;


const string test_langnames (json_object *json_in) {
cout << "# LANGNAME: " << json_object_to_json_string(json_in);
UErrorCode status = U_ZERO_ERROR;

json_object *label_obj = json_object_object_get(json_in, "label");
string label_string = json_object_get_string(label_obj);
cout << "# LABEL: " << json_object_get_string(label_obj);

json_object *return_json = json_object_new_object();
json_object_object_add(return_json, "label", label_obj);
json_object_object_add(return_json,
"result",
json_object_new_string(result.c_str()));

// The locale in which the name is given.
json_object *locale_label_obj = json_object_object_get(json_in, "locale_label");
string locale_string = json_object_get_string(locale_label_obj);
cout << "# locale label: " << json_object_get_string(locale_label_obj);

// The language's name to be displayed.
json_object *language_label_obj = json_object_object_get(json_in, "language_label");
string language_label_string = json_object_get_string(language_label_obj);
cout << "# language label: " << json_object_get_string(language_label_obj);

Locale display_locale(locale_string);
UnicodeString display_lang(lange_label_string);
Locale displayLocale(locale_string.c_str());

Locale testLocale(language_label_string.c_str());

UnicodeString &name = getDisplayLanguage(const display_locale, UnicodeString &display_lang);
UnicodeString testLang;

testLocale.getDisplayName(displayLocale, testLang);
// The following gives only the language name, without region information
/// testLocale.getDisplayLanguage(displayLocale, testLang);

json_object *return_json = json_object_new_object();
json_object_object_add(return_json, "label", label_obj);
json_object_object_add(return_json,
"result",
json_object_new_string(name.c_str()));
string return_str = json_object_to_json_string(return_json);

char test_result_string[1000] = "";

int32_t chars_out = testLang.extract(test_result_string, 1000, nullptr, status);
if (U_FAILURE(status)) {
json_object_object_add(return_json,
"error", json_object_new_string("langnames extract error"));
} else {
json_object_object_add(return_json,
"result",
json_object_new_string(test_result_string));
}

return result_string;
string return_string = json_object_to_json_string(return_json);
return return_string;
}
29 changes: 17 additions & 12 deletions executors/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ using std::string;

// Test functions
extern const string test_collator(json_object *json_in);
// extern const string test_numfmt(json_object *json_in);
// extern const string test_langnames(json_object *json_in);
extern const string test_langnames(json_object *json_in);

std::string supported_tests[6] = {
"collation_short"
// "decimal_fmt",
// "number_fmt",
// "display_names",
// "language_display_name",
// "likely_subtags"
//"display_names",
"lang_names",
"language_display_name",
"likely_subtags"
};


Expand Down Expand Up @@ -95,8 +95,7 @@ int main(int argc, const char** argv)
// Parse the JSON data.
// Get the test type and call the test function.

std::string outputLine = "# BAD TEST ";
// !!! cout << "# input line: " << line << endl;
std::string outputLine;

struct json_object *json_input;
json_input = json_tokener_parse(line.c_str());
Expand All @@ -109,11 +108,17 @@ int main(int argc, const char** argv)
// else if (test_type == "number_fmt") {
// outputLine = test_numfmt(json_input);
// // }
// else if (test_type == "language_display_name") {
// outputLine = test_langnames(json_input);
// }
else {
std::string outputLine = "# BAD TEST " + test_type;
else if (test_type == "lang_names") {
outputLine = test_langnames(json_input);
}
else if (test_type == "likely_subtags") {
// !!! outputLine = test_likely_subtags(json_input);
}
else {
outputLine = "# BAD TEST " + test_type;
// "{\"error\": \"unknown test type\"," +
// "\"test_type\":" + test_type + "," +
// "\"unsupported_test:\"" + test_type + "}";
}

// TODO: Instead of a string, get JSON output and stringify it.
Expand Down
22 changes: 13 additions & 9 deletions run_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
"icu_version": "icu71",
"exec": "cpp",
"test_type": [
"collation_short"
"collation_short",
"lang_names"
],
"per_execution": 100
"per_execution": 10000
}
},
{
Expand All @@ -24,9 +25,10 @@
"icu_version": "icu72",
"exec": "cpp",
"test_type": [
"collation_short"
"collation_short",
"lang_names"
],
"per_execution": 100
"per_execution": 10000
}
},
{
Expand All @@ -39,24 +41,26 @@
"icu_version": "icu73",
"exec": "cpp",
"test_type": [
"collation_short"
"collation_short",
"lang_names"
],
"per_execution": 100
"per_execution": 10000
}
},
{
"prereq": {
"name": "Get ICU4x",
"name": "Get ICU4C 74",
"version": "74.1",
"command": "bash ../executors/cpp/set_icu4c_binary.sh ../gh-cache/icu4c-74_1-Ubuntu22.04-x64.tgz"
},
"run": {
"icu_version": "icu74",
"exec": "cpp",
"test_type": [
"collation_short"
"collation_short",
"lang_names"
],
"per_execution": 100
"per_execution": 10000
}
},
{
Expand Down
13 changes: 5 additions & 8 deletions testdriver/testplan.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,18 +520,15 @@ def send_one_line(self, input_line):
logging.error(' !!!!!! exec_list = %s\n input_line = %s' % (self.exec_list, input_line))
logging.error(' !!!!!! %s' % self.run_error_message)

# TODO!!!! Return an error for the offending line instead of failing for the whole batch

return None
input = json.loads(input_line.replace('#EXIT', ''))
error_result = {'label': input['label'],
'input_data': input,
# Handle problems with decoding errors and other unknowns.
error_result = {'label': 'UNKNOWN',
'input_data': input_line,
'error': self.run_error_message
}
}
return json.dumps(error_result)
except BaseException as err:
logging.error('!!! send_one_line fails: input => %s<. Err = %s', input_line, err)
input = json.loads(input_line.replace('#EXIT', ''))
input = json.loads(input_line.replace('#EXIT', '').strip())
error_result = {'label': input['label'],
'input_data': input,
'error': err
Expand Down
Loading

0 comments on commit c5dde43

Please sign in to comment.