Define simple configuration on INI files.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include "../src/ini-config.h"
  5. #include "../src/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. }