API
ttyIOUtils_test.cpp
Go to the documentation of this file.
1 #include "../../../tests/catch2/catch.hpp"
2 
3 
4 #include "../ttyIOUtils.hpp"
5 
6 namespace ttyIOUtils_test
7 {
8 
9 SCENARIO( "A string needs to be telnet-ified", "[libMagAOX::tty]" )
10 {
11  GIVEN("Strings in non-telnet format with single chars")
12  {
13  std::string telnetStr, inputStr;
14  int rv;
15 
16  WHEN("A single \\r char at end")
17  {
18  inputStr = "test\r";
19  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
20  REQUIRE(rv == 0);
21  REQUIRE(telnetStr == "test\r\n");
22  }
23 
24  WHEN("A single \\n char at end")
25  {
26  inputStr = "test\n";
27  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
28  REQUIRE(rv == 0);
29  REQUIRE(telnetStr == "test\r\n");
30  }
31 
32  WHEN("A single \\r char in the middle")
33  {
34  inputStr = "test\rtest";
35  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
36  REQUIRE(rv == 0);
37  REQUIRE(telnetStr == "test\r\ntest");
38  }
39 
40  WHEN("A single \\n char in the middle")
41  {
42  inputStr = "test\ntest";
43  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
44  REQUIRE(rv == 0);
45  REQUIRE(telnetStr == "test\r\ntest");
46  }
47 
48  WHEN("A single \\r char at the beginning")
49  {
50  inputStr = "\rtest";
51  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
52  REQUIRE(rv == 0);
53  REQUIRE(telnetStr == "\r\ntest");
54  }
55 
56  WHEN("A single \\n char at the beginning")
57  {
58  inputStr = "\ntest";
59  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
60  REQUIRE(rv == 0);
61  REQUIRE(telnetStr == "\r\ntest");
62  }
63  }
64 
65  GIVEN("Strings in non-telnet format with two split chars")
66  {
67  std::string telnetStr, inputStr;
68  int rv;
69 
70  WHEN("A single \\r char at end, a \\n at beginning")
71  {
72  inputStr = "\ntest\r";
73  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
74  REQUIRE(rv == 0);
75  REQUIRE(telnetStr == "\r\ntest\r\n");
76  }
77 
78  WHEN("A single \\n char at end, a \\r at beginning")
79  {
80  inputStr = "\rtest\n";
81  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
82  REQUIRE(rv == 0);
83  REQUIRE(telnetStr == "\r\ntest\r\n");
84  }
85 
86  WHEN("A single \\r char in the middle, a \n at beginning")
87  {
88  inputStr = "\ntest\rtset";
89  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
90  REQUIRE(rv == 0);
91  REQUIRE(telnetStr == "\r\ntest\r\ntset");
92  }
93 
94  WHEN("A single \\n char in the middle, a \r at beginning")
95  {
96  inputStr = "\rtest\ntest";
97  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
98  REQUIRE(rv == 0);
99  REQUIRE(telnetStr == "\r\ntest\r\ntest");
100  }
101 
102  WHEN("A single \\r char at the beginning, a \\r at end")
103  {
104  inputStr = "\rtest\r";
105  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
106  REQUIRE(rv == 0);
107  REQUIRE(telnetStr == "\r\ntest\r\n");
108  }
109 
110  WHEN("A single \\n char at the beginning, a \\n at end")
111  {
112  inputStr = "\ntest\r\n";
113  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
114  REQUIRE(rv == 0);
115  REQUIRE(telnetStr == "\r\ntest\r\n");
116  }
117  }
118 
119  GIVEN("Strings already in telnet format")
120  {
121  std::string telnetStr, inputStr;
122  int rv;
123 
124  WHEN("A \\r\\n at end")
125  {
126  inputStr = "test\r\n";
127  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
128  REQUIRE(rv == 0);
129  REQUIRE(telnetStr == "test\r\n");
130  }
131 
132  WHEN("A \\r\\n char in the middle")
133  {
134  inputStr = "test\r\ntest";
135  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
136  REQUIRE(rv == 0);
137  REQUIRE(telnetStr == "test\r\ntest");
138  }
139 
140  WHEN("A \\r\\n char at the beginning")
141  {
142  inputStr = "\r\ntest";
143  rv = MagAOX::tty::telnetCRLF(telnetStr, inputStr );
144  REQUIRE(rv == 0);
145  REQUIRE(telnetStr == "\r\ntest");
146  }
147 
148  }
149 }
150 
151 } //namespace ttyIOUtils_test
#define GIVEN(desc)
Definition: catch.hpp:17763
#define WHEN(desc)
Definition: catch.hpp:17765
#define REQUIRE(...)
Definition: catch.hpp:17676
int telnetCRLF(std::string &telnetStr, const std::string &inputStr)
Replace lone \r and \n with \r\n for telnet-ness.
Definition: ttyIOUtils.cpp:26
SCENARIO("A string needs to be telnet-ified", "[libMagAOX::tty]")