DefaultInterfaceController_multiIface_test.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "crypto/random/Random.h"
  16. #include "interface/MultiInterface.h"
  17. #include "memory/MallocAllocator.h"
  18. #include "memory/Allocator.h"
  19. #include "test/TestFramework.h"
  20. static int allocatorsFreed;
  21. static int allocatorFreed(struct Allocator_OnFreeJob* job)
  22. {
  23. allocatorsFreed++;
  24. return 0;
  25. }
  26. // make sure unauthenticated interfaces are cleared out if they don't send valid packets.
  27. int main()
  28. {
  29. struct Allocator* alloc = MallocAllocator_new(1<<20);
  30. struct TestFramework* tf = TestFramework_setUp(NULL, alloc, NULL);
  31. struct Interface iface = {
  32. .allocator = alloc
  33. };
  34. struct MultiInterface* mif = MultiInterface_new(8, &iface, tf->ifController, NULL);
  35. struct Interface* peerIf = MultiInterface_ifaceForKey(mif, "The Key ");
  36. InterfaceController_registerPeer(tf->ifController, NULL, NULL, true, false, peerIf);
  37. Allocator_onFree(peerIf->allocator, allocatorFreed, NULL);
  38. struct Message* msg;
  39. Message_STACK(msg, 0, 128);
  40. Message_push(msg, "invalid poop", 12, NULL);
  41. Message_push(msg, "The Key ", 8, NULL);
  42. iface.receiveMessage(msg, &iface);
  43. Assert_always(allocatorsFreed == 1);
  44. Allocator_free(alloc);
  45. return 0;
  46. }