unit1394.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2016, 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.haxx.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. ***************************************************************************/
  22. #include "curlcheck.h"
  23. #include "tool_getparam.h"
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include "memdebug.h" /* LAST include file */
  28. static CURLcode unit_setup(void)
  29. {
  30. return CURLE_OK;
  31. }
  32. static void unit_stop(void)
  33. {
  34. }
  35. UNITTEST_START
  36. const char *values[] = {
  37. /* -E parameter */ /* exp. cert name */ /* exp. passphrase */
  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",
  42. "foo:bar\\\\:baz", "foo", "bar\\\\:baz",
  43. "foo\\bar\\baz", "foo\\bar\\baz", NULL,
  44. "foo\\\\bar\\\\baz", "foo\\bar\\baz", NULL,
  45. "foo\\", "foo\\", NULL,
  46. "foo\\\\", "foo\\", NULL,
  47. "foo:bar\\", "foo", "bar\\",
  48. "foo:bar\\\\", "foo", "bar\\\\",
  49. "foo:bar:", "foo", "bar:",
  50. "foo\\::bar\\:", "foo:", "bar\\:",
  51. "pkcs11:foobar", "pkcs11:foobar", NULL,
  52. "PKCS11:foobar", "PKCS11:foobar", NULL,
  53. "PkCs11:foobar", "PkCs11:foobar", NULL,
  54. #ifdef WIN32
  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",
  59. "c:\\foo:bar\\\\:baz", "c:\\foo", "bar\\\\:baz",
  60. "c:\\foo\\bar\\baz", "c:\\foo\\bar\\baz", NULL,
  61. "c:\\foo\\\\bar\\\\baz", "c:\\foo\\bar\\baz", NULL,
  62. "c:\\foo\\", "c:\\foo\\", NULL,
  63. "c:\\foo\\\\", "c:\\foo\\", NULL,
  64. "c:\\foo:bar\\", "c:\\foo", "bar\\",
  65. "c:\\foo:bar\\\\", "c:\\foo", "bar\\\\",
  66. "c:\\foo:bar:", "c:\\foo", "bar:",
  67. "c:\\foo\\::bar\\:", "c:\\foo:", "bar\\:",
  68. #endif
  69. NULL, NULL, NULL,
  70. };
  71. const char **p;
  72. char *certname, *passphrase;
  73. for(p = values; *p; p += 3) {
  74. parse_cert_parameter(p[0], &certname, &passphrase);
  75. if(p[1]) {
  76. if(certname) {
  77. if(strcmp(p[1], certname)) {
  78. printf("expected certname '%s' but got '%s' "
  79. "for -E param '%s'\n", p[1], certname, p[0]);
  80. fail("assertion failure");
  81. }
  82. }
  83. else {
  84. printf("expected certname '%s' but got NULL "
  85. "for -E param '%s'\n", p[1], p[0]);
  86. fail("assertion failure");
  87. }
  88. }
  89. else {
  90. if(certname) {
  91. printf("expected certname NULL but got '%s' "
  92. "for -E param '%s'\n", certname, p[0]);
  93. fail("assertion failure");
  94. }
  95. }
  96. if(p[2]) {
  97. if(passphrase) {
  98. if(strcmp(p[2], passphrase)) {
  99. printf("expected passphrase '%s' but got '%s'"
  100. "for -E param '%s'\n", p[2], passphrase, p[0]);
  101. fail("assertion failure");
  102. }
  103. }
  104. else {
  105. printf("expected passphrase '%s' but got NULL "
  106. "for -E param '%s'\n", p[2], p[0]);
  107. fail("assertion failure");
  108. }
  109. }
  110. else {
  111. if(passphrase) {
  112. printf("expected passphrase NULL but got '%s' "
  113. "for -E param '%s'\n", passphrase, p[0]);
  114. fail("assertion failure");
  115. }
  116. }
  117. if(certname) free(certname);
  118. if(passphrase) free(passphrase);
  119. }
  120. UNITTEST_STOP