test_gnsrecord_block_expiration.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /*
  2. This file is part of GNUnet.
  3. Copyright (C) 2013 GNUnet e.V.
  4. GNUnet is free software: you can redistribute it and/or modify it
  5. under the terms of the GNU Affero General Public License as published
  6. by the Free Software Foundation, either version 3 of the License,
  7. or (at your option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Affero General Public License for more details.
  12. You should have received a copy of the GNU Affero General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. SPDX-License-Identifier: AGPL3.0-or-later
  15. */
  16. /**
  17. * @file gnsrecord/test_gnsrecord_crypto.c
  18. * @brief testcase for block creation, verification and decryption
  19. */
  20. #include "platform.h"
  21. #include "gnunet_util_lib.h"
  22. #include "gnunet_gnsrecord_lib.h"
  23. #define RECORDS 5
  24. #define TEST_RECORD_TYPE 1234
  25. #define TEST_RECORD_DATALEN 123
  26. #define TEST_RECORD_DATA 'a'
  27. #define TEST_REMOVE_RECORD_TYPE 4321
  28. #define TEST_REMOVE_RECORD_DATALEN 255
  29. #define TEST_REMOVE_RECORD_DATA 'b'
  30. static int res;
  31. static void
  32. run (void *cls, char *const *args, const char *cfgfile,
  33. const struct GNUNET_CONFIGURATION_Handle *cfg)
  34. {
  35. struct GNUNET_GNSRECORD_Data rd[2];
  36. struct GNUNET_TIME_Absolute expiration_abs;
  37. struct GNUNET_TIME_Absolute expiration_abs_shadow;
  38. expiration_abs.abs_value_us = GNUNET_TIME_absolute_get ().abs_value_us
  39. + GNUNET_TIME_UNIT_SECONDS.rel_value_us;
  40. expiration_abs_shadow.abs_value_us = GNUNET_TIME_absolute_get ().abs_value_us
  41. + GNUNET_TIME_UNIT_MINUTES.rel_value_us;
  42. /* create record */
  43. rd[0].expiration_time = expiration_abs.abs_value_us;
  44. rd[0].record_type = TEST_RECORD_TYPE;
  45. rd[0].data_size = TEST_RECORD_DATALEN;
  46. rd[0].data = GNUNET_malloc (TEST_RECORD_DATALEN);
  47. rd[0].flags = GNUNET_GNSRECORD_RF_NONE;
  48. memset ((char *) rd[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
  49. rd[1].expiration_time = expiration_abs.abs_value_us;
  50. rd[1].record_type = TEST_RECORD_TYPE;
  51. rd[1].data_size = TEST_RECORD_DATALEN;
  52. rd[1].data = GNUNET_malloc (TEST_RECORD_DATALEN);
  53. rd[1].flags = GNUNET_GNSRECORD_RF_NONE;
  54. memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
  55. GNUNET_assert (expiration_abs.abs_value_us ==
  56. GNUNET_GNSRECORD_record_get_expiration_time (2,
  57. rd).abs_value_us);
  58. rd[1].expiration_time = expiration_abs_shadow.abs_value_us;
  59. rd[1].record_type = TEST_RECORD_TYPE;
  60. rd[1].data_size = TEST_RECORD_DATALEN;
  61. rd[1].data = GNUNET_malloc (TEST_RECORD_DATALEN);
  62. rd[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
  63. memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
  64. GNUNET_assert (expiration_abs_shadow.abs_value_us ==
  65. GNUNET_GNSRECORD_record_get_expiration_time (2,
  66. rd).abs_value_us);
  67. res = 0;
  68. }
  69. int
  70. main (int argc, char *argv[])
  71. {
  72. static char *const argvx[] = { "test-gnsrecord-crypto",
  73. NULL };
  74. static struct GNUNET_GETOPT_CommandLineOption options[] = {
  75. GNUNET_GETOPT_OPTION_END
  76. };
  77. res = 1;
  78. GNUNET_PROGRAM_run ((sizeof(argvx) / sizeof(char *)) - 1, argvx,
  79. "test-namestore-api",
  80. "nohelp", options, &run, &res);
  81. return res;
  82. }
  83. /* end of test_gnsrecord_crypto.c */