asn1_string_table_test.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2017 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. /* Tests for the ANS1_STRING_TABLE_* functions */
  10. #include <stdio.h>
  11. #include <string.h>
  12. #include <openssl/asn1.h>
  13. #include "testutil.h"
  14. static int test_string_tbl(void)
  15. {
  16. const ASN1_STRING_TABLE *tmp = NULL;
  17. int nid = 12345678, nid2 = 87654321, rv = 0, ret = 0;
  18. tmp = ASN1_STRING_TABLE_get(nid);
  19. if (!TEST_ptr_null(tmp)) {
  20. TEST_info("asn1 string table: ASN1_STRING_TABLE_get non-exist nid");
  21. goto out;
  22. }
  23. ret = ASN1_STRING_TABLE_add(nid, -1, -1, MBSTRING_ASC, 0);
  24. if (!TEST_true(ret)) {
  25. TEST_info("asn1 string table: add NID(%d) failed", nid);
  26. goto out;
  27. }
  28. ret = ASN1_STRING_TABLE_add(nid2, -1, -1, MBSTRING_ASC, 0);
  29. if (!TEST_true(ret)) {
  30. TEST_info("asn1 string table: add NID(%d) failed", nid2);
  31. goto out;
  32. }
  33. tmp = ASN1_STRING_TABLE_get(nid);
  34. if (!TEST_ptr(tmp)) {
  35. TEST_info("asn1 string table: get NID(%d) failed", nid);
  36. goto out;
  37. }
  38. tmp = ASN1_STRING_TABLE_get(nid2);
  39. if (!TEST_ptr(tmp)) {
  40. TEST_info("asn1 string table: get NID(%d) failed", nid2);
  41. goto out;
  42. }
  43. ASN1_STRING_TABLE_cleanup();
  44. /* check if all newly added NIDs are cleaned up */
  45. tmp = ASN1_STRING_TABLE_get(nid);
  46. if (!TEST_ptr_null(tmp)) {
  47. TEST_info("asn1 string table: get NID(%d) failed", nid);
  48. goto out;
  49. }
  50. tmp = ASN1_STRING_TABLE_get(nid2);
  51. if (!TEST_ptr_null(tmp)) {
  52. TEST_info("asn1 string table: get NID(%d) failed", nid2);
  53. goto out;
  54. }
  55. rv = 1;
  56. out:
  57. return rv;
  58. }
  59. int setup_tests(void)
  60. {
  61. ADD_TEST(test_string_tbl);
  62. return 1;
  63. }