Define simple configuration on INI files.
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

78 wiersze
1.9 KiB

  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include "../source/ini-config.h"
  5. #include "../source/types/int.h"
  6. static int8_t default_int8_value = 0;
  7. static int8_t read_int8_values[] = { 0, 0, 0, 0, 0 };
  8. static int8_t expected_int8_values[] = { 0, 127, -128, -128, 127 };
  9. static INI_ConfigItem items[] = {
  10. {
  11. .section = "Int",
  12. .key = "Int8_0",
  13. .type = INI_CONFIG_TYPE_I8,
  14. .default_value = &default_int8_value,
  15. .transformer = INI_CONFIG_TRANSFORMER_NONE,
  16. .validator = NULL,
  17. .cmdline_option = NULL,
  18. .dest = &read_int8_values[0],
  19. },
  20. {
  21. .section = "Int",
  22. .key = "Int8_1",
  23. .type = INI_CONFIG_TYPE_I8,
  24. .default_value = &default_int8_value,
  25. .transformer = INI_CONFIG_TRANSFORMER_NONE,
  26. .validator = NULL,
  27. .cmdline_option = NULL,
  28. .dest = &read_int8_values[1],
  29. },
  30. {
  31. .section = "Int",
  32. .key = "Int8_2",
  33. .type = INI_CONFIG_TYPE_I8,
  34. .default_value = &default_int8_value,
  35. .transformer = INI_CONFIG_TRANSFORMER_NONE,
  36. .validator = NULL,
  37. .cmdline_option = NULL,
  38. .dest = &read_int8_values[2],
  39. },
  40. {
  41. .section = "Int",
  42. .key = "Int8_3",
  43. .type = INI_CONFIG_TYPE_I8,
  44. .default_value = &default_int8_value,
  45. .transformer = INI_CONFIG_TRANSFORMER_NONE,
  46. .validator = NULL,
  47. .cmdline_option = NULL,
  48. .dest = &read_int8_values[3],
  49. },
  50. {
  51. .section = "Int",
  52. .key = "Int8_4",
  53. .type = INI_CONFIG_TYPE_I8,
  54. .default_value = &default_int8_value,
  55. .transformer = INI_CONFIG_TRANSFORMER_NONE,
  56. .validator = NULL,
  57. .cmdline_option = NULL,
  58. .dest = &read_int8_values[4],
  59. },
  60. INI_CONFIG_ITEM_NULL
  61. };
  62. int main() {
  63. printf("Fixture file exists? ");
  64. const char* argv[] = { };
  65. int argc = 0;
  66. assert(INI_ConfigInitialize(items, "test-int.ini", argc, argv) == 0);
  67. printf("Yes.\n");
  68. for (uint8_t i = 0; i < 5; i += 1) {
  69. printf("read: %d, expected: %d\n", read_int8_values[i], expected_int8_values[i]);
  70. assert(read_int8_values[i] == expected_int8_values[i]);
  71. }
  72. return 0;
  73. }