ifile_stream_test.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // SuperTux
  2. // Copyright (C) 2021 Ingo Ruhnke <grumbel@gmail.com>
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. #include <gtest/gtest.h>
  17. #include <array>
  18. #include <fstream>
  19. #include <iostream>
  20. #include <physfs.h>
  21. #include "physfs/ifile_stream.hpp"
  22. TEST(IFileStreamTest, test)
  23. {
  24. PHYSFS_init("ifile_stream_test");
  25. PHYSFS_mount("../tests/data", nullptr, 1);
  26. IFileStream in("test.dat");
  27. size_t total_bytes = 0;
  28. std::array<char, 1024> buffer;
  29. while (in.read(buffer.data(), buffer.size())) {
  30. total_bytes += in.gcount();
  31. ASSERT_EQ(total_bytes, in.tellg());
  32. };
  33. total_bytes += in.gcount();
  34. // tellg() will return -1 instead of the actual value as long as
  35. // eofbit is set
  36. in.clear();
  37. ASSERT_EQ(total_bytes, in.tellg());
  38. std::ifstream fin("../tests/data/test.dat");
  39. fin.seekg(0, std::ios::end);
  40. ASSERT_EQ(fin.tellg(), in.tellg());
  41. }
  42. /* EOF */