t_wcscoll.c revision 1.1
11.1Sperseant/* $NetBSD: t_wcscoll.c,v 1.1 2017/07/14 14:57:43 perseant Exp $ */ 21.1Sperseant 31.1Sperseant/*- 41.1Sperseant * Copyright (c) 2017 The NetBSD Foundation, Inc. 51.1Sperseant * All rights reserved. 61.1Sperseant * 71.1Sperseant * This code is derived from software contributed to The NetBSD Foundation 81.1Sperseant * by Konrad Schroder. 91.1Sperseant * 101.1Sperseant * Redistribution and use in source and binary forms, with or without 111.1Sperseant * modification, are permitted provided that the following conditions 121.1Sperseant * are met: 131.1Sperseant * 1. Redistributions of source code must retain the above copyright 141.1Sperseant * notice, this list of conditions and the following disclaimer. 151.1Sperseant * 2. Redistributions in binary form must reproduce the above copyright 161.1Sperseant * notice, this list of conditions and the following disclaimer in the 171.1Sperseant * documentation and/or other materials provided with the distribution. 181.1Sperseant * 191.1Sperseant * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sperseant * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sperseant * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sperseant * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sperseant * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sperseant * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sperseant * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sperseant * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sperseant * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sperseant * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sperseant * POSSIBILITY OF SUCH DAMAGE. 301.1Sperseant */ 311.1Sperseant 321.1Sperseant#include <sys/cdefs.h> 331.1Sperseant__COPYRIGHT("@(#) Copyright (c) 2017\ 341.1Sperseant The NetBSD Foundation, inc. All rights reserved."); 351.1Sperseant__RCSID("$NetBSD: t_wcscoll.c,v 1.1 2017/07/14 14:57:43 perseant Exp $"); 361.1Sperseant 371.1Sperseant#include <locale.h> 381.1Sperseant#include <stdio.h> 391.1Sperseant#include <stdlib.h> 401.1Sperseant#include <string.h> 411.1Sperseant#include <limits.h> 421.1Sperseant#include <wchar.h> 431.1Sperseant 441.1Sperseant#include <atf-c.h> 451.1Sperseant 461.1Sperseantstatic struct test { 471.1Sperseant const char *locale; 481.1Sperseant const wchar_t *in_order[10]; 491.1Sperseant} tests[] = { 501.1Sperseant { 511.1Sperseant "C", { 521.1Sperseant L"A string beginning with a" 531.1Sperseant L"Capital Letter", 541.1Sperseant L"always comes before", 551.1Sperseant L"another beginning lowercase", 561.1Sperseant L"assuming ASCII of course", 571.1Sperseant NULL } 581.1Sperseant } , { 591.1Sperseant "en_US.UTF-8", { 601.1Sperseant L"A string beginning with a" 611.1Sperseant L"Capital Letter", 621.1Sperseant L"always comes before", 631.1Sperseant L"another beginning lowercase", 641.1Sperseant L"assuming ASCII of course", 651.1Sperseant NULL } 661.1Sperseant }, 671.1Sperseant /* 681.1Sperseant * The rest of these examples are from Wikipedia. 691.1Sperseant */ 701.1Sperseant { 711.1Sperseant "de_DE.UTF-8", { 721.1Sperseant L"Arg", 731.1Sperseant L"Ärgerlich", 741.1Sperseant L"Arm", 751.1Sperseant L"Assistent", 761.1Sperseant L"Aßlar", 771.1Sperseant L"Assoziation", 781.1Sperseant NULL } 791.1Sperseant }, { 801.1Sperseant "ru_RU.KOI-8", { 811.1Sperseant L"едок", 821.1Sperseant L"ёж", 831.1Sperseant L"ездить", 841.1Sperseant NULL } 851.1Sperseant }, { /* Old-style Spanish collation, expect fail with DUCET */ 861.1Sperseant "es_ES.UTF-8", { 871.1Sperseant L"cinco", 881.1Sperseant L"credo", 891.1Sperseant L"chispa", 901.1Sperseant L"lomo", 911.1Sperseant L"luz", 921.1Sperseant L"llama", 931.1Sperseant NULL } 941.1Sperseant }, { /* We don't have Slovak locale files, expect fail */ 951.1Sperseant "sk_SK.UTF-8", { 961.1Sperseant L"baa", 971.1Sperseant L"baá", 981.1Sperseant L"báa", 991.1Sperseant L"bab", 1001.1Sperseant L"báb", 1011.1Sperseant L"bac", 1021.1Sperseant L"bác", 1031.1Sperseant L"bač", 1041.1Sperseant L"báč", 1051.1Sperseant NULL } 1061.1Sperseant }, { 1071.1Sperseant NULL, 1081.1Sperseant { NULL } 1091.1Sperseant } 1101.1Sperseant}; 1111.1Sperseant 1121.1Sperseantstatic void 1131.1Sperseanth_wcscoll(const struct test *t) 1141.1Sperseant{ 1151.1Sperseant const wchar_t * const *wcp; 1161.1Sperseant const wchar_t * const *owcp; 1171.1Sperseant 1181.1Sperseant ATF_REQUIRE_STREQ(setlocale(LC_ALL, "C"), "C"); 1191.1Sperseant printf("Trying locale %s...\n", t->locale); 1201.1Sperseant ATF_REQUIRE(setlocale(LC_COLLATE, t->locale) != NULL); 1211.1Sperseant printf("Using locale: %s\n", setlocale(LC_ALL, NULL)); 1221.1Sperseant 1231.1Sperseant for (wcp = &t->in_order[0], owcp = wcp++; 1241.1Sperseant *wcp != NULL; owcp = wcp++) { 1251.1Sperseant printf("Check L\"%S\" < L\"%S\"\n", *owcp, *wcp); 1261.1Sperseant ATF_CHECK(wcscoll(*owcp, *wcp) < 0); 1271.1Sperseant } 1281.1Sperseant} 1291.1Sperseant 1301.1SperseantATF_TC(wcscoll); 1311.1SperseantATF_TC_HEAD(wcscoll, tc) 1321.1Sperseant{ 1331.1Sperseant atf_tc_set_md_var(tc, "descr", 1341.1Sperseant "Checks collation using wcscoll(3) under different locales"); 1351.1Sperseant} 1361.1SperseantATF_TC_BODY(wcscoll, tc) 1371.1Sperseant{ 1381.1Sperseant struct test *t; 1391.1Sperseant 1401.1Sperseant atf_tc_expect_fail("LC_COLLATE support is not yet fully implemented"); 1411.1Sperseant for (t = &tests[0]; t->locale != NULL; ++t) 1421.1Sperseant h_wcscoll(t); 1431.1Sperseant} 1441.1Sperseant 1451.1SperseantATF_TP_ADD_TCS(tp) 1461.1Sperseant{ 1471.1Sperseant 1481.1Sperseant ATF_TP_ADD_TC(tp, wcscoll); 1491.1Sperseant 1501.1Sperseant return atf_no_error(); 1511.1Sperseant} 152