You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

uoEntryEnumeratorTest.cpp 2.8KB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*********************************************************************
  2. * Software License Agreement (AGPL-3 License)
  3. *
  4. * OpenViBE SDK Test Software
  5. * Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
  6. * Copyright (C) Inria, 2015-2017,V1.0
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License version 3,
  10. * as published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program.
  19. * If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <string>
  22. #include <vector>
  23. #include <fs/IEntryEnumerator.h>
  24. #include "ovtAssert.h"
  25. class EntryEnumeratorCallBack final : public FS::IEntryEnumeratorCallBack
  26. {
  27. public:
  28. bool callback(FS::IEntryEnumerator::IEntry& rEntry, FS::IEntryEnumerator::IAttributes& rAttributes) override
  29. {
  30. if (rAttributes.isFile()) { m_files.push_back(rEntry.getName()); }
  31. return true;
  32. }
  33. void release() { m_files.clear(); }
  34. std::vector<std::string> m_files;
  35. };
  36. int uoEntryEnumeratorTest(int /*argc*/, char* argv[])
  37. {
  38. const std::string dataDirectory = argv[1];
  39. EntryEnumeratorCallBack cb;
  40. FS::IEntryEnumerator* enumerator = createEntryEnumerator(cb);
  41. enumerator->enumerate((dataDirectory + "*.txt").c_str());
  42. OVT_ASSERT(cb.m_files.size() == 2, "Failure to enumerate with wildcard prefix");
  43. cb.release();
  44. // test wildcard after
  45. enumerator->enumerate((dataDirectory + "test*").c_str());
  46. OVT_ASSERT(cb.m_files.size() == 2, "Failure to enumerate with wildcard suffix");
  47. cb.release();
  48. // test wildcard after
  49. enumerator->enumerate((dataDirectory + "t*").c_str());
  50. OVT_ASSERT(cb.m_files.size() == 3, "Failure to enumerate with single letter");
  51. cb.release();
  52. // test wildcard before and after
  53. enumerator->enumerate((dataDirectory + "*oto*").c_str());
  54. OVT_ASSERT(cb.m_files.size() == 1, "Failure to enumerate with englobing wildcards");
  55. OVT_ASSERT_STREQ(cb.m_files[0], std::string(dataDirectory + "toto.md"), "Failure to enumerate with englobing wildcards");
  56. cb.release();
  57. // test wildcard in middle
  58. enumerator->enumerate((dataDirectory + "test1*xt").c_str());
  59. OVT_ASSERT(cb.m_files.size() == 1, "Failure to enumerate with middle wildcard");
  60. OVT_ASSERT_STREQ(cb.m_files[0], std::string(dataDirectory + "test1.txt"), "Failure to enumerate with middle wildcard");
  61. cb.release();
  62. // error case: no wildcard
  63. enumerator->enumerate((dataDirectory + "t").c_str());
  64. OVT_ASSERT(cb.m_files.empty(), "Failure to enumerate with no wildcard");
  65. cb.release();
  66. enumerator->release();
  67. return EXIT_SUCCESS;
  68. }