xref: /freebsd/lib/libc/tests/iconv/iconvctl_test.c (revision 559a218c9b257775fb249b67945fe4a05b7a6b9f)
107917187SEric van Gyzen /*-
207917187SEric van Gyzen  * Copyright (c) 2016 Eric van Gyzen
307917187SEric van Gyzen  *
407917187SEric van Gyzen  * Redistribution and use in source and binary forms, with or without
507917187SEric van Gyzen  * modification, are permitted provided that the following conditions
607917187SEric van Gyzen  * are met:
707917187SEric van Gyzen  * 1. Redistributions of source code must retain the above copyright
807917187SEric van Gyzen  *    notice, this list of conditions and the following disclaimer.
907917187SEric van Gyzen  * 2. Redistributions in binary form must reproduce the above copyright
1007917187SEric van Gyzen  *    notice, this list of conditions and the following disclaimer in the
1107917187SEric van Gyzen  *    documentation and/or other materials provided with the distribution.
1207917187SEric van Gyzen  *
1307917187SEric van Gyzen  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1407917187SEric van Gyzen  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1507917187SEric van Gyzen  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1607917187SEric van Gyzen  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1707917187SEric van Gyzen  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1807917187SEric van Gyzen  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1907917187SEric van Gyzen  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2007917187SEric van Gyzen  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2107917187SEric van Gyzen  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2207917187SEric van Gyzen  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2307917187SEric van Gyzen  * SUCH DAMAGE.
2407917187SEric van Gyzen  */
2507917187SEric van Gyzen 
2607917187SEric van Gyzen #include <iconv.h>
2707917187SEric van Gyzen 
2807917187SEric van Gyzen #include <atf-c.h>
2907917187SEric van Gyzen 
30*90ec6a30SAlan Somers static void
test_trivialp(const char * src,const char * dst,int expected)3107917187SEric van Gyzen test_trivialp(const char *src, const char *dst, int expected)
3207917187SEric van Gyzen {
3307917187SEric van Gyzen 	iconv_t ic;
3407917187SEric van Gyzen 	int actual, status;
3507917187SEric van Gyzen 
3607917187SEric van Gyzen 	ic = iconv_open(dst, src);
3707917187SEric van Gyzen 	ATF_REQUIRE(ic != (iconv_t)-1);
3807917187SEric van Gyzen 
3907917187SEric van Gyzen 	status = iconvctl(ic, ICONV_TRIVIALP, &actual);
4007917187SEric van Gyzen 	ATF_REQUIRE(status == 0);
4107917187SEric van Gyzen 
4207917187SEric van Gyzen 	ATF_REQUIRE(actual == expected);
4307917187SEric van Gyzen 
4407917187SEric van Gyzen 	status = iconv_close(ic);
4507917187SEric van Gyzen 	ATF_REQUIRE(status == 0);
4607917187SEric van Gyzen }
4707917187SEric van Gyzen 
4807917187SEric van Gyzen ATF_TC_WITHOUT_HEAD(iconvctl_trivialp_test);
ATF_TC_BODY(iconvctl_trivialp_test,tc)4907917187SEric van Gyzen ATF_TC_BODY(iconvctl_trivialp_test, tc)
5007917187SEric van Gyzen {
5107917187SEric van Gyzen 
5207917187SEric van Gyzen 	test_trivialp("ISO-8859-1",  "ISO-8859-1",  1);
5307917187SEric van Gyzen 	test_trivialp("ISO-8859-1",  "ISO-8859-15", 0);
5407917187SEric van Gyzen 	test_trivialp("ISO-8859-15", "ISO-8859-1",  0);
5507917187SEric van Gyzen 	test_trivialp("ISO-8859-15", "UTF-8",       0);
5607917187SEric van Gyzen 	test_trivialp("UTF-8",       "ASCII",       0);
5707917187SEric van Gyzen }
5807917187SEric van Gyzen 
ATF_TP_ADD_TCS(tp)5907917187SEric van Gyzen ATF_TP_ADD_TCS(tp)
6007917187SEric van Gyzen {
6107917187SEric van Gyzen 
6207917187SEric van Gyzen 	ATF_TP_ADD_TC(tp, iconvctl_trivialp_test);
6307917187SEric van Gyzen 
6407917187SEric van Gyzen 	return (atf_no_error());
6507917187SEric van Gyzen }
66