t_wcstod.c revision 276478
150477Speter/* $NetBSD: t_wcstod.c,v 1.3 2011/10/01 17:56:11 christos Exp $ */ 21817Sdg 31817Sdg/*- 41541Srgrimes * Copyright (c) 2011 The NetBSD Foundation, Inc. 51541Srgrimes * All rights reserved. 61541Srgrimes * 7160798Sjhb * Redistribution and use in source and binary forms, with or without 81541Srgrimes * modification, are permitted provided that the following conditions 9146806Srwatson * are met: 10146806Srwatson * 1. Redistributions of source code must retain the above copyright 11146806Srwatson * notice, this list of conditions and the following disclaimer. 12146806Srwatson * 2. Redistributions in binary form must reproduce the above copyright 13146806Srwatson * notice, this list of conditions and the following disclaimer in the 14194390Sjhb * documentation and/or other materials provided with the distribution. 15203660Sed * 16194390Sjhb * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17194390Sjhb * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 1811294Sswallace * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1910905Sbde * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 201541Srgrimes * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2110905Sbde * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2210905Sbde * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 231541Srgrimes * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 241541Srgrimes * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 251541Srgrimes * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 261541Srgrimes * POSSIBILITY OF SUCH DAMAGE. 271541Srgrimes */ 2899855Salfred 29194645Sjhb/*- 30194833Sjhb * Copyright (c)2005 Citrus Project, 311541Srgrimes * All rights reserved. 321541Srgrimes * 3369449Salfred * Redistribution and use in source and binary forms, with or without 34194383Sjhb * modification, are permitted provided that the following conditions 35160797Sjhb * are met: 36181972Sobrien * 1. Redistributions of source code must retain the above copyright 37181972Sobrien * notice, this list of conditions and the following disclaimer. 38183361Sjhb * 2. Redistributions in binary form must reproduce the above copyright 39181972Sobrien * notice, this list of conditions and the following disclaimer in the 40181972Sobrien * documentation and/or other materials provided with the distribution. 41181972Sobrien * 42181972Sobrien * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 43211838Skib * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 44104747Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 45104747Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 46123408Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 47123408Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 481541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 491541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 5011294Sswallace * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 5111294Sswallace * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 5211294Sswallace * SUCH DAMAGE. 5311294Sswallace * 541541Srgrimes */ 551541Srgrimes 561541Srgrimes#include <sys/cdefs.h> 571541Srgrimes__COPYRIGHT("@(#) Copyright (c) 2011\ 581541Srgrimes The NetBSD Foundation, inc. All rights reserved."); 591541Srgrimes__RCSID("$NetBSD: t_wcstod.c,v 1.3 2011/10/01 17:56:11 christos Exp $"); 60160798Sjhb 61160798Sjhb#include <errno.h> 62146806Srwatson#include <math.h> 63160798Sjhb#include <stdlib.h> 64160798Sjhb#include <string.h> 65146806Srwatson#include <wchar.h> 66160798Sjhb 67146806Srwatson#include <atf-c.h> 68160798Sjhb 6912216Sbde#ifdef __FreeBSD__ 7012216Sbde#include <stdio.h> 7112216Sbde#endif 72160798Sjhb 73160798Sjhb#define ALT_HUGE_VAL -1 74146806Srwatson#define ALT_MINUS_HUGE_VAL -2 75146806Srwatson#define ALT_NAN -3 76162991Srwatson 77160798Sjhb#if !defined(__vax__) 78160798Sjhbstatic struct test { 79146806Srwatson const wchar_t *wcs; 80160798Sjhb size_t len; 81160798Sjhb double val; 82160798Sjhb int err; 83160798Sjhb} tests[] = { 84160798Sjhb{ L"IN", 0, 0, 0 }, 85160798Sjhb{ L"+IN", 0, 0, 0 }, 86146806Srwatson{ L"-IN", 0, 0, 0 }, 87160798Sjhb{ L"INX", 0, 0, 0 }, 88146806Srwatson{ L"+INX", 0, 0, 0 }, 89160798Sjhb{ L"-INX", 0, 0, 0 }, 90146806Srwatson{ L"INF", 3, ALT_HUGE_VAL, 0 }, 91160798Sjhb{ L"+INF", 4, ALT_HUGE_VAL, 0 }, 92160798Sjhb{ L"-INF", 4, ALT_MINUS_HUGE_VAL, 0 }, 93146806Srwatson{ L"INFX", 3, ALT_HUGE_VAL, 0 }, 9412216Sbde{ L"+INFX", 4, ALT_HUGE_VAL, 0 }, 95160798Sjhb{ L"-INFX", 4, ALT_MINUS_HUGE_VAL, 0 }, 96160798Sjhb{ L" IN", 0, 0, 0 }, 97160798Sjhb{ L" +IN", 0, 0, 0 }, 98160798Sjhb{ L" -IN", 0, 0, 0 }, 99160798Sjhb{ L" INX", 0, 0, 0 }, 100146806Srwatson{ L" +INX", 0, 0, 0 }, 101160798Sjhb{ L" -INX", 0, 0, 0 }, 102146806Srwatson{ L"+ INF", 0, 0, 0 }, 103160798Sjhb{ L"- INF", 0, 0, 0 }, 104146806Srwatson{ L" INF", 8, ALT_HUGE_VAL, 0 }, 105160798Sjhb{ L" +INF", 9, ALT_HUGE_VAL, 0 }, 106146806Srwatson{ L" -INF", 9, ALT_MINUS_HUGE_VAL, 0 }, 107146806Srwatson{ L" INFX", 8, ALT_HUGE_VAL, 0 }, 108146806Srwatson{ L" +INFX", 9, ALT_HUGE_VAL, 0 }, 109160798Sjhb{ L" -INFX", 9, ALT_MINUS_HUGE_VAL, 0 }, 110146806Srwatson{ L" INFINIT", 8, ALT_HUGE_VAL, 0 }, 111146806Srwatson{ L" +INFINIT", 9, ALT_HUGE_VAL, 0 }, 112160798Sjhb{ L" -INFINIT", 9, ALT_MINUS_HUGE_VAL, 0 }, 113146806Srwatson{ L" INFINITY", 13, ALT_HUGE_VAL, 0 }, 114146806Srwatson{ L" +INFINITY", 14, ALT_HUGE_VAL, 0 }, 115160798Sjhb{ L" -INFINITY", 14, ALT_MINUS_HUGE_VAL, 0 }, 116146806Srwatson{ L" INFINITYX", 13, ALT_HUGE_VAL, 0 }, 117146806Srwatson{ L" +INFINITYX", 14, ALT_HUGE_VAL, 0 }, 118160798Sjhb{ L" -INFINITYX", 14, ALT_MINUS_HUGE_VAL, 0 }, 119160798Sjhb 120160798Sjhb/* NAN */ 121160798Sjhb{ L"NA", 0, 0, 0 }, 122160798Sjhb{ L"+NA", 0, 0, 0 }, 123160798Sjhb{ L"-NA", 0, 0, 0 }, 124160798Sjhb{ L"NAX", 0, 0, 0 }, 125160798Sjhb{ L"+NAX", 0, 0, 0 }, 126160798Sjhb{ L"-NAX", 0, 0, 0 }, 127160798Sjhb{ L"NAN", 3, ALT_NAN, 0 }, 128160798Sjhb{ L"+NAN", 4, ALT_NAN, 0 }, 129160798Sjhb{ L"-NAN", 4, ALT_NAN, 0 }, 130146806Srwatson{ L"NANX", 3, ALT_NAN, 0 }, 131160798Sjhb{ L"+NANX", 4, ALT_NAN, 0 }, 132146806Srwatson{ L"-NANX", 4, ALT_NAN, 0 }, 133160798Sjhb{ L" NA", 0, 0, 0 }, 134146806Srwatson{ L" +NA", 0, 0, 0 }, 135146806Srwatson{ L" -NA", 0, 0, 0 }, 136160798Sjhb{ L" NAX", 0, 0, 0 }, 137160798Sjhb{ L" +NAX", 0, 0, 0 }, 13821776Sbde{ L" -NAX", 0, 0, 0 }, 13921776Sbde{ L"+ NAN", 0, 0, 0 }, 14021776Sbde{ L"- NAN", 0, 0, 0 }, 141160798Sjhb{ L" NAN", 8, ALT_NAN, 0 }, 142146806Srwatson{ L" +NAN", 9, ALT_NAN, 0 }, 143160798Sjhb{ L" -NAN", 9, ALT_NAN, 0 }, 144160798Sjhb{ L" NANX", 8, ALT_NAN, 0 }, 145160798Sjhb{ L" +NANX", 9, ALT_NAN, 0 }, 146162373Srwatson{ L" -NANX", 9, ALT_NAN, 0 }, 147146806Srwatson 148160798Sjhb{ L"0", 1, 0, 0 }, 149146806Srwatson{ L"+0", 2, 0, 0 }, 150160798Sjhb{ L"-0", 2, 0, 0 }, 151160798Sjhb{ L" 0", 11, 0, 0 }, 152160798Sjhb{ L" +0", 12, 0, 0 }, 153176215Sru{ L" -0", 12, 0, 0 }, 154176215Sru{ L"+ 0", 0, 0, 0 }, 155160798Sjhb{ L"- 0", 0, 0, 0 }, 156146806Srwatson 157160798Sjhb{ L".", 0, 0, 0 }, 158146806Srwatson{ L".0", 2, 0, 0 }, 159160798Sjhb{ L".00", 3, 0, 0 }, 160160798Sjhb{ L".000", 4, 0, 0 }, 161160798Sjhb 162146806Srwatson{ L"0.", 2, 0, 0 }, 163146806Srwatson{ L"+0.", 3, 0, 0 }, 164162991Srwatson{ L"-0.", 3, 0, 0 }, 165146806Srwatson{ L" 0.", 12, 0, 0 }, 166160798Sjhb{ L" +0.", 13, 0, 0 }, 167146806Srwatson{ L" -0.", 13, 0, 0 }, 168160798Sjhb 169146806Srwatson{ L"0.0", 3, 0, 0 }, 170146806Srwatson{ L"+0.0", 4, 0, 0 }, 171160798Sjhb{ L"-0.0", 4, 0, 0 }, 172160798Sjhb{ L" 0.0", 13, 0, 0 }, 173160798Sjhb{ L" +0.0", 14, 0, 0 }, 174146806Srwatson{ L" -0.0", 14, 0, 0 }, 175160798Sjhb 176146806Srwatson{ L"000", 3, 0, 0 }, 177160798Sjhb{ L"+000", 4, 0, 0 }, 178160798Sjhb{ L"-000", 4, 0, 0 }, 179146806Srwatson{ L" 000", 13, 0, 0 }, 180160798Sjhb{ L" +000", 14, 0, 0 }, 181146806Srwatson{ L" -000", 14, 0, 0 }, 182146806Srwatson 183146806Srwatson{ L"000.", 4, 0, 0 }, 184160798Sjhb{ L"+000.", 5, 0, 0 }, 185146806Srwatson{ L"-000.", 5, 0, 0 }, 186160798Sjhb{ L" 000.", 14, 0, 0 }, 187146806Srwatson{ L" +000.", 15, 0, 0 }, 188160798Sjhb{ L" -000.", 15, 0, 0 }, 189146806Srwatson 190160798Sjhb{ L"000.0", 5, 0, 0 }, 191160798Sjhb{ L"+000.0", 6, 0, 0 }, 192160798Sjhb{ L"-000.0", 6, 0, 0 }, 193146806Srwatson{ L" 000.0", 15, 0, 0 }, 194160798Sjhb{ L" +000.0", 16, 0, 0 }, 195160798Sjhb{ L" -000.0", 16, 0, 0 }, 196160798Sjhb 197146806Srwatson 198160798Sjhb{ L"0.0.", 3, 0, 0 }, 199146806Srwatson{ L"+0.0.", 4, 0, 0 }, 200146806Srwatson{ L"-0.0.", 4, 0, 0 }, 201160798Sjhb{ L" 0.0.", 13, 0, 0 }, 202146806Srwatson{ L" +0.0.", 14, 0, 0 }, 203146806Srwatson{ L" -0.0.", 14, 0, 0 }, 204160798Sjhb 205160798Sjhb{ L"0.0.0", 3, 0, 0 }, 206146806Srwatson{ L"+0.0.0", 4, 0, 0 }, 207160798Sjhb{ L"-0.0.0", 4, 0, 0 }, 208123750Speter{ L" 0.0.0", 13, 0, 0 }, 20912216Sbde{ L" +0.0.0", 14, 0, 0 }, 210160798Sjhb{ L" -0.0.0", 14, 0, 0 }, 211146806Srwatson 212146806Srwatson/* XXX: FIXME */ 213160798Sjhb#if defined(__linux__) 214160798Sjhb{ L"0X", 2, 0, 0 }, 215146806Srwatson{ L"+0X", 3, 0, 0 }, 216160798Sjhb{ L"-0X", 3, 0, 0 }, 217146806Srwatson#else 218160798Sjhb{ L"0X", 1, 0, 0 }, 219146806Srwatson{ L"+0X", 2, 0, 0 }, 220194390Sjhb{ L"-0X", 2, 0, 0 }, 221146806Srwatson#endif 222160798Sjhb 223160798Sjhb/* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */ 224146806Srwatson#if !defined(__SunOS__) 225160798Sjhb#if defined(__linux__) 226146806Srwatson{ L"0X.", 3, 0, 0 }, 227160798Sjhb{ L"+0X.", 4, 0, 0 }, 228146806Srwatson{ L"-0X.", 4, 0, 0 }, 229160798Sjhb{ L" 0X.", 13, 0, 0 }, 230146806Srwatson{ L" +0X.", 14, 0, 0 }, 231160798Sjhb{ L" -0X.", 14, 0, 0 }, 232146806Srwatson#else 233160798Sjhb{ L"0X.", 1, 0, 0 }, 234146806Srwatson{ L"+0X.", 2, 0, 0 }, 235160798Sjhb{ L"-0X.", 2, 0, 0 }, 236146806Srwatson{ L" 0X.", 11, 0, 0 }, 237160798Sjhb{ L" +0X.", 12, 0, 0 }, 238160798Sjhb{ L" -0X.", 12, 0, 0 }, 239160798Sjhb#endif 24021776Sbde/* XXX: FIXME */ 24121776Sbde#if defined(__NetBSD__) || defined(__linux__) || defined(__FreeBSD__) 242160798Sjhb{ L"0X.0", 4, 0, 0 }, 243146806Srwatson{ L"+0X.0", 5, 0, 0 }, 244160798Sjhb{ L"-0X.0", 5, 0, 0 }, 245146806Srwatson{ L" 0X.0", 14, 0, 0 }, 246160798Sjhb{ L" +0X.0", 15, 0, 0 }, 247146806Srwatson{ L" -0X.0", 15, 0, 0 }, 248146806Srwatson 249160798Sjhb{ L"0X.0P", 4, 0, 0 }, 250146806Srwatson{ L"+0X.0P", 5, 0, 0 }, 251160798Sjhb{ L"-0X.0P", 5, 0, 0 }, 252146806Srwatson{ L" 0X.0P", 14, 0, 0 }, 253160798Sjhb{ L" +0X.0P", 15, 0, 0 }, 254146806Srwatson{ L" -0X.0P", 15, 0, 0 }, 255146806Srwatson#else 256160798Sjhb{ L"0X.0", 1, 0, 0 }, 257146806Srwatson{ L"+0X.0", 2, 0, 0 }, 258160798Sjhb{ L"-0X.0", 2, 0, 0 }, 259146806Srwatson{ L" 0X.0", 11, 0, 0 }, 260160798Sjhb{ L" +0X.0", 12, 0, 0 }, 261146806Srwatson{ L" -0X.0", 12, 0, 0 }, 262160798Sjhb 263160798Sjhb{ L"0X.0P", 1, 0, 0 }, 264194390Sjhb{ L"+0X.0P", 2, 0, 0 }, 265146806Srwatson{ L"-0X.0P", 2, 0, 0 }, 266146806Srwatson{ L" 0X.0P", 11, 0, 0 }, 267146806Srwatson{ L" +0X.0P", 12, 0, 0 }, 268160798Sjhb{ L" -0X.0P", 12, 0, 0 }, 269160798Sjhb#endif 270160798Sjhb 271160798Sjhb{ L"0X0", 3, 0, 0 }, 272160798Sjhb{ L"+0X0", 4, 0, 0 }, 273160798Sjhb{ L"-0X0", 4, 0, 0 }, 274160798Sjhb{ L" 0X0", 13, 0, 0 }, 275160798Sjhb{ L" +0X0", 14, 0, 0 }, 276146806Srwatson{ L" -0X0", 14, 0, 0 }, 277160798Sjhb 278160798Sjhb{ L"00X0.0", 2, 0, 0 }, 279146806Srwatson{ L"+00X0.0", 3, 0, 0 }, 280160798Sjhb{ L"-00X0.0", 3, 0, 0 }, 281160798Sjhb{ L" 00X0.0", 12, 0, 0 }, 282160798Sjhb{ L" +00X0.0", 13, 0, 0 }, 283146806Srwatson{ L" -00X0.0", 13, 0, 0 }, 284146806Srwatson 285160798Sjhb{ L"0X0P", 3, 0, 0 }, 286146806Srwatson{ L"+0X0P", 4, 0, 0 }, 287160798Sjhb{ L"-0X0P", 4, 0, 0 }, 288146806Srwatson{ L" 0X0P", 13, 0, 0 }, 289160798Sjhb{ L" +0X0P", 14, 0, 0 }, 290160798Sjhb{ L" -0X0P", 14, 0, 0 }, 291160798Sjhb 292146806Srwatson{ L"0X0.", 4, 0, 0 }, 293160798Sjhb{ L"+0X0.", 5, 0, 0 }, 294146806Srwatson{ L"-0X0.", 5, 0, 0 }, 295160798Sjhb{ L" 0X0.", 14, 0, 0 }, 296160798Sjhb{ L" +0X0.", 15, 0, 0 }, 297160798Sjhb{ L" -0X0.", 15, 0, 0 }, 298146806Srwatson 299160798Sjhb{ L"0X0.0", 5, 0, 0 }, 300194390Sjhb{ L"+0X0.0", 6, 0, 0 }, 301146806Srwatson{ L"-0X0.0", 6, 0, 0 }, 302146806Srwatson{ L" 0X0.0", 15, 0, 0 }, 3031541Srgrimes{ L" +0X0.0", 16, 0, 0 }, 3041541Srgrimes{ L" -0X0.0", 16, 0, 0 }, 3051541Srgrimes 3061541Srgrimes{ L"0X0.P", 4, 0, 0 }, 3071541Srgrimes{ L"+0X0.P", 5, 0, 0 }, 308146806Srwatson{ L"-0X0.P", 5, 0, 0 }, 309146806Srwatson{ L" 0X0.P", 14, 0, 0 }, 310146806Srwatson{ L" +0X0.P", 15, 0, 0 }, 311177633Sdfr{ L" -0X0.P", 15, 0, 0 }, 312177633Sdfr 31330740Sphk{ L"0X0.P", 4, 0, 0 }, 314161325Sjhb{ L"+0X0.P", 5, 0, 0 }, 315160798Sjhb{ L"-0X0.P", 5, 0, 0 }, 316146806Srwatson{ L" 0X0.P", 14, 0, 0 }, 317160798Sjhb{ L" +0X0.P", 15, 0, 0 }, 318146806Srwatson{ L" -0X0.P", 15, 0, 0 }, 319160798Sjhb 320146806Srwatson#endif 321146806Srwatson{ L"0.12345678", 10, 0.12345678, 0 }, 322160798Sjhb{ L"+0.12345678", 11, +0.12345678, 0 }, 323146806Srwatson{ L"-0.12345678", 11, -0.12345678, 0 }, 324160798Sjhb{ L" 0.12345678", 15, 0.12345678, 0 }, 325146806Srwatson{ L" +0.12345678", 16, +0.12345678, 0 }, 326184789Sed{ L" -0.12345678", 16, -0.12345678, 0 }, 327146806Srwatson 328184789Sed{ L"0.12345E67", 10, 0.12345E67, 0 }, 329146806Srwatson{ L"+0.12345E67", 11, +0.12345E67, 0 }, 330184789Sed{ L"-0.12345E67", 11, -0.12345E67, 0 }, 331161952Srwatson{ L" 0.12345E67", 15, 0.12345E67, 0 }, 332161952Srwatson{ L" +0.12345E67", 16, +0.12345E67, 0 }, 333146806Srwatson{ L" -0.12345E67", 16, -0.12345E67, 0 }, 334146806Srwatson 335146806Srwatson{ L"0.12345E+6", 10, 0.12345E+6, 0 }, 336160798Sjhb{ L"+0.12345E+6", 11, +0.12345E+6, 0 }, 337146806Srwatson{ L"-0.12345E+6", 11, -0.12345E+6, 0 }, 338123750Speter{ L" 0.12345E+6", 15, 0.12345E+6, 0 }, 339160798Sjhb{ L" +0.12345E+6", 16, +0.12345E+6, 0 }, 340146806Srwatson{ L" -0.12345E+6", 16, -0.12345E+6, 0 }, 341123750Speter 342160798Sjhb{ L"0.98765E-4", 10, 0.98765E-4, 0 }, 343146806Srwatson{ L"+0.98765E-4", 11, +0.98765E-4, 0 }, 344123750Speter{ L"-0.98765E-4", 11, -0.98765E-4, 0 }, 345146806Srwatson{ L" 0.98765E-4", 15, 0.98765E-4, 0 }, 346171209Speter{ L" +0.98765E-4", 16, +0.98765E-4, 0 }, 347146806Srwatson{ L" -0.98765E-4", 16, -0.98765E-4, 0 }, 348171209Speter 349171209Speter{ L"12345678E9", 10, 12345678E9, 0 }, 350146806Srwatson{ L"+12345678E9", 11, +12345678E9, 0 }, 351178888Sjulian{ L"-12345678E9", 11, -12345678E9, 0 }, 352161946Srwatson{ L" 12345678E9", 15, 12345678E9, 0 }, 353146806Srwatson{ L" +12345678E9", 16, +12345678E9, 0 }, 354146806Srwatson{ L" -12345678E9", 16, -12345678E9, 0 }, 355146806Srwatson 356146806Srwatson/* XXX: SunOS 5.8's wcstod(3) doesn't accept hex */ 3571541Srgrimes#if !defined(__SunOS__) 35849428Sjkh{ L"0x1P+2", 6, 4, 0 }, 359160798Sjhb{ L"+0x1P+2", 7, +4, 0 }, 360160798Sjhb{ L"-0x1P+2", 7, -4, 0 }, 361160798Sjhb{ L" 0x1P+2", 11, 4, 0 }, 362146806Srwatson{ L" +0x1P+2", 12, +4, 0 }, 363146806Srwatson{ L" -0x1P+2", 12, -4, 0 }, 364146806Srwatson 365146806Srwatson{ L"0x1.0P+2", 8, 4, 0 }, 366160798Sjhb{ L"+0x1.0P+2", 9, +4, 0 }, 367160798Sjhb{ L"-0x1.0P+2", 9, -4, 0 }, 368160798Sjhb{ L" 0x1.0P+2", 13, 4, 0 }, 369160798Sjhb{ L" +0x1.0P+2", 14, +4, 0 }, 370160798Sjhb{ L" -0x1.0P+2", 14, -4, 0 }, 371146806Srwatson 372160798Sjhb{ L"0x1P-2", 6, 0.25, 0 }, 373146806Srwatson{ L"+0x1P-2", 7, +0.25, 0 }, 374146806Srwatson{ L"-0x1P-2", 7, -0.25, 0 }, 375160798Sjhb{ L" 0x1P-2", 11, 0.25, 0 }, 376146806Srwatson{ L" +0x1P-2", 12, +0.25, 0 }, 377146806Srwatson{ L" -0x1P-2", 12, -0.25, 0 }, 378160798Sjhb 379146806Srwatson{ L"0x1.0P-2", 8, 0.25, 0 }, 380171209Speter{ L"+0x1.0P-2", 9, +0.25, 0 }, 381171209Speter{ L"-0x1.0P-2", 9, -0.25, 0 }, 382171209Speter{ L" 0x1.0P-2", 13, 0.25, 0 }, 383183361Sjhb{ L" +0x1.0P-2", 14, +0.25, 0 }, 384146806Srwatson{ L" -0x1.0P-2", 14, -0.25, 0 }, 385171209Speter#endif 386171209Speter 387171209Speter{ NULL, 0, 0, 0 } 388146806Srwatson}; 389171209Speter#endif /* !defined(__vax__) */ 390146806Srwatson 391160798SjhbATF_TC(wcstod); 392146806SrwatsonATF_TC_HEAD(wcstod, tc) 393146806Srwatson{ 394160798Sjhb atf_tc_set_md_var(tc, "descr", "Checks wcstod(3)"); 395160798Sjhb} 396160798SjhbATF_TC_BODY(wcstod, tc) 397160798Sjhb{ 398160798Sjhb#if defined(__vax__) 399146806Srwatson#else 400160798Sjhb struct test *t; 401146806Srwatson#endif 4022124Sdg 4032124Sdg#if !defined(__vax__) 4042124Sdg for (t = &tests[0]; t->wcs != NULL; ++t) { 4052124Sdg double d; 406209579Skib size_t n; 407209579Skib wchar_t *tail; 408209579Skib char *buf; 409209579Skib 410209579Skib /* we do not supported %ls nor %S yet. */ 411209579Skib n = wcstombs(NULL, t->wcs, 0); 412209579Skib ATF_REQUIRE((buf = (void *)malloc(n + 1)) != NULL); 413209579Skib (void)wcstombs(buf, t->wcs, n + 1); 414209579Skib (void)printf("Checking wcstod(\"%s\", &tail):\n", buf); 415209579Skib free(buf); 41612864Speter 41712864Speter errno = 0; 41814215Speter d = wcstod(t->wcs, &tail); 419194910Sjhb (void)printf("[errno]\n"); 420194910Sjhb (void)printf(" got : %s\n", strerror(errno)); 421160798Sjhb (void)printf(" expected: %s\n", strerror(t->err)); 422146806Srwatson ATF_REQUIRE_EQ(errno, t->err); 423160798Sjhb 424146806Srwatson n = (size_t)(tail - t->wcs); 425146806Srwatson (void)printf("[endptr - nptr]\n"); 426194910Sjhb (void)printf(" got : %zd\n", n); 427194910Sjhb (void)printf(" expected: %zd\n", t->len); 428160798Sjhb ATF_REQUIRE_EQ(n, t->len); 429160798Sjhb 430146806Srwatson (void)printf("[result]\n"); 431160798Sjhb (void)printf(" real: %F\n", d); 432146806Srwatson if (t->val == ALT_HUGE_VAL) { 433160798Sjhb (void)printf(" expected: %F\n", HUGE_VAL); 434146806Srwatson ATF_REQUIRE(isinf(d)); 435194910Sjhb ATF_REQUIRE_EQ(d, HUGE_VAL); 436194910Sjhb } else if (t->val == ALT_MINUS_HUGE_VAL) { 437160798Sjhb (void)printf(" expected: %F\n", -HUGE_VAL); 438160798Sjhb ATF_REQUIRE(isinf(d)); 439146806Srwatson ATF_REQUIRE_EQ(d, -HUGE_VAL); 44014219Speter } else if (t->val == ALT_NAN) { 441160798Sjhb (void)printf(" expected: %F\n", NAN); 442146806Srwatson ATF_REQUIRE(isnan(d)); 443161952Srwatson } else { 444161952Srwatson (void)printf(" expected: %F\n", t->val); 445146806Srwatson ATF_REQUIRE_EQ(d, t->val); 446160798Sjhb } 447146806Srwatson 448160798Sjhb (void)printf("\n"); 449156134Sdavidxu } 450160798Sjhb#else /* !defined(__vax__) */ 451160798Sjhb atf_tc_skip("Test is unavailable on vax."); 452151576Sdavidxu#endif /* !defined(__vax__) */ 453151576Sdavidxu} 454160798Sjhb 455151576SdavidxuATF_TP_ADD_TCS(tp) 456160798Sjhb{ 457160798Sjhb ATF_TP_ADD_TC(tp, wcstod); 458146806Srwatson 459146806Srwatson return atf_no_error(); 460146806Srwatson} 461146806Srwatson