11553Srgrimes/* 21553Srgrimes * Copyright (c) 2004 Kungliga Tekniska H��gskolan 31553Srgrimes * (Royal Institute of Technology, Stockholm, Sweden). 41553Srgrimes * All rights reserved. 51553Srgrimes * 61553Srgrimes * Redistribution and use in source and binary forms, with or without 71553Srgrimes * modification, are permitted provided that the following conditions 81553Srgrimes * are met: 91553Srgrimes * 101553Srgrimes * 1. Redistributions of source code must retain the above copyright 111553Srgrimes * notice, this list of conditions and the following disclaimer. 121553Srgrimes * 131553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 141553Srgrimes * notice, this list of conditions and the following disclaimer in the 151553Srgrimes * documentation and/or other materials provided with the distribution. 161553Srgrimes * 171553Srgrimes * 3. Neither the name of the Institute nor the names of its contributors 181553Srgrimes * may be used to endorse or promote products derived from this software 191553Srgrimes * without specific prior written permission. 201553Srgrimes * 211553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 221553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241553Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 251553Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301553Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311553Srgrimes * SUCH DAMAGE. 321553Srgrimes */ 331553Srgrimes 341553Srgrimes#ifdef HAVE_CONFIG_H 351553Srgrimes#include <config.h> 361553Srgrimes#endif 371553Srgrimes#include <stdio.h> 381553Srgrimes#include <stdlib.h> 391553Srgrimes#include <string.h> 401553Srgrimes#include <err.h> 411553Srgrimes 421553Srgrimes#include "windlocl.h" 431553Srgrimes 441553Srgrimes#define MAX_LENGTH 2 451553Srgrimes 461553Srgrimesstruct example { 471553Srgrimes uint32_t in[MAX_LENGTH]; 481553Srgrimes size_t in_len; 491553Srgrimes uint32_t out[MAX_LENGTH]; 501553Srgrimes size_t out_len; 511553Srgrimes}; 521553Srgrimes 531553Srgrimesstatic struct example cases[] = { 541553Srgrimes {{0}, 0, {0}, 0}, 551553Srgrimes {{0x0041}, 1, {0x0061}, 1}, 561553Srgrimes {{0x0061}, 1, {0x0061}, 1}, 571553Srgrimes {{0x00AD}, 1, {0}, 0}, 581553Srgrimes {{0x00DF}, 1, {0x0073, 0x0073}, 2} 591553Srgrimes}; 601553Srgrimes 611553Srgrimesstatic int 621553Srgrimestry(const struct example *c) 631553Srgrimes{ 641553Srgrimes int ret; 651553Srgrimes size_t out_len = c->out_len; 661553Srgrimes uint32_t *tmp = malloc(out_len * sizeof(uint32_t)); 671553Srgrimes if (tmp == NULL && out_len != 0) 681553Srgrimes err(1, "malloc"); 691553Srgrimes ret = _wind_stringprep_map(c->in, c->in_len, tmp, &out_len, WIND_PROFILE_NAME); 701553Srgrimes if (ret) { 711553Srgrimes printf("wind_stringprep_map failed\n"); 721553Srgrimes return 1; 731553Srgrimes } 741553Srgrimes if (out_len != c->out_len) { 751553Srgrimes printf("wrong out len\n"); 761553Srgrimes free(tmp); 771553Srgrimes return 1; 781553Srgrimes } 791553Srgrimes if (memcmp(c->out, tmp, out_len * sizeof(uint32_t)) != 0) { 801553Srgrimes printf("wrong out data\n"); 811553Srgrimes free(tmp); 821553Srgrimes return 1; 831553Srgrimes } 841553Srgrimes free(tmp); 851553Srgrimes return 0; 861553Srgrimes} 871553Srgrimes 881553Srgrimesint 891553Srgrimesmain(void) 901553Srgrimes{ 911553Srgrimes unsigned i; 921553Srgrimes unsigned failures = 0; 931553Srgrimes 941553Srgrimes for (i = 0; i < sizeof(cases)/sizeof(cases[0]); ++i) 951553Srgrimes failures += try(&cases[i]); 961553Srgrimes return failures != 0; 971553Srgrimes} 981553Srgrimes 991553Srgrimes