furi_new_test.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <furi.h>
  4. #include "minunit.h"
  5. #include "furi-new.h"
  6. const int int_value_init = 0x1234;
  7. const int int_value_changed = 0x5678;
  8. osMessageQueueId_t test_messages;
  9. typedef struct {
  10. char text[256];
  11. bool result;
  12. } test_message;
  13. #define SEND_MESSAGE(value, data) \
  14. { \
  15. message.result = value; \
  16. snprintf(message.text, 256, "Error at line %d, %s", __LINE__, data); \
  17. osMessageQueuePut(test_messages, &message, 0U, 0U); \
  18. }
  19. void _furi_new_wait() {
  20. osThreadFlagsWait(0x0001U, osFlagsWaitAny, osWaitForever);
  21. }
  22. void _furi_new_continue(FuriAppId thread_id) {
  23. osThreadFlagsSet(thread_id, 0x0001U);
  24. }
  25. void _furi_new_main_app(void* p) {
  26. test_message message;
  27. _furi_new_wait();
  28. int another_test_value = int_value_init;
  29. furi_record_create("test/another_app_record", &another_test_value);
  30. SEND_MESSAGE(false, "dummy text");
  31. new_flapp_app_exit();
  32. }
  33. void test_furi_new() {
  34. test_message message;
  35. test_messages = osMessageQueueNew(1, sizeof(test_message), NULL);
  36. // init core
  37. new_furi_init();
  38. // launch test thread
  39. FuriAppId main_app = new_flapp_app_start(_furi_new_main_app, "main_app", 512, NULL);
  40. _furi_new_continue(main_app);
  41. while(1) {
  42. if(osMessageQueueGet(test_messages, &message, NULL, osWaitForever) == osOK) {
  43. if(message.result == true) {
  44. break;
  45. } else {
  46. mu_assert(false, message.text);
  47. }
  48. }
  49. };
  50. /*
  51. // test that "create" wont affect pointer value
  52. furi_record_create("test/record", &test_value);
  53. mu_assert_int_eq(test_value, int_value_init);
  54. // test that we get correct pointer
  55. int* test_value_pointer = furi_record_open("test/record");
  56. mu_assert_pointers_not_eq(test_value_pointer, NULL);
  57. mu_assert_pointers_eq(test_value_pointer, &test_value);
  58. *test_value_pointer = int_value_changed;
  59. mu_assert_int_eq(test_value, int_value_changed);
  60. // start another app
  61. new_record_available = osSemaphoreNew(1, 1, NULL);
  62. osSemaphoreAcquire(new_record_available, osWaitForever);
  63. osThreadAttr_t another_app_attr = {.name = "another_app", .stack_size = 512};
  64. osThreadId_t player = osThreadNew(another_app, NULL, &another_app_attr);
  65. // wait until app create record
  66. osSemaphoreAcquire(new_record_available, osWaitForever);
  67. // open record, test that record pointed to int_value_init
  68. test_value_pointer = furi_record_open("test/another_app_record");
  69. mu_assert_pointers_not_eq(test_value_pointer, NULL);
  70. mu_assert_int_eq(*test_value_pointer, int_value_init);
  71. // test that we can close, (unsubscribe) from record
  72. bool close_result = new_furi_close("test/another_app_record");
  73. mu_assert(close_result, "cannot close record");
  74. */
  75. }