furi_pubsub_test.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <furi.h>
  4. #include "minunit.h"
  5. const uint32_t context_value = 0xdeadbeef;
  6. const uint32_t notify_value_0 = 0x12345678;
  7. const uint32_t notify_value_1 = 0x11223344;
  8. uint32_t pubsub_value = 0;
  9. uint32_t pubsub_context_value = 0;
  10. void test_pubsub_handler(const void* arg, void* ctx) {
  11. pubsub_value = *(uint32_t*)arg;
  12. pubsub_context_value = *(uint32_t*)ctx;
  13. }
  14. void test_furi_pubsub() {
  15. FuriPubSub* test_pubsub = NULL;
  16. FuriPubSubSubscription* test_pubsub_subscription = NULL;
  17. // init pubsub case
  18. test_pubsub = furi_pubsub_alloc();
  19. mu_assert_pointers_not_eq(test_pubsub, NULL);
  20. // subscribe pubsub case
  21. test_pubsub_subscription =
  22. furi_pubsub_subscribe(test_pubsub, test_pubsub_handler, (void*)&context_value);
  23. mu_assert_pointers_not_eq(test_pubsub_subscription, NULL);
  24. /// notify pubsub case
  25. furi_pubsub_publish(test_pubsub, (void*)&notify_value_0);
  26. mu_assert_int_eq(pubsub_value, notify_value_0);
  27. mu_assert_int_eq(pubsub_context_value, context_value);
  28. // unsubscribe pubsub case
  29. furi_pubsub_unsubscribe(test_pubsub, test_pubsub_subscription);
  30. /// notify unsubscribed pubsub case
  31. furi_pubsub_publish(test_pubsub, (void*)&notify_value_1);
  32. mu_assert_int_not_eq(pubsub_value, notify_value_1);
  33. // delete pubsub case
  34. furi_pubsub_free(test_pubsub);
  35. }