Handle utf8/utf8mb3 charset equivalence in test_set_collation

MySQL 8.4 reports 'utf8mb3' where older versions report 'utf8'. Add charset_equiv() to treat both names and their collations (e.g. utf8_general_ci vs utf8mb3_general_ci) as equivalent so the test passes on both MySQL 5.7 and 8.4 backends.
pull/5469/head
Rahim Kanji 2 months ago
parent 2d840faa7f
commit d70805d359

@ -79,18 +79,28 @@ int run_change_user_on_all(const CommandLine& cl, const std::vector<std::string>
return 0;
}
static bool charset_equiv(const char* a, const char* b) {
if (strcmp(a, b) == 0) return true;
std::string sa(a), sb(b);
if ((sa == "utf8" && sb == "utf8mb3") || (sa == "utf8mb3" && sb == "utf8")) return true;
// collation equivalence: utf8_general_ci == utf8mb3_general_ci
if (sa.rfind("utf8_", 0) == 0 && sb == "utf8mb3" + sa.substr(4)) return true;
if (sb.rfind("utf8_", 0) == 0 && sa == "utf8mb3" + sb.substr(4)) return true;
return false;
}
void check_variables(MYSQL_RES *proxy_res, std::string collation) {
std::size_t found = collation.find("_");
std::string charset = collation.substr(0,found);
MYSQL_ROW row = mysql_fetch_row(proxy_res);
ok(strcmp(row[1], charset.c_str()) == 0, "'character_set_client' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]);
ok(charset_equiv(row[1], charset.c_str()), "'character_set_client' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]);
row = mysql_fetch_row(proxy_res);
ok(strcmp(row[1], charset.c_str()) == 0, "'character_set_connection' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]);
ok(charset_equiv(row[1], charset.c_str()), "'character_set_connection' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]);
row = mysql_fetch_row(proxy_res);
ok(strcmp(row[1], charset.c_str()) == 0, "'character_set_results' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]);
ok(charset_equiv(row[1], charset.c_str()), "'character_set_results' matches (expected: '%s') == (actual: '%s')", charset.c_str(), row[1]);
row = mysql_fetch_row(proxy_res);
ok(strcmp(row[1], collation.c_str()) == 0, "'collation_connection' matches (expected: '%s') == (actual: '%s')", collation.c_str(), row[1]);
ok(charset_equiv(row[1], collation.c_str()), "'collation_connection' matches (expected: '%s') == (actual: '%s')", collation.c_str(), row[1]);
}

Loading…
Cancel
Save