General Purpose library for Freestanding C++ and POSIX systems
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.

123 lines
2.6 KiB

  1. #include "shared_fd.hpp"
  2. #include "test_scaffold.h"
  3. struct create_test : public test_scaffold {
  4. create_test() {
  5. name = __FILE__ ":1";
  6. }
  7. virtual int run() {
  8. auto fd = gp::shared_fd::create("./bin/test_n", int(gp::open_modes::user_read) | int(gp::open_modes::user_write));
  9. return fd.is_valid()?0:1;
  10. }
  11. };
  12. append_test dummy_sdfhuisd3(new create_test{});
  13. struct open_test : public test_scaffold {
  14. open_test() {
  15. name = __FILE__ ":2";
  16. }
  17. virtual int run() {
  18. auto fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::append));
  19. return fd.is_valid()?0:1;
  20. }
  21. };
  22. append_test dummy_sdf564dd3(new open_test{});
  23. struct manip_test : public test_scaffold {
  24. manip_test() {
  25. name = __FILE__ ":3";
  26. }
  27. virtual int run() {
  28. auto fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::append));
  29. int error = fd.is_valid()?0:1;
  30. auto fd_cpy = fd;
  31. error += fd_cpy.is_valid()?0:1;
  32. gp::shared_fd constr_cpy(fd_cpy);
  33. error += constr_cpy.is_valid()?0:1;
  34. gp::shared_fd constr_mv(std::move(constr_cpy));
  35. error += constr_mv.is_valid()?0:1;
  36. gp::shared_fd assign_cpy;
  37. assign_cpy.operator=(fd_cpy);
  38. error += assign_cpy.is_valid()?0:1;
  39. gp::shared_fd assign_mv;
  40. assign_mv.operator=(std::move(assign_cpy));
  41. error += assign_mv.is_valid()?0:1;
  42. error += (!assign_cpy.is_valid())?0:1;
  43. return error;
  44. }
  45. };
  46. append_test dummy_lkjs64dd3(new manip_test{});
  47. struct rw_test : public test_scaffold {
  48. rw_test() {
  49. name = __FILE__ ":4";
  50. }
  51. virtual int run() {
  52. auto fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::write));
  53. int error = fd.is_valid()?0:1;
  54. fd.write("potatoes");
  55. error += fd.has_failed();
  56. fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::read));
  57. std::array<char,8> buffer;
  58. auto str = fd.read(std::string_view(buffer.begin(), buffer.size()));
  59. error += fd.has_failed();
  60. error += (str != "potatoes");
  61. return error;
  62. }
  63. };
  64. append_test dummy_l6z5e4rdd3(new rw_test{});
  65. struct rw_err_test : public test_scaffold {
  66. rw_err_test() {
  67. name = __FILE__ ":5";
  68. }
  69. virtual int run() {
  70. auto fd = gp::shared_fd::create("./bin/test_n", int(gp::open_modes::user_read) | int(gp::open_modes::user_write));
  71. fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::read));
  72. int error = fd.is_valid()?0:1;
  73. fd.write("potatoes");
  74. error += fd.has_failed();
  75. fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::write));
  76. error += fd.is_valid()?0:1;
  77. std::array<char,8> buffer;
  78. auto str = fd.read(std::string_view(buffer.begin(), buffer.size()));
  79. error += fd.has_failed();
  80. return error == 2 ? 0 : 1;
  81. }
  82. };
  83. append_test dummy_l6987erd3(new rw_err_test{});