DefaultInterfaceController_multiIface_test.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. 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);
  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);
  41. Message_push(msg, "The Key ", 8);
  42. iface.receiveMessage(msg, &iface);
  43. Assert_true(allocatorsFreed == 1);
  44. Allocator_free(alloc);
  45. }