|
@@ -0,0 +1,124 @@
|
|
|
+// Not sure where to begin with gtest?
|
|
|
+//
|
|
|
+// What can I test with gtest?
|
|
|
+//
|
|
|
+// googletest/googletest/docs/primer.md
|
|
|
+
|
|
|
+#include "terminal.h"
|
|
|
+#include "gtest/gtest.h"
|
|
|
+#include <string>
|
|
|
+
|
|
|
+/*
|
|
|
+
|
|
|
+struct console_details {
|
|
|
+ int posx, posy;
|
|
|
+ int savedx, savedy;
|
|
|
+ char ansi[20]; // current ANSI command being processed.
|
|
|
+ int in_ansi;
|
|
|
+ int fgcolor; // 0-7 // not 0-15
|
|
|
+ int bgcolor; // 0-7
|
|
|
+ int status; // 0, 1 or 5 (Blink)
|
|
|
+};
|
|
|
+
|
|
|
+enum ANSI_TYPE { START, CURSOR, COLOR, CLEAR, OTHER };
|
|
|
+
|
|
|
+struct termchar {
|
|
|
+ int in_ansi;
|
|
|
+ ANSI_TYPE ansi; // undefined if in_ansi is false
|
|
|
+};
|
|
|
+
|
|
|
+void console_init(struct console_details *cdp);
|
|
|
+void ansi_color(struct console_details *cdp, int color);
|
|
|
+const char *color_restore(struct console_details *cdp);
|
|
|
+ANSI_TYPE console_ansi(struct console_details *cdp, const char *ansi);
|
|
|
+
|
|
|
+termchar console_char(struct console_details *cdp, char ch);
|
|
|
+void console_receive(struct console_details *cdp, std::string chars);
|
|
|
+
|
|
|
+*/
|
|
|
+
|
|
|
+console_details console;
|
|
|
+const std::string reset("\x1b[0m\x1b[2J\x1b[1;1H");
|
|
|
+
|
|
|
+#define GTEST_COUT std::cerr << "[ ] [ INFO ]"
|
|
|
+
|
|
|
+namespace {
|
|
|
+
|
|
|
+TEST(ConsoleInit, init) {
|
|
|
+ console_init(&console);
|
|
|
+ ASSERT_EQ(console.posx, 0);
|
|
|
+ ASSERT_EQ(console.posy, 0);
|
|
|
+ ASSERT_EQ(console.in_ansi, 0);
|
|
|
+ ASSERT_EQ(console.ansi[0], 0);
|
|
|
+ ASSERT_EQ(console.status, 0);
|
|
|
+ ASSERT_EQ(console.bgcolor, 0);
|
|
|
+ ASSERT_EQ(console.fgcolor, 7);
|
|
|
+
|
|
|
+ std::string reset("\x1b[0m\x1b[2J\x1b[1;1H");
|
|
|
+ console_receive(&console, reset);
|
|
|
+ ASSERT_EQ(console.posx, 0);
|
|
|
+ ASSERT_EQ(console.posy, 0);
|
|
|
+ ASSERT_EQ(console.in_ansi, 0);
|
|
|
+ ASSERT_EQ(console.ansi[0], 0);
|
|
|
+ ASSERT_EQ(console.status, 0);
|
|
|
+ ASSERT_EQ(console.bgcolor, 0);
|
|
|
+ ASSERT_EQ(console.fgcolor, 7);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ConsoleBasic, simpleString) {
|
|
|
+ console_init(&console);
|
|
|
+ std::string send("Hello");
|
|
|
+
|
|
|
+ console_receive(&console, send);
|
|
|
+ ASSERT_NE(console.posx, 0);
|
|
|
+ ASSERT_EQ(console.posx, (int)send.size());
|
|
|
+ ASSERT_EQ(console.posy, 0);
|
|
|
+
|
|
|
+ console_receive(&console, reset);
|
|
|
+ ASSERT_EQ(console.posx, 0);
|
|
|
+ ASSERT_EQ(console.posy, 0);
|
|
|
+ send = "Hello\r\n";
|
|
|
+ console_receive(&console, send);
|
|
|
+ ASSERT_EQ(console.posx, 0);
|
|
|
+ ASSERT_EQ(console.posy, 1);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ConsolePosition, simplePositions) {
|
|
|
+ console_init(&console);
|
|
|
+ std::string send("\x1b[10;5H"); // Y;X
|
|
|
+
|
|
|
+ console_receive(&console, send);
|
|
|
+ ASSERT_EQ(console.posx, 4);
|
|
|
+ ASSERT_EQ(console.posy, 9);
|
|
|
+ std::string save_pos("\x1b[s");
|
|
|
+ std::string restore_pos("\x1b[u");
|
|
|
+ console_receive(&console, save_pos);
|
|
|
+ ASSERT_EQ(console.posx, 4);
|
|
|
+ ASSERT_EQ(console.posy, 9);
|
|
|
+ send = "\x1b[5;10H";
|
|
|
+ console_receive(&console, send);
|
|
|
+ ASSERT_EQ(console.posx, 9);
|
|
|
+ ASSERT_EQ(console.posy, 4);
|
|
|
+ console_receive(&console, restore_pos);
|
|
|
+ ASSERT_EQ(console.posx, 4);
|
|
|
+ ASSERT_EQ(console.posy, 9);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ConsoleCRNL, NLCRTests) {
|
|
|
+ console_init(&console);
|
|
|
+ std::string send("Hello\r");
|
|
|
+ console_receive(&console, send);
|
|
|
+ ASSERT_EQ(console.posx, 0);
|
|
|
+ ASSERT_EQ(console.posy, 0);
|
|
|
+ send = "Hello\n";
|
|
|
+ console_receive(&console, send);
|
|
|
+ ASSERT_EQ(console.posy, 1);
|
|
|
+ ASSERT_EQ(console.posx, 5);
|
|
|
+ console_receive(&console, reset);
|
|
|
+ send = "Hello\r\n";
|
|
|
+ console_receive(&console, send);
|
|
|
+ ASSERT_EQ(console.posx, 0);
|
|
|
+ ASSERT_EQ(console.posy, 1);
|
|
|
+}
|
|
|
+
|
|
|
+} // namespace
|