TestFileSystem.cc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "FileSystem.h"
  19. #include "test_commons.h"
  20. TEST(FileSystem, RawFileSystem) {
  21. FileSystem & fs = FileSystem::getLocal();
  22. fs.mkdirs("temp");
  23. string temppath = "temp/data";
  24. string content;
  25. GenerateKVTextLength(content, 4111111, "word");
  26. FileOutputStream * output = (FileOutputStream*)fs.create(temppath, true);
  27. output->write(content.data(), content.length());
  28. output->close();
  29. delete output;
  30. FileInputStream * input = (FileInputStream*)fs.open(temppath);
  31. char buff[1024];
  32. int64_t total = 0;
  33. while (true) {
  34. int rd = input->read(buff, 1024);
  35. if (rd <= 0) {
  36. break;
  37. }
  38. ASSERT_EQ(content.substr(total, rd), string(buff, rd));
  39. total += rd;
  40. }
  41. ASSERT_EQ(content.length(), total);
  42. delete input;
  43. ASSERT_EQ(fs.getLength(temppath), content.length());
  44. ASSERT_TRUE(fs.exists(temppath));
  45. fs.remove("temp");
  46. ASSERT_FALSE(fs.exists(temppath));
  47. }