123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- #include "render.h"
- #include "terminal.h"
- #include "utils.h"
- #include "wordplay.h"
- #include "gtest/gtest.h"
- #include <errno.h>
- #include <fcntl.h>
- #include <string>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <time.h>
- #include <unistd.h>
- #define GTEST_COUT std::cerr << "[ ] [ INFO ]"
- struct console_details console;
- std::string username = "Pseudonym";
- std::string fullname = "Joe User";
- int harry_level(void) { return 4; }
- int randint(int x) { return 1; }
- int randrange(int x, int y) { return x; }
- int random_activate(int x) { return 1; }
- char *repr(const char *) {
- static char text[] = "tada!";
- return text;
- }
- bool replace(std::string &str, const std::string &from, const std::string &to) {
- size_t start_pos = str.find(from);
- if (start_pos == std::string::npos)
- return false;
- str.replace(start_pos, from.length(), to);
- return true;
- }
- const char *logrepr(const char *) {
- static char text[] = "repr!";
- return text;
- }
- namespace {
- class MangleFixture : public ::testing::Test {
- public:
- time_t start;
- int fd;
- const char *filename = "mangle.testing";
- protected:
- virtual void SetUp() {
- console_init(&console);
- start = time(NULL);
-
- fd = creat(filename, S_IRUSR | S_IWUSR);
- }
- virtual void TearDown() {
- if (fd > 0)
- close(fd);
- unlink(filename);
- }
- };
- TEST_F(MangleFixture, TestMangle) {
- std::string data("The bear is sticky");
-
- mangle(fd, data);
- int lfd = open(filename, O_RDONLY);
- char buffer[100];
- int len = read(lfd, buffer, sizeof(buffer));
- if (len == -1) {
- ASSERT_EQ(errno, 0);
- }
- buffer[len] = 0;
- close(lfd);
- GTEST_COUT << "buffer:" << buffer << std::endl;
- ASSERT_STREQ(
- buffer,
- "T \bh \be \b \bb \be \ba \br \b \bi \bs \b \bs \bt \bi \bc \bk \by \b");
- }
- }
|