dump.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
  5. #include <cassert>
  6. #include <cstdint>
  7. #include <cstdio>
  8. #include <vector>
  9. extern "C" int32_t read_box_from_buffer(uint8_t *buffer, size_t size);
  10. void test_arg_validation()
  11. {
  12. int32_t rv;
  13. rv = read_box_from_buffer(nullptr, 0);
  14. assert(rv < 0);
  15. size_t len = 4097;
  16. rv = read_box_from_buffer(nullptr, len);
  17. assert(rv < 0);
  18. std::vector<uint8_t> buf;
  19. rv = read_box_from_buffer(buf.data(), buf.size());
  20. assert(rv < 0);
  21. buf.reserve(len);
  22. rv = read_box_from_buffer(buf.data(), buf.size());
  23. assert(rv < 0);
  24. }
  25. void read_file(const char* filename)
  26. {
  27. FILE* f = fopen(filename, "rb");
  28. assert(f != nullptr);
  29. size_t len = 4096;
  30. std::vector<uint8_t> buf(len);
  31. size_t read = fread(buf.data(), sizeof(decltype(buf)::value_type), buf.size(), f);
  32. buf.resize(read);
  33. fclose(f);
  34. fprintf(stderr, "Parsing %lu byte buffer.\n", (unsigned long)read);
  35. int32_t rv = read_box_from_buffer(buf.data(), buf.size());
  36. assert(rv >= 0);
  37. fprintf(stderr, "%d tracks returned to C code.\n", rv);
  38. }
  39. int main(int argc, char* argv[])
  40. {
  41. test_arg_validation();
  42. for (auto i = 1; i < argc; ++i) {
  43. read_file(argv[i]);
  44. }
  45. return 0;
  46. }