diff --git a/executors/cpp/coll.cpp.new b/executors/cpp/coll.cpp.new deleted file mode 100644 index c39ad571..00000000 --- a/executors/cpp/coll.cpp.new +++ /dev/null @@ -1,246 +0,0 @@ -/************************************************************************* - * - * © 2016 and later: Unicode, Inc. and others. - * License & terms of use: http://www.unicode.org/copyright.html - * - ************************************************************************* - ************************************************************************* - * COPYRIGHT: - * Copyright (C) 2002-2006 IBM, Inc. All Rights Reserved. - * - *************************************************************************/ - -/** - * This calls collation on pairs of strings for ICU_conformance testing. - */ - - -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "./util.h" - -using std::cout; -using std::endl; -using std::string; - -using icu::Locale; -using icu::UnicodeString; -using icu::Collator; -using icu::RuleBasedCollator; - -/** - * TestCollator -- process JSON inputs, run comparator, return result - */ -auto TestCollator(json_object *json_in) -> string { - 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); - - json_object *str1 = json_object_object_get(json_in, "s1"); - json_object *str2 = json_object_object_get(json_in, "s2"); - - string string1 = json_object_get_string(str1); - string string2 = json_object_get_string(str2); - - // Does this conversion preserve the data? - UnicodeString us1 = UnicodeString::fromUTF8(string1); - UnicodeString us2 = UnicodeString::fromUTF8(string2); - - string test_result; - int uni_result_utf8; - - json_object *locale_obj = json_object_object_get(json_in, "locale"); - const char *locale_string; - if (locale_obj != nullptr) { - locale_string = json_object_get_string(locale_obj); - } else { - locale_string = "und"; - } - - // Comparison type - json_object *compare_type_obj = - json_object_object_get(json_in, "compare_type"); - string compare_type_string; - if (compare_type_obj != nullptr) { - compare_type_string = json_object_get_string(compare_type_obj); - } - - // Strength of comparison - Collator::ECollationStrength strength_type = Collator::PRIMARY; - string strength_string; - - json_object *strength_obj = json_object_object_get(json_in, "strength"); - if (strength_obj != nullptr) { - strength_string = json_object_get_string(strength_obj); - if (strength_string == "primary") { - strength_type = Collator::PRIMARY; - } else if (strength_string == "secondary") { - strength_type = Collator:: SECONDARY; - } else if (strength_string == "tertiary") { - strength_type = Collator::TERTIARY; - } else if (strength_string == "quaternary") { - strength_type = Collator::QUATERNARY; - } else if (strength_string == "IDENTICAL") { - strength_type = Collator::IDENTICAL; - } - } - - // Check for rule-based collation - json_object *rules_obj = json_object_object_get(json_in, "rules"); - string rules_string; - if (rules_obj != nullptr) { - rules_string = json_object_get_string(rules_obj); - } - UnicodeString uni_rules = UnicodeString::fromUTF8(rules_string); - - // Allow for different levels or types of comparison. - json_object *compare_type = json_object_object_get(json_in, "compare_type"); - if (compare_type != nullptr) { - // TODO: Apply this in tests. - const char *comparison_type = json_object_get_string(compare_type); - } - - // Handle some options - json_object *ignore_obj = - json_object_object_get(json_in, "ignorePunctuation"); - - const int32_t unspecified_length = -1; - bool coll_result = true; - - // The json test output. - json_object *return_json = json_object_new_object(); - json_object_object_add(return_json, "label", label_obj); - - int uni_result; - // Create a C++ collator and try it. - - Collator *uni_coll = nullptr; - string return_string; - - if (!rules_string.empty()) { - string uni_rules_string; - // TODO: Check if this is needed. - uni_rules.toUTF8String(uni_rules_string); - - // Make sure normalization is consistent - RuleBasedCollator *rb_coll = new RuleBasedCollator(uni_rules, UCOL_ON, status); - if (check_icu_error(status, return_json, "create RuleBasedCollator")) { - return_string = json_object_to_json_string(return_json); - json_object_put(return_json); - return return_string; - } - - uni_result = rb_coll->compare(us1, us2, status); - if (check_icu_error(status, return_json, "rb_coll->compare")) { - return_string = json_object_to_json_string(return_json); - json_object_put(return_json); - return return_string; - } - - // Don't need this anymore. - delete rb_coll; - } else { - // Not a rule-based collator. - if (strlen(locale_string) <= 0) { - uni_coll = Collator::createInstance(status); - } else { - uni_coll = Collator::createInstance(Locale(locale_string), status); - } - - if (check_icu_error( - status, return_json, "create collator instance")) { - return_string = json_object_to_json_string(return_json); - json_object_put(return_json); - return return_string; - } - - // Make sure normalization is consistent - uni_coll->setAttribute(UCOL_NORMALIZATION_MODE, UCOL_ON, status); - if (check_icu_error( - status, return_json, "error setting normalization to UCOL_ON")) { - return_string = json_object_to_json_string(return_json); - json_object_put(return_json); - return return_string; - } - - if (strength_obj != nullptr) { - uni_coll->setStrength(strength_type); - } - - if (ignore_obj != nullptr) { - const bool ignore_punctuation_bool = json_object_get_boolean(ignore_obj) != 0; - if (ignore_punctuation_bool) { - uni_coll->setAttribute(UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, status); - if (check_icu_error( - status, return_json, - "set UCOL_ALTERNATE_HANDLING to UCOL_SHIFTED")) { - return_string = json_object_to_json_string(return_json); - json_object_put(return_json); - return return_string; - } - } - } - - // Just to check the result. - uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore return - if (check_icu_error( - status, return_json, - "getet UCOL_ALTERNATE_HANDLING")) { - return_string = json_object_to_json_string(return_json); - json_object_put(return_json); - return return_string; - } - - // Perform the string comparison - uni_result = uni_coll->compare(us1, us2, status); - if (check_icu_error( status, return_json, "uni_coll_compare")) { - return_string = json_object_to_json_string(return_json); - json_object_put(return_json); - return return_string; - } - - if (uni_coll != nullptr) { - uni_coll->getAttribute(UCOL_ALTERNATE_HANDLING, status); // ignore result - } - delete uni_coll; - if (check_icu_error( status, return_json, "uni_coll->getATTRIBUTE")) { - return_string = json_object_to_json_string(return_json); - json_object_put(return_json); - return return_string; - } - } - - coll_result = (uni_result != UCOL_GREATER); - if (!coll_result) { - // Test did not succeed! - // Include data compared in the failing test - json_object_object_add( - return_json, "s1", json_object_new_string(string1.c_str())); - json_object_object_add( - return_json, "s2", json_object_new_string(string2.c_str())); - - // Record the actual returned value - json_object_object_add( - return_json, "compare", json_object_new_int64(uni_result)); - } - - json_object_object_add( - return_json, "result", json_object_new_boolean(static_cast(coll_result))); - - return_string = json_object_to_json_string(return_json); - json_object_put(return_json); - return return_string; -}