benc_serializeList_test.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 "memory/Allocator.h"
  16. #include "memory/MallocAllocator.h"
  17. #include "io/Reader.h"
  18. #include "io/ArrayReader.h"
  19. #include "io/Writer.h"
  20. #include "io/ArrayWriter.h"
  21. #include "benc/String.h"
  22. #include "benc/Dict.h"
  23. #include "benc/serialization/BencSerializer.h"
  24. #include "benc/serialization/standard/StandardBencSerializer.h"
  25. #include "util/Bits.h"
  26. #include "util/platform/libc/strlen.h"
  27. #include <stdio.h>
  28. static int parseEmptyList()
  29. {
  30. char* test = "d" "2:hi" "le" "e";
  31. struct Allocator* alloc = MallocAllocator_new(1<<20);
  32. struct Reader* reader = ArrayReader_new(test, strlen(test), alloc);
  33. Dict d;
  34. int ret = StandardBencSerializer_get()->parseDictionary(reader, alloc, &d);
  35. char out[256];
  36. struct Writer* w = ArrayWriter_new(out, 256, alloc);
  37. ret |= StandardBencSerializer_get()->serializeDictionary(w, &d);
  38. ret |= Bits_memcmp(test, out, strlen(test));
  39. Allocator_free(alloc);
  40. return ret;
  41. }
  42. int main()
  43. {
  44. return parseEmptyList();
  45. }