1226031Sstas/* 2226031Sstas * Copyright (c) 2008 Kungliga Tekniska H��gskolan 3226031Sstas * (Royal Institute of Technology, Stockholm, Sweden). 4226031Sstas * All rights reserved. 5226031Sstas * 6226031Sstas * Redistribution and use in source and binary forms, with or without 7226031Sstas * modification, are permitted provided that the following conditions 8226031Sstas * are met: 9226031Sstas * 10226031Sstas * 1. Redistributions of source code must retain the above copyright 11226031Sstas * notice, this list of conditions and the following disclaimer. 12226031Sstas * 13226031Sstas * 2. Redistributions in binary form must reproduce the above copyright 14226031Sstas * notice, this list of conditions and the following disclaimer in the 15226031Sstas * documentation and/or other materials provided with the distribution. 16226031Sstas * 17226031Sstas * 3. Neither the name of the Institute nor the names of its contributors 18226031Sstas * may be used to endorse or promote products derived from this software 19226031Sstas * without specific prior written permission. 20226031Sstas * 21226031Sstas * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND 22226031Sstas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23226031Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24226031Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE 25226031Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26226031Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27226031Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28226031Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29226031Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30226031Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31226031Sstas * SUCH DAMAGE. 32226031Sstas */ 33226031Sstas 34226031Sstas#ifdef HAVE_CONFIG_H 35226031Sstas#include <config.h> 36226031Sstas#endif 37226031Sstas#include <stdio.h> 38226031Sstas#include <string.h> 39226031Sstas#include <err.h> 40226031Sstas#include <assert.h> 41226031Sstas#include "windlocl.h" 42226031Sstas 43226031Sstas#define MAX_LENGTH 10 44226031Sstas 45226031Sstasstruct testcase { 46226031Sstas uint32_t in[MAX_LENGTH]; 47226031Sstas size_t ilen; 48226031Sstas uint32_t out[MAX_LENGTH]; 49226031Sstas size_t olen; 50226031Sstas}; 51226031Sstas 52226031Sstasstatic const struct testcase testcases[] = { 53226031Sstas { { 0x20 }, 1, { 0 }, 0 }, 54226031Sstas { { 0x20, 0x61 }, 2, { 0x20, 0x61, 0x20}, 3 }, 55226031Sstas { { 0x20, 0x61, 0x20 }, 3, { 0x20, 0x61, 0x20}, 3 }, 56226031Sstas { { 0x20, 0x61, 0x20, 0x61 }, 4, { 0x20, 0x61, 0x20, 0x20, 0x61, 0x20}, 6 } 57226031Sstas}; 58226031Sstas 59226031Sstasstatic const struct testcase testcases2[] = { 60226031Sstas { { 0x20 }, 1, { 0x20 }, 1 }, 61226031Sstas { { 0x20, 0x41 }, 2, { 0x20, 0x61}, 2 } 62226031Sstas}; 63226031Sstas 64226031Sstas 65226031Sstasint 66226031Sstasmain(void) 67226031Sstas{ 68226031Sstas uint32_t out[MAX_LENGTH]; 69226031Sstas unsigned failures = 0; 70226031Sstas unsigned i; 71226031Sstas size_t olen; 72226031Sstas int ret; 73226031Sstas 74226031Sstas 75226031Sstas for (i = 0; i < sizeof(testcases)/sizeof(testcases[0]); ++i) { 76226031Sstas const struct testcase *t = &testcases[i]; 77226031Sstas 78226031Sstas olen = sizeof(out)/sizeof(out[0]); 79226031Sstas assert(olen > t->olen); 80226031Sstas 81226031Sstas ret = _wind_ldap_case_exact_attribute(t->in, t->ilen, out, &olen); 82226031Sstas if (ret) { 83226031Sstas printf("wlcea: %u: %d\n", i, ret); 84226031Sstas ++failures; 85226031Sstas continue; 86226031Sstas } 87226031Sstas if (olen != t->olen) { 88226031Sstas printf("len wlcea: %u %u != %u\n", i, 89226031Sstas (unsigned)olen, (unsigned)t->olen); 90226031Sstas failures++; 91226031Sstas continue; 92226031Sstas } 93226031Sstas if (memcmp(t->out, out, sizeof(out[0]) * olen) != 0) { 94226031Sstas printf("memcmp wlcea: %u\n", i); 95226031Sstas failures++; 96226031Sstas continue; 97226031Sstas } 98226031Sstas } 99226031Sstas 100226031Sstas for (i = 0; i < sizeof(testcases2)/sizeof(testcases2[0]); ++i) { 101226031Sstas const struct testcase *t = &testcases2[i]; 102226031Sstas 103226031Sstas olen = sizeof(out)/sizeof(out[0]); 104226031Sstas assert(olen > t->olen); 105226031Sstas 106226031Sstas ret = wind_stringprep(t->in, t->ilen, out, &olen, 107226031Sstas WIND_PROFILE_LDAP_CASE); 108226031Sstas 109226031Sstas if (ret) { 110226031Sstas printf("wsplc: %u: %d\n", i, ret); 111226031Sstas ++failures; 112226031Sstas continue; 113226031Sstas } 114226031Sstas 115226031Sstas if (olen != t->olen) { 116226031Sstas printf("strlen wsplc: %u: %d\n", i, ret); 117226031Sstas ++failures; 118226031Sstas continue; 119226031Sstas } 120226031Sstas if (memcmp(t->out, out, sizeof(out[0]) * olen) != 0) { 121226031Sstas printf("memcmp wsplc: %u\n", i); 122226031Sstas failures++; 123226031Sstas continue; 124226031Sstas } 125226031Sstas } 126226031Sstas 127226031Sstas return failures != 0; 128226031Sstas} 129