tool1394.c (4638B)
1 /*************************************************************************** 2 * _ _ ____ _ 3 * Project ___| | | | _ \| | 4 * / __| | | | |_) | | 5 * | (__| |_| | _ <| |___ 6 * \___|\___/|_| \_\_____| 7 * 8 * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al. 9 * 10 * This software is licensed as described in the file COPYING, which 11 * you should have received as part of this distribution. The terms 12 * are also available at https://curl.se/docs/copyright.html. 13 * 14 * You may opt to use, copy, modify, merge, publish, distribute and/or sell 15 * copies of the Software, and permit persons to whom the Software is 16 * furnished to do so, under the terms of the COPYING file. 17 * 18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 19 * KIND, either express or implied. 20 * 21 * SPDX-License-Identifier: curl 22 * 23 ***************************************************************************/ 24 #include "unitcheck.h" 25 26 #include "tool_getparam.h" 27 28 #include "memdebug.h" /* LAST include file */ 29 30 static CURLcode test_tool1394(char *arg) 31 { 32 UNITTEST_BEGIN_SIMPLE 33 34 static const char *values[] = { 35 /* -E parameter */ /* exp. cert name */ /* exp. passphrase */ 36 "foo:bar:baz", "foo", "bar:baz", 37 "foo\\:bar:baz", "foo:bar", "baz", 38 "foo\\\\:bar:baz", "foo\\", "bar:baz", 39 "foo:bar\\:baz", "foo", "bar\\:baz", 40 "foo:bar\\\\:baz", "foo", "bar\\\\:baz", 41 "foo\\bar\\baz", "foo\\bar\\baz", NULL, 42 "foo\\\\bar\\\\baz", "foo\\bar\\baz", NULL, 43 "foo\\", "foo\\", NULL, 44 "foo\\\\", "foo\\", NULL, 45 "foo:bar\\", "foo", "bar\\", 46 "foo:bar\\\\", "foo", "bar\\\\", 47 "foo:bar:", "foo", "bar:", 48 "foo\\::bar\\:", "foo:", "bar\\:", 49 "pkcs11:foobar", "pkcs11:foobar", NULL, 50 "PKCS11:foobar", "PKCS11:foobar", NULL, 51 "PkCs11:foobar", "PkCs11:foobar", NULL, 52 #ifdef _WIN32 53 "c:\\foo:bar:baz", "c:\\foo", "bar:baz", 54 "c:\\foo\\:bar:baz", "c:\\foo:bar", "baz", 55 "c:\\foo\\\\:bar:baz", "c:\\foo\\", "bar:baz", 56 "c:\\foo:bar\\:baz", "c:\\foo", "bar\\:baz", 57 "c:\\foo:bar\\\\:baz", "c:\\foo", "bar\\\\:baz", 58 "c:\\foo\\bar\\baz", "c:\\foo\\bar\\baz", NULL, 59 "c:\\foo\\\\bar\\\\baz", "c:\\foo\\bar\\baz", NULL, 60 "c:\\foo\\", "c:\\foo\\", NULL, 61 "c:\\foo\\\\", "c:\\foo\\", NULL, 62 "c:\\foo:bar\\", "c:\\foo", "bar\\", 63 "c:\\foo:bar\\\\", "c:\\foo", "bar\\\\", 64 "c:\\foo:bar:", "c:\\foo", "bar:", 65 "c:\\foo\\::bar\\:", "c:\\foo:", "bar\\:", 66 #endif 67 NULL, NULL, NULL, 68 }; 69 const char **p; 70 char *certname, *passphrase; 71 for(p = values; *p; p += 3) { 72 parse_cert_parameter(p[0], &certname, &passphrase); 73 if(p[1]) { 74 if(certname) { 75 if(strcmp(p[1], certname)) { 76 printf("expected certname '%s' but got '%s' " 77 "for -E param '%s'\n", p[1], certname, p[0]); 78 fail("assertion failure"); 79 } 80 } 81 else { 82 printf("expected certname '%s' but got NULL " 83 "for -E param '%s'\n", p[1], p[0]); 84 fail("assertion failure"); 85 } 86 } 87 else { 88 if(certname) { 89 printf("expected certname NULL but got '%s' " 90 "for -E param '%s'\n", certname, p[0]); 91 fail("assertion failure"); 92 } 93 } 94 if(p[2]) { 95 if(passphrase) { 96 if(strcmp(p[2], passphrase)) { 97 printf("expected passphrase '%s' but got '%s'" 98 "for -E param '%s'\n", p[2], passphrase, p[0]); 99 fail("assertion failure"); 100 } 101 } 102 else { 103 printf("expected passphrase '%s' but got NULL " 104 "for -E param '%s'\n", p[2], p[0]); 105 fail("assertion failure"); 106 } 107 } 108 else { 109 if(passphrase) { 110 printf("expected passphrase NULL but got '%s' " 111 "for -E param '%s'\n", passphrase, p[0]); 112 fail("assertion failure"); 113 } 114 } 115 if(certname) 116 free(certname); 117 if(passphrase) 118 free(passphrase); 119 } 120 121 UNITTEST_END_SIMPLE 122 }