test_gnsrecord_block_expiration.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2013 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. 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. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file gnsrecord/test_gnsrecord_crypto.c
  19. * @brief testcase for block creation, verification and decryption
  20. */
  21. #include "platform.h"
  22. #include "gnunet_util_lib.h"
  23. #include "gnunet_gnsrecord_lib.h"
  24. #define RECORDS 5
  25. #define TEST_RECORD_TYPE 1234
  26. #define TEST_RECORD_DATALEN 123
  27. #define TEST_RECORD_DATA 'a'
  28. #define TEST_REMOVE_RECORD_TYPE 4321
  29. #define TEST_REMOVE_RECORD_DATALEN 255
  30. #define TEST_REMOVE_RECORD_DATA 'b'
  31. static int res;
  32. static void
  33. run (void *cls, char *const *args, const char *cfgfile,
  34. const struct GNUNET_CONFIGURATION_Handle *cfg)
  35. {
  36. struct GNUNET_GNSRECORD_Data rd[2];
  37. struct GNUNET_TIME_Absolute expiration_abs;
  38. struct GNUNET_TIME_Absolute expiration_abs_shadow;
  39. expiration_abs.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us +
  40. GNUNET_TIME_UNIT_SECONDS.rel_value_us;
  41. expiration_abs_shadow.abs_value_us = GNUNET_TIME_absolute_get().abs_value_us +
  42. GNUNET_TIME_UNIT_MINUTES.rel_value_us;
  43. /* create record */
  44. rd[0].expiration_time = expiration_abs.abs_value_us;
  45. rd[0].record_type = TEST_RECORD_TYPE;
  46. rd[0].data_size = TEST_RECORD_DATALEN;
  47. rd[0].data = GNUNET_malloc(TEST_RECORD_DATALEN);
  48. rd[0].flags = GNUNET_GNSRECORD_RF_NONE;
  49. memset ((char *) rd[0].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
  50. rd[1].expiration_time = expiration_abs.abs_value_us;
  51. rd[1].record_type = TEST_RECORD_TYPE;
  52. rd[1].data_size = TEST_RECORD_DATALEN;
  53. rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
  54. rd[1].flags = GNUNET_GNSRECORD_RF_NONE;
  55. memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
  56. GNUNET_assert (expiration_abs.abs_value_us == GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
  57. rd[1].expiration_time = expiration_abs_shadow.abs_value_us;
  58. rd[1].record_type = TEST_RECORD_TYPE;
  59. rd[1].data_size = TEST_RECORD_DATALEN;
  60. rd[1].data = GNUNET_malloc(TEST_RECORD_DATALEN);
  61. rd[1].flags = GNUNET_GNSRECORD_RF_SHADOW_RECORD;
  62. memset ((char *) rd[1].data, TEST_RECORD_DATA, TEST_RECORD_DATALEN);
  63. GNUNET_assert (expiration_abs_shadow.abs_value_us == GNUNET_GNSRECORD_record_get_expiration_time(2, rd).abs_value_us);
  64. res = 0;
  65. }
  66. int
  67. main (int argc, char *argv[])
  68. {
  69. static char *const argvx[] = { "test-gnsrecord-crypto",
  70. NULL
  71. };
  72. static struct GNUNET_GETOPT_CommandLineOption options[] = {
  73. GNUNET_GETOPT_OPTION_END
  74. };
  75. res = 1;
  76. GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, "test-namestore-api",
  77. "nohelp", options, &run, &res);
  78. return res;
  79. }
  80. /* end of test_gnsrecord_crypto.c */