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.
 
 

124 lines
2.6 KiB

#include "shared_fd.hpp"
#include "test_scaffold.h"
struct create_test : public test_scaffold {
create_test() {
name = __FILE__ ":1";
}
virtual int run() {
auto fd = gp::shared_fd::create("./bin/test_n", int(gp::open_modes::user_read) | int(gp::open_modes::user_write));
return fd.is_valid()?0:1;
}
};
append_test dummy_sdfhuisd3(new create_test{});
struct open_test : public test_scaffold {
open_test() {
name = __FILE__ ":2";
}
virtual int run() {
auto fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::append));
return fd.is_valid()?0:1;
}
};
append_test dummy_sdf564dd3(new open_test{});
struct manip_test : public test_scaffold {
manip_test() {
name = __FILE__ ":3";
}
virtual int run() {
auto fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::append));
int error = fd.is_valid()?0:1;
auto fd_cpy = fd;
error += fd_cpy.is_valid()?0:1;
gp::shared_fd constr_cpy(fd_cpy);
error += constr_cpy.is_valid()?0:1;
gp::shared_fd constr_mv(std::move(constr_cpy));
error += constr_mv.is_valid()?0:1;
gp::shared_fd assign_cpy;
assign_cpy.operator=(fd_cpy);
error += assign_cpy.is_valid()?0:1;
gp::shared_fd assign_mv;
assign_mv.operator=(std::move(assign_cpy));
error += assign_mv.is_valid()?0:1;
error += (!assign_cpy.is_valid())?0:1;
return error;
}
};
append_test dummy_lkjs64dd3(new manip_test{});
struct rw_test : public test_scaffold {
rw_test() {
name = __FILE__ ":4";
}
virtual int run() {
auto fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::write));
int error = fd.is_valid()?0:1;
fd.write("potatoes");
error += fd.has_failed();
fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::read));
std::array<char,8> buffer;
auto str = fd.read(std::string_view(buffer.begin(), buffer.size()));
error += fd.has_failed();
error += (str != "potatoes");
return error;
}
};
append_test dummy_l6z5e4rdd3(new rw_test{});
struct rw_err_test : public test_scaffold {
rw_err_test() {
name = __FILE__ ":5";
}
virtual int run() {
auto fd = gp::shared_fd::create("./bin/test_n", int(gp::open_modes::user_read) | int(gp::open_modes::user_write));
fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::read));
int error = fd.is_valid()?0:1;
fd.write("potatoes");
error += fd.has_failed();
fd = gp::shared_fd::open("./bin/test_n", int(gp::open_options::write));
error += fd.is_valid()?0:1;
std::array<char,8> buffer;
auto str = fd.read(std::string_view(buffer.begin(), buffer.size()));
error += fd.has_failed();
return error == 2 ? 0 : 1;
}
};
append_test dummy_l6987erd3(new rw_err_test{});